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 /* for input setup functions */
80 #define SETUPINPUT_SCREEN_POS_START 0
81 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
82 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
83 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
85 /* for various menu stuff */
86 #define MENU_SCREEN_START_XPOS 1
87 #define MENU_SCREEN_START_YPOS 2
88 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
89 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
90 #define MENU_TITLE1_YPOS 8
91 #define MENU_TITLE2_YPOS 46
92 #define MENU_SCREEN_INFO_XSTART 16
93 #define MENU_SCREEN_INFO_YSTART1 100
94 #define MENU_SCREEN_INFO_YSTART2 128
95 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
96 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
97 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
98 MENU_SCREEN_INFO_YSTART2 - \
100 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
101 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
102 MENU_SCREEN_INFO_YSTEP, \
103 MAX_INFO_ELEMENTS_ON_SCREEN)
104 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
105 #define MAX_MENU_TEXT_LENGTH_BIG 13
106 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
108 /* buttons and scrollbars identifiers */
109 #define SCREEN_CTRL_ID_PREV_LEVEL 0
110 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
111 #define SCREEN_CTRL_ID_PREV_PLAYER 2
112 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
113 #define SCREEN_CTRL_ID_SCROLL_UP 4
114 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
115 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
117 #define NUM_SCREEN_GADGETS 7
119 #define NUM_SCREEN_MENUBUTTONS 4
120 #define NUM_SCREEN_SCROLLBUTTONS 2
121 #define NUM_SCREEN_SCROLLBARS 1
123 #define SCREEN_MASK_MAIN (1 << 0)
124 #define SCREEN_MASK_INPUT (1 << 1)
126 /* graphic position and size values for buttons and scrollbars */
127 #define SC_MENUBUTTON_XSIZE TILEX
128 #define SC_MENUBUTTON_YSIZE TILEY
130 #define SC_SCROLLBUTTON_XSIZE TILEX
131 #define SC_SCROLLBUTTON_YSIZE TILEY
133 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
135 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
136 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
137 SC_SCROLLBUTTON_YSIZE)
139 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
140 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
142 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
143 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
144 SC_SCROLLBUTTON_YSIZE)
146 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
147 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
148 SC_SCROLL_VERTICAL_YSIZE)
150 #define SC_BORDER_SIZE 14
153 /* forward declarations of internal functions */
154 static void HandleScreenGadgets(struct GadgetInfo *);
155 static void HandleSetupScreen_Generic(int, int, int, int, int);
156 static void HandleSetupScreen_Input(int, int, int, int, int);
157 static void CustomizeKeyboard(int);
158 static void CalibrateJoystick(int);
159 static void execSetupGame(void);
160 static void execSetupGraphics(void);
161 static void execSetupSound(void);
162 static void execSetupTouch(void);
163 static void execSetupArtwork(void);
164 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
166 static void DrawChooseLevelSet(void);
167 static void DrawChooseLevelNr(void);
168 static void DrawInfoScreen(void);
169 static void DrawAndFadeInInfoScreen(int);
170 static void DrawSetupScreen(void);
172 static void DrawInfoScreenExt(int, int);
173 static void DrawInfoScreen_NotAvailable(char *, char *);
174 static void DrawInfoScreen_HelpAnim(int, int, boolean);
175 static void DrawInfoScreen_HelpText(int, int, int, int);
176 static void HandleInfoScreen_Main(int, int, int, int, int);
177 static void HandleInfoScreen_TitleScreen(int);
178 static void HandleInfoScreen_Elements(int);
179 static void HandleInfoScreen_Music(int);
180 static void HandleInfoScreen_Credits(int);
181 static void HandleInfoScreen_Program(int);
182 static void HandleInfoScreen_Version(int);
184 static void MapScreenMenuGadgets(int);
185 static void MapScreenGadgets(int);
186 static void MapScreenTreeGadgets(TreeInfo *);
188 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
190 static int info_mode = INFO_MODE_MAIN;
191 static int setup_mode = SETUP_MODE_MAIN;
193 static TreeInfo *screen_modes = NULL;
194 static TreeInfo *screen_mode_current = NULL;
196 static TreeInfo *window_sizes = NULL;
197 static TreeInfo *window_size_current = NULL;
199 static TreeInfo *scaling_types = NULL;
200 static TreeInfo *scaling_type_current = NULL;
202 static TreeInfo *scroll_delays = NULL;
203 static TreeInfo *scroll_delay_current = NULL;
205 static TreeInfo *snapshot_modes = NULL;
206 static TreeInfo *snapshot_mode_current = NULL;
208 static TreeInfo *game_speeds = NULL;
209 static TreeInfo *game_speed_current = NULL;
211 static TreeInfo *volumes_simple = NULL;
212 static TreeInfo *volume_simple_current = NULL;
214 static TreeInfo *volumes_loops = NULL;
215 static TreeInfo *volume_loops_current = NULL;
217 static TreeInfo *volumes_music = NULL;
218 static TreeInfo *volume_music_current = NULL;
220 static TreeInfo *touch_controls = NULL;
221 static TreeInfo *touch_control_current = NULL;
223 static TreeInfo *move_distances = NULL;
224 static TreeInfo *move_distance_current = NULL;
226 static TreeInfo *drop_distances = NULL;
227 static TreeInfo *drop_distance_current = NULL;
229 static TreeInfo *level_number = NULL;
230 static TreeInfo *level_number_current = NULL;
236 } window_sizes_list[] =
241 { 100, "100 % (Default)" },
258 } scaling_types_list[] =
260 { SCALING_QUALITY_NEAREST, "None" },
261 { SCALING_QUALITY_LINEAR, "Linear" },
262 { SCALING_QUALITY_BEST, "Anisotropic" },
271 } game_speeds_list[] =
280 { 1000, "1/1s (Extremely Slow)" },
285 { 29, "1/35s (Original Supaplex)" },
287 { 20, "1/50s (Normal Speed)" },
288 { 14, "1/70s (Maximum Supaplex)" },
292 { 1, "1/1000s (Extremely Fast)" },
302 } scroll_delays_list[] =
304 { 0, "0 Tiles (No Scroll Delay)" },
307 { 3, "3 Tiles (Default)" },
312 { 8, "8 Tiles (Maximum Scroll Delay)"},
321 } snapshot_modes_list[] =
323 { STR_SNAPSHOT_MODE_OFF, "Off" },
324 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
325 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
358 } touch_controls_list[] =
360 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
361 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
385 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
386 (s) <= GAME_MODE_SETUP ? (s) : \
387 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
388 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
390 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
391 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
392 (i) <= INFO_MODE_LEVELSET ? (i) : \
395 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
396 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
397 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
398 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
399 SETUP_MODE_CHOOSE_ARTWORK : \
400 SETUP_MODE_CHOOSE_OTHER)
402 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
403 menu.draw_xoffset[GAME_MODE_INFO] : \
404 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
405 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
406 menu.draw_yoffset[GAME_MODE_INFO] : \
407 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
409 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
410 menu.draw_xoffset[GAME_MODE_SETUP] : \
411 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
412 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
413 menu.draw_yoffset[GAME_MODE_SETUP] : \
414 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
416 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
417 DRAW_XOFFSET_INFO(info_mode) : \
418 (s) == GAME_MODE_SETUP ? \
419 DRAW_XOFFSET_SETUP(setup_mode) : \
420 menu.draw_xoffset[DRAW_MODE(s)])
421 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
422 DRAW_YOFFSET_INFO(info_mode) : \
423 (s) == GAME_MODE_SETUP ? \
424 DRAW_YOFFSET_SETUP(setup_mode) : \
425 menu.draw_yoffset[DRAW_MODE(s)])
427 #define mSX (SX + DRAW_XOFFSET(game_status))
428 #define mSY (SY + DRAW_YOFFSET(game_status))
430 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
431 menu.list_size[game_status] : \
432 MAX_MENU_ENTRIES_ON_SCREEN)
434 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
435 NUM_MENU_ENTRIES_ON_SCREEN)
438 /* title display and control definitions */
440 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
441 2 * MAX_NUM_TITLE_MESSAGES)
443 #define NO_DIRECT_LEVEL_SELECT (-1)
446 static int num_title_screens = 0;
448 struct TitleControlInfo
456 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
458 /* main menu display and control definitions */
460 #define MAIN_CONTROL_NAME 0
461 #define MAIN_CONTROL_LEVELS 1
462 #define MAIN_CONTROL_SCORES 2
463 #define MAIN_CONTROL_EDITOR 3
464 #define MAIN_CONTROL_INFO 4
465 #define MAIN_CONTROL_GAME 5
466 #define MAIN_CONTROL_SETUP 6
467 #define MAIN_CONTROL_QUIT 7
468 #define MAIN_CONTROL_PREV_LEVEL 8
469 #define MAIN_CONTROL_NEXT_LEVEL 9
470 #define MAIN_CONTROL_FIRST_LEVEL 10
471 #define MAIN_CONTROL_LAST_LEVEL 11
472 #define MAIN_CONTROL_LEVEL_NUMBER 12
473 #define MAIN_CONTROL_LEVEL_INFO_1 13
474 #define MAIN_CONTROL_LEVEL_INFO_2 14
475 #define MAIN_CONTROL_LEVEL_NAME 15
476 #define MAIN_CONTROL_LEVEL_AUTHOR 16
477 #define MAIN_CONTROL_LEVEL_YEAR 17
478 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
479 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
480 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
481 #define MAIN_CONTROL_TITLE_1 21
482 #define MAIN_CONTROL_TITLE_2 22
483 #define MAIN_CONTROL_TITLE_3 23
485 static char str_main_text_name[10];
486 static char str_main_text_first_level[10];
487 static char str_main_text_last_level[10];
488 static char str_main_text_level_number[10];
490 static char *main_text_name = str_main_text_name;
491 static char *main_text_first_level = str_main_text_first_level;
492 static char *main_text_last_level = str_main_text_last_level;
493 static char *main_text_level_number = str_main_text_level_number;
494 static char *main_text_levels = "Levelset";
495 static char *main_text_scores = "Hall Of Fame";
496 static char *main_text_editor = "Level Creator";
497 static char *main_text_info = "Info Screen";
498 static char *main_text_game = "Start Game";
499 static char *main_text_setup = "Setup";
500 static char *main_text_quit = "Quit";
501 static char *main_text_level_name = level.name;
502 static char *main_text_level_author = level.author;
503 static char *main_text_level_year = NULL;
504 static char *main_text_level_imported_from = NULL;
505 static char *main_text_level_imported_by = NULL;
506 static char *main_text_level_tested_by = NULL;
507 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
508 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
509 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
511 struct MainControlInfo
515 struct MenuPosInfo *pos_button;
518 struct TextPosInfo *pos_text;
521 struct TextPosInfo *pos_input;
525 static struct MainControlInfo main_controls[] =
529 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
530 &menu.main.text.name, &main_text_name,
531 &menu.main.input.name, &setup.player_name,
535 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
536 &menu.main.text.levels, &main_text_levels,
541 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
542 &menu.main.text.scores, &main_text_scores,
547 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
548 &menu.main.text.editor, &main_text_editor,
553 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
554 &menu.main.text.info, &main_text_info,
559 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
560 &menu.main.text.game, &main_text_game,
565 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
566 &menu.main.text.setup, &main_text_setup,
571 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
572 &menu.main.text.quit, &main_text_quit,
576 /* (these two buttons are real gadgets) */
578 MAIN_CONTROL_PREV_LEVEL,
579 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
584 MAIN_CONTROL_NEXT_LEVEL,
585 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
591 MAIN_CONTROL_FIRST_LEVEL,
593 &menu.main.text.first_level, &main_text_first_level,
597 MAIN_CONTROL_LAST_LEVEL,
599 &menu.main.text.last_level, &main_text_last_level,
603 MAIN_CONTROL_LEVEL_NUMBER,
605 &menu.main.text.level_number, &main_text_level_number,
609 MAIN_CONTROL_LEVEL_INFO_1,
611 &menu.main.text.level_info_1, NULL,
615 MAIN_CONTROL_LEVEL_INFO_2,
617 &menu.main.text.level_info_2, NULL,
621 MAIN_CONTROL_LEVEL_NAME,
623 &menu.main.text.level_name, &main_text_level_name,
627 MAIN_CONTROL_LEVEL_AUTHOR,
629 &menu.main.text.level_author, &main_text_level_author,
633 MAIN_CONTROL_LEVEL_YEAR,
635 &menu.main.text.level_year, &main_text_level_year,
639 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
641 &menu.main.text.level_imported_from, &main_text_level_imported_from,
645 MAIN_CONTROL_LEVEL_IMPORTED_BY,
647 &menu.main.text.level_imported_by, &main_text_level_imported_by,
651 MAIN_CONTROL_LEVEL_TESTED_BY,
653 &menu.main.text.level_tested_by, &main_text_level_tested_by,
657 MAIN_CONTROL_TITLE_1,
659 &menu.main.text.title_1, &main_text_title_1,
663 MAIN_CONTROL_TITLE_2,
665 &menu.main.text.title_2, &main_text_title_2,
669 MAIN_CONTROL_TITLE_3,
671 &menu.main.text.title_3, &main_text_title_3,
684 static int getTitleScreenGraphic(int nr, boolean initial)
686 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
689 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
691 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
695 static int getTitleScreenGameMode(boolean initial)
697 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
701 static int getTitleMessageGameMode(boolean initial)
703 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
707 static int getTitleScreenBackground(boolean initial)
709 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
714 static int getTitleMessageBackground(int nr, boolean initial)
716 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
720 static int getTitleBackground(int nr, boolean initial, boolean is_image)
722 int base = (is_image ?
723 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
724 IMG_BACKGROUND_TITLESCREEN_1) :
725 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
726 IMG_BACKGROUND_TITLEMESSAGE_1));
727 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
728 IMG_BACKGROUND_TITLE);
729 int graphic_local = base + nr;
731 if (graphic_info[graphic_local].bitmap != NULL)
732 return graphic_local;
734 if (graphic_info[graphic_global].bitmap != NULL)
735 return graphic_global;
737 return IMG_UNDEFINED;
740 static int getTitleSound(struct TitleControlInfo *tci)
742 boolean is_image = tci->is_image;
743 int initial = tci->initial;
744 int nr = tci->local_nr;
745 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
746 int base = (is_image ?
747 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
748 SND_BACKGROUND_TITLESCREEN_1) :
749 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
750 SND_BACKGROUND_TITLEMESSAGE_1));
751 int sound_global = menu.sound[mode];
752 int sound_local = base + nr;
755 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
756 nr, initial, is_image,
757 sound_global, getSoundListEntry(sound_global)->filename,
758 sound_local, getSoundListEntry(sound_local)->filename);
761 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
764 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
767 return SND_UNDEFINED;
770 static int getTitleMusic(struct TitleControlInfo *tci)
772 boolean is_image = tci->is_image;
773 int initial = tci->initial;
774 int nr = tci->local_nr;
775 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
776 int base = (is_image ?
777 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
778 MUS_BACKGROUND_TITLESCREEN_1) :
779 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
780 MUS_BACKGROUND_TITLEMESSAGE_1));
781 int music_global = menu.music[mode];
782 int music_local = base + nr;
785 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
786 nr, initial, is_image,
787 music_global, getMusicListEntry(music_global)->filename,
788 music_local, getMusicListEntry(music_local)->filename);
791 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
794 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
797 return MUS_UNDEFINED;
800 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
802 boolean is_image = tci->is_image;
803 int initial = tci->initial;
804 int nr = tci->local_nr;
805 struct TitleFadingInfo ti;
809 int graphic = getTitleScreenGraphic(nr, initial);
811 /* initialize fading control values to default title config settings */
812 ti = (initial ? title_initial_default : title_default);
814 /* override default settings with image config settings, if defined */
815 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
816 ti.fade_mode = graphic_info[graphic].fade_mode;
817 if (graphic_info[graphic].fade_delay > -1)
818 ti.fade_delay = graphic_info[graphic].fade_delay;
819 if (graphic_info[graphic].post_delay > -1)
820 ti.post_delay = graphic_info[graphic].post_delay;
821 if (graphic_info[graphic].auto_delay > -1)
822 ti.auto_delay = graphic_info[graphic].auto_delay;
828 ti.fade_mode = titlemessage_initial[nr].fade_mode;
829 ti.fade_delay = titlemessage_initial[nr].fade_delay;
830 ti.post_delay = titlemessage_initial[nr].post_delay;
831 ti.auto_delay = titlemessage_initial[nr].auto_delay;
835 ti.fade_mode = titlemessage[nr].fade_mode;
836 ti.fade_delay = titlemessage[nr].fade_delay;
837 ti.post_delay = titlemessage[nr].post_delay;
838 ti.auto_delay = titlemessage[nr].auto_delay;
845 static int compareTitleControlInfo(const void *object1, const void *object2)
847 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
848 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
851 if (tci1->initial != tci2->initial)
852 compare_result = (tci1->initial ? -1 : +1);
853 else if (tci1->sort_priority != tci2->sort_priority)
854 compare_result = tci1->sort_priority - tci2->sort_priority;
855 else if (tci1->is_image != tci2->is_image)
856 compare_result = (tci1->is_image ? -1 : +1);
858 compare_result = tci1->local_nr - tci2->local_nr;
860 return compare_result;
863 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
865 int nr, int sort_priority)
867 title_controls[num_title_screens].is_image = is_image;
868 title_controls[num_title_screens].initial = initial;
869 title_controls[num_title_screens].local_nr = nr;
870 title_controls[num_title_screens].sort_priority = sort_priority;
875 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
879 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
881 int graphic = getTitleScreenGraphic(i, initial);
882 Bitmap *bitmap = graphic_info[graphic].bitmap;
883 int sort_priority = graphic_info[graphic].sort_priority;
886 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
889 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
891 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
892 char *filename = getLevelSetTitleMessageFilename(i, initial);
893 int sort_priority = tmi->sort_priority;
895 if (filename != NULL)
896 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
900 static void InitializeTitleControls(boolean show_title_initial)
902 num_title_screens = 0;
904 /* 1st step: initialize title screens for game start (only when starting) */
905 if (show_title_initial)
906 InitializeTitleControls_CheckTitleInfo(TRUE);
908 /* 2nd step: initialize title screens for current level set */
909 InitializeTitleControls_CheckTitleInfo(FALSE);
911 /* sort title screens according to sort_priority and title number */
912 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
913 compareTitleControlInfo);
916 static boolean visibleMenuPos(struct MenuPosInfo *pos)
918 return (pos != NULL && pos->x != -1 && pos->y != -1);
921 static boolean visibleTextPos(struct TextPosInfo *pos)
923 return (pos != NULL && pos->x != -1 && pos->y != -1);
926 static void InitializeMainControls()
928 boolean local_team_mode = (!options.network && setup.team_mode);
931 /* set main control text values to dynamically determined values */
932 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
934 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
935 menu.main.text.first_level.size));
936 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
937 menu.main.text.last_level.size));
938 strcpy(main_text_level_number, int2str(level_nr,
939 menu.main.text.level_number.size));
941 main_text_level_year = leveldir_current->year;
942 main_text_level_imported_from = leveldir_current->imported_from;
943 main_text_level_imported_by = leveldir_current->imported_by;
944 main_text_level_tested_by = leveldir_current->tested_by;
946 /* set main control screen positions to dynamically determined values */
947 for (i = 0; main_controls[i].nr != -1; i++)
949 struct MainControlInfo *mci = &main_controls[i];
951 struct MenuPosInfo *pos_button = mci->pos_button;
952 struct TextPosInfo *pos_text = mci->pos_text;
953 struct TextPosInfo *pos_input = mci->pos_input;
954 char *text = (mci->text ? *mci->text : NULL);
955 char *input = (mci->input ? *mci->input : NULL);
956 int button_graphic = mci->button_graphic;
957 int font_text = (pos_text ? pos_text->font : -1);
958 int font_input = (pos_input ? pos_input->font : -1);
960 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
961 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
962 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
963 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
964 int text_chars = (text != NULL ? strlen(text) : 0);
965 int input_chars = (input != NULL ? strlen(input) : 0);
968 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
970 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
971 int text_width = font_text_width * text_chars;
972 int text_height = font_text_height;
973 int input_width = font_input_width * input_chars;
974 int input_height = font_input_height;
976 if (nr == MAIN_CONTROL_NAME)
978 menu.main.input.name.width = input_width;
979 menu.main.input.name.height = input_height;
982 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
984 pos_button->width = button_width;
985 pos_button->height = button_height;
988 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
990 /* calculate size for non-clickable text -- needed for text alignment */
991 boolean calculate_text_size = (pos_button == NULL && text != NULL);
993 if (pos_text->width == -1 || calculate_text_size)
994 pos_text->width = text_width;
995 if (pos_text->height == -1 || calculate_text_size)
996 pos_text->height = text_height;
998 if (visibleMenuPos(pos_button))
1000 if (pos_text->x == -1)
1001 pos_text->x = pos_button->x + pos_button->width;
1002 if (pos_text->y == -1)
1004 pos_button->y + (pos_button->height - pos_text->height) / 2;
1008 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1010 if (visibleTextPos(pos_text))
1012 if (pos_input->x == -1)
1013 pos_input->x = pos_text->x + pos_text->width;
1014 if (pos_input->y == -1)
1015 pos_input->y = pos_text->y;
1018 if (pos_input->width == -1)
1019 pos_input->width = input_width;
1020 if (pos_input->height == -1)
1021 pos_input->height = input_height;
1026 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1027 int graphic, boolean pressed)
1029 struct GraphicInfo *g = &graphic_info[graphic];
1032 int xoffset = (pressed ? g->pressed_xoffset : 0);
1033 int yoffset = (pressed ? g->pressed_yoffset : 0);
1035 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1037 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1038 g->width, g->height, dst_x, dst_y);
1041 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1042 boolean active_input,
1043 boolean pressed_button)
1047 for (i = 0; main_controls[i].nr != -1; i++)
1049 struct MainControlInfo *mci = &main_controls[i];
1051 if (mci->nr == nr || nr == -1)
1053 struct MenuPosInfo *pos_button = mci->pos_button;
1054 struct TextPosInfo *pos_text = mci->pos_text;
1055 struct TextPosInfo *pos_input = mci->pos_input;
1056 char *text = (mci->text ? *mci->text : NULL);
1057 char *input = (mci->input ? *mci->input : NULL);
1058 int button_graphic = mci->button_graphic;
1059 int font_text = (pos_text ? pos_text->font : -1);
1060 int font_input = (pos_input ? pos_input->font : -1);
1064 button_graphic = BUTTON_ACTIVE(button_graphic);
1065 font_text = FONT_ACTIVE(font_text);
1070 font_input = FONT_ACTIVE(font_input);
1073 if (visibleMenuPos(pos_button))
1075 struct MenuPosInfo *pos = pos_button;
1076 int x = mSX + pos->x;
1077 int y = mSY + pos->y;
1079 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1080 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1083 if (visibleTextPos(pos_text) && text != NULL)
1085 struct TextPosInfo *pos = pos_text;
1086 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1087 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1090 /* (check why/if this is needed) */
1091 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1093 DrawText(x, y, text, font_text);
1096 if (visibleTextPos(pos_input) && input != NULL)
1098 struct TextPosInfo *pos = pos_input;
1099 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1100 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1103 /* (check why/if this is needed) */
1104 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1106 DrawText(x, y, input, font_input);
1112 static void DrawCursorAndText_Main(int nr, boolean active_text,
1113 boolean pressed_button)
1115 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1119 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1120 boolean pressed_button)
1122 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1126 static struct MainControlInfo *getMainControlInfo(int nr)
1130 for (i = 0; main_controls[i].nr != -1; i++)
1131 if (main_controls[i].nr == nr)
1132 return &main_controls[i];
1137 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1142 int rect_x = ALIGNED_TEXT_XPOS(rect);
1143 int rect_y = ALIGNED_TEXT_YPOS(rect);
1145 return (x >= rect_x && x < rect_x + rect->width &&
1146 y >= rect_y && y < rect_y + rect->height);
1149 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1154 int rect_x = ALIGNED_TEXT_XPOS(rect);
1155 int rect_y = ALIGNED_TEXT_YPOS(rect);
1158 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1159 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1160 (x >= rect_x && x < rect_x + rect->width &&
1161 y >= rect_y && y < rect_y + rect->height));
1164 return (x >= rect_x && x < rect_x + rect->width &&
1165 y >= rect_y && y < rect_y + rect->height);
1168 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1170 static int cursor_array[MAX_LEV_FIELDY];
1171 int x = mSX + TILEX * xpos;
1172 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1177 cursor_array[ypos] = graphic;
1179 graphic = cursor_array[ypos];
1183 graphic = BUTTON_ACTIVE(graphic);
1185 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1186 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1189 static void initCursor(int ypos, int graphic)
1191 drawCursorExt(0, ypos, FALSE, graphic);
1194 static void drawCursor(int ypos, boolean active)
1196 drawCursorExt(0, ypos, active, -1);
1199 static void drawCursorXY(int xpos, int ypos, int graphic)
1201 drawCursorExt(xpos, ypos, FALSE, graphic);
1204 static void drawChooseTreeCursor(int ypos, boolean active)
1206 int last_game_status = game_status; /* save current game status */
1208 drawCursorExt(0, ypos, active, -1);
1210 game_status = last_game_status; /* restore current game status */
1215 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1216 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1219 int effectiveGameStatus()
1221 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1222 return GAME_MODE_TITLE;
1227 void DrawTitleScreenImage(int nr, boolean initial)
1229 int graphic = getTitleScreenGraphic(nr, initial);
1230 Bitmap *bitmap = graphic_info[graphic].bitmap;
1231 int width = graphic_info[graphic].width;
1232 int height = graphic_info[graphic].height;
1233 int src_x = graphic_info[graphic].src_x;
1234 int src_y = graphic_info[graphic].src_y;
1240 if (width > WIN_XSIZE)
1242 /* image width too large for window => center image horizontally */
1243 src_x = (width - WIN_XSIZE) / 2;
1247 if (height > WIN_YSIZE)
1249 /* image height too large for window => center image vertically */
1250 src_y = (height - WIN_YSIZE) / 2;
1254 /* always display title screens centered */
1255 dst_x = (WIN_XSIZE - width) / 2;
1256 dst_y = (WIN_YSIZE - height) / 2;
1258 SetDrawBackgroundMask(REDRAW_ALL);
1259 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1261 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1263 if (DrawingOnBackground(dst_x, dst_y))
1264 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1266 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1268 redraw_mask = REDRAW_ALL;
1271 void DrawTitleScreenMessage(int nr, boolean initial)
1273 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1274 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1275 int last_game_status = game_status; /* save current game status */
1277 if (filename == NULL)
1280 /* force TITLE font on title message screen */
1281 game_status = getTitleMessageGameMode(initial);
1283 /* if chars set to "-1", automatically determine by text and font width */
1284 if (tmi->chars == -1)
1285 tmi->chars = tmi->width / getFontWidth(tmi->font);
1287 tmi->width = tmi->chars * getFontWidth(tmi->font);
1289 /* if lines set to "-1", automatically determine by text and font height */
1290 if (tmi->lines == -1)
1291 tmi->lines = tmi->height / getFontHeight(tmi->font);
1293 tmi->height = tmi->lines * getFontHeight(tmi->font);
1295 SetDrawBackgroundMask(REDRAW_ALL);
1296 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1298 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1300 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1301 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1302 tmi->autowrap, tmi->centered, tmi->parse_comments);
1304 game_status = last_game_status; /* restore current game status */
1307 void DrawTitleScreen()
1309 KeyboardAutoRepeatOff();
1311 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1316 boolean CheckTitleScreen(boolean levelset_has_changed)
1318 static boolean show_title_initial = TRUE;
1319 boolean show_titlescreen = FALSE;
1321 /* needed to be able to skip title screen, if no image or message defined */
1322 InitializeTitleControls(show_title_initial);
1324 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1325 show_titlescreen = TRUE;
1327 /* show initial title images and messages only once at program start */
1328 show_title_initial = FALSE;
1330 return (show_titlescreen && num_title_screens > 0);
1333 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1335 static LevelDirTree *leveldir_last_valid = NULL;
1336 boolean levelset_has_changed = FALSE;
1338 LimitScreenUpdates(FALSE);
1340 FadeSetLeaveScreen();
1342 /* do not fade out here -- function may continue and fade on editor screen */
1345 FadeSoundsAndMusic();
1347 KeyboardAutoRepeatOn();
1350 audio.sound_deactivated = FALSE;
1354 /* needed if last screen was the playing screen, invoked from level editor */
1355 if (level_editor_test_game)
1357 game_status = GAME_MODE_EDITOR;
1363 /* needed if last screen was the setup screen and fullscreen state changed */
1364 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1365 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1367 /* leveldir_current may be invalid (level group, parent link) */
1368 if (!validLevelSeries(leveldir_current))
1369 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1371 if (leveldir_current != leveldir_last_valid)
1372 levelset_has_changed = TRUE;
1374 /* store valid level series information */
1375 leveldir_last_valid = leveldir_current;
1377 init_last = init; /* switch to new busy animation */
1379 /* needed if last screen (level choice) changed graphics, sounds or music */
1380 ReloadCustomArtwork(0);
1382 if (redraw_mask & REDRAW_ALL)
1383 fade_mask = REDRAW_ALL;
1387 /* needed if different viewport properties defined for menues */
1388 ChangeViewportPropertiesIfNeeded();
1390 /* needed if last screen was the editor screen */
1391 UndrawSpecialEditorDoor();
1393 SetDrawtoField(DRAW_BACKBUFFER);
1395 if (CheckTitleScreen(levelset_has_changed))
1397 game_status = GAME_MODE_TITLE;
1404 /* level_nr may have been set to value over handicap with level editor */
1405 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1406 level_nr = leveldir_current->handicap_level;
1408 LoadLevel(level_nr);
1409 LoadScore(level_nr);
1411 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1412 SetDrawDeactivationMask(REDRAW_NONE);
1413 SetDrawBackgroundMask(REDRAW_FIELD);
1415 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1417 if (fade_mask == REDRAW_ALL)
1418 RedrawGlobalBorder();
1422 InitializeMainControls();
1424 DrawCursorAndText_Main(-1, FALSE, FALSE);
1425 DrawPreviewLevelInitial();
1427 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1430 if (TAPE_IS_EMPTY(tape))
1432 DrawCompleteVideoDisplay();
1437 /* create gadgets for main menu screen */
1438 FreeScreenGadgets();
1439 CreateScreenGadgets();
1441 /* map gadgets for main menu screen */
1443 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1445 /* copy actual game door content to door double buffer for OpenDoor() */
1446 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1448 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1450 DrawMaskedBorder(REDRAW_ALL);
1455 /* update screen area with special editor door */
1456 redraw_mask |= REDRAW_ALL;
1459 SetMouseCursor(CURSOR_DEFAULT);
1463 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1466 void DrawAndFadeInMainMenu(int fade_mask)
1468 DrawMainMenuExt(fade_mask, TRUE);
1473 DrawMainMenuExt(REDRAW_ALL, FALSE);
1476 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1477 static void gotoTopLevelDir()
1479 /* move upwards to top level directory */
1480 while (leveldir_current->node_parent)
1482 /* write a "path" into level tree for easy navigation to last level */
1483 if (leveldir_current->node_parent->node_group->cl_first == -1)
1485 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1486 int leveldir_pos = posTreeInfo(leveldir_current);
1487 int num_page_entries;
1488 int cl_first, cl_cursor;
1490 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1491 num_page_entries = num_leveldirs;
1493 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1495 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1496 cl_cursor = leveldir_pos - cl_first;
1498 leveldir_current->node_parent->node_group->cl_first = cl_first;
1499 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1502 leveldir_current = leveldir_current->node_parent;
1507 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1509 static unsigned int title_delay = 0;
1510 static int title_screen_nr = 0;
1511 static int last_sound = -1, last_music = -1;
1512 boolean return_to_main_menu = FALSE;
1513 boolean use_fading_main_menu = TRUE;
1514 struct TitleControlInfo *tci;
1515 struct TitleFadingInfo fading_default;
1516 struct TitleFadingInfo fading_last = fading;
1517 struct TitleFadingInfo fading_next;
1520 if (button == MB_MENU_INITIALIZE)
1523 title_screen_nr = 0;
1524 tci = &title_controls[title_screen_nr];
1526 last_sound = SND_UNDEFINED;
1527 last_music = MUS_UNDEFINED;
1529 if (game_status == GAME_MODE_INFO)
1531 if (num_title_screens == 0)
1533 DrawInfoScreen_NotAvailable("Title screen information:",
1534 "No title screen for this level set.");
1539 FadeSoundsAndMusic();
1541 FadeOut(REDRAW_ALL);
1545 DrawTitleScreenImage(tci->local_nr, tci->initial);
1547 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1549 fading_default = (tci->initial ? title_initial_default : title_default);
1551 fading = fading_next = getTitleFading(tci);
1553 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1554 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1556 fading.fade_mode = FADE_MODE_FADE;
1557 fading.fade_delay = fading_default.fade_delay;
1560 sound = getTitleSound(tci);
1561 music = getTitleMusic(tci);
1563 if (sound != last_sound)
1564 PlayMenuSoundExt(sound);
1565 if (music != last_music)
1566 PlayMenuMusicExt(music);
1571 SetMouseCursor(CURSOR_NONE);
1575 fading = fading_next;
1577 DelayReached(&title_delay, 0); /* reset delay counter */
1582 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1583 button = MB_MENU_CHOICE;
1585 if (button == MB_MENU_LEAVE)
1587 return_to_main_menu = TRUE;
1588 use_fading_main_menu = FALSE;
1590 else if (button == MB_MENU_CHOICE)
1592 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1594 FadeSetEnterScreen();
1596 info_mode = INFO_MODE_MAIN;
1597 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1603 tci = &title_controls[title_screen_nr];
1605 if (title_screen_nr < num_title_screens)
1607 sound = getTitleSound(tci);
1608 music = getTitleMusic(tci);
1610 if (sound == SND_UNDEFINED || sound != last_sound)
1612 if (music == MUS_UNDEFINED || music != last_music)
1615 FadeOut(REDRAW_ALL);
1618 DrawTitleScreenImage(tci->local_nr, tci->initial);
1620 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1622 fading_next = getTitleFading(tci);
1624 sound = getTitleSound(tci);
1625 music = getTitleMusic(tci);
1627 if (sound != last_sound)
1628 PlayMenuSoundExt(sound);
1629 if (music != last_music)
1630 PlayMenuMusicExt(music);
1635 /* last screen already faded out, next screen has no animation */
1636 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1637 fading_next.fade_mode == FADE_MODE_NONE)
1638 fading = fading_next;
1642 fading = fading_next;
1644 DelayReached(&title_delay, 0); /* reset delay counter */
1648 FadeSoundsAndMusic();
1650 return_to_main_menu = TRUE;
1654 if (return_to_main_menu)
1656 SetMouseCursor(CURSOR_DEFAULT);
1658 if (game_status == GAME_MODE_INFO)
1660 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1662 info_mode = INFO_MODE_MAIN;
1664 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1666 else /* default: return to main menu */
1668 game_status = GAME_MODE_MAIN;
1670 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1675 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1677 int old_level_nr = level_nr;
1680 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1681 new_level_nr = selected_level_nr;
1683 new_level_nr = old_level_nr + step * direction;
1685 if (new_level_nr < leveldir_current->first_level)
1686 new_level_nr = leveldir_current->first_level;
1687 if (new_level_nr > leveldir_current->last_level)
1688 new_level_nr = leveldir_current->last_level;
1690 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1692 /* skipping levels is only allowed when trying to skip single level */
1693 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1694 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1696 leveldir_current->handicap_level++;
1697 SaveLevelSetup_SeriesInfo();
1700 new_level_nr = leveldir_current->handicap_level;
1703 if (new_level_nr != old_level_nr)
1705 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1707 PlaySound(SND_MENU_ITEM_SELECTING);
1709 level_nr = new_level_nr;
1711 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1712 int2str(level_nr, menu.main.text.level_number.size),
1713 mci->pos_text->font);
1715 LoadLevel(level_nr);
1716 DrawPreviewLevelInitial();
1720 DrawCompleteVideoDisplay();
1722 /* needed because DrawPreviewLevelInitial() takes some time */
1724 /* SyncDisplay(); */
1728 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1730 static int choice = MAIN_CONTROL_GAME;
1731 static boolean button_pressed_last = FALSE;
1732 boolean button_pressed = FALSE;
1736 if (button == MB_MENU_INITIALIZE)
1738 DrawCursorAndText_Main(choice, TRUE, FALSE);
1743 if (mx || my) /* mouse input */
1747 for (i = 0; main_controls[i].nr != -1; i++)
1749 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1750 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1751 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1753 pos = main_controls[i].nr;
1759 // handle pressed/unpressed state for active/inactive menu buttons
1760 // (if pos != -1, "i" contains index position corresponding to "pos")
1762 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1763 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1764 button_pressed = TRUE;
1766 if (button_pressed != button_pressed_last)
1768 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1771 PlaySound(SND_MENU_BUTTON_PRESSING);
1773 PlaySound(SND_MENU_BUTTON_RELEASING);
1776 else if (dx || dy) /* keyboard input */
1778 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1779 choice == MAIN_CONTROL_SETUP))
1780 button = MB_MENU_CHOICE;
1785 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1787 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1789 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1791 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1793 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1795 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1797 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1799 game_status = GAME_MODE_LEVELNR;
1801 ChangeViewportPropertiesIfNeeded();
1803 DrawChooseLevelNr();
1805 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1811 PlaySound(SND_MENU_ITEM_ACTIVATING);
1813 DrawCursorAndText_Main(choice, FALSE, FALSE);
1814 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1821 PlaySound(SND_MENU_ITEM_SELECTING);
1823 if (pos == MAIN_CONTROL_NAME)
1825 game_status = GAME_MODE_PSEUDO_TYPENAME;
1827 HandleTypeName(strlen(setup.player_name), 0);
1829 else if (pos == MAIN_CONTROL_LEVELS)
1833 game_status = GAME_MODE_LEVELS;
1835 SaveLevelSetup_LastSeries();
1836 SaveLevelSetup_SeriesInfo();
1838 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1842 ChangeViewportPropertiesIfNeeded();
1844 DrawChooseLevelSet();
1847 else if (pos == MAIN_CONTROL_SCORES)
1849 game_status = GAME_MODE_SCORES;
1851 ChangeViewportPropertiesIfNeeded();
1855 else if (pos == MAIN_CONTROL_EDITOR)
1857 if (leveldir_current->readonly &&
1858 !strEqual(setup.player_name, "Artsoft"))
1859 Request("This level is read only!", REQ_CONFIRM);
1861 CloseDoor(DOOR_CLOSE_2);
1863 game_status = GAME_MODE_EDITOR;
1865 FadeSetEnterScreen();
1869 else if (pos == MAIN_CONTROL_INFO)
1871 game_status = GAME_MODE_INFO;
1872 info_mode = INFO_MODE_MAIN;
1874 ChangeViewportPropertiesIfNeeded();
1878 else if (pos == MAIN_CONTROL_GAME)
1880 StartGameActions(options.network, setup.autorecord, level.random_seed);
1882 else if (pos == MAIN_CONTROL_SETUP)
1884 game_status = GAME_MODE_SETUP;
1885 setup_mode = SETUP_MODE_MAIN;
1887 ChangeViewportPropertiesIfNeeded();
1891 else if (pos == MAIN_CONTROL_QUIT)
1893 SaveLevelSetup_LastSeries();
1894 SaveLevelSetup_SeriesInfo();
1896 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1897 game_status = GAME_MODE_QUIT;
1902 button_pressed_last = button_pressed;
1906 /* ========================================================================= */
1907 /* info screen functions */
1908 /* ========================================================================= */
1910 static struct TokenInfo *info_info;
1911 static int num_info_info;
1913 static void execInfoTitleScreen()
1915 info_mode = INFO_MODE_TITLE;
1920 static void execInfoElements()
1922 info_mode = INFO_MODE_ELEMENTS;
1927 static void execInfoMusic()
1929 info_mode = INFO_MODE_MUSIC;
1934 static void execInfoCredits()
1936 info_mode = INFO_MODE_CREDITS;
1941 static void execInfoProgram()
1943 info_mode = INFO_MODE_PROGRAM;
1948 static void execInfoVersion()
1950 info_mode = INFO_MODE_VERSION;
1955 static void execInfoLevelSet()
1957 info_mode = INFO_MODE_LEVELSET;
1962 static void execExitInfo()
1964 game_status = GAME_MODE_MAIN;
1966 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1969 static struct TokenInfo info_info_main[] =
1971 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1972 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1973 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1974 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1975 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1976 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1977 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1978 { TYPE_EMPTY, NULL, "" },
1979 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1984 static void DrawCursorAndText_Info(int pos, boolean active)
1986 int xpos = MENU_SCREEN_START_XPOS;
1987 int ypos = MENU_SCREEN_START_YPOS + pos;
1988 int font_nr = FONT_MENU_1;
1991 font_nr = FONT_ACTIVE(font_nr);
1993 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1995 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1996 drawCursor(pos, active);
1999 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2004 CloseDoor(DOOR_CLOSE_2);
2006 /* (needed after displaying title screens which disable auto repeat) */
2007 KeyboardAutoRepeatOn();
2009 FadeSetLeaveScreen();
2013 if (fade_mask == REDRAW_ALL)
2015 RedrawGlobalBorder();
2017 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2022 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2024 info_info = info_info_main;
2027 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2029 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2030 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2031 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2032 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2033 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2034 initCursor(i, IMG_MENU_BUTTON);
2036 DrawCursorAndText_Info(i, FALSE);
2041 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2046 DrawMaskedBorder(fade_mask);
2053 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2055 static int choice_store[MAX_INFO_MODES];
2056 int choice = choice_store[info_mode]; /* always starts with 0 */
2060 if (button == MB_MENU_INITIALIZE)
2062 /* advance to first valid menu entry */
2063 while (choice < num_info_info &&
2064 info_info[choice].type & TYPE_SKIP_ENTRY)
2066 choice_store[info_mode] = choice;
2068 DrawCursorAndText_Info(choice, TRUE);
2072 else if (button == MB_MENU_LEAVE)
2074 for (y = 0; y < num_info_info; y++)
2076 if (info_info[y].type & TYPE_LEAVE_MENU)
2078 void (*menu_callback_function)(void) = info_info[y].value;
2082 menu_callback_function();
2084 break; /* absolutely needed because function changes 'info_info'! */
2091 if (mx || my) /* mouse input */
2093 x = (mx - mSX) / 32;
2094 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2096 else if (dx || dy) /* keyboard input */
2100 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2102 if (info_info[choice].type & menu_navigation_type ||
2103 info_info[choice].type & TYPE_ENTER_SCREEN ||
2104 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2105 info_info[choice].type & TYPE_YES_NO_AUTO)
2106 button = MB_MENU_CHOICE;
2111 /* jump to next non-empty menu entry (up or down) */
2112 while (y > 0 && y < num_info_info - 1 &&
2113 info_info[y].type & TYPE_SKIP_ENTRY)
2117 if (IN_VIS_MENU(x, y) &&
2118 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2124 PlaySound(SND_MENU_ITEM_ACTIVATING);
2126 DrawCursorAndText_Info(choice, FALSE);
2127 DrawCursorAndText_Info(y, TRUE);
2129 choice = choice_store[info_mode] = y;
2132 else if (!(info_info[y].type & TYPE_GHOSTED))
2134 PlaySound(SND_MENU_ITEM_SELECTING);
2136 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2138 void (*menu_callback_function)(void) = info_info[choice].value;
2140 FadeSetFromType(info_info[y].type);
2142 menu_callback_function();
2148 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2150 int ystart1 = mSY - SY + 100;
2151 int ystart2 = mSY - SY + 150;
2152 int ybottom = mSY - SY + SYSIZE - 20;
2154 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2156 FadeOut(REDRAW_FIELD);
2161 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2162 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2164 DrawTextSCentered(ybottom, FONT_TEXT_4,
2165 "Press any key or button for info menu");
2167 FadeIn(REDRAW_FIELD);
2170 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2172 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2173 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2174 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2175 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2176 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2177 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2178 int ystep = MENU_SCREEN_INFO_YSTEP;
2179 int element, action, direction;
2187 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2188 infoscreen_step[i] = infoscreen_frame[i] = 0;
2193 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2195 DrawTextSCentered(ybottom, FONT_TEXT_4,
2196 "Press any key or button for next page");
2202 while (helpanim_info[j].element != HELPANIM_LIST_END)
2204 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2209 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2218 j += infoscreen_step[i - start];
2220 element = helpanim_info[j].element;
2221 action = helpanim_info[j].action;
2222 direction = helpanim_info[j].direction;
2225 element = EL_UNKNOWN;
2227 if (action != -1 && direction != -1)
2228 graphic = el_act_dir2img(element, action, direction);
2229 else if (action != -1)
2230 graphic = el_act2img(element, action);
2231 else if (direction != -1)
2232 graphic = el_dir2img(element, direction);
2234 graphic = el2img(element);
2236 delay = helpanim_info[j++].delay;
2241 if (infoscreen_frame[i - start] == 0)
2244 infoscreen_frame[i - start] = delay - 1;
2248 sync_frame = delay - infoscreen_frame[i - start];
2249 infoscreen_frame[i - start]--;
2252 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2254 if (!infoscreen_frame[i - start])
2255 infoscreen_step[i - start] = 0;
2259 if (!infoscreen_frame[i - start])
2260 infoscreen_step[i - start]++;
2261 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2267 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2269 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2270 graphic, sync_frame, USE_MASKING);
2273 DrawInfoScreen_HelpText(element, action, direction, i - start);
2278 redraw_mask |= REDRAW_FIELD;
2283 static char *getHelpText(int element, int action, int direction)
2285 char token[MAX_LINE_LEN];
2287 strcpy(token, element_info[element].token_name);
2290 strcat(token, element_action_info[action].suffix);
2292 if (direction != -1)
2293 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2295 return getHashEntry(helptext_info, token);
2298 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2300 int font_nr = FONT_INFO_ELEMENTS;
2301 int font_width = getFontWidth(font_nr);
2302 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2303 int sy = mSY + 65 + 2 * 32 + 1;
2304 int ystep = TILEY + 4;
2305 int pad_x = sx - SX;
2306 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2307 int max_lines_per_text = 2;
2310 if (action != -1 && direction != -1) /* element.action.direction */
2311 text = getHelpText(element, action, direction);
2313 if (text == NULL && action != -1) /* element.action */
2314 text = getHelpText(element, action, -1);
2316 if (text == NULL && direction != -1) /* element.direction */
2317 text = getHelpText(element, -1, direction);
2319 if (text == NULL) /* base element */
2320 text = getHelpText(element, -1, -1);
2322 if (text == NULL) /* not found */
2323 text = "No description available";
2325 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2326 sy += getFontHeight(font_nr) / 2;
2328 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2329 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2330 TRUE, FALSE, FALSE);
2333 void DrawInfoScreen_TitleScreen()
2338 void HandleInfoScreen_TitleScreen(int button)
2340 HandleTitleScreen(0, 0, 0, 0, button);
2343 void DrawInfoScreen_Elements()
2345 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2347 FadeOut(REDRAW_FIELD);
2352 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2354 FadeIn(REDRAW_FIELD);
2359 void HandleInfoScreen_Elements(int button)
2361 static unsigned int info_delay = 0;
2362 static int num_anims;
2363 static int num_pages;
2365 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2368 if (button == MB_MENU_INITIALIZE)
2370 boolean new_element = TRUE;
2374 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2376 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2378 else if (new_element)
2381 new_element = FALSE;
2385 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2389 if (button == MB_MENU_LEAVE)
2391 PlaySound(SND_MENU_ITEM_SELECTING);
2393 info_mode = INFO_MODE_MAIN;
2398 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2400 if (button != MB_MENU_INITIALIZE)
2402 PlaySound(SND_MENU_ITEM_SELECTING);
2407 if (page >= num_pages)
2409 FadeSoundsAndMusic();
2411 info_mode = INFO_MODE_MAIN;
2412 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2418 FadeSetNextScreen();
2420 if (button != MB_MENU_INITIALIZE)
2421 FadeOut(REDRAW_FIELD);
2423 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2425 if (button != MB_MENU_INITIALIZE)
2426 FadeIn(REDRAW_FIELD);
2430 if (DelayReached(&info_delay, GameFrameDelay))
2431 if (page < num_pages)
2432 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2434 PlayMenuSoundIfLoop();
2438 void DrawInfoScreen_Music()
2440 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2442 FadeOut(REDRAW_FIELD);
2449 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2451 FadeIn(REDRAW_FIELD);
2454 void HandleInfoScreen_Music(int button)
2456 static struct MusicFileInfo *list = NULL;
2457 int ystart1 = mSY - SY + 100;
2458 int ystart2 = mSY - SY + 150;
2459 int ybottom = mSY - SY + SYSIZE - 20;
2462 if (button == MB_MENU_INITIALIZE)
2464 list = music_file_info;
2468 FadeSoundsAndMusic();
2473 DrawTextSCentered(ystart1, FONT_TEXT_1,
2474 "No music info for this level set.");
2476 DrawTextSCentered(ybottom, FONT_TEXT_4,
2477 "Press any key or button for info menu");
2483 if (button == MB_MENU_LEAVE)
2485 PlaySound(SND_MENU_ITEM_SELECTING);
2487 FadeSoundsAndMusic();
2489 info_mode = INFO_MODE_MAIN;
2494 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2498 if (button != MB_MENU_INITIALIZE)
2500 PlaySound(SND_MENU_ITEM_SELECTING);
2508 FadeSoundsAndMusic();
2510 info_mode = INFO_MODE_MAIN;
2511 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2516 FadeSoundsAndMusic();
2518 if (list != music_file_info)
2519 FadeSetNextScreen();
2521 if (button != MB_MENU_INITIALIZE)
2522 FadeOut(REDRAW_FIELD);
2529 int sound = list->music;
2531 if (sound_info[sound].loop)
2532 PlaySoundLoop(sound);
2536 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2540 PlayMusic(list->music);
2542 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2545 if (!strEqual(list->title, UNKNOWN_NAME))
2547 if (!strEqual(list->title_header, UNKNOWN_NAME))
2548 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2550 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2553 if (!strEqual(list->artist, UNKNOWN_NAME))
2555 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2556 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2558 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2560 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2563 if (!strEqual(list->album, UNKNOWN_NAME))
2565 if (!strEqual(list->album_header, UNKNOWN_NAME))
2566 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2568 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2570 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2573 if (!strEqual(list->year, UNKNOWN_NAME))
2575 if (!strEqual(list->year_header, UNKNOWN_NAME))
2576 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2578 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2580 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2583 DrawTextSCentered(ybottom, FONT_TEXT_4,
2584 "Press any key or button for next page");
2586 if (button != MB_MENU_INITIALIZE)
2587 FadeIn(REDRAW_FIELD);
2590 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2591 PlaySoundLoop(list->music);
2594 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2596 int ystart1 = mSY - SY + 100;
2597 int ystart2 = mSY - SY + 150;
2598 int ybottom = mSY - SY + SYSIZE - 20;
2604 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2608 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2609 "Special thanks to");
2610 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2612 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2614 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2615 "\"Boulder Dash\"");
2616 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2618 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2620 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2622 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2623 "First Star Software");
2625 else if (screen_nr == 1)
2627 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2628 "Special thanks to");
2629 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2630 "Klaus Heinz & Volker Wertich");
2631 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2633 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2634 "\"Emerald Mine\"");
2635 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2637 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2639 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2641 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2644 else if (screen_nr == 2)
2646 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2647 "Special thanks to");
2648 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2649 "Michael Stopp & Philip Jespersen");
2650 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2652 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2654 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2656 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2658 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2660 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2661 "Digital Integration");
2663 else if (screen_nr == 3)
2665 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2666 "Special thanks to");
2667 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2668 "Hiroyuki Imabayashi");
2669 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2671 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2673 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2675 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2677 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2679 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2682 else if (screen_nr == 4)
2684 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2685 "Special thanks to");
2686 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2688 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2690 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2691 "J\xfcrgen Bonhagen");
2692 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2693 "for the continuous creation");
2694 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2695 "of outstanding level sets");
2697 else if (screen_nr == 5)
2699 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2701 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2703 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2704 "for ideas and inspiration by");
2705 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2708 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2710 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2712 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2713 "for ideas and inspiration by");
2714 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2717 else if (screen_nr == 6)
2719 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2721 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2724 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2725 "for the code base used for the");
2726 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2727 "native Emerald Mine engine");
2729 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2730 "for the new Emerald Mine engine");
2733 else if (screen_nr == 7)
2735 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2737 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2739 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2740 "for the initial DOS port");
2742 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2744 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2746 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2747 "for some additional toons");
2749 else if (screen_nr == 8)
2751 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2752 "And not to forget:");
2753 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2755 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2756 "All those who contributed");
2757 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2758 "levels to this game");
2759 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2763 DrawTextSCentered(ybottom, FONT_TEXT_4,
2764 "Press any key or button for next page");
2767 void DrawInfoScreen_Credits()
2769 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2771 FadeSoundsAndMusic();
2773 FadeOut(REDRAW_FIELD);
2775 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2777 FadeIn(REDRAW_FIELD);
2780 void HandleInfoScreen_Credits(int button)
2782 static int screen_nr = 0;
2783 int num_screens = 9;
2785 if (button == MB_MENU_INITIALIZE)
2789 // DrawInfoScreen_CreditsScreen(screen_nr);
2792 if (button == MB_MENU_LEAVE)
2794 PlaySound(SND_MENU_ITEM_SELECTING);
2796 info_mode = INFO_MODE_MAIN;
2801 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2803 if (button != MB_MENU_INITIALIZE)
2805 PlaySound(SND_MENU_ITEM_SELECTING);
2810 if (screen_nr >= num_screens)
2812 FadeSoundsAndMusic();
2814 info_mode = INFO_MODE_MAIN;
2815 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2821 FadeSetNextScreen();
2823 if (button != MB_MENU_INITIALIZE)
2824 FadeOut(REDRAW_FIELD);
2826 DrawInfoScreen_CreditsScreen(screen_nr);
2828 if (button != MB_MENU_INITIALIZE)
2829 FadeIn(REDRAW_FIELD);
2833 PlayMenuSoundIfLoop();
2837 void DrawInfoScreen_Program()
2839 int ystart1 = mSY - SY + 100;
2840 int ystart2 = mSY - SY + 150;
2841 int ybottom = mSY - SY + SYSIZE - 20;
2844 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2846 FadeOut(REDRAW_FIELD);
2851 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2853 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2854 "This game is Freeware!");
2855 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2856 "If you like it, send e-mail to:");
2857 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2858 PROGRAM_EMAIL_STRING);
2859 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2860 "More information and levels:");
2861 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2862 PROGRAM_WEBSITE_STRING);
2863 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2864 "If you have created new levels,");
2865 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2866 "send them to me to include them!");
2867 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2870 DrawTextSCentered(ybottom, FONT_TEXT_4,
2871 "Press any key or button for info menu");
2873 FadeIn(REDRAW_FIELD);
2876 void HandleInfoScreen_Program(int button)
2878 if (button == MB_MENU_LEAVE)
2880 PlaySound(SND_MENU_ITEM_SELECTING);
2882 info_mode = INFO_MODE_MAIN;
2887 else if (button == MB_MENU_CHOICE)
2889 PlaySound(SND_MENU_ITEM_SELECTING);
2891 FadeSoundsAndMusic();
2893 info_mode = INFO_MODE_MAIN;
2894 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2898 PlayMenuSoundIfLoop();
2902 void DrawInfoScreen_Version()
2904 int font_header = FONT_TEXT_3;
2905 int font_text = FONT_TEXT_2;
2906 int xstep = getFontWidth(font_text);
2907 int ystep = getFontHeight(font_text);
2908 int ystart1 = mSY - SY + 100;
2909 int ystart2 = mSY - SY + 150;
2910 int ybottom = mSY - SY + SYSIZE - 20;
2911 int xstart1 = mSX - SX + 2 * xstep;
2912 int xstart2 = mSX - SX + 18 * xstep;
2913 int xstart3 = mSX - SX + 28 * xstep;
2914 SDL_version sdl_version_compiled;
2915 const SDL_version *sdl_version_linked;
2916 int driver_name_len = 10;
2917 #if defined(TARGET_SDL2)
2918 SDL_version sdl_version_linked_ext;
2919 const char *driver_name = NULL;
2921 char driver_name[driver_name_len];
2924 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2926 FadeOut(REDRAW_FIELD);
2931 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2933 DrawTextF(xstart1, ystart2, font_header, "Name");
2934 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2937 DrawTextF(xstart1, ystart2, font_header, "Version");
2938 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
2941 DrawTextF(xstart1, ystart2, font_header, "Platform");
2942 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2945 DrawTextF(xstart1, ystart2, font_header, "Target");
2946 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2949 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2950 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2952 ystart2 += 3 * ystep;
2953 DrawTextF(xstart1, ystart2, font_header, "Library");
2954 DrawTextF(xstart2, ystart2, font_header, "compiled");
2955 DrawTextF(xstart3, ystart2, font_header, "linked");
2957 SDL_VERSION(&sdl_version_compiled);
2958 #if defined(TARGET_SDL2)
2959 SDL_GetVersion(&sdl_version_linked_ext);
2960 sdl_version_linked = &sdl_version_linked_ext;
2962 sdl_version_linked = SDL_Linked_Version();
2965 ystart2 += 2 * ystep;
2966 DrawTextF(xstart1, ystart2, font_text, "SDL");
2967 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2968 sdl_version_compiled.major,
2969 sdl_version_compiled.minor,
2970 sdl_version_compiled.patch);
2971 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2972 sdl_version_linked->major,
2973 sdl_version_linked->minor,
2974 sdl_version_linked->patch);
2976 SDL_IMAGE_VERSION(&sdl_version_compiled);
2977 sdl_version_linked = IMG_Linked_Version();
2980 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2981 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2982 sdl_version_compiled.major,
2983 sdl_version_compiled.minor,
2984 sdl_version_compiled.patch);
2985 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2986 sdl_version_linked->major,
2987 sdl_version_linked->minor,
2988 sdl_version_linked->patch);
2990 SDL_MIXER_VERSION(&sdl_version_compiled);
2991 sdl_version_linked = Mix_Linked_Version();
2994 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2995 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2996 sdl_version_compiled.major,
2997 sdl_version_compiled.minor,
2998 sdl_version_compiled.patch);
2999 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3000 sdl_version_linked->major,
3001 sdl_version_linked->minor,
3002 sdl_version_linked->patch);
3004 SDL_NET_VERSION(&sdl_version_compiled);
3005 sdl_version_linked = SDLNet_Linked_Version();
3008 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3009 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3010 sdl_version_compiled.major,
3011 sdl_version_compiled.minor,
3012 sdl_version_compiled.patch);
3013 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3014 sdl_version_linked->major,
3015 sdl_version_linked->minor,
3016 sdl_version_linked->patch);
3018 ystart2 += 3 * ystep;
3019 DrawTextF(xstart1, ystart2, font_header, "Driver");
3020 DrawTextF(xstart2, ystart2, font_header, "Requested");
3021 DrawTextF(xstart3, ystart2, font_header, "Used");
3023 #if defined(TARGET_SDL2)
3024 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3026 SDL_VideoDriverName(driver_name, driver_name_len);
3029 ystart2 += 2 * ystep;
3030 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3031 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3032 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3034 #if defined(TARGET_SDL2)
3035 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3037 SDL_AudioDriverName(driver_name, driver_name_len);
3041 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3042 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3043 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3045 DrawTextSCentered(ybottom, FONT_TEXT_4,
3046 "Press any key or button for info menu");
3048 FadeIn(REDRAW_FIELD);
3051 void HandleInfoScreen_Version(int button)
3053 if (button == MB_MENU_LEAVE)
3055 PlaySound(SND_MENU_ITEM_SELECTING);
3057 info_mode = INFO_MODE_MAIN;
3062 else if (button == MB_MENU_CHOICE)
3064 PlaySound(SND_MENU_ITEM_SELECTING);
3066 FadeSoundsAndMusic();
3068 info_mode = INFO_MODE_MAIN;
3069 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3073 PlayMenuSoundIfLoop();
3077 void DrawInfoScreen_LevelSet()
3079 struct TitleMessageInfo *tmi = &readme;
3080 char *filename = getLevelSetInfoFilename();
3081 char *title = "Level Set Information:";
3082 int ystart1 = mSY - SY + 100;
3083 int ybottom = mSY - SY + SYSIZE - 20;
3085 if (filename == NULL)
3087 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3092 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3094 FadeOut(REDRAW_FIELD);
3099 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3101 /* if x position set to "-1", automatically determine by playfield width */
3103 tmi->x = SXSIZE / 2;
3105 /* if y position set to "-1", use static default value */
3109 /* if width set to "-1", automatically determine by playfield width */
3110 if (tmi->width == -1)
3111 tmi->width = SXSIZE - 2 * TILEX;
3113 /* if height set to "-1", automatically determine by playfield height */
3114 if (tmi->height == -1)
3115 tmi->height = SYSIZE - 20 - tmi->y - 10;
3117 /* if chars set to "-1", automatically determine by text and font width */
3118 if (tmi->chars == -1)
3119 tmi->chars = tmi->width / getFontWidth(tmi->font);
3121 tmi->width = tmi->chars * getFontWidth(tmi->font);
3123 /* if lines set to "-1", automatically determine by text and font height */
3124 if (tmi->lines == -1)
3125 tmi->lines = tmi->height / getFontHeight(tmi->font);
3127 tmi->height = tmi->lines * getFontHeight(tmi->font);
3129 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3130 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3131 tmi->autowrap, tmi->centered, tmi->parse_comments);
3133 DrawTextSCentered(ybottom, FONT_TEXT_4,
3134 "Press any key or button for info menu");
3136 FadeIn(REDRAW_FIELD);
3139 void HandleInfoScreen_LevelSet(int button)
3141 if (button == MB_MENU_LEAVE)
3143 PlaySound(SND_MENU_ITEM_SELECTING);
3145 info_mode = INFO_MODE_MAIN;
3150 else if (button == MB_MENU_CHOICE)
3152 PlaySound(SND_MENU_ITEM_SELECTING);
3154 FadeSoundsAndMusic();
3156 info_mode = INFO_MODE_MAIN;
3157 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3161 PlayMenuSoundIfLoop();
3165 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3167 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3169 if (info_mode == INFO_MODE_TITLE)
3170 DrawInfoScreen_TitleScreen();
3171 else if (info_mode == INFO_MODE_ELEMENTS)
3172 DrawInfoScreen_Elements();
3173 else if (info_mode == INFO_MODE_MUSIC)
3174 DrawInfoScreen_Music();
3175 else if (info_mode == INFO_MODE_CREDITS)
3176 DrawInfoScreen_Credits();
3177 else if (info_mode == INFO_MODE_PROGRAM)
3178 DrawInfoScreen_Program();
3179 else if (info_mode == INFO_MODE_VERSION)
3180 DrawInfoScreen_Version();
3181 else if (info_mode == INFO_MODE_LEVELSET)
3182 DrawInfoScreen_LevelSet();
3184 DrawInfoScreen_Main(fade_mask, do_fading);
3186 if (info_mode != INFO_MODE_MAIN &&
3187 info_mode != INFO_MODE_TITLE &&
3188 info_mode != INFO_MODE_MUSIC)
3195 void DrawAndFadeInInfoScreen(int fade_mask)
3197 DrawInfoScreenExt(fade_mask, TRUE);
3200 void DrawInfoScreen()
3202 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3205 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3207 if (info_mode == INFO_MODE_TITLE)
3208 HandleInfoScreen_TitleScreen(button);
3209 else if (info_mode == INFO_MODE_ELEMENTS)
3210 HandleInfoScreen_Elements(button);
3211 else if (info_mode == INFO_MODE_MUSIC)
3212 HandleInfoScreen_Music(button);
3213 else if (info_mode == INFO_MODE_CREDITS)
3214 HandleInfoScreen_Credits(button);
3215 else if (info_mode == INFO_MODE_PROGRAM)
3216 HandleInfoScreen_Program(button);
3217 else if (info_mode == INFO_MODE_VERSION)
3218 HandleInfoScreen_Version(button);
3219 else if (info_mode == INFO_MODE_LEVELSET)
3220 HandleInfoScreen_LevelSet(button);
3222 HandleInfoScreen_Main(mx, my, dx, dy, button);
3226 /* ========================================================================= */
3227 /* type name functions */
3228 /* ========================================================================= */
3230 void HandleTypeName(int newxpos, Key key)
3232 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3233 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3234 struct TextPosInfo *pos = mci->pos_input;
3235 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3236 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3237 static int xpos = 0;
3238 int font_nr = pos->font;
3239 int font_active_nr = FONT_ACTIVE(font_nr);
3240 int font_width = getFontWidth(font_active_nr);
3241 char key_char = getValidConfigValueChar(getCharFromKey(key));
3242 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3243 boolean is_active = TRUE;
3245 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3249 strcpy(last_player_name, setup.player_name);
3253 #if defined(TARGET_SDL2)
3254 SDL_StartTextInput();
3257 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3259 setup.player_name[xpos] = key_char;
3260 setup.player_name[xpos + 1] = 0;
3264 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3268 setup.player_name[xpos] = 0;
3270 else if (key == KSYM_Return && xpos > 0)
3276 game_status = GAME_MODE_MAIN;
3278 else if (key == KSYM_Escape)
3280 strcpy(setup.player_name, last_player_name);
3284 game_status = GAME_MODE_MAIN;
3289 pos->width = (strlen(setup.player_name) + 1) * font_width;
3290 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3292 DrawText(startx, starty, setup.player_name, font_active_nr);
3293 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3297 pos->width = strlen(setup.player_name) * font_width;
3298 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3300 DrawText(startx, starty, setup.player_name, font_nr);
3302 #if defined(TARGET_SDL2)
3303 SDL_StopTextInput();
3309 /* ========================================================================= */
3310 /* tree menu functions */
3311 /* ========================================================================= */
3313 static void DrawChooseTree(TreeInfo **ti_ptr)
3315 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3317 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3319 game_status = GAME_MODE_MAIN;
3321 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3328 FreeScreenGadgets();
3329 CreateScreenGadgets();
3331 CloseDoor(DOOR_CLOSE_2);
3337 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3338 MapScreenTreeGadgets(*ti_ptr);
3345 static void AdjustScrollbar(int id, int items_max, int items_visible,
3348 struct GadgetInfo *gi = screen_gadget[id];
3350 if (item_position > items_max - items_visible)
3351 item_position = items_max - items_visible;
3353 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3354 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3355 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3358 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3360 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3364 static void clearMenuListArea()
3366 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3368 /* correct scrollbar position if placed outside menu (playfield) area */
3369 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
3370 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
3372 /* clear menu list area, but not title or scrollbar */
3373 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3374 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
3377 static void drawChooseTreeList(int first_entry, int num_page_entries,
3381 char *title_string = NULL;
3382 int yoffset_sets = MENU_TITLE1_YPOS;
3383 int yoffset_setup = 16;
3384 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3385 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3386 int last_game_status = game_status; /* save current game status */
3388 title_string = ti->infotext;
3390 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3392 clearMenuListArea();
3394 for (i = 0; i < num_page_entries; i++)
3396 TreeInfo *node, *node_first;
3397 int entry_pos = first_entry + i;
3398 int xpos = MENU_SCREEN_START_XPOS;
3399 int ypos = MENU_SCREEN_START_YPOS + i;
3400 int startx = mSX + xpos * 32;
3401 int starty = mSY + ypos * 32;
3402 int font_nr = FONT_TEXT_1;
3403 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3404 int startx_text = startx + font_xoffset;
3405 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3406 int text_size = startx_scrollbar - startx_text;
3407 int max_buffer_len = text_size / getFontWidth(font_nr);
3408 char buffer[max_buffer_len + 1];
3410 node_first = getTreeInfoFirstGroupEntry(ti);
3411 node = getTreeInfoFromPos(node_first, entry_pos);
3413 strncpy(buffer, node->name, max_buffer_len);
3414 buffer[max_buffer_len] = '\0';
3416 DrawText(startx, starty, buffer, font_nr + node->color);
3418 if (node->parent_link)
3419 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3420 else if (node->level_group)
3421 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3423 initCursor(i, IMG_MENU_BUTTON);
3426 game_status = last_game_status; /* restore current game status */
3428 redraw_mask |= REDRAW_FIELD;
3431 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3433 TreeInfo *node, *node_first;
3434 int x, last_redraw_mask = redraw_mask;
3435 int ypos = MENU_TITLE2_YPOS;
3436 int font_nr = FONT_TITLE_2;
3438 if (ti->type == TREE_TYPE_LEVEL_NR)
3439 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3441 if (ti->type != TREE_TYPE_LEVEL_DIR)
3444 node_first = getTreeInfoFirstGroupEntry(ti);
3445 node = getTreeInfoFromPos(node_first, entry_pos);
3447 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3449 if (node->parent_link)
3450 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3451 node->node_parent->name);
3452 else if (node->level_group)
3453 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3455 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3456 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3457 node->levels, (node->levels > 1 ? "levels" : "level"),
3460 /* let BackToFront() redraw only what is needed */
3461 redraw_mask = last_redraw_mask | REDRAW_TILES;
3462 for (x = 0; x < SCR_FIELDX; x++)
3463 MarkTileDirty(x, 1);
3466 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3469 TreeInfo *ti = *ti_ptr;
3471 int y = ti->cl_cursor;
3472 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3473 int num_entries = numTreeInfoInGroup(ti);
3474 int num_page_entries;
3475 int last_game_status = game_status; /* save current game status */
3476 boolean position_set_by_scrollbar = (dx == 999);
3478 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3479 num_page_entries = num_entries;
3481 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3483 game_status = last_game_status; /* restore current game status */
3485 if (button == MB_MENU_INITIALIZE)
3487 int num_entries = numTreeInfoInGroup(ti);
3488 int entry_pos = posTreeInfo(ti);
3490 if (ti->cl_first == -1)
3492 /* only on initialization */
3493 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3494 ti->cl_cursor = entry_pos - ti->cl_first;
3496 else if (ti->cl_cursor >= num_page_entries ||
3497 (num_entries > num_page_entries &&
3498 num_entries - ti->cl_first < num_page_entries))
3500 /* only after change of list size (by custom graphic configuration) */
3501 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3502 ti->cl_cursor = entry_pos - ti->cl_first;
3505 if (position_set_by_scrollbar)
3508 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3511 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3512 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3513 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3517 else if (button == MB_MENU_LEAVE)
3521 PlaySound(SND_MENU_ITEM_SELECTING);
3523 if (ti->node_parent)
3525 *ti_ptr = ti->node_parent;
3526 DrawChooseTree(ti_ptr);
3528 else if (game_status == GAME_MODE_SETUP)
3530 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3531 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3532 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3534 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3535 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3536 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3537 execSetupGraphics();
3538 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3539 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3540 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3542 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3543 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3544 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3551 if (game_status == GAME_MODE_LEVELNR)
3553 int new_level_nr = atoi(level_number_current->identifier);
3555 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3558 game_status = GAME_MODE_MAIN;
3560 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3566 if (mx || my) /* mouse input */
3568 int last_game_status = game_status; /* save current game status */
3570 x = (mx - mSX) / 32;
3571 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3573 game_status = last_game_status; /* restore current game status */
3575 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3577 /* move cursor instead of scrolling when already at start/end of list */
3578 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3580 else if (dy == +1 * SCROLL_LINE &&
3581 ti->cl_first + num_page_entries == num_entries)
3584 /* handle scrolling screen one line or page */
3585 if (ti->cl_cursor + dy < 0 ||
3586 ti->cl_cursor + dy > num_page_entries - 1)
3588 boolean redraw = FALSE;
3590 if (ABS(dy) == SCROLL_PAGE)
3591 step = num_page_entries - 1;
3593 if (dy < 0 && ti->cl_first > 0)
3595 /* scroll page/line up */
3597 ti->cl_first -= step;
3598 if (ti->cl_first < 0)
3603 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3605 /* scroll page/line down */
3607 ti->cl_first += step;
3608 if (ti->cl_first + num_page_entries > num_entries)
3609 ti->cl_first = MAX(0, num_entries - num_page_entries);
3616 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3617 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3618 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3620 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3627 /* handle moving cursor one line */
3628 y = ti->cl_cursor + dy;
3633 TreeInfo *node_first, *node_cursor;
3634 int entry_pos = ti->cl_first + y;
3636 node_first = getTreeInfoFirstGroupEntry(ti);
3637 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3639 if (node_cursor->node_group)
3643 PlaySound(SND_MENU_ITEM_SELECTING);
3645 node_cursor->cl_first = ti->cl_first;
3646 node_cursor->cl_cursor = ti->cl_cursor;
3647 *ti_ptr = node_cursor->node_group;
3648 DrawChooseTree(ti_ptr);
3653 else if (dx == -1 && ti->node_parent)
3657 PlaySound(SND_MENU_ITEM_SELECTING);
3659 *ti_ptr = ti->node_parent;
3660 DrawChooseTree(ti_ptr);
3665 if (!anyScrollbarGadgetActive() &&
3666 IN_VIS_MENU(x, y) &&
3667 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3668 y >= 0 && y < num_page_entries)
3672 if (y != ti->cl_cursor)
3674 PlaySound(SND_MENU_ITEM_ACTIVATING);
3676 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3677 drawChooseTreeCursor(y, TRUE);
3678 drawChooseTreeInfo(ti->cl_first + y, ti);
3685 TreeInfo *node_first, *node_cursor;
3686 int entry_pos = ti->cl_first + y;
3688 PlaySound(SND_MENU_ITEM_SELECTING);
3690 node_first = getTreeInfoFirstGroupEntry(ti);
3691 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3693 if (node_cursor->node_group)
3697 node_cursor->cl_first = ti->cl_first;
3698 node_cursor->cl_cursor = ti->cl_cursor;
3699 *ti_ptr = node_cursor->node_group;
3700 DrawChooseTree(ti_ptr);
3702 else if (node_cursor->parent_link)
3706 *ti_ptr = node_cursor->node_parent;
3707 DrawChooseTree(ti_ptr);
3713 node_cursor->cl_first = ti->cl_first;
3714 node_cursor->cl_cursor = ti->cl_cursor;
3715 *ti_ptr = node_cursor;
3717 if (ti->type == TREE_TYPE_LEVEL_DIR)
3719 LoadLevelSetup_SeriesInfo();
3721 SaveLevelSetup_LastSeries();
3722 SaveLevelSetup_SeriesInfo();
3726 if (game_status == GAME_MODE_SETUP)
3728 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3729 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3730 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3732 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3733 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3734 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3735 execSetupGraphics();
3736 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3737 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3738 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3740 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3741 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3742 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3749 if (game_status == GAME_MODE_LEVELNR)
3751 int new_level_nr = atoi(level_number_current->identifier);
3753 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3756 game_status = GAME_MODE_MAIN;
3765 void DrawChooseLevelSet()
3767 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3769 DrawChooseTree(&leveldir_current);
3775 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3777 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3780 void DrawChooseLevelNr()
3784 if (level_number != NULL)
3786 freeTreeInfo(level_number);
3788 level_number = NULL;
3791 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3793 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3794 char identifier[32], name[32];
3797 /* temporarily load level info to get level name */
3798 LoadLevelInfoOnly(i);
3800 ti->node_top = &level_number;
3801 ti->sort_priority = 10000 + value;
3802 ti->color = (level.no_valid_file ? FC_BLUE :
3803 LevelStats_getSolved(i) ? FC_GREEN :
3804 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3806 sprintf(identifier, "%d", value);
3807 sprintf(name, "%03d: %s", value,
3808 (level.no_valid_file ? "(no file)" : level.name));
3810 setString(&ti->identifier, identifier);
3811 setString(&ti->name, name);
3812 setString(&ti->name_sorting, name);
3814 pushTreeInfo(&level_number, ti);
3817 /* sort level number values to start with lowest level number */
3818 sortTreeInfo(&level_number);
3820 /* set current level number to current level number */
3821 level_number_current =
3822 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3824 /* if that also fails, set current level number to first available level */
3825 if (level_number_current == NULL)
3826 level_number_current = level_number;
3828 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3830 DrawChooseTree(&level_number_current);
3836 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3838 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3841 void DrawHallOfFame(int highlight_position)
3843 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3846 FadeSoundsAndMusic();
3848 /* (this is needed when called from GameEnd() after winning a game) */
3849 KeyboardAutoRepeatOn();
3852 /* (this is needed when called from GameEnd() after winning a game) */
3853 SetDrawDeactivationMask(REDRAW_NONE);
3854 SetDrawBackgroundMask(REDRAW_FIELD);
3856 CloseDoor(DOOR_CLOSE_2);
3858 if (highlight_position < 0)
3859 LoadScore(level_nr);
3861 FadeSetEnterScreen();
3870 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3875 static void drawHallOfFameList(int first_entry, int highlight_position)
3879 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3882 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3883 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3884 "HighScores of Level %d", level_nr);
3886 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3888 int entry = first_entry + i;
3889 boolean active = (entry == highlight_position);
3890 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3891 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3892 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3893 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3894 int dx1 = 3 * getFontWidth(font_nr1);
3895 int dx2 = dx1 + getFontWidth(font_nr1);
3896 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
3897 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
3898 int sy = mSY + 64 + i * 32;
3900 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3901 DrawText(mSX + dx1, sy, ".", font_nr1);
3903 for (j = 0; j < num_dots; j++)
3904 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
3906 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3907 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3909 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3912 redraw_mask |= REDRAW_FIELD;
3915 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3917 static int first_entry = 0;
3918 static int highlight_position = 0;
3919 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3921 if (button == MB_MENU_INITIALIZE)
3924 highlight_position = mx;
3925 drawHallOfFameList(first_entry, highlight_position);
3930 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3931 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3935 if (first_entry > 0)
3937 first_entry -= step;
3938 if (first_entry < 0)
3941 drawHallOfFameList(first_entry, highlight_position);
3946 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3948 first_entry += step;
3949 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3950 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3952 drawHallOfFameList(first_entry, highlight_position);
3955 else if (button == MB_MENU_LEAVE)
3957 PlaySound(SND_MENU_ITEM_SELECTING);
3959 FadeSound(SND_BACKGROUND_SCORES);
3961 game_status = GAME_MODE_MAIN;
3965 else if (button == MB_MENU_CHOICE)
3967 PlaySound(SND_MENU_ITEM_SELECTING);
3969 FadeSound(SND_BACKGROUND_SCORES);
3971 game_status = GAME_MODE_MAIN;
3973 DrawAndFadeInMainMenu(REDRAW_FIELD);
3976 if (game_status == GAME_MODE_SCORES)
3977 PlayMenuSoundIfLoop();
3981 /* ========================================================================= */
3982 /* setup screen functions */
3983 /* ========================================================================= */
3985 static struct TokenInfo *setup_info;
3986 static int num_setup_info; /* number of setup entries shown on screen */
3987 static int max_setup_info; /* total number of setup entries in list */
3989 static char *screen_mode_text;
3990 static char *window_size_text;
3991 static char *scaling_type_text;
3992 static char *scroll_delay_text;
3993 static char *snapshot_mode_text;
3994 static char *game_speed_text;
3995 static char *graphics_set_name;
3996 static char *sounds_set_name;
3997 static char *music_set_name;
3998 static char *volume_simple_text;
3999 static char *volume_loops_text;
4000 static char *volume_music_text;
4001 static char *touch_controls_text;
4002 static char *move_distance_text;
4003 static char *drop_distance_text;
4005 static void execSetupMain()
4007 setup_mode = SETUP_MODE_MAIN;
4012 static void execSetupGame_setGameSpeeds()
4014 if (game_speeds == NULL)
4018 for (i = 0; game_speeds_list[i].value != -1; i++)
4020 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4021 char identifier[32], name[32];
4022 int value = game_speeds_list[i].value;
4023 char *text = game_speeds_list[i].text;
4025 ti->node_top = &game_speeds;
4026 ti->sort_priority = 10000 - value;
4028 sprintf(identifier, "%d", value);
4029 sprintf(name, "%s", text);
4031 setString(&ti->identifier, identifier);
4032 setString(&ti->name, name);
4033 setString(&ti->name_sorting, name);
4034 setString(&ti->infotext, "Game Speed");
4036 pushTreeInfo(&game_speeds, ti);
4039 /* sort game speed values to start with slowest game speed */
4040 sortTreeInfo(&game_speeds);
4042 /* set current game speed to configured game speed value */
4043 game_speed_current =
4044 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4046 /* if that fails, set current game speed to reliable default value */
4047 if (game_speed_current == NULL)
4048 game_speed_current =
4049 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4051 /* if that also fails, set current game speed to first available speed */
4052 if (game_speed_current == NULL)
4053 game_speed_current = game_speeds;
4056 setup.game_frame_delay = atoi(game_speed_current->identifier);
4058 /* needed for displaying game speed text instead of identifier */
4059 game_speed_text = game_speed_current->name;
4062 static void execSetupGame_setScrollDelays()
4064 if (scroll_delays == NULL)
4068 for (i = 0; scroll_delays_list[i].value != -1; i++)
4070 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4071 char identifier[32], name[32];
4072 int value = scroll_delays_list[i].value;
4073 char *text = scroll_delays_list[i].text;
4075 ti->node_top = &scroll_delays;
4076 ti->sort_priority = value;
4078 sprintf(identifier, "%d", value);
4079 sprintf(name, "%s", text);
4081 setString(&ti->identifier, identifier);
4082 setString(&ti->name, name);
4083 setString(&ti->name_sorting, name);
4084 setString(&ti->infotext, "Scaling Type");
4086 pushTreeInfo(&scroll_delays, ti);
4089 /* sort scaling type values to start with lowest scaling type value */
4090 sortTreeInfo(&scroll_delays);
4092 /* set current scaling type value to configured scaling type value */
4093 scroll_delay_current =
4094 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4096 /* if that fails, set current scaling type to reliable default value */
4097 if (scroll_delay_current == NULL)
4098 scroll_delay_current =
4099 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4101 /* if that also fails, set current scaling type to first available value */
4102 if (scroll_delay_current == NULL)
4103 scroll_delay_current = scroll_delays;
4106 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4108 /* needed for displaying scaling type text instead of identifier */
4109 scroll_delay_text = scroll_delay_current->name;
4112 static void execSetupGame_setSnapshotModes()
4114 if (snapshot_modes == NULL)
4118 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4120 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4121 char identifier[32], name[32];
4122 char *value = snapshot_modes_list[i].value;
4123 char *text = snapshot_modes_list[i].text;
4125 ti->node_top = &snapshot_modes;
4126 ti->sort_priority = i;
4128 sprintf(identifier, "%s", value);
4129 sprintf(name, "%s", text);
4131 setString(&ti->identifier, identifier);
4132 setString(&ti->name, name);
4133 setString(&ti->name_sorting, name);
4134 setString(&ti->infotext, "Snapshot Mode");
4136 pushTreeInfo(&snapshot_modes, ti);
4139 /* sort snapshot mode values to start with lowest snapshot mode value */
4140 sortTreeInfo(&snapshot_modes);
4142 /* set current snapshot mode value to configured snapshot mode value */
4143 snapshot_mode_current =
4144 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4146 /* if that fails, set current snapshot mode to reliable default value */
4147 if (snapshot_mode_current == NULL)
4148 snapshot_mode_current =
4149 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4151 /* if that also fails, set current snapshot mode to first available value */
4152 if (snapshot_mode_current == NULL)
4153 snapshot_mode_current = snapshot_modes;
4156 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4158 /* needed for displaying snapshot mode text instead of identifier */
4159 snapshot_mode_text = snapshot_mode_current->name;
4162 static void execSetupGame()
4164 execSetupGame_setGameSpeeds();
4165 execSetupGame_setScrollDelays();
4166 execSetupGame_setSnapshotModes();
4168 setup_mode = SETUP_MODE_GAME;
4173 static void execSetupChooseGameSpeed()
4175 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4180 static void execSetupChooseScrollDelay()
4182 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4187 static void execSetupChooseSnapshotMode()
4189 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4194 static void execSetupEditor()
4196 setup_mode = SETUP_MODE_EDITOR;
4201 static void execSetupGraphics_setWindowSizes(boolean update_list)
4203 if (window_sizes != NULL && update_list)
4205 freeTreeInfo(window_sizes);
4207 window_sizes = NULL;
4210 if (window_sizes == NULL)
4212 boolean current_window_size_found = FALSE;
4215 for (i = 0; window_sizes_list[i].value != -1; i++)
4217 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4218 char identifier[32], name[32];
4219 int value = window_sizes_list[i].value;
4220 char *text = window_sizes_list[i].text;
4222 ti->node_top = &window_sizes;
4223 ti->sort_priority = value;
4225 sprintf(identifier, "%d", value);
4226 sprintf(name, "%s", text);
4228 setString(&ti->identifier, identifier);
4229 setString(&ti->name, name);
4230 setString(&ti->name_sorting, name);
4231 setString(&ti->infotext, "Window Scaling");
4233 pushTreeInfo(&window_sizes, ti);
4235 if (value == setup.window_scaling_percent)
4236 current_window_size_found = TRUE;
4239 if (!current_window_size_found)
4241 // add entry for non-preset window scaling value
4243 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4244 char identifier[32], name[32];
4245 int value = setup.window_scaling_percent;
4247 ti->node_top = &window_sizes;
4248 ti->sort_priority = value;
4250 sprintf(identifier, "%d", value);
4251 sprintf(name, "%d %% (Current)", value);
4253 setString(&ti->identifier, identifier);
4254 setString(&ti->name, name);
4255 setString(&ti->name_sorting, name);
4256 setString(&ti->infotext, "Window Scaling");
4258 pushTreeInfo(&window_sizes, ti);
4261 /* sort window size values to start with lowest window size value */
4262 sortTreeInfo(&window_sizes);
4264 /* set current window size value to configured window size value */
4265 window_size_current =
4266 getTreeInfoFromIdentifier(window_sizes,
4267 i_to_a(setup.window_scaling_percent));
4269 /* if that fails, set current window size to reliable default value */
4270 if (window_size_current == NULL)
4271 window_size_current =
4272 getTreeInfoFromIdentifier(window_sizes,
4273 i_to_a(STD_WINDOW_SCALING_PERCENT));
4275 /* if that also fails, set current window size to first available value */
4276 if (window_size_current == NULL)
4277 window_size_current = window_sizes;
4280 setup.window_scaling_percent = atoi(window_size_current->identifier);
4282 /* needed for displaying window size text instead of identifier */
4283 window_size_text = window_size_current->name;
4286 static void execSetupGraphics_setScalingTypes()
4288 if (scaling_types == NULL)
4292 for (i = 0; scaling_types_list[i].value != NULL; i++)
4294 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4295 char identifier[32], name[32];
4296 char *value = scaling_types_list[i].value;
4297 char *text = scaling_types_list[i].text;
4299 ti->node_top = &scaling_types;
4300 ti->sort_priority = i;
4302 sprintf(identifier, "%s", value);
4303 sprintf(name, "%s", text);
4305 setString(&ti->identifier, identifier);
4306 setString(&ti->name, name);
4307 setString(&ti->name_sorting, name);
4308 setString(&ti->infotext, "Anti-Aliasing");
4310 pushTreeInfo(&scaling_types, ti);
4313 /* sort scaling type values to start with lowest scaling type value */
4314 sortTreeInfo(&scaling_types);
4316 /* set current scaling type value to configured scaling type value */
4317 scaling_type_current =
4318 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4320 /* if that fails, set current scaling type to reliable default value */
4321 if (scaling_type_current == NULL)
4322 scaling_type_current =
4323 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4325 /* if that also fails, set current scaling type to first available value */
4326 if (scaling_type_current == NULL)
4327 scaling_type_current = scaling_types;
4330 setup.window_scaling_quality = scaling_type_current->identifier;
4332 /* needed for displaying scaling type text instead of identifier */
4333 scaling_type_text = scaling_type_current->name;
4336 static void execSetupGraphics_setScreenModes()
4338 // if (screen_modes == NULL && video.fullscreen_available)
4339 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4343 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4345 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4346 char identifier[32], name[32];
4347 int x = video.fullscreen_modes[i].width;
4348 int y = video.fullscreen_modes[i].height;
4351 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4353 ti->node_top = &screen_modes;
4354 ti->sort_priority = x * 10000 + y;
4356 sprintf(identifier, "%dx%d", x, y);
4357 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4359 setString(&ti->identifier, identifier);
4360 setString(&ti->name, name);
4361 setString(&ti->name_sorting, name);
4362 setString(&ti->infotext, "Fullscreen Mode");
4364 pushTreeInfo(&screen_modes, ti);
4367 /* sort fullscreen modes to start with lowest available screen resolution */
4368 sortTreeInfo(&screen_modes);
4370 /* set current screen mode for fullscreen mode to configured setup value */
4371 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4372 setup.fullscreen_mode);
4374 /* if that fails, set current screen mode to reliable default value */
4375 if (screen_mode_current == NULL)
4376 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4377 DEFAULT_FULLSCREEN_MODE);
4379 /* if that also fails, set current screen mode to first available mode */
4380 if (screen_mode_current == NULL)
4381 screen_mode_current = screen_modes;
4383 if (screen_mode_current == NULL)
4384 video.fullscreen_available = FALSE;
4387 // if (video.fullscreen_available)
4388 if (screen_mode_current != NULL)
4390 setup.fullscreen_mode = screen_mode_current->identifier;
4392 /* needed for displaying screen mode name instead of identifier */
4393 screen_mode_text = screen_mode_current->name;
4397 static void execSetupGraphics()
4399 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4401 // update "setup.window_scaling_percent" from list selection
4402 execSetupGraphics_setWindowSizes(FALSE);
4406 // update list selection from "setup.window_scaling_percent"
4407 execSetupGraphics_setWindowSizes(TRUE);
4410 execSetupGraphics_setScalingTypes();
4411 execSetupGraphics_setScreenModes();
4413 setup_mode = SETUP_MODE_GRAPHICS;
4417 #if defined(TARGET_SDL2)
4418 // window scaling may have changed at this point
4419 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4421 // window scaling quality may have changed at this point
4422 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4423 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4427 #if !defined(PLATFORM_ANDROID)
4428 #if defined(TARGET_SDL2)
4429 static void execSetupChooseWindowSize()
4431 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4436 static void execSetupChooseScalingType()
4438 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4443 static void execSetupChooseScreenMode()
4445 if (!video.fullscreen_available)
4448 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4455 static void execSetupChooseVolumeSimple()
4457 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4462 static void execSetupChooseVolumeLoops()
4464 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4469 static void execSetupChooseVolumeMusic()
4471 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4476 static void execSetupSound()
4478 if (volumes_simple == NULL)
4480 boolean current_volume_simple_found = FALSE;
4483 for (i = 0; volumes_list[i].value != -1; i++)
4485 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4486 char identifier[32], name[32];
4487 int value = volumes_list[i].value;
4488 char *text = volumes_list[i].text;
4490 ti->node_top = &volumes_simple;
4491 ti->sort_priority = value;
4493 sprintf(identifier, "%d", value);
4494 sprintf(name, "%s", text);
4496 setString(&ti->identifier, identifier);
4497 setString(&ti->name, name);
4498 setString(&ti->name_sorting, name);
4499 setString(&ti->infotext, "Sound Volume");
4501 pushTreeInfo(&volumes_simple, ti);
4503 if (value == setup.volume_simple)
4504 current_volume_simple_found = TRUE;
4507 if (!current_volume_simple_found)
4509 // add entry for non-preset volume value
4511 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4512 char identifier[32], name[32];
4513 int value = setup.volume_simple;
4515 ti->node_top = &volumes_simple;
4516 ti->sort_priority = value;
4518 sprintf(identifier, "%d", value);
4519 sprintf(name, "%d %% (Current)", value);
4521 setString(&ti->identifier, identifier);
4522 setString(&ti->name, name);
4523 setString(&ti->name_sorting, name);
4524 setString(&ti->infotext, "Sound Volume");
4526 pushTreeInfo(&volumes_simple, ti);
4529 /* sort volume values to start with lowest volume value */
4530 sortTreeInfo(&volumes_simple);
4532 /* set current volume value to configured volume value */
4533 volume_simple_current =
4534 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4536 /* if that fails, set current volume to reliable default value */
4537 if (volume_simple_current == NULL)
4538 volume_simple_current =
4539 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4541 /* if that also fails, set current volume to first available value */
4542 if (volume_simple_current == NULL)
4543 volume_simple_current = volumes_simple;
4546 if (volumes_loops == NULL)
4548 boolean current_volume_loops_found = FALSE;
4551 for (i = 0; volumes_list[i].value != -1; i++)
4553 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4554 char identifier[32], name[32];
4555 int value = volumes_list[i].value;
4556 char *text = volumes_list[i].text;
4558 ti->node_top = &volumes_loops;
4559 ti->sort_priority = value;
4561 sprintf(identifier, "%d", value);
4562 sprintf(name, "%s", text);
4564 setString(&ti->identifier, identifier);
4565 setString(&ti->name, name);
4566 setString(&ti->name_sorting, name);
4567 setString(&ti->infotext, "Loops Volume");
4569 pushTreeInfo(&volumes_loops, ti);
4571 if (value == setup.volume_loops)
4572 current_volume_loops_found = TRUE;
4575 if (!current_volume_loops_found)
4577 // add entry for non-preset volume value
4579 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4580 char identifier[32], name[32];
4581 int value = setup.volume_loops;
4583 ti->node_top = &volumes_loops;
4584 ti->sort_priority = value;
4586 sprintf(identifier, "%d", value);
4587 sprintf(name, "%d %% (Current)", value);
4589 setString(&ti->identifier, identifier);
4590 setString(&ti->name, name);
4591 setString(&ti->name_sorting, name);
4592 setString(&ti->infotext, "Loops Volume");
4594 pushTreeInfo(&volumes_loops, ti);
4597 /* sort volume values to start with lowest volume value */
4598 sortTreeInfo(&volumes_loops);
4600 /* set current volume value to configured volume value */
4601 volume_loops_current =
4602 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4604 /* if that fails, set current volume to reliable default value */
4605 if (volume_loops_current == NULL)
4606 volume_loops_current =
4607 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4609 /* if that also fails, set current volume to first available value */
4610 if (volume_loops_current == NULL)
4611 volume_loops_current = volumes_loops;
4614 if (volumes_music == NULL)
4616 boolean current_volume_music_found = FALSE;
4619 for (i = 0; volumes_list[i].value != -1; i++)
4621 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4622 char identifier[32], name[32];
4623 int value = volumes_list[i].value;
4624 char *text = volumes_list[i].text;
4626 ti->node_top = &volumes_music;
4627 ti->sort_priority = value;
4629 sprintf(identifier, "%d", value);
4630 sprintf(name, "%s", text);
4632 setString(&ti->identifier, identifier);
4633 setString(&ti->name, name);
4634 setString(&ti->name_sorting, name);
4635 setString(&ti->infotext, "Music Volume");
4637 pushTreeInfo(&volumes_music, ti);
4639 if (value == setup.volume_music)
4640 current_volume_music_found = TRUE;
4643 if (!current_volume_music_found)
4645 // add entry for non-preset volume value
4647 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4648 char identifier[32], name[32];
4649 int value = setup.volume_music;
4651 ti->node_top = &volumes_music;
4652 ti->sort_priority = value;
4654 sprintf(identifier, "%d", value);
4655 sprintf(name, "%d %% (Current)", value);
4657 setString(&ti->identifier, identifier);
4658 setString(&ti->name, name);
4659 setString(&ti->name_sorting, name);
4660 setString(&ti->infotext, "Music Volume");
4662 pushTreeInfo(&volumes_music, ti);
4665 /* sort volume values to start with lowest volume value */
4666 sortTreeInfo(&volumes_music);
4668 /* set current volume value to configured volume value */
4669 volume_music_current =
4670 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4672 /* if that fails, set current volume to reliable default value */
4673 if (volume_music_current == NULL)
4674 volume_music_current =
4675 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4677 /* if that also fails, set current volume to first available value */
4678 if (volume_music_current == NULL)
4679 volume_music_current = volumes_music;
4682 setup.volume_simple = atoi(volume_simple_current->identifier);
4683 setup.volume_loops = atoi(volume_loops_current->identifier);
4684 setup.volume_music = atoi(volume_music_current->identifier);
4686 /* needed for displaying volume text instead of identifier */
4687 volume_simple_text = volume_simple_current->name;
4688 volume_loops_text = volume_loops_current->name;
4689 volume_music_text = volume_music_current->name;
4691 setup_mode = SETUP_MODE_SOUND;
4696 static void execSetupChooseTouchControls()
4698 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4703 static void execSetupChooseMoveDistance()
4705 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4710 static void execSetupChooseDropDistance()
4712 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4717 static void execSetupTouch()
4719 if (touch_controls == NULL)
4723 for (i = 0; touch_controls_list[i].value != NULL; i++)
4725 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4726 char identifier[32], name[32];
4727 char *value = touch_controls_list[i].value;
4728 char *text = touch_controls_list[i].text;
4730 ti->node_top = &touch_controls;
4731 ti->sort_priority = i;
4733 sprintf(identifier, "%s", value);
4734 sprintf(name, "%s", text);
4736 setString(&ti->identifier, identifier);
4737 setString(&ti->name, name);
4738 setString(&ti->name_sorting, name);
4739 setString(&ti->infotext, "Control Type");
4741 pushTreeInfo(&touch_controls, ti);
4744 /* sort touch control values to start with lowest touch control value */
4745 sortTreeInfo(&touch_controls);
4747 /* set current touch control value to configured touch control value */
4748 touch_control_current =
4749 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4751 /* if that fails, set current touch control to reliable default value */
4752 if (touch_control_current == NULL)
4753 touch_control_current =
4754 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4756 /* if that also fails, set current touch control to first available value */
4757 if (touch_control_current == NULL)
4758 touch_control_current = touch_controls;
4761 if (move_distances == NULL)
4765 for (i = 0; distances_list[i].value != -1; i++)
4767 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4768 char identifier[32], name[32];
4769 int value = distances_list[i].value;
4770 char *text = distances_list[i].text;
4772 ti->node_top = &move_distances;
4773 ti->sort_priority = value;
4775 sprintf(identifier, "%d", value);
4776 sprintf(name, "%s", text);
4778 setString(&ti->identifier, identifier);
4779 setString(&ti->name, name);
4780 setString(&ti->name_sorting, name);
4781 setString(&ti->infotext, "Move Distance");
4783 pushTreeInfo(&move_distances, ti);
4786 /* sort distance values to start with lowest distance value */
4787 sortTreeInfo(&move_distances);
4789 /* set current distance value to configured distance value */
4790 move_distance_current =
4791 getTreeInfoFromIdentifier(move_distances,
4792 i_to_a(setup.touch.move_distance));
4794 /* if that fails, set current distance to reliable default value */
4795 if (move_distance_current == NULL)
4796 move_distance_current =
4797 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4799 /* if that also fails, set current distance to first available value */
4800 if (move_distance_current == NULL)
4801 move_distance_current = move_distances;
4804 if (drop_distances == NULL)
4808 for (i = 0; distances_list[i].value != -1; i++)
4810 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4811 char identifier[32], name[32];
4812 int value = distances_list[i].value;
4813 char *text = distances_list[i].text;
4815 ti->node_top = &drop_distances;
4816 ti->sort_priority = value;
4818 sprintf(identifier, "%d", value);
4819 sprintf(name, "%s", text);
4821 setString(&ti->identifier, identifier);
4822 setString(&ti->name, name);
4823 setString(&ti->name_sorting, name);
4824 setString(&ti->infotext, "Drop Distance");
4826 pushTreeInfo(&drop_distances, ti);
4829 /* sort distance values to start with lowest distance value */
4830 sortTreeInfo(&drop_distances);
4832 /* set current distance value to configured distance value */
4833 drop_distance_current =
4834 getTreeInfoFromIdentifier(drop_distances,
4835 i_to_a(setup.touch.drop_distance));
4837 /* if that fails, set current distance to reliable default value */
4838 if (drop_distance_current == NULL)
4839 drop_distance_current =
4840 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
4842 /* if that also fails, set current distance to first available value */
4843 if (drop_distance_current == NULL)
4844 drop_distance_current = drop_distances;
4847 setup.touch.control_type = touch_control_current->identifier;
4848 setup.touch.move_distance = atoi(move_distance_current->identifier);
4849 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
4851 /* needed for displaying volume text instead of identifier */
4852 touch_controls_text = touch_control_current->name;
4853 move_distance_text = move_distance_current->name;
4854 drop_distance_text = drop_distance_current->name;
4856 setup_mode = SETUP_MODE_TOUCH;
4861 static void execSetupArtwork()
4864 printf("::: '%s', '%s', '%s'\n",
4865 artwork.gfx_current->subdir,
4866 artwork.gfx_current->fullpath,
4867 artwork.gfx_current->basepath);
4870 setup.graphics_set = artwork.gfx_current->identifier;
4871 setup.sounds_set = artwork.snd_current->identifier;
4872 setup.music_set = artwork.mus_current->identifier;
4874 /* needed if last screen (setup choice) changed graphics, sounds or music */
4875 ReloadCustomArtwork(0);
4877 /* needed for displaying artwork name instead of artwork identifier */
4878 graphics_set_name = artwork.gfx_current->name;
4879 sounds_set_name = artwork.snd_current->name;
4880 music_set_name = artwork.mus_current->name;
4882 setup_mode = SETUP_MODE_ARTWORK;
4887 static void execSetupChooseGraphics()
4889 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4894 static void execSetupChooseSounds()
4896 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4901 static void execSetupChooseMusic()
4903 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4908 #if !defined(PLATFORM_ANDROID)
4909 static void execSetupInput()
4911 setup_mode = SETUP_MODE_INPUT;
4917 static void execSetupShortcuts()
4919 setup_mode = SETUP_MODE_SHORTCUTS;
4924 static void execSetupShortcuts1()
4926 setup_mode = SETUP_MODE_SHORTCUTS_1;
4931 static void execSetupShortcuts2()
4933 setup_mode = SETUP_MODE_SHORTCUTS_2;
4938 static void execSetupShortcuts3()
4940 setup_mode = SETUP_MODE_SHORTCUTS_3;
4945 static void execSetupShortcuts4()
4947 setup_mode = SETUP_MODE_SHORTCUTS_4;
4952 static void execSetupShortcuts5()
4954 setup_mode = SETUP_MODE_SHORTCUTS_5;
4959 static void execExitSetup()
4961 game_status = GAME_MODE_MAIN;
4963 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4966 static void execSaveAndExitSetup()
4972 static struct TokenInfo setup_info_main[] =
4974 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4975 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4976 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4977 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4978 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4979 #if !defined(PLATFORM_ANDROID)
4980 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4981 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4983 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4985 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4986 { TYPE_EMPTY, NULL, "" },
4987 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4988 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4993 static struct TokenInfo setup_info_game[] =
4995 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4996 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4997 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4998 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4999 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5000 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5001 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5002 { TYPE_STRING, &game_speed_text, "" },
5004 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5005 { TYPE_STRING, &scroll_delay_text, "" },
5007 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5008 { TYPE_STRING, &snapshot_mode_text, "" },
5009 { TYPE_EMPTY, NULL, "" },
5010 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5015 static struct TokenInfo setup_info_editor[] =
5018 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5019 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5020 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5021 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5022 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5023 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5024 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5025 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5027 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5028 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5029 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5031 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5033 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5034 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5035 { TYPE_EMPTY, NULL, "" },
5037 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5038 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5039 { TYPE_EMPTY, NULL, "" },
5041 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5042 { TYPE_EMPTY, NULL, "" },
5043 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5048 static struct TokenInfo setup_info_graphics[] =
5050 #if !defined(PLATFORM_ANDROID)
5051 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5052 #if defined(TARGET_SDL2)
5053 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5054 { TYPE_STRING, &window_size_text, "" },
5055 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5056 { TYPE_STRING, &scaling_type_text, "" },
5058 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5059 { TYPE_STRING, &screen_mode_text, "" },
5063 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5064 { TYPE_STRING, &scroll_delay_text, "" },
5066 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5067 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5068 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5069 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5070 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5071 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5072 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5073 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5074 { TYPE_EMPTY, NULL, "" },
5075 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5080 static struct TokenInfo setup_info_sound[] =
5082 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5083 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5084 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5085 { TYPE_EMPTY, NULL, "" },
5086 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5087 { TYPE_STRING, &volume_simple_text, "" },
5088 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5089 { TYPE_STRING, &volume_loops_text, "" },
5090 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5091 { TYPE_STRING, &volume_music_text, "" },
5092 { TYPE_EMPTY, NULL, "" },
5093 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5098 static struct TokenInfo setup_info_artwork[] =
5100 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5101 { TYPE_STRING, &graphics_set_name, "" },
5102 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5103 { TYPE_STRING, &sounds_set_name, "" },
5104 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5105 { TYPE_STRING, &music_set_name, "" },
5106 { TYPE_EMPTY, NULL, "" },
5107 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5108 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5109 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5110 { TYPE_EMPTY, NULL, "" },
5111 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5116 static struct TokenInfo setup_info_input[] =
5118 { TYPE_SWITCH, NULL, "Player:" },
5119 { TYPE_SWITCH, NULL, "Device:" },
5120 { TYPE_ENTER_MENU, NULL, "" },
5121 { TYPE_EMPTY, NULL, "" },
5122 { TYPE_EMPTY, NULL, "" },
5123 { TYPE_EMPTY, NULL, "" },
5124 { TYPE_EMPTY, NULL, "" },
5125 { TYPE_EMPTY, NULL, "" },
5126 { TYPE_EMPTY, NULL, "" },
5127 { TYPE_EMPTY, NULL, "" },
5128 { TYPE_EMPTY, NULL, "" },
5129 { TYPE_EMPTY, NULL, "" },
5130 { TYPE_EMPTY, NULL, "" },
5131 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5136 static struct TokenInfo setup_info_touch[] =
5138 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5139 { TYPE_STRING, &touch_controls_text, "" },
5140 { TYPE_EMPTY, NULL, "" },
5141 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5142 { TYPE_STRING, &move_distance_text, "" },
5143 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5144 { TYPE_STRING, &drop_distance_text, "" },
5145 { TYPE_EMPTY, NULL, "" },
5146 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5151 static struct TokenInfo setup_info_shortcuts[] =
5153 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5154 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5155 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5156 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5157 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5158 { TYPE_EMPTY, NULL, "" },
5159 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5164 static struct TokenInfo setup_info_shortcuts_1[] =
5166 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5167 { TYPE_KEY, &setup.shortcut.save_game, "" },
5168 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5169 { TYPE_KEY, &setup.shortcut.load_game, "" },
5170 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5171 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5172 { TYPE_EMPTY, NULL, "" },
5173 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5174 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5175 { TYPE_EMPTY, NULL, "" },
5176 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5181 static struct TokenInfo setup_info_shortcuts_2[] =
5183 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5184 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5185 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5186 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5187 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5188 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5189 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5190 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5191 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5192 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5193 { TYPE_EMPTY, NULL, "" },
5194 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5199 static struct TokenInfo setup_info_shortcuts_3[] =
5201 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5202 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5203 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5204 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5205 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5206 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5207 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5208 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5209 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5210 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5211 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5212 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5213 { TYPE_EMPTY, NULL, "" },
5214 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5219 static struct TokenInfo setup_info_shortcuts_4[] =
5221 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5222 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5223 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5224 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5225 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5226 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5227 { TYPE_EMPTY, NULL, "" },
5228 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5233 static struct TokenInfo setup_info_shortcuts_5[] =
5235 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5236 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5237 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5238 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5239 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5240 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5241 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5242 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5243 { TYPE_EMPTY, NULL, "" },
5244 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5249 static Key getSetupKey()
5251 Key key = KSYM_UNDEFINED;
5252 boolean got_key_event = FALSE;
5254 while (!got_key_event)
5256 if (PendingEvent()) /* got event */
5264 case EVENT_KEYPRESS:
5266 key = GetEventKey((KeyEvent *)&event, TRUE);
5268 /* press 'Escape' or 'Enter' to keep the existing key binding */
5269 if (key == KSYM_Escape || key == KSYM_Return)
5270 key = KSYM_UNDEFINED; /* keep old value */
5272 got_key_event = TRUE;
5276 case EVENT_KEYRELEASE:
5277 key_joystick_mapping = 0;
5281 HandleOtherEvents(&event);
5289 /* don't eat all CPU time */
5296 static int getSetupTextFont(int type)
5298 if (type & (TYPE_SWITCH |
5310 static int getSetupValueFont(int type, void *value)
5312 if (type & TYPE_KEY)
5313 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5314 else if (type & TYPE_STRING)
5315 return FONT_VALUE_2;
5316 else if (type & TYPE_ECS_AGA)
5317 return FONT_VALUE_1;
5318 else if (type & TYPE_BOOLEAN_STYLE)
5319 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5320 else if (type & TYPE_YES_NO_AUTO)
5321 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5322 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5324 return FONT_VALUE_1;
5327 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5329 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5330 struct TokenInfo *si = &setup_info[si_pos];
5331 boolean font_draw_xoffset_modified = FALSE;
5332 int font_draw_xoffset_old = -1;
5333 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5334 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5335 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5336 int xpos = menu_screen_value_xpos;
5337 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5338 int startx = mSX + xpos * 32;
5339 int starty = mSY + ypos * 32;
5340 int font_nr, font_width;
5341 int type = si->type;
5342 void *value = si->value;
5343 char *value_string = getSetupValue(type, value);
5346 if (value_string == NULL)
5349 if (type & TYPE_KEY)
5351 xpos = MENU_SCREEN_START_XPOS;
5353 if (type & TYPE_QUERY)
5354 value_string = "<press key>";
5356 else if (type & TYPE_STRING)
5358 int max_value_len = (SCR_FIELDX - 2) * 2;
5360 xpos = MENU_SCREEN_START_XPOS;
5362 if (strlen(value_string) > max_value_len)
5363 value_string[max_value_len] = '\0';
5365 else if (type & TYPE_YES_NO_AUTO)
5367 xpos = menu_screen_value_xpos - 1;
5370 startx = mSX + xpos * 32;
5371 starty = mSY + ypos * 32;
5372 font_nr = getSetupValueFont(type, value);
5373 font_width = getFontWidth(font_nr);
5375 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5376 if (setup_mode != SETUP_MODE_INPUT)
5378 int max_menu_text_length_big = (menu_screen_value_xpos -
5379 MENU_SCREEN_START_XPOS);
5380 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5381 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5382 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5383 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5384 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5385 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5386 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5387 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5388 boolean correct_font_draw_xoffset = FALSE;
5390 if (xpos == MENU_SCREEN_START_XPOS &&
5391 startx + font1_xoffset < text_startx + text_font_xoffset)
5392 correct_font_draw_xoffset = TRUE;
5394 if (xpos == menu_screen_value_xpos &&
5395 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5396 correct_font_draw_xoffset = TRUE;
5398 /* check if setup value would overlap with setup text when printed */
5399 /* (this can happen for extreme/wrong values for font draw offset) */
5400 if (correct_font_draw_xoffset)
5402 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5403 font_draw_xoffset_modified = TRUE;
5405 if (type & TYPE_KEY)
5406 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5407 else if (!(type & TYPE_STRING))
5408 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5409 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5413 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5414 DrawText(startx + i * font_width, starty, " ", font_nr);
5416 DrawText(startx, starty, value_string, font_nr);
5418 if (font_draw_xoffset_modified)
5419 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5422 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5424 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5425 struct TokenInfo *si = &setup_info[si_pos];
5427 if (si->type & TYPE_BOOLEAN_STYLE)
5429 *(boolean *)si->value ^= TRUE;
5431 else if (si->type & TYPE_YES_NO_AUTO)
5435 (*(int *)si->value == AUTO ? TRUE :
5436 *(int *)si->value == TRUE ? FALSE : AUTO) :
5437 (*(int *)si->value == TRUE ? AUTO :
5438 *(int *)si->value == AUTO ? FALSE : TRUE));
5440 else if (si->type & TYPE_KEY)
5444 si->type |= TYPE_QUERY;
5445 drawSetupValue(screen_pos, setup_info_pos_raw);
5446 si->type &= ~TYPE_QUERY;
5448 key = getSetupKey();
5449 if (key != KSYM_UNDEFINED)
5450 *(Key *)si->value = key;
5453 drawSetupValue(screen_pos, setup_info_pos_raw);
5455 // fullscreen state may have changed at this point
5456 if (si->value == &setup.fullscreen)
5457 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5460 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5463 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5464 struct TokenInfo *si = &setup_info[si_pos];
5465 int xpos = MENU_SCREEN_START_XPOS;
5466 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5467 int font_nr = getSetupTextFont(si->type);
5469 if (setup_info == setup_info_input)
5470 font_nr = FONT_MENU_1;
5473 font_nr = FONT_ACTIVE(font_nr);
5475 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5477 if (si->type & ~TYPE_SKIP_ENTRY)
5478 drawCursor(screen_pos, active);
5481 static void drawSetupInfoList(struct TokenInfo *setup_info,
5482 int first_entry, int num_page_entries)
5486 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5487 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5489 if (num_page_entries > max_setup_info)
5490 num_page_entries = max_setup_info;
5492 if (first_entry + num_page_entries > max_setup_info)
5495 clearMenuListArea();
5497 for (i = 0; i < num_page_entries; i++)
5499 int setup_info_pos = first_entry + i;
5500 struct TokenInfo *si = &setup_info[setup_info_pos];
5501 void *value_ptr = si->value;
5503 /* set some entries to "unchangeable" according to other variables */
5504 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5505 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5506 (value_ptr == &setup.sound_music && !audio.music_available) ||
5507 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5508 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5509 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5510 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5511 si->type |= TYPE_GHOSTED;
5513 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5514 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5515 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5516 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5517 else if (si->type & ~TYPE_SKIP_ENTRY)
5518 initCursor(i, IMG_MENU_BUTTON);
5520 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5522 if (si->type & TYPE_VALUE)
5523 drawSetupValue(i, setup_info_pos);
5527 static void DrawSetupScreen_Generic()
5529 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5530 boolean redraw_all = FALSE;
5531 char *title_string = NULL;
5536 FreeScreenGadgets();
5537 CreateScreenGadgets();
5539 CloseDoor(DOOR_CLOSE_2);
5541 if (redraw_mask & REDRAW_ALL)
5548 if (setup_mode == SETUP_MODE_MAIN)
5550 setup_info = setup_info_main;
5551 title_string = "Setup";
5553 else if (setup_mode == SETUP_MODE_GAME)
5555 setup_info = setup_info_game;
5556 title_string = "Setup Game";
5558 else if (setup_mode == SETUP_MODE_EDITOR)
5560 setup_info = setup_info_editor;
5561 title_string = "Setup Editor";
5563 else if (setup_mode == SETUP_MODE_GRAPHICS)
5565 setup_info = setup_info_graphics;
5566 title_string = "Setup Graphics";
5568 else if (setup_mode == SETUP_MODE_SOUND)
5570 setup_info = setup_info_sound;
5571 title_string = "Setup Sound";
5573 else if (setup_mode == SETUP_MODE_ARTWORK)
5575 setup_info = setup_info_artwork;
5576 title_string = "Custom Artwork";
5578 else if (setup_mode == SETUP_MODE_TOUCH)
5580 setup_info = setup_info_touch;
5581 title_string = "Setup Touch Ctrls";
5583 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5585 setup_info = setup_info_shortcuts;
5586 title_string = "Setup Shortcuts";
5588 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5590 setup_info = setup_info_shortcuts_1;
5591 title_string = "Setup Shortcuts";
5593 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5595 setup_info = setup_info_shortcuts_2;
5596 title_string = "Setup Shortcuts";
5598 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5600 setup_info = setup_info_shortcuts_3;
5601 title_string = "Setup Shortcuts";
5603 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5605 setup_info = setup_info_shortcuts_4;
5606 title_string = "Setup Shortcuts";
5608 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5610 setup_info = setup_info_shortcuts_5;
5611 title_string = "Setup Shortcuts";
5614 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5616 // determine maximal number of setup entries that can be displayed on screen
5618 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5621 // determine maximal number of setup entries available for this setup screen
5623 for (i = 0; setup_info[i].type != 0; i++)
5626 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5628 MapScreenGadgets(max_setup_info);
5631 redraw_mask = fade_mask = REDRAW_ALL;
5638 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5640 static int choice_store[MAX_SETUP_MODES];
5641 static int first_entry_store[MAX_SETUP_MODES];
5642 int choice = choice_store[setup_mode]; /* starts with 0 */
5643 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5645 int y = choice - first_entry;
5647 boolean position_set_by_scrollbar = (dx == 999);
5648 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5649 int num_page_entries;
5651 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5653 if (button == MB_MENU_INITIALIZE)
5655 /* advance to first valid menu entry */
5656 while (choice < num_setup_info &&
5657 setup_info[choice].type & TYPE_SKIP_ENTRY)
5660 if (position_set_by_scrollbar)
5661 first_entry = first_entry_store[setup_mode] = dy;
5663 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5664 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5666 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5668 if (choice < first_entry)
5670 choice = first_entry;
5672 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5675 else if (choice > first_entry + num_page_entries - 1)
5677 choice = first_entry + num_page_entries - 1;
5679 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5683 choice_store[setup_mode] = choice;
5685 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5689 else if (button == MB_MENU_LEAVE)
5693 PlaySound(SND_MENU_ITEM_SELECTING);
5695 for (i = 0; setup_info[i].type != 0; i++)
5697 if (setup_info[i].type & TYPE_LEAVE_MENU)
5699 void (*menu_callback_function)(void) = setup_info[i].value;
5703 menu_callback_function();
5705 break; /* absolutely needed because function changes 'setup_info'! */
5712 if (mx || my) /* mouse input */
5714 x = (mx - mSX) / 32;
5715 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5717 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5719 /* move cursor instead of scrolling when already at start/end of list */
5720 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5722 else if (dy == +1 * SCROLL_LINE &&
5723 first_entry + num_page_entries == max_setup_info)
5726 /* handle scrolling screen one line or page */
5728 y + dy > num_page_entries - 1)
5730 boolean redraw = FALSE;
5732 if (ABS(dy) == SCROLL_PAGE)
5733 step = num_page_entries - 1;
5735 if (dy < 0 && first_entry > 0)
5737 /* scroll page/line up */
5739 first_entry -= step;
5740 if (first_entry < 0)
5745 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5747 /* scroll page/line down */
5749 first_entry += step;
5750 if (first_entry + num_page_entries > max_setup_info)
5751 first_entry = MAX(0, max_setup_info - num_page_entries);
5758 choice += first_entry - first_entry_store[setup_mode];
5760 if (choice < first_entry)
5762 choice = first_entry;
5764 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5767 else if (choice > first_entry + num_page_entries - 1)
5769 choice = first_entry + num_page_entries - 1;
5771 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5774 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5778 if (choice < first_entry ||
5779 choice > first_entry + num_page_entries - 1)
5780 first_entry += SIGN(dy);
5783 first_entry_store[setup_mode] = first_entry;
5784 choice_store[setup_mode] = choice;
5786 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5788 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5790 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5791 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5799 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5801 if (setup_info[choice].type & menu_navigation_type ||
5802 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5803 setup_info[choice].type & TYPE_YES_NO_AUTO)
5804 button = MB_MENU_CHOICE;
5809 /* jump to next non-empty menu entry (up or down) */
5810 while (first_entry + y > 0 &&
5811 first_entry + y < max_setup_info - 1 &&
5812 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
5815 if (!IN_VIS_MENU(x, y))
5817 choice += y - y_old;
5819 if (choice < first_entry)
5820 first_entry = choice;
5821 else if (choice > first_entry + num_page_entries - 1)
5822 first_entry = choice - num_page_entries + 1;
5824 if (first_entry >= 0 &&
5825 first_entry + num_page_entries <= max_setup_info)
5827 first_entry_store[setup_mode] = first_entry;
5829 if (choice < first_entry)
5830 choice = first_entry;
5831 else if (choice > first_entry + num_page_entries - 1)
5832 choice = first_entry + num_page_entries - 1;
5834 choice_store[setup_mode] = choice;
5836 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5838 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5840 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5841 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5848 if (!anyScrollbarGadgetActive() &&
5849 IN_VIS_MENU(x, y) &&
5850 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
5851 y >= 0 && y < num_page_entries)
5855 if (first_entry + y != choice &&
5856 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
5858 PlaySound(SND_MENU_ITEM_ACTIVATING);
5860 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
5861 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
5863 choice = choice_store[setup_mode] = first_entry + y;
5866 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
5868 PlaySound(SND_MENU_ITEM_SELECTING);
5870 /* when selecting key headline, execute function for key value change */
5871 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
5872 setup_info[first_entry + y + 1].type & TYPE_KEY)
5875 /* when selecting string value, execute function for list selection */
5876 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
5877 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
5880 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
5882 void (*menu_callback_function)(void) =
5883 setup_info[first_entry + y].value;
5885 FadeSetFromType(setup_info[first_entry + y].type);
5887 menu_callback_function();
5891 if (setup_info[first_entry + y].type & TYPE_VALUE)
5892 changeSetupValue(y, first_entry + y, dx);
5898 void DrawSetupScreen_Input()
5902 FadeOut(REDRAW_FIELD);
5906 setup_info = setup_info_input;
5908 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5910 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5911 "Joysticks deactivated on this screen");
5913 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5915 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5916 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5917 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5918 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5919 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5920 initCursor(i, IMG_MENU_BUTTON);
5922 DrawCursorAndText_Setup(i, -1, FALSE);
5925 /* create gadgets for setup input menu screen */
5926 FreeScreenGadgets();
5927 CreateScreenGadgets();
5929 /* map gadgets for setup input menu screen */
5930 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5932 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5934 FadeIn(REDRAW_FIELD);
5939 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5941 if (device_name == NULL)
5944 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5947 if (strlen(device_name) > 1)
5949 char c1 = device_name[strlen(device_name) - 1];
5950 char c2 = device_name[strlen(device_name) - 2];
5952 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5953 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5956 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5957 strlen(device_name));
5960 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5963 static struct SetupKeyboardInfo custom_key;
5970 { &custom_key.left, "Joystick Left" },
5971 { &custom_key.right, "Joystick Right" },
5972 { &custom_key.up, "Joystick Up" },
5973 { &custom_key.down, "Joystick Down" },
5974 { &custom_key.snap, "Button 1" },
5975 { &custom_key.drop, "Button 2" }
5977 static char *joystick_name[MAX_PLAYERS] =
5984 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5988 custom_key = setup.input[player_nr].key;
5990 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5991 FONT_INPUT_1_ACTIVE);
5993 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5995 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5996 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5998 if (setup.input[player_nr].use_joystick)
6000 char *device_name = setup.input[player_nr].joy.device_name;
6001 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6002 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6004 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6005 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6009 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6010 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6013 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6015 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6016 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6017 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6018 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6020 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6021 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6022 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6023 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6024 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6025 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6027 for (i = 0; i < 6; i++)
6029 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6031 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6033 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6034 (setup.input[player_nr].use_joystick ?
6036 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6040 static int input_player_nr = 0;
6042 void HandleSetupScreen_Input_Player(int step, int direction)
6044 int old_player_nr = input_player_nr;
6047 new_player_nr = old_player_nr + step * direction;
6048 if (new_player_nr < 0)
6050 if (new_player_nr > MAX_PLAYERS - 1)
6051 new_player_nr = MAX_PLAYERS - 1;
6053 if (new_player_nr != old_player_nr)
6055 input_player_nr = new_player_nr;
6057 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6061 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6063 static int choice = 0;
6066 int pos_start = SETUPINPUT_SCREEN_POS_START;
6067 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6068 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6069 int pos_end = SETUPINPUT_SCREEN_POS_END;
6071 if (button == MB_MENU_INITIALIZE)
6073 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6075 DrawCursorAndText_Setup(choice, -1, TRUE);
6079 else if (button == MB_MENU_LEAVE)
6081 setup_mode = SETUP_MODE_MAIN;
6088 if (mx || my) /* mouse input */
6090 x = (mx - mSX) / 32;
6091 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6093 else if (dx || dy) /* keyboard input */
6095 if (dx && choice == 0)
6096 x = (dx < 0 ? 10 : 12);
6097 else if ((dx && choice == 1) ||
6098 (dx == +1 && choice == 2) ||
6099 (dx == -1 && choice == pos_end))
6100 button = MB_MENU_CHOICE;
6104 if (y >= pos_empty1 && y <= pos_empty2)
6105 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6108 if (y == 0 && dx != 0 && button)
6110 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6112 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6113 y >= pos_start && y <= pos_end &&
6114 !(y >= pos_empty1 && y <= pos_empty2))
6120 DrawCursorAndText_Setup(choice, -1, FALSE);
6121 DrawCursorAndText_Setup(y, -1, TRUE);
6123 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6132 char *device_name = setup.input[input_player_nr].joy.device_name;
6134 if (!setup.input[input_player_nr].use_joystick)
6136 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6138 setJoystickDeviceToNr(device_name, new_device_nr);
6139 setup.input[input_player_nr].use_joystick = TRUE;
6143 int device_nr = getJoystickNrFromDeviceName(device_name);
6144 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6146 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6147 setup.input[input_player_nr].use_joystick = FALSE;
6149 setJoystickDeviceToNr(device_name, new_device_nr);
6152 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6156 if (setup.input[input_player_nr].use_joystick)
6159 CalibrateJoystick(input_player_nr);
6162 CustomizeKeyboard(input_player_nr);
6164 else if (y == pos_end)
6170 setup_mode = SETUP_MODE_MAIN;
6177 void CustomizeKeyboard(int player_nr)
6181 boolean finished = FALSE;
6182 static struct SetupKeyboardInfo custom_key;
6187 } customize_step[] =
6189 { &custom_key.left, "Move Left" },
6190 { &custom_key.right, "Move Right" },
6191 { &custom_key.up, "Move Up" },
6192 { &custom_key.down, "Move Down" },
6193 { &custom_key.snap, "Snap Field" },
6194 { &custom_key.drop, "Drop Element" }
6197 /* read existing key bindings from player setup */
6198 custom_key = setup.input[player_nr].key;
6201 FadeOut(REDRAW_FIELD);
6205 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6208 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6209 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6210 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6211 "Key:", FONT_INPUT_1_ACTIVE);
6212 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6213 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6215 FadeIn(REDRAW_FIELD);
6221 if (PendingEvent()) /* got event */
6229 case EVENT_KEYPRESS:
6231 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6233 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6235 if (key == KSYM_Escape)
6236 FadeSkipNextFadeIn();
6242 /* all keys configured -- wait for "Escape" or "Return" key */
6246 /* press 'Enter' to keep the existing key binding */
6247 if (key == KSYM_Return)
6248 key = *customize_step[step_nr].key;
6250 /* check if key already used */
6251 for (i = 0; i < step_nr; i++)
6252 if (*customize_step[i].key == key)
6257 /* got new key binding */
6258 *customize_step[step_nr].key = key;
6259 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6261 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6262 getKeyNameFromKey(key), FONT_VALUE_1);
6265 /* un-highlight last query */
6266 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6267 customize_step[step_nr - 1].text, FONT_MENU_1);
6268 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6269 "Key:", FONT_MENU_1);
6271 /* press 'Enter' to leave */
6274 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6275 "Press Enter", FONT_TITLE_1);
6279 /* query next key binding */
6280 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6281 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6282 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6283 "Key:", FONT_INPUT_1_ACTIVE);
6284 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6285 getKeyNameFromKey(*customize_step[step_nr].key),
6290 case EVENT_KEYRELEASE:
6291 key_joystick_mapping = 0;
6295 HandleOtherEvents(&event);
6303 /* don't eat all CPU time */
6307 /* write new key bindings back to player setup */
6308 setup.input[player_nr].key = custom_key;
6311 DrawSetupScreen_Input();
6314 static boolean CalibrateJoystickMain(int player_nr)
6316 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6317 int new_joystick_xright = JOYSTICK_XMIDDLE;
6318 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6319 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6320 int new_joystick_xmiddle, new_joystick_ymiddle;
6322 int joystick_fd = joystick.fd[player_nr];
6323 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6324 boolean check[3][3];
6325 int check_remaining = 3 * 3;
6330 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6333 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6337 FadeOut(REDRAW_FIELD);
6341 for (y = 0; y < 3; y++)
6343 for (x = 0; x < 3; x++)
6345 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6346 check[x][y] = FALSE;
6350 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6351 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6352 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6353 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6354 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6355 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6356 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6358 joy_value = Joystick(player_nr);
6359 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6360 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6362 /* eventually uncalibrated center position (joystick could be uncentered) */
6363 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6366 new_joystick_xmiddle = joy_x;
6367 new_joystick_ymiddle = joy_y;
6369 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6371 FadeIn(REDRAW_FIELD);
6373 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6378 if (PendingEvent()) /* got event */
6386 case EVENT_KEYPRESS:
6387 switch (GetEventKey((KeyEvent *)&event, TRUE))
6390 if (check_remaining == 0)
6395 FadeSkipNextFadeIn();
6404 case EVENT_KEYRELEASE:
6405 key_joystick_mapping = 0;
6409 HandleOtherEvents(&event);
6414 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6417 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6418 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6419 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6420 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6422 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6423 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6424 setup.input[player_nr].joy.xright = new_joystick_xright;
6425 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6426 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6427 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6429 CheckJoystickData();
6431 joy_value = Joystick(player_nr);
6433 if (joy_value & JOY_BUTTON && check_remaining == 0)
6436 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6437 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6439 if (x != last_x || y != last_y)
6441 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6442 IMG_MENU_CALIBRATE_YELLOW, 0);
6443 DrawFixedGraphic(xpos + x, ypos + y,
6444 IMG_MENU_CALIBRATE_RED, 0);
6449 if (check_remaining > 0 && !check[x+1][y+1])
6451 check[x+1][y+1] = TRUE;
6459 /* don't eat all CPU time */
6463 /* calibrated center position (joystick should now be centered) */
6464 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6467 new_joystick_xmiddle = joy_x;
6468 new_joystick_ymiddle = joy_y;
6472 /* wait until the last pressed button was released */
6473 while (Joystick(player_nr) & JOY_BUTTON)
6475 if (PendingEvent()) /* got event */
6480 HandleOtherEvents(&event);
6489 void CalibrateJoystick(int player_nr)
6491 if (!CalibrateJoystickMain(player_nr))
6493 char *device_name = setup.input[player_nr].joy.device_name;
6494 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6495 int xpos = mSX - SX;
6496 int ypos = mSY - SY;
6500 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6501 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6504 Delay(2000); /* show error message for a short time */
6509 DrawSetupScreen_Input();
6512 void DrawSetupScreen()
6514 DeactivateJoystick();
6516 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6518 if (setup_mode == SETUP_MODE_INPUT)
6519 DrawSetupScreen_Input();
6520 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6521 DrawChooseTree(&game_speed_current);
6522 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6523 DrawChooseTree(&scroll_delay_current);
6524 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6525 DrawChooseTree(&snapshot_mode_current);
6526 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6527 DrawChooseTree(&screen_mode_current);
6528 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6529 DrawChooseTree(&window_size_current);
6530 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6531 DrawChooseTree(&scaling_type_current);
6532 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6533 DrawChooseTree(&artwork.gfx_current);
6534 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6535 DrawChooseTree(&artwork.snd_current);
6536 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6537 DrawChooseTree(&artwork.mus_current);
6538 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6539 DrawChooseTree(&volume_simple_current);
6540 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6541 DrawChooseTree(&volume_loops_current);
6542 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6543 DrawChooseTree(&volume_music_current);
6544 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6545 DrawChooseTree(&touch_control_current);
6546 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6547 DrawChooseTree(&move_distance_current);
6548 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6549 DrawChooseTree(&drop_distance_current);
6551 DrawSetupScreen_Generic();
6557 void RedrawSetupScreenAfterFullscreenToggle()
6559 if (setup_mode == SETUP_MODE_GRAPHICS ||
6560 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6562 // update list selection from "setup.window_scaling_percent"
6563 execSetupGraphics_setWindowSizes(TRUE);
6569 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6571 if (setup_mode == SETUP_MODE_INPUT)
6572 HandleSetupScreen_Input(mx, my, dx, dy, button);
6573 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6574 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6575 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6576 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6577 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6578 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6579 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6580 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6581 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6582 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6583 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6584 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6585 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6586 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6587 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6588 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6589 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6590 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6591 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6592 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6593 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6594 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6595 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6596 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6597 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6598 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6599 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6600 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6601 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6602 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6604 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6607 void HandleGameActions()
6609 if (game_status != GAME_MODE_PLAYING)
6612 GameActions(); /* main game loop */
6614 if (tape.auto_play && !tape.playing)
6615 AutoPlayTape(); /* continue automatically playing next tape */
6619 /* ---------- new screen button stuff -------------------------------------- */
6621 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6625 case SCREEN_CTRL_ID_PREV_LEVEL:
6626 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6627 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6630 case SCREEN_CTRL_ID_NEXT_LEVEL:
6631 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6632 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6635 case SCREEN_CTRL_ID_PREV_PLAYER:
6636 *x = mSX + TILEX * 10;
6637 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6640 case SCREEN_CTRL_ID_NEXT_PLAYER:
6641 *x = mSX + TILEX * 12;
6642 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6646 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6652 int gfx_unpressed, gfx_pressed;
6653 void (*get_gadget_position)(int *, int *, int);
6657 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6660 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6661 getScreenMenuButtonPos,
6662 SCREEN_CTRL_ID_PREV_LEVEL,
6667 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6668 getScreenMenuButtonPos,
6669 SCREEN_CTRL_ID_NEXT_LEVEL,
6674 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6675 getScreenMenuButtonPos,
6676 SCREEN_CTRL_ID_PREV_PLAYER,
6681 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6682 getScreenMenuButtonPos,
6683 SCREEN_CTRL_ID_NEXT_PLAYER,
6691 int gfx_unpressed, gfx_pressed;
6695 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6698 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6699 -1, -1, /* these values are not constant, but can change at runtime */
6700 SCREEN_CTRL_ID_SCROLL_UP,
6704 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6705 -1, -1, /* these values are not constant, but can change at runtime */
6706 SCREEN_CTRL_ID_SCROLL_DOWN,
6713 int gfx_unpressed, gfx_pressed;
6719 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6722 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6723 -1, -1, /* these values are not constant, but can change at runtime */
6724 -1, -1, /* these values are not constant, but can change at runtime */
6725 GD_TYPE_SCROLLBAR_VERTICAL,
6726 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6727 "scroll level series vertically"
6731 static void CreateScreenMenubuttons()
6733 struct GadgetInfo *gi;
6734 unsigned int event_mask;
6737 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6739 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6740 int gfx_unpressed, gfx_pressed;
6741 int x, y, width, height;
6742 int gd_x1, gd_x2, gd_y1, gd_y2;
6743 int id = menubutton_info[i].gadget_id;
6745 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6747 menubutton_info[i].get_gadget_position(&x, &y, id);
6749 width = SC_MENUBUTTON_XSIZE;
6750 height = SC_MENUBUTTON_YSIZE;
6752 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6753 gfx_pressed = menubutton_info[i].gfx_pressed;
6754 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6755 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6756 gd_x1 = graphic_info[gfx_unpressed].src_x;
6757 gd_y1 = graphic_info[gfx_unpressed].src_y;
6758 gd_x2 = graphic_info[gfx_pressed].src_x;
6759 gd_y2 = graphic_info[gfx_pressed].src_y;
6761 gi = CreateGadget(GDI_CUSTOM_ID, id,
6762 GDI_CUSTOM_TYPE_ID, i,
6763 GDI_INFO_TEXT, menubutton_info[i].infotext,
6768 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6769 GDI_STATE, GD_BUTTON_UNPRESSED,
6770 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6771 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6772 GDI_DIRECT_DRAW, FALSE,
6773 GDI_EVENT_MASK, event_mask,
6774 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6778 Error(ERR_EXIT, "cannot create gadget");
6780 screen_gadget[id] = gi;
6784 static void CreateScreenScrollbuttons()
6786 struct GadgetInfo *gi;
6787 unsigned int event_mask;
6790 /* these values are not constant, but can change at runtime */
6791 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6792 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6793 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6794 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6796 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6798 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6799 int gfx_unpressed, gfx_pressed;
6800 int x, y, width, height;
6801 int gd_x1, gd_x2, gd_y1, gd_y2;
6802 int id = scrollbutton_info[i].gadget_id;
6804 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6806 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6807 y = mSY + scrollbutton_info[i].y;
6808 width = SC_SCROLLBUTTON_XSIZE;
6809 height = SC_SCROLLBUTTON_YSIZE;
6811 /* correct scrollbar position if placed outside menu (playfield) area */
6812 if (x > SX + SC_SCROLL_UP_XPOS)
6813 x = SX + SC_SCROLL_UP_XPOS;
6815 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6816 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6817 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6819 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6820 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6821 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6822 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6823 gd_x1 = graphic_info[gfx_unpressed].src_x;
6824 gd_y1 = graphic_info[gfx_unpressed].src_y;
6825 gd_x2 = graphic_info[gfx_pressed].src_x;
6826 gd_y2 = graphic_info[gfx_pressed].src_y;
6828 gi = CreateGadget(GDI_CUSTOM_ID, id,
6829 GDI_CUSTOM_TYPE_ID, i,
6830 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6835 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6836 GDI_STATE, GD_BUTTON_UNPRESSED,
6837 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6838 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6839 GDI_DIRECT_DRAW, FALSE,
6840 GDI_EVENT_MASK, event_mask,
6841 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6845 Error(ERR_EXIT, "cannot create gadget");
6847 screen_gadget[id] = gi;
6851 static void CreateScreenScrollbars()
6855 /* these values are not constant, but can change at runtime */
6856 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6857 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6858 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6859 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6861 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6863 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6864 int gfx_unpressed, gfx_pressed;
6865 int x, y, width, height;
6866 int gd_x1, gd_x2, gd_y1, gd_y2;
6867 struct GadgetInfo *gi;
6868 int items_max, items_visible, item_position;
6869 unsigned int event_mask;
6870 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6871 int id = scrollbar_info[i].gadget_id;
6873 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6875 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6876 y = mSY + scrollbar_info[i].y;
6877 width = scrollbar_info[i].width;
6878 height = scrollbar_info[i].height;
6880 /* correct scrollbar position if placed outside menu (playfield) area */
6881 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6882 x = SX + SC_SCROLL_VERTICAL_XPOS;
6884 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6885 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6887 items_max = num_page_entries;
6888 items_visible = num_page_entries;
6891 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6892 gfx_pressed = scrollbar_info[i].gfx_pressed;
6893 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6894 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6895 gd_x1 = graphic_info[gfx_unpressed].src_x;
6896 gd_y1 = graphic_info[gfx_unpressed].src_y;
6897 gd_x2 = graphic_info[gfx_pressed].src_x;
6898 gd_y2 = graphic_info[gfx_pressed].src_y;
6900 gi = CreateGadget(GDI_CUSTOM_ID, id,
6901 GDI_CUSTOM_TYPE_ID, i,
6902 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6907 GDI_TYPE, scrollbar_info[i].type,
6908 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6909 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6910 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6911 GDI_WHEEL_AREA_X, SX,
6912 GDI_WHEEL_AREA_Y, SY,
6913 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6914 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6915 GDI_STATE, GD_BUTTON_UNPRESSED,
6916 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6917 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6918 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6919 GDI_DIRECT_DRAW, FALSE,
6920 GDI_EVENT_MASK, event_mask,
6921 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6925 Error(ERR_EXIT, "cannot create gadget");
6927 screen_gadget[id] = gi;
6931 void CreateScreenGadgets()
6933 int last_game_status = game_status; /* save current game status */
6935 CreateScreenMenubuttons();
6937 CreateScreenScrollbuttons();
6938 CreateScreenScrollbars();
6940 game_status = last_game_status; /* restore current game status */
6943 void FreeScreenGadgets()
6947 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6948 FreeGadget(screen_gadget[i]);
6951 void MapScreenMenuGadgets(int screen_mask)
6955 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6956 if (screen_mask & menubutton_info[i].screen_mask)
6957 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6960 void MapScreenGadgets(int num_entries)
6964 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6967 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6968 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6970 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6971 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6974 void MapScreenTreeGadgets(TreeInfo *ti)
6976 MapScreenGadgets(numTreeInfoInGroup(ti));
6979 static void HandleScreenGadgets(struct GadgetInfo *gi)
6981 int id = gi->custom_id;
6982 int button = gi->event.button;
6983 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6987 case SCREEN_CTRL_ID_PREV_LEVEL:
6988 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6991 case SCREEN_CTRL_ID_NEXT_LEVEL:
6992 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6995 case SCREEN_CTRL_ID_PREV_PLAYER:
6996 HandleSetupScreen_Input_Player(step, -1);
6999 case SCREEN_CTRL_ID_NEXT_PLAYER:
7000 HandleSetupScreen_Input_Player(step, +1);
7003 case SCREEN_CTRL_ID_SCROLL_UP:
7004 if (game_status == GAME_MODE_LEVELS)
7005 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7006 else if (game_status == GAME_MODE_LEVELNR)
7007 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7008 else if (game_status == GAME_MODE_SETUP)
7009 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7012 case SCREEN_CTRL_ID_SCROLL_DOWN:
7013 if (game_status == GAME_MODE_LEVELS)
7014 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7015 else if (game_status == GAME_MODE_LEVELNR)
7016 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7017 else if (game_status == GAME_MODE_SETUP)
7018 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7021 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7022 if (game_status == GAME_MODE_LEVELS)
7023 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7024 else if (game_status == GAME_MODE_LEVELNR)
7025 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7026 else if (game_status == GAME_MODE_SETUP)
7027 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);