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"
26 /* screens on the info screen */
27 #define INFO_MODE_MAIN 0
28 #define INFO_MODE_TITLE 1
29 #define INFO_MODE_ELEMENTS 2
30 #define INFO_MODE_MUSIC 3
31 #define INFO_MODE_CREDITS 4
32 #define INFO_MODE_PROGRAM 5
33 #define INFO_MODE_VERSION 6
34 #define INFO_MODE_LEVELSET 7
36 #define MAX_INFO_MODES 8
38 /* screens on the setup screen */
39 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
40 /* (should also match corresponding entries in src/conf_gfx.c) */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_TOUCH 7
49 #define SETUP_MODE_SHORTCUTS 8
50 #define SETUP_MODE_SHORTCUTS_1 9
51 #define SETUP_MODE_SHORTCUTS_2 10
52 #define SETUP_MODE_SHORTCUTS_3 11
53 #define SETUP_MODE_SHORTCUTS_4 12
54 #define SETUP_MODE_SHORTCUTS_5 13
56 /* sub-screens on the setup screen (generic) */
57 #define SETUP_MODE_CHOOSE_ARTWORK 14
58 #define SETUP_MODE_CHOOSE_OTHER 15
60 /* sub-screens on the setup screen (specific) */
61 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
64 #define SETUP_MODE_CHOOSE_SCREEN_MODE 19
65 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
66 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
67 #define SETUP_MODE_CHOOSE_GRAPHICS 22
68 #define SETUP_MODE_CHOOSE_SOUNDS 23
69 #define SETUP_MODE_CHOOSE_MUSIC 24
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
73 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
74 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
75 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
77 #define MAX_SETUP_MODES 31
79 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
81 /* for input setup functions */
82 #define SETUPINPUT_SCREEN_POS_START 0
83 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
84 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
85 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
87 /* for various menu stuff */
88 #define MENU_SCREEN_START_XPOS 1
89 #define MENU_SCREEN_START_YPOS 2
90 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
91 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
103 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
104 MENU_SCREEN_INFO_YSTEP)
105 #define NUM_INFO_ELEMENTS_FROM_CONF \
106 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
107 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
108 MAX_MENU_ENTRIES_ON_SCREEN)
109 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
110 MAX_INFO_ELEMENTS_ON_SCREEN), \
111 NUM_INFO_ELEMENTS_FROM_CONF)
112 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
113 #define MAX_MENU_TEXT_LENGTH_BIG 13
114 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
116 /* buttons and scrollbars identifiers */
117 #define SCREEN_CTRL_ID_PREV_LEVEL 0
118 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
119 #define SCREEN_CTRL_ID_PREV_PLAYER 2
120 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
121 #define SCREEN_CTRL_ID_SCROLL_UP 4
122 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
123 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
125 #define NUM_SCREEN_GADGETS 7
127 #define NUM_SCREEN_MENUBUTTONS 4
128 #define NUM_SCREEN_SCROLLBUTTONS 2
129 #define NUM_SCREEN_SCROLLBARS 1
131 #define SCREEN_MASK_MAIN (1 << 0)
132 #define SCREEN_MASK_INPUT (1 << 1)
134 /* graphic position and size values for buttons and scrollbars */
135 #define SC_MENUBUTTON_XSIZE TILEX
136 #define SC_MENUBUTTON_YSIZE TILEY
138 #define SC_SCROLLBUTTON_XSIZE TILEX
139 #define SC_SCROLLBUTTON_YSIZE TILEY
141 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
143 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
144 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
145 SC_SCROLLBUTTON_YSIZE)
147 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
148 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
150 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
151 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
152 SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
156 SC_SCROLL_VERTICAL_YSIZE)
158 #define SC_BORDER_SIZE 14
161 /* forward declarations of internal functions */
162 static void HandleScreenGadgets(struct GadgetInfo *);
163 static void HandleSetupScreen_Generic(int, int, int, int, int);
164 static void HandleSetupScreen_Input(int, int, int, int, int);
165 static void CustomizeKeyboard(int);
166 static void CalibrateJoystick(int);
167 static void execSetupGame(void);
168 static void execSetupGraphics(void);
169 static void execSetupSound(void);
170 static void execSetupTouch(void);
171 static void execSetupArtwork(void);
172 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
174 static void DrawChooseLevelSet(void);
175 static void DrawChooseLevelNr(void);
176 static void DrawInfoScreen(void);
177 static void DrawSetupScreen(void);
179 static void DrawInfoScreen_NotAvailable(char *, char *);
180 static void DrawInfoScreen_HelpAnim(int, int, boolean);
181 static void DrawInfoScreen_HelpText(int, int, int, int);
182 static void HandleInfoScreen_Main(int, int, int, int, int);
183 static void HandleInfoScreen_TitleScreen(int);
184 static void HandleInfoScreen_Elements(int);
185 static void HandleInfoScreen_Music(int);
186 static void HandleInfoScreen_Credits(int);
187 static void HandleInfoScreen_Program(int);
188 static void HandleInfoScreen_Version(int);
190 static void MapScreenMenuGadgets(int);
191 static void MapScreenGadgets(int);
192 static void MapScreenTreeGadgets(TreeInfo *);
194 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
196 static int info_mode = INFO_MODE_MAIN;
197 static int setup_mode = SETUP_MODE_MAIN;
199 static TreeInfo *screen_modes = NULL;
200 static TreeInfo *screen_mode_current = NULL;
202 static TreeInfo *window_sizes = NULL;
203 static TreeInfo *window_size_current = NULL;
205 static TreeInfo *scaling_types = NULL;
206 static TreeInfo *scaling_type_current = NULL;
208 static TreeInfo *scroll_delays = NULL;
209 static TreeInfo *scroll_delay_current = NULL;
211 static TreeInfo *snapshot_modes = NULL;
212 static TreeInfo *snapshot_mode_current = NULL;
214 static TreeInfo *game_speeds = NULL;
215 static TreeInfo *game_speed_current = NULL;
217 static TreeInfo *volumes_simple = NULL;
218 static TreeInfo *volume_simple_current = NULL;
220 static TreeInfo *volumes_loops = NULL;
221 static TreeInfo *volume_loops_current = NULL;
223 static TreeInfo *volumes_music = NULL;
224 static TreeInfo *volume_music_current = NULL;
226 static TreeInfo *touch_controls = NULL;
227 static TreeInfo *touch_control_current = NULL;
229 static TreeInfo *move_distances = NULL;
230 static TreeInfo *move_distance_current = NULL;
232 static TreeInfo *drop_distances = NULL;
233 static TreeInfo *drop_distance_current = NULL;
235 static TreeInfo *level_number = NULL;
236 static TreeInfo *level_number_current = NULL;
238 static unsigned int sync_frame_delay = 0;
239 static unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
245 } window_sizes_list[] =
250 { 100, "100 % (Default)" },
267 } scaling_types_list[] =
269 { SCALING_QUALITY_NEAREST, "None" },
270 { SCALING_QUALITY_LINEAR, "Linear" },
271 { SCALING_QUALITY_BEST, "Anisotropic" },
280 } game_speeds_list[] =
289 { 1000, "1/1s (Extremely Slow)" },
294 { 29, "1/35s (Original Supaplex)" },
296 { 20, "1/50s (Normal Speed)" },
297 { 14, "1/70s (Maximum Supaplex)" },
301 { 1, "1/1000s (Extremely Fast)" },
311 } scroll_delays_list[] =
313 { 0, "0 Tiles (No Scroll Delay)" },
316 { 3, "3 Tiles (Default)" },
321 { 8, "8 Tiles (Maximum Scroll Delay)"},
330 } snapshot_modes_list[] =
332 { STR_SNAPSHOT_MODE_OFF, "Off" },
333 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
334 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
335 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
368 } touch_controls_list[] =
370 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
371 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
395 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
396 (s) <= GAME_MODE_SETUP ? (s) : \
397 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
398 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
400 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
401 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
402 (i) <= INFO_MODE_LEVELSET ? (i) : \
405 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
406 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
407 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
408 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
409 SETUP_MODE_CHOOSE_ARTWORK : \
410 SETUP_MODE_CHOOSE_OTHER)
412 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
413 menu.draw_xoffset[GAME_MODE_INFO] : \
414 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
415 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
416 menu.draw_yoffset[GAME_MODE_INFO] : \
417 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
419 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
420 menu.draw_xoffset[GAME_MODE_SETUP] : \
421 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
422 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
423 menu.draw_yoffset[GAME_MODE_SETUP] : \
424 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
426 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
427 DRAW_XOFFSET_INFO(info_mode) : \
428 (s) == GAME_MODE_SETUP ? \
429 DRAW_XOFFSET_SETUP(setup_mode) : \
430 menu.draw_xoffset[DRAW_MODE(s)])
431 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
432 DRAW_YOFFSET_INFO(info_mode) : \
433 (s) == GAME_MODE_SETUP ? \
434 DRAW_YOFFSET_SETUP(setup_mode) : \
435 menu.draw_yoffset[DRAW_MODE(s)])
437 #define mSX (SX + DRAW_XOFFSET(game_status))
438 #define mSY (SY + DRAW_YOFFSET(game_status))
440 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
441 menu.list_size[game_status] : \
442 MAX_MENU_ENTRIES_ON_SCREEN)
444 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
445 NUM_MENU_ENTRIES_ON_SCREEN)
448 /* title display and control definitions */
450 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
451 2 * MAX_NUM_TITLE_MESSAGES)
453 #define NO_DIRECT_LEVEL_SELECT (-1)
456 static int num_title_screens = 0;
458 struct TitleControlInfo
467 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
469 /* main menu display and control definitions */
471 #define MAIN_CONTROL_NAME 0
472 #define MAIN_CONTROL_LEVELS 1
473 #define MAIN_CONTROL_SCORES 2
474 #define MAIN_CONTROL_EDITOR 3
475 #define MAIN_CONTROL_INFO 4
476 #define MAIN_CONTROL_GAME 5
477 #define MAIN_CONTROL_SETUP 6
478 #define MAIN_CONTROL_QUIT 7
479 #define MAIN_CONTROL_PREV_LEVEL 8
480 #define MAIN_CONTROL_NEXT_LEVEL 9
481 #define MAIN_CONTROL_FIRST_LEVEL 10
482 #define MAIN_CONTROL_LAST_LEVEL 11
483 #define MAIN_CONTROL_LEVEL_NUMBER 12
484 #define MAIN_CONTROL_LEVEL_INFO_1 13
485 #define MAIN_CONTROL_LEVEL_INFO_2 14
486 #define MAIN_CONTROL_LEVEL_NAME 15
487 #define MAIN_CONTROL_LEVEL_AUTHOR 16
488 #define MAIN_CONTROL_LEVEL_YEAR 17
489 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
490 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
491 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
492 #define MAIN_CONTROL_TITLE_1 21
493 #define MAIN_CONTROL_TITLE_2 22
494 #define MAIN_CONTROL_TITLE_3 23
496 static char str_main_text_name[10];
497 static char str_main_text_first_level[10];
498 static char str_main_text_last_level[10];
499 static char str_main_text_level_number[10];
501 static char *main_text_name = str_main_text_name;
502 static char *main_text_first_level = str_main_text_first_level;
503 static char *main_text_last_level = str_main_text_last_level;
504 static char *main_text_level_number = str_main_text_level_number;
505 static char *main_text_levels = "Levelset";
506 static char *main_text_scores = "Hall Of Fame";
507 static char *main_text_editor = "Level Creator";
508 static char *main_text_info = "Info Screen";
509 static char *main_text_game = "Start Game";
510 static char *main_text_setup = "Setup";
511 static char *main_text_quit = "Quit";
512 static char *main_text_level_name = level.name;
513 static char *main_text_level_author = level.author;
514 static char *main_text_level_year = NULL;
515 static char *main_text_level_imported_from = NULL;
516 static char *main_text_level_imported_by = NULL;
517 static char *main_text_level_tested_by = NULL;
519 struct MainControlInfo
523 struct MenuPosInfo *pos_button;
526 struct TextPosInfo *pos_text;
529 struct TextPosInfo *pos_input;
533 static struct MainControlInfo main_controls[] =
537 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
538 &menu.main.text.name, &main_text_name,
539 &menu.main.input.name, &setup.player_name,
543 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
544 &menu.main.text.levels, &main_text_levels,
549 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
550 &menu.main.text.scores, &main_text_scores,
555 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
556 &menu.main.text.editor, &main_text_editor,
561 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
562 &menu.main.text.info, &main_text_info,
567 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
568 &menu.main.text.game, &main_text_game,
573 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
574 &menu.main.text.setup, &main_text_setup,
579 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
580 &menu.main.text.quit, &main_text_quit,
584 /* (these two buttons are real gadgets) */
586 MAIN_CONTROL_PREV_LEVEL,
587 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
592 MAIN_CONTROL_NEXT_LEVEL,
593 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
599 MAIN_CONTROL_FIRST_LEVEL,
601 &menu.main.text.first_level, &main_text_first_level,
605 MAIN_CONTROL_LAST_LEVEL,
607 &menu.main.text.last_level, &main_text_last_level,
611 MAIN_CONTROL_LEVEL_NUMBER,
613 &menu.main.text.level_number, &main_text_level_number,
617 MAIN_CONTROL_LEVEL_INFO_1,
619 &menu.main.text.level_info_1, NULL,
623 MAIN_CONTROL_LEVEL_INFO_2,
625 &menu.main.text.level_info_2, NULL,
629 MAIN_CONTROL_LEVEL_NAME,
631 &menu.main.text.level_name, &main_text_level_name,
635 MAIN_CONTROL_LEVEL_AUTHOR,
637 &menu.main.text.level_author, &main_text_level_author,
641 MAIN_CONTROL_LEVEL_YEAR,
643 &menu.main.text.level_year, &main_text_level_year,
647 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
649 &menu.main.text.level_imported_from, &main_text_level_imported_from,
653 MAIN_CONTROL_LEVEL_IMPORTED_BY,
655 &menu.main.text.level_imported_by, &main_text_level_imported_by,
659 MAIN_CONTROL_LEVEL_TESTED_BY,
661 &menu.main.text.level_tested_by, &main_text_level_tested_by,
665 MAIN_CONTROL_TITLE_1,
667 &menu.main.text.title_1, &setup.internal.program_title,
671 MAIN_CONTROL_TITLE_2,
673 &menu.main.text.title_2, &setup.internal.program_copyright,
677 MAIN_CONTROL_TITLE_3,
679 &menu.main.text.title_3, &setup.internal.program_company,
692 static int getTitleScreenGraphic(int nr, boolean initial)
694 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
697 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
699 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
703 static int getTitleScreenGameMode(boolean initial)
705 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
709 static int getTitleMessageGameMode(boolean initial)
711 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
715 static int getTitleScreenBackground(boolean initial)
717 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
722 static int getTitleMessageBackground(int nr, boolean initial)
724 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
728 static int getTitleBackground(int nr, boolean initial, boolean is_image)
730 int base = (is_image ?
731 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
732 IMG_BACKGROUND_TITLESCREEN_1) :
733 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
734 IMG_BACKGROUND_TITLEMESSAGE_1));
735 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
736 IMG_BACKGROUND_TITLE);
737 int graphic_local = base + nr;
739 if (graphic_info[graphic_local].bitmap != NULL)
740 return graphic_local;
742 if (graphic_info[graphic_global].bitmap != NULL)
743 return graphic_global;
745 return IMG_UNDEFINED;
748 static int getTitleSound(struct TitleControlInfo *tci)
750 boolean is_image = tci->is_image;
751 int initial = tci->initial;
752 int nr = tci->local_nr;
753 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
754 int base = (is_image ?
755 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
756 SND_BACKGROUND_TITLESCREEN_1) :
757 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
758 SND_BACKGROUND_TITLEMESSAGE_1));
759 int sound_global = menu.sound[mode];
760 int sound_local = base + nr;
763 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
764 nr, initial, is_image,
765 sound_global, getSoundListEntry(sound_global)->filename,
766 sound_local, getSoundListEntry(sound_local)->filename);
769 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
772 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
775 return SND_UNDEFINED;
778 static int getTitleMusic(struct TitleControlInfo *tci)
780 boolean is_image = tci->is_image;
781 int initial = tci->initial;
782 int nr = tci->local_nr;
783 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
784 int base = (is_image ?
785 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
786 MUS_BACKGROUND_TITLESCREEN_1) :
787 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
788 MUS_BACKGROUND_TITLEMESSAGE_1));
789 int music_global = menu.music[mode];
790 int music_local = base + nr;
793 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
794 nr, initial, is_image,
795 music_global, getMusicListEntry(music_global)->filename,
796 music_local, getMusicListEntry(music_local)->filename);
799 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
802 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
805 return MUS_UNDEFINED;
808 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
810 boolean is_image = tci->is_image;
811 boolean initial = tci->initial;
812 boolean first = tci->first;
813 int nr = tci->local_nr;
814 struct TitleMessageInfo tmi;
815 struct TitleFadingInfo ti;
817 tmi = (is_image ? (initial ? (first ?
818 titlescreen_initial_first[nr] :
819 titlescreen_initial[nr])
821 titlescreen_first[nr] :
823 : (initial ? (first ?
824 titlemessage_initial_first[nr] :
825 titlemessage_initial[nr])
827 titlemessage_first[nr] :
830 ti.fade_mode = tmi.fade_mode;
831 ti.fade_delay = tmi.fade_delay;
832 ti.post_delay = tmi.post_delay;
833 ti.auto_delay = tmi.auto_delay;
838 static int compareTitleControlInfo(const void *object1, const void *object2)
840 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
841 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
844 if (tci1->initial != tci2->initial)
845 compare_result = (tci1->initial ? -1 : +1);
846 else if (tci1->sort_priority != tci2->sort_priority)
847 compare_result = tci1->sort_priority - tci2->sort_priority;
848 else if (tci1->is_image != tci2->is_image)
849 compare_result = (tci1->is_image ? -1 : +1);
851 compare_result = tci1->local_nr - tci2->local_nr;
853 return compare_result;
856 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
858 int nr, int sort_priority)
860 title_controls[num_title_screens].is_image = is_image;
861 title_controls[num_title_screens].initial = initial;
862 title_controls[num_title_screens].local_nr = nr;
863 title_controls[num_title_screens].sort_priority = sort_priority;
865 title_controls[num_title_screens].first = FALSE; /* will be set later */
870 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
874 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
876 int graphic = getTitleScreenGraphic(i, initial);
877 Bitmap *bitmap = graphic_info[graphic].bitmap;
878 int sort_priority = graphic_info[graphic].sort_priority;
881 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
884 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
886 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
887 char *filename = getLevelSetTitleMessageFilename(i, initial);
888 int sort_priority = tmi->sort_priority;
890 if (filename != NULL)
891 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
895 static void InitializeTitleControls(boolean show_title_initial)
897 num_title_screens = 0;
899 /* 1st step: initialize title screens for game start (only when starting) */
900 if (show_title_initial)
901 InitializeTitleControls_CheckTitleInfo(TRUE);
903 /* 2nd step: initialize title screens for current level set */
904 InitializeTitleControls_CheckTitleInfo(FALSE);
906 /* sort title screens according to sort_priority and title number */
907 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
908 compareTitleControlInfo);
910 /* mark first title screen */
911 title_controls[0].first = TRUE;
914 static boolean visibleMenuPos(struct MenuPosInfo *pos)
916 return (pos != NULL && pos->x != -1 && pos->y != -1);
919 static boolean visibleTextPos(struct TextPosInfo *pos)
921 return (pos != NULL && pos->x != -1 && pos->y != -1);
924 static void InitializeMainControls()
926 boolean local_team_mode = (!options.network && setup.team_mode);
929 /* set main control text values to dynamically determined values */
930 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
932 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
933 menu.main.text.first_level.size));
934 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
935 menu.main.text.last_level.size));
936 strcpy(main_text_level_number, int2str(level_nr,
937 menu.main.text.level_number.size));
939 main_text_level_year = leveldir_current->year;
940 main_text_level_imported_from = leveldir_current->imported_from;
941 main_text_level_imported_by = leveldir_current->imported_by;
942 main_text_level_tested_by = leveldir_current->tested_by;
944 /* set main control screen positions to dynamically determined values */
945 for (i = 0; main_controls[i].nr != -1; i++)
947 struct MainControlInfo *mci = &main_controls[i];
949 struct MenuPosInfo *pos_button = mci->pos_button;
950 struct TextPosInfo *pos_text = mci->pos_text;
951 struct TextPosInfo *pos_input = mci->pos_input;
952 char *text = (mci->text ? *mci->text : NULL);
953 char *input = (mci->input ? *mci->input : NULL);
954 int button_graphic = mci->button_graphic;
955 int font_text = (pos_text ? pos_text->font : -1);
956 int font_input = (pos_input ? pos_input->font : -1);
958 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
959 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
960 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
961 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
962 int text_chars = (text != NULL ? strlen(text) : 0);
963 int input_chars = (input != NULL ? strlen(input) : 0);
966 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
968 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
969 int text_width = font_text_width * text_chars;
970 int text_height = font_text_height;
971 int input_width = font_input_width * input_chars;
972 int input_height = font_input_height;
974 if (nr == MAIN_CONTROL_NAME)
976 menu.main.input.name.width = input_width;
977 menu.main.input.name.height = input_height;
980 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
982 pos_button->width = button_width;
983 pos_button->height = button_height;
986 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
988 /* calculate size for non-clickable text -- needed for text alignment */
989 boolean calculate_text_size = (pos_button == NULL && text != NULL);
991 if (pos_text->width == -1 || calculate_text_size)
992 pos_text->width = text_width;
993 if (pos_text->height == -1 || calculate_text_size)
994 pos_text->height = text_height;
996 if (visibleMenuPos(pos_button))
998 if (pos_text->x == -1)
999 pos_text->x = pos_button->x + pos_button->width;
1000 if (pos_text->y == -1)
1002 pos_button->y + (pos_button->height - pos_text->height) / 2;
1006 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1008 if (visibleTextPos(pos_text))
1010 if (pos_input->x == -1)
1011 pos_input->x = pos_text->x + pos_text->width;
1012 if (pos_input->y == -1)
1013 pos_input->y = pos_text->y;
1016 if (pos_input->width == -1)
1017 pos_input->width = input_width;
1018 if (pos_input->height == -1)
1019 pos_input->height = input_height;
1024 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1025 int graphic, boolean pressed)
1027 struct GraphicInfo *g = &graphic_info[graphic];
1030 int xoffset = (pressed ? g->pressed_xoffset : 0);
1031 int yoffset = (pressed ? g->pressed_yoffset : 0);
1033 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1035 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1036 g->width, g->height, dst_x, dst_y);
1039 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1040 boolean active_input,
1041 boolean pressed_button)
1045 for (i = 0; main_controls[i].nr != -1; i++)
1047 struct MainControlInfo *mci = &main_controls[i];
1049 if (mci->nr == nr || nr == -1)
1051 struct MenuPosInfo *pos_button = mci->pos_button;
1052 struct TextPosInfo *pos_text = mci->pos_text;
1053 struct TextPosInfo *pos_input = mci->pos_input;
1054 char *text = (mci->text ? *mci->text : NULL);
1055 char *input = (mci->input ? *mci->input : NULL);
1056 int button_graphic = mci->button_graphic;
1057 int font_text = (pos_text ? pos_text->font : -1);
1058 int font_input = (pos_input ? pos_input->font : -1);
1062 button_graphic = BUTTON_ACTIVE(button_graphic);
1063 font_text = FONT_ACTIVE(font_text);
1068 font_input = FONT_ACTIVE(font_input);
1071 if (visibleMenuPos(pos_button))
1073 struct MenuPosInfo *pos = pos_button;
1074 int x = mSX + pos->x;
1075 int y = mSY + pos->y;
1077 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1078 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1081 if (visibleTextPos(pos_text) && text != NULL)
1083 struct TextPosInfo *pos = pos_text;
1084 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1085 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1088 /* (check why/if this is needed) */
1089 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1091 DrawText(x, y, text, font_text);
1094 if (visibleTextPos(pos_input) && input != NULL)
1096 struct TextPosInfo *pos = pos_input;
1097 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1098 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1101 /* (check why/if this is needed) */
1102 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1104 DrawText(x, y, input, font_input);
1110 static void DrawCursorAndText_Main(int nr, boolean active_text,
1111 boolean pressed_button)
1113 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1117 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1118 boolean pressed_button)
1120 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1124 static struct MainControlInfo *getMainControlInfo(int nr)
1128 for (i = 0; main_controls[i].nr != -1; i++)
1129 if (main_controls[i].nr == nr)
1130 return &main_controls[i];
1135 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1140 int rect_x = ALIGNED_TEXT_XPOS(rect);
1141 int rect_y = ALIGNED_TEXT_YPOS(rect);
1143 return (x >= rect_x && x < rect_x + rect->width &&
1144 y >= rect_y && y < rect_y + rect->height);
1147 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1152 int rect_x = ALIGNED_TEXT_XPOS(rect);
1153 int rect_y = ALIGNED_TEXT_YPOS(rect);
1156 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1157 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1158 (x >= rect_x && x < rect_x + rect->width &&
1159 y >= rect_y && y < rect_y + rect->height));
1162 return (x >= rect_x && x < rect_x + rect->width &&
1163 y >= rect_y && y < rect_y + rect->height);
1166 static void AdjustScrollbar(int id, int items_max, int items_visible,
1169 struct GadgetInfo *gi = screen_gadget[id];
1171 if (item_position > items_max - items_visible)
1172 item_position = items_max - items_visible;
1174 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1175 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1176 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1179 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1181 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1185 static void clearMenuListArea()
1187 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1189 /* correct scrollbar position if placed outside menu (playfield) area */
1190 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1191 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1193 /* clear menu list area, but not title or scrollbar */
1194 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1195 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1198 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1200 static int cursor_array[MAX_LEV_FIELDY];
1201 int x = mSX + TILEX * xpos;
1202 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1207 cursor_array[ypos] = graphic;
1209 graphic = cursor_array[ypos];
1213 graphic = BUTTON_ACTIVE(graphic);
1215 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1216 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1219 static void initCursor(int ypos, int graphic)
1221 drawCursorExt(0, ypos, FALSE, graphic);
1224 static void drawCursor(int ypos, boolean active)
1226 drawCursorExt(0, ypos, active, -1);
1229 static void drawCursorXY(int xpos, int ypos, int graphic)
1231 drawCursorExt(xpos, ypos, FALSE, graphic);
1234 static void drawChooseTreeCursor(int ypos, boolean active)
1236 int last_game_status = game_status; /* save current game status */
1238 drawCursorExt(0, ypos, active, -1);
1240 SetGameStatus(last_game_status); /* restore current game status */
1245 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1246 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1247 setup.internal.program_copyright);
1250 void DrawTitleScreenImage(int nr, boolean initial)
1252 int graphic = getTitleScreenGraphic(nr, initial);
1253 Bitmap *bitmap = graphic_info[graphic].bitmap;
1254 int width = graphic_info[graphic].width;
1255 int height = graphic_info[graphic].height;
1256 int src_x = graphic_info[graphic].src_x;
1257 int src_y = graphic_info[graphic].src_y;
1263 if (width > WIN_XSIZE)
1265 /* image width too large for window => center image horizontally */
1266 src_x = (width - WIN_XSIZE) / 2;
1270 if (height > WIN_YSIZE)
1272 /* image height too large for window => center image vertically */
1273 src_y = (height - WIN_YSIZE) / 2;
1277 /* always display title screens centered */
1278 dst_x = (WIN_XSIZE - width) / 2;
1279 dst_y = (WIN_YSIZE - height) / 2;
1281 SetDrawBackgroundMask(REDRAW_ALL);
1282 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1284 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1286 if (DrawingOnBackground(dst_x, dst_y))
1287 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1289 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1291 redraw_mask = REDRAW_ALL;
1294 void DrawTitleScreenMessage(int nr, boolean initial)
1296 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1297 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1298 int last_game_status = game_status; /* save current game status */
1300 if (filename == NULL)
1303 /* force TITLE font on title message screen */
1304 SetGameStatus(getTitleMessageGameMode(initial));
1306 /* if chars *and* width set to "-1", automatically determine width */
1307 if (tmi->chars == -1 && tmi->width == -1)
1308 tmi->width = viewport.window[game_status].width;
1310 /* if lines *and* height set to "-1", automatically determine height */
1311 if (tmi->lines == -1 && tmi->height == -1)
1312 tmi->height = viewport.window[game_status].height;
1314 /* if chars set to "-1", automatically determine by text and font width */
1315 if (tmi->chars == -1)
1316 tmi->chars = tmi->width / getFontWidth(tmi->font);
1318 tmi->width = tmi->chars * getFontWidth(tmi->font);
1320 /* if lines set to "-1", automatically determine by text and font height */
1321 if (tmi->lines == -1)
1322 tmi->lines = tmi->height / getFontHeight(tmi->font);
1324 tmi->height = tmi->lines * getFontHeight(tmi->font);
1326 /* if x set to "-1", automatically determine by width and alignment */
1328 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1330 /* if y set to "-1", automatically determine by height and alignment */
1332 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1334 SetDrawBackgroundMask(REDRAW_ALL);
1335 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1337 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1339 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1340 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1341 tmi->autowrap, tmi->centered, tmi->parse_comments);
1343 SetGameStatus(last_game_status); /* restore current game status */
1346 void DrawTitleScreen()
1348 KeyboardAutoRepeatOff();
1350 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1355 boolean CheckTitleScreen(boolean levelset_has_changed)
1357 static boolean show_title_initial = TRUE;
1358 boolean show_titlescreen = FALSE;
1360 /* needed to be able to skip title screen, if no image or message defined */
1361 InitializeTitleControls(show_title_initial);
1363 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1364 show_titlescreen = TRUE;
1366 /* show initial title images and messages only once at program start */
1367 show_title_initial = FALSE;
1369 return (show_titlescreen && num_title_screens > 0);
1374 static LevelDirTree *leveldir_last_valid = NULL;
1375 boolean levelset_has_changed = FALSE;
1376 int fade_mask = REDRAW_FIELD;
1378 LimitScreenUpdates(FALSE);
1380 FadeSetLeaveScreen();
1382 /* do not fade out here -- function may continue and fade on editor screen */
1385 FadeSoundsAndMusic();
1387 KeyboardAutoRepeatOn();
1390 audio.sound_deactivated = FALSE;
1394 /* needed if last screen was the playing screen, invoked from level editor */
1395 if (level_editor_test_game)
1397 CloseDoor(DOOR_CLOSE_ALL);
1399 SetGameStatus(GAME_MODE_EDITOR);
1406 /* needed if last screen was the setup screen and fullscreen state changed */
1407 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1408 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1410 /* leveldir_current may be invalid (level group, parent link) */
1411 if (!validLevelSeries(leveldir_current))
1412 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1414 if (leveldir_current != leveldir_last_valid)
1415 levelset_has_changed = TRUE;
1417 /* store valid level series information */
1418 leveldir_last_valid = leveldir_current;
1420 init_last = init; /* switch to new busy animation */
1422 /* needed if last screen (level choice) changed graphics, sounds or music */
1423 ReloadCustomArtwork(0);
1425 if (CheckTitleScreen(levelset_has_changed))
1427 game_status_last_screen = GAME_MODE_MAIN;
1429 SetGameStatus(GAME_MODE_TITLE);
1436 /* needed if different viewport properties defined for menues */
1437 ChangeViewportPropertiesIfNeeded();
1439 if (redraw_mask & REDRAW_ALL)
1440 fade_mask = REDRAW_ALL;
1442 if (CheckIfGlobalBorderHasChanged())
1443 fade_mask = REDRAW_ALL;
1447 SetDrawtoField(DRAW_BACKBUFFER);
1449 /* level_nr may have been set to value over handicap with level editor */
1450 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1451 level_nr = leveldir_current->handicap_level;
1453 LoadLevel(level_nr);
1454 LoadScore(level_nr);
1456 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1457 SetDrawDeactivationMask(REDRAW_NONE);
1458 SetDrawBackgroundMask(REDRAW_FIELD);
1460 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1463 if (fade_mask == REDRAW_ALL)
1464 RedrawGlobalBorder();
1469 InitializeMainControls();
1471 DrawCursorAndText_Main(-1, FALSE, FALSE);
1472 DrawPreviewLevelInitial();
1474 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1477 if (TAPE_IS_EMPTY(tape))
1479 DrawCompleteVideoDisplay();
1484 /* create gadgets for main menu screen */
1485 FreeScreenGadgets();
1486 CreateScreenGadgets();
1488 /* map gadgets for main menu screen */
1490 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1492 /* copy actual game door content to door double buffer for OpenDoor() */
1493 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1494 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1496 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1498 DrawMaskedBorder(fade_mask);
1503 /* update screen area with special editor door */
1504 redraw_mask |= REDRAW_ALL;
1507 SetMouseCursor(CURSOR_DEFAULT);
1511 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1514 static void gotoTopLevelDir()
1516 /* move upwards until inside (but not above) top level directory */
1517 while (leveldir_current->node_parent &&
1518 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1520 /* write a "path" into level tree for easy navigation to last level */
1521 if (leveldir_current->node_parent->node_group->cl_first == -1)
1523 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1524 int leveldir_pos = posTreeInfo(leveldir_current);
1525 int num_page_entries;
1526 int cl_first, cl_cursor;
1528 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1529 num_page_entries = num_leveldirs;
1531 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1533 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1534 cl_cursor = leveldir_pos - cl_first;
1536 leveldir_current->node_parent->node_group->cl_first = cl_first;
1537 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1540 leveldir_current = leveldir_current->node_parent;
1544 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1546 static unsigned int title_delay = 0;
1547 static int title_screen_nr = 0;
1548 static int last_sound = -1, last_music = -1;
1549 boolean return_to_main_menu = FALSE;
1550 struct TitleControlInfo *tci;
1553 if (button == MB_MENU_INITIALIZE)
1556 title_screen_nr = 0;
1557 tci = &title_controls[title_screen_nr];
1559 last_sound = SND_UNDEFINED;
1560 last_music = MUS_UNDEFINED;
1562 if (num_title_screens != 0)
1564 FadeSetEnterScreen();
1566 /* use individual title fading instead of global "enter screen" fading */
1567 fading = getTitleFading(tci);
1570 if (game_status_last_screen == GAME_MODE_INFO)
1572 if (num_title_screens == 0)
1574 /* switch game mode from title screen mode back to info screen mode */
1575 SetGameStatus(GAME_MODE_INFO);
1577 DrawInfoScreen_NotAvailable("Title screen information:",
1578 "No title screen for this level set.");
1583 FadeSoundsAndMusic();
1586 FadeOut(REDRAW_ALL);
1588 /* only required to update logic for redrawing global border */
1591 /* title screens may have different window size */
1592 ChangeViewportPropertiesIfNeeded();
1595 DrawTitleScreenImage(tci->local_nr, tci->initial);
1597 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1599 sound = getTitleSound(tci);
1600 music = getTitleMusic(tci);
1602 if (sound != last_sound)
1603 PlayMenuSoundExt(sound);
1604 if (music != last_music)
1605 PlayMenuMusicExt(music);
1610 SetMouseCursor(CURSOR_NONE);
1614 DelayReached(&title_delay, 0); /* reset delay counter */
1619 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1620 button = MB_MENU_CHOICE;
1622 if (button == MB_MENU_LEAVE)
1624 return_to_main_menu = TRUE;
1626 else if (button == MB_MENU_CHOICE)
1628 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1630 SetGameStatus(GAME_MODE_INFO);
1632 info_mode = INFO_MODE_MAIN;
1640 tci = &title_controls[title_screen_nr];
1642 if (title_screen_nr < num_title_screens)
1644 sound = getTitleSound(tci);
1645 music = getTitleMusic(tci);
1647 if (sound == SND_UNDEFINED || sound != last_sound)
1649 if (music == MUS_UNDEFINED || music != last_music)
1652 fading = getTitleFading(tci);
1654 FadeOut(REDRAW_ALL);
1657 DrawTitleScreenImage(tci->local_nr, tci->initial);
1659 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1661 sound = getTitleSound(tci);
1662 music = getTitleMusic(tci);
1664 if (sound != last_sound)
1665 PlayMenuSoundExt(sound);
1666 if (music != last_music)
1667 PlayMenuMusicExt(music);
1674 DelayReached(&title_delay, 0); /* reset delay counter */
1678 FadeSoundsAndMusic();
1680 return_to_main_menu = TRUE;
1684 if (return_to_main_menu)
1686 SetMouseCursor(CURSOR_DEFAULT);
1688 /* force full menu screen redraw after displaying title screens */
1689 redraw_mask = REDRAW_ALL;
1691 if (game_status_last_screen == GAME_MODE_INFO)
1693 SetGameStatus(GAME_MODE_INFO);
1695 info_mode = INFO_MODE_MAIN;
1699 else /* default: return to main menu */
1701 SetGameStatus(GAME_MODE_MAIN);
1708 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1710 int old_level_nr = level_nr;
1713 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1714 new_level_nr = selected_level_nr;
1716 new_level_nr = old_level_nr + step * direction;
1718 if (new_level_nr < leveldir_current->first_level)
1719 new_level_nr = leveldir_current->first_level;
1720 if (new_level_nr > leveldir_current->last_level)
1721 new_level_nr = leveldir_current->last_level;
1723 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1725 /* skipping levels is only allowed when trying to skip single level */
1726 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1727 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1729 leveldir_current->handicap_level++;
1730 SaveLevelSetup_SeriesInfo();
1733 new_level_nr = leveldir_current->handicap_level;
1736 if (new_level_nr != old_level_nr)
1738 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1740 PlaySound(SND_MENU_ITEM_SELECTING);
1742 level_nr = new_level_nr;
1744 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1745 int2str(level_nr, menu.main.text.level_number.size),
1746 mci->pos_text->font);
1748 LoadLevel(level_nr);
1749 DrawPreviewLevelInitial();
1753 DrawCompleteVideoDisplay();
1755 /* needed because DrawPreviewLevelInitial() takes some time */
1757 /* SyncDisplay(); */
1761 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1763 static int choice = MAIN_CONTROL_GAME;
1764 static boolean button_pressed_last = FALSE;
1765 boolean button_pressed = FALSE;
1769 if (button == MB_MENU_INITIALIZE)
1771 DrawCursorAndText_Main(choice, TRUE, FALSE);
1776 if (mx || my) /* mouse input */
1780 for (i = 0; main_controls[i].nr != -1; i++)
1782 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1783 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1784 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1786 pos = main_controls[i].nr;
1792 // handle pressed/unpressed state for active/inactive menu buttons
1793 // (if pos != -1, "i" contains index position corresponding to "pos")
1795 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1796 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1797 button_pressed = TRUE;
1799 if (button_pressed != button_pressed_last)
1801 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1804 PlaySound(SND_MENU_BUTTON_PRESSING);
1806 PlaySound(SND_MENU_BUTTON_RELEASING);
1809 else if (dx || dy) /* keyboard input */
1811 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1812 choice == MAIN_CONTROL_SETUP))
1813 button = MB_MENU_CHOICE;
1818 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1820 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1822 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1824 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1826 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1828 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1830 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1834 CloseDoor(DOOR_CLOSE_2);
1836 SetGameStatus(GAME_MODE_LEVELNR);
1838 ChangeViewportPropertiesIfNeeded();
1840 DrawChooseLevelNr();
1842 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1848 PlaySound(SND_MENU_ITEM_ACTIVATING);
1850 DrawCursorAndText_Main(choice, FALSE, FALSE);
1851 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1858 PlaySound(SND_MENU_ITEM_SELECTING);
1860 if (pos == MAIN_CONTROL_NAME)
1862 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1864 HandleTypeName(strlen(setup.player_name), 0);
1866 else if (pos == MAIN_CONTROL_LEVELS)
1872 CloseDoor(DOOR_CLOSE_2);
1874 SetGameStatus(GAME_MODE_LEVELS);
1876 SaveLevelSetup_LastSeries();
1877 SaveLevelSetup_SeriesInfo();
1879 if (setup.internal.choose_from_top_leveldir)
1882 ChangeViewportPropertiesIfNeeded();
1884 DrawChooseLevelSet();
1887 else if (pos == MAIN_CONTROL_SCORES)
1891 CloseDoor(DOOR_CLOSE_2);
1893 SetGameStatus(GAME_MODE_SCORES);
1897 else if (pos == MAIN_CONTROL_EDITOR)
1899 if (leveldir_current->readonly &&
1900 !strEqual(setup.player_name, "Artsoft"))
1901 Request("This level is read only!", REQ_CONFIRM);
1905 CloseDoor(DOOR_CLOSE_2);
1907 SetGameStatus(GAME_MODE_EDITOR);
1909 FadeSetEnterScreen();
1913 else if (pos == MAIN_CONTROL_INFO)
1917 CloseDoor(DOOR_CLOSE_2);
1919 SetGameStatus(GAME_MODE_INFO);
1921 info_mode = INFO_MODE_MAIN;
1923 ChangeViewportPropertiesIfNeeded();
1927 else if (pos == MAIN_CONTROL_GAME)
1931 StartGameActions(options.network, setup.autorecord, level.random_seed);
1933 else if (pos == MAIN_CONTROL_SETUP)
1937 CloseDoor(DOOR_CLOSE_2);
1939 SetGameStatus(GAME_MODE_SETUP);
1941 setup_mode = SETUP_MODE_MAIN;
1943 ChangeViewportPropertiesIfNeeded();
1947 else if (pos == MAIN_CONTROL_QUIT)
1949 SaveLevelSetup_LastSeries();
1950 SaveLevelSetup_SeriesInfo();
1952 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1953 SetGameStatus(GAME_MODE_QUIT);
1958 button_pressed_last = button_pressed;
1962 /* ========================================================================= */
1963 /* info screen functions */
1964 /* ========================================================================= */
1966 static struct TokenInfo *info_info;
1967 static int num_info_info; /* number of info entries shown on screen */
1968 static int max_info_info; /* total number of info entries in list */
1970 static void execInfoTitleScreen()
1972 info_mode = INFO_MODE_TITLE;
1977 static void execInfoElements()
1979 info_mode = INFO_MODE_ELEMENTS;
1984 static void execInfoMusic()
1986 info_mode = INFO_MODE_MUSIC;
1991 static void execInfoCredits()
1993 info_mode = INFO_MODE_CREDITS;
1998 static void execInfoProgram()
2000 info_mode = INFO_MODE_PROGRAM;
2005 static void execInfoVersion()
2007 info_mode = INFO_MODE_VERSION;
2012 static void execInfoLevelSet()
2014 info_mode = INFO_MODE_LEVELSET;
2019 static void execExitInfo()
2021 SetGameStatus(GAME_MODE_MAIN);
2026 static struct TokenInfo info_info_main[] =
2028 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2029 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2030 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2031 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2032 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2033 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2034 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2035 { TYPE_EMPTY, NULL, "" },
2036 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2041 static int getMenuTextFont(int type)
2043 if (type & (TYPE_SWITCH |
2055 static struct TokenInfo *setup_info;
2056 static struct TokenInfo setup_info_input[];
2058 static struct TokenInfo *menu_info;
2060 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2061 int screen_pos, int menu_info_pos_raw,
2064 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2065 struct TokenInfo *ti = &token_info[pos];
2066 int xpos = MENU_SCREEN_START_XPOS;
2067 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2068 int font_nr = getMenuTextFont(ti->type);
2070 if (token_info == setup_info_input)
2071 font_nr = FONT_MENU_1;
2074 font_nr = FONT_ACTIVE(font_nr);
2076 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2078 if (ti->type & ~TYPE_SKIP_ENTRY)
2079 drawCursor(screen_pos, active);
2082 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2085 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2088 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2091 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2094 static char *screen_mode_text;
2095 static char *window_size_text;
2096 static char *scaling_type_text;
2098 static void drawSetupValue(int, int);
2100 static void drawMenuInfoList(int first_entry, int num_page_entries,
2101 int max_page_entries)
2105 if (first_entry + num_page_entries > max_page_entries)
2108 clearMenuListArea();
2110 for (i = 0; i < num_page_entries; i++)
2112 int menu_info_pos = first_entry + i;
2113 struct TokenInfo *si = &menu_info[menu_info_pos];
2114 void *value_ptr = si->value;
2116 /* set some entries to "unchangeable" according to other variables */
2117 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2118 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2119 (value_ptr == &setup.sound_music && !audio.music_available) ||
2120 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2121 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2122 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2123 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2124 si->type |= TYPE_GHOSTED;
2126 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2127 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2128 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2129 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2130 else if (si->type & ~TYPE_SKIP_ENTRY)
2131 initCursor(i, IMG_MENU_BUTTON);
2133 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2135 if (si->type & TYPE_VALUE &&
2136 menu_info == setup_info)
2137 drawSetupValue(i, menu_info_pos);
2141 static void DrawInfoScreen_Main()
2143 int fade_mask = REDRAW_FIELD;
2146 if (redraw_mask & REDRAW_ALL)
2147 fade_mask = REDRAW_ALL;
2149 if (CheckIfGlobalBorderHasChanged())
2150 fade_mask = REDRAW_ALL;
2154 FreeScreenGadgets();
2155 CreateScreenGadgets();
2157 /* (needed after displaying title screens which disable auto repeat) */
2158 KeyboardAutoRepeatOn();
2160 FadeSetLeaveScreen();
2164 ChangeViewportPropertiesIfNeeded();
2168 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2170 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2172 info_info = info_info_main;
2174 // determine maximal number of info entries that can be displayed on screen
2176 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2179 // determine maximal number of info entries available for menu of info screen
2181 for (i = 0; info_info[i].type != 0; i++)
2184 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2186 MapScreenGadgets(max_info_info);
2191 DrawMaskedBorder(fade_mask);
2198 static void changeSetupValue(int, int, int);
2200 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2201 int mode, int num_page_entries, int max_page_entries)
2203 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2204 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2205 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2206 int *num_page_entries_last = num_page_entries_all_last[game_status];
2207 int *choice_store = choice_stores[game_status];
2208 int *first_entry_store = first_entry_stores[game_status];
2209 int choice = choice_store[mode]; /* starts with 0 */
2210 int first_entry = first_entry_store[mode]; /* starts with 0 */
2212 int y = choice - first_entry;
2214 boolean position_set_by_scrollbar = (dx == 999);
2215 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2218 if (button == MB_MENU_INITIALIZE)
2220 // check if number of menu page entries has changed (may happen by change
2221 // of custom artwork definition value for 'list_size' for this menu screen)
2222 // (in this case, the last menu position most probably has to be corrected)
2223 if (num_page_entries != num_page_entries_last[mode])
2225 choice_store[mode] = first_entry_store[mode] = 0;
2227 choice = first_entry = 0;
2230 num_page_entries_last[mode] = num_page_entries;
2233 /* advance to first valid menu entry */
2234 while (choice < num_page_entries &&
2235 menu_info[choice].type & TYPE_SKIP_ENTRY)
2238 if (position_set_by_scrollbar)
2239 first_entry = first_entry_store[mode] = dy;
2241 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2242 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2244 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2246 if (choice < first_entry)
2248 choice = first_entry;
2250 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2253 else if (choice > first_entry + num_page_entries - 1)
2255 choice = first_entry + num_page_entries - 1;
2257 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2261 choice_store[mode] = choice;
2263 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2267 else if (button == MB_MENU_LEAVE)
2269 PlaySound(SND_MENU_ITEM_SELECTING);
2271 for (i = 0; i < max_page_entries; i++)
2273 if (menu_info[i].type & TYPE_LEAVE_MENU)
2275 void (*menu_callback_function)(void) = menu_info[i].value;
2279 menu_callback_function();
2281 break; /* absolutely needed because function changes 'menu_info'! */
2288 if (mx || my) /* mouse input */
2290 x = (mx - mSX) / 32;
2291 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2293 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2295 /* move cursor instead of scrolling when already at start/end of list */
2296 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2298 else if (dy == +1 * SCROLL_LINE &&
2299 first_entry + num_page_entries == max_page_entries)
2302 /* handle scrolling screen one line or page */
2304 y + dy > num_page_entries - 1)
2306 boolean redraw = FALSE;
2308 if (ABS(dy) == SCROLL_PAGE)
2309 step = num_page_entries - 1;
2311 if (dy < 0 && first_entry > 0)
2313 /* scroll page/line up */
2315 first_entry -= step;
2316 if (first_entry < 0)
2321 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2323 /* scroll page/line down */
2325 first_entry += step;
2326 if (first_entry + num_page_entries > max_page_entries)
2327 first_entry = MAX(0, max_page_entries - num_page_entries);
2334 choice += first_entry - first_entry_store[mode];
2336 if (choice < first_entry)
2338 choice = first_entry;
2340 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2343 else if (choice > first_entry + num_page_entries - 1)
2345 choice = first_entry + num_page_entries - 1;
2347 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2350 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2354 if (choice < first_entry ||
2355 choice > first_entry + num_page_entries - 1)
2356 first_entry += SIGN(dy);
2359 first_entry_store[mode] = first_entry;
2360 choice_store[mode] = choice;
2362 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2364 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2366 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2367 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2375 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2377 if (menu_info[choice].type & menu_navigation_type ||
2378 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2379 menu_info[choice].type & TYPE_YES_NO_AUTO)
2380 button = MB_MENU_CHOICE;
2385 /* jump to next non-empty menu entry (up or down) */
2386 while (first_entry + y > 0 &&
2387 first_entry + y < max_page_entries - 1 &&
2388 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2391 if (!IN_VIS_MENU(x, y))
2393 choice += y - y_old;
2395 if (choice < first_entry)
2396 first_entry = choice;
2397 else if (choice > first_entry + num_page_entries - 1)
2398 first_entry = choice - num_page_entries + 1;
2400 if (first_entry >= 0 &&
2401 first_entry + num_page_entries <= max_page_entries)
2403 first_entry_store[mode] = first_entry;
2405 if (choice < first_entry)
2406 choice = first_entry;
2407 else if (choice > first_entry + num_page_entries - 1)
2408 choice = first_entry + num_page_entries - 1;
2410 choice_store[mode] = choice;
2412 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2414 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2416 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2417 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2424 if (!anyScrollbarGadgetActive() &&
2425 IN_VIS_MENU(x, y) &&
2426 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2427 y >= 0 && y < num_page_entries)
2431 if (first_entry + y != choice &&
2432 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2434 PlaySound(SND_MENU_ITEM_ACTIVATING);
2436 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2437 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2439 choice = choice_store[mode] = first_entry + y;
2442 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2444 PlaySound(SND_MENU_ITEM_SELECTING);
2446 /* when selecting key headline, execute function for key value change */
2447 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2448 menu_info[first_entry + y + 1].type & TYPE_KEY)
2451 /* when selecting string value, execute function for list selection */
2452 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2453 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2456 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2458 void (*menu_callback_function)(void) =
2459 menu_info[first_entry + y].value;
2461 FadeSetFromType(menu_info[first_entry + y].type);
2463 menu_callback_function();
2465 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2466 menu_info == setup_info)
2468 changeSetupValue(y, first_entry + y, dx);
2474 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2476 menu_info = info_info;
2478 HandleMenuScreen(mx, my, dx, dy, button,
2479 info_mode, num_info_info, max_info_info);
2482 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2484 int ystart1 = mSY - SY + 100;
2485 int ystart2 = mSY - SY + 150;
2486 int ybottom = mSY - SY + SYSIZE - 20;
2488 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2490 FadeOut(REDRAW_FIELD);
2495 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2496 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2498 DrawTextSCentered(ybottom, FONT_TEXT_4,
2499 "Press any key or button for info menu");
2501 FadeIn(REDRAW_FIELD);
2504 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2506 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2507 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2508 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2509 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2510 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2511 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2512 int ystep = MENU_SCREEN_INFO_YSTEP;
2513 int element, action, direction;
2521 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2522 infoscreen_step[i] = infoscreen_frame[i] = 0;
2527 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2529 DrawTextSCentered(ybottom, FONT_TEXT_4,
2530 "Press any key or button for next page");
2536 while (helpanim_info[j].element != HELPANIM_LIST_END)
2538 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2543 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2552 j += infoscreen_step[i - start];
2554 element = helpanim_info[j].element;
2555 action = helpanim_info[j].action;
2556 direction = helpanim_info[j].direction;
2559 element = EL_UNKNOWN;
2561 if (action != -1 && direction != -1)
2562 graphic = el_act_dir2img(element, action, direction);
2563 else if (action != -1)
2564 graphic = el_act2img(element, action);
2565 else if (direction != -1)
2566 graphic = el_dir2img(element, direction);
2568 graphic = el2img(element);
2570 delay = helpanim_info[j++].delay;
2575 if (infoscreen_frame[i - start] == 0)
2578 infoscreen_frame[i - start] = delay - 1;
2582 sync_frame = delay - infoscreen_frame[i - start];
2583 infoscreen_frame[i - start]--;
2586 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2588 if (!infoscreen_frame[i - start])
2589 infoscreen_step[i - start] = 0;
2593 if (!infoscreen_frame[i - start])
2594 infoscreen_step[i - start]++;
2595 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2601 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2603 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2604 graphic, sync_frame, USE_MASKING);
2607 DrawInfoScreen_HelpText(element, action, direction, i - start);
2612 redraw_mask |= REDRAW_FIELD;
2617 static char *getHelpText(int element, int action, int direction)
2619 char token[MAX_LINE_LEN];
2621 strcpy(token, element_info[element].token_name);
2624 strcat(token, element_action_info[action].suffix);
2626 if (direction != -1)
2627 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2629 return getHashEntry(helptext_info, token);
2632 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2634 int font_nr = FONT_INFO_ELEMENTS;
2635 int font_width = getFontWidth(font_nr);
2636 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2637 int sy = mSY + 65 + 2 * 32 + 1;
2638 int ystep = TILEY + 4;
2639 int pad_x = sx - SX;
2640 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2641 int max_lines_per_text = 2;
2644 if (action != -1 && direction != -1) /* element.action.direction */
2645 text = getHelpText(element, action, direction);
2647 if (text == NULL && action != -1) /* element.action */
2648 text = getHelpText(element, action, -1);
2650 if (text == NULL && direction != -1) /* element.direction */
2651 text = getHelpText(element, -1, direction);
2653 if (text == NULL) /* base element */
2654 text = getHelpText(element, -1, -1);
2656 if (text == NULL) /* not found */
2657 text = "No description available";
2659 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2660 sy += getFontHeight(font_nr) / 2;
2662 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2663 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2664 TRUE, FALSE, FALSE);
2667 void DrawInfoScreen_TitleScreen()
2669 game_status_last_screen = GAME_MODE_INFO;
2671 SetGameStatus(GAME_MODE_TITLE);
2676 void HandleInfoScreen_TitleScreen(int button)
2678 HandleTitleScreen(0, 0, 0, 0, button);
2681 void DrawInfoScreen_Elements()
2683 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2685 FadeOut(REDRAW_FIELD);
2690 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2692 FadeIn(REDRAW_FIELD);
2697 void HandleInfoScreen_Elements(int button)
2699 static unsigned int info_delay = 0;
2700 static int num_anims;
2701 static int num_pages;
2703 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2706 if (button == MB_MENU_INITIALIZE)
2708 boolean new_element = TRUE;
2712 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2714 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2716 else if (new_element)
2719 new_element = FALSE;
2723 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2727 if (button == MB_MENU_LEAVE)
2729 PlaySound(SND_MENU_ITEM_SELECTING);
2731 info_mode = INFO_MODE_MAIN;
2736 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2738 if (button != MB_MENU_INITIALIZE)
2740 PlaySound(SND_MENU_ITEM_SELECTING);
2745 if (page >= num_pages)
2747 FadeSoundsAndMusic();
2749 info_mode = INFO_MODE_MAIN;
2756 FadeSetNextScreen();
2758 if (button != MB_MENU_INITIALIZE)
2759 FadeOut(REDRAW_FIELD);
2761 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2763 if (button != MB_MENU_INITIALIZE)
2764 FadeIn(REDRAW_FIELD);
2768 if (DelayReached(&info_delay, GameFrameDelay))
2769 if (page < num_pages)
2770 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2772 PlayMenuSoundIfLoop();
2776 void DrawInfoScreen_Music()
2778 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2780 FadeOut(REDRAW_FIELD);
2787 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2789 FadeIn(REDRAW_FIELD);
2792 void HandleInfoScreen_Music(int button)
2794 static struct MusicFileInfo *list = NULL;
2795 int ystart1 = mSY - SY + 100;
2796 int ystart2 = mSY - SY + 150;
2797 int ybottom = mSY - SY + SYSIZE - 20;
2800 if (button == MB_MENU_INITIALIZE)
2802 list = music_file_info;
2806 FadeSoundsAndMusic();
2811 DrawTextSCentered(ystart1, FONT_TEXT_1,
2812 "No music info for this level set.");
2814 DrawTextSCentered(ybottom, FONT_TEXT_4,
2815 "Press any key or button for info menu");
2821 if (button == MB_MENU_LEAVE)
2823 PlaySound(SND_MENU_ITEM_SELECTING);
2825 FadeSoundsAndMusic();
2827 info_mode = INFO_MODE_MAIN;
2832 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2836 if (button != MB_MENU_INITIALIZE)
2838 PlaySound(SND_MENU_ITEM_SELECTING);
2846 FadeSoundsAndMusic();
2848 info_mode = INFO_MODE_MAIN;
2854 FadeSoundsAndMusic();
2856 if (list != music_file_info)
2857 FadeSetNextScreen();
2859 if (button != MB_MENU_INITIALIZE)
2860 FadeOut(REDRAW_FIELD);
2867 int sound = list->music;
2869 if (sound_info[sound].loop)
2870 PlaySoundLoop(sound);
2874 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2878 PlayMusic(list->music);
2880 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2883 if (!strEqual(list->title, UNKNOWN_NAME))
2885 if (!strEqual(list->title_header, UNKNOWN_NAME))
2886 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2888 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2891 if (!strEqual(list->artist, UNKNOWN_NAME))
2893 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2894 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2896 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2898 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2901 if (!strEqual(list->album, UNKNOWN_NAME))
2903 if (!strEqual(list->album_header, UNKNOWN_NAME))
2904 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2906 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2908 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2911 if (!strEqual(list->year, UNKNOWN_NAME))
2913 if (!strEqual(list->year_header, UNKNOWN_NAME))
2914 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2916 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2918 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2921 DrawTextSCentered(ybottom, FONT_TEXT_4,
2922 "Press any key or button for next page");
2924 if (button != MB_MENU_INITIALIZE)
2925 FadeIn(REDRAW_FIELD);
2928 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2929 PlaySoundLoop(list->music);
2932 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2934 int ystart1 = mSY - SY + 100;
2935 int ystart2 = mSY - SY + 150;
2936 int ybottom = mSY - SY + SYSIZE - 20;
2942 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2946 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2947 "Special thanks to");
2948 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2950 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2952 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2953 "\"Boulder Dash\"");
2954 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2956 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2958 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2960 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2961 "First Star Software");
2963 else if (screen_nr == 1)
2965 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2966 "Special thanks to");
2967 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2968 "Klaus Heinz & Volker Wertich");
2969 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2971 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2972 "\"Emerald Mine\"");
2973 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2975 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2977 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2979 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2982 else if (screen_nr == 2)
2984 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2985 "Special thanks to");
2986 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2987 "Michael Stopp & Philip Jespersen");
2988 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2990 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2992 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2994 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2996 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2998 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2999 "Digital Integration");
3001 else if (screen_nr == 3)
3003 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3004 "Special thanks to");
3005 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3006 "Hiroyuki Imabayashi");
3007 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3009 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3011 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3013 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3015 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3017 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3020 else if (screen_nr == 4)
3022 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3023 "Special thanks to");
3024 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3026 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3028 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3029 "J\xfcrgen Bonhagen");
3030 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3031 "for the continuous creation");
3032 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3033 "of outstanding level sets");
3035 else if (screen_nr == 5)
3037 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3039 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3041 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3042 "for ideas and inspiration by");
3043 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3046 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3048 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3050 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3051 "for ideas and inspiration by");
3052 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3055 else if (screen_nr == 6)
3057 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3059 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3062 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3063 "for the code base used for the");
3064 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3065 "native Emerald Mine engine");
3067 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3068 "for the new Emerald Mine engine");
3071 else if (screen_nr == 7)
3073 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3075 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3077 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3078 "for the initial DOS port");
3080 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3082 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3084 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3085 "for some additional toons");
3087 else if (screen_nr == 8)
3089 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3090 "And not to forget:");
3091 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3093 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3094 "All those who contributed");
3095 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3096 "levels to this game");
3097 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3101 DrawTextSCentered(ybottom, FONT_TEXT_4,
3102 "Press any key or button for next page");
3105 void DrawInfoScreen_Credits()
3107 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3109 FadeSoundsAndMusic();
3111 FadeOut(REDRAW_FIELD);
3113 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3115 FadeIn(REDRAW_FIELD);
3118 void HandleInfoScreen_Credits(int button)
3120 static int screen_nr = 0;
3121 int num_screens = 9;
3123 if (button == MB_MENU_INITIALIZE)
3127 // DrawInfoScreen_CreditsScreen(screen_nr);
3130 if (button == MB_MENU_LEAVE)
3132 PlaySound(SND_MENU_ITEM_SELECTING);
3134 info_mode = INFO_MODE_MAIN;
3139 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3141 if (button != MB_MENU_INITIALIZE)
3143 PlaySound(SND_MENU_ITEM_SELECTING);
3148 if (screen_nr >= num_screens)
3150 FadeSoundsAndMusic();
3152 info_mode = INFO_MODE_MAIN;
3159 FadeSetNextScreen();
3161 if (button != MB_MENU_INITIALIZE)
3162 FadeOut(REDRAW_FIELD);
3164 DrawInfoScreen_CreditsScreen(screen_nr);
3166 if (button != MB_MENU_INITIALIZE)
3167 FadeIn(REDRAW_FIELD);
3171 PlayMenuSoundIfLoop();
3175 void DrawInfoScreen_Program()
3177 int ystart1 = mSY - SY + 100;
3178 int ystart2 = mSY - SY + 150;
3179 int ybottom = mSY - SY + SYSIZE - 20;
3182 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3184 FadeOut(REDRAW_FIELD);
3189 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3191 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3192 "This game is Freeware!");
3193 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3194 "If you like it, send e-mail to:");
3195 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3196 setup.internal.program_email);
3197 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3198 "More information and levels:");
3199 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3200 setup.internal.program_website);
3201 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3202 "If you have created new levels,");
3203 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3204 "send them to me to include them!");
3205 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3208 DrawTextSCentered(ybottom, FONT_TEXT_4,
3209 "Press any key or button for info menu");
3211 FadeIn(REDRAW_FIELD);
3214 void HandleInfoScreen_Program(int button)
3216 if (button == MB_MENU_LEAVE)
3218 PlaySound(SND_MENU_ITEM_SELECTING);
3220 info_mode = INFO_MODE_MAIN;
3225 else if (button == MB_MENU_CHOICE)
3227 PlaySound(SND_MENU_ITEM_SELECTING);
3229 FadeSoundsAndMusic();
3231 info_mode = INFO_MODE_MAIN;
3236 PlayMenuSoundIfLoop();
3240 void DrawInfoScreen_Version()
3242 int font_header = FONT_TEXT_3;
3243 int font_text = FONT_TEXT_2;
3244 int xstep = getFontWidth(font_text);
3245 int ystep = getFontHeight(font_text);
3246 int ystart1 = mSY - SY + 100;
3247 int ystart2 = mSY - SY + 150;
3248 int ybottom = mSY - SY + SYSIZE - 20;
3249 int xstart1 = mSX - SX + 2 * xstep;
3250 int xstart2 = mSX - SX + 18 * xstep;
3251 int xstart3 = mSX - SX + 28 * xstep;
3252 SDL_version sdl_version_compiled;
3253 const SDL_version *sdl_version_linked;
3254 int driver_name_len = 10;
3255 #if defined(TARGET_SDL2)
3256 SDL_version sdl_version_linked_ext;
3257 const char *driver_name = NULL;
3259 char driver_name[driver_name_len];
3262 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3264 FadeOut(REDRAW_FIELD);
3269 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3271 DrawTextF(xstart1, ystart2, font_header, "Name");
3272 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3275 DrawTextF(xstart1, ystart2, font_header, "Version");
3276 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3279 DrawTextF(xstart1, ystart2, font_header, "Platform");
3280 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3283 DrawTextF(xstart1, ystart2, font_header, "Target");
3284 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3287 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3288 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3290 ystart2 += 3 * ystep;
3291 DrawTextF(xstart1, ystart2, font_header, "Library");
3292 DrawTextF(xstart2, ystart2, font_header, "compiled");
3293 DrawTextF(xstart3, ystart2, font_header, "linked");
3295 SDL_VERSION(&sdl_version_compiled);
3296 #if defined(TARGET_SDL2)
3297 SDL_GetVersion(&sdl_version_linked_ext);
3298 sdl_version_linked = &sdl_version_linked_ext;
3300 sdl_version_linked = SDL_Linked_Version();
3303 ystart2 += 2 * ystep;
3304 DrawTextF(xstart1, ystart2, font_text, "SDL");
3305 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3306 sdl_version_compiled.major,
3307 sdl_version_compiled.minor,
3308 sdl_version_compiled.patch);
3309 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3310 sdl_version_linked->major,
3311 sdl_version_linked->minor,
3312 sdl_version_linked->patch);
3314 SDL_IMAGE_VERSION(&sdl_version_compiled);
3315 sdl_version_linked = IMG_Linked_Version();
3318 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3319 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3320 sdl_version_compiled.major,
3321 sdl_version_compiled.minor,
3322 sdl_version_compiled.patch);
3323 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3324 sdl_version_linked->major,
3325 sdl_version_linked->minor,
3326 sdl_version_linked->patch);
3328 SDL_MIXER_VERSION(&sdl_version_compiled);
3329 sdl_version_linked = Mix_Linked_Version();
3332 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3333 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3334 sdl_version_compiled.major,
3335 sdl_version_compiled.minor,
3336 sdl_version_compiled.patch);
3337 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3338 sdl_version_linked->major,
3339 sdl_version_linked->minor,
3340 sdl_version_linked->patch);
3342 SDL_NET_VERSION(&sdl_version_compiled);
3343 sdl_version_linked = SDLNet_Linked_Version();
3346 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3347 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3348 sdl_version_compiled.major,
3349 sdl_version_compiled.minor,
3350 sdl_version_compiled.patch);
3351 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3352 sdl_version_linked->major,
3353 sdl_version_linked->minor,
3354 sdl_version_linked->patch);
3356 ystart2 += 3 * ystep;
3357 DrawTextF(xstart1, ystart2, font_header, "Driver");
3358 DrawTextF(xstart2, ystart2, font_header, "Requested");
3359 DrawTextF(xstart3, ystart2, font_header, "Used");
3361 #if defined(TARGET_SDL2)
3362 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3364 SDL_VideoDriverName(driver_name, driver_name_len);
3367 ystart2 += 2 * ystep;
3368 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3369 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3370 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3372 #if defined(TARGET_SDL2)
3373 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3375 SDL_AudioDriverName(driver_name, driver_name_len);
3379 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3380 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3381 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3383 DrawTextSCentered(ybottom, FONT_TEXT_4,
3384 "Press any key or button for info menu");
3386 FadeIn(REDRAW_FIELD);
3389 void HandleInfoScreen_Version(int button)
3391 if (button == MB_MENU_LEAVE)
3393 PlaySound(SND_MENU_ITEM_SELECTING);
3395 info_mode = INFO_MODE_MAIN;
3400 else if (button == MB_MENU_CHOICE)
3402 PlaySound(SND_MENU_ITEM_SELECTING);
3404 FadeSoundsAndMusic();
3406 info_mode = INFO_MODE_MAIN;
3411 PlayMenuSoundIfLoop();
3415 void DrawInfoScreen_LevelSet()
3417 struct TitleMessageInfo *tmi = &readme;
3418 char *filename = getLevelSetInfoFilename();
3419 char *title = "Level Set Information:";
3420 int ystart1 = mSY - SY + 100;
3421 int ybottom = mSY - SY + SYSIZE - 20;
3423 if (filename == NULL)
3425 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3430 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3432 FadeOut(REDRAW_FIELD);
3437 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3439 /* if x position set to "-1", automatically determine by playfield width */
3441 tmi->x = SXSIZE / 2;
3443 /* if y position set to "-1", use static default value */
3447 /* if width set to "-1", automatically determine by playfield width */
3448 if (tmi->width == -1)
3449 tmi->width = SXSIZE - 2 * TILEX;
3451 /* if height set to "-1", automatically determine by playfield height */
3452 if (tmi->height == -1)
3453 tmi->height = SYSIZE - 20 - tmi->y - 10;
3455 /* if chars set to "-1", automatically determine by text and font width */
3456 if (tmi->chars == -1)
3457 tmi->chars = tmi->width / getFontWidth(tmi->font);
3459 tmi->width = tmi->chars * getFontWidth(tmi->font);
3461 /* if lines set to "-1", automatically determine by text and font height */
3462 if (tmi->lines == -1)
3463 tmi->lines = tmi->height / getFontHeight(tmi->font);
3465 tmi->height = tmi->lines * getFontHeight(tmi->font);
3467 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3468 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3469 tmi->autowrap, tmi->centered, tmi->parse_comments);
3471 DrawTextSCentered(ybottom, FONT_TEXT_4,
3472 "Press any key or button for info menu");
3474 FadeIn(REDRAW_FIELD);
3477 void HandleInfoScreen_LevelSet(int button)
3479 if (button == MB_MENU_LEAVE)
3481 PlaySound(SND_MENU_ITEM_SELECTING);
3483 info_mode = INFO_MODE_MAIN;
3488 else if (button == MB_MENU_CHOICE)
3490 PlaySound(SND_MENU_ITEM_SELECTING);
3492 FadeSoundsAndMusic();
3494 info_mode = INFO_MODE_MAIN;
3499 PlayMenuSoundIfLoop();
3503 static void DrawInfoScreen()
3505 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3507 if (info_mode == INFO_MODE_TITLE)
3508 DrawInfoScreen_TitleScreen();
3509 else if (info_mode == INFO_MODE_ELEMENTS)
3510 DrawInfoScreen_Elements();
3511 else if (info_mode == INFO_MODE_MUSIC)
3512 DrawInfoScreen_Music();
3513 else if (info_mode == INFO_MODE_CREDITS)
3514 DrawInfoScreen_Credits();
3515 else if (info_mode == INFO_MODE_PROGRAM)
3516 DrawInfoScreen_Program();
3517 else if (info_mode == INFO_MODE_VERSION)
3518 DrawInfoScreen_Version();
3519 else if (info_mode == INFO_MODE_LEVELSET)
3520 DrawInfoScreen_LevelSet();
3522 DrawInfoScreen_Main();
3524 if (info_mode != INFO_MODE_MAIN &&
3525 info_mode != INFO_MODE_TITLE &&
3526 info_mode != INFO_MODE_MUSIC)
3533 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3535 if (info_mode == INFO_MODE_TITLE)
3536 HandleInfoScreen_TitleScreen(button);
3537 else if (info_mode == INFO_MODE_ELEMENTS)
3538 HandleInfoScreen_Elements(button);
3539 else if (info_mode == INFO_MODE_MUSIC)
3540 HandleInfoScreen_Music(button);
3541 else if (info_mode == INFO_MODE_CREDITS)
3542 HandleInfoScreen_Credits(button);
3543 else if (info_mode == INFO_MODE_PROGRAM)
3544 HandleInfoScreen_Program(button);
3545 else if (info_mode == INFO_MODE_VERSION)
3546 HandleInfoScreen_Version(button);
3547 else if (info_mode == INFO_MODE_LEVELSET)
3548 HandleInfoScreen_LevelSet(button);
3550 HandleInfoScreen_Main(mx, my, dx, dy, button);
3554 /* ========================================================================= */
3555 /* type name functions */
3556 /* ========================================================================= */
3558 void HandleTypeName(int newxpos, Key key)
3560 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3561 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3562 struct TextPosInfo *pos = mci->pos_input;
3563 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3564 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3565 static int xpos = 0;
3566 int font_nr = pos->font;
3567 int font_active_nr = FONT_ACTIVE(font_nr);
3568 int font_width = getFontWidth(font_active_nr);
3569 char key_char = getValidConfigValueChar(getCharFromKey(key));
3570 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3571 boolean is_active = TRUE;
3573 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3577 strcpy(last_player_name, setup.player_name);
3581 #if defined(TARGET_SDL2)
3582 SDL_StartTextInput();
3585 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3587 setup.player_name[xpos] = key_char;
3588 setup.player_name[xpos + 1] = 0;
3592 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3596 setup.player_name[xpos] = 0;
3598 else if (key == KSYM_Return && xpos > 0)
3604 SetGameStatus(GAME_MODE_MAIN);
3606 else if (key == KSYM_Escape)
3608 strcpy(setup.player_name, last_player_name);
3612 SetGameStatus(GAME_MODE_MAIN);
3617 pos->width = (strlen(setup.player_name) + 1) * font_width;
3618 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3620 DrawText(startx, starty, setup.player_name, font_active_nr);
3621 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3625 pos->width = strlen(setup.player_name) * font_width;
3626 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3628 DrawText(startx, starty, setup.player_name, font_nr);
3630 #if defined(TARGET_SDL2)
3631 SDL_StopTextInput();
3637 /* ========================================================================= */
3638 /* tree menu functions */
3639 /* ========================================================================= */
3641 static void DrawChooseTree(TreeInfo **ti_ptr)
3643 int fade_mask = REDRAW_FIELD;
3645 if (CheckIfGlobalBorderHasChanged())
3646 fade_mask = REDRAW_ALL;
3648 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3650 SetGameStatus(GAME_MODE_MAIN);
3659 FreeScreenGadgets();
3660 CreateScreenGadgets();
3666 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3668 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3669 MapScreenTreeGadgets(*ti_ptr);
3671 DrawMaskedBorder(fade_mask);
3678 static void drawChooseTreeList(int first_entry, int num_page_entries,
3682 char *title_string = NULL;
3683 int yoffset_sets = MENU_TITLE1_YPOS;
3684 int yoffset_setup = 16;
3685 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3686 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3687 int last_game_status = game_status; /* save current game status */
3689 title_string = ti->infotext;
3691 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3693 clearMenuListArea();
3695 for (i = 0; i < num_page_entries; i++)
3697 TreeInfo *node, *node_first;
3698 int entry_pos = first_entry + i;
3699 int xpos = MENU_SCREEN_START_XPOS;
3700 int ypos = MENU_SCREEN_START_YPOS + i;
3701 int startx = mSX + xpos * 32;
3702 int starty = mSY + ypos * 32;
3703 int font_nr = FONT_TEXT_1;
3704 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3705 int startx_text = startx + font_xoffset;
3706 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3707 int text_size = startx_scrollbar - startx_text;
3708 int max_buffer_len = text_size / getFontWidth(font_nr);
3709 char buffer[max_buffer_len + 1];
3711 node_first = getTreeInfoFirstGroupEntry(ti);
3712 node = getTreeInfoFromPos(node_first, entry_pos);
3714 strncpy(buffer, node->name, max_buffer_len);
3715 buffer[max_buffer_len] = '\0';
3717 DrawText(startx, starty, buffer, font_nr + node->color);
3719 if (node->parent_link)
3720 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3721 else if (node->level_group)
3722 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3724 initCursor(i, IMG_MENU_BUTTON);
3727 SetGameStatus(last_game_status); /* restore current game status */
3729 redraw_mask |= REDRAW_FIELD;
3732 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3734 TreeInfo *node, *node_first;
3735 int x, last_redraw_mask = redraw_mask;
3736 int ypos = MENU_TITLE2_YPOS;
3737 int font_nr = FONT_TITLE_2;
3739 if (ti->type == TREE_TYPE_LEVEL_NR)
3740 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3742 if (ti->type != TREE_TYPE_LEVEL_DIR)
3745 node_first = getTreeInfoFirstGroupEntry(ti);
3746 node = getTreeInfoFromPos(node_first, entry_pos);
3748 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3750 if (node->parent_link)
3751 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3752 node->node_parent->name);
3753 else if (node->level_group)
3754 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3756 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3757 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3758 node->levels, (node->levels > 1 ? "levels" : "level"),
3761 /* let BackToFront() redraw only what is needed */
3762 redraw_mask = last_redraw_mask;
3763 for (x = 0; x < SCR_FIELDX; x++)
3764 MarkTileDirty(x, 1);
3767 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3770 TreeInfo *ti = *ti_ptr;
3772 int y = ti->cl_cursor;
3773 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3774 int num_entries = numTreeInfoInGroup(ti);
3775 int num_page_entries;
3776 int last_game_status = game_status; /* save current game status */
3777 boolean position_set_by_scrollbar = (dx == 999);
3779 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3780 num_page_entries = num_entries;
3782 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3784 SetGameStatus(last_game_status); /* restore current game status */
3786 if (button == MB_MENU_INITIALIZE)
3788 int num_entries = numTreeInfoInGroup(ti);
3789 int entry_pos = posTreeInfo(ti);
3791 if (ti->cl_first == -1)
3793 /* only on initialization */
3794 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3795 ti->cl_cursor = entry_pos - ti->cl_first;
3797 else if (ti->cl_cursor >= num_page_entries ||
3798 (num_entries > num_page_entries &&
3799 num_entries - ti->cl_first < num_page_entries))
3801 /* only after change of list size (by custom graphic configuration) */
3802 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3803 ti->cl_cursor = entry_pos - ti->cl_first;
3806 if (position_set_by_scrollbar)
3809 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3812 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3813 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3814 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3818 else if (button == MB_MENU_LEAVE)
3822 PlaySound(SND_MENU_ITEM_SELECTING);
3824 if (ti->node_parent)
3826 *ti_ptr = ti->node_parent;
3827 DrawChooseTree(ti_ptr);
3829 else if (game_status == GAME_MODE_SETUP)
3831 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3832 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3833 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3835 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3836 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3837 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3838 execSetupGraphics();
3839 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3840 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3841 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3843 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3844 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3845 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3852 if (game_status == GAME_MODE_LEVELNR)
3854 int new_level_nr = atoi(level_number_current->identifier);
3856 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3859 SetGameStatus(GAME_MODE_MAIN);
3867 if (mx || my) /* mouse input */
3869 int last_game_status = game_status; /* save current game status */
3871 x = (mx - mSX) / 32;
3872 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3874 SetGameStatus(last_game_status); /* restore current game status */
3876 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3878 /* move cursor instead of scrolling when already at start/end of list */
3879 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3881 else if (dy == +1 * SCROLL_LINE &&
3882 ti->cl_first + num_page_entries == num_entries)
3885 /* handle scrolling screen one line or page */
3886 if (ti->cl_cursor + dy < 0 ||
3887 ti->cl_cursor + dy > num_page_entries - 1)
3889 boolean redraw = FALSE;
3891 if (ABS(dy) == SCROLL_PAGE)
3892 step = num_page_entries - 1;
3894 if (dy < 0 && ti->cl_first > 0)
3896 /* scroll page/line up */
3898 ti->cl_first -= step;
3899 if (ti->cl_first < 0)
3904 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3906 /* scroll page/line down */
3908 ti->cl_first += step;
3909 if (ti->cl_first + num_page_entries > num_entries)
3910 ti->cl_first = MAX(0, num_entries - num_page_entries);
3917 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3918 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3919 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3921 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3928 /* handle moving cursor one line */
3929 y = ti->cl_cursor + dy;
3934 TreeInfo *node_first, *node_cursor;
3935 int entry_pos = ti->cl_first + y;
3937 node_first = getTreeInfoFirstGroupEntry(ti);
3938 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3940 if (node_cursor->node_group)
3944 PlaySound(SND_MENU_ITEM_SELECTING);
3946 node_cursor->cl_first = ti->cl_first;
3947 node_cursor->cl_cursor = ti->cl_cursor;
3948 *ti_ptr = node_cursor->node_group;
3949 DrawChooseTree(ti_ptr);
3954 else if (dx == -1 && ti->node_parent)
3958 PlaySound(SND_MENU_ITEM_SELECTING);
3960 *ti_ptr = ti->node_parent;
3961 DrawChooseTree(ti_ptr);
3966 if (!anyScrollbarGadgetActive() &&
3967 IN_VIS_MENU(x, y) &&
3968 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3969 y >= 0 && y < num_page_entries)
3973 if (y != ti->cl_cursor)
3975 PlaySound(SND_MENU_ITEM_ACTIVATING);
3977 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3978 drawChooseTreeCursor(y, TRUE);
3979 drawChooseTreeInfo(ti->cl_first + y, ti);
3986 TreeInfo *node_first, *node_cursor;
3987 int entry_pos = ti->cl_first + y;
3989 PlaySound(SND_MENU_ITEM_SELECTING);
3991 node_first = getTreeInfoFirstGroupEntry(ti);
3992 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3994 if (node_cursor->node_group)
3998 node_cursor->cl_first = ti->cl_first;
3999 node_cursor->cl_cursor = ti->cl_cursor;
4000 *ti_ptr = node_cursor->node_group;
4001 DrawChooseTree(ti_ptr);
4003 else if (node_cursor->parent_link)
4007 *ti_ptr = node_cursor->node_parent;
4008 DrawChooseTree(ti_ptr);
4014 node_cursor->cl_first = ti->cl_first;
4015 node_cursor->cl_cursor = ti->cl_cursor;
4016 *ti_ptr = node_cursor;
4018 if (ti->type == TREE_TYPE_LEVEL_DIR)
4020 LoadLevelSetup_SeriesInfo();
4022 SaveLevelSetup_LastSeries();
4023 SaveLevelSetup_SeriesInfo();
4027 if (game_status == GAME_MODE_SETUP)
4029 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4030 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4031 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4033 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4034 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4035 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4036 execSetupGraphics();
4037 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4038 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4039 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4041 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4042 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4043 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4050 if (game_status == GAME_MODE_LEVELNR)
4052 int new_level_nr = atoi(level_number_current->identifier);
4054 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4057 SetGameStatus(GAME_MODE_MAIN);
4066 void DrawChooseLevelSet()
4068 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4070 DrawChooseTree(&leveldir_current);
4076 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4078 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4081 void DrawChooseLevelNr()
4085 if (level_number != NULL)
4087 freeTreeInfo(level_number);
4089 level_number = NULL;
4092 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4094 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4095 char identifier[32], name[32];
4098 /* temporarily load level info to get level name */
4099 LoadLevelInfoOnly(i);
4101 ti->node_top = &level_number;
4102 ti->sort_priority = 10000 + value;
4103 ti->color = (level.no_valid_file ? FC_BLUE :
4104 LevelStats_getSolved(i) ? FC_GREEN :
4105 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4107 sprintf(identifier, "%d", value);
4108 sprintf(name, "%03d: %s", value,
4109 (level.no_valid_file ? "(no file)" : level.name));
4111 setString(&ti->identifier, identifier);
4112 setString(&ti->name, name);
4113 setString(&ti->name_sorting, name);
4115 pushTreeInfo(&level_number, ti);
4118 /* sort level number values to start with lowest level number */
4119 sortTreeInfo(&level_number);
4121 /* set current level number to current level number */
4122 level_number_current =
4123 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4125 /* if that also fails, set current level number to first available level */
4126 if (level_number_current == NULL)
4127 level_number_current = level_number;
4129 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4131 DrawChooseTree(&level_number_current);
4137 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4139 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4142 void DrawHallOfFame(int highlight_position)
4144 int fade_mask = REDRAW_FIELD;
4146 /* needed if different viewport properties defined for scores */
4147 ChangeViewportPropertiesIfNeeded();
4149 if (CheckIfGlobalBorderHasChanged())
4150 fade_mask = REDRAW_ALL;
4153 FadeSoundsAndMusic();
4155 /* (this is needed when called from GameEnd() after winning a game) */
4156 KeyboardAutoRepeatOn();
4159 /* (this is needed when called from GameEnd() after winning a game) */
4160 SetDrawDeactivationMask(REDRAW_NONE);
4161 SetDrawBackgroundMask(REDRAW_FIELD);
4163 if (highlight_position < 0)
4164 LoadScore(level_nr);
4166 FadeSetEnterScreen();
4175 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4177 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4179 DrawMaskedBorder(fade_mask);
4184 static void drawHallOfFameList(int first_entry, int highlight_position)
4188 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4191 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4192 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4193 "HighScores of Level %d", level_nr);
4195 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4197 int entry = first_entry + i;
4198 boolean active = (entry == highlight_position);
4199 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4200 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4201 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4202 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4203 int dx1 = 3 * getFontWidth(font_nr1);
4204 int dx2 = dx1 + getFontWidth(font_nr1);
4205 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4206 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4207 int sy = mSY + 64 + i * 32;
4209 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4210 DrawText(mSX + dx1, sy, ".", font_nr1);
4212 for (j = 0; j < num_dots; j++)
4213 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4215 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4216 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4218 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4221 redraw_mask |= REDRAW_FIELD;
4224 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4226 static int first_entry = 0;
4227 static int highlight_position = 0;
4228 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4230 if (button == MB_MENU_INITIALIZE)
4233 highlight_position = mx;
4234 drawHallOfFameList(first_entry, highlight_position);
4239 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4240 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4244 if (first_entry > 0)
4246 first_entry -= step;
4247 if (first_entry < 0)
4250 drawHallOfFameList(first_entry, highlight_position);
4255 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4257 first_entry += step;
4258 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4259 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4261 drawHallOfFameList(first_entry, highlight_position);
4264 else if (button == MB_MENU_LEAVE)
4266 PlaySound(SND_MENU_ITEM_SELECTING);
4268 FadeSound(SND_BACKGROUND_SCORES);
4270 SetGameStatus(GAME_MODE_MAIN);
4274 else if (button == MB_MENU_CHOICE)
4276 PlaySound(SND_MENU_ITEM_SELECTING);
4278 FadeSound(SND_BACKGROUND_SCORES);
4280 SetGameStatus(GAME_MODE_MAIN);
4285 if (game_status == GAME_MODE_SCORES)
4286 PlayMenuSoundIfLoop();
4290 /* ========================================================================= */
4291 /* setup screen functions */
4292 /* ========================================================================= */
4294 static struct TokenInfo *setup_info;
4295 static int num_setup_info; /* number of setup entries shown on screen */
4296 static int max_setup_info; /* total number of setup entries in list */
4298 static char *screen_mode_text;
4299 static char *window_size_text;
4300 static char *scaling_type_text;
4301 static char *scroll_delay_text;
4302 static char *snapshot_mode_text;
4303 static char *game_speed_text;
4304 static char *graphics_set_name;
4305 static char *sounds_set_name;
4306 static char *music_set_name;
4307 static char *volume_simple_text;
4308 static char *volume_loops_text;
4309 static char *volume_music_text;
4310 static char *touch_controls_text;
4311 static char *move_distance_text;
4312 static char *drop_distance_text;
4314 static void execSetupMain()
4316 setup_mode = SETUP_MODE_MAIN;
4321 static void execSetupGame_setGameSpeeds()
4323 if (game_speeds == NULL)
4327 for (i = 0; game_speeds_list[i].value != -1; i++)
4329 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4330 char identifier[32], name[32];
4331 int value = game_speeds_list[i].value;
4332 char *text = game_speeds_list[i].text;
4334 ti->node_top = &game_speeds;
4335 ti->sort_priority = 10000 - value;
4337 sprintf(identifier, "%d", value);
4338 sprintf(name, "%s", text);
4340 setString(&ti->identifier, identifier);
4341 setString(&ti->name, name);
4342 setString(&ti->name_sorting, name);
4343 setString(&ti->infotext, "Game Speed");
4345 pushTreeInfo(&game_speeds, ti);
4348 /* sort game speed values to start with slowest game speed */
4349 sortTreeInfo(&game_speeds);
4351 /* set current game speed to configured game speed value */
4352 game_speed_current =
4353 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4355 /* if that fails, set current game speed to reliable default value */
4356 if (game_speed_current == NULL)
4357 game_speed_current =
4358 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4360 /* if that also fails, set current game speed to first available speed */
4361 if (game_speed_current == NULL)
4362 game_speed_current = game_speeds;
4365 setup.game_frame_delay = atoi(game_speed_current->identifier);
4367 /* needed for displaying game speed text instead of identifier */
4368 game_speed_text = game_speed_current->name;
4371 static void execSetupGame_setScrollDelays()
4373 if (scroll_delays == NULL)
4377 for (i = 0; scroll_delays_list[i].value != -1; i++)
4379 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4380 char identifier[32], name[32];
4381 int value = scroll_delays_list[i].value;
4382 char *text = scroll_delays_list[i].text;
4384 ti->node_top = &scroll_delays;
4385 ti->sort_priority = value;
4387 sprintf(identifier, "%d", value);
4388 sprintf(name, "%s", text);
4390 setString(&ti->identifier, identifier);
4391 setString(&ti->name, name);
4392 setString(&ti->name_sorting, name);
4393 setString(&ti->infotext, "Scaling Type");
4395 pushTreeInfo(&scroll_delays, ti);
4398 /* sort scaling type values to start with lowest scaling type value */
4399 sortTreeInfo(&scroll_delays);
4401 /* set current scaling type value to configured scaling type value */
4402 scroll_delay_current =
4403 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4405 /* if that fails, set current scaling type to reliable default value */
4406 if (scroll_delay_current == NULL)
4407 scroll_delay_current =
4408 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4410 /* if that also fails, set current scaling type to first available value */
4411 if (scroll_delay_current == NULL)
4412 scroll_delay_current = scroll_delays;
4415 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4417 /* needed for displaying scaling type text instead of identifier */
4418 scroll_delay_text = scroll_delay_current->name;
4421 static void execSetupGame_setSnapshotModes()
4423 if (snapshot_modes == NULL)
4427 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4429 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4430 char identifier[32], name[32];
4431 char *value = snapshot_modes_list[i].value;
4432 char *text = snapshot_modes_list[i].text;
4434 ti->node_top = &snapshot_modes;
4435 ti->sort_priority = i;
4437 sprintf(identifier, "%s", value);
4438 sprintf(name, "%s", text);
4440 setString(&ti->identifier, identifier);
4441 setString(&ti->name, name);
4442 setString(&ti->name_sorting, name);
4443 setString(&ti->infotext, "Snapshot Mode");
4445 pushTreeInfo(&snapshot_modes, ti);
4448 /* sort snapshot mode values to start with lowest snapshot mode value */
4449 sortTreeInfo(&snapshot_modes);
4451 /* set current snapshot mode value to configured snapshot mode value */
4452 snapshot_mode_current =
4453 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4455 /* if that fails, set current snapshot mode to reliable default value */
4456 if (snapshot_mode_current == NULL)
4457 snapshot_mode_current =
4458 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4460 /* if that also fails, set current snapshot mode to first available value */
4461 if (snapshot_mode_current == NULL)
4462 snapshot_mode_current = snapshot_modes;
4465 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4467 /* needed for displaying snapshot mode text instead of identifier */
4468 snapshot_mode_text = snapshot_mode_current->name;
4471 static void execSetupGame()
4473 execSetupGame_setGameSpeeds();
4474 execSetupGame_setScrollDelays();
4475 execSetupGame_setSnapshotModes();
4477 setup_mode = SETUP_MODE_GAME;
4482 static void execSetupChooseGameSpeed()
4484 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4489 static void execSetupChooseScrollDelay()
4491 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4496 static void execSetupChooseSnapshotMode()
4498 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4503 static void execSetupEditor()
4505 setup_mode = SETUP_MODE_EDITOR;
4510 static void execSetupGraphics_setWindowSizes(boolean update_list)
4512 if (window_sizes != NULL && update_list)
4514 freeTreeInfo(window_sizes);
4516 window_sizes = NULL;
4519 if (window_sizes == NULL)
4521 boolean current_window_size_found = FALSE;
4524 for (i = 0; window_sizes_list[i].value != -1; i++)
4526 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4527 char identifier[32], name[32];
4528 int value = window_sizes_list[i].value;
4529 char *text = window_sizes_list[i].text;
4531 ti->node_top = &window_sizes;
4532 ti->sort_priority = value;
4534 sprintf(identifier, "%d", value);
4535 sprintf(name, "%s", text);
4537 setString(&ti->identifier, identifier);
4538 setString(&ti->name, name);
4539 setString(&ti->name_sorting, name);
4540 setString(&ti->infotext, "Window Scaling");
4542 pushTreeInfo(&window_sizes, ti);
4544 if (value == setup.window_scaling_percent)
4545 current_window_size_found = TRUE;
4548 if (!current_window_size_found)
4550 // add entry for non-preset window scaling value
4552 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4553 char identifier[32], name[32];
4554 int value = setup.window_scaling_percent;
4556 ti->node_top = &window_sizes;
4557 ti->sort_priority = value;
4559 sprintf(identifier, "%d", value);
4560 sprintf(name, "%d %% (Current)", value);
4562 setString(&ti->identifier, identifier);
4563 setString(&ti->name, name);
4564 setString(&ti->name_sorting, name);
4565 setString(&ti->infotext, "Window Scaling");
4567 pushTreeInfo(&window_sizes, ti);
4570 /* sort window size values to start with lowest window size value */
4571 sortTreeInfo(&window_sizes);
4573 /* set current window size value to configured window size value */
4574 window_size_current =
4575 getTreeInfoFromIdentifier(window_sizes,
4576 i_to_a(setup.window_scaling_percent));
4578 /* if that fails, set current window size to reliable default value */
4579 if (window_size_current == NULL)
4580 window_size_current =
4581 getTreeInfoFromIdentifier(window_sizes,
4582 i_to_a(STD_WINDOW_SCALING_PERCENT));
4584 /* if that also fails, set current window size to first available value */
4585 if (window_size_current == NULL)
4586 window_size_current = window_sizes;
4589 setup.window_scaling_percent = atoi(window_size_current->identifier);
4591 /* needed for displaying window size text instead of identifier */
4592 window_size_text = window_size_current->name;
4595 static void execSetupGraphics_setScalingTypes()
4597 if (scaling_types == NULL)
4601 for (i = 0; scaling_types_list[i].value != NULL; i++)
4603 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4604 char identifier[32], name[32];
4605 char *value = scaling_types_list[i].value;
4606 char *text = scaling_types_list[i].text;
4608 ti->node_top = &scaling_types;
4609 ti->sort_priority = i;
4611 sprintf(identifier, "%s", value);
4612 sprintf(name, "%s", text);
4614 setString(&ti->identifier, identifier);
4615 setString(&ti->name, name);
4616 setString(&ti->name_sorting, name);
4617 setString(&ti->infotext, "Anti-Aliasing");
4619 pushTreeInfo(&scaling_types, ti);
4622 /* sort scaling type values to start with lowest scaling type value */
4623 sortTreeInfo(&scaling_types);
4625 /* set current scaling type value to configured scaling type value */
4626 scaling_type_current =
4627 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4629 /* if that fails, set current scaling type to reliable default value */
4630 if (scaling_type_current == NULL)
4631 scaling_type_current =
4632 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4634 /* if that also fails, set current scaling type to first available value */
4635 if (scaling_type_current == NULL)
4636 scaling_type_current = scaling_types;
4639 setup.window_scaling_quality = scaling_type_current->identifier;
4641 /* needed for displaying scaling type text instead of identifier */
4642 scaling_type_text = scaling_type_current->name;
4645 static void execSetupGraphics_setScreenModes()
4647 // if (screen_modes == NULL && video.fullscreen_available)
4648 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4652 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4654 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4655 char identifier[32], name[32];
4656 int x = video.fullscreen_modes[i].width;
4657 int y = video.fullscreen_modes[i].height;
4660 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4662 ti->node_top = &screen_modes;
4663 ti->sort_priority = x * 10000 + y;
4665 sprintf(identifier, "%dx%d", x, y);
4666 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4668 setString(&ti->identifier, identifier);
4669 setString(&ti->name, name);
4670 setString(&ti->name_sorting, name);
4671 setString(&ti->infotext, "Fullscreen Mode");
4673 pushTreeInfo(&screen_modes, ti);
4676 /* sort fullscreen modes to start with lowest available screen resolution */
4677 sortTreeInfo(&screen_modes);
4679 /* set current screen mode for fullscreen mode to configured setup value */
4680 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4681 setup.fullscreen_mode);
4683 /* if that fails, set current screen mode to reliable default value */
4684 if (screen_mode_current == NULL)
4685 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4686 DEFAULT_FULLSCREEN_MODE);
4688 /* if that also fails, set current screen mode to first available mode */
4689 if (screen_mode_current == NULL)
4690 screen_mode_current = screen_modes;
4692 if (screen_mode_current == NULL)
4693 video.fullscreen_available = FALSE;
4696 // if (video.fullscreen_available)
4697 if (screen_mode_current != NULL)
4699 setup.fullscreen_mode = screen_mode_current->identifier;
4701 /* needed for displaying screen mode name instead of identifier */
4702 screen_mode_text = screen_mode_current->name;
4706 static void execSetupGraphics()
4708 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4710 // update "setup.window_scaling_percent" from list selection
4711 execSetupGraphics_setWindowSizes(FALSE);
4715 // update list selection from "setup.window_scaling_percent"
4716 execSetupGraphics_setWindowSizes(TRUE);
4719 execSetupGraphics_setScalingTypes();
4720 execSetupGraphics_setScreenModes();
4722 setup_mode = SETUP_MODE_GRAPHICS;
4726 #if defined(TARGET_SDL2)
4727 // window scaling may have changed at this point
4728 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4730 // window scaling quality may have changed at this point
4731 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4732 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4736 #if !defined(PLATFORM_ANDROID)
4737 #if defined(TARGET_SDL2)
4738 static void execSetupChooseWindowSize()
4740 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4745 static void execSetupChooseScalingType()
4747 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4752 static void execSetupChooseScreenMode()
4754 if (!video.fullscreen_available)
4757 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4764 static void execSetupChooseVolumeSimple()
4766 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4771 static void execSetupChooseVolumeLoops()
4773 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4778 static void execSetupChooseVolumeMusic()
4780 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4785 static void execSetupSound()
4787 if (volumes_simple == NULL)
4789 boolean current_volume_simple_found = FALSE;
4792 for (i = 0; volumes_list[i].value != -1; i++)
4794 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4795 char identifier[32], name[32];
4796 int value = volumes_list[i].value;
4797 char *text = volumes_list[i].text;
4799 ti->node_top = &volumes_simple;
4800 ti->sort_priority = value;
4802 sprintf(identifier, "%d", value);
4803 sprintf(name, "%s", text);
4805 setString(&ti->identifier, identifier);
4806 setString(&ti->name, name);
4807 setString(&ti->name_sorting, name);
4808 setString(&ti->infotext, "Sound Volume");
4810 pushTreeInfo(&volumes_simple, ti);
4812 if (value == setup.volume_simple)
4813 current_volume_simple_found = TRUE;
4816 if (!current_volume_simple_found)
4818 // add entry for non-preset volume value
4820 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4821 char identifier[32], name[32];
4822 int value = setup.volume_simple;
4824 ti->node_top = &volumes_simple;
4825 ti->sort_priority = value;
4827 sprintf(identifier, "%d", value);
4828 sprintf(name, "%d %% (Current)", value);
4830 setString(&ti->identifier, identifier);
4831 setString(&ti->name, name);
4832 setString(&ti->name_sorting, name);
4833 setString(&ti->infotext, "Sound Volume");
4835 pushTreeInfo(&volumes_simple, ti);
4838 /* sort volume values to start with lowest volume value */
4839 sortTreeInfo(&volumes_simple);
4841 /* set current volume value to configured volume value */
4842 volume_simple_current =
4843 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4845 /* if that fails, set current volume to reliable default value */
4846 if (volume_simple_current == NULL)
4847 volume_simple_current =
4848 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4850 /* if that also fails, set current volume to first available value */
4851 if (volume_simple_current == NULL)
4852 volume_simple_current = volumes_simple;
4855 if (volumes_loops == NULL)
4857 boolean current_volume_loops_found = FALSE;
4860 for (i = 0; volumes_list[i].value != -1; i++)
4862 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4863 char identifier[32], name[32];
4864 int value = volumes_list[i].value;
4865 char *text = volumes_list[i].text;
4867 ti->node_top = &volumes_loops;
4868 ti->sort_priority = value;
4870 sprintf(identifier, "%d", value);
4871 sprintf(name, "%s", text);
4873 setString(&ti->identifier, identifier);
4874 setString(&ti->name, name);
4875 setString(&ti->name_sorting, name);
4876 setString(&ti->infotext, "Loops Volume");
4878 pushTreeInfo(&volumes_loops, ti);
4880 if (value == setup.volume_loops)
4881 current_volume_loops_found = TRUE;
4884 if (!current_volume_loops_found)
4886 // add entry for non-preset volume value
4888 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4889 char identifier[32], name[32];
4890 int value = setup.volume_loops;
4892 ti->node_top = &volumes_loops;
4893 ti->sort_priority = value;
4895 sprintf(identifier, "%d", value);
4896 sprintf(name, "%d %% (Current)", value);
4898 setString(&ti->identifier, identifier);
4899 setString(&ti->name, name);
4900 setString(&ti->name_sorting, name);
4901 setString(&ti->infotext, "Loops Volume");
4903 pushTreeInfo(&volumes_loops, ti);
4906 /* sort volume values to start with lowest volume value */
4907 sortTreeInfo(&volumes_loops);
4909 /* set current volume value to configured volume value */
4910 volume_loops_current =
4911 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4913 /* if that fails, set current volume to reliable default value */
4914 if (volume_loops_current == NULL)
4915 volume_loops_current =
4916 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4918 /* if that also fails, set current volume to first available value */
4919 if (volume_loops_current == NULL)
4920 volume_loops_current = volumes_loops;
4923 if (volumes_music == NULL)
4925 boolean current_volume_music_found = FALSE;
4928 for (i = 0; volumes_list[i].value != -1; i++)
4930 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4931 char identifier[32], name[32];
4932 int value = volumes_list[i].value;
4933 char *text = volumes_list[i].text;
4935 ti->node_top = &volumes_music;
4936 ti->sort_priority = value;
4938 sprintf(identifier, "%d", value);
4939 sprintf(name, "%s", text);
4941 setString(&ti->identifier, identifier);
4942 setString(&ti->name, name);
4943 setString(&ti->name_sorting, name);
4944 setString(&ti->infotext, "Music Volume");
4946 pushTreeInfo(&volumes_music, ti);
4948 if (value == setup.volume_music)
4949 current_volume_music_found = TRUE;
4952 if (!current_volume_music_found)
4954 // add entry for non-preset volume value
4956 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4957 char identifier[32], name[32];
4958 int value = setup.volume_music;
4960 ti->node_top = &volumes_music;
4961 ti->sort_priority = value;
4963 sprintf(identifier, "%d", value);
4964 sprintf(name, "%d %% (Current)", value);
4966 setString(&ti->identifier, identifier);
4967 setString(&ti->name, name);
4968 setString(&ti->name_sorting, name);
4969 setString(&ti->infotext, "Music Volume");
4971 pushTreeInfo(&volumes_music, ti);
4974 /* sort volume values to start with lowest volume value */
4975 sortTreeInfo(&volumes_music);
4977 /* set current volume value to configured volume value */
4978 volume_music_current =
4979 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4981 /* if that fails, set current volume to reliable default value */
4982 if (volume_music_current == NULL)
4983 volume_music_current =
4984 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4986 /* if that also fails, set current volume to first available value */
4987 if (volume_music_current == NULL)
4988 volume_music_current = volumes_music;
4991 setup.volume_simple = atoi(volume_simple_current->identifier);
4992 setup.volume_loops = atoi(volume_loops_current->identifier);
4993 setup.volume_music = atoi(volume_music_current->identifier);
4995 /* needed for displaying volume text instead of identifier */
4996 volume_simple_text = volume_simple_current->name;
4997 volume_loops_text = volume_loops_current->name;
4998 volume_music_text = volume_music_current->name;
5000 setup_mode = SETUP_MODE_SOUND;
5005 static void execSetupChooseTouchControls()
5007 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5012 static void execSetupChooseMoveDistance()
5014 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5019 static void execSetupChooseDropDistance()
5021 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5026 static void execSetupTouch()
5028 if (touch_controls == NULL)
5032 for (i = 0; touch_controls_list[i].value != NULL; i++)
5034 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5035 char identifier[32], name[32];
5036 char *value = touch_controls_list[i].value;
5037 char *text = touch_controls_list[i].text;
5039 ti->node_top = &touch_controls;
5040 ti->sort_priority = i;
5042 sprintf(identifier, "%s", value);
5043 sprintf(name, "%s", text);
5045 setString(&ti->identifier, identifier);
5046 setString(&ti->name, name);
5047 setString(&ti->name_sorting, name);
5048 setString(&ti->infotext, "Control Type");
5050 pushTreeInfo(&touch_controls, ti);
5053 /* sort touch control values to start with lowest touch control value */
5054 sortTreeInfo(&touch_controls);
5056 /* set current touch control value to configured touch control value */
5057 touch_control_current =
5058 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5060 /* if that fails, set current touch control to reliable default value */
5061 if (touch_control_current == NULL)
5062 touch_control_current =
5063 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5065 /* if that also fails, set current touch control to first available value */
5066 if (touch_control_current == NULL)
5067 touch_control_current = touch_controls;
5070 if (move_distances == NULL)
5074 for (i = 0; distances_list[i].value != -1; i++)
5076 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5077 char identifier[32], name[32];
5078 int value = distances_list[i].value;
5079 char *text = distances_list[i].text;
5081 ti->node_top = &move_distances;
5082 ti->sort_priority = value;
5084 sprintf(identifier, "%d", value);
5085 sprintf(name, "%s", text);
5087 setString(&ti->identifier, identifier);
5088 setString(&ti->name, name);
5089 setString(&ti->name_sorting, name);
5090 setString(&ti->infotext, "Move Distance");
5092 pushTreeInfo(&move_distances, ti);
5095 /* sort distance values to start with lowest distance value */
5096 sortTreeInfo(&move_distances);
5098 /* set current distance value to configured distance value */
5099 move_distance_current =
5100 getTreeInfoFromIdentifier(move_distances,
5101 i_to_a(setup.touch.move_distance));
5103 /* if that fails, set current distance to reliable default value */
5104 if (move_distance_current == NULL)
5105 move_distance_current =
5106 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5108 /* if that also fails, set current distance to first available value */
5109 if (move_distance_current == NULL)
5110 move_distance_current = move_distances;
5113 if (drop_distances == NULL)
5117 for (i = 0; distances_list[i].value != -1; i++)
5119 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5120 char identifier[32], name[32];
5121 int value = distances_list[i].value;
5122 char *text = distances_list[i].text;
5124 ti->node_top = &drop_distances;
5125 ti->sort_priority = value;
5127 sprintf(identifier, "%d", value);
5128 sprintf(name, "%s", text);
5130 setString(&ti->identifier, identifier);
5131 setString(&ti->name, name);
5132 setString(&ti->name_sorting, name);
5133 setString(&ti->infotext, "Drop Distance");
5135 pushTreeInfo(&drop_distances, ti);
5138 /* sort distance values to start with lowest distance value */
5139 sortTreeInfo(&drop_distances);
5141 /* set current distance value to configured distance value */
5142 drop_distance_current =
5143 getTreeInfoFromIdentifier(drop_distances,
5144 i_to_a(setup.touch.drop_distance));
5146 /* if that fails, set current distance to reliable default value */
5147 if (drop_distance_current == NULL)
5148 drop_distance_current =
5149 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5151 /* if that also fails, set current distance to first available value */
5152 if (drop_distance_current == NULL)
5153 drop_distance_current = drop_distances;
5156 setup.touch.control_type = touch_control_current->identifier;
5157 setup.touch.move_distance = atoi(move_distance_current->identifier);
5158 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5160 /* needed for displaying volume text instead of identifier */
5161 touch_controls_text = touch_control_current->name;
5162 move_distance_text = move_distance_current->name;
5163 drop_distance_text = drop_distance_current->name;
5165 setup_mode = SETUP_MODE_TOUCH;
5170 static void execSetupArtwork()
5173 printf("::: '%s', '%s', '%s'\n",
5174 artwork.gfx_current->subdir,
5175 artwork.gfx_current->fullpath,
5176 artwork.gfx_current->basepath);
5179 setup.graphics_set = artwork.gfx_current->identifier;
5180 setup.sounds_set = artwork.snd_current->identifier;
5181 setup.music_set = artwork.mus_current->identifier;
5183 /* needed if last screen (setup choice) changed graphics, sounds or music */
5184 ReloadCustomArtwork(0);
5186 /* needed for displaying artwork name instead of artwork identifier */
5187 graphics_set_name = artwork.gfx_current->name;
5188 sounds_set_name = artwork.snd_current->name;
5189 music_set_name = artwork.mus_current->name;
5191 setup_mode = SETUP_MODE_ARTWORK;
5196 static void execSetupChooseGraphics()
5198 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5203 static void execSetupChooseSounds()
5205 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5210 static void execSetupChooseMusic()
5212 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5217 #if !defined(PLATFORM_ANDROID)
5218 static void execSetupInput()
5220 setup_mode = SETUP_MODE_INPUT;
5226 static void execSetupShortcuts()
5228 setup_mode = SETUP_MODE_SHORTCUTS;
5233 static void execSetupShortcuts1()
5235 setup_mode = SETUP_MODE_SHORTCUTS_1;
5240 static void execSetupShortcuts2()
5242 setup_mode = SETUP_MODE_SHORTCUTS_2;
5247 static void execSetupShortcuts3()
5249 setup_mode = SETUP_MODE_SHORTCUTS_3;
5254 static void execSetupShortcuts4()
5256 setup_mode = SETUP_MODE_SHORTCUTS_4;
5261 static void execSetupShortcuts5()
5263 setup_mode = SETUP_MODE_SHORTCUTS_5;
5268 static void execExitSetup()
5270 SetGameStatus(GAME_MODE_MAIN);
5275 static void execSaveAndExitSetup()
5281 static struct TokenInfo setup_info_main[] =
5283 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5284 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5285 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5286 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5287 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5288 #if !defined(PLATFORM_ANDROID)
5289 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5290 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5292 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5294 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5295 { TYPE_EMPTY, NULL, "" },
5296 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5297 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5302 static struct TokenInfo setup_info_game[] =
5304 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5305 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5306 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5307 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5308 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5309 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5310 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5311 { TYPE_STRING, &game_speed_text, "" },
5313 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5314 { TYPE_STRING, &scroll_delay_text, "" },
5316 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5317 { TYPE_STRING, &snapshot_mode_text, "" },
5318 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5319 { TYPE_EMPTY, NULL, "" },
5320 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5325 static struct TokenInfo setup_info_editor[] =
5328 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5329 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5330 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5331 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5332 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5333 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5334 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5335 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5337 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5338 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5339 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5341 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5343 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5344 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5345 { TYPE_EMPTY, NULL, "" },
5347 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5348 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5349 { TYPE_EMPTY, NULL, "" },
5351 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5352 { TYPE_EMPTY, NULL, "" },
5353 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5358 static struct TokenInfo setup_info_graphics[] =
5360 #if !defined(PLATFORM_ANDROID)
5361 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5362 #if defined(TARGET_SDL2)
5363 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5364 { TYPE_STRING, &window_size_text, "" },
5365 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5366 { TYPE_STRING, &scaling_type_text, "" },
5368 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5369 { TYPE_STRING, &screen_mode_text, "" },
5373 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5374 { TYPE_STRING, &scroll_delay_text, "" },
5376 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5377 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5378 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5379 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5380 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5381 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5382 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5383 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5384 { TYPE_EMPTY, NULL, "" },
5385 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5390 static struct TokenInfo setup_info_sound[] =
5392 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5393 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5394 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5395 { TYPE_EMPTY, NULL, "" },
5396 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5397 { TYPE_STRING, &volume_simple_text, "" },
5398 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5399 { TYPE_STRING, &volume_loops_text, "" },
5400 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5401 { TYPE_STRING, &volume_music_text, "" },
5402 { TYPE_EMPTY, NULL, "" },
5403 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5408 static struct TokenInfo setup_info_artwork[] =
5410 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5411 { TYPE_STRING, &graphics_set_name, "" },
5412 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5413 { TYPE_STRING, &sounds_set_name, "" },
5414 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5415 { TYPE_STRING, &music_set_name, "" },
5416 { TYPE_EMPTY, NULL, "" },
5417 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5418 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5419 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5420 { TYPE_EMPTY, NULL, "" },
5421 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5426 static struct TokenInfo setup_info_input[] =
5428 { TYPE_SWITCH, NULL, "Player:" },
5429 { TYPE_SWITCH, NULL, "Device:" },
5430 { TYPE_ENTER_MENU, NULL, "" },
5431 { TYPE_EMPTY, NULL, "" },
5432 { TYPE_EMPTY, NULL, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_EMPTY, NULL, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_EMPTY, NULL, "" },
5437 { TYPE_EMPTY, NULL, "" },
5438 { TYPE_EMPTY, NULL, "" },
5439 { TYPE_EMPTY, NULL, "" },
5440 { TYPE_EMPTY, NULL, "" },
5441 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5446 static struct TokenInfo setup_info_touch[] =
5448 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5449 { TYPE_STRING, &touch_controls_text, "" },
5450 { TYPE_EMPTY, NULL, "" },
5451 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5452 { TYPE_STRING, &move_distance_text, "" },
5453 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5454 { TYPE_STRING, &drop_distance_text, "" },
5455 { TYPE_EMPTY, NULL, "" },
5456 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5461 static struct TokenInfo setup_info_shortcuts[] =
5463 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5464 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5465 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5466 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5467 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5468 { TYPE_EMPTY, NULL, "" },
5469 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5474 static struct TokenInfo setup_info_shortcuts_1[] =
5476 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5477 { TYPE_KEY, &setup.shortcut.save_game, "" },
5478 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5479 { TYPE_KEY, &setup.shortcut.load_game, "" },
5480 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5481 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5482 { TYPE_EMPTY, NULL, "" },
5483 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5484 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5485 { TYPE_EMPTY, NULL, "" },
5486 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5491 static struct TokenInfo setup_info_shortcuts_2[] =
5493 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5494 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5495 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5496 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5497 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5498 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5499 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5500 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5501 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5502 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5503 { TYPE_EMPTY, NULL, "" },
5504 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5509 static struct TokenInfo setup_info_shortcuts_3[] =
5511 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5512 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5513 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5514 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5515 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5516 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5517 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5518 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5519 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5520 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5521 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5522 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5523 { TYPE_EMPTY, NULL, "" },
5524 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5529 static struct TokenInfo setup_info_shortcuts_4[] =
5531 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5532 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5533 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5534 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5535 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5536 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5537 { TYPE_EMPTY, NULL, "" },
5538 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5543 static struct TokenInfo setup_info_shortcuts_5[] =
5545 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5546 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5547 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5548 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5549 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5550 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5551 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5552 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5553 { TYPE_EMPTY, NULL, "" },
5554 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5559 static Key getSetupKey()
5561 Key key = KSYM_UNDEFINED;
5562 boolean got_key_event = FALSE;
5564 while (!got_key_event)
5566 if (PendingEvent()) /* got event */
5574 case EVENT_KEYPRESS:
5576 key = GetEventKey((KeyEvent *)&event, TRUE);
5578 /* press 'Escape' or 'Enter' to keep the existing key binding */
5579 if (key == KSYM_Escape || key == KSYM_Return)
5580 key = KSYM_UNDEFINED; /* keep old value */
5582 got_key_event = TRUE;
5586 case EVENT_KEYRELEASE:
5587 key_joystick_mapping = 0;
5591 HandleOtherEvents(&event);
5599 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
5605 static int getSetupValueFont(int type, void *value)
5607 if (type & TYPE_KEY)
5608 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5609 else if (type & TYPE_STRING)
5610 return FONT_VALUE_2;
5611 else if (type & TYPE_ECS_AGA)
5612 return FONT_VALUE_1;
5613 else if (type & TYPE_BOOLEAN_STYLE)
5614 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5615 else if (type & TYPE_YES_NO_AUTO)
5616 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5617 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5619 return FONT_VALUE_1;
5622 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5624 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5625 struct TokenInfo *si = &setup_info[si_pos];
5626 boolean font_draw_xoffset_modified = FALSE;
5627 int font_draw_xoffset_old = -1;
5628 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5629 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5630 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5631 int xpos = menu_screen_value_xpos;
5632 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5633 int startx = mSX + xpos * 32;
5634 int starty = mSY + ypos * 32;
5635 int font_nr, font_width;
5636 int type = si->type;
5637 void *value = si->value;
5638 char *value_string = getSetupValue(type, value);
5641 if (value_string == NULL)
5644 if (type & TYPE_KEY)
5646 xpos = MENU_SCREEN_START_XPOS;
5648 if (type & TYPE_QUERY)
5649 value_string = "<press key>";
5651 else if (type & TYPE_STRING)
5653 int max_value_len = (SCR_FIELDX - 2) * 2;
5655 xpos = MENU_SCREEN_START_XPOS;
5657 if (strlen(value_string) > max_value_len)
5658 value_string[max_value_len] = '\0';
5660 else if (type & TYPE_YES_NO_AUTO)
5662 xpos = menu_screen_value_xpos - 1;
5665 startx = mSX + xpos * 32;
5666 starty = mSY + ypos * 32;
5667 font_nr = getSetupValueFont(type, value);
5668 font_width = getFontWidth(font_nr);
5670 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5671 if (setup_mode != SETUP_MODE_INPUT)
5673 int max_menu_text_length_big = (menu_screen_value_xpos -
5674 MENU_SCREEN_START_XPOS);
5675 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5676 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5677 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5678 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5679 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5680 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5681 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5682 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5683 boolean correct_font_draw_xoffset = FALSE;
5685 if (xpos == MENU_SCREEN_START_XPOS &&
5686 startx + font1_xoffset < text_startx + text_font_xoffset)
5687 correct_font_draw_xoffset = TRUE;
5689 if (xpos == menu_screen_value_xpos &&
5690 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5691 correct_font_draw_xoffset = TRUE;
5693 /* check if setup value would overlap with setup text when printed */
5694 /* (this can happen for extreme/wrong values for font draw offset) */
5695 if (correct_font_draw_xoffset)
5697 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5698 font_draw_xoffset_modified = TRUE;
5700 if (type & TYPE_KEY)
5701 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5702 else if (!(type & TYPE_STRING))
5703 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5704 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5708 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5709 DrawText(startx + i * font_width, starty, " ", font_nr);
5711 DrawText(startx, starty, value_string, font_nr);
5713 if (font_draw_xoffset_modified)
5714 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5717 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5719 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5720 struct TokenInfo *si = &setup_info[si_pos];
5722 if (si->type & TYPE_BOOLEAN_STYLE)
5724 *(boolean *)si->value ^= TRUE;
5726 else if (si->type & TYPE_YES_NO_AUTO)
5730 (*(int *)si->value == AUTO ? TRUE :
5731 *(int *)si->value == TRUE ? FALSE : AUTO) :
5732 (*(int *)si->value == TRUE ? AUTO :
5733 *(int *)si->value == AUTO ? FALSE : TRUE));
5735 else if (si->type & TYPE_KEY)
5739 si->type |= TYPE_QUERY;
5740 drawSetupValue(screen_pos, setup_info_pos_raw);
5741 si->type &= ~TYPE_QUERY;
5743 key = getSetupKey();
5744 if (key != KSYM_UNDEFINED)
5745 *(Key *)si->value = key;
5748 drawSetupValue(screen_pos, setup_info_pos_raw);
5750 // fullscreen state may have changed at this point
5751 if (si->value == &setup.fullscreen)
5752 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5755 static void DrawSetupScreen_Generic()
5757 int fade_mask = REDRAW_FIELD;
5758 boolean redraw_all = FALSE;
5759 char *title_string = NULL;
5762 if (CheckIfGlobalBorderHasChanged())
5763 fade_mask = REDRAW_ALL;
5767 FreeScreenGadgets();
5768 CreateScreenGadgets();
5770 if (redraw_mask & REDRAW_ALL)
5777 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5779 if (setup_mode == SETUP_MODE_MAIN)
5781 setup_info = setup_info_main;
5782 title_string = "Setup";
5784 else if (setup_mode == SETUP_MODE_GAME)
5786 setup_info = setup_info_game;
5787 title_string = "Setup Game";
5789 else if (setup_mode == SETUP_MODE_EDITOR)
5791 setup_info = setup_info_editor;
5792 title_string = "Setup Editor";
5794 else if (setup_mode == SETUP_MODE_GRAPHICS)
5796 setup_info = setup_info_graphics;
5797 title_string = "Setup Graphics";
5799 else if (setup_mode == SETUP_MODE_SOUND)
5801 setup_info = setup_info_sound;
5802 title_string = "Setup Sound";
5804 else if (setup_mode == SETUP_MODE_ARTWORK)
5806 setup_info = setup_info_artwork;
5807 title_string = "Custom Artwork";
5809 else if (setup_mode == SETUP_MODE_TOUCH)
5811 setup_info = setup_info_touch;
5812 title_string = "Setup Touch Ctrls";
5814 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5816 setup_info = setup_info_shortcuts;
5817 title_string = "Setup Shortcuts";
5819 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5821 setup_info = setup_info_shortcuts_1;
5822 title_string = "Setup Shortcuts";
5824 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5826 setup_info = setup_info_shortcuts_2;
5827 title_string = "Setup Shortcuts";
5829 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5831 setup_info = setup_info_shortcuts_3;
5832 title_string = "Setup Shortcuts";
5834 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5836 setup_info = setup_info_shortcuts_4;
5837 title_string = "Setup Shortcuts";
5839 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5841 setup_info = setup_info_shortcuts_5;
5842 title_string = "Setup Shortcuts";
5845 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5847 // determine maximal number of setup entries that can be displayed on screen
5849 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5852 // determine maximal number of setup entries available for this setup screen
5854 for (i = 0; setup_info[i].type != 0; i++)
5857 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5859 MapScreenGadgets(max_setup_info);
5862 redraw_mask = fade_mask = REDRAW_ALL;
5864 DrawMaskedBorder(fade_mask);
5871 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5873 menu_info = setup_info;
5875 HandleMenuScreen(mx, my, dx, dy, button,
5876 setup_mode, num_setup_info, max_setup_info);
5879 void DrawSetupScreen_Input()
5883 FadeOut(REDRAW_FIELD);
5887 setup_info = setup_info_input;
5889 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5891 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5892 "Joysticks deactivated on this screen");
5894 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5896 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5897 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5898 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5899 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5900 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5901 initCursor(i, IMG_MENU_BUTTON);
5903 DrawCursorAndText_Setup(i, -1, FALSE);
5906 /* create gadgets for setup input menu screen */
5907 FreeScreenGadgets();
5908 CreateScreenGadgets();
5910 /* map gadgets for setup input menu screen */
5911 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5913 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5915 FadeIn(REDRAW_FIELD);
5920 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5922 if (device_name == NULL)
5925 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5928 if (strlen(device_name) > 1)
5930 char c1 = device_name[strlen(device_name) - 1];
5931 char c2 = device_name[strlen(device_name) - 2];
5933 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5934 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5937 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5938 strlen(device_name));
5941 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5944 static struct SetupKeyboardInfo custom_key;
5951 { &custom_key.left, "Joystick Left" },
5952 { &custom_key.right, "Joystick Right" },
5953 { &custom_key.up, "Joystick Up" },
5954 { &custom_key.down, "Joystick Down" },
5955 { &custom_key.snap, "Button 1" },
5956 { &custom_key.drop, "Button 2" }
5958 static char *joystick_name[MAX_PLAYERS] =
5965 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5969 custom_key = setup.input[player_nr].key;
5971 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5972 FONT_INPUT_1_ACTIVE);
5974 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5976 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5977 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5979 if (setup.input[player_nr].use_joystick)
5981 char *device_name = setup.input[player_nr].joy.device_name;
5982 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5983 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5985 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5986 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5990 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5991 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5994 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5996 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5997 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5998 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5999 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6001 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6002 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6003 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6004 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6005 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6006 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6008 for (i = 0; i < 6; i++)
6010 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6012 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6014 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6015 (setup.input[player_nr].use_joystick ?
6017 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6021 static int input_player_nr = 0;
6023 void HandleSetupScreen_Input_Player(int step, int direction)
6025 int old_player_nr = input_player_nr;
6028 new_player_nr = old_player_nr + step * direction;
6029 if (new_player_nr < 0)
6031 if (new_player_nr > MAX_PLAYERS - 1)
6032 new_player_nr = MAX_PLAYERS - 1;
6034 if (new_player_nr != old_player_nr)
6036 input_player_nr = new_player_nr;
6038 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6042 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6044 static int choice = 0;
6047 int pos_start = SETUPINPUT_SCREEN_POS_START;
6048 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6049 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6050 int pos_end = SETUPINPUT_SCREEN_POS_END;
6052 if (button == MB_MENU_INITIALIZE)
6054 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6056 DrawCursorAndText_Setup(choice, -1, TRUE);
6060 else if (button == MB_MENU_LEAVE)
6062 setup_mode = SETUP_MODE_MAIN;
6069 if (mx || my) /* mouse input */
6071 x = (mx - mSX) / 32;
6072 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6074 else if (dx || dy) /* keyboard input */
6076 if (dx && choice == 0)
6077 x = (dx < 0 ? 10 : 12);
6078 else if ((dx && choice == 1) ||
6079 (dx == +1 && choice == 2) ||
6080 (dx == -1 && choice == pos_end))
6081 button = MB_MENU_CHOICE;
6085 if (y >= pos_empty1 && y <= pos_empty2)
6086 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6089 if (y == 0 && dx != 0 && button)
6091 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6093 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6094 y >= pos_start && y <= pos_end &&
6095 !(y >= pos_empty1 && y <= pos_empty2))
6101 DrawCursorAndText_Setup(choice, -1, FALSE);
6102 DrawCursorAndText_Setup(y, -1, TRUE);
6104 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6113 char *device_name = setup.input[input_player_nr].joy.device_name;
6115 if (!setup.input[input_player_nr].use_joystick)
6117 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6119 setJoystickDeviceToNr(device_name, new_device_nr);
6120 setup.input[input_player_nr].use_joystick = TRUE;
6124 int device_nr = getJoystickNrFromDeviceName(device_name);
6125 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6127 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6128 setup.input[input_player_nr].use_joystick = FALSE;
6130 setJoystickDeviceToNr(device_name, new_device_nr);
6133 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6137 if (setup.input[input_player_nr].use_joystick)
6140 CalibrateJoystick(input_player_nr);
6143 CustomizeKeyboard(input_player_nr);
6145 else if (y == pos_end)
6151 setup_mode = SETUP_MODE_MAIN;
6158 void CustomizeKeyboard(int player_nr)
6162 boolean finished = FALSE;
6163 static struct SetupKeyboardInfo custom_key;
6168 } customize_step[] =
6170 { &custom_key.left, "Move Left" },
6171 { &custom_key.right, "Move Right" },
6172 { &custom_key.up, "Move Up" },
6173 { &custom_key.down, "Move Down" },
6174 { &custom_key.snap, "Snap Field" },
6175 { &custom_key.drop, "Drop Element" }
6178 /* read existing key bindings from player setup */
6179 custom_key = setup.input[player_nr].key;
6182 FadeOut(REDRAW_FIELD);
6186 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6189 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6190 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6191 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6192 "Key:", FONT_INPUT_1_ACTIVE);
6193 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6194 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6196 FadeIn(REDRAW_FIELD);
6202 if (PendingEvent()) /* got event */
6210 case EVENT_KEYPRESS:
6212 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6214 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6216 if (key == KSYM_Escape)
6217 FadeSkipNextFadeIn();
6223 /* all keys configured -- wait for "Escape" or "Return" key */
6227 /* press 'Enter' to keep the existing key binding */
6228 if (key == KSYM_Return)
6229 key = *customize_step[step_nr].key;
6231 /* check if key already used */
6232 for (i = 0; i < step_nr; i++)
6233 if (*customize_step[i].key == key)
6238 /* got new key binding */
6239 *customize_step[step_nr].key = key;
6240 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6242 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6243 getKeyNameFromKey(key), FONT_VALUE_1);
6246 /* un-highlight last query */
6247 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6248 customize_step[step_nr - 1].text, FONT_MENU_1);
6249 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6250 "Key:", FONT_MENU_1);
6252 /* press 'Enter' to leave */
6255 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6256 "Press Enter", FONT_TITLE_1);
6260 /* query next key binding */
6261 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6262 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6263 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6264 "Key:", FONT_INPUT_1_ACTIVE);
6265 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6266 getKeyNameFromKey(*customize_step[step_nr].key),
6271 case EVENT_KEYRELEASE:
6272 key_joystick_mapping = 0;
6276 HandleOtherEvents(&event);
6284 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6287 /* write new key bindings back to player setup */
6288 setup.input[player_nr].key = custom_key;
6291 DrawSetupScreen_Input();
6294 static boolean CalibrateJoystickMain(int player_nr)
6296 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6297 int new_joystick_xright = JOYSTICK_XMIDDLE;
6298 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6299 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6300 int new_joystick_xmiddle, new_joystick_ymiddle;
6302 int joystick_fd = joystick.fd[player_nr];
6303 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6304 boolean check[3][3];
6305 int check_remaining = 3 * 3;
6310 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6313 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6317 FadeOut(REDRAW_FIELD);
6321 for (y = 0; y < 3; y++)
6323 for (x = 0; x < 3; x++)
6325 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6326 check[x][y] = FALSE;
6330 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6331 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6332 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6333 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6334 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6335 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6336 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6338 joy_value = Joystick(player_nr);
6339 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6340 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6342 /* eventually uncalibrated center position (joystick could be uncentered) */
6343 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6346 new_joystick_xmiddle = joy_x;
6347 new_joystick_ymiddle = joy_y;
6349 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6351 FadeIn(REDRAW_FIELD);
6353 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6358 if (PendingEvent()) /* got event */
6366 case EVENT_KEYPRESS:
6367 switch (GetEventKey((KeyEvent *)&event, TRUE))
6370 if (check_remaining == 0)
6375 FadeSkipNextFadeIn();
6384 case EVENT_KEYRELEASE:
6385 key_joystick_mapping = 0;
6389 HandleOtherEvents(&event);
6394 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6397 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6398 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6399 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6400 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6402 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6403 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6404 setup.input[player_nr].joy.xright = new_joystick_xright;
6405 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6406 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6407 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6409 CheckJoystickData();
6411 joy_value = Joystick(player_nr);
6413 if (joy_value & JOY_BUTTON && check_remaining == 0)
6416 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6417 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6419 if (x != last_x || y != last_y)
6421 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6422 IMG_MENU_CALIBRATE_YELLOW, 0);
6423 DrawFixedGraphic(xpos + x, ypos + y,
6424 IMG_MENU_CALIBRATE_RED, 0);
6429 if (check_remaining > 0 && !check[x+1][y+1])
6431 check[x+1][y+1] = TRUE;
6439 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6442 /* calibrated center position (joystick should now be centered) */
6443 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6446 new_joystick_xmiddle = joy_x;
6447 new_joystick_ymiddle = joy_y;
6451 /* wait until the last pressed button was released */
6452 while (Joystick(player_nr) & JOY_BUTTON)
6454 if (PendingEvent()) /* got event */
6459 HandleOtherEvents(&event);
6461 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6468 void CalibrateJoystick(int player_nr)
6470 if (!CalibrateJoystickMain(player_nr))
6472 char *device_name = setup.input[player_nr].joy.device_name;
6473 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6474 int xpos = mSX - SX;
6475 int ypos = mSY - SY;
6479 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6480 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6483 Delay(2000); /* show error message for a short time */
6488 DrawSetupScreen_Input();
6491 void DrawSetupScreen()
6493 DeactivateJoystick();
6495 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6497 if (setup_mode == SETUP_MODE_INPUT)
6498 DrawSetupScreen_Input();
6499 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6500 DrawChooseTree(&game_speed_current);
6501 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6502 DrawChooseTree(&scroll_delay_current);
6503 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6504 DrawChooseTree(&snapshot_mode_current);
6505 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6506 DrawChooseTree(&screen_mode_current);
6507 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6508 DrawChooseTree(&window_size_current);
6509 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6510 DrawChooseTree(&scaling_type_current);
6511 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6512 DrawChooseTree(&artwork.gfx_current);
6513 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6514 DrawChooseTree(&artwork.snd_current);
6515 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6516 DrawChooseTree(&artwork.mus_current);
6517 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6518 DrawChooseTree(&volume_simple_current);
6519 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6520 DrawChooseTree(&volume_loops_current);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6522 DrawChooseTree(&volume_music_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6524 DrawChooseTree(&touch_control_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6526 DrawChooseTree(&move_distance_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6528 DrawChooseTree(&drop_distance_current);
6530 DrawSetupScreen_Generic();
6536 void RedrawSetupScreenAfterFullscreenToggle()
6538 if (setup_mode == SETUP_MODE_GRAPHICS ||
6539 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6541 // update list selection from "setup.window_scaling_percent"
6542 execSetupGraphics_setWindowSizes(TRUE);
6548 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6550 if (setup_mode == SETUP_MODE_INPUT)
6551 HandleSetupScreen_Input(mx, my, dx, dy, button);
6552 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6553 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6554 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6555 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6556 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6557 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6558 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6559 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6560 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6561 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6562 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6563 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6564 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6565 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6566 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6567 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6568 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6569 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6570 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6571 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6573 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6575 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6577 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6579 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6581 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6583 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6586 void HandleGameActions()
6588 if (game_status != GAME_MODE_PLAYING)
6591 GameActions(); /* main game loop */
6593 if (tape.auto_play && !tape.playing)
6594 AutoPlayTape(); /* continue automatically playing next tape */
6598 /* ---------- new screen button stuff -------------------------------------- */
6600 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6604 case SCREEN_CTRL_ID_PREV_LEVEL:
6605 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6606 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6609 case SCREEN_CTRL_ID_NEXT_LEVEL:
6610 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6611 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6614 case SCREEN_CTRL_ID_PREV_PLAYER:
6615 *x = mSX + TILEX * 10;
6616 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6619 case SCREEN_CTRL_ID_NEXT_PLAYER:
6620 *x = mSX + TILEX * 12;
6621 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6625 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6631 int gfx_unpressed, gfx_pressed;
6632 void (*get_gadget_position)(int *, int *, int);
6636 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6639 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6640 getScreenMenuButtonPos,
6641 SCREEN_CTRL_ID_PREV_LEVEL,
6646 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6647 getScreenMenuButtonPos,
6648 SCREEN_CTRL_ID_NEXT_LEVEL,
6653 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6654 getScreenMenuButtonPos,
6655 SCREEN_CTRL_ID_PREV_PLAYER,
6660 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6661 getScreenMenuButtonPos,
6662 SCREEN_CTRL_ID_NEXT_PLAYER,
6670 int gfx_unpressed, gfx_pressed;
6674 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6677 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6678 -1, -1, /* these values are not constant, but can change at runtime */
6679 SCREEN_CTRL_ID_SCROLL_UP,
6683 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6684 -1, -1, /* these values are not constant, but can change at runtime */
6685 SCREEN_CTRL_ID_SCROLL_DOWN,
6692 int gfx_unpressed, gfx_pressed;
6698 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6701 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6702 -1, -1, /* these values are not constant, but can change at runtime */
6703 -1, -1, /* these values are not constant, but can change at runtime */
6704 GD_TYPE_SCROLLBAR_VERTICAL,
6705 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6706 "scroll level series vertically"
6710 static void CreateScreenMenubuttons()
6712 struct GadgetInfo *gi;
6713 unsigned int event_mask;
6716 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6718 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6719 int gfx_unpressed, gfx_pressed;
6720 int x, y, width, height;
6721 int gd_x1, gd_x2, gd_y1, gd_y2;
6722 int id = menubutton_info[i].gadget_id;
6724 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6726 menubutton_info[i].get_gadget_position(&x, &y, id);
6728 width = SC_MENUBUTTON_XSIZE;
6729 height = SC_MENUBUTTON_YSIZE;
6731 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6732 gfx_pressed = menubutton_info[i].gfx_pressed;
6733 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6734 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6735 gd_x1 = graphic_info[gfx_unpressed].src_x;
6736 gd_y1 = graphic_info[gfx_unpressed].src_y;
6737 gd_x2 = graphic_info[gfx_pressed].src_x;
6738 gd_y2 = graphic_info[gfx_pressed].src_y;
6740 gi = CreateGadget(GDI_CUSTOM_ID, id,
6741 GDI_CUSTOM_TYPE_ID, i,
6742 GDI_INFO_TEXT, menubutton_info[i].infotext,
6747 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6748 GDI_STATE, GD_BUTTON_UNPRESSED,
6749 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6750 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6751 GDI_DIRECT_DRAW, FALSE,
6752 GDI_EVENT_MASK, event_mask,
6753 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6757 Error(ERR_EXIT, "cannot create gadget");
6759 screen_gadget[id] = gi;
6763 static void CreateScreenScrollbuttons()
6765 struct GadgetInfo *gi;
6766 unsigned int event_mask;
6769 /* these values are not constant, but can change at runtime */
6770 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6771 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6772 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6773 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6775 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6777 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6778 int gfx_unpressed, gfx_pressed;
6779 int x, y, width, height;
6780 int gd_x1, gd_x2, gd_y1, gd_y2;
6781 int id = scrollbutton_info[i].gadget_id;
6783 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6785 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6786 y = mSY + scrollbutton_info[i].y;
6787 width = SC_SCROLLBUTTON_XSIZE;
6788 height = SC_SCROLLBUTTON_YSIZE;
6790 /* correct scrollbar position if placed outside menu (playfield) area */
6791 if (x > SX + SC_SCROLL_UP_XPOS)
6792 x = SX + SC_SCROLL_UP_XPOS;
6794 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6795 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6796 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6798 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6799 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6800 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6801 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6802 gd_x1 = graphic_info[gfx_unpressed].src_x;
6803 gd_y1 = graphic_info[gfx_unpressed].src_y;
6804 gd_x2 = graphic_info[gfx_pressed].src_x;
6805 gd_y2 = graphic_info[gfx_pressed].src_y;
6807 gi = CreateGadget(GDI_CUSTOM_ID, id,
6808 GDI_CUSTOM_TYPE_ID, i,
6809 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6814 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6815 GDI_STATE, GD_BUTTON_UNPRESSED,
6816 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6817 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6818 GDI_DIRECT_DRAW, FALSE,
6819 GDI_EVENT_MASK, event_mask,
6820 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6824 Error(ERR_EXIT, "cannot create gadget");
6826 screen_gadget[id] = gi;
6830 static void CreateScreenScrollbars()
6834 /* these values are not constant, but can change at runtime */
6835 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6836 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6837 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6838 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6840 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6842 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6843 int gfx_unpressed, gfx_pressed;
6844 int x, y, width, height;
6845 int gd_x1, gd_x2, gd_y1, gd_y2;
6846 struct GadgetInfo *gi;
6847 int items_max, items_visible, item_position;
6848 unsigned int event_mask;
6849 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6850 int id = scrollbar_info[i].gadget_id;
6852 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6854 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6855 y = mSY + scrollbar_info[i].y;
6856 width = scrollbar_info[i].width;
6857 height = scrollbar_info[i].height;
6859 /* correct scrollbar position if placed outside menu (playfield) area */
6860 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6861 x = SX + SC_SCROLL_VERTICAL_XPOS;
6863 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6864 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6866 items_max = num_page_entries;
6867 items_visible = num_page_entries;
6870 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6871 gfx_pressed = scrollbar_info[i].gfx_pressed;
6872 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6873 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6874 gd_x1 = graphic_info[gfx_unpressed].src_x;
6875 gd_y1 = graphic_info[gfx_unpressed].src_y;
6876 gd_x2 = graphic_info[gfx_pressed].src_x;
6877 gd_y2 = graphic_info[gfx_pressed].src_y;
6879 gi = CreateGadget(GDI_CUSTOM_ID, id,
6880 GDI_CUSTOM_TYPE_ID, i,
6881 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6886 GDI_TYPE, scrollbar_info[i].type,
6887 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6888 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6889 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6890 GDI_WHEEL_AREA_X, SX,
6891 GDI_WHEEL_AREA_Y, SY,
6892 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6893 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6894 GDI_STATE, GD_BUTTON_UNPRESSED,
6895 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6896 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6897 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6898 GDI_DIRECT_DRAW, FALSE,
6899 GDI_EVENT_MASK, event_mask,
6900 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6904 Error(ERR_EXIT, "cannot create gadget");
6906 screen_gadget[id] = gi;
6910 void CreateScreenGadgets()
6912 int last_game_status = game_status; /* save current game status */
6914 CreateScreenMenubuttons();
6916 CreateScreenScrollbuttons();
6917 CreateScreenScrollbars();
6919 SetGameStatus(last_game_status); /* restore current game status */
6922 void FreeScreenGadgets()
6926 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6927 FreeGadget(screen_gadget[i]);
6930 void MapScreenMenuGadgets(int screen_mask)
6934 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6935 if (screen_mask & menubutton_info[i].screen_mask)
6936 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6939 void MapScreenGadgets(int num_entries)
6943 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6946 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6947 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6949 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6950 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6953 void MapScreenTreeGadgets(TreeInfo *ti)
6955 MapScreenGadgets(numTreeInfoInGroup(ti));
6958 static void HandleScreenGadgets(struct GadgetInfo *gi)
6960 int id = gi->custom_id;
6961 int button = gi->event.button;
6962 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6966 case SCREEN_CTRL_ID_PREV_LEVEL:
6967 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6970 case SCREEN_CTRL_ID_NEXT_LEVEL:
6971 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6974 case SCREEN_CTRL_ID_PREV_PLAYER:
6975 HandleSetupScreen_Input_Player(step, -1);
6978 case SCREEN_CTRL_ID_NEXT_PLAYER:
6979 HandleSetupScreen_Input_Player(step, +1);
6982 case SCREEN_CTRL_ID_SCROLL_UP:
6983 if (game_status == GAME_MODE_LEVELS)
6984 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6985 else if (game_status == GAME_MODE_LEVELNR)
6986 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6987 else if (game_status == GAME_MODE_SETUP)
6988 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6989 else if (game_status == GAME_MODE_INFO)
6990 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6993 case SCREEN_CTRL_ID_SCROLL_DOWN:
6994 if (game_status == GAME_MODE_LEVELS)
6995 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6996 else if (game_status == GAME_MODE_LEVELNR)
6997 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6998 else if (game_status == GAME_MODE_SETUP)
6999 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7000 else if (game_status == GAME_MODE_INFO)
7001 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7004 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7005 if (game_status == GAME_MODE_LEVELS)
7006 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7007 else if (game_status == GAME_MODE_LEVELNR)
7008 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7009 else if (game_status == GAME_MODE_SETUP)
7010 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7011 else if (game_status == GAME_MODE_INFO)
7012 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);