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;
508 struct MainControlInfo
512 struct MenuPosInfo *pos_button;
515 struct TextPosInfo *pos_text;
518 struct TextPosInfo *pos_input;
522 static struct MainControlInfo main_controls[] =
526 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
527 &menu.main.text.name, &main_text_name,
528 &menu.main.input.name, &setup.player_name,
532 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
533 &menu.main.text.levels, &main_text_levels,
538 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
539 &menu.main.text.scores, &main_text_scores,
544 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
545 &menu.main.text.editor, &main_text_editor,
550 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
551 &menu.main.text.info, &main_text_info,
556 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
557 &menu.main.text.game, &main_text_game,
562 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
563 &menu.main.text.setup, &main_text_setup,
568 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
569 &menu.main.text.quit, &main_text_quit,
573 /* (these two buttons are real gadgets) */
575 MAIN_CONTROL_PREV_LEVEL,
576 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
581 MAIN_CONTROL_NEXT_LEVEL,
582 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
588 MAIN_CONTROL_FIRST_LEVEL,
590 &menu.main.text.first_level, &main_text_first_level,
594 MAIN_CONTROL_LAST_LEVEL,
596 &menu.main.text.last_level, &main_text_last_level,
600 MAIN_CONTROL_LEVEL_NUMBER,
602 &menu.main.text.level_number, &main_text_level_number,
606 MAIN_CONTROL_LEVEL_INFO_1,
608 &menu.main.text.level_info_1, NULL,
612 MAIN_CONTROL_LEVEL_INFO_2,
614 &menu.main.text.level_info_2, NULL,
618 MAIN_CONTROL_LEVEL_NAME,
620 &menu.main.text.level_name, &main_text_level_name,
624 MAIN_CONTROL_LEVEL_AUTHOR,
626 &menu.main.text.level_author, &main_text_level_author,
630 MAIN_CONTROL_LEVEL_YEAR,
632 &menu.main.text.level_year, &main_text_level_year,
636 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
638 &menu.main.text.level_imported_from, &main_text_level_imported_from,
642 MAIN_CONTROL_LEVEL_IMPORTED_BY,
644 &menu.main.text.level_imported_by, &main_text_level_imported_by,
648 MAIN_CONTROL_LEVEL_TESTED_BY,
650 &menu.main.text.level_tested_by, &main_text_level_tested_by,
654 MAIN_CONTROL_TITLE_1,
656 &menu.main.text.title_1, &setup.internal.program_title,
660 MAIN_CONTROL_TITLE_2,
662 &menu.main.text.title_2, &setup.internal.program_copyright,
666 MAIN_CONTROL_TITLE_3,
668 &menu.main.text.title_3, &setup.internal.program_company,
681 static int getTitleScreenGraphic(int nr, boolean initial)
683 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
686 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
688 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
692 static int getTitleScreenGameMode(boolean initial)
694 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
698 static int getTitleMessageGameMode(boolean initial)
700 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
704 static int getTitleScreenBackground(boolean initial)
706 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
711 static int getTitleMessageBackground(int nr, boolean initial)
713 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
717 static int getTitleBackground(int nr, boolean initial, boolean is_image)
719 int base = (is_image ?
720 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
721 IMG_BACKGROUND_TITLESCREEN_1) :
722 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
723 IMG_BACKGROUND_TITLEMESSAGE_1));
724 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
725 IMG_BACKGROUND_TITLE);
726 int graphic_local = base + nr;
728 if (graphic_info[graphic_local].bitmap != NULL)
729 return graphic_local;
731 if (graphic_info[graphic_global].bitmap != NULL)
732 return graphic_global;
734 return IMG_UNDEFINED;
737 static int getTitleSound(struct TitleControlInfo *tci)
739 boolean is_image = tci->is_image;
740 int initial = tci->initial;
741 int nr = tci->local_nr;
742 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
743 int base = (is_image ?
744 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
745 SND_BACKGROUND_TITLESCREEN_1) :
746 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
747 SND_BACKGROUND_TITLEMESSAGE_1));
748 int sound_global = menu.sound[mode];
749 int sound_local = base + nr;
752 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
753 nr, initial, is_image,
754 sound_global, getSoundListEntry(sound_global)->filename,
755 sound_local, getSoundListEntry(sound_local)->filename);
758 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
761 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
764 return SND_UNDEFINED;
767 static int getTitleMusic(struct TitleControlInfo *tci)
769 boolean is_image = tci->is_image;
770 int initial = tci->initial;
771 int nr = tci->local_nr;
772 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
773 int base = (is_image ?
774 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
775 MUS_BACKGROUND_TITLESCREEN_1) :
776 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
777 MUS_BACKGROUND_TITLEMESSAGE_1));
778 int music_global = menu.music[mode];
779 int music_local = base + nr;
782 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
783 nr, initial, is_image,
784 music_global, getMusicListEntry(music_global)->filename,
785 music_local, getMusicListEntry(music_local)->filename);
788 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
791 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
794 return MUS_UNDEFINED;
797 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
799 boolean is_image = tci->is_image;
800 int initial = tci->initial;
801 int nr = tci->local_nr;
802 struct TitleFadingInfo ti;
806 int graphic = getTitleScreenGraphic(nr, initial);
808 /* initialize fading control values to default title config settings */
809 ti = (initial ? title_initial_default : title_default);
811 /* override default settings with image config settings, if defined */
812 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
813 ti.fade_mode = graphic_info[graphic].fade_mode;
814 if (graphic_info[graphic].fade_delay > -1)
815 ti.fade_delay = graphic_info[graphic].fade_delay;
816 if (graphic_info[graphic].post_delay > -1)
817 ti.post_delay = graphic_info[graphic].post_delay;
818 if (graphic_info[graphic].auto_delay > -1)
819 ti.auto_delay = graphic_info[graphic].auto_delay;
825 ti.fade_mode = titlemessage_initial[nr].fade_mode;
826 ti.fade_delay = titlemessage_initial[nr].fade_delay;
827 ti.post_delay = titlemessage_initial[nr].post_delay;
828 ti.auto_delay = titlemessage_initial[nr].auto_delay;
832 ti.fade_mode = titlemessage[nr].fade_mode;
833 ti.fade_delay = titlemessage[nr].fade_delay;
834 ti.post_delay = titlemessage[nr].post_delay;
835 ti.auto_delay = titlemessage[nr].auto_delay;
842 static int compareTitleControlInfo(const void *object1, const void *object2)
844 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
845 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
848 if (tci1->initial != tci2->initial)
849 compare_result = (tci1->initial ? -1 : +1);
850 else if (tci1->sort_priority != tci2->sort_priority)
851 compare_result = tci1->sort_priority - tci2->sort_priority;
852 else if (tci1->is_image != tci2->is_image)
853 compare_result = (tci1->is_image ? -1 : +1);
855 compare_result = tci1->local_nr - tci2->local_nr;
857 return compare_result;
860 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
862 int nr, int sort_priority)
864 title_controls[num_title_screens].is_image = is_image;
865 title_controls[num_title_screens].initial = initial;
866 title_controls[num_title_screens].local_nr = nr;
867 title_controls[num_title_screens].sort_priority = sort_priority;
872 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
876 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
878 int graphic = getTitleScreenGraphic(i, initial);
879 Bitmap *bitmap = graphic_info[graphic].bitmap;
880 int sort_priority = graphic_info[graphic].sort_priority;
883 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
886 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
888 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
889 char *filename = getLevelSetTitleMessageFilename(i, initial);
890 int sort_priority = tmi->sort_priority;
892 if (filename != NULL)
893 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
897 static void InitializeTitleControls(boolean show_title_initial)
899 num_title_screens = 0;
901 /* 1st step: initialize title screens for game start (only when starting) */
902 if (show_title_initial)
903 InitializeTitleControls_CheckTitleInfo(TRUE);
905 /* 2nd step: initialize title screens for current level set */
906 InitializeTitleControls_CheckTitleInfo(FALSE);
908 /* sort title screens according to sort_priority and title number */
909 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
910 compareTitleControlInfo);
913 static boolean visibleMenuPos(struct MenuPosInfo *pos)
915 return (pos != NULL && pos->x != -1 && pos->y != -1);
918 static boolean visibleTextPos(struct TextPosInfo *pos)
920 return (pos != NULL && pos->x != -1 && pos->y != -1);
923 static void InitializeMainControls()
925 boolean local_team_mode = (!options.network && setup.team_mode);
928 /* set main control text values to dynamically determined values */
929 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
931 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
932 menu.main.text.first_level.size));
933 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
934 menu.main.text.last_level.size));
935 strcpy(main_text_level_number, int2str(level_nr,
936 menu.main.text.level_number.size));
938 main_text_level_year = leveldir_current->year;
939 main_text_level_imported_from = leveldir_current->imported_from;
940 main_text_level_imported_by = leveldir_current->imported_by;
941 main_text_level_tested_by = leveldir_current->tested_by;
943 /* set main control screen positions to dynamically determined values */
944 for (i = 0; main_controls[i].nr != -1; i++)
946 struct MainControlInfo *mci = &main_controls[i];
948 struct MenuPosInfo *pos_button = mci->pos_button;
949 struct TextPosInfo *pos_text = mci->pos_text;
950 struct TextPosInfo *pos_input = mci->pos_input;
951 char *text = (mci->text ? *mci->text : NULL);
952 char *input = (mci->input ? *mci->input : NULL);
953 int button_graphic = mci->button_graphic;
954 int font_text = (pos_text ? pos_text->font : -1);
955 int font_input = (pos_input ? pos_input->font : -1);
957 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
958 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
959 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
960 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
961 int text_chars = (text != NULL ? strlen(text) : 0);
962 int input_chars = (input != NULL ? strlen(input) : 0);
965 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
967 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
968 int text_width = font_text_width * text_chars;
969 int text_height = font_text_height;
970 int input_width = font_input_width * input_chars;
971 int input_height = font_input_height;
973 if (nr == MAIN_CONTROL_NAME)
975 menu.main.input.name.width = input_width;
976 menu.main.input.name.height = input_height;
979 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
981 pos_button->width = button_width;
982 pos_button->height = button_height;
985 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
987 /* calculate size for non-clickable text -- needed for text alignment */
988 boolean calculate_text_size = (pos_button == NULL && text != NULL);
990 if (pos_text->width == -1 || calculate_text_size)
991 pos_text->width = text_width;
992 if (pos_text->height == -1 || calculate_text_size)
993 pos_text->height = text_height;
995 if (visibleMenuPos(pos_button))
997 if (pos_text->x == -1)
998 pos_text->x = pos_button->x + pos_button->width;
999 if (pos_text->y == -1)
1001 pos_button->y + (pos_button->height - pos_text->height) / 2;
1005 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1007 if (visibleTextPos(pos_text))
1009 if (pos_input->x == -1)
1010 pos_input->x = pos_text->x + pos_text->width;
1011 if (pos_input->y == -1)
1012 pos_input->y = pos_text->y;
1015 if (pos_input->width == -1)
1016 pos_input->width = input_width;
1017 if (pos_input->height == -1)
1018 pos_input->height = input_height;
1023 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1024 int graphic, boolean pressed)
1026 struct GraphicInfo *g = &graphic_info[graphic];
1029 int xoffset = (pressed ? g->pressed_xoffset : 0);
1030 int yoffset = (pressed ? g->pressed_yoffset : 0);
1032 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1034 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1035 g->width, g->height, dst_x, dst_y);
1038 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1039 boolean active_input,
1040 boolean pressed_button)
1044 for (i = 0; main_controls[i].nr != -1; i++)
1046 struct MainControlInfo *mci = &main_controls[i];
1048 if (mci->nr == nr || nr == -1)
1050 struct MenuPosInfo *pos_button = mci->pos_button;
1051 struct TextPosInfo *pos_text = mci->pos_text;
1052 struct TextPosInfo *pos_input = mci->pos_input;
1053 char *text = (mci->text ? *mci->text : NULL);
1054 char *input = (mci->input ? *mci->input : NULL);
1055 int button_graphic = mci->button_graphic;
1056 int font_text = (pos_text ? pos_text->font : -1);
1057 int font_input = (pos_input ? pos_input->font : -1);
1061 button_graphic = BUTTON_ACTIVE(button_graphic);
1062 font_text = FONT_ACTIVE(font_text);
1067 font_input = FONT_ACTIVE(font_input);
1070 if (visibleMenuPos(pos_button))
1072 struct MenuPosInfo *pos = pos_button;
1073 int x = mSX + pos->x;
1074 int y = mSY + pos->y;
1076 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1077 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1080 if (visibleTextPos(pos_text) && text != NULL)
1082 struct TextPosInfo *pos = pos_text;
1083 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1084 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1087 /* (check why/if this is needed) */
1088 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1090 DrawText(x, y, text, font_text);
1093 if (visibleTextPos(pos_input) && input != NULL)
1095 struct TextPosInfo *pos = pos_input;
1096 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1097 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1100 /* (check why/if this is needed) */
1101 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1103 DrawText(x, y, input, font_input);
1109 static void DrawCursorAndText_Main(int nr, boolean active_text,
1110 boolean pressed_button)
1112 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1116 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1117 boolean pressed_button)
1119 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1123 static struct MainControlInfo *getMainControlInfo(int nr)
1127 for (i = 0; main_controls[i].nr != -1; i++)
1128 if (main_controls[i].nr == nr)
1129 return &main_controls[i];
1134 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1139 int rect_x = ALIGNED_TEXT_XPOS(rect);
1140 int rect_y = ALIGNED_TEXT_YPOS(rect);
1142 return (x >= rect_x && x < rect_x + rect->width &&
1143 y >= rect_y && y < rect_y + rect->height);
1146 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1151 int rect_x = ALIGNED_TEXT_XPOS(rect);
1152 int rect_y = ALIGNED_TEXT_YPOS(rect);
1155 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1156 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1157 (x >= rect_x && x < rect_x + rect->width &&
1158 y >= rect_y && y < rect_y + rect->height));
1161 return (x >= rect_x && x < rect_x + rect->width &&
1162 y >= rect_y && y < rect_y + rect->height);
1165 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1167 static int cursor_array[MAX_LEV_FIELDY];
1168 int x = mSX + TILEX * xpos;
1169 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1174 cursor_array[ypos] = graphic;
1176 graphic = cursor_array[ypos];
1180 graphic = BUTTON_ACTIVE(graphic);
1182 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1183 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1186 static void initCursor(int ypos, int graphic)
1188 drawCursorExt(0, ypos, FALSE, graphic);
1191 static void drawCursor(int ypos, boolean active)
1193 drawCursorExt(0, ypos, active, -1);
1196 static void drawCursorXY(int xpos, int ypos, int graphic)
1198 drawCursorExt(xpos, ypos, FALSE, graphic);
1201 static void drawChooseTreeCursor(int ypos, boolean active)
1203 int last_game_status = game_status; /* save current game status */
1205 drawCursorExt(0, ypos, active, -1);
1207 game_status = last_game_status; /* restore current game status */
1212 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1213 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1214 setup.internal.program_copyright);
1217 int effectiveGameStatus()
1219 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1220 return GAME_MODE_TITLE;
1225 void DrawTitleScreenImage(int nr, boolean initial)
1227 int graphic = getTitleScreenGraphic(nr, initial);
1228 Bitmap *bitmap = graphic_info[graphic].bitmap;
1229 int width = graphic_info[graphic].width;
1230 int height = graphic_info[graphic].height;
1231 int src_x = graphic_info[graphic].src_x;
1232 int src_y = graphic_info[graphic].src_y;
1238 if (width > WIN_XSIZE)
1240 /* image width too large for window => center image horizontally */
1241 src_x = (width - WIN_XSIZE) / 2;
1245 if (height > WIN_YSIZE)
1247 /* image height too large for window => center image vertically */
1248 src_y = (height - WIN_YSIZE) / 2;
1252 /* always display title screens centered */
1253 dst_x = (WIN_XSIZE - width) / 2;
1254 dst_y = (WIN_YSIZE - height) / 2;
1256 SetDrawBackgroundMask(REDRAW_ALL);
1257 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1259 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1261 if (DrawingOnBackground(dst_x, dst_y))
1262 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1264 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1266 redraw_mask = REDRAW_ALL;
1269 void DrawTitleScreenMessage(int nr, boolean initial)
1271 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1272 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1273 int last_game_status = game_status; /* save current game status */
1275 if (filename == NULL)
1278 /* force TITLE font on title message screen */
1279 game_status = getTitleMessageGameMode(initial);
1281 /* if chars set to "-1", automatically determine by text and font width */
1282 if (tmi->chars == -1)
1283 tmi->chars = tmi->width / getFontWidth(tmi->font);
1285 tmi->width = tmi->chars * getFontWidth(tmi->font);
1287 /* if lines set to "-1", automatically determine by text and font height */
1288 if (tmi->lines == -1)
1289 tmi->lines = tmi->height / getFontHeight(tmi->font);
1291 tmi->height = tmi->lines * getFontHeight(tmi->font);
1293 SetDrawBackgroundMask(REDRAW_ALL);
1294 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1296 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1298 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1299 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1300 tmi->autowrap, tmi->centered, tmi->parse_comments);
1302 game_status = last_game_status; /* restore current game status */
1305 void DrawTitleScreen()
1307 KeyboardAutoRepeatOff();
1309 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1314 boolean CheckTitleScreen(boolean levelset_has_changed)
1316 static boolean show_title_initial = TRUE;
1317 boolean show_titlescreen = FALSE;
1319 /* needed to be able to skip title screen, if no image or message defined */
1320 InitializeTitleControls(show_title_initial);
1322 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1323 show_titlescreen = TRUE;
1325 /* show initial title images and messages only once at program start */
1326 show_title_initial = FALSE;
1328 return (show_titlescreen && num_title_screens > 0);
1331 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1333 static LevelDirTree *leveldir_last_valid = NULL;
1334 boolean levelset_has_changed = FALSE;
1336 LimitScreenUpdates(FALSE);
1338 FadeSetLeaveScreen();
1340 /* do not fade out here -- function may continue and fade on editor screen */
1343 FadeSoundsAndMusic();
1345 KeyboardAutoRepeatOn();
1348 audio.sound_deactivated = FALSE;
1352 /* needed if last screen was the playing screen, invoked from level editor */
1353 if (level_editor_test_game)
1355 game_status = GAME_MODE_EDITOR;
1361 /* needed if last screen was the setup screen and fullscreen state changed */
1362 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1363 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1365 /* leveldir_current may be invalid (level group, parent link) */
1366 if (!validLevelSeries(leveldir_current))
1367 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1369 if (leveldir_current != leveldir_last_valid)
1370 levelset_has_changed = TRUE;
1372 /* store valid level series information */
1373 leveldir_last_valid = leveldir_current;
1375 init_last = init; /* switch to new busy animation */
1377 /* needed if last screen (level choice) changed graphics, sounds or music */
1378 ReloadCustomArtwork(0);
1380 if (redraw_mask & REDRAW_ALL)
1381 fade_mask = REDRAW_ALL;
1385 /* needed if different viewport properties defined for menues */
1386 ChangeViewportPropertiesIfNeeded();
1388 /* needed if last screen was the editor screen */
1389 UndrawSpecialEditorDoor();
1391 SetDrawtoField(DRAW_BACKBUFFER);
1393 if (CheckTitleScreen(levelset_has_changed))
1395 game_status = GAME_MODE_TITLE;
1402 /* level_nr may have been set to value over handicap with level editor */
1403 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1404 level_nr = leveldir_current->handicap_level;
1406 LoadLevel(level_nr);
1407 LoadScore(level_nr);
1409 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1410 SetDrawDeactivationMask(REDRAW_NONE);
1411 SetDrawBackgroundMask(REDRAW_FIELD);
1413 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1415 if (fade_mask == REDRAW_ALL)
1416 RedrawGlobalBorder();
1420 InitializeMainControls();
1422 DrawCursorAndText_Main(-1, FALSE, FALSE);
1423 DrawPreviewLevelInitial();
1425 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1428 if (TAPE_IS_EMPTY(tape))
1430 DrawCompleteVideoDisplay();
1435 /* create gadgets for main menu screen */
1436 FreeScreenGadgets();
1437 CreateScreenGadgets();
1439 /* map gadgets for main menu screen */
1441 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1443 /* copy actual game door content to door double buffer for OpenDoor() */
1444 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1446 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1448 DrawMaskedBorder(REDRAW_ALL);
1453 /* update screen area with special editor door */
1454 redraw_mask |= REDRAW_ALL;
1457 SetMouseCursor(CURSOR_DEFAULT);
1461 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1464 void DrawAndFadeInMainMenu(int fade_mask)
1466 DrawMainMenuExt(fade_mask, TRUE);
1471 DrawMainMenuExt(REDRAW_ALL, FALSE);
1474 static void gotoTopLevelDir()
1476 /* move upwards until inside (but not above) top level directory */
1477 while (leveldir_current->node_parent &&
1478 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1480 /* write a "path" into level tree for easy navigation to last level */
1481 if (leveldir_current->node_parent->node_group->cl_first == -1)
1483 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1484 int leveldir_pos = posTreeInfo(leveldir_current);
1485 int num_page_entries;
1486 int cl_first, cl_cursor;
1488 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1489 num_page_entries = num_leveldirs;
1491 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1493 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1494 cl_cursor = leveldir_pos - cl_first;
1496 leveldir_current->node_parent->node_group->cl_first = cl_first;
1497 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1500 leveldir_current = leveldir_current->node_parent;
1504 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1506 static unsigned int title_delay = 0;
1507 static int title_screen_nr = 0;
1508 static int last_sound = -1, last_music = -1;
1509 boolean return_to_main_menu = FALSE;
1510 boolean use_fading_main_menu = TRUE;
1511 struct TitleControlInfo *tci;
1512 struct TitleFadingInfo fading_default;
1513 struct TitleFadingInfo fading_last = fading;
1514 struct TitleFadingInfo fading_next;
1517 if (button == MB_MENU_INITIALIZE)
1520 title_screen_nr = 0;
1521 tci = &title_controls[title_screen_nr];
1523 last_sound = SND_UNDEFINED;
1524 last_music = MUS_UNDEFINED;
1526 if (game_status == GAME_MODE_INFO)
1528 if (num_title_screens == 0)
1530 DrawInfoScreen_NotAvailable("Title screen information:",
1531 "No title screen for this level set.");
1536 FadeSoundsAndMusic();
1538 FadeOut(REDRAW_ALL);
1542 DrawTitleScreenImage(tci->local_nr, tci->initial);
1544 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1546 fading_default = (tci->initial ? title_initial_default : title_default);
1548 fading = fading_next = getTitleFading(tci);
1550 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1551 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1553 fading.fade_mode = FADE_MODE_FADE;
1554 fading.fade_delay = fading_default.fade_delay;
1557 sound = getTitleSound(tci);
1558 music = getTitleMusic(tci);
1560 if (sound != last_sound)
1561 PlayMenuSoundExt(sound);
1562 if (music != last_music)
1563 PlayMenuMusicExt(music);
1568 SetMouseCursor(CURSOR_NONE);
1572 fading = fading_next;
1574 DelayReached(&title_delay, 0); /* reset delay counter */
1579 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1580 button = MB_MENU_CHOICE;
1582 if (button == MB_MENU_LEAVE)
1584 return_to_main_menu = TRUE;
1585 use_fading_main_menu = FALSE;
1587 else if (button == MB_MENU_CHOICE)
1589 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1591 FadeSetEnterScreen();
1593 info_mode = INFO_MODE_MAIN;
1594 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1600 tci = &title_controls[title_screen_nr];
1602 if (title_screen_nr < num_title_screens)
1604 sound = getTitleSound(tci);
1605 music = getTitleMusic(tci);
1607 if (sound == SND_UNDEFINED || sound != last_sound)
1609 if (music == MUS_UNDEFINED || music != last_music)
1612 FadeOut(REDRAW_ALL);
1615 DrawTitleScreenImage(tci->local_nr, tci->initial);
1617 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1619 fading_next = getTitleFading(tci);
1621 sound = getTitleSound(tci);
1622 music = getTitleMusic(tci);
1624 if (sound != last_sound)
1625 PlayMenuSoundExt(sound);
1626 if (music != last_music)
1627 PlayMenuMusicExt(music);
1632 /* last screen already faded out, next screen has no animation */
1633 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1634 fading_next.fade_mode == FADE_MODE_NONE)
1635 fading = fading_next;
1639 fading = fading_next;
1641 DelayReached(&title_delay, 0); /* reset delay counter */
1645 FadeSoundsAndMusic();
1647 return_to_main_menu = TRUE;
1651 if (return_to_main_menu)
1653 SetMouseCursor(CURSOR_DEFAULT);
1655 if (game_status == GAME_MODE_INFO)
1657 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1659 info_mode = INFO_MODE_MAIN;
1661 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1663 else /* default: return to main menu */
1665 game_status = GAME_MODE_MAIN;
1667 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1672 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1674 int old_level_nr = level_nr;
1677 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1678 new_level_nr = selected_level_nr;
1680 new_level_nr = old_level_nr + step * direction;
1682 if (new_level_nr < leveldir_current->first_level)
1683 new_level_nr = leveldir_current->first_level;
1684 if (new_level_nr > leveldir_current->last_level)
1685 new_level_nr = leveldir_current->last_level;
1687 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1689 /* skipping levels is only allowed when trying to skip single level */
1690 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1691 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1693 leveldir_current->handicap_level++;
1694 SaveLevelSetup_SeriesInfo();
1697 new_level_nr = leveldir_current->handicap_level;
1700 if (new_level_nr != old_level_nr)
1702 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1704 PlaySound(SND_MENU_ITEM_SELECTING);
1706 level_nr = new_level_nr;
1708 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1709 int2str(level_nr, menu.main.text.level_number.size),
1710 mci->pos_text->font);
1712 LoadLevel(level_nr);
1713 DrawPreviewLevelInitial();
1717 DrawCompleteVideoDisplay();
1719 /* needed because DrawPreviewLevelInitial() takes some time */
1721 /* SyncDisplay(); */
1725 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1727 static int choice = MAIN_CONTROL_GAME;
1728 static boolean button_pressed_last = FALSE;
1729 boolean button_pressed = FALSE;
1733 if (button == MB_MENU_INITIALIZE)
1735 DrawCursorAndText_Main(choice, TRUE, FALSE);
1740 if (mx || my) /* mouse input */
1744 for (i = 0; main_controls[i].nr != -1; i++)
1746 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1747 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1748 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1750 pos = main_controls[i].nr;
1756 // handle pressed/unpressed state for active/inactive menu buttons
1757 // (if pos != -1, "i" contains index position corresponding to "pos")
1759 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1760 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1761 button_pressed = TRUE;
1763 if (button_pressed != button_pressed_last)
1765 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1768 PlaySound(SND_MENU_BUTTON_PRESSING);
1770 PlaySound(SND_MENU_BUTTON_RELEASING);
1773 else if (dx || dy) /* keyboard input */
1775 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1776 choice == MAIN_CONTROL_SETUP))
1777 button = MB_MENU_CHOICE;
1782 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1784 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1786 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1788 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1790 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1792 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1794 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1796 game_status = GAME_MODE_LEVELNR;
1798 ChangeViewportPropertiesIfNeeded();
1800 DrawChooseLevelNr();
1802 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1808 PlaySound(SND_MENU_ITEM_ACTIVATING);
1810 DrawCursorAndText_Main(choice, FALSE, FALSE);
1811 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1818 PlaySound(SND_MENU_ITEM_SELECTING);
1820 if (pos == MAIN_CONTROL_NAME)
1822 game_status = GAME_MODE_PSEUDO_TYPENAME;
1824 HandleTypeName(strlen(setup.player_name), 0);
1826 else if (pos == MAIN_CONTROL_LEVELS)
1830 game_status = GAME_MODE_LEVELS;
1832 SaveLevelSetup_LastSeries();
1833 SaveLevelSetup_SeriesInfo();
1835 if (setup.internal.choose_from_top_leveldir)
1838 ChangeViewportPropertiesIfNeeded();
1840 DrawChooseLevelSet();
1843 else if (pos == MAIN_CONTROL_SCORES)
1845 game_status = GAME_MODE_SCORES;
1847 ChangeViewportPropertiesIfNeeded();
1851 else if (pos == MAIN_CONTROL_EDITOR)
1853 if (leveldir_current->readonly &&
1854 !strEqual(setup.player_name, "Artsoft"))
1855 Request("This level is read only!", REQ_CONFIRM);
1857 CloseDoor(DOOR_CLOSE_2);
1859 game_status = GAME_MODE_EDITOR;
1861 FadeSetEnterScreen();
1865 else if (pos == MAIN_CONTROL_INFO)
1867 game_status = GAME_MODE_INFO;
1868 info_mode = INFO_MODE_MAIN;
1870 ChangeViewportPropertiesIfNeeded();
1874 else if (pos == MAIN_CONTROL_GAME)
1876 StartGameActions(options.network, setup.autorecord, level.random_seed);
1878 else if (pos == MAIN_CONTROL_SETUP)
1880 game_status = GAME_MODE_SETUP;
1881 setup_mode = SETUP_MODE_MAIN;
1883 ChangeViewportPropertiesIfNeeded();
1887 else if (pos == MAIN_CONTROL_QUIT)
1889 SaveLevelSetup_LastSeries();
1890 SaveLevelSetup_SeriesInfo();
1892 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1893 game_status = GAME_MODE_QUIT;
1898 button_pressed_last = button_pressed;
1902 /* ========================================================================= */
1903 /* info screen functions */
1904 /* ========================================================================= */
1906 static struct TokenInfo *info_info;
1907 static int num_info_info;
1909 static void execInfoTitleScreen()
1911 info_mode = INFO_MODE_TITLE;
1916 static void execInfoElements()
1918 info_mode = INFO_MODE_ELEMENTS;
1923 static void execInfoMusic()
1925 info_mode = INFO_MODE_MUSIC;
1930 static void execInfoCredits()
1932 info_mode = INFO_MODE_CREDITS;
1937 static void execInfoProgram()
1939 info_mode = INFO_MODE_PROGRAM;
1944 static void execInfoVersion()
1946 info_mode = INFO_MODE_VERSION;
1951 static void execInfoLevelSet()
1953 info_mode = INFO_MODE_LEVELSET;
1958 static void execExitInfo()
1960 game_status = GAME_MODE_MAIN;
1962 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1965 static struct TokenInfo info_info_main[] =
1967 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1968 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1969 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1970 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1971 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1972 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1973 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1974 { TYPE_EMPTY, NULL, "" },
1975 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1980 static void DrawCursorAndText_Info(int pos, boolean active)
1982 int xpos = MENU_SCREEN_START_XPOS;
1983 int ypos = MENU_SCREEN_START_YPOS + pos;
1984 int font_nr = FONT_MENU_1;
1987 font_nr = FONT_ACTIVE(font_nr);
1989 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1991 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1992 drawCursor(pos, active);
1995 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2000 CloseDoor(DOOR_CLOSE_2);
2002 /* (needed after displaying title screens which disable auto repeat) */
2003 KeyboardAutoRepeatOn();
2005 FadeSetLeaveScreen();
2009 if (fade_mask == REDRAW_ALL)
2011 RedrawGlobalBorder();
2013 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2018 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2020 info_info = info_info_main;
2023 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2025 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2026 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2027 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2028 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2029 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2030 initCursor(i, IMG_MENU_BUTTON);
2032 DrawCursorAndText_Info(i, FALSE);
2037 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2042 DrawMaskedBorder(fade_mask);
2049 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2051 static int choice_store[MAX_INFO_MODES];
2052 int choice = choice_store[info_mode]; /* always starts with 0 */
2056 if (button == MB_MENU_INITIALIZE)
2058 /* advance to first valid menu entry */
2059 while (choice < num_info_info &&
2060 info_info[choice].type & TYPE_SKIP_ENTRY)
2062 choice_store[info_mode] = choice;
2064 DrawCursorAndText_Info(choice, TRUE);
2068 else if (button == MB_MENU_LEAVE)
2070 for (y = 0; y < num_info_info; y++)
2072 if (info_info[y].type & TYPE_LEAVE_MENU)
2074 void (*menu_callback_function)(void) = info_info[y].value;
2078 menu_callback_function();
2080 break; /* absolutely needed because function changes 'info_info'! */
2087 if (mx || my) /* mouse input */
2089 x = (mx - mSX) / 32;
2090 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2092 else if (dx || dy) /* keyboard input */
2096 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2098 if (info_info[choice].type & menu_navigation_type ||
2099 info_info[choice].type & TYPE_ENTER_SCREEN ||
2100 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2101 info_info[choice].type & TYPE_YES_NO_AUTO)
2102 button = MB_MENU_CHOICE;
2107 /* jump to next non-empty menu entry (up or down) */
2108 while (y > 0 && y < num_info_info - 1 &&
2109 info_info[y].type & TYPE_SKIP_ENTRY)
2113 if (IN_VIS_MENU(x, y) &&
2114 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2120 PlaySound(SND_MENU_ITEM_ACTIVATING);
2122 DrawCursorAndText_Info(choice, FALSE);
2123 DrawCursorAndText_Info(y, TRUE);
2125 choice = choice_store[info_mode] = y;
2128 else if (!(info_info[y].type & TYPE_GHOSTED))
2130 PlaySound(SND_MENU_ITEM_SELECTING);
2132 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2134 void (*menu_callback_function)(void) = info_info[choice].value;
2136 FadeSetFromType(info_info[y].type);
2138 menu_callback_function();
2144 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2146 int ystart1 = mSY - SY + 100;
2147 int ystart2 = mSY - SY + 150;
2148 int ybottom = mSY - SY + SYSIZE - 20;
2150 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2152 FadeOut(REDRAW_FIELD);
2157 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2158 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2160 DrawTextSCentered(ybottom, FONT_TEXT_4,
2161 "Press any key or button for info menu");
2163 FadeIn(REDRAW_FIELD);
2166 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2168 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2169 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2170 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2171 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2172 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2173 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2174 int ystep = MENU_SCREEN_INFO_YSTEP;
2175 int element, action, direction;
2183 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2184 infoscreen_step[i] = infoscreen_frame[i] = 0;
2189 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2191 DrawTextSCentered(ybottom, FONT_TEXT_4,
2192 "Press any key or button for next page");
2198 while (helpanim_info[j].element != HELPANIM_LIST_END)
2200 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2205 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2214 j += infoscreen_step[i - start];
2216 element = helpanim_info[j].element;
2217 action = helpanim_info[j].action;
2218 direction = helpanim_info[j].direction;
2221 element = EL_UNKNOWN;
2223 if (action != -1 && direction != -1)
2224 graphic = el_act_dir2img(element, action, direction);
2225 else if (action != -1)
2226 graphic = el_act2img(element, action);
2227 else if (direction != -1)
2228 graphic = el_dir2img(element, direction);
2230 graphic = el2img(element);
2232 delay = helpanim_info[j++].delay;
2237 if (infoscreen_frame[i - start] == 0)
2240 infoscreen_frame[i - start] = delay - 1;
2244 sync_frame = delay - infoscreen_frame[i - start];
2245 infoscreen_frame[i - start]--;
2248 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2250 if (!infoscreen_frame[i - start])
2251 infoscreen_step[i - start] = 0;
2255 if (!infoscreen_frame[i - start])
2256 infoscreen_step[i - start]++;
2257 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2263 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2265 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2266 graphic, sync_frame, USE_MASKING);
2269 DrawInfoScreen_HelpText(element, action, direction, i - start);
2274 redraw_mask |= REDRAW_FIELD;
2279 static char *getHelpText(int element, int action, int direction)
2281 char token[MAX_LINE_LEN];
2283 strcpy(token, element_info[element].token_name);
2286 strcat(token, element_action_info[action].suffix);
2288 if (direction != -1)
2289 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2291 return getHashEntry(helptext_info, token);
2294 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2296 int font_nr = FONT_INFO_ELEMENTS;
2297 int font_width = getFontWidth(font_nr);
2298 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2299 int sy = mSY + 65 + 2 * 32 + 1;
2300 int ystep = TILEY + 4;
2301 int pad_x = sx - SX;
2302 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2303 int max_lines_per_text = 2;
2306 if (action != -1 && direction != -1) /* element.action.direction */
2307 text = getHelpText(element, action, direction);
2309 if (text == NULL && action != -1) /* element.action */
2310 text = getHelpText(element, action, -1);
2312 if (text == NULL && direction != -1) /* element.direction */
2313 text = getHelpText(element, -1, direction);
2315 if (text == NULL) /* base element */
2316 text = getHelpText(element, -1, -1);
2318 if (text == NULL) /* not found */
2319 text = "No description available";
2321 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2322 sy += getFontHeight(font_nr) / 2;
2324 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2325 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2326 TRUE, FALSE, FALSE);
2329 void DrawInfoScreen_TitleScreen()
2334 void HandleInfoScreen_TitleScreen(int button)
2336 HandleTitleScreen(0, 0, 0, 0, button);
2339 void DrawInfoScreen_Elements()
2341 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2343 FadeOut(REDRAW_FIELD);
2348 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2350 FadeIn(REDRAW_FIELD);
2355 void HandleInfoScreen_Elements(int button)
2357 static unsigned int info_delay = 0;
2358 static int num_anims;
2359 static int num_pages;
2361 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2364 if (button == MB_MENU_INITIALIZE)
2366 boolean new_element = TRUE;
2370 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2372 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2374 else if (new_element)
2377 new_element = FALSE;
2381 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2385 if (button == MB_MENU_LEAVE)
2387 PlaySound(SND_MENU_ITEM_SELECTING);
2389 info_mode = INFO_MODE_MAIN;
2394 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2396 if (button != MB_MENU_INITIALIZE)
2398 PlaySound(SND_MENU_ITEM_SELECTING);
2403 if (page >= num_pages)
2405 FadeSoundsAndMusic();
2407 info_mode = INFO_MODE_MAIN;
2408 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2414 FadeSetNextScreen();
2416 if (button != MB_MENU_INITIALIZE)
2417 FadeOut(REDRAW_FIELD);
2419 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2421 if (button != MB_MENU_INITIALIZE)
2422 FadeIn(REDRAW_FIELD);
2426 if (DelayReached(&info_delay, GameFrameDelay))
2427 if (page < num_pages)
2428 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2430 PlayMenuSoundIfLoop();
2434 void DrawInfoScreen_Music()
2436 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2438 FadeOut(REDRAW_FIELD);
2445 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2447 FadeIn(REDRAW_FIELD);
2450 void HandleInfoScreen_Music(int button)
2452 static struct MusicFileInfo *list = NULL;
2453 int ystart1 = mSY - SY + 100;
2454 int ystart2 = mSY - SY + 150;
2455 int ybottom = mSY - SY + SYSIZE - 20;
2458 if (button == MB_MENU_INITIALIZE)
2460 list = music_file_info;
2464 FadeSoundsAndMusic();
2469 DrawTextSCentered(ystart1, FONT_TEXT_1,
2470 "No music info for this level set.");
2472 DrawTextSCentered(ybottom, FONT_TEXT_4,
2473 "Press any key or button for info menu");
2479 if (button == MB_MENU_LEAVE)
2481 PlaySound(SND_MENU_ITEM_SELECTING);
2483 FadeSoundsAndMusic();
2485 info_mode = INFO_MODE_MAIN;
2490 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2494 if (button != MB_MENU_INITIALIZE)
2496 PlaySound(SND_MENU_ITEM_SELECTING);
2504 FadeSoundsAndMusic();
2506 info_mode = INFO_MODE_MAIN;
2507 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2512 FadeSoundsAndMusic();
2514 if (list != music_file_info)
2515 FadeSetNextScreen();
2517 if (button != MB_MENU_INITIALIZE)
2518 FadeOut(REDRAW_FIELD);
2525 int sound = list->music;
2527 if (sound_info[sound].loop)
2528 PlaySoundLoop(sound);
2532 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2536 PlayMusic(list->music);
2538 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2541 if (!strEqual(list->title, UNKNOWN_NAME))
2543 if (!strEqual(list->title_header, UNKNOWN_NAME))
2544 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2546 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2549 if (!strEqual(list->artist, UNKNOWN_NAME))
2551 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2552 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2554 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2556 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2559 if (!strEqual(list->album, UNKNOWN_NAME))
2561 if (!strEqual(list->album_header, UNKNOWN_NAME))
2562 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2564 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2566 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2569 if (!strEqual(list->year, UNKNOWN_NAME))
2571 if (!strEqual(list->year_header, UNKNOWN_NAME))
2572 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2574 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2576 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2579 DrawTextSCentered(ybottom, FONT_TEXT_4,
2580 "Press any key or button for next page");
2582 if (button != MB_MENU_INITIALIZE)
2583 FadeIn(REDRAW_FIELD);
2586 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2587 PlaySoundLoop(list->music);
2590 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2592 int ystart1 = mSY - SY + 100;
2593 int ystart2 = mSY - SY + 150;
2594 int ybottom = mSY - SY + SYSIZE - 20;
2600 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2604 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2605 "Special thanks to");
2606 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2608 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2610 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2611 "\"Boulder Dash\"");
2612 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2614 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2616 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2618 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2619 "First Star Software");
2621 else if (screen_nr == 1)
2623 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2624 "Special thanks to");
2625 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2626 "Klaus Heinz & Volker Wertich");
2627 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2629 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2630 "\"Emerald Mine\"");
2631 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2633 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2635 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2637 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2640 else if (screen_nr == 2)
2642 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2643 "Special thanks to");
2644 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2645 "Michael Stopp & Philip Jespersen");
2646 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2648 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2650 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2652 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2654 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2656 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2657 "Digital Integration");
2659 else if (screen_nr == 3)
2661 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2662 "Special thanks to");
2663 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2664 "Hiroyuki Imabayashi");
2665 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2667 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2669 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2671 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2673 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2675 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2678 else if (screen_nr == 4)
2680 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2681 "Special thanks to");
2682 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2684 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2686 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2687 "J\xfcrgen Bonhagen");
2688 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2689 "for the continuous creation");
2690 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2691 "of outstanding level sets");
2693 else if (screen_nr == 5)
2695 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2697 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2699 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2700 "for ideas and inspiration by");
2701 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2704 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2706 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2708 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2709 "for ideas and inspiration by");
2710 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2713 else if (screen_nr == 6)
2715 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2717 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2720 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2721 "for the code base used for the");
2722 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2723 "native Emerald Mine engine");
2725 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2726 "for the new Emerald Mine engine");
2729 else if (screen_nr == 7)
2731 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2733 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2735 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2736 "for the initial DOS port");
2738 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2740 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2742 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2743 "for some additional toons");
2745 else if (screen_nr == 8)
2747 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2748 "And not to forget:");
2749 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2751 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2752 "All those who contributed");
2753 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2754 "levels to this game");
2755 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2759 DrawTextSCentered(ybottom, FONT_TEXT_4,
2760 "Press any key or button for next page");
2763 void DrawInfoScreen_Credits()
2765 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2767 FadeSoundsAndMusic();
2769 FadeOut(REDRAW_FIELD);
2771 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2773 FadeIn(REDRAW_FIELD);
2776 void HandleInfoScreen_Credits(int button)
2778 static int screen_nr = 0;
2779 int num_screens = 9;
2781 if (button == MB_MENU_INITIALIZE)
2785 // DrawInfoScreen_CreditsScreen(screen_nr);
2788 if (button == MB_MENU_LEAVE)
2790 PlaySound(SND_MENU_ITEM_SELECTING);
2792 info_mode = INFO_MODE_MAIN;
2797 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2799 if (button != MB_MENU_INITIALIZE)
2801 PlaySound(SND_MENU_ITEM_SELECTING);
2806 if (screen_nr >= num_screens)
2808 FadeSoundsAndMusic();
2810 info_mode = INFO_MODE_MAIN;
2811 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2817 FadeSetNextScreen();
2819 if (button != MB_MENU_INITIALIZE)
2820 FadeOut(REDRAW_FIELD);
2822 DrawInfoScreen_CreditsScreen(screen_nr);
2824 if (button != MB_MENU_INITIALIZE)
2825 FadeIn(REDRAW_FIELD);
2829 PlayMenuSoundIfLoop();
2833 void DrawInfoScreen_Program()
2835 int ystart1 = mSY - SY + 100;
2836 int ystart2 = mSY - SY + 150;
2837 int ybottom = mSY - SY + SYSIZE - 20;
2840 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2842 FadeOut(REDRAW_FIELD);
2847 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2849 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2850 "This game is Freeware!");
2851 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2852 "If you like it, send e-mail to:");
2853 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2854 setup.internal.program_email);
2855 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2856 "More information and levels:");
2857 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2858 setup.internal.program_website);
2859 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2860 "If you have created new levels,");
2861 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2862 "send them to me to include them!");
2863 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2866 DrawTextSCentered(ybottom, FONT_TEXT_4,
2867 "Press any key or button for info menu");
2869 FadeIn(REDRAW_FIELD);
2872 void HandleInfoScreen_Program(int button)
2874 if (button == MB_MENU_LEAVE)
2876 PlaySound(SND_MENU_ITEM_SELECTING);
2878 info_mode = INFO_MODE_MAIN;
2883 else if (button == MB_MENU_CHOICE)
2885 PlaySound(SND_MENU_ITEM_SELECTING);
2887 FadeSoundsAndMusic();
2889 info_mode = INFO_MODE_MAIN;
2890 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2894 PlayMenuSoundIfLoop();
2898 void DrawInfoScreen_Version()
2900 int font_header = FONT_TEXT_3;
2901 int font_text = FONT_TEXT_2;
2902 int xstep = getFontWidth(font_text);
2903 int ystep = getFontHeight(font_text);
2904 int ystart1 = mSY - SY + 100;
2905 int ystart2 = mSY - SY + 150;
2906 int ybottom = mSY - SY + SYSIZE - 20;
2907 int xstart1 = mSX - SX + 2 * xstep;
2908 int xstart2 = mSX - SX + 18 * xstep;
2909 int xstart3 = mSX - SX + 28 * xstep;
2910 SDL_version sdl_version_compiled;
2911 const SDL_version *sdl_version_linked;
2912 int driver_name_len = 10;
2913 #if defined(TARGET_SDL2)
2914 SDL_version sdl_version_linked_ext;
2915 const char *driver_name = NULL;
2917 char driver_name[driver_name_len];
2920 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2922 FadeOut(REDRAW_FIELD);
2927 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2929 DrawTextF(xstart1, ystart2, font_header, "Name");
2930 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
2933 DrawTextF(xstart1, ystart2, font_header, "Version");
2934 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
2937 DrawTextF(xstart1, ystart2, font_header, "Platform");
2938 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2941 DrawTextF(xstart1, ystart2, font_header, "Target");
2942 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2945 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2946 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2948 ystart2 += 3 * ystep;
2949 DrawTextF(xstart1, ystart2, font_header, "Library");
2950 DrawTextF(xstart2, ystart2, font_header, "compiled");
2951 DrawTextF(xstart3, ystart2, font_header, "linked");
2953 SDL_VERSION(&sdl_version_compiled);
2954 #if defined(TARGET_SDL2)
2955 SDL_GetVersion(&sdl_version_linked_ext);
2956 sdl_version_linked = &sdl_version_linked_ext;
2958 sdl_version_linked = SDL_Linked_Version();
2961 ystart2 += 2 * ystep;
2962 DrawTextF(xstart1, ystart2, font_text, "SDL");
2963 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2964 sdl_version_compiled.major,
2965 sdl_version_compiled.minor,
2966 sdl_version_compiled.patch);
2967 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2968 sdl_version_linked->major,
2969 sdl_version_linked->minor,
2970 sdl_version_linked->patch);
2972 SDL_IMAGE_VERSION(&sdl_version_compiled);
2973 sdl_version_linked = IMG_Linked_Version();
2976 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2977 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2978 sdl_version_compiled.major,
2979 sdl_version_compiled.minor,
2980 sdl_version_compiled.patch);
2981 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2982 sdl_version_linked->major,
2983 sdl_version_linked->minor,
2984 sdl_version_linked->patch);
2986 SDL_MIXER_VERSION(&sdl_version_compiled);
2987 sdl_version_linked = Mix_Linked_Version();
2990 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2991 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2992 sdl_version_compiled.major,
2993 sdl_version_compiled.minor,
2994 sdl_version_compiled.patch);
2995 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2996 sdl_version_linked->major,
2997 sdl_version_linked->minor,
2998 sdl_version_linked->patch);
3000 SDL_NET_VERSION(&sdl_version_compiled);
3001 sdl_version_linked = SDLNet_Linked_Version();
3004 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3005 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3006 sdl_version_compiled.major,
3007 sdl_version_compiled.minor,
3008 sdl_version_compiled.patch);
3009 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3010 sdl_version_linked->major,
3011 sdl_version_linked->minor,
3012 sdl_version_linked->patch);
3014 ystart2 += 3 * ystep;
3015 DrawTextF(xstart1, ystart2, font_header, "Driver");
3016 DrawTextF(xstart2, ystart2, font_header, "Requested");
3017 DrawTextF(xstart3, ystart2, font_header, "Used");
3019 #if defined(TARGET_SDL2)
3020 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3022 SDL_VideoDriverName(driver_name, driver_name_len);
3025 ystart2 += 2 * ystep;
3026 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3027 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3028 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3030 #if defined(TARGET_SDL2)
3031 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3033 SDL_AudioDriverName(driver_name, driver_name_len);
3037 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3038 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3039 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3041 DrawTextSCentered(ybottom, FONT_TEXT_4,
3042 "Press any key or button for info menu");
3044 FadeIn(REDRAW_FIELD);
3047 void HandleInfoScreen_Version(int button)
3049 if (button == MB_MENU_LEAVE)
3051 PlaySound(SND_MENU_ITEM_SELECTING);
3053 info_mode = INFO_MODE_MAIN;
3058 else if (button == MB_MENU_CHOICE)
3060 PlaySound(SND_MENU_ITEM_SELECTING);
3062 FadeSoundsAndMusic();
3064 info_mode = INFO_MODE_MAIN;
3065 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3069 PlayMenuSoundIfLoop();
3073 void DrawInfoScreen_LevelSet()
3075 struct TitleMessageInfo *tmi = &readme;
3076 char *filename = getLevelSetInfoFilename();
3077 char *title = "Level Set Information:";
3078 int ystart1 = mSY - SY + 100;
3079 int ybottom = mSY - SY + SYSIZE - 20;
3081 if (filename == NULL)
3083 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3088 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3090 FadeOut(REDRAW_FIELD);
3095 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3097 /* if x position set to "-1", automatically determine by playfield width */
3099 tmi->x = SXSIZE / 2;
3101 /* if y position set to "-1", use static default value */
3105 /* if width set to "-1", automatically determine by playfield width */
3106 if (tmi->width == -1)
3107 tmi->width = SXSIZE - 2 * TILEX;
3109 /* if height set to "-1", automatically determine by playfield height */
3110 if (tmi->height == -1)
3111 tmi->height = SYSIZE - 20 - tmi->y - 10;
3113 /* if chars set to "-1", automatically determine by text and font width */
3114 if (tmi->chars == -1)
3115 tmi->chars = tmi->width / getFontWidth(tmi->font);
3117 tmi->width = tmi->chars * getFontWidth(tmi->font);
3119 /* if lines set to "-1", automatically determine by text and font height */
3120 if (tmi->lines == -1)
3121 tmi->lines = tmi->height / getFontHeight(tmi->font);
3123 tmi->height = tmi->lines * getFontHeight(tmi->font);
3125 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3126 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3127 tmi->autowrap, tmi->centered, tmi->parse_comments);
3129 DrawTextSCentered(ybottom, FONT_TEXT_4,
3130 "Press any key or button for info menu");
3132 FadeIn(REDRAW_FIELD);
3135 void HandleInfoScreen_LevelSet(int button)
3137 if (button == MB_MENU_LEAVE)
3139 PlaySound(SND_MENU_ITEM_SELECTING);
3141 info_mode = INFO_MODE_MAIN;
3146 else if (button == MB_MENU_CHOICE)
3148 PlaySound(SND_MENU_ITEM_SELECTING);
3150 FadeSoundsAndMusic();
3152 info_mode = INFO_MODE_MAIN;
3153 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3157 PlayMenuSoundIfLoop();
3161 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3163 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3165 if (info_mode == INFO_MODE_TITLE)
3166 DrawInfoScreen_TitleScreen();
3167 else if (info_mode == INFO_MODE_ELEMENTS)
3168 DrawInfoScreen_Elements();
3169 else if (info_mode == INFO_MODE_MUSIC)
3170 DrawInfoScreen_Music();
3171 else if (info_mode == INFO_MODE_CREDITS)
3172 DrawInfoScreen_Credits();
3173 else if (info_mode == INFO_MODE_PROGRAM)
3174 DrawInfoScreen_Program();
3175 else if (info_mode == INFO_MODE_VERSION)
3176 DrawInfoScreen_Version();
3177 else if (info_mode == INFO_MODE_LEVELSET)
3178 DrawInfoScreen_LevelSet();
3180 DrawInfoScreen_Main(fade_mask, do_fading);
3182 if (info_mode != INFO_MODE_MAIN &&
3183 info_mode != INFO_MODE_TITLE &&
3184 info_mode != INFO_MODE_MUSIC)
3191 void DrawAndFadeInInfoScreen(int fade_mask)
3193 DrawInfoScreenExt(fade_mask, TRUE);
3196 void DrawInfoScreen()
3198 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3201 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3203 if (info_mode == INFO_MODE_TITLE)
3204 HandleInfoScreen_TitleScreen(button);
3205 else if (info_mode == INFO_MODE_ELEMENTS)
3206 HandleInfoScreen_Elements(button);
3207 else if (info_mode == INFO_MODE_MUSIC)
3208 HandleInfoScreen_Music(button);
3209 else if (info_mode == INFO_MODE_CREDITS)
3210 HandleInfoScreen_Credits(button);
3211 else if (info_mode == INFO_MODE_PROGRAM)
3212 HandleInfoScreen_Program(button);
3213 else if (info_mode == INFO_MODE_VERSION)
3214 HandleInfoScreen_Version(button);
3215 else if (info_mode == INFO_MODE_LEVELSET)
3216 HandleInfoScreen_LevelSet(button);
3218 HandleInfoScreen_Main(mx, my, dx, dy, button);
3222 /* ========================================================================= */
3223 /* type name functions */
3224 /* ========================================================================= */
3226 void HandleTypeName(int newxpos, Key key)
3228 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3229 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3230 struct TextPosInfo *pos = mci->pos_input;
3231 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3232 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3233 static int xpos = 0;
3234 int font_nr = pos->font;
3235 int font_active_nr = FONT_ACTIVE(font_nr);
3236 int font_width = getFontWidth(font_active_nr);
3237 char key_char = getValidConfigValueChar(getCharFromKey(key));
3238 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3239 boolean is_active = TRUE;
3241 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3245 strcpy(last_player_name, setup.player_name);
3249 #if defined(TARGET_SDL2)
3250 SDL_StartTextInput();
3253 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3255 setup.player_name[xpos] = key_char;
3256 setup.player_name[xpos + 1] = 0;
3260 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3264 setup.player_name[xpos] = 0;
3266 else if (key == KSYM_Return && xpos > 0)
3272 game_status = GAME_MODE_MAIN;
3274 else if (key == KSYM_Escape)
3276 strcpy(setup.player_name, last_player_name);
3280 game_status = GAME_MODE_MAIN;
3285 pos->width = (strlen(setup.player_name) + 1) * font_width;
3286 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3288 DrawText(startx, starty, setup.player_name, font_active_nr);
3289 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3293 pos->width = strlen(setup.player_name) * font_width;
3294 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3296 DrawText(startx, starty, setup.player_name, font_nr);
3298 #if defined(TARGET_SDL2)
3299 SDL_StopTextInput();
3305 /* ========================================================================= */
3306 /* tree menu functions */
3307 /* ========================================================================= */
3309 static void DrawChooseTree(TreeInfo **ti_ptr)
3311 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3313 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3315 game_status = GAME_MODE_MAIN;
3317 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3324 FreeScreenGadgets();
3325 CreateScreenGadgets();
3327 CloseDoor(DOOR_CLOSE_2);
3333 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3334 MapScreenTreeGadgets(*ti_ptr);
3341 static void AdjustScrollbar(int id, int items_max, int items_visible,
3344 struct GadgetInfo *gi = screen_gadget[id];
3346 if (item_position > items_max - items_visible)
3347 item_position = items_max - items_visible;
3349 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3350 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3351 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3354 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3356 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3360 static void clearMenuListArea()
3362 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3364 /* correct scrollbar position if placed outside menu (playfield) area */
3365 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
3366 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
3368 /* clear menu list area, but not title or scrollbar */
3369 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3370 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
3373 static void drawChooseTreeList(int first_entry, int num_page_entries,
3377 char *title_string = NULL;
3378 int yoffset_sets = MENU_TITLE1_YPOS;
3379 int yoffset_setup = 16;
3380 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3381 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3382 int last_game_status = game_status; /* save current game status */
3384 title_string = ti->infotext;
3386 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3388 clearMenuListArea();
3390 for (i = 0; i < num_page_entries; i++)
3392 TreeInfo *node, *node_first;
3393 int entry_pos = first_entry + i;
3394 int xpos = MENU_SCREEN_START_XPOS;
3395 int ypos = MENU_SCREEN_START_YPOS + i;
3396 int startx = mSX + xpos * 32;
3397 int starty = mSY + ypos * 32;
3398 int font_nr = FONT_TEXT_1;
3399 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3400 int startx_text = startx + font_xoffset;
3401 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3402 int text_size = startx_scrollbar - startx_text;
3403 int max_buffer_len = text_size / getFontWidth(font_nr);
3404 char buffer[max_buffer_len + 1];
3406 node_first = getTreeInfoFirstGroupEntry(ti);
3407 node = getTreeInfoFromPos(node_first, entry_pos);
3409 strncpy(buffer, node->name, max_buffer_len);
3410 buffer[max_buffer_len] = '\0';
3412 DrawText(startx, starty, buffer, font_nr + node->color);
3414 if (node->parent_link)
3415 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3416 else if (node->level_group)
3417 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3419 initCursor(i, IMG_MENU_BUTTON);
3422 game_status = last_game_status; /* restore current game status */
3424 redraw_mask |= REDRAW_FIELD;
3427 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3429 TreeInfo *node, *node_first;
3430 int x, last_redraw_mask = redraw_mask;
3431 int ypos = MENU_TITLE2_YPOS;
3432 int font_nr = FONT_TITLE_2;
3434 if (ti->type == TREE_TYPE_LEVEL_NR)
3435 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3437 if (ti->type != TREE_TYPE_LEVEL_DIR)
3440 node_first = getTreeInfoFirstGroupEntry(ti);
3441 node = getTreeInfoFromPos(node_first, entry_pos);
3443 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3445 if (node->parent_link)
3446 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3447 node->node_parent->name);
3448 else if (node->level_group)
3449 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3451 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3452 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3453 node->levels, (node->levels > 1 ? "levels" : "level"),
3456 /* let BackToFront() redraw only what is needed */
3457 redraw_mask = last_redraw_mask;
3458 for (x = 0; x < SCR_FIELDX; x++)
3459 MarkTileDirty(x, 1);
3462 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3465 TreeInfo *ti = *ti_ptr;
3467 int y = ti->cl_cursor;
3468 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3469 int num_entries = numTreeInfoInGroup(ti);
3470 int num_page_entries;
3471 int last_game_status = game_status; /* save current game status */
3472 boolean position_set_by_scrollbar = (dx == 999);
3474 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3475 num_page_entries = num_entries;
3477 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3479 game_status = last_game_status; /* restore current game status */
3481 if (button == MB_MENU_INITIALIZE)
3483 int num_entries = numTreeInfoInGroup(ti);
3484 int entry_pos = posTreeInfo(ti);
3486 if (ti->cl_first == -1)
3488 /* only on initialization */
3489 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3490 ti->cl_cursor = entry_pos - ti->cl_first;
3492 else if (ti->cl_cursor >= num_page_entries ||
3493 (num_entries > num_page_entries &&
3494 num_entries - ti->cl_first < num_page_entries))
3496 /* only after change of list size (by custom graphic configuration) */
3497 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3498 ti->cl_cursor = entry_pos - ti->cl_first;
3501 if (position_set_by_scrollbar)
3504 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3507 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3508 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3509 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3513 else if (button == MB_MENU_LEAVE)
3517 PlaySound(SND_MENU_ITEM_SELECTING);
3519 if (ti->node_parent)
3521 *ti_ptr = ti->node_parent;
3522 DrawChooseTree(ti_ptr);
3524 else if (game_status == GAME_MODE_SETUP)
3526 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3527 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3528 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3530 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3531 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3532 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3533 execSetupGraphics();
3534 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3535 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3536 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3538 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3539 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3540 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3547 if (game_status == GAME_MODE_LEVELNR)
3549 int new_level_nr = atoi(level_number_current->identifier);
3551 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3554 game_status = GAME_MODE_MAIN;
3556 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3562 if (mx || my) /* mouse input */
3564 int last_game_status = game_status; /* save current game status */
3566 x = (mx - mSX) / 32;
3567 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3569 game_status = last_game_status; /* restore current game status */
3571 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3573 /* move cursor instead of scrolling when already at start/end of list */
3574 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3576 else if (dy == +1 * SCROLL_LINE &&
3577 ti->cl_first + num_page_entries == num_entries)
3580 /* handle scrolling screen one line or page */
3581 if (ti->cl_cursor + dy < 0 ||
3582 ti->cl_cursor + dy > num_page_entries - 1)
3584 boolean redraw = FALSE;
3586 if (ABS(dy) == SCROLL_PAGE)
3587 step = num_page_entries - 1;
3589 if (dy < 0 && ti->cl_first > 0)
3591 /* scroll page/line up */
3593 ti->cl_first -= step;
3594 if (ti->cl_first < 0)
3599 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3601 /* scroll page/line down */
3603 ti->cl_first += step;
3604 if (ti->cl_first + num_page_entries > num_entries)
3605 ti->cl_first = MAX(0, num_entries - num_page_entries);
3612 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3613 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3614 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3616 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3623 /* handle moving cursor one line */
3624 y = ti->cl_cursor + dy;
3629 TreeInfo *node_first, *node_cursor;
3630 int entry_pos = ti->cl_first + y;
3632 node_first = getTreeInfoFirstGroupEntry(ti);
3633 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3635 if (node_cursor->node_group)
3639 PlaySound(SND_MENU_ITEM_SELECTING);
3641 node_cursor->cl_first = ti->cl_first;
3642 node_cursor->cl_cursor = ti->cl_cursor;
3643 *ti_ptr = node_cursor->node_group;
3644 DrawChooseTree(ti_ptr);
3649 else if (dx == -1 && ti->node_parent)
3653 PlaySound(SND_MENU_ITEM_SELECTING);
3655 *ti_ptr = ti->node_parent;
3656 DrawChooseTree(ti_ptr);
3661 if (!anyScrollbarGadgetActive() &&
3662 IN_VIS_MENU(x, y) &&
3663 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3664 y >= 0 && y < num_page_entries)
3668 if (y != ti->cl_cursor)
3670 PlaySound(SND_MENU_ITEM_ACTIVATING);
3672 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3673 drawChooseTreeCursor(y, TRUE);
3674 drawChooseTreeInfo(ti->cl_first + y, ti);
3681 TreeInfo *node_first, *node_cursor;
3682 int entry_pos = ti->cl_first + y;
3684 PlaySound(SND_MENU_ITEM_SELECTING);
3686 node_first = getTreeInfoFirstGroupEntry(ti);
3687 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3689 if (node_cursor->node_group)
3693 node_cursor->cl_first = ti->cl_first;
3694 node_cursor->cl_cursor = ti->cl_cursor;
3695 *ti_ptr = node_cursor->node_group;
3696 DrawChooseTree(ti_ptr);
3698 else if (node_cursor->parent_link)
3702 *ti_ptr = node_cursor->node_parent;
3703 DrawChooseTree(ti_ptr);
3709 node_cursor->cl_first = ti->cl_first;
3710 node_cursor->cl_cursor = ti->cl_cursor;
3711 *ti_ptr = node_cursor;
3713 if (ti->type == TREE_TYPE_LEVEL_DIR)
3715 LoadLevelSetup_SeriesInfo();
3717 SaveLevelSetup_LastSeries();
3718 SaveLevelSetup_SeriesInfo();
3722 if (game_status == GAME_MODE_SETUP)
3724 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3725 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3726 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3728 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3729 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3730 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3731 execSetupGraphics();
3732 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3733 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3734 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3736 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3737 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3738 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3745 if (game_status == GAME_MODE_LEVELNR)
3747 int new_level_nr = atoi(level_number_current->identifier);
3749 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3752 game_status = GAME_MODE_MAIN;
3761 void DrawChooseLevelSet()
3763 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3765 DrawChooseTree(&leveldir_current);
3771 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3773 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3776 void DrawChooseLevelNr()
3780 if (level_number != NULL)
3782 freeTreeInfo(level_number);
3784 level_number = NULL;
3787 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3789 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3790 char identifier[32], name[32];
3793 /* temporarily load level info to get level name */
3794 LoadLevelInfoOnly(i);
3796 ti->node_top = &level_number;
3797 ti->sort_priority = 10000 + value;
3798 ti->color = (level.no_valid_file ? FC_BLUE :
3799 LevelStats_getSolved(i) ? FC_GREEN :
3800 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3802 sprintf(identifier, "%d", value);
3803 sprintf(name, "%03d: %s", value,
3804 (level.no_valid_file ? "(no file)" : level.name));
3806 setString(&ti->identifier, identifier);
3807 setString(&ti->name, name);
3808 setString(&ti->name_sorting, name);
3810 pushTreeInfo(&level_number, ti);
3813 /* sort level number values to start with lowest level number */
3814 sortTreeInfo(&level_number);
3816 /* set current level number to current level number */
3817 level_number_current =
3818 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3820 /* if that also fails, set current level number to first available level */
3821 if (level_number_current == NULL)
3822 level_number_current = level_number;
3824 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3826 DrawChooseTree(&level_number_current);
3832 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3834 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3837 void DrawHallOfFame(int highlight_position)
3839 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3842 FadeSoundsAndMusic();
3844 /* (this is needed when called from GameEnd() after winning a game) */
3845 KeyboardAutoRepeatOn();
3848 /* (this is needed when called from GameEnd() after winning a game) */
3849 SetDrawDeactivationMask(REDRAW_NONE);
3850 SetDrawBackgroundMask(REDRAW_FIELD);
3852 CloseDoor(DOOR_CLOSE_2);
3854 if (highlight_position < 0)
3855 LoadScore(level_nr);
3857 FadeSetEnterScreen();
3866 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3871 static void drawHallOfFameList(int first_entry, int highlight_position)
3875 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3878 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3879 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3880 "HighScores of Level %d", level_nr);
3882 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3884 int entry = first_entry + i;
3885 boolean active = (entry == highlight_position);
3886 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3887 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3888 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3889 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3890 int dx1 = 3 * getFontWidth(font_nr1);
3891 int dx2 = dx1 + getFontWidth(font_nr1);
3892 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
3893 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
3894 int sy = mSY + 64 + i * 32;
3896 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3897 DrawText(mSX + dx1, sy, ".", font_nr1);
3899 for (j = 0; j < num_dots; j++)
3900 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
3902 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3903 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3905 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3908 redraw_mask |= REDRAW_FIELD;
3911 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3913 static int first_entry = 0;
3914 static int highlight_position = 0;
3915 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3917 if (button == MB_MENU_INITIALIZE)
3920 highlight_position = mx;
3921 drawHallOfFameList(first_entry, highlight_position);
3926 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3927 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3931 if (first_entry > 0)
3933 first_entry -= step;
3934 if (first_entry < 0)
3937 drawHallOfFameList(first_entry, highlight_position);
3942 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3944 first_entry += step;
3945 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3946 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3948 drawHallOfFameList(first_entry, highlight_position);
3951 else if (button == MB_MENU_LEAVE)
3953 PlaySound(SND_MENU_ITEM_SELECTING);
3955 FadeSound(SND_BACKGROUND_SCORES);
3957 game_status = GAME_MODE_MAIN;
3961 else if (button == MB_MENU_CHOICE)
3963 PlaySound(SND_MENU_ITEM_SELECTING);
3965 FadeSound(SND_BACKGROUND_SCORES);
3967 game_status = GAME_MODE_MAIN;
3969 DrawAndFadeInMainMenu(REDRAW_FIELD);
3972 if (game_status == GAME_MODE_SCORES)
3973 PlayMenuSoundIfLoop();
3977 /* ========================================================================= */
3978 /* setup screen functions */
3979 /* ========================================================================= */
3981 static struct TokenInfo *setup_info;
3982 static int num_setup_info; /* number of setup entries shown on screen */
3983 static int max_setup_info; /* total number of setup entries in list */
3985 static char *screen_mode_text;
3986 static char *window_size_text;
3987 static char *scaling_type_text;
3988 static char *scroll_delay_text;
3989 static char *snapshot_mode_text;
3990 static char *game_speed_text;
3991 static char *graphics_set_name;
3992 static char *sounds_set_name;
3993 static char *music_set_name;
3994 static char *volume_simple_text;
3995 static char *volume_loops_text;
3996 static char *volume_music_text;
3997 static char *touch_controls_text;
3998 static char *move_distance_text;
3999 static char *drop_distance_text;
4001 static void execSetupMain()
4003 setup_mode = SETUP_MODE_MAIN;
4008 static void execSetupGame_setGameSpeeds()
4010 if (game_speeds == NULL)
4014 for (i = 0; game_speeds_list[i].value != -1; i++)
4016 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4017 char identifier[32], name[32];
4018 int value = game_speeds_list[i].value;
4019 char *text = game_speeds_list[i].text;
4021 ti->node_top = &game_speeds;
4022 ti->sort_priority = 10000 - value;
4024 sprintf(identifier, "%d", value);
4025 sprintf(name, "%s", text);
4027 setString(&ti->identifier, identifier);
4028 setString(&ti->name, name);
4029 setString(&ti->name_sorting, name);
4030 setString(&ti->infotext, "Game Speed");
4032 pushTreeInfo(&game_speeds, ti);
4035 /* sort game speed values to start with slowest game speed */
4036 sortTreeInfo(&game_speeds);
4038 /* set current game speed to configured game speed value */
4039 game_speed_current =
4040 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4042 /* if that fails, set current game speed to reliable default value */
4043 if (game_speed_current == NULL)
4044 game_speed_current =
4045 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4047 /* if that also fails, set current game speed to first available speed */
4048 if (game_speed_current == NULL)
4049 game_speed_current = game_speeds;
4052 setup.game_frame_delay = atoi(game_speed_current->identifier);
4054 /* needed for displaying game speed text instead of identifier */
4055 game_speed_text = game_speed_current->name;
4058 static void execSetupGame_setScrollDelays()
4060 if (scroll_delays == NULL)
4064 for (i = 0; scroll_delays_list[i].value != -1; i++)
4066 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4067 char identifier[32], name[32];
4068 int value = scroll_delays_list[i].value;
4069 char *text = scroll_delays_list[i].text;
4071 ti->node_top = &scroll_delays;
4072 ti->sort_priority = value;
4074 sprintf(identifier, "%d", value);
4075 sprintf(name, "%s", text);
4077 setString(&ti->identifier, identifier);
4078 setString(&ti->name, name);
4079 setString(&ti->name_sorting, name);
4080 setString(&ti->infotext, "Scaling Type");
4082 pushTreeInfo(&scroll_delays, ti);
4085 /* sort scaling type values to start with lowest scaling type value */
4086 sortTreeInfo(&scroll_delays);
4088 /* set current scaling type value to configured scaling type value */
4089 scroll_delay_current =
4090 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4092 /* if that fails, set current scaling type to reliable default value */
4093 if (scroll_delay_current == NULL)
4094 scroll_delay_current =
4095 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4097 /* if that also fails, set current scaling type to first available value */
4098 if (scroll_delay_current == NULL)
4099 scroll_delay_current = scroll_delays;
4102 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4104 /* needed for displaying scaling type text instead of identifier */
4105 scroll_delay_text = scroll_delay_current->name;
4108 static void execSetupGame_setSnapshotModes()
4110 if (snapshot_modes == NULL)
4114 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4116 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4117 char identifier[32], name[32];
4118 char *value = snapshot_modes_list[i].value;
4119 char *text = snapshot_modes_list[i].text;
4121 ti->node_top = &snapshot_modes;
4122 ti->sort_priority = i;
4124 sprintf(identifier, "%s", value);
4125 sprintf(name, "%s", text);
4127 setString(&ti->identifier, identifier);
4128 setString(&ti->name, name);
4129 setString(&ti->name_sorting, name);
4130 setString(&ti->infotext, "Snapshot Mode");
4132 pushTreeInfo(&snapshot_modes, ti);
4135 /* sort snapshot mode values to start with lowest snapshot mode value */
4136 sortTreeInfo(&snapshot_modes);
4138 /* set current snapshot mode value to configured snapshot mode value */
4139 snapshot_mode_current =
4140 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4142 /* if that fails, set current snapshot mode to reliable default value */
4143 if (snapshot_mode_current == NULL)
4144 snapshot_mode_current =
4145 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4147 /* if that also fails, set current snapshot mode to first available value */
4148 if (snapshot_mode_current == NULL)
4149 snapshot_mode_current = snapshot_modes;
4152 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4154 /* needed for displaying snapshot mode text instead of identifier */
4155 snapshot_mode_text = snapshot_mode_current->name;
4158 static void execSetupGame()
4160 execSetupGame_setGameSpeeds();
4161 execSetupGame_setScrollDelays();
4162 execSetupGame_setSnapshotModes();
4164 setup_mode = SETUP_MODE_GAME;
4169 static void execSetupChooseGameSpeed()
4171 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4176 static void execSetupChooseScrollDelay()
4178 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4183 static void execSetupChooseSnapshotMode()
4185 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4190 static void execSetupEditor()
4192 setup_mode = SETUP_MODE_EDITOR;
4197 static void execSetupGraphics_setWindowSizes(boolean update_list)
4199 if (window_sizes != NULL && update_list)
4201 freeTreeInfo(window_sizes);
4203 window_sizes = NULL;
4206 if (window_sizes == NULL)
4208 boolean current_window_size_found = FALSE;
4211 for (i = 0; window_sizes_list[i].value != -1; i++)
4213 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4214 char identifier[32], name[32];
4215 int value = window_sizes_list[i].value;
4216 char *text = window_sizes_list[i].text;
4218 ti->node_top = &window_sizes;
4219 ti->sort_priority = value;
4221 sprintf(identifier, "%d", value);
4222 sprintf(name, "%s", text);
4224 setString(&ti->identifier, identifier);
4225 setString(&ti->name, name);
4226 setString(&ti->name_sorting, name);
4227 setString(&ti->infotext, "Window Scaling");
4229 pushTreeInfo(&window_sizes, ti);
4231 if (value == setup.window_scaling_percent)
4232 current_window_size_found = TRUE;
4235 if (!current_window_size_found)
4237 // add entry for non-preset window scaling value
4239 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4240 char identifier[32], name[32];
4241 int value = setup.window_scaling_percent;
4243 ti->node_top = &window_sizes;
4244 ti->sort_priority = value;
4246 sprintf(identifier, "%d", value);
4247 sprintf(name, "%d %% (Current)", value);
4249 setString(&ti->identifier, identifier);
4250 setString(&ti->name, name);
4251 setString(&ti->name_sorting, name);
4252 setString(&ti->infotext, "Window Scaling");
4254 pushTreeInfo(&window_sizes, ti);
4257 /* sort window size values to start with lowest window size value */
4258 sortTreeInfo(&window_sizes);
4260 /* set current window size value to configured window size value */
4261 window_size_current =
4262 getTreeInfoFromIdentifier(window_sizes,
4263 i_to_a(setup.window_scaling_percent));
4265 /* if that fails, set current window size to reliable default value */
4266 if (window_size_current == NULL)
4267 window_size_current =
4268 getTreeInfoFromIdentifier(window_sizes,
4269 i_to_a(STD_WINDOW_SCALING_PERCENT));
4271 /* if that also fails, set current window size to first available value */
4272 if (window_size_current == NULL)
4273 window_size_current = window_sizes;
4276 setup.window_scaling_percent = atoi(window_size_current->identifier);
4278 /* needed for displaying window size text instead of identifier */
4279 window_size_text = window_size_current->name;
4282 static void execSetupGraphics_setScalingTypes()
4284 if (scaling_types == NULL)
4288 for (i = 0; scaling_types_list[i].value != NULL; i++)
4290 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4291 char identifier[32], name[32];
4292 char *value = scaling_types_list[i].value;
4293 char *text = scaling_types_list[i].text;
4295 ti->node_top = &scaling_types;
4296 ti->sort_priority = i;
4298 sprintf(identifier, "%s", value);
4299 sprintf(name, "%s", text);
4301 setString(&ti->identifier, identifier);
4302 setString(&ti->name, name);
4303 setString(&ti->name_sorting, name);
4304 setString(&ti->infotext, "Anti-Aliasing");
4306 pushTreeInfo(&scaling_types, ti);
4309 /* sort scaling type values to start with lowest scaling type value */
4310 sortTreeInfo(&scaling_types);
4312 /* set current scaling type value to configured scaling type value */
4313 scaling_type_current =
4314 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4316 /* if that fails, set current scaling type to reliable default value */
4317 if (scaling_type_current == NULL)
4318 scaling_type_current =
4319 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4321 /* if that also fails, set current scaling type to first available value */
4322 if (scaling_type_current == NULL)
4323 scaling_type_current = scaling_types;
4326 setup.window_scaling_quality = scaling_type_current->identifier;
4328 /* needed for displaying scaling type text instead of identifier */
4329 scaling_type_text = scaling_type_current->name;
4332 static void execSetupGraphics_setScreenModes()
4334 // if (screen_modes == NULL && video.fullscreen_available)
4335 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4339 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4341 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4342 char identifier[32], name[32];
4343 int x = video.fullscreen_modes[i].width;
4344 int y = video.fullscreen_modes[i].height;
4347 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4349 ti->node_top = &screen_modes;
4350 ti->sort_priority = x * 10000 + y;
4352 sprintf(identifier, "%dx%d", x, y);
4353 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4355 setString(&ti->identifier, identifier);
4356 setString(&ti->name, name);
4357 setString(&ti->name_sorting, name);
4358 setString(&ti->infotext, "Fullscreen Mode");
4360 pushTreeInfo(&screen_modes, ti);
4363 /* sort fullscreen modes to start with lowest available screen resolution */
4364 sortTreeInfo(&screen_modes);
4366 /* set current screen mode for fullscreen mode to configured setup value */
4367 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4368 setup.fullscreen_mode);
4370 /* if that fails, set current screen mode to reliable default value */
4371 if (screen_mode_current == NULL)
4372 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4373 DEFAULT_FULLSCREEN_MODE);
4375 /* if that also fails, set current screen mode to first available mode */
4376 if (screen_mode_current == NULL)
4377 screen_mode_current = screen_modes;
4379 if (screen_mode_current == NULL)
4380 video.fullscreen_available = FALSE;
4383 // if (video.fullscreen_available)
4384 if (screen_mode_current != NULL)
4386 setup.fullscreen_mode = screen_mode_current->identifier;
4388 /* needed for displaying screen mode name instead of identifier */
4389 screen_mode_text = screen_mode_current->name;
4393 static void execSetupGraphics()
4395 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4397 // update "setup.window_scaling_percent" from list selection
4398 execSetupGraphics_setWindowSizes(FALSE);
4402 // update list selection from "setup.window_scaling_percent"
4403 execSetupGraphics_setWindowSizes(TRUE);
4406 execSetupGraphics_setScalingTypes();
4407 execSetupGraphics_setScreenModes();
4409 setup_mode = SETUP_MODE_GRAPHICS;
4413 #if defined(TARGET_SDL2)
4414 // window scaling may have changed at this point
4415 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4417 // window scaling quality may have changed at this point
4418 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4419 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4423 #if !defined(PLATFORM_ANDROID)
4424 #if defined(TARGET_SDL2)
4425 static void execSetupChooseWindowSize()
4427 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4432 static void execSetupChooseScalingType()
4434 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4439 static void execSetupChooseScreenMode()
4441 if (!video.fullscreen_available)
4444 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4451 static void execSetupChooseVolumeSimple()
4453 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4458 static void execSetupChooseVolumeLoops()
4460 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4465 static void execSetupChooseVolumeMusic()
4467 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4472 static void execSetupSound()
4474 if (volumes_simple == NULL)
4476 boolean current_volume_simple_found = FALSE;
4479 for (i = 0; volumes_list[i].value != -1; i++)
4481 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4482 char identifier[32], name[32];
4483 int value = volumes_list[i].value;
4484 char *text = volumes_list[i].text;
4486 ti->node_top = &volumes_simple;
4487 ti->sort_priority = value;
4489 sprintf(identifier, "%d", value);
4490 sprintf(name, "%s", text);
4492 setString(&ti->identifier, identifier);
4493 setString(&ti->name, name);
4494 setString(&ti->name_sorting, name);
4495 setString(&ti->infotext, "Sound Volume");
4497 pushTreeInfo(&volumes_simple, ti);
4499 if (value == setup.volume_simple)
4500 current_volume_simple_found = TRUE;
4503 if (!current_volume_simple_found)
4505 // add entry for non-preset volume value
4507 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4508 char identifier[32], name[32];
4509 int value = setup.volume_simple;
4511 ti->node_top = &volumes_simple;
4512 ti->sort_priority = value;
4514 sprintf(identifier, "%d", value);
4515 sprintf(name, "%d %% (Current)", value);
4517 setString(&ti->identifier, identifier);
4518 setString(&ti->name, name);
4519 setString(&ti->name_sorting, name);
4520 setString(&ti->infotext, "Sound Volume");
4522 pushTreeInfo(&volumes_simple, ti);
4525 /* sort volume values to start with lowest volume value */
4526 sortTreeInfo(&volumes_simple);
4528 /* set current volume value to configured volume value */
4529 volume_simple_current =
4530 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4532 /* if that fails, set current volume to reliable default value */
4533 if (volume_simple_current == NULL)
4534 volume_simple_current =
4535 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4537 /* if that also fails, set current volume to first available value */
4538 if (volume_simple_current == NULL)
4539 volume_simple_current = volumes_simple;
4542 if (volumes_loops == NULL)
4544 boolean current_volume_loops_found = FALSE;
4547 for (i = 0; volumes_list[i].value != -1; i++)
4549 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4550 char identifier[32], name[32];
4551 int value = volumes_list[i].value;
4552 char *text = volumes_list[i].text;
4554 ti->node_top = &volumes_loops;
4555 ti->sort_priority = value;
4557 sprintf(identifier, "%d", value);
4558 sprintf(name, "%s", text);
4560 setString(&ti->identifier, identifier);
4561 setString(&ti->name, name);
4562 setString(&ti->name_sorting, name);
4563 setString(&ti->infotext, "Loops Volume");
4565 pushTreeInfo(&volumes_loops, ti);
4567 if (value == setup.volume_loops)
4568 current_volume_loops_found = TRUE;
4571 if (!current_volume_loops_found)
4573 // add entry for non-preset volume value
4575 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4576 char identifier[32], name[32];
4577 int value = setup.volume_loops;
4579 ti->node_top = &volumes_loops;
4580 ti->sort_priority = value;
4582 sprintf(identifier, "%d", value);
4583 sprintf(name, "%d %% (Current)", value);
4585 setString(&ti->identifier, identifier);
4586 setString(&ti->name, name);
4587 setString(&ti->name_sorting, name);
4588 setString(&ti->infotext, "Loops Volume");
4590 pushTreeInfo(&volumes_loops, ti);
4593 /* sort volume values to start with lowest volume value */
4594 sortTreeInfo(&volumes_loops);
4596 /* set current volume value to configured volume value */
4597 volume_loops_current =
4598 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4600 /* if that fails, set current volume to reliable default value */
4601 if (volume_loops_current == NULL)
4602 volume_loops_current =
4603 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4605 /* if that also fails, set current volume to first available value */
4606 if (volume_loops_current == NULL)
4607 volume_loops_current = volumes_loops;
4610 if (volumes_music == NULL)
4612 boolean current_volume_music_found = FALSE;
4615 for (i = 0; volumes_list[i].value != -1; i++)
4617 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4618 char identifier[32], name[32];
4619 int value = volumes_list[i].value;
4620 char *text = volumes_list[i].text;
4622 ti->node_top = &volumes_music;
4623 ti->sort_priority = value;
4625 sprintf(identifier, "%d", value);
4626 sprintf(name, "%s", text);
4628 setString(&ti->identifier, identifier);
4629 setString(&ti->name, name);
4630 setString(&ti->name_sorting, name);
4631 setString(&ti->infotext, "Music Volume");
4633 pushTreeInfo(&volumes_music, ti);
4635 if (value == setup.volume_music)
4636 current_volume_music_found = TRUE;
4639 if (!current_volume_music_found)
4641 // add entry for non-preset volume value
4643 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4644 char identifier[32], name[32];
4645 int value = setup.volume_music;
4647 ti->node_top = &volumes_music;
4648 ti->sort_priority = value;
4650 sprintf(identifier, "%d", value);
4651 sprintf(name, "%d %% (Current)", value);
4653 setString(&ti->identifier, identifier);
4654 setString(&ti->name, name);
4655 setString(&ti->name_sorting, name);
4656 setString(&ti->infotext, "Music Volume");
4658 pushTreeInfo(&volumes_music, ti);
4661 /* sort volume values to start with lowest volume value */
4662 sortTreeInfo(&volumes_music);
4664 /* set current volume value to configured volume value */
4665 volume_music_current =
4666 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4668 /* if that fails, set current volume to reliable default value */
4669 if (volume_music_current == NULL)
4670 volume_music_current =
4671 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4673 /* if that also fails, set current volume to first available value */
4674 if (volume_music_current == NULL)
4675 volume_music_current = volumes_music;
4678 setup.volume_simple = atoi(volume_simple_current->identifier);
4679 setup.volume_loops = atoi(volume_loops_current->identifier);
4680 setup.volume_music = atoi(volume_music_current->identifier);
4682 /* needed for displaying volume text instead of identifier */
4683 volume_simple_text = volume_simple_current->name;
4684 volume_loops_text = volume_loops_current->name;
4685 volume_music_text = volume_music_current->name;
4687 setup_mode = SETUP_MODE_SOUND;
4692 static void execSetupChooseTouchControls()
4694 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4699 static void execSetupChooseMoveDistance()
4701 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4706 static void execSetupChooseDropDistance()
4708 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4713 static void execSetupTouch()
4715 if (touch_controls == NULL)
4719 for (i = 0; touch_controls_list[i].value != NULL; i++)
4721 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4722 char identifier[32], name[32];
4723 char *value = touch_controls_list[i].value;
4724 char *text = touch_controls_list[i].text;
4726 ti->node_top = &touch_controls;
4727 ti->sort_priority = i;
4729 sprintf(identifier, "%s", value);
4730 sprintf(name, "%s", text);
4732 setString(&ti->identifier, identifier);
4733 setString(&ti->name, name);
4734 setString(&ti->name_sorting, name);
4735 setString(&ti->infotext, "Control Type");
4737 pushTreeInfo(&touch_controls, ti);
4740 /* sort touch control values to start with lowest touch control value */
4741 sortTreeInfo(&touch_controls);
4743 /* set current touch control value to configured touch control value */
4744 touch_control_current =
4745 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4747 /* if that fails, set current touch control to reliable default value */
4748 if (touch_control_current == NULL)
4749 touch_control_current =
4750 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4752 /* if that also fails, set current touch control to first available value */
4753 if (touch_control_current == NULL)
4754 touch_control_current = touch_controls;
4757 if (move_distances == NULL)
4761 for (i = 0; distances_list[i].value != -1; i++)
4763 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4764 char identifier[32], name[32];
4765 int value = distances_list[i].value;
4766 char *text = distances_list[i].text;
4768 ti->node_top = &move_distances;
4769 ti->sort_priority = value;
4771 sprintf(identifier, "%d", value);
4772 sprintf(name, "%s", text);
4774 setString(&ti->identifier, identifier);
4775 setString(&ti->name, name);
4776 setString(&ti->name_sorting, name);
4777 setString(&ti->infotext, "Move Distance");
4779 pushTreeInfo(&move_distances, ti);
4782 /* sort distance values to start with lowest distance value */
4783 sortTreeInfo(&move_distances);
4785 /* set current distance value to configured distance value */
4786 move_distance_current =
4787 getTreeInfoFromIdentifier(move_distances,
4788 i_to_a(setup.touch.move_distance));
4790 /* if that fails, set current distance to reliable default value */
4791 if (move_distance_current == NULL)
4792 move_distance_current =
4793 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4795 /* if that also fails, set current distance to first available value */
4796 if (move_distance_current == NULL)
4797 move_distance_current = move_distances;
4800 if (drop_distances == NULL)
4804 for (i = 0; distances_list[i].value != -1; i++)
4806 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4807 char identifier[32], name[32];
4808 int value = distances_list[i].value;
4809 char *text = distances_list[i].text;
4811 ti->node_top = &drop_distances;
4812 ti->sort_priority = value;
4814 sprintf(identifier, "%d", value);
4815 sprintf(name, "%s", text);
4817 setString(&ti->identifier, identifier);
4818 setString(&ti->name, name);
4819 setString(&ti->name_sorting, name);
4820 setString(&ti->infotext, "Drop Distance");
4822 pushTreeInfo(&drop_distances, ti);
4825 /* sort distance values to start with lowest distance value */
4826 sortTreeInfo(&drop_distances);
4828 /* set current distance value to configured distance value */
4829 drop_distance_current =
4830 getTreeInfoFromIdentifier(drop_distances,
4831 i_to_a(setup.touch.drop_distance));
4833 /* if that fails, set current distance to reliable default value */
4834 if (drop_distance_current == NULL)
4835 drop_distance_current =
4836 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
4838 /* if that also fails, set current distance to first available value */
4839 if (drop_distance_current == NULL)
4840 drop_distance_current = drop_distances;
4843 setup.touch.control_type = touch_control_current->identifier;
4844 setup.touch.move_distance = atoi(move_distance_current->identifier);
4845 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
4847 /* needed for displaying volume text instead of identifier */
4848 touch_controls_text = touch_control_current->name;
4849 move_distance_text = move_distance_current->name;
4850 drop_distance_text = drop_distance_current->name;
4852 setup_mode = SETUP_MODE_TOUCH;
4857 static void execSetupArtwork()
4860 printf("::: '%s', '%s', '%s'\n",
4861 artwork.gfx_current->subdir,
4862 artwork.gfx_current->fullpath,
4863 artwork.gfx_current->basepath);
4866 setup.graphics_set = artwork.gfx_current->identifier;
4867 setup.sounds_set = artwork.snd_current->identifier;
4868 setup.music_set = artwork.mus_current->identifier;
4870 /* needed if last screen (setup choice) changed graphics, sounds or music */
4871 ReloadCustomArtwork(0);
4873 /* needed for displaying artwork name instead of artwork identifier */
4874 graphics_set_name = artwork.gfx_current->name;
4875 sounds_set_name = artwork.snd_current->name;
4876 music_set_name = artwork.mus_current->name;
4878 setup_mode = SETUP_MODE_ARTWORK;
4883 static void execSetupChooseGraphics()
4885 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4890 static void execSetupChooseSounds()
4892 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4897 static void execSetupChooseMusic()
4899 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4904 #if !defined(PLATFORM_ANDROID)
4905 static void execSetupInput()
4907 setup_mode = SETUP_MODE_INPUT;
4913 static void execSetupShortcuts()
4915 setup_mode = SETUP_MODE_SHORTCUTS;
4920 static void execSetupShortcuts1()
4922 setup_mode = SETUP_MODE_SHORTCUTS_1;
4927 static void execSetupShortcuts2()
4929 setup_mode = SETUP_MODE_SHORTCUTS_2;
4934 static void execSetupShortcuts3()
4936 setup_mode = SETUP_MODE_SHORTCUTS_3;
4941 static void execSetupShortcuts4()
4943 setup_mode = SETUP_MODE_SHORTCUTS_4;
4948 static void execSetupShortcuts5()
4950 setup_mode = SETUP_MODE_SHORTCUTS_5;
4955 static void execExitSetup()
4957 game_status = GAME_MODE_MAIN;
4959 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4962 static void execSaveAndExitSetup()
4968 static struct TokenInfo setup_info_main[] =
4970 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4971 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4972 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4973 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4974 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4975 #if !defined(PLATFORM_ANDROID)
4976 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4977 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4979 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4981 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4982 { TYPE_EMPTY, NULL, "" },
4983 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4984 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4989 static struct TokenInfo setup_info_game[] =
4991 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4992 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4993 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4994 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4995 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4996 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4997 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4998 { TYPE_STRING, &game_speed_text, "" },
5000 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5001 { TYPE_STRING, &scroll_delay_text, "" },
5003 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5004 { TYPE_STRING, &snapshot_mode_text, "" },
5005 { TYPE_EMPTY, NULL, "" },
5006 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5011 static struct TokenInfo setup_info_editor[] =
5014 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5015 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5016 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5017 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5018 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5019 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5020 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5021 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5023 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5024 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5025 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5027 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5029 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5030 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5031 { TYPE_EMPTY, NULL, "" },
5033 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5034 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5035 { TYPE_EMPTY, NULL, "" },
5037 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5038 { TYPE_EMPTY, NULL, "" },
5039 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5044 static struct TokenInfo setup_info_graphics[] =
5046 #if !defined(PLATFORM_ANDROID)
5047 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5048 #if defined(TARGET_SDL2)
5049 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5050 { TYPE_STRING, &window_size_text, "" },
5051 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5052 { TYPE_STRING, &scaling_type_text, "" },
5054 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5055 { TYPE_STRING, &screen_mode_text, "" },
5059 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5060 { TYPE_STRING, &scroll_delay_text, "" },
5062 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5063 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5064 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5065 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5066 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5067 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5068 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5069 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5070 { TYPE_EMPTY, NULL, "" },
5071 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5076 static struct TokenInfo setup_info_sound[] =
5078 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5079 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5080 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5081 { TYPE_EMPTY, NULL, "" },
5082 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5083 { TYPE_STRING, &volume_simple_text, "" },
5084 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5085 { TYPE_STRING, &volume_loops_text, "" },
5086 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5087 { TYPE_STRING, &volume_music_text, "" },
5088 { TYPE_EMPTY, NULL, "" },
5089 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5094 static struct TokenInfo setup_info_artwork[] =
5096 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5097 { TYPE_STRING, &graphics_set_name, "" },
5098 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5099 { TYPE_STRING, &sounds_set_name, "" },
5100 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5101 { TYPE_STRING, &music_set_name, "" },
5102 { TYPE_EMPTY, NULL, "" },
5103 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5104 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5105 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5106 { TYPE_EMPTY, NULL, "" },
5107 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5112 static struct TokenInfo setup_info_input[] =
5114 { TYPE_SWITCH, NULL, "Player:" },
5115 { TYPE_SWITCH, NULL, "Device:" },
5116 { TYPE_ENTER_MENU, NULL, "" },
5117 { TYPE_EMPTY, NULL, "" },
5118 { TYPE_EMPTY, NULL, "" },
5119 { TYPE_EMPTY, NULL, "" },
5120 { TYPE_EMPTY, 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_LEAVE_MENU, execSetupMain, "Back" },
5132 static struct TokenInfo setup_info_touch[] =
5134 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5135 { TYPE_STRING, &touch_controls_text, "" },
5136 { TYPE_EMPTY, NULL, "" },
5137 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5138 { TYPE_STRING, &move_distance_text, "" },
5139 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5140 { TYPE_STRING, &drop_distance_text, "" },
5141 { TYPE_EMPTY, NULL, "" },
5142 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5147 static struct TokenInfo setup_info_shortcuts[] =
5149 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5150 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5151 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5152 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5153 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5154 { TYPE_EMPTY, NULL, "" },
5155 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5160 static struct TokenInfo setup_info_shortcuts_1[] =
5162 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5163 { TYPE_KEY, &setup.shortcut.save_game, "" },
5164 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5165 { TYPE_KEY, &setup.shortcut.load_game, "" },
5166 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5167 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5168 { TYPE_EMPTY, NULL, "" },
5169 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5170 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5171 { TYPE_EMPTY, NULL, "" },
5172 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5177 static struct TokenInfo setup_info_shortcuts_2[] =
5179 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5180 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5181 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5182 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5183 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5184 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5185 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5186 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5187 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5188 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5189 { TYPE_EMPTY, NULL, "" },
5190 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5195 static struct TokenInfo setup_info_shortcuts_3[] =
5197 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5198 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5199 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5200 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5201 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5202 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5203 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5204 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5205 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5206 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5207 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5208 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5209 { TYPE_EMPTY, NULL, "" },
5210 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5215 static struct TokenInfo setup_info_shortcuts_4[] =
5217 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5218 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5219 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5220 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5221 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5222 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5223 { TYPE_EMPTY, NULL, "" },
5224 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5229 static struct TokenInfo setup_info_shortcuts_5[] =
5231 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5232 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5233 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5234 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5235 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5236 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5237 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5238 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5239 { TYPE_EMPTY, NULL, "" },
5240 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5245 static Key getSetupKey()
5247 Key key = KSYM_UNDEFINED;
5248 boolean got_key_event = FALSE;
5250 while (!got_key_event)
5252 if (PendingEvent()) /* got event */
5260 case EVENT_KEYPRESS:
5262 key = GetEventKey((KeyEvent *)&event, TRUE);
5264 /* press 'Escape' or 'Enter' to keep the existing key binding */
5265 if (key == KSYM_Escape || key == KSYM_Return)
5266 key = KSYM_UNDEFINED; /* keep old value */
5268 got_key_event = TRUE;
5272 case EVENT_KEYRELEASE:
5273 key_joystick_mapping = 0;
5277 HandleOtherEvents(&event);
5285 /* don't eat all CPU time */
5292 static int getSetupTextFont(int type)
5294 if (type & (TYPE_SWITCH |
5306 static int getSetupValueFont(int type, void *value)
5308 if (type & TYPE_KEY)
5309 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5310 else if (type & TYPE_STRING)
5311 return FONT_VALUE_2;
5312 else if (type & TYPE_ECS_AGA)
5313 return FONT_VALUE_1;
5314 else if (type & TYPE_BOOLEAN_STYLE)
5315 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5316 else if (type & TYPE_YES_NO_AUTO)
5317 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5318 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5320 return FONT_VALUE_1;
5323 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5325 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5326 struct TokenInfo *si = &setup_info[si_pos];
5327 boolean font_draw_xoffset_modified = FALSE;
5328 int font_draw_xoffset_old = -1;
5329 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5330 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5331 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5332 int xpos = menu_screen_value_xpos;
5333 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5334 int startx = mSX + xpos * 32;
5335 int starty = mSY + ypos * 32;
5336 int font_nr, font_width;
5337 int type = si->type;
5338 void *value = si->value;
5339 char *value_string = getSetupValue(type, value);
5342 if (value_string == NULL)
5345 if (type & TYPE_KEY)
5347 xpos = MENU_SCREEN_START_XPOS;
5349 if (type & TYPE_QUERY)
5350 value_string = "<press key>";
5352 else if (type & TYPE_STRING)
5354 int max_value_len = (SCR_FIELDX - 2) * 2;
5356 xpos = MENU_SCREEN_START_XPOS;
5358 if (strlen(value_string) > max_value_len)
5359 value_string[max_value_len] = '\0';
5361 else if (type & TYPE_YES_NO_AUTO)
5363 xpos = menu_screen_value_xpos - 1;
5366 startx = mSX + xpos * 32;
5367 starty = mSY + ypos * 32;
5368 font_nr = getSetupValueFont(type, value);
5369 font_width = getFontWidth(font_nr);
5371 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5372 if (setup_mode != SETUP_MODE_INPUT)
5374 int max_menu_text_length_big = (menu_screen_value_xpos -
5375 MENU_SCREEN_START_XPOS);
5376 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5377 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5378 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5379 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5380 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5381 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5382 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5383 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5384 boolean correct_font_draw_xoffset = FALSE;
5386 if (xpos == MENU_SCREEN_START_XPOS &&
5387 startx + font1_xoffset < text_startx + text_font_xoffset)
5388 correct_font_draw_xoffset = TRUE;
5390 if (xpos == menu_screen_value_xpos &&
5391 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5392 correct_font_draw_xoffset = TRUE;
5394 /* check if setup value would overlap with setup text when printed */
5395 /* (this can happen for extreme/wrong values for font draw offset) */
5396 if (correct_font_draw_xoffset)
5398 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5399 font_draw_xoffset_modified = TRUE;
5401 if (type & TYPE_KEY)
5402 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5403 else if (!(type & TYPE_STRING))
5404 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5405 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5409 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5410 DrawText(startx + i * font_width, starty, " ", font_nr);
5412 DrawText(startx, starty, value_string, font_nr);
5414 if (font_draw_xoffset_modified)
5415 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5418 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5420 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5421 struct TokenInfo *si = &setup_info[si_pos];
5423 if (si->type & TYPE_BOOLEAN_STYLE)
5425 *(boolean *)si->value ^= TRUE;
5427 else if (si->type & TYPE_YES_NO_AUTO)
5431 (*(int *)si->value == AUTO ? TRUE :
5432 *(int *)si->value == TRUE ? FALSE : AUTO) :
5433 (*(int *)si->value == TRUE ? AUTO :
5434 *(int *)si->value == AUTO ? FALSE : TRUE));
5436 else if (si->type & TYPE_KEY)
5440 si->type |= TYPE_QUERY;
5441 drawSetupValue(screen_pos, setup_info_pos_raw);
5442 si->type &= ~TYPE_QUERY;
5444 key = getSetupKey();
5445 if (key != KSYM_UNDEFINED)
5446 *(Key *)si->value = key;
5449 drawSetupValue(screen_pos, setup_info_pos_raw);
5451 // fullscreen state may have changed at this point
5452 if (si->value == &setup.fullscreen)
5453 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5456 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5459 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5460 struct TokenInfo *si = &setup_info[si_pos];
5461 int xpos = MENU_SCREEN_START_XPOS;
5462 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5463 int font_nr = getSetupTextFont(si->type);
5465 if (setup_info == setup_info_input)
5466 font_nr = FONT_MENU_1;
5469 font_nr = FONT_ACTIVE(font_nr);
5471 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5473 if (si->type & ~TYPE_SKIP_ENTRY)
5474 drawCursor(screen_pos, active);
5477 static void drawSetupInfoList(struct TokenInfo *setup_info,
5478 int first_entry, int num_page_entries)
5482 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5483 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5485 if (num_page_entries > max_setup_info)
5486 num_page_entries = max_setup_info;
5488 if (first_entry + num_page_entries > max_setup_info)
5491 clearMenuListArea();
5493 for (i = 0; i < num_page_entries; i++)
5495 int setup_info_pos = first_entry + i;
5496 struct TokenInfo *si = &setup_info[setup_info_pos];
5497 void *value_ptr = si->value;
5499 /* set some entries to "unchangeable" according to other variables */
5500 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5501 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5502 (value_ptr == &setup.sound_music && !audio.music_available) ||
5503 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5504 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5505 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5506 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5507 si->type |= TYPE_GHOSTED;
5509 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5510 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5511 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5512 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5513 else if (si->type & ~TYPE_SKIP_ENTRY)
5514 initCursor(i, IMG_MENU_BUTTON);
5516 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5518 if (si->type & TYPE_VALUE)
5519 drawSetupValue(i, setup_info_pos);
5523 static void DrawSetupScreen_Generic()
5525 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5526 boolean redraw_all = FALSE;
5527 char *title_string = NULL;
5532 FreeScreenGadgets();
5533 CreateScreenGadgets();
5535 CloseDoor(DOOR_CLOSE_2);
5537 if (redraw_mask & REDRAW_ALL)
5544 if (setup_mode == SETUP_MODE_MAIN)
5546 setup_info = setup_info_main;
5547 title_string = "Setup";
5549 else if (setup_mode == SETUP_MODE_GAME)
5551 setup_info = setup_info_game;
5552 title_string = "Setup Game";
5554 else if (setup_mode == SETUP_MODE_EDITOR)
5556 setup_info = setup_info_editor;
5557 title_string = "Setup Editor";
5559 else if (setup_mode == SETUP_MODE_GRAPHICS)
5561 setup_info = setup_info_graphics;
5562 title_string = "Setup Graphics";
5564 else if (setup_mode == SETUP_MODE_SOUND)
5566 setup_info = setup_info_sound;
5567 title_string = "Setup Sound";
5569 else if (setup_mode == SETUP_MODE_ARTWORK)
5571 setup_info = setup_info_artwork;
5572 title_string = "Custom Artwork";
5574 else if (setup_mode == SETUP_MODE_TOUCH)
5576 setup_info = setup_info_touch;
5577 title_string = "Setup Touch Ctrls";
5579 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5581 setup_info = setup_info_shortcuts;
5582 title_string = "Setup Shortcuts";
5584 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5586 setup_info = setup_info_shortcuts_1;
5587 title_string = "Setup Shortcuts";
5589 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5591 setup_info = setup_info_shortcuts_2;
5592 title_string = "Setup Shortcuts";
5594 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5596 setup_info = setup_info_shortcuts_3;
5597 title_string = "Setup Shortcuts";
5599 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5601 setup_info = setup_info_shortcuts_4;
5602 title_string = "Setup Shortcuts";
5604 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5606 setup_info = setup_info_shortcuts_5;
5607 title_string = "Setup Shortcuts";
5610 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5612 // determine maximal number of setup entries that can be displayed on screen
5614 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5617 // determine maximal number of setup entries available for this setup screen
5619 for (i = 0; setup_info[i].type != 0; i++)
5622 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5624 MapScreenGadgets(max_setup_info);
5627 redraw_mask = fade_mask = REDRAW_ALL;
5634 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5636 static int choice_store[MAX_SETUP_MODES];
5637 static int first_entry_store[MAX_SETUP_MODES];
5638 int choice = choice_store[setup_mode]; /* starts with 0 */
5639 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5641 int y = choice - first_entry;
5643 boolean position_set_by_scrollbar = (dx == 999);
5644 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5645 int num_page_entries;
5647 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5649 if (button == MB_MENU_INITIALIZE)
5651 /* advance to first valid menu entry */
5652 while (choice < num_setup_info &&
5653 setup_info[choice].type & TYPE_SKIP_ENTRY)
5656 if (position_set_by_scrollbar)
5657 first_entry = first_entry_store[setup_mode] = dy;
5659 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5660 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5662 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5664 if (choice < first_entry)
5666 choice = first_entry;
5668 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5671 else if (choice > first_entry + num_page_entries - 1)
5673 choice = first_entry + num_page_entries - 1;
5675 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5679 choice_store[setup_mode] = choice;
5681 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5685 else if (button == MB_MENU_LEAVE)
5689 PlaySound(SND_MENU_ITEM_SELECTING);
5691 for (i = 0; setup_info[i].type != 0; i++)
5693 if (setup_info[i].type & TYPE_LEAVE_MENU)
5695 void (*menu_callback_function)(void) = setup_info[i].value;
5699 menu_callback_function();
5701 break; /* absolutely needed because function changes 'setup_info'! */
5708 if (mx || my) /* mouse input */
5710 x = (mx - mSX) / 32;
5711 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5713 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5715 /* move cursor instead of scrolling when already at start/end of list */
5716 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5718 else if (dy == +1 * SCROLL_LINE &&
5719 first_entry + num_page_entries == max_setup_info)
5722 /* handle scrolling screen one line or page */
5724 y + dy > num_page_entries - 1)
5726 boolean redraw = FALSE;
5728 if (ABS(dy) == SCROLL_PAGE)
5729 step = num_page_entries - 1;
5731 if (dy < 0 && first_entry > 0)
5733 /* scroll page/line up */
5735 first_entry -= step;
5736 if (first_entry < 0)
5741 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5743 /* scroll page/line down */
5745 first_entry += step;
5746 if (first_entry + num_page_entries > max_setup_info)
5747 first_entry = MAX(0, max_setup_info - num_page_entries);
5754 choice += first_entry - first_entry_store[setup_mode];
5756 if (choice < first_entry)
5758 choice = first_entry;
5760 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5763 else if (choice > first_entry + num_page_entries - 1)
5765 choice = first_entry + num_page_entries - 1;
5767 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5770 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5774 if (choice < first_entry ||
5775 choice > first_entry + num_page_entries - 1)
5776 first_entry += SIGN(dy);
5779 first_entry_store[setup_mode] = first_entry;
5780 choice_store[setup_mode] = choice;
5782 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5784 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5786 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5787 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5795 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5797 if (setup_info[choice].type & menu_navigation_type ||
5798 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5799 setup_info[choice].type & TYPE_YES_NO_AUTO)
5800 button = MB_MENU_CHOICE;
5805 /* jump to next non-empty menu entry (up or down) */
5806 while (first_entry + y > 0 &&
5807 first_entry + y < max_setup_info - 1 &&
5808 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
5811 if (!IN_VIS_MENU(x, y))
5813 choice += y - y_old;
5815 if (choice < first_entry)
5816 first_entry = choice;
5817 else if (choice > first_entry + num_page_entries - 1)
5818 first_entry = choice - num_page_entries + 1;
5820 if (first_entry >= 0 &&
5821 first_entry + num_page_entries <= max_setup_info)
5823 first_entry_store[setup_mode] = first_entry;
5825 if (choice < first_entry)
5826 choice = first_entry;
5827 else if (choice > first_entry + num_page_entries - 1)
5828 choice = first_entry + num_page_entries - 1;
5830 choice_store[setup_mode] = choice;
5832 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5834 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5836 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5837 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5844 if (!anyScrollbarGadgetActive() &&
5845 IN_VIS_MENU(x, y) &&
5846 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
5847 y >= 0 && y < num_page_entries)
5851 if (first_entry + y != choice &&
5852 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
5854 PlaySound(SND_MENU_ITEM_ACTIVATING);
5856 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
5857 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
5859 choice = choice_store[setup_mode] = first_entry + y;
5862 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
5864 PlaySound(SND_MENU_ITEM_SELECTING);
5866 /* when selecting key headline, execute function for key value change */
5867 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
5868 setup_info[first_entry + y + 1].type & TYPE_KEY)
5871 /* when selecting string value, execute function for list selection */
5872 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
5873 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
5876 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
5878 void (*menu_callback_function)(void) =
5879 setup_info[first_entry + y].value;
5881 FadeSetFromType(setup_info[first_entry + y].type);
5883 menu_callback_function();
5887 if (setup_info[first_entry + y].type & TYPE_VALUE)
5888 changeSetupValue(y, first_entry + y, dx);
5894 void DrawSetupScreen_Input()
5898 FadeOut(REDRAW_FIELD);
5902 setup_info = setup_info_input;
5904 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5906 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5907 "Joysticks deactivated on this screen");
5909 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5911 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5912 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5913 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5914 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5915 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5916 initCursor(i, IMG_MENU_BUTTON);
5918 DrawCursorAndText_Setup(i, -1, FALSE);
5921 /* create gadgets for setup input menu screen */
5922 FreeScreenGadgets();
5923 CreateScreenGadgets();
5925 /* map gadgets for setup input menu screen */
5926 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5928 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5930 FadeIn(REDRAW_FIELD);
5935 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5937 if (device_name == NULL)
5940 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5943 if (strlen(device_name) > 1)
5945 char c1 = device_name[strlen(device_name) - 1];
5946 char c2 = device_name[strlen(device_name) - 2];
5948 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5949 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5952 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5953 strlen(device_name));
5956 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5959 static struct SetupKeyboardInfo custom_key;
5966 { &custom_key.left, "Joystick Left" },
5967 { &custom_key.right, "Joystick Right" },
5968 { &custom_key.up, "Joystick Up" },
5969 { &custom_key.down, "Joystick Down" },
5970 { &custom_key.snap, "Button 1" },
5971 { &custom_key.drop, "Button 2" }
5973 static char *joystick_name[MAX_PLAYERS] =
5980 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5984 custom_key = setup.input[player_nr].key;
5986 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5987 FONT_INPUT_1_ACTIVE);
5989 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5991 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5992 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5994 if (setup.input[player_nr].use_joystick)
5996 char *device_name = setup.input[player_nr].joy.device_name;
5997 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5998 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6000 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6001 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6005 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6006 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6009 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6011 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6012 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6013 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6014 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6016 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6017 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6018 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6019 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6020 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6021 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6023 for (i = 0; i < 6; i++)
6025 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6027 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6029 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6030 (setup.input[player_nr].use_joystick ?
6032 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6036 static int input_player_nr = 0;
6038 void HandleSetupScreen_Input_Player(int step, int direction)
6040 int old_player_nr = input_player_nr;
6043 new_player_nr = old_player_nr + step * direction;
6044 if (new_player_nr < 0)
6046 if (new_player_nr > MAX_PLAYERS - 1)
6047 new_player_nr = MAX_PLAYERS - 1;
6049 if (new_player_nr != old_player_nr)
6051 input_player_nr = new_player_nr;
6053 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6057 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6059 static int choice = 0;
6062 int pos_start = SETUPINPUT_SCREEN_POS_START;
6063 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6064 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6065 int pos_end = SETUPINPUT_SCREEN_POS_END;
6067 if (button == MB_MENU_INITIALIZE)
6069 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6071 DrawCursorAndText_Setup(choice, -1, TRUE);
6075 else if (button == MB_MENU_LEAVE)
6077 setup_mode = SETUP_MODE_MAIN;
6084 if (mx || my) /* mouse input */
6086 x = (mx - mSX) / 32;
6087 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6089 else if (dx || dy) /* keyboard input */
6091 if (dx && choice == 0)
6092 x = (dx < 0 ? 10 : 12);
6093 else if ((dx && choice == 1) ||
6094 (dx == +1 && choice == 2) ||
6095 (dx == -1 && choice == pos_end))
6096 button = MB_MENU_CHOICE;
6100 if (y >= pos_empty1 && y <= pos_empty2)
6101 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6104 if (y == 0 && dx != 0 && button)
6106 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6108 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6109 y >= pos_start && y <= pos_end &&
6110 !(y >= pos_empty1 && y <= pos_empty2))
6116 DrawCursorAndText_Setup(choice, -1, FALSE);
6117 DrawCursorAndText_Setup(y, -1, TRUE);
6119 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6128 char *device_name = setup.input[input_player_nr].joy.device_name;
6130 if (!setup.input[input_player_nr].use_joystick)
6132 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6134 setJoystickDeviceToNr(device_name, new_device_nr);
6135 setup.input[input_player_nr].use_joystick = TRUE;
6139 int device_nr = getJoystickNrFromDeviceName(device_name);
6140 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6142 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6143 setup.input[input_player_nr].use_joystick = FALSE;
6145 setJoystickDeviceToNr(device_name, new_device_nr);
6148 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6152 if (setup.input[input_player_nr].use_joystick)
6155 CalibrateJoystick(input_player_nr);
6158 CustomizeKeyboard(input_player_nr);
6160 else if (y == pos_end)
6166 setup_mode = SETUP_MODE_MAIN;
6173 void CustomizeKeyboard(int player_nr)
6177 boolean finished = FALSE;
6178 static struct SetupKeyboardInfo custom_key;
6183 } customize_step[] =
6185 { &custom_key.left, "Move Left" },
6186 { &custom_key.right, "Move Right" },
6187 { &custom_key.up, "Move Up" },
6188 { &custom_key.down, "Move Down" },
6189 { &custom_key.snap, "Snap Field" },
6190 { &custom_key.drop, "Drop Element" }
6193 /* read existing key bindings from player setup */
6194 custom_key = setup.input[player_nr].key;
6197 FadeOut(REDRAW_FIELD);
6201 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6204 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6205 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6206 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6207 "Key:", FONT_INPUT_1_ACTIVE);
6208 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6209 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6211 FadeIn(REDRAW_FIELD);
6217 if (PendingEvent()) /* got event */
6225 case EVENT_KEYPRESS:
6227 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6229 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6231 if (key == KSYM_Escape)
6232 FadeSkipNextFadeIn();
6238 /* all keys configured -- wait for "Escape" or "Return" key */
6242 /* press 'Enter' to keep the existing key binding */
6243 if (key == KSYM_Return)
6244 key = *customize_step[step_nr].key;
6246 /* check if key already used */
6247 for (i = 0; i < step_nr; i++)
6248 if (*customize_step[i].key == key)
6253 /* got new key binding */
6254 *customize_step[step_nr].key = key;
6255 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6257 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6258 getKeyNameFromKey(key), FONT_VALUE_1);
6261 /* un-highlight last query */
6262 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6263 customize_step[step_nr - 1].text, FONT_MENU_1);
6264 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6265 "Key:", FONT_MENU_1);
6267 /* press 'Enter' to leave */
6270 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6271 "Press Enter", FONT_TITLE_1);
6275 /* query next key binding */
6276 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6277 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6278 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6279 "Key:", FONT_INPUT_1_ACTIVE);
6280 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6281 getKeyNameFromKey(*customize_step[step_nr].key),
6286 case EVENT_KEYRELEASE:
6287 key_joystick_mapping = 0;
6291 HandleOtherEvents(&event);
6299 /* don't eat all CPU time */
6303 /* write new key bindings back to player setup */
6304 setup.input[player_nr].key = custom_key;
6307 DrawSetupScreen_Input();
6310 static boolean CalibrateJoystickMain(int player_nr)
6312 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6313 int new_joystick_xright = JOYSTICK_XMIDDLE;
6314 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6315 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6316 int new_joystick_xmiddle, new_joystick_ymiddle;
6318 int joystick_fd = joystick.fd[player_nr];
6319 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6320 boolean check[3][3];
6321 int check_remaining = 3 * 3;
6326 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6329 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6333 FadeOut(REDRAW_FIELD);
6337 for (y = 0; y < 3; y++)
6339 for (x = 0; x < 3; x++)
6341 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6342 check[x][y] = FALSE;
6346 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6347 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6348 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6349 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6350 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6351 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6352 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6354 joy_value = Joystick(player_nr);
6355 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6356 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6358 /* eventually uncalibrated center position (joystick could be uncentered) */
6359 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6362 new_joystick_xmiddle = joy_x;
6363 new_joystick_ymiddle = joy_y;
6365 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6367 FadeIn(REDRAW_FIELD);
6369 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6374 if (PendingEvent()) /* got event */
6382 case EVENT_KEYPRESS:
6383 switch (GetEventKey((KeyEvent *)&event, TRUE))
6386 if (check_remaining == 0)
6391 FadeSkipNextFadeIn();
6400 case EVENT_KEYRELEASE:
6401 key_joystick_mapping = 0;
6405 HandleOtherEvents(&event);
6410 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6413 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6414 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6415 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6416 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6418 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6419 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6420 setup.input[player_nr].joy.xright = new_joystick_xright;
6421 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6422 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6423 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6425 CheckJoystickData();
6427 joy_value = Joystick(player_nr);
6429 if (joy_value & JOY_BUTTON && check_remaining == 0)
6432 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6433 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6435 if (x != last_x || y != last_y)
6437 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6438 IMG_MENU_CALIBRATE_YELLOW, 0);
6439 DrawFixedGraphic(xpos + x, ypos + y,
6440 IMG_MENU_CALIBRATE_RED, 0);
6445 if (check_remaining > 0 && !check[x+1][y+1])
6447 check[x+1][y+1] = TRUE;
6455 /* don't eat all CPU time */
6459 /* calibrated center position (joystick should now be centered) */
6460 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6463 new_joystick_xmiddle = joy_x;
6464 new_joystick_ymiddle = joy_y;
6468 /* wait until the last pressed button was released */
6469 while (Joystick(player_nr) & JOY_BUTTON)
6471 if (PendingEvent()) /* got event */
6476 HandleOtherEvents(&event);
6485 void CalibrateJoystick(int player_nr)
6487 if (!CalibrateJoystickMain(player_nr))
6489 char *device_name = setup.input[player_nr].joy.device_name;
6490 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6491 int xpos = mSX - SX;
6492 int ypos = mSY - SY;
6496 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6497 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6500 Delay(2000); /* show error message for a short time */
6505 DrawSetupScreen_Input();
6508 void DrawSetupScreen()
6510 DeactivateJoystick();
6512 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6514 if (setup_mode == SETUP_MODE_INPUT)
6515 DrawSetupScreen_Input();
6516 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6517 DrawChooseTree(&game_speed_current);
6518 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6519 DrawChooseTree(&scroll_delay_current);
6520 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6521 DrawChooseTree(&snapshot_mode_current);
6522 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6523 DrawChooseTree(&screen_mode_current);
6524 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6525 DrawChooseTree(&window_size_current);
6526 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6527 DrawChooseTree(&scaling_type_current);
6528 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6529 DrawChooseTree(&artwork.gfx_current);
6530 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6531 DrawChooseTree(&artwork.snd_current);
6532 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6533 DrawChooseTree(&artwork.mus_current);
6534 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6535 DrawChooseTree(&volume_simple_current);
6536 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6537 DrawChooseTree(&volume_loops_current);
6538 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6539 DrawChooseTree(&volume_music_current);
6540 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6541 DrawChooseTree(&touch_control_current);
6542 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6543 DrawChooseTree(&move_distance_current);
6544 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6545 DrawChooseTree(&drop_distance_current);
6547 DrawSetupScreen_Generic();
6553 void RedrawSetupScreenAfterFullscreenToggle()
6555 if (setup_mode == SETUP_MODE_GRAPHICS ||
6556 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6558 // update list selection from "setup.window_scaling_percent"
6559 execSetupGraphics_setWindowSizes(TRUE);
6565 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6567 if (setup_mode == SETUP_MODE_INPUT)
6568 HandleSetupScreen_Input(mx, my, dx, dy, button);
6569 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6570 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6571 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6572 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6573 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6574 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6575 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6576 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6577 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6578 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6579 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6580 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6581 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6582 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6583 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6584 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6585 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6586 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6587 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6588 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6589 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6590 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6591 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6592 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6593 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6594 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6595 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6596 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6597 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6598 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6600 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6603 void HandleGameActions()
6605 if (game_status != GAME_MODE_PLAYING)
6608 GameActions(); /* main game loop */
6610 if (tape.auto_play && !tape.playing)
6611 AutoPlayTape(); /* continue automatically playing next tape */
6615 /* ---------- new screen button stuff -------------------------------------- */
6617 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6621 case SCREEN_CTRL_ID_PREV_LEVEL:
6622 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6623 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6626 case SCREEN_CTRL_ID_NEXT_LEVEL:
6627 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6628 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6631 case SCREEN_CTRL_ID_PREV_PLAYER:
6632 *x = mSX + TILEX * 10;
6633 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6636 case SCREEN_CTRL_ID_NEXT_PLAYER:
6637 *x = mSX + TILEX * 12;
6638 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6642 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6648 int gfx_unpressed, gfx_pressed;
6649 void (*get_gadget_position)(int *, int *, int);
6653 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6656 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6657 getScreenMenuButtonPos,
6658 SCREEN_CTRL_ID_PREV_LEVEL,
6663 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6664 getScreenMenuButtonPos,
6665 SCREEN_CTRL_ID_NEXT_LEVEL,
6670 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6671 getScreenMenuButtonPos,
6672 SCREEN_CTRL_ID_PREV_PLAYER,
6677 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6678 getScreenMenuButtonPos,
6679 SCREEN_CTRL_ID_NEXT_PLAYER,
6687 int gfx_unpressed, gfx_pressed;
6691 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6694 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6695 -1, -1, /* these values are not constant, but can change at runtime */
6696 SCREEN_CTRL_ID_SCROLL_UP,
6700 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6701 -1, -1, /* these values are not constant, but can change at runtime */
6702 SCREEN_CTRL_ID_SCROLL_DOWN,
6709 int gfx_unpressed, gfx_pressed;
6715 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6718 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6719 -1, -1, /* these values are not constant, but can change at runtime */
6720 -1, -1, /* these values are not constant, but can change at runtime */
6721 GD_TYPE_SCROLLBAR_VERTICAL,
6722 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6723 "scroll level series vertically"
6727 static void CreateScreenMenubuttons()
6729 struct GadgetInfo *gi;
6730 unsigned int event_mask;
6733 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6735 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6736 int gfx_unpressed, gfx_pressed;
6737 int x, y, width, height;
6738 int gd_x1, gd_x2, gd_y1, gd_y2;
6739 int id = menubutton_info[i].gadget_id;
6741 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6743 menubutton_info[i].get_gadget_position(&x, &y, id);
6745 width = SC_MENUBUTTON_XSIZE;
6746 height = SC_MENUBUTTON_YSIZE;
6748 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6749 gfx_pressed = menubutton_info[i].gfx_pressed;
6750 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6751 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6752 gd_x1 = graphic_info[gfx_unpressed].src_x;
6753 gd_y1 = graphic_info[gfx_unpressed].src_y;
6754 gd_x2 = graphic_info[gfx_pressed].src_x;
6755 gd_y2 = graphic_info[gfx_pressed].src_y;
6757 gi = CreateGadget(GDI_CUSTOM_ID, id,
6758 GDI_CUSTOM_TYPE_ID, i,
6759 GDI_INFO_TEXT, menubutton_info[i].infotext,
6764 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6765 GDI_STATE, GD_BUTTON_UNPRESSED,
6766 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6767 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6768 GDI_DIRECT_DRAW, FALSE,
6769 GDI_EVENT_MASK, event_mask,
6770 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6774 Error(ERR_EXIT, "cannot create gadget");
6776 screen_gadget[id] = gi;
6780 static void CreateScreenScrollbuttons()
6782 struct GadgetInfo *gi;
6783 unsigned int event_mask;
6786 /* these values are not constant, but can change at runtime */
6787 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6788 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6789 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6790 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6792 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6794 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6795 int gfx_unpressed, gfx_pressed;
6796 int x, y, width, height;
6797 int gd_x1, gd_x2, gd_y1, gd_y2;
6798 int id = scrollbutton_info[i].gadget_id;
6800 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6802 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6803 y = mSY + scrollbutton_info[i].y;
6804 width = SC_SCROLLBUTTON_XSIZE;
6805 height = SC_SCROLLBUTTON_YSIZE;
6807 /* correct scrollbar position if placed outside menu (playfield) area */
6808 if (x > SX + SC_SCROLL_UP_XPOS)
6809 x = SX + SC_SCROLL_UP_XPOS;
6811 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6812 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6813 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6815 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6816 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6817 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6818 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6819 gd_x1 = graphic_info[gfx_unpressed].src_x;
6820 gd_y1 = graphic_info[gfx_unpressed].src_y;
6821 gd_x2 = graphic_info[gfx_pressed].src_x;
6822 gd_y2 = graphic_info[gfx_pressed].src_y;
6824 gi = CreateGadget(GDI_CUSTOM_ID, id,
6825 GDI_CUSTOM_TYPE_ID, i,
6826 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6831 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6832 GDI_STATE, GD_BUTTON_UNPRESSED,
6833 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6834 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6835 GDI_DIRECT_DRAW, FALSE,
6836 GDI_EVENT_MASK, event_mask,
6837 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6841 Error(ERR_EXIT, "cannot create gadget");
6843 screen_gadget[id] = gi;
6847 static void CreateScreenScrollbars()
6851 /* these values are not constant, but can change at runtime */
6852 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6853 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6854 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6855 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6857 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6859 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6860 int gfx_unpressed, gfx_pressed;
6861 int x, y, width, height;
6862 int gd_x1, gd_x2, gd_y1, gd_y2;
6863 struct GadgetInfo *gi;
6864 int items_max, items_visible, item_position;
6865 unsigned int event_mask;
6866 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6867 int id = scrollbar_info[i].gadget_id;
6869 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6871 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6872 y = mSY + scrollbar_info[i].y;
6873 width = scrollbar_info[i].width;
6874 height = scrollbar_info[i].height;
6876 /* correct scrollbar position if placed outside menu (playfield) area */
6877 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6878 x = SX + SC_SCROLL_VERTICAL_XPOS;
6880 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6881 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6883 items_max = num_page_entries;
6884 items_visible = num_page_entries;
6887 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6888 gfx_pressed = scrollbar_info[i].gfx_pressed;
6889 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6890 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6891 gd_x1 = graphic_info[gfx_unpressed].src_x;
6892 gd_y1 = graphic_info[gfx_unpressed].src_y;
6893 gd_x2 = graphic_info[gfx_pressed].src_x;
6894 gd_y2 = graphic_info[gfx_pressed].src_y;
6896 gi = CreateGadget(GDI_CUSTOM_ID, id,
6897 GDI_CUSTOM_TYPE_ID, i,
6898 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6903 GDI_TYPE, scrollbar_info[i].type,
6904 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6905 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6906 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6907 GDI_WHEEL_AREA_X, SX,
6908 GDI_WHEEL_AREA_Y, SY,
6909 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6910 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6911 GDI_STATE, GD_BUTTON_UNPRESSED,
6912 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6913 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6914 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6915 GDI_DIRECT_DRAW, FALSE,
6916 GDI_EVENT_MASK, event_mask,
6917 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6921 Error(ERR_EXIT, "cannot create gadget");
6923 screen_gadget[id] = gi;
6927 void CreateScreenGadgets()
6929 int last_game_status = game_status; /* save current game status */
6931 CreateScreenMenubuttons();
6933 CreateScreenScrollbuttons();
6934 CreateScreenScrollbars();
6936 game_status = last_game_status; /* restore current game status */
6939 void FreeScreenGadgets()
6943 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6944 FreeGadget(screen_gadget[i]);
6947 void MapScreenMenuGadgets(int screen_mask)
6951 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6952 if (screen_mask & menubutton_info[i].screen_mask)
6953 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6956 void MapScreenGadgets(int num_entries)
6960 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6963 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6964 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6966 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6967 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6970 void MapScreenTreeGadgets(TreeInfo *ti)
6972 MapScreenGadgets(numTreeInfoInGroup(ti));
6975 static void HandleScreenGadgets(struct GadgetInfo *gi)
6977 int id = gi->custom_id;
6978 int button = gi->event.button;
6979 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6983 case SCREEN_CTRL_ID_PREV_LEVEL:
6984 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6987 case SCREEN_CTRL_ID_NEXT_LEVEL:
6988 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6991 case SCREEN_CTRL_ID_PREV_PLAYER:
6992 HandleSetupScreen_Input_Player(step, -1);
6995 case SCREEN_CTRL_ID_NEXT_PLAYER:
6996 HandleSetupScreen_Input_Player(step, +1);
6999 case SCREEN_CTRL_ID_SCROLL_UP:
7000 if (game_status == GAME_MODE_LEVELS)
7001 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7002 else if (game_status == GAME_MODE_LEVELNR)
7003 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7004 else if (game_status == GAME_MODE_SETUP)
7005 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7008 case SCREEN_CTRL_ID_SCROLL_DOWN:
7009 if (game_status == GAME_MODE_LEVELS)
7010 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7011 else if (game_status == GAME_MODE_LEVELNR)
7012 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7013 else if (game_status == GAME_MODE_SETUP)
7014 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7017 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7018 if (game_status == GAME_MODE_LEVELS)
7019 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7020 else if (game_status == GAME_MODE_LEVELNR)
7021 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7022 else if (game_status == GAME_MODE_SETUP)
7023 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);