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_GRAPHICS 22
72 #define SETUP_MODE_CHOOSE_SOUNDS 23
73 #define SETUP_MODE_CHOOSE_MUSIC 24
74 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
75 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
76 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
77 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
78 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
79 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
81 #define MAX_SETUP_MODES 31
83 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
85 /* setup screen titles */
86 #define STR_SETUP_MAIN "Setup"
87 #define STR_SETUP_GAME "Game & Menu"
88 #define STR_SETUP_EDITOR "Editor"
89 #define STR_SETUP_GRAPHICS "Graphics"
90 #define STR_SETUP_SOUND "Sound & Music"
91 #define STR_SETUP_ARTWORK "Custom Artwork"
92 #define STR_SETUP_INPUT "Input Devices"
93 #define STR_SETUP_TOUCH "Touch Controls"
94 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
95 #define STR_SETUP_EXIT "Exit"
96 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
98 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
99 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
100 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
101 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
102 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
103 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
104 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
105 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
106 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
107 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
108 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
109 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
111 /* for input setup functions */
112 #define SETUPINPUT_SCREEN_POS_START 0
113 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
114 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
115 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
117 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
118 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
120 /* for various menu stuff */
121 #define MENU_SCREEN_START_XPOS 1
122 #define MENU_SCREEN_START_YPOS 2
123 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
124 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
125 #define MENU_TITLE1_YPOS 8
126 #define MENU_TITLE2_YPOS 46
127 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
128 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
129 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
130 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
131 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
132 #define MENU_SCREEN_INFO_XSTART 16
133 #define MENU_SCREEN_INFO_YSTART1 100
134 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
135 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
136 MENU_INFO_FONT_TITLE))
137 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
138 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
139 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
140 MENU_SCREEN_INFO_YSTART2 - \
142 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
143 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
144 MENU_SCREEN_INFO_YSTEP)
145 #define NUM_INFO_ELEMENTS_FROM_CONF \
146 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
147 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
148 MAX_MENU_ENTRIES_ON_SCREEN)
149 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
150 MAX_INFO_ELEMENTS_ON_SCREEN), \
151 NUM_INFO_ELEMENTS_FROM_CONF)
152 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
153 #define MAX_MENU_TEXT_LENGTH_BIG 13
154 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
156 /* buttons and scrollbars identifiers */
157 #define SCREEN_CTRL_ID_PREV_LEVEL 0
158 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
159 #define SCREEN_CTRL_ID_PREV_PLAYER 2
160 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
161 #define SCREEN_CTRL_ID_SCROLL_UP 4
162 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
163 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
165 #define NUM_SCREEN_GADGETS 7
167 #define NUM_SCREEN_MENUBUTTONS 4
168 #define NUM_SCREEN_SCROLLBUTTONS 2
169 #define NUM_SCREEN_SCROLLBARS 1
171 #define SCREEN_MASK_MAIN (1 << 0)
172 #define SCREEN_MASK_INPUT (1 << 1)
174 /* graphic position and size values for buttons and scrollbars */
175 #define SC_MENUBUTTON_XSIZE TILEX
176 #define SC_MENUBUTTON_YSIZE TILEY
178 #define SC_SCROLLBUTTON_XSIZE TILEX
179 #define SC_SCROLLBUTTON_YSIZE TILEY
181 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
183 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
184 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
185 SC_SCROLLBUTTON_YSIZE)
187 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
188 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
190 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
191 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
192 SC_SCROLLBUTTON_YSIZE)
194 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
195 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
196 SC_SCROLL_VERTICAL_YSIZE)
198 #define SC_BORDER_SIZE 14
201 /* forward declarations of internal functions */
202 static void HandleScreenGadgets(struct GadgetInfo *);
203 static void HandleSetupScreen_Generic(int, int, int, int, int);
204 static void HandleSetupScreen_Input(int, int, int, int, int);
205 static void CustomizeKeyboard(int);
206 static void ConfigureJoystick(int);
207 static void execSetupGame(void);
208 static void execSetupGraphics(void);
209 static void execSetupSound(void);
210 static void execSetupTouch(void);
211 static void execSetupArtwork(void);
212 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
214 static void DrawChooseLevelSet(void);
215 static void DrawChooseLevelNr(void);
216 static void DrawInfoScreen(void);
217 static void DrawSetupScreen(void);
219 static void DrawInfoScreen_NotAvailable(char *, char *);
220 static void DrawInfoScreen_HelpAnim(int, int, boolean);
221 static void DrawInfoScreen_HelpText(int, int, int, int);
222 static void HandleInfoScreen_Main(int, int, int, int, int);
223 static void HandleInfoScreen_TitleScreen(int);
224 static void HandleInfoScreen_Elements(int);
225 static void HandleInfoScreen_Music(int);
226 static void HandleInfoScreen_Credits(int);
227 static void HandleInfoScreen_Program(int);
228 static void HandleInfoScreen_Version(int);
230 static void MapScreenMenuGadgets(int);
231 static void MapScreenGadgets(int);
232 static void MapScreenTreeGadgets(TreeInfo *);
234 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
236 static int info_mode = INFO_MODE_MAIN;
237 static int setup_mode = SETUP_MODE_MAIN;
239 static TreeInfo *window_sizes = NULL;
240 static TreeInfo *window_size_current = NULL;
242 static TreeInfo *scaling_types = NULL;
243 static TreeInfo *scaling_type_current = NULL;
245 static TreeInfo *rendering_modes = NULL;
246 static TreeInfo *rendering_mode_current = NULL;
248 static TreeInfo *scroll_delays = NULL;
249 static TreeInfo *scroll_delay_current = NULL;
251 static TreeInfo *snapshot_modes = NULL;
252 static TreeInfo *snapshot_mode_current = NULL;
254 static TreeInfo *game_speeds = NULL;
255 static TreeInfo *game_speed_current = NULL;
257 static TreeInfo *volumes_simple = NULL;
258 static TreeInfo *volume_simple_current = NULL;
260 static TreeInfo *volumes_loops = NULL;
261 static TreeInfo *volume_loops_current = NULL;
263 static TreeInfo *volumes_music = NULL;
264 static TreeInfo *volume_music_current = NULL;
266 static TreeInfo *touch_controls = NULL;
267 static TreeInfo *touch_control_current = NULL;
269 static TreeInfo *move_distances = NULL;
270 static TreeInfo *move_distance_current = NULL;
272 static TreeInfo *drop_distances = NULL;
273 static TreeInfo *drop_distance_current = NULL;
275 static TreeInfo *level_number = NULL;
276 static TreeInfo *level_number_current = NULL;
282 } window_sizes_list[] =
287 { 100, "100 % (Default)" },
304 } scaling_types_list[] =
306 { SCALING_QUALITY_NEAREST, "None" },
307 { SCALING_QUALITY_LINEAR, "Linear" },
308 { SCALING_QUALITY_BEST, "Anisotropic" },
317 } rendering_modes_list[] =
319 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
320 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
322 // this mode may work under certain conditions, but does not work on Windows
323 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
325 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
334 } game_speeds_list[] =
343 { 1000, "1/1s (Extremely Slow)" },
348 { 29, "1/35s (Original Supaplex)" },
350 { 20, "1/50s (Normal Speed)" },
351 { 14, "1/70s (Maximum Supaplex)" },
355 { 1, "1/1000s (Extremely Fast)" },
365 } scroll_delays_list[] =
367 { 0, "0 Tiles (No Scroll Delay)" },
370 { 3, "3 Tiles (Default)" },
375 { 8, "8 Tiles (Maximum Scroll Delay)"},
384 } snapshot_modes_list[] =
386 { STR_SNAPSHOT_MODE_OFF, "Off" },
387 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
388 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
389 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
422 } touch_controls_list[] =
424 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
425 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
426 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
450 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
451 (s) <= GAME_MODE_SETUP ? (s) : \
452 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
453 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
455 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
456 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
457 (i) <= INFO_MODE_LEVELSET ? (i) : \
460 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
461 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
462 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
463 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
464 SETUP_MODE_CHOOSE_ARTWORK : \
465 SETUP_MODE_CHOOSE_OTHER)
467 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
468 menu.draw_xoffset[GAME_MODE_INFO] : \
469 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
470 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
471 menu.draw_yoffset[GAME_MODE_INFO] : \
472 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
473 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
474 menu.extra_spacing[GAME_MODE_INFO] : \
475 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
477 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
478 menu.draw_xoffset[GAME_MODE_SETUP] : \
479 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
480 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
481 menu.draw_yoffset[GAME_MODE_SETUP] : \
482 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
483 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
484 menu.extra_spacing[GAME_MODE_SETUP] : \
485 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
487 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
488 DRAW_XOFFSET_INFO(info_mode) : \
489 (s) == GAME_MODE_SETUP ? \
490 DRAW_XOFFSET_SETUP(setup_mode) : \
491 menu.draw_xoffset[DRAW_MODE(s)])
492 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
493 DRAW_YOFFSET_INFO(info_mode) : \
494 (s) == GAME_MODE_SETUP ? \
495 DRAW_YOFFSET_SETUP(setup_mode) : \
496 menu.draw_yoffset[DRAW_MODE(s)])
497 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
498 EXTRA_SPACING_INFO(info_mode) : \
499 (s) == GAME_MODE_SETUP ? \
500 EXTRA_SPACING_SETUP(setup_mode) : \
501 menu.extra_spacing[DRAW_MODE(s)])
503 #define mSX (SX + DRAW_XOFFSET(game_status))
504 #define mSY (SY + DRAW_YOFFSET(game_status))
506 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
507 menu.list_size[game_status] : \
508 MAX_MENU_ENTRIES_ON_SCREEN)
510 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
511 NUM_MENU_ENTRIES_ON_SCREEN)
514 /* title display and control definitions */
516 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
517 2 * MAX_NUM_TITLE_MESSAGES)
519 #define NO_DIRECT_LEVEL_SELECT (-1)
522 static int num_title_screens = 0;
524 struct TitleControlInfo
533 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
535 /* main menu display and control definitions */
537 #define MAIN_CONTROL_NAME 0
538 #define MAIN_CONTROL_LEVELS 1
539 #define MAIN_CONTROL_SCORES 2
540 #define MAIN_CONTROL_EDITOR 3
541 #define MAIN_CONTROL_INFO 4
542 #define MAIN_CONTROL_GAME 5
543 #define MAIN_CONTROL_SETUP 6
544 #define MAIN_CONTROL_QUIT 7
545 #define MAIN_CONTROL_PREV_LEVEL 8
546 #define MAIN_CONTROL_NEXT_LEVEL 9
547 #define MAIN_CONTROL_FIRST_LEVEL 10
548 #define MAIN_CONTROL_LAST_LEVEL 11
549 #define MAIN_CONTROL_LEVEL_NUMBER 12
550 #define MAIN_CONTROL_LEVEL_INFO_1 13
551 #define MAIN_CONTROL_LEVEL_INFO_2 14
552 #define MAIN_CONTROL_LEVEL_NAME 15
553 #define MAIN_CONTROL_LEVEL_AUTHOR 16
554 #define MAIN_CONTROL_LEVEL_YEAR 17
555 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
556 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
557 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
558 #define MAIN_CONTROL_TITLE_1 21
559 #define MAIN_CONTROL_TITLE_2 22
560 #define MAIN_CONTROL_TITLE_3 23
562 static char str_main_text_name[10];
563 static char str_main_text_first_level[10];
564 static char str_main_text_last_level[10];
565 static char str_main_text_level_number[10];
567 static char *main_text_name = str_main_text_name;
568 static char *main_text_first_level = str_main_text_first_level;
569 static char *main_text_last_level = str_main_text_last_level;
570 static char *main_text_level_number = str_main_text_level_number;
571 static char *main_text_levels = "Levelset";
572 static char *main_text_scores = "Hall Of Fame";
573 static char *main_text_editor = "Level Creator";
574 static char *main_text_info = "Info Screen";
575 static char *main_text_game = "Start Game";
576 static char *main_text_setup = "Setup";
577 static char *main_text_quit = "Quit";
578 static char *main_text_level_name = level.name;
579 static char *main_text_level_author = level.author;
580 static char *main_text_level_year = NULL;
581 static char *main_text_level_imported_from = NULL;
582 static char *main_text_level_imported_by = NULL;
583 static char *main_text_level_tested_by = NULL;
585 struct MainControlInfo
589 struct MenuPosInfo *pos_button;
592 struct TextPosInfo *pos_text;
595 struct TextPosInfo *pos_input;
599 static struct MainControlInfo main_controls[] =
603 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
604 &menu.main.text.name, &main_text_name,
605 &menu.main.input.name, &setup.player_name,
609 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
610 &menu.main.text.levels, &main_text_levels,
615 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
616 &menu.main.text.scores, &main_text_scores,
621 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
622 &menu.main.text.editor, &main_text_editor,
627 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
628 &menu.main.text.info, &main_text_info,
633 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
634 &menu.main.text.game, &main_text_game,
639 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
640 &menu.main.text.setup, &main_text_setup,
645 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
646 &menu.main.text.quit, &main_text_quit,
650 /* (these two buttons are real gadgets) */
652 MAIN_CONTROL_PREV_LEVEL,
653 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
658 MAIN_CONTROL_NEXT_LEVEL,
659 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
665 MAIN_CONTROL_FIRST_LEVEL,
667 &menu.main.text.first_level, &main_text_first_level,
671 MAIN_CONTROL_LAST_LEVEL,
673 &menu.main.text.last_level, &main_text_last_level,
677 MAIN_CONTROL_LEVEL_NUMBER,
679 &menu.main.text.level_number, &main_text_level_number,
683 MAIN_CONTROL_LEVEL_INFO_1,
685 &menu.main.text.level_info_1, NULL,
689 MAIN_CONTROL_LEVEL_INFO_2,
691 &menu.main.text.level_info_2, NULL,
695 MAIN_CONTROL_LEVEL_NAME,
697 &menu.main.text.level_name, &main_text_level_name,
701 MAIN_CONTROL_LEVEL_AUTHOR,
703 &menu.main.text.level_author, &main_text_level_author,
707 MAIN_CONTROL_LEVEL_YEAR,
709 &menu.main.text.level_year, &main_text_level_year,
713 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
715 &menu.main.text.level_imported_from, &main_text_level_imported_from,
719 MAIN_CONTROL_LEVEL_IMPORTED_BY,
721 &menu.main.text.level_imported_by, &main_text_level_imported_by,
725 MAIN_CONTROL_LEVEL_TESTED_BY,
727 &menu.main.text.level_tested_by, &main_text_level_tested_by,
731 MAIN_CONTROL_TITLE_1,
733 &menu.main.text.title_1, &setup.internal.program_title,
737 MAIN_CONTROL_TITLE_2,
739 &menu.main.text.title_2, &setup.internal.program_copyright,
743 MAIN_CONTROL_TITLE_3,
745 &menu.main.text.title_3, &setup.internal.program_company,
758 static int getTitleScreenGraphic(int nr, boolean initial)
760 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
763 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
765 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
769 static int getTitleScreenGameMode(boolean initial)
771 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
775 static int getTitleMessageGameMode(boolean initial)
777 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
780 static int getTitleAnimMode(struct TitleControlInfo *tci)
782 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
784 return base + tci->local_nr;
788 static int getTitleScreenBackground(boolean initial)
790 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
795 static int getTitleMessageBackground(int nr, boolean initial)
797 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
801 static int getTitleBackground(int nr, boolean initial, boolean is_image)
803 int base = (is_image ?
804 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
805 IMG_BACKGROUND_TITLESCREEN_1) :
806 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
807 IMG_BACKGROUND_TITLEMESSAGE_1));
808 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
809 IMG_BACKGROUND_TITLE);
810 int graphic_local = base + nr;
812 if (graphic_info[graphic_local].bitmap != NULL)
813 return graphic_local;
815 if (graphic_info[graphic_global].bitmap != NULL)
816 return graphic_global;
818 return IMG_UNDEFINED;
821 static int getTitleSound(struct TitleControlInfo *tci)
823 boolean is_image = tci->is_image;
824 int initial = tci->initial;
825 int nr = tci->local_nr;
826 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
827 int base = (is_image ?
828 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
829 SND_BACKGROUND_TITLESCREEN_1) :
830 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
831 SND_BACKGROUND_TITLEMESSAGE_1));
832 int sound_global = menu.sound[mode];
833 int sound_local = base + nr;
836 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
837 nr, initial, is_image,
838 sound_global, getSoundListEntry(sound_global)->filename,
839 sound_local, getSoundListEntry(sound_local)->filename);
842 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
845 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
848 return SND_UNDEFINED;
851 static int getTitleMusic(struct TitleControlInfo *tci)
853 boolean is_image = tci->is_image;
854 int initial = tci->initial;
855 int nr = tci->local_nr;
856 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
857 int base = (is_image ?
858 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
859 MUS_BACKGROUND_TITLESCREEN_1) :
860 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
861 MUS_BACKGROUND_TITLEMESSAGE_1));
862 int music_global = menu.music[mode];
863 int music_local = base + nr;
866 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
867 nr, initial, is_image,
868 music_global, getMusicListEntry(music_global)->filename,
869 music_local, getMusicListEntry(music_local)->filename);
872 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
875 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
878 return MUS_UNDEFINED;
881 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
883 boolean is_image = tci->is_image;
884 boolean initial = tci->initial;
885 boolean first = tci->first;
886 int nr = tci->local_nr;
887 struct TitleMessageInfo tmi;
888 struct TitleFadingInfo ti;
890 tmi = (is_image ? (initial ? (first ?
891 titlescreen_initial_first[nr] :
892 titlescreen_initial[nr])
894 titlescreen_first[nr] :
896 : (initial ? (first ?
897 titlemessage_initial_first[nr] :
898 titlemessage_initial[nr])
900 titlemessage_first[nr] :
903 ti.fade_mode = tmi.fade_mode;
904 ti.fade_delay = tmi.fade_delay;
905 ti.post_delay = tmi.post_delay;
906 ti.auto_delay = tmi.auto_delay;
911 static int compareTitleControlInfo(const void *object1, const void *object2)
913 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
914 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
917 if (tci1->initial != tci2->initial)
918 compare_result = (tci1->initial ? -1 : +1);
919 else if (tci1->sort_priority != tci2->sort_priority)
920 compare_result = tci1->sort_priority - tci2->sort_priority;
921 else if (tci1->is_image != tci2->is_image)
922 compare_result = (tci1->is_image ? -1 : +1);
924 compare_result = tci1->local_nr - tci2->local_nr;
926 return compare_result;
929 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
931 int nr, int sort_priority)
933 title_controls[num_title_screens].is_image = is_image;
934 title_controls[num_title_screens].initial = initial;
935 title_controls[num_title_screens].local_nr = nr;
936 title_controls[num_title_screens].sort_priority = sort_priority;
938 title_controls[num_title_screens].first = FALSE; /* will be set later */
943 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
947 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
949 int graphic = getTitleScreenGraphic(i, initial);
950 Bitmap *bitmap = graphic_info[graphic].bitmap;
951 int sort_priority = graphic_info[graphic].sort_priority;
954 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
957 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
959 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
960 char *filename = getLevelSetTitleMessageFilename(i, initial);
961 int sort_priority = tmi->sort_priority;
963 if (filename != NULL)
964 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
968 static void InitializeTitleControls(boolean show_title_initial)
970 num_title_screens = 0;
972 /* 1st step: initialize title screens for game start (only when starting) */
973 if (show_title_initial)
974 InitializeTitleControls_CheckTitleInfo(TRUE);
976 /* 2nd step: initialize title screens for current level set */
977 InitializeTitleControls_CheckTitleInfo(FALSE);
979 /* sort title screens according to sort_priority and title number */
980 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
981 compareTitleControlInfo);
983 /* mark first title screen */
984 title_controls[0].first = TRUE;
987 static boolean visibleMenuPos(struct MenuPosInfo *pos)
989 return (pos != NULL && pos->x != -1 && pos->y != -1);
992 static boolean visibleTextPos(struct TextPosInfo *pos)
994 return (pos != NULL && pos->x != -1 && pos->y != -1);
997 static void InitializeMainControls()
999 boolean local_team_mode = (!options.network && setup.team_mode);
1002 /* set main control text values to dynamically determined values */
1003 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1005 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1006 menu.main.text.first_level.size));
1007 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1008 menu.main.text.last_level.size));
1009 strcpy(main_text_level_number, int2str(level_nr,
1010 menu.main.text.level_number.size));
1012 main_text_level_year = leveldir_current->year;
1013 main_text_level_imported_from = leveldir_current->imported_from;
1014 main_text_level_imported_by = leveldir_current->imported_by;
1015 main_text_level_tested_by = leveldir_current->tested_by;
1017 /* set main control screen positions to dynamically determined values */
1018 for (i = 0; main_controls[i].nr != -1; i++)
1020 struct MainControlInfo *mci = &main_controls[i];
1022 struct MenuPosInfo *pos_button = mci->pos_button;
1023 struct TextPosInfo *pos_text = mci->pos_text;
1024 struct TextPosInfo *pos_input = mci->pos_input;
1025 char *text = (mci->text ? *mci->text : NULL);
1026 char *input = (mci->input ? *mci->input : NULL);
1027 int button_graphic = mci->button_graphic;
1028 int font_text = (pos_text ? pos_text->font : -1);
1029 int font_input = (pos_input ? pos_input->font : -1);
1031 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1032 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1033 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1034 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1035 int text_chars = (text != NULL ? strlen(text) : 0);
1036 int input_chars = (input != NULL ? strlen(input) : 0);
1039 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1041 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1042 int text_width = font_text_width * text_chars;
1043 int text_height = font_text_height;
1044 int input_width = font_input_width * input_chars;
1045 int input_height = font_input_height;
1047 if (nr == MAIN_CONTROL_NAME)
1049 menu.main.input.name.width = input_width;
1050 menu.main.input.name.height = input_height;
1053 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1055 pos_button->width = button_width;
1056 pos_button->height = button_height;
1059 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1061 /* calculate size for non-clickable text -- needed for text alignment */
1062 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1064 if (pos_text->width == -1 || calculate_text_size)
1065 pos_text->width = text_width;
1066 if (pos_text->height == -1 || calculate_text_size)
1067 pos_text->height = text_height;
1069 if (visibleMenuPos(pos_button))
1071 if (pos_text->x == -1)
1072 pos_text->x = pos_button->x + pos_button->width;
1073 if (pos_text->y == -1)
1075 pos_button->y + (pos_button->height - pos_text->height) / 2;
1079 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1081 if (visibleTextPos(pos_text))
1083 if (pos_input->x == -1)
1084 pos_input->x = pos_text->x + pos_text->width;
1085 if (pos_input->y == -1)
1086 pos_input->y = pos_text->y;
1089 if (pos_input->width == -1)
1090 pos_input->width = input_width;
1091 if (pos_input->height == -1)
1092 pos_input->height = input_height;
1097 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1098 int graphic, boolean pressed)
1100 struct GraphicInfo *g = &graphic_info[graphic];
1103 int xoffset = (pressed ? g->pressed_xoffset : 0);
1104 int yoffset = (pressed ? g->pressed_yoffset : 0);
1106 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1108 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1109 g->width, g->height, dst_x, dst_y);
1112 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1113 boolean active_input,
1114 boolean pressed_button)
1118 for (i = 0; main_controls[i].nr != -1; i++)
1120 struct MainControlInfo *mci = &main_controls[i];
1122 if (mci->nr == nr || nr == -1)
1124 struct MenuPosInfo *pos_button = mci->pos_button;
1125 struct TextPosInfo *pos_text = mci->pos_text;
1126 struct TextPosInfo *pos_input = mci->pos_input;
1127 char *text = (mci->text ? *mci->text : NULL);
1128 char *input = (mci->input ? *mci->input : NULL);
1129 int button_graphic = mci->button_graphic;
1130 int font_text = (pos_text ? pos_text->font : -1);
1131 int font_input = (pos_input ? pos_input->font : -1);
1135 button_graphic = BUTTON_ACTIVE(button_graphic);
1136 font_text = FONT_ACTIVE(font_text);
1141 font_input = FONT_ACTIVE(font_input);
1144 if (visibleMenuPos(pos_button))
1146 struct MenuPosInfo *pos = pos_button;
1147 int x = mSX + pos->x;
1148 int y = mSY + pos->y;
1150 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1151 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1154 if (visibleTextPos(pos_text) && text != NULL)
1156 struct TextPosInfo *pos = pos_text;
1157 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1158 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1161 /* (check why/if this is needed) */
1162 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1164 DrawText(x, y, text, font_text);
1167 if (visibleTextPos(pos_input) && input != NULL)
1169 struct TextPosInfo *pos = pos_input;
1170 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1171 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1174 /* (check why/if this is needed) */
1175 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1177 DrawText(x, y, input, font_input);
1183 static void DrawCursorAndText_Main(int nr, boolean active_text,
1184 boolean pressed_button)
1186 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1190 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1191 boolean pressed_button)
1193 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1197 static struct MainControlInfo *getMainControlInfo(int nr)
1201 for (i = 0; main_controls[i].nr != -1; i++)
1202 if (main_controls[i].nr == nr)
1203 return &main_controls[i];
1208 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1213 int rect_x = ALIGNED_TEXT_XPOS(rect);
1214 int rect_y = ALIGNED_TEXT_YPOS(rect);
1216 return (x >= rect_x && x < rect_x + rect->width &&
1217 y >= rect_y && y < rect_y + rect->height);
1220 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1225 int rect_x = ALIGNED_TEXT_XPOS(rect);
1226 int rect_y = ALIGNED_TEXT_YPOS(rect);
1229 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1230 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1231 (x >= rect_x && x < rect_x + rect->width &&
1232 y >= rect_y && y < rect_y + rect->height));
1235 return (x >= rect_x && x < rect_x + rect->width &&
1236 y >= rect_y && y < rect_y + rect->height);
1239 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1241 int rect_width = preview->xsize * preview->tile_size;
1242 int rect_height = preview->ysize * preview->tile_size;
1243 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1244 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1246 return (x >= rect_x && x < rect_x + rect_width &&
1247 y >= rect_y && y < rect_y + rect_height);
1250 static void AdjustScrollbar(int id, int items_max, int items_visible,
1253 struct GadgetInfo *gi = screen_gadget[id];
1255 if (item_position > items_max - items_visible)
1256 item_position = items_max - items_visible;
1258 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1259 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1260 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1263 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1265 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1269 static void clearMenuListArea()
1271 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1273 /* correct scrollbar position if placed outside menu (playfield) area */
1274 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1275 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1277 /* clear menu list area, but not title or scrollbar */
1278 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1279 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1282 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1284 static int cursor_array[MAX_LEV_FIELDY];
1285 int x = mSX + TILEX * xpos;
1286 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1291 cursor_array[ypos] = graphic;
1293 graphic = cursor_array[ypos];
1297 graphic = BUTTON_ACTIVE(graphic);
1299 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1300 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1303 static void initCursor(int ypos, int graphic)
1305 drawCursorExt(0, ypos, FALSE, graphic);
1308 static void drawCursor(int ypos, boolean active)
1310 drawCursorExt(0, ypos, active, -1);
1313 static void drawCursorXY(int xpos, int ypos, int graphic)
1315 drawCursorExt(xpos, ypos, FALSE, graphic);
1318 static void drawChooseTreeCursor(int ypos, boolean active)
1320 drawCursorExt(0, ypos, active, -1);
1325 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1326 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1327 setup.internal.program_copyright);
1330 void DrawTitleScreenImage(int nr, boolean initial)
1332 int graphic = getTitleScreenGraphic(nr, initial);
1333 Bitmap *bitmap = graphic_info[graphic].bitmap;
1334 int width = graphic_info[graphic].width;
1335 int height = graphic_info[graphic].height;
1336 int src_x = graphic_info[graphic].src_x;
1337 int src_y = graphic_info[graphic].src_y;
1343 if (width > WIN_XSIZE)
1345 /* image width too large for window => center image horizontally */
1346 src_x = (width - WIN_XSIZE) / 2;
1350 if (height > WIN_YSIZE)
1352 /* image height too large for window => center image vertically */
1353 src_y = (height - WIN_YSIZE) / 2;
1357 /* always display title screens centered */
1358 dst_x = (WIN_XSIZE - width) / 2;
1359 dst_y = (WIN_YSIZE - height) / 2;
1361 SetDrawBackgroundMask(REDRAW_ALL);
1362 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1364 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1366 if (DrawingOnBackground(dst_x, dst_y))
1367 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1369 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1371 redraw_mask = REDRAW_ALL;
1374 void DrawTitleScreenMessage(int nr, boolean initial)
1376 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1377 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1379 if (filename == NULL)
1382 /* force TITLE font on title message screen */
1383 SetFontStatus(getTitleMessageGameMode(initial));
1385 /* if chars *and* width set to "-1", automatically determine width */
1386 if (tmi->chars == -1 && tmi->width == -1)
1387 tmi->width = viewport.window[game_status].width;
1389 /* if lines *and* height set to "-1", automatically determine height */
1390 if (tmi->lines == -1 && tmi->height == -1)
1391 tmi->height = viewport.window[game_status].height;
1393 /* if chars set to "-1", automatically determine by text and font width */
1394 if (tmi->chars == -1)
1395 tmi->chars = tmi->width / getFontWidth(tmi->font);
1397 tmi->width = tmi->chars * getFontWidth(tmi->font);
1399 /* if lines set to "-1", automatically determine by text and font height */
1400 if (tmi->lines == -1)
1401 tmi->lines = tmi->height / getFontHeight(tmi->font);
1403 tmi->height = tmi->lines * getFontHeight(tmi->font);
1405 /* if x set to "-1", automatically determine by width and alignment */
1407 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1409 /* if y set to "-1", automatically determine by height and alignment */
1411 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1413 SetDrawBackgroundMask(REDRAW_ALL);
1414 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1416 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1418 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1419 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1420 tmi->autowrap, tmi->centered, tmi->parse_comments);
1425 void DrawTitleScreen()
1427 KeyboardAutoRepeatOff();
1429 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1432 boolean CheckTitleScreen(boolean levelset_has_changed)
1434 static boolean show_title_initial = TRUE;
1435 boolean show_titlescreen = FALSE;
1437 /* needed to be able to skip title screen, if no image or message defined */
1438 InitializeTitleControls(show_title_initial);
1440 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1441 show_titlescreen = TRUE;
1443 /* show initial title images and messages only once at program start */
1444 show_title_initial = FALSE;
1446 return (show_titlescreen && num_title_screens > 0);
1451 static LevelDirTree *leveldir_last_valid = NULL;
1452 boolean levelset_has_changed = FALSE;
1453 int fade_mask = REDRAW_FIELD;
1455 LimitScreenUpdates(FALSE);
1457 FadeSetLeaveScreen();
1459 /* do not fade out here -- function may continue and fade on editor screen */
1462 FadeMenuSoundsAndMusic();
1464 ExpireSoundLoops(FALSE);
1466 KeyboardAutoRepeatOn();
1468 audio.sound_deactivated = FALSE;
1472 /* needed if last screen was the playing screen, invoked from level editor */
1473 if (level_editor_test_game)
1475 CloseDoor(DOOR_CLOSE_ALL);
1477 SetGameStatus(GAME_MODE_EDITOR);
1484 /* needed if last screen was the setup screen and fullscreen state changed */
1485 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1486 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1488 /* leveldir_current may be invalid (level group, parent link) */
1489 if (!validLevelSeries(leveldir_current))
1490 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1492 if (leveldir_current != leveldir_last_valid)
1493 levelset_has_changed = TRUE;
1495 /* store valid level series information */
1496 leveldir_last_valid = leveldir_current;
1498 init_last = init; /* switch to new busy animation */
1500 /* needed if last screen (level choice) changed graphics, sounds or music */
1501 ReloadCustomArtwork(0);
1503 if (CheckTitleScreen(levelset_has_changed))
1505 SetGameStatus(GAME_MODE_TITLE);
1512 if (redraw_mask & REDRAW_ALL)
1513 fade_mask = REDRAW_ALL;
1515 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1516 fade_mask = REDRAW_ALL;
1520 /* needed if different viewport properties defined for menues */
1521 ChangeViewportPropertiesIfNeeded();
1523 SetDrawtoField(DRAW_TO_BACKBUFFER);
1525 /* level_nr may have been set to value over handicap with level editor */
1526 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1527 level_nr = leveldir_current->handicap_level;
1529 LoadLevel(level_nr);
1530 LoadScore(level_nr);
1532 SaveLevelSetup_SeriesInfo();
1534 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1535 SetDrawDeactivationMask(REDRAW_NONE);
1536 SetDrawBackgroundMask(REDRAW_FIELD);
1538 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1541 if (fade_mask == REDRAW_ALL)
1542 RedrawGlobalBorder();
1547 InitializeMainControls();
1549 DrawCursorAndText_Main(-1, FALSE, FALSE);
1550 DrawPreviewLevelInitial();
1552 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1555 if (TAPE_IS_EMPTY(tape))
1557 DrawCompleteVideoDisplay();
1559 PlayMenuSoundsAndMusic();
1561 /* create gadgets for main menu screen */
1562 FreeScreenGadgets();
1563 CreateScreenGadgets();
1565 /* map gadgets for main menu screen */
1567 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1569 /* copy actual game door content to door double buffer for OpenDoor() */
1570 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1571 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1573 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1575 DrawMaskedBorder(fade_mask);
1580 /* update screen area with special editor door */
1581 redraw_mask |= REDRAW_ALL;
1584 SetMouseCursor(CURSOR_DEFAULT);
1586 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1589 static void gotoTopLevelDir()
1591 /* move upwards until inside (but not above) top level directory */
1592 while (leveldir_current->node_parent &&
1593 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1595 /* write a "path" into level tree for easy navigation to last level */
1596 if (leveldir_current->node_parent->node_group->cl_first == -1)
1598 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1599 int leveldir_pos = posTreeInfo(leveldir_current);
1600 int num_page_entries;
1601 int cl_first, cl_cursor;
1603 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1604 num_page_entries = num_leveldirs;
1606 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1608 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1609 cl_cursor = leveldir_pos - cl_first;
1611 leveldir_current->node_parent->node_group->cl_first = cl_first;
1612 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1615 leveldir_current = leveldir_current->node_parent;
1619 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1621 static unsigned int title_delay = 0;
1622 static int title_screen_nr = 0;
1623 static int last_sound = -1, last_music = -1;
1624 boolean return_to_main_menu = FALSE;
1625 struct TitleControlInfo *tci;
1628 if (button == MB_MENU_INITIALIZE)
1631 title_screen_nr = 0;
1632 tci = &title_controls[title_screen_nr];
1634 SetAnimStatus(getTitleAnimMode(tci));
1636 last_sound = SND_UNDEFINED;
1637 last_music = MUS_UNDEFINED;
1639 if (num_title_screens != 0)
1641 FadeSetEnterScreen();
1643 /* use individual title fading instead of global "enter screen" fading */
1644 fading = getTitleFading(tci);
1647 if (game_status_last_screen == GAME_MODE_INFO)
1649 if (num_title_screens == 0)
1651 /* switch game mode from title screen mode back to info screen mode */
1652 SetGameStatus(GAME_MODE_INFO);
1654 /* store that last screen was info screen, not main menu screen */
1655 game_status_last_screen = GAME_MODE_INFO;
1657 DrawInfoScreen_NotAvailable("Title screen information:",
1658 "No title screen for this level set.");
1662 FadeMenuSoundsAndMusic();
1665 FadeOut(REDRAW_ALL);
1667 /* title screens may have different window size */
1668 ChangeViewportPropertiesIfNeeded();
1670 /* only required to update logic for redrawing global border */
1674 DrawTitleScreenImage(tci->local_nr, tci->initial);
1676 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1678 sound = getTitleSound(tci);
1679 music = getTitleMusic(tci);
1681 if (sound != last_sound)
1682 PlayMenuSoundExt(sound);
1683 if (music != last_music)
1684 PlayMenuMusicExt(music);
1689 SetMouseCursor(CURSOR_NONE);
1693 DelayReached(&title_delay, 0); /* reset delay counter */
1698 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1699 button = MB_MENU_CHOICE;
1701 if (button == MB_MENU_LEAVE)
1703 return_to_main_menu = TRUE;
1705 else if (button == MB_MENU_CHOICE)
1707 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1709 SetGameStatus(GAME_MODE_INFO);
1711 info_mode = INFO_MODE_MAIN;
1720 if (title_screen_nr < num_title_screens)
1722 tci = &title_controls[title_screen_nr];
1724 SetAnimStatus(getTitleAnimMode(tci));
1726 sound = getTitleSound(tci);
1727 music = getTitleMusic(tci);
1729 if (last_sound != SND_UNDEFINED && sound != last_sound)
1730 FadeSound(last_sound);
1731 if (last_music != MUS_UNDEFINED && music != last_music)
1734 fading = getTitleFading(tci);
1736 FadeOut(REDRAW_ALL);
1739 DrawTitleScreenImage(tci->local_nr, tci->initial);
1741 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1743 sound = getTitleSound(tci);
1744 music = getTitleMusic(tci);
1746 if (sound != last_sound)
1747 PlayMenuSoundExt(sound);
1748 if (music != last_music)
1749 PlayMenuMusicExt(music);
1756 DelayReached(&title_delay, 0); /* reset delay counter */
1760 FadeMenuSoundsAndMusic();
1762 return_to_main_menu = TRUE;
1766 if (return_to_main_menu)
1768 SetMouseCursor(CURSOR_DEFAULT);
1770 /* force full menu screen redraw after displaying title screens */
1771 redraw_mask = REDRAW_ALL;
1773 if (game_status_last_screen == GAME_MODE_INFO)
1775 SetGameStatus(GAME_MODE_INFO);
1777 info_mode = INFO_MODE_MAIN;
1781 else /* default: return to main menu */
1783 SetGameStatus(GAME_MODE_MAIN);
1790 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1792 int old_level_nr = level_nr;
1795 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1796 new_level_nr = selected_level_nr;
1798 new_level_nr = old_level_nr + step * direction;
1800 if (new_level_nr < leveldir_current->first_level)
1801 new_level_nr = leveldir_current->first_level;
1802 if (new_level_nr > leveldir_current->last_level)
1803 new_level_nr = leveldir_current->last_level;
1805 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1807 /* skipping levels is only allowed when trying to skip single level */
1808 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1809 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1811 leveldir_current->handicap_level++;
1812 SaveLevelSetup_SeriesInfo();
1815 new_level_nr = leveldir_current->handicap_level;
1818 if (new_level_nr != old_level_nr)
1820 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1822 PlaySound(SND_MENU_ITEM_SELECTING);
1824 level_nr = new_level_nr;
1826 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1827 int2str(level_nr, menu.main.text.level_number.size),
1828 mci->pos_text->font);
1830 LoadLevel(level_nr);
1831 DrawPreviewLevelInitial();
1835 DrawCompleteVideoDisplay();
1837 SaveLevelSetup_SeriesInfo();
1839 /* needed because DrawPreviewLevelInitial() takes some time */
1841 /* SyncDisplay(); */
1845 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1847 static int choice = MAIN_CONTROL_GAME;
1848 static boolean button_pressed_last = FALSE;
1849 boolean button_pressed = FALSE;
1853 if (button == MB_MENU_INITIALIZE)
1855 DrawCursorAndText_Main(choice, TRUE, FALSE);
1860 if (mx || my) /* mouse input */
1864 for (i = 0; main_controls[i].nr != -1; i++)
1866 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1867 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1868 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1870 pos = main_controls[i].nr;
1876 /* check if level preview was clicked */
1877 if (insidePreviewRect(&preview, mx - SX, my - SY))
1878 pos = MAIN_CONTROL_GAME;
1880 // handle pressed/unpressed state for active/inactive menu buttons
1881 // (if pos != -1, "i" contains index position corresponding to "pos")
1883 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1884 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1885 button_pressed = TRUE;
1887 if (button_pressed != button_pressed_last)
1889 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1892 PlaySound(SND_MENU_BUTTON_PRESSING);
1894 PlaySound(SND_MENU_BUTTON_RELEASING);
1897 else if (dx || dy) /* keyboard input */
1899 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1900 choice == MAIN_CONTROL_SETUP))
1901 button = MB_MENU_CHOICE;
1906 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1908 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1910 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1912 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1914 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1916 CloseDoor(DOOR_CLOSE_2);
1918 SetGameStatus(GAME_MODE_LEVELNR);
1920 DrawChooseLevelNr();
1922 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1928 PlaySound(SND_MENU_ITEM_ACTIVATING);
1930 DrawCursorAndText_Main(choice, FALSE, FALSE);
1931 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1937 if (choice != MAIN_CONTROL_INFO &&
1938 choice != MAIN_CONTROL_SETUP)
1939 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
1944 PlaySound(SND_MENU_ITEM_SELECTING);
1946 if (pos == MAIN_CONTROL_NAME)
1948 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1950 HandleTypeName(strlen(setup.player_name), 0);
1952 else if (pos == MAIN_CONTROL_LEVELS)
1956 CloseDoor(DOOR_CLOSE_2);
1958 SetGameStatus(GAME_MODE_LEVELS);
1960 SaveLevelSetup_LastSeries();
1961 SaveLevelSetup_SeriesInfo();
1963 if (setup.internal.choose_from_top_leveldir)
1966 DrawChooseLevelSet();
1969 else if (pos == MAIN_CONTROL_SCORES)
1971 CloseDoor(DOOR_CLOSE_2);
1973 SetGameStatus(GAME_MODE_SCORES);
1977 else if (pos == MAIN_CONTROL_EDITOR)
1979 if (leveldir_current->readonly &&
1980 !strEqual(setup.player_name, "Artsoft"))
1981 Request("This level is read only!", REQ_CONFIRM);
1983 CloseDoor(DOOR_CLOSE_2);
1985 SetGameStatus(GAME_MODE_EDITOR);
1987 FadeSetEnterScreen();
1991 else if (pos == MAIN_CONTROL_INFO)
1993 CloseDoor(DOOR_CLOSE_2);
1995 SetGameStatus(GAME_MODE_INFO);
1997 info_mode = INFO_MODE_MAIN;
2001 else if (pos == MAIN_CONTROL_GAME)
2003 StartGameActions(options.network, setup.autorecord, level.random_seed);
2005 else if (pos == MAIN_CONTROL_SETUP)
2007 CloseDoor(DOOR_CLOSE_2);
2009 SetGameStatus(GAME_MODE_SETUP);
2011 setup_mode = SETUP_MODE_MAIN;
2015 else if (pos == MAIN_CONTROL_QUIT)
2017 SaveLevelSetup_LastSeries();
2018 SaveLevelSetup_SeriesInfo();
2020 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2021 SetGameStatus(GAME_MODE_QUIT);
2026 button_pressed_last = button_pressed;
2030 /* ========================================================================= */
2031 /* info screen functions */
2032 /* ========================================================================= */
2034 static struct TokenInfo *info_info;
2035 static int num_info_info; /* number of info entries shown on screen */
2036 static int max_info_info; /* total number of info entries in list */
2038 static void execInfoTitleScreen()
2040 info_mode = INFO_MODE_TITLE;
2045 static void execInfoElements()
2047 info_mode = INFO_MODE_ELEMENTS;
2052 static void execInfoMusic()
2054 info_mode = INFO_MODE_MUSIC;
2059 static void execInfoCredits()
2061 info_mode = INFO_MODE_CREDITS;
2066 static void execInfoProgram()
2068 info_mode = INFO_MODE_PROGRAM;
2073 static void execInfoVersion()
2075 info_mode = INFO_MODE_VERSION;
2080 static void execInfoLevelSet()
2082 info_mode = INFO_MODE_LEVELSET;
2087 static void execExitInfo()
2089 SetGameStatus(GAME_MODE_MAIN);
2094 static struct TokenInfo info_info_main[] =
2096 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2097 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2098 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2099 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2100 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2101 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2102 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2103 { TYPE_EMPTY, NULL, "" },
2104 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2109 static int getMenuTextFont(int type)
2111 if (type & (TYPE_SWITCH |
2123 static struct TokenInfo *setup_info;
2124 static struct TokenInfo setup_info_input[];
2126 static struct TokenInfo *menu_info;
2128 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2129 int screen_pos, int menu_info_pos_raw,
2132 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2133 struct TokenInfo *ti = &token_info[pos];
2134 int xpos = MENU_SCREEN_START_XPOS;
2135 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2136 int font_nr = getMenuTextFont(ti->type);
2138 if (token_info == setup_info_input)
2139 font_nr = FONT_MENU_1;
2142 font_nr = FONT_ACTIVE(font_nr);
2144 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2146 if (ti->type & ~TYPE_SKIP_ENTRY)
2147 drawCursor(screen_pos, active);
2150 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2153 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2156 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2159 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2162 static char *window_size_text;
2163 static char *scaling_type_text;
2165 static void drawSetupValue(int, int);
2167 static void drawMenuInfoList(int first_entry, int num_page_entries,
2168 int max_page_entries)
2172 if (first_entry + num_page_entries > max_page_entries)
2175 clearMenuListArea();
2177 for (i = 0; i < num_page_entries; i++)
2179 int menu_info_pos = first_entry + i;
2180 struct TokenInfo *si = &menu_info[menu_info_pos];
2181 void *value_ptr = si->value;
2183 /* set some entries to "unchangeable" according to other variables */
2184 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2185 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2186 (value_ptr == &setup.sound_music && !audio.music_available) ||
2187 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2188 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2189 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2190 si->type |= TYPE_GHOSTED;
2192 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2193 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2194 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2195 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2196 else if (si->type & ~TYPE_SKIP_ENTRY)
2197 initCursor(i, IMG_MENU_BUTTON);
2199 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2201 if (si->type & TYPE_VALUE &&
2202 menu_info == setup_info)
2203 drawSetupValue(i, menu_info_pos);
2207 static void DrawInfoScreen_Main()
2209 int fade_mask = REDRAW_FIELD;
2212 if (redraw_mask & REDRAW_ALL)
2213 fade_mask = REDRAW_ALL;
2215 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2216 fade_mask = REDRAW_ALL;
2219 FadeMenuSoundsAndMusic();
2221 FreeScreenGadgets();
2222 CreateScreenGadgets();
2224 /* (needed after displaying title screens which disable auto repeat) */
2225 KeyboardAutoRepeatOn();
2227 FadeSetLeaveScreen();
2231 /* needed if different viewport properties defined for info screen */
2232 ChangeViewportPropertiesIfNeeded();
2234 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2238 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2240 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2242 info_info = info_info_main;
2244 // determine maximal number of info entries that can be displayed on screen
2246 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2249 // determine maximal number of info entries available for menu of info screen
2251 for (i = 0; info_info[i].type != 0; i++)
2254 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2256 MapScreenGadgets(max_info_info);
2258 PlayMenuSoundsAndMusic();
2260 DrawMaskedBorder(fade_mask);
2265 static void changeSetupValue(int, int, int);
2267 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2268 int mode, int num_page_entries, int max_page_entries)
2270 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2271 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2272 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2273 int *num_page_entries_last = num_page_entries_all_last[game_status];
2274 int *choice_store = choice_stores[game_status];
2275 int *first_entry_store = first_entry_stores[game_status];
2276 int choice = choice_store[mode]; /* starts with 0 */
2277 int first_entry = first_entry_store[mode]; /* starts with 0 */
2279 int y = choice - first_entry;
2281 boolean position_set_by_scrollbar = (dx == 999);
2282 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2285 if (button == MB_MENU_INITIALIZE)
2287 // check if number of menu page entries has changed (may happen by change
2288 // of custom artwork definition value for 'list_size' for this menu screen)
2289 // (in this case, the last menu position most probably has to be corrected)
2290 if (num_page_entries != num_page_entries_last[mode])
2292 choice_store[mode] = first_entry_store[mode] = 0;
2294 choice = first_entry = 0;
2297 num_page_entries_last[mode] = num_page_entries;
2300 /* advance to first valid menu entry */
2301 while (choice < num_page_entries &&
2302 menu_info[choice].type & TYPE_SKIP_ENTRY)
2305 if (position_set_by_scrollbar)
2306 first_entry = first_entry_store[mode] = dy;
2308 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2309 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2311 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2313 if (choice < first_entry)
2315 choice = first_entry;
2317 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2320 else if (choice > first_entry + num_page_entries - 1)
2322 choice = first_entry + num_page_entries - 1;
2324 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2328 choice_store[mode] = choice;
2330 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2334 else if (button == MB_MENU_LEAVE)
2336 PlaySound(SND_MENU_ITEM_SELECTING);
2338 for (i = 0; i < max_page_entries; i++)
2340 if (menu_info[i].type & TYPE_LEAVE_MENU)
2342 void (*menu_callback_function)(void) = menu_info[i].value;
2346 menu_callback_function();
2348 break; /* absolutely needed because function changes 'menu_info'! */
2355 if (mx || my) /* mouse input */
2357 x = (mx - mSX) / 32;
2358 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2360 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2362 /* move cursor instead of scrolling when already at start/end of list */
2363 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2365 else if (dy == +1 * SCROLL_LINE &&
2366 first_entry + num_page_entries == max_page_entries)
2369 /* handle scrolling screen one line or page */
2371 y + dy > num_page_entries - 1)
2373 boolean redraw = FALSE;
2375 if (ABS(dy) == SCROLL_PAGE)
2376 step = num_page_entries - 1;
2378 if (dy < 0 && first_entry > 0)
2380 /* scroll page/line up */
2382 first_entry -= step;
2383 if (first_entry < 0)
2388 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2390 /* scroll page/line down */
2392 first_entry += step;
2393 if (first_entry + num_page_entries > max_page_entries)
2394 first_entry = MAX(0, max_page_entries - num_page_entries);
2401 choice += first_entry - first_entry_store[mode];
2403 if (choice < first_entry)
2405 choice = first_entry;
2407 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2410 else if (choice > first_entry + num_page_entries - 1)
2412 choice = first_entry + num_page_entries - 1;
2414 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2417 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2421 if (choice < first_entry ||
2422 choice > first_entry + num_page_entries - 1)
2423 first_entry += SIGN(dy);
2426 first_entry_store[mode] = first_entry;
2427 choice_store[mode] = choice;
2429 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2431 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2433 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2434 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2442 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2444 if (menu_info[choice].type & menu_navigation_type ||
2445 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2446 menu_info[choice].type & TYPE_YES_NO_AUTO)
2447 button = MB_MENU_CHOICE;
2452 /* jump to next non-empty menu entry (up or down) */
2453 while (first_entry + y > 0 &&
2454 first_entry + y < max_page_entries - 1 &&
2455 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2458 if (!IN_VIS_MENU(x, y))
2460 choice += y - y_old;
2462 if (choice < first_entry)
2463 first_entry = choice;
2464 else if (choice > first_entry + num_page_entries - 1)
2465 first_entry = choice - num_page_entries + 1;
2467 if (first_entry >= 0 &&
2468 first_entry + num_page_entries <= max_page_entries)
2470 first_entry_store[mode] = first_entry;
2472 if (choice < first_entry)
2473 choice = first_entry;
2474 else if (choice > first_entry + num_page_entries - 1)
2475 choice = first_entry + num_page_entries - 1;
2477 choice_store[mode] = choice;
2479 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2481 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2483 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2484 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2491 if (!anyScrollbarGadgetActive() &&
2492 IN_VIS_MENU(x, y) &&
2493 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2494 y >= 0 && y < num_page_entries)
2498 if (first_entry + y != choice &&
2499 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2501 PlaySound(SND_MENU_ITEM_ACTIVATING);
2503 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2504 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2506 choice = choice_store[mode] = first_entry + y;
2510 PlaySound(SND_MENU_ITEM_SELECTING);
2512 for (i = 0; menu_info[i].type != 0; i++)
2514 if (menu_info[i].type & TYPE_LEAVE_MENU)
2516 void (*menu_callback_function)(void) = menu_info[i].value;
2520 menu_callback_function();
2522 /* absolutely needed because function changes 'menu_info'! */
2530 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2532 PlaySound(SND_MENU_ITEM_SELECTING);
2534 /* when selecting key headline, execute function for key value change */
2535 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2536 menu_info[first_entry + y + 1].type & TYPE_KEY)
2539 /* when selecting string value, execute function for list selection */
2540 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2541 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2544 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2546 void (*menu_callback_function)(void) =
2547 menu_info[first_entry + y].value;
2549 FadeSetFromType(menu_info[first_entry + y].type);
2551 menu_callback_function();
2553 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2554 menu_info == setup_info)
2556 changeSetupValue(y, first_entry + y, dx);
2562 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2564 menu_info = info_info;
2566 HandleMenuScreen(mx, my, dx, dy, button,
2567 info_mode, num_info_info, max_info_info);
2570 static int getMenuFontSpacing(int spacing_height, int font_nr)
2572 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2574 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2578 static int getMenuTextSpacing(int spacing_height, int font_nr)
2580 return (getMenuFontSpacing(spacing_height, font_nr) +
2581 EXTRA_SPACING(game_status));
2584 static int getMenuTextStep(int spacing_height, int font_nr)
2586 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2589 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2591 int font_title = MENU_INFO_FONT_TITLE;
2592 int font_error = FONT_TEXT_2;
2593 int font_foot = MENU_INFO_FONT_FOOT;
2594 int spacing_title = menu.headline1_spacing_info[info_mode];
2595 int ystep_title = getMenuTextStep(spacing_title, font_title);
2596 int ystart1 = mSY - SY + 100;
2597 int ystart2 = ystart1 + ystep_title;
2598 int ybottom = mSY - SY + SYSIZE - 20;
2600 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2602 FadeOut(REDRAW_FIELD);
2607 DrawTextSCentered(ystart1, font_title, text_title);
2608 DrawTextSCentered(ystart2, font_error, text_error);
2610 DrawTextSCentered(ybottom, font_foot,
2611 "Press any key or button for info menu");
2613 FadeIn(REDRAW_FIELD);
2616 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2618 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2619 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2620 int font_title = MENU_INFO_FONT_TITLE;
2621 int font_foot = MENU_INFO_FONT_FOOT;
2622 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2623 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2624 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2625 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2626 int ystep = MENU_SCREEN_INFO_YSTEP;
2627 int element, action, direction;
2635 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2636 infoscreen_step[i] = infoscreen_frame[i] = 0;
2641 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2643 DrawTextSCentered(ybottom, font_foot,
2644 "Press any key or button for next page");
2650 while (helpanim_info[j].element != HELPANIM_LIST_END)
2652 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2657 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2666 j += infoscreen_step[i - start];
2668 element = helpanim_info[j].element;
2669 action = helpanim_info[j].action;
2670 direction = helpanim_info[j].direction;
2673 element = EL_UNKNOWN;
2675 if (action != -1 && direction != -1)
2676 graphic = el_act_dir2img(element, action, direction);
2677 else if (action != -1)
2678 graphic = el_act2img(element, action);
2679 else if (direction != -1)
2680 graphic = el_dir2img(element, direction);
2682 graphic = el2img(element);
2684 delay = helpanim_info[j++].delay;
2689 if (infoscreen_frame[i - start] == 0)
2692 infoscreen_frame[i - start] = delay - 1;
2696 sync_frame = delay - infoscreen_frame[i - start];
2697 infoscreen_frame[i - start]--;
2700 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2702 if (!infoscreen_frame[i - start])
2703 infoscreen_step[i - start] = 0;
2707 if (!infoscreen_frame[i - start])
2708 infoscreen_step[i - start]++;
2709 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2715 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2717 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2718 graphic, sync_frame, USE_MASKING);
2721 DrawInfoScreen_HelpText(element, action, direction, i - start);
2726 redraw_mask |= REDRAW_FIELD;
2731 static char *getHelpText(int element, int action, int direction)
2733 char token[MAX_LINE_LEN];
2735 strcpy(token, element_info[element].token_name);
2738 strcat(token, element_action_info[action].suffix);
2740 if (direction != -1)
2741 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2743 return getHashEntry(helptext_info, token);
2746 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2748 int font_nr = FONT_INFO_ELEMENTS;
2749 int font_width = getFontWidth(font_nr);
2750 int font_height = getFontHeight(font_nr);
2751 int yoffset = (TILEX - 2 * font_height) / 2;
2752 int xstart = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2753 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2754 int ystep = TILEY + 4;
2755 int pad_x = xstart - SX;
2756 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2757 int max_lines_per_text = 2;
2760 if (action != -1 && direction != -1) /* element.action.direction */
2761 text = getHelpText(element, action, direction);
2763 if (text == NULL && action != -1) /* element.action */
2764 text = getHelpText(element, action, -1);
2766 if (text == NULL && direction != -1) /* element.direction */
2767 text = getHelpText(element, -1, direction);
2769 if (text == NULL) /* base element */
2770 text = getHelpText(element, -1, -1);
2772 if (text == NULL) /* not found */
2773 text = "No description available";
2775 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2776 ystart += getFontHeight(font_nr) / 2;
2778 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2779 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2780 TRUE, FALSE, FALSE);
2783 void DrawInfoScreen_TitleScreen()
2785 SetGameStatus(GAME_MODE_TITLE);
2790 void HandleInfoScreen_TitleScreen(int button)
2792 HandleTitleScreen(0, 0, 0, 0, button);
2795 void DrawInfoScreen_Elements()
2797 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2799 FadeOut(REDRAW_FIELD);
2804 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2806 FadeIn(REDRAW_FIELD);
2809 void HandleInfoScreen_Elements(int button)
2811 static unsigned int info_delay = 0;
2812 static int num_anims;
2813 static int num_pages;
2815 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2818 if (button == MB_MENU_INITIALIZE)
2820 boolean new_element = TRUE;
2824 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2826 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2828 else if (new_element)
2831 new_element = FALSE;
2835 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2839 if (button == MB_MENU_LEAVE)
2841 PlaySound(SND_MENU_ITEM_SELECTING);
2843 info_mode = INFO_MODE_MAIN;
2848 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2850 if (button != MB_MENU_INITIALIZE)
2852 PlaySound(SND_MENU_ITEM_SELECTING);
2857 if (page >= num_pages)
2859 FadeMenuSoundsAndMusic();
2861 info_mode = INFO_MODE_MAIN;
2868 FadeSetNextScreen();
2870 if (button != MB_MENU_INITIALIZE)
2871 FadeOut(REDRAW_FIELD);
2873 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2875 if (button != MB_MENU_INITIALIZE)
2876 FadeIn(REDRAW_FIELD);
2880 if (DelayReached(&info_delay, GameFrameDelay))
2881 if (page < num_pages)
2882 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2884 PlayMenuSoundIfLoop();
2888 void DrawInfoScreen_Music()
2890 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2892 FadeOut(REDRAW_FIELD);
2899 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2901 FadeIn(REDRAW_FIELD);
2904 void HandleInfoScreen_Music(int button)
2906 static struct MusicFileInfo *list = NULL;
2907 int font_title = MENU_INFO_FONT_TITLE;
2908 int font_head = MENU_INFO_FONT_HEAD;
2909 int font_text = MENU_INFO_FONT_TEXT;
2910 int font_foot = MENU_INFO_FONT_FOOT;
2911 int spacing_title = menu.headline1_spacing_info[info_mode];
2912 int spacing_head = menu.headline2_spacing_info[info_mode];
2913 int ystep_title = getMenuTextStep(spacing_title, font_title);
2914 int ystep_head = getMenuTextStep(spacing_head, font_head);
2915 int ystart = mSY - SY + 100;
2916 int ybottom = mSY - SY + SYSIZE - 20;
2918 if (button == MB_MENU_INITIALIZE)
2920 list = music_file_info;
2924 FadeMenuSoundsAndMusic();
2929 DrawTextSCentered(ystart, font_title,
2930 "No music info for this level set.");
2932 DrawTextSCentered(ybottom, font_foot,
2933 "Press any key or button for info menu");
2939 if (button == MB_MENU_LEAVE)
2941 PlaySound(SND_MENU_ITEM_SELECTING);
2943 FadeMenuSoundsAndMusic();
2945 info_mode = INFO_MODE_MAIN;
2950 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2952 if (button != MB_MENU_INITIALIZE)
2954 PlaySound(SND_MENU_ITEM_SELECTING);
2962 FadeMenuSoundsAndMusic();
2964 info_mode = INFO_MODE_MAIN;
2970 FadeMenuSoundsAndMusic();
2972 if (list != music_file_info)
2973 FadeSetNextScreen();
2975 if (button != MB_MENU_INITIALIZE)
2976 FadeOut(REDRAW_FIELD);
2983 int sound = list->music;
2985 if (sound_info[sound].loop)
2986 PlaySoundLoop(sound);
2990 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
2994 PlayMusic(list->music);
2996 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
2999 ystart += ystep_title;
3001 if (!strEqual(list->title, UNKNOWN_NAME))
3003 if (!strEqual(list->title_header, UNKNOWN_NAME))
3005 DrawTextSCentered(ystart, font_head, list->title_header);
3006 ystart += ystep_head;
3009 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3010 ystart += ystep_head;
3013 if (!strEqual(list->artist, UNKNOWN_NAME))
3015 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3016 DrawTextSCentered(ystart, font_head, list->artist_header);
3018 DrawTextSCentered(ystart, font_head, "by");
3020 ystart += ystep_head;
3022 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3023 ystart += ystep_head;
3026 if (!strEqual(list->album, UNKNOWN_NAME))
3028 if (!strEqual(list->album_header, UNKNOWN_NAME))
3029 DrawTextSCentered(ystart, font_head, list->album_header);
3031 DrawTextSCentered(ystart, font_head, "from the album");
3033 ystart += ystep_head;
3035 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3036 ystart += ystep_head;
3039 if (!strEqual(list->year, UNKNOWN_NAME))
3041 if (!strEqual(list->year_header, UNKNOWN_NAME))
3042 DrawTextSCentered(ystart, font_head, list->year_header);
3044 DrawTextSCentered(ystart, font_head, "from the year");
3046 ystart += ystep_head;
3048 DrawTextFCentered(ystart, font_text, "%s", list->year);
3049 ystart += ystep_head;
3052 DrawTextSCentered(ybottom, FONT_TEXT_4,
3053 "Press any key or button for next page");
3055 if (button != MB_MENU_INITIALIZE)
3056 FadeIn(REDRAW_FIELD);
3059 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3060 PlaySoundLoop(list->music);
3063 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3065 int font_title = MENU_INFO_FONT_TITLE;
3066 int font_head = MENU_INFO_FONT_HEAD;
3067 int font_text = MENU_INFO_FONT_TEXT;
3068 int font_foot = MENU_INFO_FONT_FOOT;
3069 int spacing_title = menu.headline1_spacing_info[info_mode];
3070 int spacing_head = menu.headline2_spacing_info[info_mode];
3071 int spacing_para = menu.paragraph_spacing_info[info_mode];
3072 int spacing_line = menu.line_spacing_info[info_mode];
3073 int ystep_title = getMenuTextStep(spacing_title, font_title);
3074 int ystep_head = getMenuTextStep(spacing_head, font_head);
3075 int ystep_para = getMenuTextStep(spacing_para, font_text);
3076 int ystep_line = getMenuTextStep(spacing_line, font_text);
3077 int ystart = mSY - SY + 100;
3078 int ybottom = mSY - SY + SYSIZE - 20;
3083 DrawTextSCentered(ystart, font_title, "Credits:");
3084 ystart += ystep_title;
3088 DrawTextSCentered(ystart, font_head,
3089 "Special thanks to");
3090 ystart += ystep_head;
3091 DrawTextSCentered(ystart, font_text,
3093 ystart += ystep_head;
3094 DrawTextSCentered(ystart, font_head,
3096 ystart += ystep_head;
3097 DrawTextSCentered(ystart, font_text,
3098 "\"Boulder Dash\"");
3099 ystart += ystep_head;
3100 DrawTextSCentered(ystart, font_head,
3102 ystart += ystep_head;
3103 DrawTextSCentered(ystart, font_text,
3105 ystart += ystep_head;
3106 DrawTextSCentered(ystart, font_head,
3108 ystart += ystep_head;
3109 DrawTextSCentered(ystart, font_text,
3110 "First Star Software");
3112 else if (screen_nr == 1)
3114 DrawTextSCentered(ystart, font_head,
3115 "Special thanks to");
3116 ystart += ystep_head;
3117 DrawTextSCentered(ystart, font_text,
3118 "Klaus Heinz & Volker Wertich");
3119 ystart += ystep_head;
3120 DrawTextSCentered(ystart, font_head,
3122 ystart += ystep_head;
3123 DrawTextSCentered(ystart, font_text,
3124 "\"Emerald Mine\"");
3125 ystart += ystep_head;
3126 DrawTextSCentered(ystart, font_head,
3128 ystart += ystep_head;
3129 DrawTextSCentered(ystart, font_text,
3131 ystart += ystep_head;
3132 DrawTextSCentered(ystart, font_head,
3134 ystart += ystep_head;
3135 DrawTextSCentered(ystart, font_text,
3138 else if (screen_nr == 2)
3140 DrawTextSCentered(ystart, font_head,
3141 "Special thanks to");
3142 ystart += ystep_head;
3143 DrawTextSCentered(ystart, font_text,
3144 "Michael Stopp & Philip Jespersen");
3145 ystart += ystep_head;
3146 DrawTextSCentered(ystart, font_head,
3148 ystart += ystep_head;
3149 DrawTextSCentered(ystart, font_text,
3151 ystart += ystep_head;
3152 DrawTextSCentered(ystart, font_head,
3154 ystart += ystep_head;
3155 DrawTextSCentered(ystart, font_text,
3157 ystart += ystep_head;
3158 DrawTextSCentered(ystart, font_head,
3160 ystart += ystep_head;
3161 DrawTextSCentered(ystart, font_text,
3162 "Digital Integration");
3164 else if (screen_nr == 3)
3166 DrawTextSCentered(ystart, font_head,
3167 "Special thanks to");
3168 ystart += ystep_head;
3169 DrawTextSCentered(ystart, font_text,
3170 "Hiroyuki Imabayashi");
3171 ystart += ystep_head;
3172 DrawTextSCentered(ystart, font_head,
3174 ystart += ystep_head;
3175 DrawTextSCentered(ystart, font_text,
3177 ystart += ystep_head;
3178 DrawTextSCentered(ystart, font_head,
3180 ystart += ystep_head;
3181 DrawTextSCentered(ystart, font_text,
3183 ystart += ystep_head;
3184 DrawTextSCentered(ystart, font_head,
3186 ystart += ystep_head;
3187 DrawTextSCentered(ystart, font_text,
3190 else if (screen_nr == 4)
3192 DrawTextSCentered(ystart, font_head,
3193 "Special thanks to");
3194 ystart += ystep_head;
3195 DrawTextSCentered(ystart, font_text,
3197 ystart += ystep_head;
3198 DrawTextSCentered(ystart, font_head,
3200 ystart += ystep_head;
3201 DrawTextSCentered(ystart, font_text,
3202 "J\xfcrgen Bonhagen");
3203 ystart += ystep_head;
3204 DrawTextSCentered(ystart, font_head,
3205 "for the continuous creation");
3206 ystart += ystep_line;
3207 DrawTextSCentered(ystart, font_head,
3208 "of outstanding level sets");
3210 else if (screen_nr == 5)
3212 DrawTextSCentered(ystart, font_head,
3214 ystart += ystep_head;
3215 DrawTextSCentered(ystart, font_text,
3217 ystart += ystep_head;
3218 DrawTextSCentered(ystart, font_head,
3219 "for ideas and inspiration by");
3220 ystart += ystep_head;
3221 DrawTextSCentered(ystart, font_text,
3223 ystart += ystep_para;
3225 DrawTextSCentered(ystart, font_head,
3227 ystart += ystep_head;
3228 DrawTextSCentered(ystart, font_text,
3230 ystart += ystep_head;
3231 DrawTextSCentered(ystart, font_head,
3232 "for ideas and inspiration by");
3233 ystart += ystep_head;
3234 DrawTextSCentered(ystart, font_text,
3237 else if (screen_nr == 6)
3239 DrawTextSCentered(ystart, font_head,
3241 ystart += ystep_head;
3242 DrawTextSCentered(ystart, font_text,
3244 ystart += ystep_head;
3245 DrawTextSCentered(ystart, font_head,
3246 "for the code base used for the");
3247 ystart += ystep_line;
3248 DrawTextSCentered(ystart, font_head,
3249 "native Emerald Mine engine");
3251 else if (screen_nr == 7)
3253 DrawTextSCentered(ystart, font_head,
3255 ystart += ystep_head;
3256 DrawTextSCentered(ystart, font_text,
3258 ystart += ystep_head;
3259 DrawTextSCentered(ystart, font_head,
3260 "for the initial DOS port");
3261 ystart += ystep_para;
3263 DrawTextSCentered(ystart, font_head,
3265 ystart += ystep_head;
3266 DrawTextSCentered(ystart, font_text,
3268 ystart += ystep_head;
3269 DrawTextSCentered(ystart, font_head,
3270 "for some additional toons");
3272 else if (screen_nr == 8)
3274 DrawTextSCentered(ystart, font_head,
3275 "And not to forget:");
3276 ystart += ystep_head;
3277 DrawTextSCentered(ystart, font_head,
3279 ystart += ystep_head;
3280 DrawTextSCentered(ystart, font_text,
3281 "All those who contributed");
3282 ystart += ystep_line;
3283 DrawTextSCentered(ystart, font_text,
3284 "levels to this game");
3285 ystart += ystep_line;
3286 DrawTextSCentered(ystart, font_text,
3290 DrawTextSCentered(ybottom, font_foot,
3291 "Press any key or button for next page");
3294 void DrawInfoScreen_Credits()
3296 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3298 FadeMenuSoundsAndMusic();
3300 FadeOut(REDRAW_FIELD);
3302 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3304 FadeIn(REDRAW_FIELD);
3307 void HandleInfoScreen_Credits(int button)
3309 static int screen_nr = 0;
3310 int num_screens = 9;
3312 if (button == MB_MENU_INITIALIZE)
3316 // DrawInfoScreen_CreditsScreen(screen_nr);
3319 if (button == MB_MENU_LEAVE)
3321 PlaySound(SND_MENU_ITEM_SELECTING);
3323 info_mode = INFO_MODE_MAIN;
3328 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3330 if (button != MB_MENU_INITIALIZE)
3332 PlaySound(SND_MENU_ITEM_SELECTING);
3337 if (screen_nr >= num_screens)
3339 FadeMenuSoundsAndMusic();
3341 info_mode = INFO_MODE_MAIN;
3348 FadeSetNextScreen();
3350 if (button != MB_MENU_INITIALIZE)
3351 FadeOut(REDRAW_FIELD);
3353 DrawInfoScreen_CreditsScreen(screen_nr);
3355 if (button != MB_MENU_INITIALIZE)
3356 FadeIn(REDRAW_FIELD);
3360 PlayMenuSoundIfLoop();
3364 void DrawInfoScreen_Program()
3366 int font_title = MENU_INFO_FONT_TITLE;
3367 int font_head = MENU_INFO_FONT_HEAD;
3368 int font_text = MENU_INFO_FONT_TEXT;
3369 int font_foot = MENU_INFO_FONT_FOOT;
3370 int spacing_title = menu.headline1_spacing_info[info_mode];
3371 int spacing_head = menu.headline2_spacing_info[info_mode];
3372 int spacing_para = menu.paragraph_spacing_info[info_mode];
3373 int spacing_line = menu.line_spacing_info[info_mode];
3374 int ystep_title = getMenuTextStep(spacing_title, font_title);
3375 int ystep_head = getMenuTextStep(spacing_head, font_head);
3376 int ystep_para = getMenuTextStep(spacing_para, font_text);
3377 int ystep_line = getMenuTextStep(spacing_line, font_text);
3378 int ystart = mSY - SY + 100;
3379 int ybottom = mSY - SY + SYSIZE - 20;
3381 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3383 FadeOut(REDRAW_FIELD);
3388 DrawTextSCentered(ystart, font_title, "Program Information:");
3389 ystart += ystep_title;
3391 DrawTextSCentered(ystart, font_head,
3392 "This game is Freeware!");
3393 ystart += ystep_head;
3394 DrawTextSCentered(ystart, font_head,
3395 "If you like it, send e-mail to:");
3396 ystart += ystep_head;
3397 DrawTextSCentered(ystart, font_text,
3398 setup.internal.program_email);
3399 ystart += ystep_para;
3401 DrawTextSCentered(ystart, font_head,
3402 "More information and levels:");
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_text,
3405 setup.internal.program_website);
3406 ystart += ystep_para;
3408 DrawTextSCentered(ystart, font_head,
3409 "If you have created new levels,");
3410 ystart += ystep_line;
3411 DrawTextSCentered(ystart, font_head,
3412 "send them to me to include them!");
3413 ystart += ystep_head;
3414 DrawTextSCentered(ystart, font_head,
3417 DrawTextSCentered(ybottom, font_foot,
3418 "Press any key or button for info menu");
3420 FadeIn(REDRAW_FIELD);
3423 void HandleInfoScreen_Program(int button)
3425 if (button == MB_MENU_LEAVE)
3427 PlaySound(SND_MENU_ITEM_SELECTING);
3429 info_mode = INFO_MODE_MAIN;
3434 else if (button == MB_MENU_CHOICE)
3436 PlaySound(SND_MENU_ITEM_SELECTING);
3438 FadeMenuSoundsAndMusic();
3440 info_mode = INFO_MODE_MAIN;
3445 PlayMenuSoundIfLoop();
3449 void DrawInfoScreen_Version()
3451 int font_title = MENU_INFO_FONT_TITLE;
3452 int font_head = MENU_INFO_FONT_HEAD;
3453 int font_text = MENU_INFO_FONT_TEXT;
3454 int font_foot = MENU_INFO_FONT_FOOT;
3455 int spacing_title = menu.headline1_spacing_info[info_mode];
3456 int spacing_head = menu.headline2_spacing_info[info_mode];
3457 int spacing_para = menu.paragraph_spacing_info[info_mode];
3458 int spacing_line = menu.line_spacing_info[info_mode];
3459 int xstep = getFontWidth(font_text);
3460 int ystep_title = getMenuTextStep(spacing_title, font_title);
3461 int ystep_head = getMenuTextStep(spacing_head, font_head);
3462 int ystep_para = getMenuTextStep(spacing_para, font_text);
3463 int ystep_line = getMenuTextStep(spacing_line, font_text);
3464 int ystart = mSY - SY + 100;
3465 int ybottom = mSY - SY + SYSIZE - 20;
3466 int xstart1 = mSX - SX + 2 * xstep;
3467 int xstart2 = mSX - SX + 18 * xstep;
3468 int xstart3 = mSX - SX + 28 * xstep;
3469 SDL_version sdl_version_compiled;
3470 const SDL_version *sdl_version_linked;
3471 int driver_name_len = 10;
3472 #if defined(TARGET_SDL2)
3473 SDL_version sdl_version_linked_ext;
3474 const char *driver_name = NULL;
3476 char driver_name[driver_name_len];
3479 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3481 FadeOut(REDRAW_FIELD);
3486 DrawTextSCentered(ystart, font_title, "Version Information:");
3487 ystart += ystep_title;
3489 DrawTextF(xstart1, ystart, font_head, "Name");
3490 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3491 ystart += ystep_line;
3493 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3495 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3496 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3497 ystart += ystep_line;
3499 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3500 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3501 ystart += ystep_line;
3505 DrawTextF(xstart1, ystart, font_head, "Version");
3506 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3507 ystart += ystep_line;
3510 DrawTextF(xstart1, ystart, font_head, "Platform");
3511 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3512 ystart += ystep_line;
3514 DrawTextF(xstart1, ystart, font_head, "Target");
3515 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3516 ystart += ystep_line;
3518 DrawTextF(xstart1, ystart, font_head, "Source date");
3519 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3520 ystart += ystep_para;
3522 DrawTextF(xstart1, ystart, font_head, "Library");
3523 DrawTextF(xstart2, ystart, font_head, "compiled");
3524 DrawTextF(xstart3, ystart, font_head, "linked");
3525 ystart += ystep_head;
3527 SDL_VERSION(&sdl_version_compiled);
3528 #if defined(TARGET_SDL2)
3529 SDL_GetVersion(&sdl_version_linked_ext);
3530 sdl_version_linked = &sdl_version_linked_ext;
3532 sdl_version_linked = SDL_Linked_Version();
3535 DrawTextF(xstart1, ystart, font_text, "SDL");
3536 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3537 sdl_version_compiled.major,
3538 sdl_version_compiled.minor,
3539 sdl_version_compiled.patch);
3540 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3541 sdl_version_linked->major,
3542 sdl_version_linked->minor,
3543 sdl_version_linked->patch);
3544 ystart += ystep_line;
3546 SDL_IMAGE_VERSION(&sdl_version_compiled);
3547 sdl_version_linked = IMG_Linked_Version();
3549 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3550 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3551 sdl_version_compiled.major,
3552 sdl_version_compiled.minor,
3553 sdl_version_compiled.patch);
3554 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3555 sdl_version_linked->major,
3556 sdl_version_linked->minor,
3557 sdl_version_linked->patch);
3558 ystart += ystep_line;
3560 SDL_MIXER_VERSION(&sdl_version_compiled);
3561 sdl_version_linked = Mix_Linked_Version();
3563 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3564 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3565 sdl_version_compiled.major,
3566 sdl_version_compiled.minor,
3567 sdl_version_compiled.patch);
3568 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3569 sdl_version_linked->major,
3570 sdl_version_linked->minor,
3571 sdl_version_linked->patch);
3572 ystart += ystep_line;
3574 SDL_NET_VERSION(&sdl_version_compiled);
3575 sdl_version_linked = SDLNet_Linked_Version();
3577 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3578 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3579 sdl_version_compiled.major,
3580 sdl_version_compiled.minor,
3581 sdl_version_compiled.patch);
3582 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3583 sdl_version_linked->major,
3584 sdl_version_linked->minor,
3585 sdl_version_linked->patch);
3586 ystart += ystep_para;
3588 DrawTextF(xstart1, ystart, font_head, "Driver");
3589 DrawTextF(xstart2, ystart, font_head, "Requested");
3590 DrawTextF(xstart3, ystart, font_head, "Used");
3591 ystart += ystep_head;
3593 #if defined(TARGET_SDL2)
3594 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3596 SDL_VideoDriverName(driver_name, driver_name_len);
3599 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3600 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3601 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3602 ystart += ystep_line;
3604 #if defined(TARGET_SDL2)
3605 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3607 SDL_AudioDriverName(driver_name, driver_name_len);
3610 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3611 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3612 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3614 DrawTextSCentered(ybottom, font_foot,
3615 "Press any key or button for info menu");
3617 FadeIn(REDRAW_FIELD);
3620 void HandleInfoScreen_Version(int button)
3622 if (button == MB_MENU_LEAVE)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 info_mode = INFO_MODE_MAIN;
3631 else if (button == MB_MENU_CHOICE)
3633 PlaySound(SND_MENU_ITEM_SELECTING);
3635 FadeMenuSoundsAndMusic();
3637 info_mode = INFO_MODE_MAIN;
3642 PlayMenuSoundIfLoop();
3646 void DrawInfoScreen_LevelSet()
3648 struct TitleMessageInfo *tmi = &readme;
3649 char *filename = getLevelSetInfoFilename();
3650 char *title = "Level Set Information:";
3651 int ystart = mSY - SY + 100;
3652 int ybottom = mSY - SY + SYSIZE - 20;
3654 if (filename == NULL)
3656 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3661 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3663 FadeOut(REDRAW_FIELD);
3668 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3670 /* if x position set to "-1", automatically determine by playfield width */
3672 tmi->x = SXSIZE / 2;
3674 /* if y position set to "-1", use static default value */
3678 /* if width set to "-1", automatically determine by playfield width */
3679 if (tmi->width == -1)
3680 tmi->width = SXSIZE - 2 * TILEX;
3682 /* if height set to "-1", automatically determine by playfield height */
3683 if (tmi->height == -1)
3684 tmi->height = SYSIZE - 20 - tmi->y - 10;
3686 /* if chars set to "-1", automatically determine by text and font width */
3687 if (tmi->chars == -1)
3688 tmi->chars = tmi->width / getFontWidth(tmi->font);
3690 tmi->width = tmi->chars * getFontWidth(tmi->font);
3692 /* if lines set to "-1", automatically determine by text and font height */
3693 if (tmi->lines == -1)
3694 tmi->lines = tmi->height / getFontHeight(tmi->font);
3696 tmi->height = tmi->lines * getFontHeight(tmi->font);
3698 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3699 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3700 tmi->autowrap, tmi->centered, tmi->parse_comments);
3702 DrawTextSCentered(ybottom, FONT_TEXT_4,
3703 "Press any key or button for info menu");
3705 FadeIn(REDRAW_FIELD);
3708 void HandleInfoScreen_LevelSet(int button)
3710 if (button == MB_MENU_LEAVE)
3712 PlaySound(SND_MENU_ITEM_SELECTING);
3714 info_mode = INFO_MODE_MAIN;
3719 else if (button == MB_MENU_CHOICE)
3721 PlaySound(SND_MENU_ITEM_SELECTING);
3723 FadeMenuSoundsAndMusic();
3725 info_mode = INFO_MODE_MAIN;
3730 PlayMenuSoundIfLoop();
3734 static void DrawInfoScreen()
3736 if (info_mode == INFO_MODE_TITLE)
3737 DrawInfoScreen_TitleScreen();
3738 else if (info_mode == INFO_MODE_ELEMENTS)
3739 DrawInfoScreen_Elements();
3740 else if (info_mode == INFO_MODE_MUSIC)
3741 DrawInfoScreen_Music();
3742 else if (info_mode == INFO_MODE_CREDITS)
3743 DrawInfoScreen_Credits();
3744 else if (info_mode == INFO_MODE_PROGRAM)
3745 DrawInfoScreen_Program();
3746 else if (info_mode == INFO_MODE_VERSION)
3747 DrawInfoScreen_Version();
3748 else if (info_mode == INFO_MODE_LEVELSET)
3749 DrawInfoScreen_LevelSet();
3751 DrawInfoScreen_Main();
3753 if (info_mode != INFO_MODE_MAIN &&
3754 info_mode != INFO_MODE_TITLE &&
3755 info_mode != INFO_MODE_MUSIC)
3756 PlayMenuSoundsAndMusic();
3759 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3761 if (info_mode == INFO_MODE_TITLE)
3762 HandleInfoScreen_TitleScreen(button);
3763 else if (info_mode == INFO_MODE_ELEMENTS)
3764 HandleInfoScreen_Elements(button);
3765 else if (info_mode == INFO_MODE_MUSIC)
3766 HandleInfoScreen_Music(button);
3767 else if (info_mode == INFO_MODE_CREDITS)
3768 HandleInfoScreen_Credits(button);
3769 else if (info_mode == INFO_MODE_PROGRAM)
3770 HandleInfoScreen_Program(button);
3771 else if (info_mode == INFO_MODE_VERSION)
3772 HandleInfoScreen_Version(button);
3773 else if (info_mode == INFO_MODE_LEVELSET)
3774 HandleInfoScreen_LevelSet(button);
3776 HandleInfoScreen_Main(mx, my, dx, dy, button);
3780 /* ========================================================================= */
3781 /* type name functions */
3782 /* ========================================================================= */
3784 void HandleTypeName(int newxpos, Key key)
3786 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3787 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3788 struct TextPosInfo *pos = mci->pos_input;
3789 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3790 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3791 static int xpos = 0;
3792 int font_nr = pos->font;
3793 int font_active_nr = FONT_ACTIVE(font_nr);
3794 int font_width = getFontWidth(font_active_nr);
3795 char key_char = getValidConfigValueChar(getCharFromKey(key));
3796 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3797 boolean is_active = TRUE;
3799 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3803 strcpy(last_player_name, setup.player_name);
3807 StartTextInput(startx, starty, pos->width, pos->height);
3809 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3811 setup.player_name[xpos] = key_char;
3812 setup.player_name[xpos + 1] = 0;
3816 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3820 setup.player_name[xpos] = 0;
3822 else if (key == KSYM_Return && xpos > 0)
3828 SetGameStatus(GAME_MODE_MAIN);
3830 else if (key == KSYM_Escape)
3832 strcpy(setup.player_name, last_player_name);
3836 SetGameStatus(GAME_MODE_MAIN);
3841 pos->width = (strlen(setup.player_name) + 1) * font_width;
3842 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3844 DrawText(startx, starty, setup.player_name, font_active_nr);
3845 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3849 pos->width = strlen(setup.player_name) * font_width;
3850 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3852 DrawText(startx, starty, setup.player_name, font_nr);
3859 /* ========================================================================= */
3860 /* tree menu functions */
3861 /* ========================================================================= */
3863 static void DrawChooseTree(TreeInfo **ti_ptr)
3865 int fade_mask = REDRAW_FIELD;
3867 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3868 fade_mask = REDRAW_ALL;
3870 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3872 SetGameStatus(GAME_MODE_MAIN);
3881 FreeScreenGadgets();
3882 CreateScreenGadgets();
3886 /* needed if different viewport properties defined for choosing level (set) */
3887 ChangeViewportPropertiesIfNeeded();
3889 if (game_status == GAME_MODE_LEVELNR)
3890 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3891 else if (game_status == GAME_MODE_LEVELS)
3892 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3896 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3898 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3899 MapScreenTreeGadgets(*ti_ptr);
3901 DrawMaskedBorder(fade_mask);
3906 static void drawChooseTreeList(int first_entry, int num_page_entries,
3910 char *title_string = NULL;
3911 int yoffset_sets = MENU_TITLE1_YPOS;
3912 int yoffset_setup = 16;
3913 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3914 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3916 title_string = ti->infotext;
3918 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3920 clearMenuListArea();
3922 for (i = 0; i < num_page_entries; i++)
3924 TreeInfo *node, *node_first;
3925 int entry_pos = first_entry + i;
3926 int xpos = MENU_SCREEN_START_XPOS;
3927 int ypos = MENU_SCREEN_START_YPOS + i;
3928 int startx = mSX + xpos * 32;
3929 int starty = mSY + ypos * 32;
3930 int font_nr = FONT_TEXT_1;
3931 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3932 int startx_text = startx + font_xoffset;
3933 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3934 int text_size = startx_scrollbar - startx_text;
3935 int max_buffer_len = text_size / getFontWidth(font_nr);
3936 char buffer[max_buffer_len + 1];
3938 node_first = getTreeInfoFirstGroupEntry(ti);
3939 node = getTreeInfoFromPos(node_first, entry_pos);
3941 strncpy(buffer, node->name, max_buffer_len);
3942 buffer[max_buffer_len] = '\0';
3944 DrawText(startx, starty, buffer, font_nr + node->color);
3946 if (node->parent_link)
3947 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3948 else if (node->level_group)
3949 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3951 initCursor(i, IMG_MENU_BUTTON);
3954 redraw_mask |= REDRAW_FIELD;
3957 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3959 TreeInfo *node, *node_first;
3960 int x, last_redraw_mask = redraw_mask;
3961 int ypos = MENU_TITLE2_YPOS;
3962 int font_nr = FONT_TITLE_2;
3964 if (ti->type == TREE_TYPE_LEVEL_NR)
3965 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3967 if (ti->type != TREE_TYPE_LEVEL_DIR)
3970 node_first = getTreeInfoFirstGroupEntry(ti);
3971 node = getTreeInfoFromPos(node_first, entry_pos);
3973 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3975 if (node->parent_link)
3976 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3977 node->node_parent->name);
3978 else if (node->level_group)
3979 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3981 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3982 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3983 node->levels, (node->levels > 1 ? "levels" : "level"),
3986 /* let BackToFront() redraw only what is needed */
3987 redraw_mask = last_redraw_mask;
3988 for (x = 0; x < SCR_FIELDX; x++)
3989 MarkTileDirty(x, 1);
3992 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3995 TreeInfo *ti = *ti_ptr;
3997 int y = ti->cl_cursor;
3998 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3999 int num_entries = numTreeInfoInGroup(ti);
4000 int num_page_entries;
4001 boolean position_set_by_scrollbar = (dx == 999);
4003 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4004 num_page_entries = num_entries;
4006 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4008 if (button == MB_MENU_INITIALIZE)
4010 int num_entries = numTreeInfoInGroup(ti);
4011 int entry_pos = posTreeInfo(ti);
4013 if (ti->cl_first == -1)
4015 /* only on initialization */
4016 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4017 ti->cl_cursor = entry_pos - ti->cl_first;
4019 else if (ti->cl_cursor >= num_page_entries ||
4020 (num_entries > num_page_entries &&
4021 num_entries - ti->cl_first < num_page_entries))
4023 /* only after change of list size (by custom graphic configuration) */
4024 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4025 ti->cl_cursor = entry_pos - ti->cl_first;
4028 if (position_set_by_scrollbar)
4031 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4034 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4035 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4036 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4040 else if (button == MB_MENU_LEAVE)
4044 PlaySound(SND_MENU_ITEM_SELECTING);
4046 if (ti->node_parent)
4048 *ti_ptr = ti->node_parent;
4049 DrawChooseTree(ti_ptr);
4051 else if (game_status == GAME_MODE_SETUP)
4053 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4054 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4055 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4057 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4058 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4059 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4060 execSetupGraphics();
4061 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4062 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4063 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4065 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4066 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4067 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4074 if (game_status == GAME_MODE_LEVELNR)
4076 int new_level_nr = atoi(level_number_current->identifier);
4078 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4081 SetGameStatus(GAME_MODE_MAIN);
4089 if (mx || my) /* mouse input */
4091 x = (mx - mSX) / 32;
4092 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4094 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4096 /* move cursor instead of scrolling when already at start/end of list */
4097 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4099 else if (dy == +1 * SCROLL_LINE &&
4100 ti->cl_first + num_page_entries == num_entries)
4103 /* handle scrolling screen one line or page */
4104 if (ti->cl_cursor + dy < 0 ||
4105 ti->cl_cursor + dy > num_page_entries - 1)
4107 boolean redraw = FALSE;
4109 if (ABS(dy) == SCROLL_PAGE)
4110 step = num_page_entries - 1;
4112 if (dy < 0 && ti->cl_first > 0)
4114 /* scroll page/line up */
4116 ti->cl_first -= step;
4117 if (ti->cl_first < 0)
4122 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4124 /* scroll page/line down */
4126 ti->cl_first += step;
4127 if (ti->cl_first + num_page_entries > num_entries)
4128 ti->cl_first = MAX(0, num_entries - num_page_entries);
4135 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4136 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4137 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4139 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4146 /* handle moving cursor one line */
4147 y = ti->cl_cursor + dy;
4152 TreeInfo *node_first, *node_cursor;
4153 int entry_pos = ti->cl_first + y;
4155 node_first = getTreeInfoFirstGroupEntry(ti);
4156 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4158 if (node_cursor->node_group)
4162 PlaySound(SND_MENU_ITEM_SELECTING);
4164 node_cursor->cl_first = ti->cl_first;
4165 node_cursor->cl_cursor = ti->cl_cursor;
4166 *ti_ptr = node_cursor->node_group;
4167 DrawChooseTree(ti_ptr);
4172 else if (dx == -1 && ti->node_parent)
4176 PlaySound(SND_MENU_ITEM_SELECTING);
4178 *ti_ptr = ti->node_parent;
4179 DrawChooseTree(ti_ptr);
4184 if (!anyScrollbarGadgetActive() &&
4185 IN_VIS_MENU(x, y) &&
4186 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4187 y >= 0 && y < num_page_entries)
4191 if (y != ti->cl_cursor)
4193 PlaySound(SND_MENU_ITEM_ACTIVATING);
4195 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4196 drawChooseTreeCursor(y, TRUE);
4197 drawChooseTreeInfo(ti->cl_first + y, ti);
4203 if (game_status == GAME_MODE_SETUP)
4205 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4206 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4207 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4209 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4210 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4211 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4212 execSetupGraphics();
4213 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4214 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4215 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4217 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4218 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4219 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4228 TreeInfo *node_first, *node_cursor;
4229 int entry_pos = ti->cl_first + y;
4231 PlaySound(SND_MENU_ITEM_SELECTING);
4233 node_first = getTreeInfoFirstGroupEntry(ti);
4234 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4236 if (node_cursor->node_group)
4240 node_cursor->cl_first = ti->cl_first;
4241 node_cursor->cl_cursor = ti->cl_cursor;
4242 *ti_ptr = node_cursor->node_group;
4243 DrawChooseTree(ti_ptr);
4245 else if (node_cursor->parent_link)
4249 *ti_ptr = node_cursor->node_parent;
4250 DrawChooseTree(ti_ptr);
4256 node_cursor->cl_first = ti->cl_first;
4257 node_cursor->cl_cursor = ti->cl_cursor;
4258 *ti_ptr = node_cursor;
4260 if (ti->type == TREE_TYPE_LEVEL_DIR)
4262 LoadLevelSetup_SeriesInfo();
4264 SaveLevelSetup_LastSeries();
4265 SaveLevelSetup_SeriesInfo();
4269 if (game_status == GAME_MODE_SETUP)
4271 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4272 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4273 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4275 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4276 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4277 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4278 execSetupGraphics();
4279 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4280 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4281 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4283 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4284 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4285 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4292 if (game_status == GAME_MODE_LEVELNR)
4294 int new_level_nr = atoi(level_number_current->identifier);
4296 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4299 SetGameStatus(GAME_MODE_MAIN);
4308 void DrawChooseLevelSet()
4310 FadeMenuSoundsAndMusic();
4312 DrawChooseTree(&leveldir_current);
4314 PlayMenuSoundsAndMusic();
4317 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4319 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4322 void DrawChooseLevelNr()
4326 FadeMenuSoundsAndMusic();
4328 if (level_number != NULL)
4330 freeTreeInfo(level_number);
4332 level_number = NULL;
4335 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4337 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4338 char identifier[32], name[32];
4341 /* temporarily load level info to get level name */
4342 LoadLevelInfoOnly(i);
4344 ti->node_top = &level_number;
4345 ti->sort_priority = 10000 + value;
4346 ti->color = (level.no_level_file ? FC_BLUE :
4347 LevelStats_getSolved(i) ? FC_GREEN :
4348 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4350 snprintf(identifier, sizeof(identifier), "%d", value);
4351 snprintf(name, sizeof(name), "%03d: %s", value,
4352 (level.no_level_file ? "(no file)" : level.name));
4354 setString(&ti->identifier, identifier);
4355 setString(&ti->name, name);
4356 setString(&ti->name_sorting, name);
4358 pushTreeInfo(&level_number, ti);
4361 /* sort level number values to start with lowest level number */
4362 sortTreeInfo(&level_number);
4364 /* set current level number to current level number */
4365 level_number_current =
4366 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4368 /* if that also fails, set current level number to first available level */
4369 if (level_number_current == NULL)
4370 level_number_current = level_number;
4372 DrawChooseTree(&level_number_current);
4374 PlayMenuSoundsAndMusic();
4377 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4379 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4382 void DrawHallOfFame(int highlight_position)
4384 int fade_mask = REDRAW_FIELD;
4386 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4387 fade_mask = REDRAW_ALL;
4390 FadeMenuSoundsAndMusic();
4392 /* (this is needed when called from GameEnd() after winning a game) */
4393 KeyboardAutoRepeatOn();
4395 /* (this is needed when called from GameEnd() after winning a game) */
4396 SetDrawDeactivationMask(REDRAW_NONE);
4397 SetDrawBackgroundMask(REDRAW_FIELD);
4399 if (highlight_position < 0)
4400 LoadScore(level_nr);
4402 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4404 FadeSetEnterScreen();
4408 /* needed if different viewport properties defined for scores */
4409 ChangeViewportPropertiesIfNeeded();
4411 PlayMenuSoundsAndMusic();
4413 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4415 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4417 DrawMaskedBorder(fade_mask);
4422 static void drawHallOfFameList(int first_entry, int highlight_position)
4426 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4429 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4430 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4431 "HighScores of Level %d", level_nr);
4433 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4435 int entry = first_entry + i;
4436 boolean active = (entry == highlight_position);
4437 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4438 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4439 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4440 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4441 int dxoff = getFontDrawOffsetX(font_nr1);
4442 int dx1 = 3 * getFontWidth(font_nr1);
4443 int dx2 = dx1 + getFontWidth(font_nr1);
4444 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4445 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4446 int sy = mSY + 64 + i * 32;
4448 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4449 DrawText(mSX + dx1, sy, ".", font_nr1);
4451 for (j = 0; j < num_dots; j++)
4452 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4454 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4455 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4457 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4460 redraw_mask |= REDRAW_FIELD;
4463 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4465 static int first_entry = 0;
4466 static int highlight_position = 0;
4467 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4469 if (button == MB_MENU_INITIALIZE)
4472 highlight_position = mx;
4473 drawHallOfFameList(first_entry, highlight_position);
4478 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4479 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4483 if (first_entry > 0)
4485 first_entry -= step;
4486 if (first_entry < 0)
4489 drawHallOfFameList(first_entry, highlight_position);
4494 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4496 first_entry += step;
4497 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4498 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4500 drawHallOfFameList(first_entry, highlight_position);
4503 else if (button == MB_MENU_LEAVE)
4505 PlaySound(SND_MENU_ITEM_SELECTING);
4507 FadeSound(SND_BACKGROUND_SCORES);
4509 SetGameStatus(GAME_MODE_MAIN);
4513 else if (button == MB_MENU_CHOICE)
4515 PlaySound(SND_MENU_ITEM_SELECTING);
4517 FadeSound(SND_BACKGROUND_SCORES);
4519 SetGameStatus(GAME_MODE_MAIN);
4524 if (game_status == GAME_MODE_SCORES)
4525 PlayMenuSoundIfLoop();
4529 /* ========================================================================= */
4530 /* setup screen functions */
4531 /* ========================================================================= */
4533 static struct TokenInfo *setup_info;
4534 static int num_setup_info; /* number of setup entries shown on screen */
4535 static int max_setup_info; /* total number of setup entries in list */
4537 static char *window_size_text;
4538 static char *scaling_type_text;
4539 static char *rendering_mode_text;
4540 static char *scroll_delay_text;
4541 static char *snapshot_mode_text;
4542 static char *game_speed_text;
4543 static char *graphics_set_name;
4544 static char *sounds_set_name;
4545 static char *music_set_name;
4546 static char *volume_simple_text;
4547 static char *volume_loops_text;
4548 static char *volume_music_text;
4549 static char *touch_controls_text;
4550 static char *move_distance_text;
4551 static char *drop_distance_text;
4553 static void execSetupMain()
4555 setup_mode = SETUP_MODE_MAIN;
4560 static void execSetupGame_setGameSpeeds()
4562 if (game_speeds == NULL)
4566 for (i = 0; game_speeds_list[i].value != -1; i++)
4568 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4569 char identifier[32], name[32];
4570 int value = game_speeds_list[i].value;
4571 char *text = game_speeds_list[i].text;
4573 ti->node_top = &game_speeds;
4574 ti->sort_priority = 10000 - value;
4576 sprintf(identifier, "%d", value);
4577 sprintf(name, "%s", text);
4579 setString(&ti->identifier, identifier);
4580 setString(&ti->name, name);
4581 setString(&ti->name_sorting, name);
4582 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4584 pushTreeInfo(&game_speeds, ti);
4587 /* sort game speed values to start with slowest game speed */
4588 sortTreeInfo(&game_speeds);
4590 /* set current game speed to configured game speed value */
4591 game_speed_current =
4592 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4594 /* if that fails, set current game speed to reliable default value */
4595 if (game_speed_current == NULL)
4596 game_speed_current =
4597 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4599 /* if that also fails, set current game speed to first available speed */
4600 if (game_speed_current == NULL)
4601 game_speed_current = game_speeds;
4604 setup.game_frame_delay = atoi(game_speed_current->identifier);
4606 /* needed for displaying game speed text instead of identifier */
4607 game_speed_text = game_speed_current->name;
4610 static void execSetupGame_setScrollDelays()
4612 if (scroll_delays == NULL)
4616 for (i = 0; scroll_delays_list[i].value != -1; i++)
4618 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4619 char identifier[32], name[32];
4620 int value = scroll_delays_list[i].value;
4621 char *text = scroll_delays_list[i].text;
4623 ti->node_top = &scroll_delays;
4624 ti->sort_priority = value;
4626 sprintf(identifier, "%d", value);
4627 sprintf(name, "%s", text);
4629 setString(&ti->identifier, identifier);
4630 setString(&ti->name, name);
4631 setString(&ti->name_sorting, name);
4632 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4634 pushTreeInfo(&scroll_delays, ti);
4637 /* sort scroll delay values to start with lowest scroll delay value */
4638 sortTreeInfo(&scroll_delays);
4640 /* set current scroll delay value to configured scroll delay value */
4641 scroll_delay_current =
4642 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4644 /* if that fails, set current scroll delay to reliable default value */
4645 if (scroll_delay_current == NULL)
4646 scroll_delay_current =
4647 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4649 /* if that also fails, set current scroll delay to first available value */
4650 if (scroll_delay_current == NULL)
4651 scroll_delay_current = scroll_delays;
4654 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4656 /* needed for displaying scroll delay text instead of identifier */
4657 scroll_delay_text = scroll_delay_current->name;
4660 static void execSetupGame_setSnapshotModes()
4662 if (snapshot_modes == NULL)
4666 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4668 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4669 char identifier[32], name[32];
4670 char *value = snapshot_modes_list[i].value;
4671 char *text = snapshot_modes_list[i].text;
4673 ti->node_top = &snapshot_modes;
4674 ti->sort_priority = i;
4676 sprintf(identifier, "%s", value);
4677 sprintf(name, "%s", text);
4679 setString(&ti->identifier, identifier);
4680 setString(&ti->name, name);
4681 setString(&ti->name_sorting, name);
4682 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4684 pushTreeInfo(&snapshot_modes, ti);
4687 /* sort snapshot mode values to start with lowest snapshot mode value */
4688 sortTreeInfo(&snapshot_modes);
4690 /* set current snapshot mode value to configured snapshot mode value */
4691 snapshot_mode_current =
4692 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4694 /* if that fails, set current snapshot mode to reliable default value */
4695 if (snapshot_mode_current == NULL)
4696 snapshot_mode_current =
4697 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4699 /* if that also fails, set current snapshot mode to first available value */
4700 if (snapshot_mode_current == NULL)
4701 snapshot_mode_current = snapshot_modes;
4704 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4706 /* needed for displaying snapshot mode text instead of identifier */
4707 snapshot_mode_text = snapshot_mode_current->name;
4710 static void execSetupGame()
4712 execSetupGame_setGameSpeeds();
4713 execSetupGame_setScrollDelays();
4714 execSetupGame_setSnapshotModes();
4716 setup_mode = SETUP_MODE_GAME;
4721 static void execSetupChooseGameSpeed()
4723 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4728 static void execSetupChooseScrollDelay()
4730 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4735 static void execSetupChooseSnapshotMode()
4737 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4742 static void execSetupEditor()
4744 setup_mode = SETUP_MODE_EDITOR;
4749 static void execSetupGraphics_setWindowSizes(boolean update_list)
4751 if (window_sizes != NULL && update_list)
4753 freeTreeInfo(window_sizes);
4755 window_sizes = NULL;
4758 if (window_sizes == NULL)
4760 boolean current_window_size_found = FALSE;
4763 for (i = 0; window_sizes_list[i].value != -1; i++)
4765 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4766 char identifier[32], name[32];
4767 int value = window_sizes_list[i].value;
4768 char *text = window_sizes_list[i].text;
4770 ti->node_top = &window_sizes;
4771 ti->sort_priority = value;
4773 sprintf(identifier, "%d", value);
4774 sprintf(name, "%s", text);
4776 setString(&ti->identifier, identifier);
4777 setString(&ti->name, name);
4778 setString(&ti->name_sorting, name);
4779 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4781 pushTreeInfo(&window_sizes, ti);
4783 if (value == setup.window_scaling_percent)
4784 current_window_size_found = TRUE;
4787 if (!current_window_size_found)
4789 // add entry for non-preset window scaling value
4791 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4792 char identifier[32], name[32];
4793 int value = setup.window_scaling_percent;
4795 ti->node_top = &window_sizes;
4796 ti->sort_priority = value;
4798 sprintf(identifier, "%d", value);
4799 sprintf(name, "%d %% (Current)", value);
4801 setString(&ti->identifier, identifier);
4802 setString(&ti->name, name);
4803 setString(&ti->name_sorting, name);
4804 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4806 pushTreeInfo(&window_sizes, ti);
4809 /* sort window size values to start with lowest window size value */
4810 sortTreeInfo(&window_sizes);
4812 /* set current window size value to configured window size value */
4813 window_size_current =
4814 getTreeInfoFromIdentifier(window_sizes,
4815 i_to_a(setup.window_scaling_percent));
4817 /* if that fails, set current window size to reliable default value */
4818 if (window_size_current == NULL)
4819 window_size_current =
4820 getTreeInfoFromIdentifier(window_sizes,
4821 i_to_a(STD_WINDOW_SCALING_PERCENT));
4823 /* if that also fails, set current window size to first available value */
4824 if (window_size_current == NULL)
4825 window_size_current = window_sizes;
4828 setup.window_scaling_percent = atoi(window_size_current->identifier);
4830 /* needed for displaying window size text instead of identifier */
4831 window_size_text = window_size_current->name;
4834 static void execSetupGraphics_setScalingTypes()
4836 if (scaling_types == NULL)
4840 for (i = 0; scaling_types_list[i].value != NULL; i++)
4842 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4843 char identifier[32], name[32];
4844 char *value = scaling_types_list[i].value;
4845 char *text = scaling_types_list[i].text;
4847 ti->node_top = &scaling_types;
4848 ti->sort_priority = i;
4850 sprintf(identifier, "%s", value);
4851 sprintf(name, "%s", text);
4853 setString(&ti->identifier, identifier);
4854 setString(&ti->name, name);
4855 setString(&ti->name_sorting, name);
4856 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4858 pushTreeInfo(&scaling_types, ti);
4861 /* sort scaling type values to start with lowest scaling type value */
4862 sortTreeInfo(&scaling_types);
4864 /* set current scaling type value to configured scaling type value */
4865 scaling_type_current =
4866 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4868 /* if that fails, set current scaling type to reliable default value */
4869 if (scaling_type_current == NULL)
4870 scaling_type_current =
4871 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4873 /* if that also fails, set current scaling type to first available value */
4874 if (scaling_type_current == NULL)
4875 scaling_type_current = scaling_types;
4878 setup.window_scaling_quality = scaling_type_current->identifier;
4880 /* needed for displaying scaling type text instead of identifier */
4881 scaling_type_text = scaling_type_current->name;
4884 static void execSetupGraphics_setRenderingModes()
4886 if (rendering_modes == NULL)
4890 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4892 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4893 char identifier[32], name[32];
4894 char *value = rendering_modes_list[i].value;
4895 char *text = rendering_modes_list[i].text;
4897 ti->node_top = &rendering_modes;
4898 ti->sort_priority = i;
4900 sprintf(identifier, "%s", value);
4901 sprintf(name, "%s", text);
4903 setString(&ti->identifier, identifier);
4904 setString(&ti->name, name);
4905 setString(&ti->name_sorting, name);
4906 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
4908 pushTreeInfo(&rendering_modes, ti);
4911 /* sort rendering mode values to start with lowest rendering mode value */
4912 sortTreeInfo(&rendering_modes);
4914 /* set current rendering mode value to configured rendering mode value */
4915 rendering_mode_current =
4916 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4918 /* if that fails, set current rendering mode to reliable default value */
4919 if (rendering_mode_current == NULL)
4920 rendering_mode_current =
4921 getTreeInfoFromIdentifier(rendering_modes,
4922 STR_SPECIAL_RENDERING_DEFAULT);
4924 /* if that also fails, set current rendering mode to first available one */
4925 if (rendering_mode_current == NULL)
4926 rendering_mode_current = rendering_modes;
4929 setup.screen_rendering_mode = rendering_mode_current->identifier;
4931 /* needed for displaying rendering mode text instead of identifier */
4932 rendering_mode_text = rendering_mode_current->name;
4935 static void execSetupGraphics()
4937 // update "setup.window_scaling_percent" from list selection
4938 // (in this case, window scaling was changed on setup screen)
4939 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4940 execSetupGraphics_setWindowSizes(FALSE);
4942 // update list selection from "setup.window_scaling_percent"
4943 // (window scaling may have changed by resizing the window)
4944 execSetupGraphics_setWindowSizes(TRUE);
4946 execSetupGraphics_setScalingTypes();
4947 execSetupGraphics_setRenderingModes();
4949 setup_mode = SETUP_MODE_GRAPHICS;
4953 #if defined(TARGET_SDL2)
4954 // window scaling may have changed at this point
4955 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4957 // window scaling quality may have changed at this point
4958 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4959 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4961 // screen rendering mode may have changed at this point
4962 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4966 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4967 static void execSetupChooseWindowSize()
4969 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4974 static void execSetupChooseScalingType()
4976 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4981 static void execSetupChooseRenderingMode()
4983 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4989 static void execSetupChooseVolumeSimple()
4991 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4996 static void execSetupChooseVolumeLoops()
4998 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5003 static void execSetupChooseVolumeMusic()
5005 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5010 static void execSetupSound()
5012 if (volumes_simple == NULL)
5014 boolean current_volume_simple_found = FALSE;
5017 for (i = 0; volumes_list[i].value != -1; i++)
5019 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5020 char identifier[32], name[32];
5021 int value = volumes_list[i].value;
5022 char *text = volumes_list[i].text;
5024 ti->node_top = &volumes_simple;
5025 ti->sort_priority = value;
5027 sprintf(identifier, "%d", value);
5028 sprintf(name, "%s", text);
5030 setString(&ti->identifier, identifier);
5031 setString(&ti->name, name);
5032 setString(&ti->name_sorting, name);
5033 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5035 pushTreeInfo(&volumes_simple, ti);
5037 if (value == setup.volume_simple)
5038 current_volume_simple_found = TRUE;
5041 if (!current_volume_simple_found)
5043 // add entry for non-preset volume value
5045 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5046 char identifier[32], name[32];
5047 int value = setup.volume_simple;
5049 ti->node_top = &volumes_simple;
5050 ti->sort_priority = value;
5052 sprintf(identifier, "%d", value);
5053 sprintf(name, "%d %% (Current)", value);
5055 setString(&ti->identifier, identifier);
5056 setString(&ti->name, name);
5057 setString(&ti->name_sorting, name);
5058 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5060 pushTreeInfo(&volumes_simple, ti);
5063 /* sort volume values to start with lowest volume value */
5064 sortTreeInfo(&volumes_simple);
5066 /* set current volume value to configured volume value */
5067 volume_simple_current =
5068 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5070 /* if that fails, set current volume to reliable default value */
5071 if (volume_simple_current == NULL)
5072 volume_simple_current =
5073 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5075 /* if that also fails, set current volume to first available value */
5076 if (volume_simple_current == NULL)
5077 volume_simple_current = volumes_simple;
5080 if (volumes_loops == NULL)
5082 boolean current_volume_loops_found = FALSE;
5085 for (i = 0; volumes_list[i].value != -1; i++)
5087 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5088 char identifier[32], name[32];
5089 int value = volumes_list[i].value;
5090 char *text = volumes_list[i].text;
5092 ti->node_top = &volumes_loops;
5093 ti->sort_priority = value;
5095 sprintf(identifier, "%d", value);
5096 sprintf(name, "%s", text);
5098 setString(&ti->identifier, identifier);
5099 setString(&ti->name, name);
5100 setString(&ti->name_sorting, name);
5101 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5103 pushTreeInfo(&volumes_loops, ti);
5105 if (value == setup.volume_loops)
5106 current_volume_loops_found = TRUE;
5109 if (!current_volume_loops_found)
5111 // add entry for non-preset volume value
5113 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5114 char identifier[32], name[32];
5115 int value = setup.volume_loops;
5117 ti->node_top = &volumes_loops;
5118 ti->sort_priority = value;
5120 sprintf(identifier, "%d", value);
5121 sprintf(name, "%d %% (Current)", value);
5123 setString(&ti->identifier, identifier);
5124 setString(&ti->name, name);
5125 setString(&ti->name_sorting, name);
5126 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5128 pushTreeInfo(&volumes_loops, ti);
5131 /* sort volume values to start with lowest volume value */
5132 sortTreeInfo(&volumes_loops);
5134 /* set current volume value to configured volume value */
5135 volume_loops_current =
5136 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5138 /* if that fails, set current volume to reliable default value */
5139 if (volume_loops_current == NULL)
5140 volume_loops_current =
5141 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5143 /* if that also fails, set current volume to first available value */
5144 if (volume_loops_current == NULL)
5145 volume_loops_current = volumes_loops;
5148 if (volumes_music == NULL)
5150 boolean current_volume_music_found = FALSE;
5153 for (i = 0; volumes_list[i].value != -1; i++)
5155 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5156 char identifier[32], name[32];
5157 int value = volumes_list[i].value;
5158 char *text = volumes_list[i].text;
5160 ti->node_top = &volumes_music;
5161 ti->sort_priority = value;
5163 sprintf(identifier, "%d", value);
5164 sprintf(name, "%s", text);
5166 setString(&ti->identifier, identifier);
5167 setString(&ti->name, name);
5168 setString(&ti->name_sorting, name);
5169 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5171 pushTreeInfo(&volumes_music, ti);
5173 if (value == setup.volume_music)
5174 current_volume_music_found = TRUE;
5177 if (!current_volume_music_found)
5179 // add entry for non-preset volume value
5181 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5182 char identifier[32], name[32];
5183 int value = setup.volume_music;
5185 ti->node_top = &volumes_music;
5186 ti->sort_priority = value;
5188 sprintf(identifier, "%d", value);
5189 sprintf(name, "%d %% (Current)", value);
5191 setString(&ti->identifier, identifier);
5192 setString(&ti->name, name);
5193 setString(&ti->name_sorting, name);
5194 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5196 pushTreeInfo(&volumes_music, ti);
5199 /* sort volume values to start with lowest volume value */
5200 sortTreeInfo(&volumes_music);
5202 /* set current volume value to configured volume value */
5203 volume_music_current =
5204 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5206 /* if that fails, set current volume to reliable default value */
5207 if (volume_music_current == NULL)
5208 volume_music_current =
5209 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5211 /* if that also fails, set current volume to first available value */
5212 if (volume_music_current == NULL)
5213 volume_music_current = volumes_music;
5216 setup.volume_simple = atoi(volume_simple_current->identifier);
5217 setup.volume_loops = atoi(volume_loops_current->identifier);
5218 setup.volume_music = atoi(volume_music_current->identifier);
5220 /* needed for displaying volume text instead of identifier */
5221 volume_simple_text = volume_simple_current->name;
5222 volume_loops_text = volume_loops_current->name;
5223 volume_music_text = volume_music_current->name;
5225 setup_mode = SETUP_MODE_SOUND;
5230 static void execSetupChooseTouchControls()
5232 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5237 static void execSetupChooseMoveDistance()
5239 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5244 static void execSetupChooseDropDistance()
5246 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5251 static void execSetupTouch()
5253 if (touch_controls == NULL)
5257 for (i = 0; touch_controls_list[i].value != NULL; i++)
5259 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5260 char identifier[32], name[32];
5261 char *value = touch_controls_list[i].value;
5262 char *text = touch_controls_list[i].text;
5264 ti->node_top = &touch_controls;
5265 ti->sort_priority = i;
5267 sprintf(identifier, "%s", value);
5268 sprintf(name, "%s", text);
5270 setString(&ti->identifier, identifier);
5271 setString(&ti->name, name);
5272 setString(&ti->name_sorting, name);
5273 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5275 pushTreeInfo(&touch_controls, ti);
5278 /* sort touch control values to start with lowest touch control value */
5279 sortTreeInfo(&touch_controls);
5281 /* set current touch control value to configured touch control value */
5282 touch_control_current =
5283 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5285 /* if that fails, set current touch control to reliable default value */
5286 if (touch_control_current == NULL)
5287 touch_control_current =
5288 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5290 /* if that also fails, set current touch control to first available value */
5291 if (touch_control_current == NULL)
5292 touch_control_current = touch_controls;
5295 if (move_distances == NULL)
5299 for (i = 0; distances_list[i].value != -1; i++)
5301 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5302 char identifier[32], name[32];
5303 int value = distances_list[i].value;
5304 char *text = distances_list[i].text;
5306 ti->node_top = &move_distances;
5307 ti->sort_priority = value;
5309 sprintf(identifier, "%d", value);
5310 sprintf(name, "%s", text);
5312 setString(&ti->identifier, identifier);
5313 setString(&ti->name, name);
5314 setString(&ti->name_sorting, name);
5315 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5317 pushTreeInfo(&move_distances, ti);
5320 /* sort distance values to start with lowest distance value */
5321 sortTreeInfo(&move_distances);
5323 /* set current distance value to configured distance value */
5324 move_distance_current =
5325 getTreeInfoFromIdentifier(move_distances,
5326 i_to_a(setup.touch.move_distance));
5328 /* if that fails, set current distance to reliable default value */
5329 if (move_distance_current == NULL)
5330 move_distance_current =
5331 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5333 /* if that also fails, set current distance to first available value */
5334 if (move_distance_current == NULL)
5335 move_distance_current = move_distances;
5338 if (drop_distances == NULL)
5342 for (i = 0; distances_list[i].value != -1; i++)
5344 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5345 char identifier[32], name[32];
5346 int value = distances_list[i].value;
5347 char *text = distances_list[i].text;
5349 ti->node_top = &drop_distances;
5350 ti->sort_priority = value;
5352 sprintf(identifier, "%d", value);
5353 sprintf(name, "%s", text);
5355 setString(&ti->identifier, identifier);
5356 setString(&ti->name, name);
5357 setString(&ti->name_sorting, name);
5358 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5360 pushTreeInfo(&drop_distances, ti);
5363 /* sort distance values to start with lowest distance value */
5364 sortTreeInfo(&drop_distances);
5366 /* set current distance value to configured distance value */
5367 drop_distance_current =
5368 getTreeInfoFromIdentifier(drop_distances,
5369 i_to_a(setup.touch.drop_distance));
5371 /* if that fails, set current distance to reliable default value */
5372 if (drop_distance_current == NULL)
5373 drop_distance_current =
5374 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5376 /* if that also fails, set current distance to first available value */
5377 if (drop_distance_current == NULL)
5378 drop_distance_current = drop_distances;
5381 setup.touch.control_type = touch_control_current->identifier;
5382 setup.touch.move_distance = atoi(move_distance_current->identifier);
5383 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5385 /* needed for displaying volume text instead of identifier */
5386 touch_controls_text = touch_control_current->name;
5387 move_distance_text = move_distance_current->name;
5388 drop_distance_text = drop_distance_current->name;
5390 setup_mode = SETUP_MODE_TOUCH;
5395 static void execSetupArtwork()
5398 printf("::: '%s', '%s', '%s'\n",
5399 artwork.gfx_current->subdir,
5400 artwork.gfx_current->fullpath,
5401 artwork.gfx_current->basepath);
5404 setup.graphics_set = artwork.gfx_current->identifier;
5405 setup.sounds_set = artwork.snd_current->identifier;
5406 setup.music_set = artwork.mus_current->identifier;
5408 /* needed if last screen (setup choice) changed graphics, sounds or music */
5409 ReloadCustomArtwork(0);
5411 /* needed for displaying artwork name instead of artwork identifier */
5412 graphics_set_name = artwork.gfx_current->name;
5413 sounds_set_name = artwork.snd_current->name;
5414 music_set_name = artwork.mus_current->name;
5416 setup_mode = SETUP_MODE_ARTWORK;
5421 static void execSetupChooseGraphics()
5423 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5428 static void execSetupChooseSounds()
5430 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5435 static void execSetupChooseMusic()
5437 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5442 static void execSetupInput()
5444 setup_mode = SETUP_MODE_INPUT;
5449 static void execSetupShortcuts()
5451 setup_mode = SETUP_MODE_SHORTCUTS;
5456 static void execSetupShortcuts1()
5458 setup_mode = SETUP_MODE_SHORTCUTS_1;
5463 static void execSetupShortcuts2()
5465 setup_mode = SETUP_MODE_SHORTCUTS_2;
5470 static void execSetupShortcuts3()
5472 setup_mode = SETUP_MODE_SHORTCUTS_3;
5477 static void execSetupShortcuts4()
5479 setup_mode = SETUP_MODE_SHORTCUTS_4;
5484 static void execSetupShortcuts5()
5486 setup_mode = SETUP_MODE_SHORTCUTS_5;
5491 static void execExitSetup()
5493 SetGameStatus(GAME_MODE_MAIN);
5498 static void execSaveAndExitSetup()
5504 static struct TokenInfo setup_info_main[] =
5506 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5507 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5508 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5509 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5510 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5511 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5512 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5513 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5514 { TYPE_EMPTY, NULL, "" },
5515 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5516 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5521 static struct TokenInfo setup_info_game[] =
5523 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5524 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5525 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5526 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5527 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5528 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5529 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5530 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5531 { TYPE_STRING, &game_speed_text, "" },
5533 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5534 { TYPE_STRING, &scroll_delay_text, "" },
5536 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5537 { TYPE_STRING, &snapshot_mode_text, "" },
5538 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5539 { TYPE_EMPTY, NULL, "" },
5540 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5545 static struct TokenInfo setup_info_editor[] =
5548 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5549 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5550 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5551 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5552 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5553 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5554 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5555 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5556 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5557 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5559 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5560 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5562 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5564 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5565 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5566 { TYPE_EMPTY, NULL, "" },
5568 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5569 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5570 { TYPE_EMPTY, NULL, "" },
5572 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5573 { TYPE_EMPTY, NULL, "" },
5574 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5579 static struct TokenInfo setup_info_graphics[] =
5581 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5582 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5583 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5584 { TYPE_STRING, &window_size_text, "" },
5585 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5586 { TYPE_STRING, &scaling_type_text, "" },
5587 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5588 { TYPE_STRING, &rendering_mode_text, "" },
5591 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5592 { TYPE_STRING, &scroll_delay_text, "" },
5594 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5595 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5596 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5597 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5598 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5599 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5600 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5601 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5602 { TYPE_EMPTY, NULL, "" },
5603 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5608 static struct TokenInfo setup_info_sound[] =
5610 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5611 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5612 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5613 { TYPE_EMPTY, NULL, "" },
5614 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5615 { TYPE_STRING, &volume_simple_text, "" },
5616 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5617 { TYPE_STRING, &volume_loops_text, "" },
5618 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5619 { TYPE_STRING, &volume_music_text, "" },
5620 { TYPE_EMPTY, NULL, "" },
5621 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5626 static struct TokenInfo setup_info_artwork[] =
5628 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5629 { TYPE_STRING, &graphics_set_name, "" },
5630 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5631 { TYPE_STRING, &sounds_set_name, "" },
5632 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5633 { TYPE_STRING, &music_set_name, "" },
5634 { TYPE_EMPTY, NULL, "" },
5635 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5636 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5637 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5638 { TYPE_EMPTY, NULL, "" },
5639 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5644 static struct TokenInfo setup_info_input[] =
5646 { TYPE_SWITCH, NULL, "Player:" },
5647 { TYPE_SWITCH, NULL, "Device:" },
5648 { TYPE_SWITCH, NULL, "" },
5649 { TYPE_EMPTY, NULL, "" },
5650 { TYPE_EMPTY, NULL, "" },
5651 { TYPE_EMPTY, NULL, "" },
5652 { TYPE_EMPTY, NULL, "" },
5653 { TYPE_EMPTY, NULL, "" },
5654 { TYPE_EMPTY, NULL, "" },
5655 { TYPE_EMPTY, NULL, "" },
5656 { TYPE_EMPTY, NULL, "" },
5657 { TYPE_EMPTY, NULL, "" },
5658 { TYPE_EMPTY, NULL, "" },
5659 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5664 static struct TokenInfo setup_info_touch[] =
5666 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5667 { TYPE_STRING, &touch_controls_text, "" },
5668 { TYPE_EMPTY, NULL, "" },
5669 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5674 static struct TokenInfo setup_info_touch_wipe_gestures[] =
5676 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5677 { TYPE_STRING, &touch_controls_text, "" },
5678 { TYPE_EMPTY, NULL, "" },
5679 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5680 { TYPE_STRING, &move_distance_text, "" },
5681 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5682 { TYPE_STRING, &drop_distance_text, "" },
5683 { TYPE_EMPTY, NULL, "" },
5684 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5689 static struct TokenInfo setup_info_shortcuts[] =
5691 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5692 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5693 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5694 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5695 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5696 { TYPE_EMPTY, NULL, "" },
5697 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5702 static struct TokenInfo setup_info_shortcuts_1[] =
5704 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5705 { TYPE_KEY, &setup.shortcut.save_game, "" },
5706 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5707 { TYPE_KEY, &setup.shortcut.load_game, "" },
5708 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5709 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5710 { TYPE_EMPTY, NULL, "" },
5711 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5712 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5713 { TYPE_EMPTY, NULL, "" },
5714 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5719 static struct TokenInfo setup_info_shortcuts_2[] =
5721 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5722 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5723 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5724 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5725 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5726 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5727 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5728 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5729 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5730 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5731 { TYPE_EMPTY, NULL, "" },
5732 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5737 static struct TokenInfo setup_info_shortcuts_3[] =
5739 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5740 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5741 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5742 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5743 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5744 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5745 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5746 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5747 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5748 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5749 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5750 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5751 { TYPE_EMPTY, NULL, "" },
5752 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5757 static struct TokenInfo setup_info_shortcuts_4[] =
5759 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5760 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5761 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5762 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5763 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5764 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5765 { TYPE_EMPTY, NULL, "" },
5766 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5771 static struct TokenInfo setup_info_shortcuts_5[] =
5773 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5774 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5775 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5776 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5777 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5778 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5779 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5780 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5781 { TYPE_EMPTY, NULL, "" },
5782 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5787 static Key getSetupKey()
5789 Key key = KSYM_UNDEFINED;
5790 boolean got_key_event = FALSE;
5792 while (!got_key_event)
5796 if (NextValidEvent(&event))
5800 case EVENT_KEYPRESS:
5802 key = GetEventKey((KeyEvent *)&event, TRUE);
5804 /* press 'Escape' or 'Enter' to keep the existing key binding */
5805 if (key == KSYM_Escape || key == KSYM_Return)
5806 key = KSYM_UNDEFINED; /* keep old value */
5808 got_key_event = TRUE;
5812 case EVENT_KEYRELEASE:
5813 key_joystick_mapping = 0;
5817 HandleOtherEvents(&event);
5828 static int getSetupValueFont(int type, void *value)
5830 if (type & TYPE_GHOSTED)
5831 return FONT_OPTION_OFF;
5832 else if (type & TYPE_KEY)
5833 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5834 else if (type & TYPE_STRING)
5835 return FONT_VALUE_2;
5836 else if (type & TYPE_ECS_AGA)
5837 return FONT_VALUE_1;
5838 else if (type & TYPE_BOOLEAN_STYLE)
5839 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5840 else if (type & TYPE_YES_NO_AUTO)
5841 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5842 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5844 return FONT_VALUE_1;
5847 static int getSetupValueFontNarrow(int type, int font_nr)
5849 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5850 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5851 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5855 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5857 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5858 struct TokenInfo *si = &setup_info[si_pos];
5859 boolean font_draw_xoffset_modified = FALSE;
5860 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5861 int font_draw_xoffset_old = -1;
5862 int xoffset = (scrollbar_needed ? -1 : 0);
5863 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5864 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5865 int xpos = menu_screen_value_xpos;
5866 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5867 int startx = mSX + xpos * 32;
5868 int starty = mSY + ypos * 32;
5869 int font_nr, font_nr_default, font_width_default;
5870 int type = si->type;
5871 void *value = si->value;
5872 char *value_string = getSetupValue(type, value);
5875 if (value_string == NULL)
5878 if (type & TYPE_KEY)
5880 xpos = MENU_SCREEN_START_XPOS;
5882 if (type & TYPE_QUERY)
5883 value_string = "<press key>";
5885 else if (type & TYPE_STRING)
5887 int max_value_len = (SCR_FIELDX - 2) * 2;
5889 xpos = MENU_SCREEN_START_XPOS;
5891 if (strlen(value_string) > max_value_len)
5892 value_string[max_value_len] = '\0';
5894 else if (type & TYPE_YES_NO_AUTO)
5896 xpos = menu_screen_value_xpos - 1;
5899 startx = mSX + xpos * 32;
5900 starty = mSY + ypos * 32;
5901 font_nr_default = getSetupValueFont(type, value);
5902 font_width_default = getFontWidth(font_nr_default);
5904 font_nr = font_nr_default;
5906 // special check if right-side setup values moved left due to scrollbar
5907 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5909 int max_menu_text_length = 26; // maximum text length for classic menu
5910 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5911 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5912 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5913 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5914 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5916 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5919 startx = mSX + xpos * 32;
5921 font_nr = getSetupValueFontNarrow(type, font_nr);
5925 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5926 if (setup_mode != SETUP_MODE_INPUT)
5928 int max_menu_text_length_big = (menu_screen_value_xpos -
5929 MENU_SCREEN_START_XPOS);
5930 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5931 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5932 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5933 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5934 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5935 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5936 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5937 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5938 boolean correct_font_draw_xoffset = FALSE;
5940 if (xpos == MENU_SCREEN_START_XPOS &&
5941 startx + font1_xoffset < text_startx + text_font_xoffset)
5942 correct_font_draw_xoffset = TRUE;
5944 if (xpos == menu_screen_value_xpos &&
5945 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5946 correct_font_draw_xoffset = TRUE;
5948 /* check if setup value would overlap with setup text when printed */
5949 /* (this can happen for extreme/wrong values for font draw offset) */
5950 if (correct_font_draw_xoffset)
5952 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5953 font_draw_xoffset_modified = TRUE;
5955 if (type & TYPE_KEY)
5956 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5957 else if (!(type & TYPE_STRING))
5958 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5959 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5963 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5964 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
5966 DrawText(startx, starty, value_string, font_nr);
5968 if (font_draw_xoffset_modified)
5969 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5972 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5974 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5975 struct TokenInfo *si = &setup_info[si_pos];
5977 if (si->type & TYPE_BOOLEAN_STYLE)
5979 *(boolean *)si->value ^= TRUE;
5981 else if (si->type & TYPE_YES_NO_AUTO)
5985 (*(int *)si->value == AUTO ? TRUE :
5986 *(int *)si->value == TRUE ? FALSE : AUTO) :
5987 (*(int *)si->value == TRUE ? AUTO :
5988 *(int *)si->value == AUTO ? FALSE : TRUE));
5990 else if (si->type & TYPE_KEY)
5994 si->type |= TYPE_QUERY;
5995 drawSetupValue(screen_pos, setup_info_pos_raw);
5996 si->type &= ~TYPE_QUERY;
5998 key = getSetupKey();
5999 if (key != KSYM_UNDEFINED)
6000 *(Key *)si->value = key;
6003 drawSetupValue(screen_pos, setup_info_pos_raw);
6005 // fullscreen state may have changed at this point
6006 if (si->value == &setup.fullscreen)
6007 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6010 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6012 static struct TokenInfo *setup_info_hide = NULL;
6017 /* determine maximum list size of target list */
6018 while (setup_info_orig[list_size++].type != 0);
6020 /* free, allocate and clear memory for target list */
6021 checked_free(setup_info_hide);
6022 setup_info_hide = checked_calloc(list_size * sizeof(struct TokenInfo));
6024 /* copy setup info list without setup entries marked as hidden */
6025 for (i = 0; setup_info_orig[i].type != 0; i++)
6026 if (!hideSetupEntry(setup_info_orig[i].value))
6027 setup_info_hide[list_pos++] = setup_info_orig[i];
6029 return setup_info_hide;
6032 static void DrawSetupScreen_Generic()
6034 int fade_mask = REDRAW_FIELD;
6035 boolean redraw_all = FALSE;
6036 char *title_string = NULL;
6039 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6040 fade_mask = REDRAW_ALL;
6043 FadeMenuSoundsAndMusic();
6045 FreeScreenGadgets();
6046 CreateScreenGadgets();
6048 if (redraw_mask & REDRAW_ALL)
6053 /* needed if different viewport properties defined for setup screen */
6054 ChangeViewportPropertiesIfNeeded();
6056 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6060 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6062 if (setup_mode == SETUP_MODE_MAIN)
6064 setup_info = setup_info_main;
6065 title_string = STR_SETUP_MAIN;
6067 else if (setup_mode == SETUP_MODE_GAME)
6069 setup_info = setup_info_game;
6070 title_string = STR_SETUP_GAME;
6072 else if (setup_mode == SETUP_MODE_EDITOR)
6074 setup_info = setup_info_editor;
6075 title_string = STR_SETUP_EDITOR;
6077 else if (setup_mode == SETUP_MODE_GRAPHICS)
6079 setup_info = setup_info_graphics;
6080 title_string = STR_SETUP_GRAPHICS;
6082 else if (setup_mode == SETUP_MODE_SOUND)
6084 setup_info = setup_info_sound;
6085 title_string = STR_SETUP_SOUND;
6087 else if (setup_mode == SETUP_MODE_ARTWORK)
6089 setup_info = setup_info_artwork;
6090 title_string = STR_SETUP_ARTWORK;
6092 else if (setup_mode == SETUP_MODE_TOUCH)
6094 setup_info = setup_info_touch;
6095 title_string = STR_SETUP_TOUCH;
6097 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6098 setup_info = setup_info_touch_wipe_gestures;
6100 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6102 setup_info = setup_info_shortcuts;
6103 title_string = STR_SETUP_SHORTCUTS;
6105 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6107 setup_info = setup_info_shortcuts_1;
6108 title_string = STR_SETUP_SHORTCUTS;
6110 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6112 setup_info = setup_info_shortcuts_2;
6113 title_string = STR_SETUP_SHORTCUTS;
6115 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6117 setup_info = setup_info_shortcuts_3;
6118 title_string = STR_SETUP_SHORTCUTS;
6120 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6122 setup_info = setup_info_shortcuts_4;
6123 title_string = STR_SETUP_SHORTCUTS;
6125 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6127 setup_info = setup_info_shortcuts_5;
6128 title_string = STR_SETUP_SHORTCUTS;
6131 /* use modified setup info without setup entries marked as hidden */
6132 setup_info = getSetupInfoFinal(setup_info);
6134 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6136 // determine maximal number of setup entries that can be displayed on screen
6138 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6141 // determine maximal number of setup entries available for this setup screen
6143 for (i = 0; setup_info[i].type != 0; i++)
6146 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6148 MapScreenGadgets(max_setup_info);
6151 redraw_mask = fade_mask = REDRAW_ALL;
6153 DrawMaskedBorder(fade_mask);
6158 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6160 menu_info = setup_info;
6162 HandleMenuScreen(mx, my, dx, dy, button,
6163 setup_mode, num_setup_info, max_setup_info);
6166 void DrawSetupScreen_Input()
6170 FadeOut(REDRAW_FIELD);
6174 setup_info = setup_info_input;
6176 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6178 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6180 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6181 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6182 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6183 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6184 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6185 initCursor(i, IMG_MENU_BUTTON);
6187 DrawCursorAndText_Setup(i, -1, FALSE);
6190 /* create gadgets for setup input menu screen */
6191 FreeScreenGadgets();
6192 CreateScreenGadgets();
6194 /* map gadgets for setup input menu screen */
6195 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6197 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6199 FadeIn(REDRAW_FIELD);
6202 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6204 if (device_name == NULL)
6207 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6210 if (strlen(device_name) > 1)
6212 char c1 = device_name[strlen(device_name) - 1];
6213 char c2 = device_name[strlen(device_name) - 2];
6215 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6216 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6219 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6220 strlen(device_name));
6223 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6226 static struct SetupKeyboardInfo custom_key;
6233 { &custom_key.left, "Axis/Pad Left" },
6234 { &custom_key.right, "Axis/Pad Right" },
6235 { &custom_key.up, "Axis/Pad Up" },
6236 { &custom_key.down, "Axis/Pad Down" },
6237 { &custom_key.snap, "Button 1/A/X" },
6238 { &custom_key.drop, "Button 2/B/Y" }
6240 static char *joystick_name[MAX_PLAYERS] =
6247 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6249 custom_key = setup.input[player_nr].key;
6251 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6252 FONT_INPUT_1_ACTIVE);
6254 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6256 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6257 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6259 if (setup.input[player_nr].use_joystick)
6261 char *device_name = setup.input[player_nr].joy.device_name;
6262 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6263 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6264 char *text = joystick_name[joystick_nr];
6265 int font_nr = (joystick_active ? FONT_VALUE_1 : FONT_VALUE_OLD);
6267 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6268 DrawText(mSX + 32, mSY + 4 * 32, "Configure", text_font_nr);
6272 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6273 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6276 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6278 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6279 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6280 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6281 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6283 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6284 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6285 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6286 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6287 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6288 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6290 for (i = 0; i < 6; i++)
6292 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6294 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6296 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6297 (setup.input[player_nr].use_joystick ?
6299 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6303 static int input_player_nr = 0;
6305 void HandleSetupScreen_Input_Player(int step, int direction)
6307 int old_player_nr = input_player_nr;
6310 new_player_nr = old_player_nr + step * direction;
6311 if (new_player_nr < 0)
6313 if (new_player_nr > MAX_PLAYERS - 1)
6314 new_player_nr = MAX_PLAYERS - 1;
6316 if (new_player_nr != old_player_nr)
6318 input_player_nr = new_player_nr;
6320 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6324 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6326 static int choice = 0;
6329 int pos_start = SETUPINPUT_SCREEN_POS_START;
6330 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6331 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6332 int pos_end = SETUPINPUT_SCREEN_POS_END;
6334 if (button == MB_MENU_INITIALIZE)
6336 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6338 DrawCursorAndText_Setup(choice, -1, TRUE);
6342 else if (button == MB_MENU_LEAVE)
6344 setup_mode = SETUP_MODE_MAIN;
6351 if (mx || my) /* mouse input */
6353 x = (mx - mSX) / 32;
6354 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6356 else if (dx || dy) /* keyboard input */
6358 if (dx && choice == 0)
6359 x = (dx < 0 ? 10 : 12);
6360 else if ((dx && choice == 1) ||
6361 (dx == -1 && choice == pos_end))
6362 button = MB_MENU_CHOICE;
6366 if (y >= pos_empty1 && y <= pos_empty2)
6367 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6370 if (y == 0 && dx != 0 && button)
6372 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6374 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6375 y >= pos_start && y <= pos_end &&
6376 !(y >= pos_empty1 && y <= pos_empty2))
6382 DrawCursorAndText_Setup(choice, -1, FALSE);
6383 DrawCursorAndText_Setup(y, -1, TRUE);
6385 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6394 char *device_name = setup.input[input_player_nr].joy.device_name;
6396 if (!setup.input[input_player_nr].use_joystick)
6398 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6400 setJoystickDeviceToNr(device_name, new_device_nr);
6401 setup.input[input_player_nr].use_joystick = TRUE;
6405 int device_nr = getJoystickNrFromDeviceName(device_name);
6406 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6408 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6409 setup.input[input_player_nr].use_joystick = FALSE;
6411 setJoystickDeviceToNr(device_name, new_device_nr);
6414 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6418 if (setup.input[input_player_nr].use_joystick)
6419 ConfigureJoystick(input_player_nr);
6421 CustomizeKeyboard(input_player_nr);
6423 else if (y == pos_end)
6429 setup_mode = SETUP_MODE_MAIN;
6436 void CustomizeKeyboard(int player_nr)
6440 boolean finished = FALSE;
6441 static struct SetupKeyboardInfo custom_key;
6446 } customize_step[] =
6448 { &custom_key.left, "Move Left" },
6449 { &custom_key.right, "Move Right" },
6450 { &custom_key.up, "Move Up" },
6451 { &custom_key.down, "Move Down" },
6452 { &custom_key.snap, "Snap Field" },
6453 { &custom_key.drop, "Drop Element" }
6456 /* read existing key bindings from player setup */
6457 custom_key = setup.input[player_nr].key;
6460 FadeOut(REDRAW_FIELD);
6464 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6467 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6468 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6469 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6470 "Key:", FONT_INPUT_1_ACTIVE);
6471 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6472 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6474 FadeIn(REDRAW_FIELD);
6480 if (NextValidEvent(&event))
6484 case EVENT_KEYPRESS:
6486 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6488 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6490 if (key == KSYM_Escape)
6491 FadeSkipNextFadeIn();
6497 /* all keys configured -- wait for "Escape" or "Return" key */
6501 /* press 'Enter' to keep the existing key binding */
6502 if (key == KSYM_Return)
6503 key = *customize_step[step_nr].key;
6505 /* check if key already used */
6506 for (i = 0; i < step_nr; i++)
6507 if (*customize_step[i].key == key)
6512 /* got new key binding */
6513 *customize_step[step_nr].key = key;
6514 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6516 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6517 getKeyNameFromKey(key), FONT_VALUE_1);
6520 /* un-highlight last query */
6521 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6522 customize_step[step_nr - 1].text, FONT_MENU_1);
6523 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6524 "Key:", FONT_MENU_1);
6526 /* press 'Enter' to leave */
6529 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6530 "Press Enter", FONT_TITLE_1);
6534 /* query next key binding */
6535 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6536 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6537 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6538 "Key:", FONT_INPUT_1_ACTIVE);
6539 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6540 getKeyNameFromKey(*customize_step[step_nr].key),
6545 case EVENT_KEYRELEASE:
6546 key_joystick_mapping = 0;
6550 HandleOtherEvents(&event);
6558 /* write new key bindings back to player setup */
6559 setup.input[player_nr].key = custom_key;
6561 DrawSetupScreen_Input();
6564 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
6566 #define MARKER_BUTTON 1
6567 #define MARKER_AXIS_X 2
6568 #define MARKER_AXIS_Y 3
6570 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
6572 #if defined(TARGET_SDL2)
6573 static boolean bitmaps_initialized = FALSE;
6574 boolean screen_initialized = FALSE;
6575 static Bitmap *controller, *button, *axis_x, *axis_y;
6577 boolean success = TRUE;
6578 boolean done = FALSE, next = FALSE;
6580 int alpha = 200, alpha_step = -1;
6581 int alpha_ticks = 0;
6582 char mapping[4096], temp[4096];
6583 int font_name = MENU_SETUP_FONT_TITLE;
6584 int font_info = MENU_SETUP_FONT_TEXT;
6585 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
6586 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
6587 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
6588 int ystep_name = getMenuTextStep(spacing_name, font_name);
6589 int ystep_line = getMenuTextStep(spacing_line, font_info);
6590 int ystep_para = getMenuTextStep(spacing_para, font_info);
6598 int axis, button, hat, hat_value;
6601 *step, *prev_step, steps[] =
6603 { 356, 155, MARKER_BUTTON, "a", },
6604 { 396, 122, MARKER_BUTTON, "b", },
6605 { 320, 125, MARKER_BUTTON, "x", },
6606 { 358, 95, MARKER_BUTTON, "y", },
6607 { 162, 125, MARKER_BUTTON, "back", },
6608 { 216, 125, MARKER_BUTTON, "guide", },
6609 { 271, 125, MARKER_BUTTON, "start", },
6610 { 110, 200, MARKER_BUTTON, "dpleft", },
6611 { 146, 228, MARKER_BUTTON, "dpdown", },
6612 { 178, 200, MARKER_BUTTON, "dpright", },
6613 { 146, 172, MARKER_BUTTON, "dpup", },
6614 { 50, 40, MARKER_BUTTON, "leftshoulder", },
6615 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
6616 { 382, 40, MARKER_BUTTON, "rightshoulder", },
6617 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
6618 { 73, 141, MARKER_BUTTON, "leftstick", },
6619 { 282, 210, MARKER_BUTTON, "rightstick", },
6620 { 73, 141, MARKER_AXIS_X, "leftx", },
6621 { 73, 141, MARKER_AXIS_Y, "lefty", },
6622 { 282, 210, MARKER_AXIS_X, "rightx", },
6623 { 282, 210, MARKER_AXIS_Y, "righty", },
6626 unsigned int event_frame_delay = 0;
6627 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
6629 ResetDelayCounter(&event_frame_delay);
6631 if (!bitmaps_initialized)
6633 controller = LoadCustomImage("joystick/controller.png");
6634 button = LoadCustomImage("joystick/button.png");
6635 axis_x = LoadCustomImage("joystick/axis_x.png");
6636 axis_y = LoadCustomImage("joystick/axis_y.png");
6638 bitmaps_initialized = TRUE;
6641 name = getFormattedJoystickName(SDL_JoystickName(joystick));
6644 /* print info about the joystick we are watching */
6645 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
6646 SDL_JoystickInstanceID(joystick), name);
6647 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
6648 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
6649 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
6652 /* initialize mapping with GUID and name */
6653 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
6655 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
6656 temp, name, SDL_GetPlatform());
6658 /* loop through all steps (buttons and axes), getting joystick events */
6659 for (i = 0; i < SDL_arraysize(steps) && !done;)
6661 Bitmap *marker = button; /* initialize with reliable default value */
6664 strcpy(step->mapping, mapping);
6668 step->hat_value = -1;
6670 marker = (step->marker == MARKER_BUTTON ? button :
6671 step->marker == MARKER_AXIS_X ? axis_x :
6672 step->marker == MARKER_AXIS_Y ? axis_y : marker);
6676 while (!done && !next)
6678 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
6679 alpha_ticks = SDL_GetTicks();
6686 else if (alpha < 128)
6692 int controller_x = SX + (SXSIZE - controller->width) / 2;
6693 int controller_y = SY + ystep_line;
6695 int marker_x = controller_x + step->x;
6696 int marker_y = controller_y + step->y;
6698 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
6699 int ystart2 = ystart1 + ystep_name + ystep_line;
6703 DrawTextSCentered(ystart1, font_name, name);
6705 DrawTextSCentered(ystart2, font_info,
6706 "Press buttons and move axes on");
6707 ystart2 += ystep_line;
6708 DrawTextSCentered(ystart2, font_info,
6709 "your controller when indicated.");
6710 ystart2 += ystep_line;
6711 DrawTextSCentered(ystart2, font_info,
6712 "(Your controller may look different.)");
6713 ystart2 += ystep_para;
6715 #if defined(PLATFORM_ANDROID)
6716 DrawTextSCentered(ystart2, font_info,
6717 "To correct a mistake,");
6718 ystart2 += ystep_line;
6719 DrawTextSCentered(ystart2, font_info,
6720 "press the 'back' button.");
6721 ystart2 += ystep_line;
6722 DrawTextSCentered(ystart2, font_info,
6723 "To skip a button or axis,");
6724 ystart2 += ystep_line;
6725 DrawTextSCentered(ystart2, font_info,
6726 "press the 'menu' button.");
6728 DrawTextSCentered(ystart2, font_info,
6729 "To correct a mistake,");
6730 ystart2 += ystep_line;
6731 DrawTextSCentered(ystart2, font_info,
6732 "press the 'backspace' key.");
6733 ystart2 += ystep_line;
6734 DrawTextSCentered(ystart2, font_info,
6735 "To skip a button or axis,");
6736 ystart2 += ystep_line;
6737 DrawTextSCentered(ystart2, font_info,
6738 "press the 'return' key.");
6739 ystart2 += ystep_line;
6740 DrawTextSCentered(ystart2, font_info,
6741 "To exit, press the 'escape' key.");
6744 BlitBitmapMasked(controller, drawto, 0, 0,
6745 controller->width, controller->height,
6746 controller_x, controller_y);
6748 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
6750 BlitBitmapMasked(marker, drawto, 0, 0,
6751 marker->width, marker->height,
6752 marker_x, marker_y);
6754 if (!screen_initialized)
6755 FadeIn(REDRAW_FIELD);
6759 screen_initialized = TRUE;
6761 while (NextValidEvent(&event))
6765 case SDL_JOYAXISMOTION:
6766 if (event.jaxis.value > 20000 ||
6767 event.jaxis.value < -20000)
6769 for (j = 0; j < i; j++)
6770 if (steps[j].axis == event.jaxis.axis)
6775 if (step->marker != MARKER_AXIS_X &&
6776 step->marker != MARKER_AXIS_Y)
6779 step->axis = event.jaxis.axis;
6780 strcat(mapping, step->field);
6781 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
6782 strcat(mapping, temp);
6790 case SDL_JOYHATMOTION:
6791 /* ignore centering; we're probably just coming back
6792 to the center from the previous item we set */
6793 if (event.jhat.value == SDL_HAT_CENTERED)
6796 for (j = 0; j < i; j++)
6797 if (steps[j].hat == event.jhat.hat &&
6798 steps[j].hat_value == event.jhat.value)
6803 step->hat = event.jhat.hat;
6804 step->hat_value = event.jhat.value;
6805 strcat(mapping, step->field);
6806 snprintf(temp, sizeof(temp), ":h%u.%u,",
6807 event.jhat.hat, event.jhat.value );
6808 strcat(mapping, temp);
6815 case SDL_JOYBALLMOTION:
6818 case SDL_JOYBUTTONUP:
6819 for (j = 0; j < i; j++)
6820 if (steps[j].button == event.jbutton.button)
6825 step->button = event.jbutton.button;
6826 strcat(mapping, step->field);
6827 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
6828 strcat(mapping, temp);
6835 case SDL_FINGERDOWN:
6836 case SDL_MOUSEBUTTONDOWN:
6837 /* skip this step */
6844 if (event.key.keysym.sym == KSYM_BackSpace ||
6845 event.key.keysym.sym == KSYM_Back)
6854 /* undo this step */
6855 prev_step = &steps[i - 1];
6856 strcpy(mapping, prev_step->mapping);
6863 if (event.key.keysym.sym == KSYM_space ||
6864 event.key.keysym.sym == KSYM_Return ||
6865 event.key.keysym.sym == KSYM_Menu)
6867 /* skip this step */
6874 if (event.key.keysym.sym == KSYM_Escape)
6884 program.exit_function(0);
6891 // do not handle events for longer than standard frame delay period
6892 if (DelayReached(&event_frame_delay, event_frame_delay_value))
6901 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
6904 // activate mapping for this game
6905 SDL_GameControllerAddMapping(mapping);
6907 // save mapping to personal mappings
6908 SaveSetup_AddGameControllerMapping(mapping);
6911 /* wait until the last pending event was removed from event queue */
6912 while (NextValidEvent(&event));
6920 static int ConfigureJoystickMain(int player_nr)
6922 char *device_name = setup.input[player_nr].joy.device_name;
6923 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6924 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6925 int success = FALSE;
6928 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6929 return JOYSTICK_NOT_AVAILABLE;
6931 if (!joystick_active || !setup.input[player_nr].use_joystick)
6932 return JOYSTICK_NOT_AVAILABLE;
6935 FadeOut(REDRAW_FIELD);
6937 // close all joystick devices (potentially opened as game controllers)
6938 for (i = 0; i < SDL_NumJoysticks(); i++)
6939 SDLCloseJoystick(i);
6941 // open joystick device as plain joystick to configure as game controller
6942 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
6944 // as the joystick was successfully opened before, this should not happen
6945 if (joystick == NULL)
6948 // create new game controller mapping (buttons and axes) for joystick device
6949 success = ConfigureJoystickMapButtonsAndAxes(joystick);
6951 // close joystick (and maybe re-open as configured game controller later)
6952 SDL_JoystickClose(joystick);
6954 // re-open all joystick devices (potentially as game controllers)
6955 for (i = 0; i < SDL_NumJoysticks(); i++)
6958 // clear all joystick input actions for all joystick devices
6959 SDLClearJoystickState();
6961 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
6964 void ConfigureJoystick(int player_nr)
6966 boolean state = ConfigureJoystickMain(player_nr);
6968 if (state != JOYSTICK_NOT_CONFIGURED)
6970 boolean success = (state == JOYSTICK_CONFIGURED);
6971 char *message = (success ? " IS CONFIGURED! " : " NOT AVAILABLE! ");
6972 char *device_name = setup.input[player_nr].joy.device_name;
6973 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6974 int xpos = mSX - SX;
6975 int ypos = mSY - SY;
6976 unsigned int wait_frame_delay = 0;
6977 unsigned int wait_frame_delay_value = 2000;
6979 ResetDelayCounter(&wait_frame_delay);
6983 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6984 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, message);
6986 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
6992 DrawSetupScreen_Input();
6995 void DrawSetupScreen()
6997 if (setup_mode == SETUP_MODE_INPUT)
6998 DrawSetupScreen_Input();
6999 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7000 DrawChooseTree(&game_speed_current);
7001 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7002 DrawChooseTree(&scroll_delay_current);
7003 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7004 DrawChooseTree(&snapshot_mode_current);
7005 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7006 DrawChooseTree(&window_size_current);
7007 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7008 DrawChooseTree(&scaling_type_current);
7009 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7010 DrawChooseTree(&rendering_mode_current);
7011 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7012 DrawChooseTree(&artwork.gfx_current);
7013 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7014 DrawChooseTree(&artwork.snd_current);
7015 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7016 DrawChooseTree(&artwork.mus_current);
7017 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7018 DrawChooseTree(&volume_simple_current);
7019 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7020 DrawChooseTree(&volume_loops_current);
7021 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7022 DrawChooseTree(&volume_music_current);
7023 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7024 DrawChooseTree(&touch_control_current);
7025 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7026 DrawChooseTree(&move_distance_current);
7027 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7028 DrawChooseTree(&drop_distance_current);
7030 DrawSetupScreen_Generic();
7032 PlayMenuSoundsAndMusic();
7035 void RedrawSetupScreenAfterFullscreenToggle()
7037 if (setup_mode == SETUP_MODE_GRAPHICS ||
7038 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7040 // update list selection from "setup.window_scaling_percent"
7041 execSetupGraphics_setWindowSizes(TRUE);
7047 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7049 if (setup_mode == SETUP_MODE_INPUT)
7050 HandleSetupScreen_Input(mx, my, dx, dy, button);
7051 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7052 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7053 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7054 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7055 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7056 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7057 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7058 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7059 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7060 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7061 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7062 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7063 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7064 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7065 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7066 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7067 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7068 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7069 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7070 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7071 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7072 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7073 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7074 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7075 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7076 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7077 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7078 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7079 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7080 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7082 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7085 void HandleGameActions()
7087 if (game_status != GAME_MODE_PLAYING)
7090 GameActions(); /* main game loop */
7092 if (tape.auto_play && !tape.playing)
7093 AutoPlayTape(); /* continue automatically playing next tape */
7097 /* ---------- new screen button stuff -------------------------------------- */
7099 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7103 case SCREEN_CTRL_ID_PREV_LEVEL:
7104 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7105 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7108 case SCREEN_CTRL_ID_NEXT_LEVEL:
7109 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7110 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7113 case SCREEN_CTRL_ID_PREV_PLAYER:
7114 *x = mSX + TILEX * 10;
7115 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7118 case SCREEN_CTRL_ID_NEXT_PLAYER:
7119 *x = mSX + TILEX * 12;
7120 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7124 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7130 int gfx_unpressed, gfx_pressed;
7131 void (*get_gadget_position)(int *, int *, int);
7135 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7138 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7139 getScreenMenuButtonPos,
7140 SCREEN_CTRL_ID_PREV_LEVEL,
7145 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7146 getScreenMenuButtonPos,
7147 SCREEN_CTRL_ID_NEXT_LEVEL,
7152 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7153 getScreenMenuButtonPos,
7154 SCREEN_CTRL_ID_PREV_PLAYER,
7159 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7160 getScreenMenuButtonPos,
7161 SCREEN_CTRL_ID_NEXT_PLAYER,
7169 int gfx_unpressed, gfx_pressed;
7173 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7176 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7177 -1, -1, /* these values are not constant, but can change at runtime */
7178 SCREEN_CTRL_ID_SCROLL_UP,
7182 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7183 -1, -1, /* these values are not constant, but can change at runtime */
7184 SCREEN_CTRL_ID_SCROLL_DOWN,
7191 int gfx_unpressed, gfx_pressed;
7197 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7200 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7201 -1, -1, /* these values are not constant, but can change at runtime */
7202 -1, -1, /* these values are not constant, but can change at runtime */
7203 GD_TYPE_SCROLLBAR_VERTICAL,
7204 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7205 "scroll level series vertically"
7209 static void CreateScreenMenubuttons()
7211 struct GadgetInfo *gi;
7212 unsigned int event_mask;
7215 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7217 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7218 int gfx_unpressed, gfx_pressed;
7219 int x, y, width, height;
7220 int gd_x1, gd_x2, gd_y1, gd_y2;
7221 int id = menubutton_info[i].gadget_id;
7223 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7225 menubutton_info[i].get_gadget_position(&x, &y, id);
7227 width = SC_MENUBUTTON_XSIZE;
7228 height = SC_MENUBUTTON_YSIZE;
7230 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7231 gfx_pressed = menubutton_info[i].gfx_pressed;
7232 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7233 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7234 gd_x1 = graphic_info[gfx_unpressed].src_x;
7235 gd_y1 = graphic_info[gfx_unpressed].src_y;
7236 gd_x2 = graphic_info[gfx_pressed].src_x;
7237 gd_y2 = graphic_info[gfx_pressed].src_y;
7239 gi = CreateGadget(GDI_CUSTOM_ID, id,
7240 GDI_CUSTOM_TYPE_ID, i,
7241 GDI_INFO_TEXT, menubutton_info[i].infotext,
7246 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7247 GDI_STATE, GD_BUTTON_UNPRESSED,
7248 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7249 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7250 GDI_DIRECT_DRAW, FALSE,
7251 GDI_EVENT_MASK, event_mask,
7252 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7256 Error(ERR_EXIT, "cannot create gadget");
7258 screen_gadget[id] = gi;
7262 static void CreateScreenScrollbuttons()
7264 struct GadgetInfo *gi;
7265 unsigned int event_mask;
7268 /* these values are not constant, but can change at runtime */
7269 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7270 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7271 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7272 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7274 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7276 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7277 int gfx_unpressed, gfx_pressed;
7278 int x, y, width, height;
7279 int gd_x1, gd_x2, gd_y1, gd_y2;
7280 int id = scrollbutton_info[i].gadget_id;
7282 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7284 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7285 y = mSY + scrollbutton_info[i].y;
7286 width = SC_SCROLLBUTTON_XSIZE;
7287 height = SC_SCROLLBUTTON_YSIZE;
7289 /* correct scrollbar position if placed outside menu (playfield) area */
7290 if (x > SX + SC_SCROLL_UP_XPOS)
7291 x = SX + SC_SCROLL_UP_XPOS;
7293 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7294 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7295 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7297 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7298 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7299 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7300 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7301 gd_x1 = graphic_info[gfx_unpressed].src_x;
7302 gd_y1 = graphic_info[gfx_unpressed].src_y;
7303 gd_x2 = graphic_info[gfx_pressed].src_x;
7304 gd_y2 = graphic_info[gfx_pressed].src_y;
7306 gi = CreateGadget(GDI_CUSTOM_ID, id,
7307 GDI_CUSTOM_TYPE_ID, i,
7308 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7313 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7314 GDI_STATE, GD_BUTTON_UNPRESSED,
7315 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7316 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7317 GDI_DIRECT_DRAW, FALSE,
7318 GDI_EVENT_MASK, event_mask,
7319 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7323 Error(ERR_EXIT, "cannot create gadget");
7325 screen_gadget[id] = gi;
7329 static void CreateScreenScrollbars()
7333 /* these values are not constant, but can change at runtime */
7334 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7335 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7336 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7337 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7339 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7341 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7342 int gfx_unpressed, gfx_pressed;
7343 int x, y, width, height;
7344 int gd_x1, gd_x2, gd_y1, gd_y2;
7345 struct GadgetInfo *gi;
7346 int items_max, items_visible, item_position;
7347 unsigned int event_mask;
7348 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7349 int id = scrollbar_info[i].gadget_id;
7351 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7353 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7354 y = mSY + scrollbar_info[i].y;
7355 width = scrollbar_info[i].width;
7356 height = scrollbar_info[i].height;
7358 /* correct scrollbar position if placed outside menu (playfield) area */
7359 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
7360 x = SX + SC_SCROLL_VERTICAL_XPOS;
7362 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7363 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7365 items_max = num_page_entries;
7366 items_visible = num_page_entries;
7369 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7370 gfx_pressed = scrollbar_info[i].gfx_pressed;
7371 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7372 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7373 gd_x1 = graphic_info[gfx_unpressed].src_x;
7374 gd_y1 = graphic_info[gfx_unpressed].src_y;
7375 gd_x2 = graphic_info[gfx_pressed].src_x;
7376 gd_y2 = graphic_info[gfx_pressed].src_y;
7378 gi = CreateGadget(GDI_CUSTOM_ID, id,
7379 GDI_CUSTOM_TYPE_ID, i,
7380 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7385 GDI_TYPE, scrollbar_info[i].type,
7386 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7387 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7388 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7389 GDI_WHEEL_AREA_X, SX,
7390 GDI_WHEEL_AREA_Y, SY,
7391 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7392 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7393 GDI_STATE, GD_BUTTON_UNPRESSED,
7394 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7395 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7396 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7397 GDI_DIRECT_DRAW, FALSE,
7398 GDI_EVENT_MASK, event_mask,
7399 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7403 Error(ERR_EXIT, "cannot create gadget");
7405 screen_gadget[id] = gi;
7409 void CreateScreenGadgets()
7411 CreateScreenMenubuttons();
7413 CreateScreenScrollbuttons();
7414 CreateScreenScrollbars();
7417 void FreeScreenGadgets()
7421 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7422 FreeGadget(screen_gadget[i]);
7425 void MapScreenMenuGadgets(int screen_mask)
7429 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7430 if (screen_mask & menubutton_info[i].screen_mask)
7431 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7434 void MapScreenGadgets(int num_entries)
7438 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7441 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7442 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7444 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7445 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7448 void MapScreenTreeGadgets(TreeInfo *ti)
7450 MapScreenGadgets(numTreeInfoInGroup(ti));
7453 static void HandleScreenGadgets(struct GadgetInfo *gi)
7455 int id = gi->custom_id;
7456 int button = gi->event.button;
7457 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7461 case SCREEN_CTRL_ID_PREV_LEVEL:
7462 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
7465 case SCREEN_CTRL_ID_NEXT_LEVEL:
7466 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
7469 case SCREEN_CTRL_ID_PREV_PLAYER:
7470 HandleSetupScreen_Input_Player(step, -1);
7473 case SCREEN_CTRL_ID_NEXT_PLAYER:
7474 HandleSetupScreen_Input_Player(step, +1);
7477 case SCREEN_CTRL_ID_SCROLL_UP:
7478 if (game_status == GAME_MODE_LEVELS)
7479 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7480 else if (game_status == GAME_MODE_LEVELNR)
7481 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7482 else if (game_status == GAME_MODE_SETUP)
7483 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7484 else if (game_status == GAME_MODE_INFO)
7485 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7488 case SCREEN_CTRL_ID_SCROLL_DOWN:
7489 if (game_status == GAME_MODE_LEVELS)
7490 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7491 else if (game_status == GAME_MODE_LEVELNR)
7492 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7493 else if (game_status == GAME_MODE_SETUP)
7494 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7495 else if (game_status == GAME_MODE_INFO)
7496 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7499 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7500 if (game_status == GAME_MODE_LEVELS)
7501 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7502 else if (game_status == GAME_MODE_LEVELNR)
7503 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7504 else if (game_status == GAME_MODE_SETUP)
7505 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7506 else if (game_status == GAME_MODE_INFO)
7507 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);