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_SCREEN_MODE 18
64 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
65 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
66 #define SETUP_MODE_CHOOSE_GRAPHICS 21
67 #define SETUP_MODE_CHOOSE_SOUNDS 22
68 #define SETUP_MODE_CHOOSE_MUSIC 23
69 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 24
70 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 25
71 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 26
72 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 27
73 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 28
74 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 29
76 #define MAX_SETUP_MODES 30
78 /* for input setup functions */
79 #define SETUPINPUT_SCREEN_POS_START 0
80 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
81 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
82 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
84 /* for various menu stuff */
85 #define MENU_SCREEN_START_XPOS 1
86 #define MENU_SCREEN_START_YPOS 2
87 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
88 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
89 #define MENU_TITLE1_YPOS 8
90 #define MENU_TITLE2_YPOS 46
91 #define MENU_SCREEN_INFO_XSTART 16
92 #define MENU_SCREEN_INFO_YSTART1 100
93 #define MENU_SCREEN_INFO_YSTART2 128
94 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
95 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
96 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
97 MENU_SCREEN_INFO_YSTART2 - \
99 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
100 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
101 MENU_SCREEN_INFO_YSTEP, \
102 MAX_INFO_ELEMENTS_ON_SCREEN)
103 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
104 #define MAX_MENU_TEXT_LENGTH_BIG 13
105 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
107 /* buttons and scrollbars identifiers */
108 #define SCREEN_CTRL_ID_PREV_LEVEL 0
109 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
110 #define SCREEN_CTRL_ID_PREV_PLAYER 2
111 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
112 #define SCREEN_CTRL_ID_SCROLL_UP 4
113 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
114 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
116 #define NUM_SCREEN_GADGETS 7
118 #define NUM_SCREEN_MENUBUTTONS 4
119 #define NUM_SCREEN_SCROLLBUTTONS 2
120 #define NUM_SCREEN_SCROLLBARS 1
122 #define SCREEN_MASK_MAIN (1 << 0)
123 #define SCREEN_MASK_INPUT (1 << 1)
125 /* graphic position and size values for buttons and scrollbars */
126 #define SC_MENUBUTTON_XSIZE TILEX
127 #define SC_MENUBUTTON_YSIZE TILEY
129 #define SC_SCROLLBUTTON_XSIZE TILEX
130 #define SC_SCROLLBUTTON_YSIZE TILEY
132 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
134 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
135 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
136 SC_SCROLLBUTTON_YSIZE)
138 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
139 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
141 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
142 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
143 SC_SCROLLBUTTON_YSIZE)
145 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
146 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
147 SC_SCROLL_VERTICAL_YSIZE)
149 #define SC_BORDER_SIZE 14
152 /* forward declarations of internal functions */
153 static void HandleScreenGadgets(struct GadgetInfo *);
154 static void HandleSetupScreen_Generic(int, int, int, int, int);
155 static void HandleSetupScreen_Input(int, int, int, int, int);
156 static void CustomizeKeyboard(int);
157 static void CalibrateJoystick(int);
158 static void execSetupGame(void);
159 static void execSetupGraphics(void);
160 static void execSetupSound(void);
161 static void execSetupTouch(void);
162 static void execSetupArtwork(void);
163 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
165 static void DrawChooseLevelSet(void);
166 static void DrawChooseLevelNr(void);
167 static void DrawInfoScreen(void);
168 static void DrawAndFadeInInfoScreen(int);
169 static void DrawSetupScreen(void);
171 static void DrawInfoScreenExt(int, int);
172 static void DrawInfoScreen_NotAvailable(char *, char *);
173 static void DrawInfoScreen_HelpAnim(int, int, boolean);
174 static void DrawInfoScreen_HelpText(int, int, int, int);
175 static void HandleInfoScreen_Main(int, int, int, int, int);
176 static void HandleInfoScreen_TitleScreen(int);
177 static void HandleInfoScreen_Elements(int);
178 static void HandleInfoScreen_Music(int);
179 static void HandleInfoScreen_Credits(int);
180 static void HandleInfoScreen_Program(int);
181 static void HandleInfoScreen_Version(int);
183 static void MapScreenMenuGadgets(int);
184 static void MapScreenGadgets(int);
185 static void MapScreenTreeGadgets(TreeInfo *);
187 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
189 static int info_mode = INFO_MODE_MAIN;
190 static int setup_mode = SETUP_MODE_MAIN;
192 static TreeInfo *screen_modes = NULL;
193 static TreeInfo *screen_mode_current = NULL;
195 static TreeInfo *window_sizes = NULL;
196 static TreeInfo *window_size_current = NULL;
198 static TreeInfo *scaling_types = NULL;
199 static TreeInfo *scaling_type_current = NULL;
201 static TreeInfo *scroll_delays = NULL;
202 static TreeInfo *scroll_delay_current = NULL;
204 static TreeInfo *game_speeds = NULL;
205 static TreeInfo *game_speed_current = NULL;
207 static TreeInfo *volumes_simple = NULL;
208 static TreeInfo *volume_simple_current = NULL;
210 static TreeInfo *volumes_loops = NULL;
211 static TreeInfo *volume_loops_current = NULL;
213 static TreeInfo *volumes_music = NULL;
214 static TreeInfo *volume_music_current = NULL;
216 static TreeInfo *touch_controls = NULL;
217 static TreeInfo *touch_control_current = NULL;
219 static TreeInfo *move_distances = NULL;
220 static TreeInfo *move_distance_current = NULL;
222 static TreeInfo *drop_distances = NULL;
223 static TreeInfo *drop_distance_current = NULL;
225 static TreeInfo *level_number = NULL;
226 static TreeInfo *level_number_current = NULL;
232 } window_sizes_list[] =
237 { 100, "100 % (Default)" },
254 } scaling_types_list[] =
256 { SCALING_QUALITY_NEAREST, "None" },
257 { SCALING_QUALITY_LINEAR, "Linear" },
258 { SCALING_QUALITY_BEST, "Anisotropic" },
267 } game_speeds_list[] =
276 { 1000, "1/1s (Extremely Slow)" },
281 { 29, "1/35s (Original Supaplex)" },
283 { 20, "1/50s (Normal Speed)" },
284 { 14, "1/70s (Maximum Supaplex)" },
288 { 1, "1/1000s (Extremely Fast)" },
298 } scroll_delays_list[] =
300 { 0, "0 Tiles (No Scroll Delay)" },
303 { 3, "3 Tiles (Default)" },
308 { 8, "8 Tiles (Maximum Scroll Delay)"},
341 } touch_controls_list[] =
343 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
344 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
368 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
369 (s) <= GAME_MODE_SETUP ? (s) : \
370 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
371 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
373 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
374 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
375 (i) <= INFO_MODE_LEVELSET ? (i) : \
378 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
379 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
380 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
381 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
382 SETUP_MODE_CHOOSE_ARTWORK : \
383 SETUP_MODE_CHOOSE_OTHER)
385 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
386 menu.draw_xoffset[GAME_MODE_INFO] : \
387 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
388 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
389 menu.draw_yoffset[GAME_MODE_INFO] : \
390 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
392 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
393 menu.draw_xoffset[GAME_MODE_SETUP] : \
394 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
395 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
396 menu.draw_yoffset[GAME_MODE_SETUP] : \
397 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
399 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
400 DRAW_XOFFSET_INFO(info_mode) : \
401 (s) == GAME_MODE_SETUP ? \
402 DRAW_XOFFSET_SETUP(setup_mode) : \
403 menu.draw_xoffset[DRAW_MODE(s)])
404 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
405 DRAW_YOFFSET_INFO(info_mode) : \
406 (s) == GAME_MODE_SETUP ? \
407 DRAW_YOFFSET_SETUP(setup_mode) : \
408 menu.draw_yoffset[DRAW_MODE(s)])
410 #define mSX (SX + DRAW_XOFFSET(game_status))
411 #define mSY (SY + DRAW_YOFFSET(game_status))
413 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
414 menu.list_size[game_status] : \
415 MAX_MENU_ENTRIES_ON_SCREEN)
417 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
418 NUM_MENU_ENTRIES_ON_SCREEN)
421 /* title display and control definitions */
423 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
424 2 * MAX_NUM_TITLE_MESSAGES)
426 #define NO_DIRECT_LEVEL_SELECT (-1)
429 static int num_title_screens = 0;
431 struct TitleControlInfo
439 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
441 /* main menu display and control definitions */
443 #define MAIN_CONTROL_NAME 0
444 #define MAIN_CONTROL_LEVELS 1
445 #define MAIN_CONTROL_SCORES 2
446 #define MAIN_CONTROL_EDITOR 3
447 #define MAIN_CONTROL_INFO 4
448 #define MAIN_CONTROL_GAME 5
449 #define MAIN_CONTROL_SETUP 6
450 #define MAIN_CONTROL_QUIT 7
451 #define MAIN_CONTROL_PREV_LEVEL 8
452 #define MAIN_CONTROL_NEXT_LEVEL 9
453 #define MAIN_CONTROL_FIRST_LEVEL 10
454 #define MAIN_CONTROL_LAST_LEVEL 11
455 #define MAIN_CONTROL_LEVEL_NUMBER 12
456 #define MAIN_CONTROL_LEVEL_INFO_1 13
457 #define MAIN_CONTROL_LEVEL_INFO_2 14
458 #define MAIN_CONTROL_LEVEL_NAME 15
459 #define MAIN_CONTROL_LEVEL_AUTHOR 16
460 #define MAIN_CONTROL_LEVEL_YEAR 17
461 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
462 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
463 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
464 #define MAIN_CONTROL_TITLE_1 21
465 #define MAIN_CONTROL_TITLE_2 22
466 #define MAIN_CONTROL_TITLE_3 23
468 static char str_main_text_name[10];
469 static char str_main_text_first_level[10];
470 static char str_main_text_last_level[10];
471 static char str_main_text_level_number[10];
473 static char *main_text_name = str_main_text_name;
474 static char *main_text_first_level = str_main_text_first_level;
475 static char *main_text_last_level = str_main_text_last_level;
476 static char *main_text_level_number = str_main_text_level_number;
477 static char *main_text_levels = "Levelset";
478 static char *main_text_scores = "Hall Of Fame";
479 static char *main_text_editor = "Level Creator";
480 static char *main_text_info = "Info Screen";
481 static char *main_text_game = "Start Game";
482 static char *main_text_setup = "Setup";
483 static char *main_text_quit = "Quit";
484 static char *main_text_level_name = level.name;
485 static char *main_text_level_author = level.author;
486 static char *main_text_level_year = NULL;
487 static char *main_text_level_imported_from = NULL;
488 static char *main_text_level_imported_by = NULL;
489 static char *main_text_level_tested_by = NULL;
490 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
491 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
492 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
494 struct MainControlInfo
498 struct MenuPosInfo *pos_button;
501 struct TextPosInfo *pos_text;
504 struct TextPosInfo *pos_input;
508 static struct MainControlInfo main_controls[] =
512 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
513 &menu.main.text.name, &main_text_name,
514 &menu.main.input.name, &setup.player_name,
518 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
519 &menu.main.text.levels, &main_text_levels,
524 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
525 &menu.main.text.scores, &main_text_scores,
530 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
531 &menu.main.text.editor, &main_text_editor,
536 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
537 &menu.main.text.info, &main_text_info,
542 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
543 &menu.main.text.game, &main_text_game,
548 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
549 &menu.main.text.setup, &main_text_setup,
554 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
555 &menu.main.text.quit, &main_text_quit,
559 /* (these two buttons are real gadgets) */
561 MAIN_CONTROL_PREV_LEVEL,
562 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
567 MAIN_CONTROL_NEXT_LEVEL,
568 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
574 MAIN_CONTROL_FIRST_LEVEL,
576 &menu.main.text.first_level, &main_text_first_level,
580 MAIN_CONTROL_LAST_LEVEL,
582 &menu.main.text.last_level, &main_text_last_level,
586 MAIN_CONTROL_LEVEL_NUMBER,
588 &menu.main.text.level_number, &main_text_level_number,
592 MAIN_CONTROL_LEVEL_INFO_1,
594 &menu.main.text.level_info_1, NULL,
598 MAIN_CONTROL_LEVEL_INFO_2,
600 &menu.main.text.level_info_2, NULL,
604 MAIN_CONTROL_LEVEL_NAME,
606 &menu.main.text.level_name, &main_text_level_name,
610 MAIN_CONTROL_LEVEL_AUTHOR,
612 &menu.main.text.level_author, &main_text_level_author,
616 MAIN_CONTROL_LEVEL_YEAR,
618 &menu.main.text.level_year, &main_text_level_year,
622 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
624 &menu.main.text.level_imported_from, &main_text_level_imported_from,
628 MAIN_CONTROL_LEVEL_IMPORTED_BY,
630 &menu.main.text.level_imported_by, &main_text_level_imported_by,
634 MAIN_CONTROL_LEVEL_TESTED_BY,
636 &menu.main.text.level_tested_by, &main_text_level_tested_by,
640 MAIN_CONTROL_TITLE_1,
642 &menu.main.text.title_1, &main_text_title_1,
646 MAIN_CONTROL_TITLE_2,
648 &menu.main.text.title_2, &main_text_title_2,
652 MAIN_CONTROL_TITLE_3,
654 &menu.main.text.title_3, &main_text_title_3,
667 static int getTitleScreenGraphic(int nr, boolean initial)
669 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
672 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
674 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
678 static int getTitleScreenGameMode(boolean initial)
680 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
684 static int getTitleMessageGameMode(boolean initial)
686 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
690 static int getTitleScreenBackground(boolean initial)
692 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
697 static int getTitleMessageBackground(int nr, boolean initial)
699 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
703 static int getTitleBackground(int nr, boolean initial, boolean is_image)
705 int base = (is_image ?
706 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
707 IMG_BACKGROUND_TITLESCREEN_1) :
708 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
709 IMG_BACKGROUND_TITLEMESSAGE_1));
710 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
711 IMG_BACKGROUND_TITLE);
712 int graphic_local = base + nr;
714 if (graphic_info[graphic_local].bitmap != NULL)
715 return graphic_local;
717 if (graphic_info[graphic_global].bitmap != NULL)
718 return graphic_global;
720 return IMG_UNDEFINED;
723 static int getTitleSound(struct TitleControlInfo *tci)
725 boolean is_image = tci->is_image;
726 int initial = tci->initial;
727 int nr = tci->local_nr;
728 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
729 int base = (is_image ?
730 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
731 SND_BACKGROUND_TITLESCREEN_1) :
732 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
733 SND_BACKGROUND_TITLEMESSAGE_1));
734 int sound_global = menu.sound[mode];
735 int sound_local = base + nr;
738 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
739 nr, initial, is_image,
740 sound_global, getSoundListEntry(sound_global)->filename,
741 sound_local, getSoundListEntry(sound_local)->filename);
744 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
747 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
750 return SND_UNDEFINED;
753 static int getTitleMusic(struct TitleControlInfo *tci)
755 boolean is_image = tci->is_image;
756 int initial = tci->initial;
757 int nr = tci->local_nr;
758 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
759 int base = (is_image ?
760 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
761 MUS_BACKGROUND_TITLESCREEN_1) :
762 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
763 MUS_BACKGROUND_TITLEMESSAGE_1));
764 int music_global = menu.music[mode];
765 int music_local = base + nr;
768 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
769 nr, initial, is_image,
770 music_global, getMusicListEntry(music_global)->filename,
771 music_local, getMusicListEntry(music_local)->filename);
774 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
777 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
780 return MUS_UNDEFINED;
783 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
785 boolean is_image = tci->is_image;
786 int initial = tci->initial;
787 int nr = tci->local_nr;
788 struct TitleFadingInfo ti;
792 int graphic = getTitleScreenGraphic(nr, initial);
794 /* initialize fading control values to default title config settings */
795 ti = (initial ? title_initial_default : title_default);
797 /* override default settings with image config settings, if defined */
798 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
799 ti.fade_mode = graphic_info[graphic].fade_mode;
800 if (graphic_info[graphic].fade_delay > -1)
801 ti.fade_delay = graphic_info[graphic].fade_delay;
802 if (graphic_info[graphic].post_delay > -1)
803 ti.post_delay = graphic_info[graphic].post_delay;
804 if (graphic_info[graphic].auto_delay > -1)
805 ti.auto_delay = graphic_info[graphic].auto_delay;
811 ti.fade_mode = titlemessage_initial[nr].fade_mode;
812 ti.fade_delay = titlemessage_initial[nr].fade_delay;
813 ti.post_delay = titlemessage_initial[nr].post_delay;
814 ti.auto_delay = titlemessage_initial[nr].auto_delay;
818 ti.fade_mode = titlemessage[nr].fade_mode;
819 ti.fade_delay = titlemessage[nr].fade_delay;
820 ti.post_delay = titlemessage[nr].post_delay;
821 ti.auto_delay = titlemessage[nr].auto_delay;
828 static int compareTitleControlInfo(const void *object1, const void *object2)
830 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
831 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
834 if (tci1->initial != tci2->initial)
835 compare_result = (tci1->initial ? -1 : +1);
836 else if (tci1->sort_priority != tci2->sort_priority)
837 compare_result = tci1->sort_priority - tci2->sort_priority;
838 else if (tci1->is_image != tci2->is_image)
839 compare_result = (tci1->is_image ? -1 : +1);
841 compare_result = tci1->local_nr - tci2->local_nr;
843 return compare_result;
846 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
848 int nr, int sort_priority)
850 title_controls[num_title_screens].is_image = is_image;
851 title_controls[num_title_screens].initial = initial;
852 title_controls[num_title_screens].local_nr = nr;
853 title_controls[num_title_screens].sort_priority = sort_priority;
858 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
862 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
864 int graphic = getTitleScreenGraphic(i, initial);
865 Bitmap *bitmap = graphic_info[graphic].bitmap;
866 int sort_priority = graphic_info[graphic].sort_priority;
869 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
872 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
874 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
875 char *filename = getLevelSetTitleMessageFilename(i, initial);
876 int sort_priority = tmi->sort_priority;
878 if (filename != NULL)
879 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
883 static void InitializeTitleControls(boolean show_title_initial)
885 num_title_screens = 0;
887 /* 1st step: initialize title screens for game start (only when starting) */
888 if (show_title_initial)
889 InitializeTitleControls_CheckTitleInfo(TRUE);
891 /* 2nd step: initialize title screens for current level set */
892 InitializeTitleControls_CheckTitleInfo(FALSE);
894 /* sort title screens according to sort_priority and title number */
895 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
896 compareTitleControlInfo);
899 static boolean visibleMenuPos(struct MenuPosInfo *pos)
901 return (pos != NULL && pos->x != -1 && pos->y != -1);
904 static boolean visibleTextPos(struct TextPosInfo *pos)
906 return (pos != NULL && pos->x != -1 && pos->y != -1);
909 static void InitializeMainControls()
911 boolean local_team_mode = (!options.network && setup.team_mode);
914 /* set main control text values to dynamically determined values */
915 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
917 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
918 menu.main.text.first_level.size));
919 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
920 menu.main.text.last_level.size));
921 strcpy(main_text_level_number, int2str(level_nr,
922 menu.main.text.level_number.size));
924 main_text_level_year = leveldir_current->year;
925 main_text_level_imported_from = leveldir_current->imported_from;
926 main_text_level_imported_by = leveldir_current->imported_by;
927 main_text_level_tested_by = leveldir_current->tested_by;
929 /* set main control screen positions to dynamically determined values */
930 for (i = 0; main_controls[i].nr != -1; i++)
932 struct MainControlInfo *mci = &main_controls[i];
934 struct MenuPosInfo *pos_button = mci->pos_button;
935 struct TextPosInfo *pos_text = mci->pos_text;
936 struct TextPosInfo *pos_input = mci->pos_input;
937 char *text = (mci->text ? *mci->text : NULL);
938 char *input = (mci->input ? *mci->input : NULL);
939 int button_graphic = mci->button_graphic;
940 int font_text = (pos_text ? pos_text->font : -1);
941 int font_input = (pos_input ? pos_input->font : -1);
943 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
944 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
945 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
946 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
947 int text_chars = (text != NULL ? strlen(text) : 0);
948 int input_chars = (input != NULL ? strlen(input) : 0);
951 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
953 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
954 int text_width = font_text_width * text_chars;
955 int text_height = font_text_height;
956 int input_width = font_input_width * input_chars;
957 int input_height = font_input_height;
959 if (nr == MAIN_CONTROL_NAME)
961 menu.main.input.name.width = input_width;
962 menu.main.input.name.height = input_height;
965 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
967 pos_button->width = button_width;
968 pos_button->height = button_height;
971 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
973 /* calculate size for non-clickable text -- needed for text alignment */
974 boolean calculate_text_size = (pos_button == NULL && text != NULL);
976 if (pos_text->width == -1 || calculate_text_size)
977 pos_text->width = text_width;
978 if (pos_text->height == -1 || calculate_text_size)
979 pos_text->height = text_height;
981 if (visibleMenuPos(pos_button))
983 if (pos_text->x == -1)
984 pos_text->x = pos_button->x + pos_button->width;
985 if (pos_text->y == -1)
987 pos_button->y + (pos_button->height - pos_text->height) / 2;
991 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
993 if (visibleTextPos(pos_text))
995 if (pos_input->x == -1)
996 pos_input->x = pos_text->x + pos_text->width;
997 if (pos_input->y == -1)
998 pos_input->y = pos_text->y;
1001 if (pos_input->width == -1)
1002 pos_input->width = input_width;
1003 if (pos_input->height == -1)
1004 pos_input->height = input_height;
1009 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1010 int graphic, boolean pressed)
1012 struct GraphicInfo *g = &graphic_info[graphic];
1015 int xoffset = (pressed ? g->pressed_xoffset : 0);
1016 int yoffset = (pressed ? g->pressed_yoffset : 0);
1018 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1020 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1021 g->width, g->height, dst_x, dst_y);
1024 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1025 boolean active_input,
1026 boolean pressed_button)
1030 for (i = 0; main_controls[i].nr != -1; i++)
1032 struct MainControlInfo *mci = &main_controls[i];
1034 if (mci->nr == nr || nr == -1)
1036 struct MenuPosInfo *pos_button = mci->pos_button;
1037 struct TextPosInfo *pos_text = mci->pos_text;
1038 struct TextPosInfo *pos_input = mci->pos_input;
1039 char *text = (mci->text ? *mci->text : NULL);
1040 char *input = (mci->input ? *mci->input : NULL);
1041 int button_graphic = mci->button_graphic;
1042 int font_text = (pos_text ? pos_text->font : -1);
1043 int font_input = (pos_input ? pos_input->font : -1);
1047 button_graphic = BUTTON_ACTIVE(button_graphic);
1048 font_text = FONT_ACTIVE(font_text);
1053 font_input = FONT_ACTIVE(font_input);
1056 if (visibleMenuPos(pos_button))
1058 struct MenuPosInfo *pos = pos_button;
1059 int x = mSX + pos->x;
1060 int y = mSY + pos->y;
1062 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1063 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1066 if (visibleTextPos(pos_text) && text != NULL)
1068 struct TextPosInfo *pos = pos_text;
1069 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1070 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1073 /* (check why/if this is needed) */
1074 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1076 DrawText(x, y, text, font_text);
1079 if (visibleTextPos(pos_input) && input != NULL)
1081 struct TextPosInfo *pos = pos_input;
1082 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1083 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1086 /* (check why/if this is needed) */
1087 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1089 DrawText(x, y, input, font_input);
1095 static void DrawCursorAndText_Main(int nr, boolean active_text,
1096 boolean pressed_button)
1098 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1102 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1103 boolean pressed_button)
1105 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1109 static struct MainControlInfo *getMainControlInfo(int nr)
1113 for (i = 0; main_controls[i].nr != -1; i++)
1114 if (main_controls[i].nr == nr)
1115 return &main_controls[i];
1120 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1125 int rect_x = ALIGNED_TEXT_XPOS(rect);
1126 int rect_y = ALIGNED_TEXT_YPOS(rect);
1128 return (x >= rect_x && x < rect_x + rect->width &&
1129 y >= rect_y && y < rect_y + rect->height);
1132 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1137 int rect_x = ALIGNED_TEXT_XPOS(rect);
1138 int rect_y = ALIGNED_TEXT_YPOS(rect);
1141 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1142 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1143 (x >= rect_x && x < rect_x + rect->width &&
1144 y >= rect_y && y < rect_y + rect->height));
1147 return (x >= rect_x && x < rect_x + rect->width &&
1148 y >= rect_y && y < rect_y + rect->height);
1151 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1153 static int cursor_array[MAX_LEV_FIELDY];
1154 int x = mSX + TILEX * xpos;
1155 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1160 cursor_array[ypos] = graphic;
1162 graphic = cursor_array[ypos];
1166 graphic = BUTTON_ACTIVE(graphic);
1168 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1169 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1172 static void initCursor(int ypos, int graphic)
1174 drawCursorExt(0, ypos, FALSE, graphic);
1177 static void drawCursor(int ypos, boolean active)
1179 drawCursorExt(0, ypos, active, -1);
1182 static void drawCursorXY(int xpos, int ypos, int graphic)
1184 drawCursorExt(xpos, ypos, FALSE, graphic);
1187 static void drawChooseTreeCursor(int ypos, boolean active)
1189 int last_game_status = game_status; /* save current game status */
1191 drawCursorExt(0, ypos, active, -1);
1193 game_status = last_game_status; /* restore current game status */
1198 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1199 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1202 int effectiveGameStatus()
1204 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1205 return GAME_MODE_TITLE;
1210 void DrawTitleScreenImage(int nr, boolean initial)
1212 int graphic = getTitleScreenGraphic(nr, initial);
1213 Bitmap *bitmap = graphic_info[graphic].bitmap;
1214 int width = graphic_info[graphic].width;
1215 int height = graphic_info[graphic].height;
1216 int src_x = graphic_info[graphic].src_x;
1217 int src_y = graphic_info[graphic].src_y;
1223 if (width > WIN_XSIZE)
1225 /* image width too large for window => center image horizontally */
1226 src_x = (width - WIN_XSIZE) / 2;
1230 if (height > WIN_YSIZE)
1232 /* image height too large for window => center image vertically */
1233 src_y = (height - WIN_YSIZE) / 2;
1237 /* always display title screens centered */
1238 dst_x = (WIN_XSIZE - width) / 2;
1239 dst_y = (WIN_YSIZE - height) / 2;
1241 SetDrawBackgroundMask(REDRAW_ALL);
1242 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1244 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1246 if (DrawingOnBackground(dst_x, dst_y))
1247 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1249 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1251 redraw_mask = REDRAW_ALL;
1254 void DrawTitleScreenMessage(int nr, boolean initial)
1256 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1257 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1258 int last_game_status = game_status; /* save current game status */
1260 if (filename == NULL)
1263 /* force TITLE font on title message screen */
1264 game_status = getTitleMessageGameMode(initial);
1266 /* if chars set to "-1", automatically determine by text and font width */
1267 if (tmi->chars == -1)
1268 tmi->chars = tmi->width / getFontWidth(tmi->font);
1270 tmi->width = tmi->chars * getFontWidth(tmi->font);
1272 /* if lines set to "-1", automatically determine by text and font height */
1273 if (tmi->lines == -1)
1274 tmi->lines = tmi->height / getFontHeight(tmi->font);
1276 tmi->height = tmi->lines * getFontHeight(tmi->font);
1278 SetDrawBackgroundMask(REDRAW_ALL);
1279 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1281 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1283 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1284 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1285 tmi->autowrap, tmi->centered, tmi->parse_comments);
1287 game_status = last_game_status; /* restore current game status */
1290 void DrawTitleScreen()
1292 KeyboardAutoRepeatOff();
1294 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1299 boolean CheckTitleScreen(boolean levelset_has_changed)
1301 static boolean show_title_initial = TRUE;
1302 boolean show_titlescreen = FALSE;
1304 /* needed to be able to skip title screen, if no image or message defined */
1305 InitializeTitleControls(show_title_initial);
1307 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1308 show_titlescreen = TRUE;
1310 /* show initial title images and messages only once at program start */
1311 show_title_initial = FALSE;
1313 return (show_titlescreen && num_title_screens > 0);
1316 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1318 static LevelDirTree *leveldir_last_valid = NULL;
1319 boolean levelset_has_changed = FALSE;
1321 LimitScreenUpdates(FALSE);
1323 FadeSetLeaveScreen();
1325 /* do not fade out here -- function may continue and fade on editor screen */
1328 FadeSoundsAndMusic();
1330 KeyboardAutoRepeatOn();
1333 audio.sound_deactivated = FALSE;
1337 /* needed if last screen was the playing screen, invoked from level editor */
1338 if (level_editor_test_game)
1340 game_status = GAME_MODE_EDITOR;
1346 /* needed if last screen was the setup screen and fullscreen state changed */
1347 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1348 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1350 /* leveldir_current may be invalid (level group, parent link) */
1351 if (!validLevelSeries(leveldir_current))
1352 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1354 if (leveldir_current != leveldir_last_valid)
1355 levelset_has_changed = TRUE;
1357 /* store valid level series information */
1358 leveldir_last_valid = leveldir_current;
1360 init_last = init; /* switch to new busy animation */
1362 /* needed if last screen (level choice) changed graphics, sounds or music */
1363 ReloadCustomArtwork(0);
1365 if (redraw_mask & REDRAW_ALL)
1366 fade_mask = REDRAW_ALL;
1370 /* needed if different viewport properties defined for menues */
1371 ChangeViewportPropertiesIfNeeded();
1373 /* needed if last screen was the editor screen */
1374 UndrawSpecialEditorDoor();
1376 SetDrawtoField(DRAW_BACKBUFFER);
1378 if (CheckTitleScreen(levelset_has_changed))
1380 game_status = GAME_MODE_TITLE;
1387 /* level_nr may have been set to value over handicap with level editor */
1388 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1389 level_nr = leveldir_current->handicap_level;
1391 LoadLevel(level_nr);
1392 LoadScore(level_nr);
1394 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1395 SetDrawDeactivationMask(REDRAW_NONE);
1396 SetDrawBackgroundMask(REDRAW_FIELD);
1398 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1400 if (fade_mask == REDRAW_ALL)
1401 RedrawGlobalBorder();
1405 InitializeMainControls();
1407 DrawCursorAndText_Main(-1, FALSE, FALSE);
1408 DrawPreviewLevelInitial();
1410 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1413 if (TAPE_IS_EMPTY(tape))
1415 DrawCompleteVideoDisplay();
1420 /* create gadgets for main menu screen */
1421 FreeScreenGadgets();
1422 CreateScreenGadgets();
1424 /* map gadgets for main menu screen */
1426 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1428 /* copy actual game door content to door double buffer for OpenDoor() */
1429 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1431 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1433 DrawMaskedBorder(REDRAW_ALL);
1438 /* update screen area with special editor door */
1439 redraw_mask |= REDRAW_ALL;
1442 SetMouseCursor(CURSOR_DEFAULT);
1446 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1449 void DrawAndFadeInMainMenu(int fade_mask)
1451 DrawMainMenuExt(fade_mask, TRUE);
1456 DrawMainMenuExt(REDRAW_ALL, FALSE);
1459 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1460 static void gotoTopLevelDir()
1462 /* move upwards to top level directory */
1463 while (leveldir_current->node_parent)
1465 /* write a "path" into level tree for easy navigation to last level */
1466 if (leveldir_current->node_parent->node_group->cl_first == -1)
1468 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1469 int leveldir_pos = posTreeInfo(leveldir_current);
1470 int num_page_entries;
1471 int cl_first, cl_cursor;
1473 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1474 num_page_entries = num_leveldirs;
1476 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1478 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1479 cl_cursor = leveldir_pos - cl_first;
1481 leveldir_current->node_parent->node_group->cl_first = cl_first;
1482 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1485 leveldir_current = leveldir_current->node_parent;
1490 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1492 static unsigned int title_delay = 0;
1493 static int title_screen_nr = 0;
1494 static int last_sound = -1, last_music = -1;
1495 boolean return_to_main_menu = FALSE;
1496 boolean use_fading_main_menu = TRUE;
1497 struct TitleControlInfo *tci;
1498 struct TitleFadingInfo fading_default;
1499 struct TitleFadingInfo fading_last = fading;
1500 struct TitleFadingInfo fading_next;
1503 if (button == MB_MENU_INITIALIZE)
1506 title_screen_nr = 0;
1507 tci = &title_controls[title_screen_nr];
1509 last_sound = SND_UNDEFINED;
1510 last_music = MUS_UNDEFINED;
1512 if (game_status == GAME_MODE_INFO)
1514 if (num_title_screens == 0)
1516 DrawInfoScreen_NotAvailable("Title screen information:",
1517 "No title screen for this level set.");
1522 FadeSoundsAndMusic();
1524 FadeOut(REDRAW_ALL);
1528 DrawTitleScreenImage(tci->local_nr, tci->initial);
1530 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1532 fading_default = (tci->initial ? title_initial_default : title_default);
1534 fading = fading_next = getTitleFading(tci);
1536 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1537 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1539 fading.fade_mode = FADE_MODE_FADE;
1540 fading.fade_delay = fading_default.fade_delay;
1543 sound = getTitleSound(tci);
1544 music = getTitleMusic(tci);
1546 if (sound != last_sound)
1547 PlayMenuSoundExt(sound);
1548 if (music != last_music)
1549 PlayMenuMusicExt(music);
1554 SetMouseCursor(CURSOR_NONE);
1558 fading = fading_next;
1560 DelayReached(&title_delay, 0); /* reset delay counter */
1565 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1566 button = MB_MENU_CHOICE;
1568 if (button == MB_MENU_LEAVE)
1570 return_to_main_menu = TRUE;
1571 use_fading_main_menu = FALSE;
1573 else if (button == MB_MENU_CHOICE)
1575 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1577 FadeSetEnterScreen();
1579 info_mode = INFO_MODE_MAIN;
1580 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1586 tci = &title_controls[title_screen_nr];
1588 if (title_screen_nr < num_title_screens)
1590 sound = getTitleSound(tci);
1591 music = getTitleMusic(tci);
1593 if (sound == SND_UNDEFINED || sound != last_sound)
1595 if (music == MUS_UNDEFINED || music != last_music)
1598 FadeOut(REDRAW_ALL);
1601 DrawTitleScreenImage(tci->local_nr, tci->initial);
1603 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1605 fading_next = getTitleFading(tci);
1607 sound = getTitleSound(tci);
1608 music = getTitleMusic(tci);
1610 if (sound != last_sound)
1611 PlayMenuSoundExt(sound);
1612 if (music != last_music)
1613 PlayMenuMusicExt(music);
1618 /* last screen already faded out, next screen has no animation */
1619 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1620 fading_next.fade_mode == FADE_MODE_NONE)
1621 fading = fading_next;
1625 fading = fading_next;
1627 DelayReached(&title_delay, 0); /* reset delay counter */
1631 FadeSoundsAndMusic();
1633 return_to_main_menu = TRUE;
1637 if (return_to_main_menu)
1639 SetMouseCursor(CURSOR_DEFAULT);
1641 if (game_status == GAME_MODE_INFO)
1643 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1645 info_mode = INFO_MODE_MAIN;
1647 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1649 else /* default: return to main menu */
1651 game_status = GAME_MODE_MAIN;
1653 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1658 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1660 int old_level_nr = level_nr;
1663 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1664 new_level_nr = selected_level_nr;
1666 new_level_nr = old_level_nr + step * direction;
1668 if (new_level_nr < leveldir_current->first_level)
1669 new_level_nr = leveldir_current->first_level;
1670 if (new_level_nr > leveldir_current->last_level)
1671 new_level_nr = leveldir_current->last_level;
1673 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1675 /* skipping levels is only allowed when trying to skip single level */
1676 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1677 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1679 leveldir_current->handicap_level++;
1680 SaveLevelSetup_SeriesInfo();
1683 new_level_nr = leveldir_current->handicap_level;
1686 if (new_level_nr != old_level_nr)
1688 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1690 PlaySound(SND_MENU_ITEM_SELECTING);
1692 level_nr = new_level_nr;
1694 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1695 int2str(level_nr, menu.main.text.level_number.size),
1696 mci->pos_text->font);
1698 LoadLevel(level_nr);
1699 DrawPreviewLevelInitial();
1703 DrawCompleteVideoDisplay();
1705 /* needed because DrawPreviewLevelInitial() takes some time */
1707 /* SyncDisplay(); */
1711 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1713 static int choice = MAIN_CONTROL_GAME;
1714 static boolean button_pressed_last = FALSE;
1715 boolean button_pressed = FALSE;
1719 if (button == MB_MENU_INITIALIZE)
1721 DrawCursorAndText_Main(choice, TRUE, FALSE);
1726 if (mx || my) /* mouse input */
1730 for (i = 0; main_controls[i].nr != -1; i++)
1732 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1733 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1734 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1736 pos = main_controls[i].nr;
1742 // handle pressed/unpressed state for active/inactive menu buttons
1743 // (if pos != -1, "i" contains index position corresponding to "pos")
1745 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1746 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1747 button_pressed = TRUE;
1749 if (button_pressed != button_pressed_last)
1750 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1752 else if (dx || dy) /* keyboard input */
1754 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1755 choice == MAIN_CONTROL_SETUP))
1756 button = MB_MENU_CHOICE;
1761 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1763 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1765 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1767 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1769 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1771 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1773 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1775 game_status = GAME_MODE_LEVELNR;
1777 ChangeViewportPropertiesIfNeeded();
1779 DrawChooseLevelNr();
1781 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1787 PlaySound(SND_MENU_ITEM_ACTIVATING);
1789 DrawCursorAndText_Main(choice, FALSE, FALSE);
1790 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1797 PlaySound(SND_MENU_ITEM_SELECTING);
1799 if (pos == MAIN_CONTROL_NAME)
1801 game_status = GAME_MODE_PSEUDO_TYPENAME;
1803 HandleTypeName(strlen(setup.player_name), 0);
1805 else if (pos == MAIN_CONTROL_LEVELS)
1809 game_status = GAME_MODE_LEVELS;
1811 SaveLevelSetup_LastSeries();
1812 SaveLevelSetup_SeriesInfo();
1814 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1818 ChangeViewportPropertiesIfNeeded();
1820 DrawChooseLevelSet();
1823 else if (pos == MAIN_CONTROL_SCORES)
1825 game_status = GAME_MODE_SCORES;
1827 ChangeViewportPropertiesIfNeeded();
1831 else if (pos == MAIN_CONTROL_EDITOR)
1833 if (leveldir_current->readonly &&
1834 !strEqual(setup.player_name, "Artsoft"))
1835 Request("This level is read only!", REQ_CONFIRM);
1837 CloseDoor(DOOR_CLOSE_2);
1839 game_status = GAME_MODE_EDITOR;
1841 FadeSetEnterScreen();
1845 else if (pos == MAIN_CONTROL_INFO)
1847 game_status = GAME_MODE_INFO;
1848 info_mode = INFO_MODE_MAIN;
1850 ChangeViewportPropertiesIfNeeded();
1854 else if (pos == MAIN_CONTROL_GAME)
1856 StartGameActions(options.network, setup.autorecord, level.random_seed);
1858 else if (pos == MAIN_CONTROL_SETUP)
1860 game_status = GAME_MODE_SETUP;
1861 setup_mode = SETUP_MODE_MAIN;
1863 ChangeViewportPropertiesIfNeeded();
1867 else if (pos == MAIN_CONTROL_QUIT)
1869 SaveLevelSetup_LastSeries();
1870 SaveLevelSetup_SeriesInfo();
1872 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1873 game_status = GAME_MODE_QUIT;
1878 button_pressed_last = button_pressed;
1882 /* ========================================================================= */
1883 /* info screen functions */
1884 /* ========================================================================= */
1886 static struct TokenInfo *info_info;
1887 static int num_info_info;
1889 static void execInfoTitleScreen()
1891 info_mode = INFO_MODE_TITLE;
1896 static void execInfoElements()
1898 info_mode = INFO_MODE_ELEMENTS;
1903 static void execInfoMusic()
1905 info_mode = INFO_MODE_MUSIC;
1910 static void execInfoCredits()
1912 info_mode = INFO_MODE_CREDITS;
1917 static void execInfoProgram()
1919 info_mode = INFO_MODE_PROGRAM;
1924 static void execInfoVersion()
1926 info_mode = INFO_MODE_VERSION;
1931 static void execInfoLevelSet()
1933 info_mode = INFO_MODE_LEVELSET;
1938 static void execExitInfo()
1940 game_status = GAME_MODE_MAIN;
1942 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1945 static struct TokenInfo info_info_main[] =
1947 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1948 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1949 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1950 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1951 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1952 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1953 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1954 { TYPE_EMPTY, NULL, "" },
1955 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1960 static void DrawCursorAndText_Info(int pos, boolean active)
1962 int xpos = MENU_SCREEN_START_XPOS;
1963 int ypos = MENU_SCREEN_START_YPOS + pos;
1964 int font_nr = FONT_MENU_1;
1967 font_nr = FONT_ACTIVE(font_nr);
1969 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1971 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1972 drawCursor(pos, active);
1975 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1980 CloseDoor(DOOR_CLOSE_2);
1982 /* (needed after displaying title screens which disable auto repeat) */
1983 KeyboardAutoRepeatOn();
1985 FadeSetLeaveScreen();
1989 if (fade_mask == REDRAW_ALL)
1991 RedrawGlobalBorder();
1993 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1998 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2000 info_info = info_info_main;
2003 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2005 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2006 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2007 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2008 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2009 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2010 initCursor(i, IMG_MENU_BUTTON);
2012 DrawCursorAndText_Info(i, FALSE);
2017 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2022 DrawMaskedBorder(fade_mask);
2029 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2031 static int choice_store[MAX_INFO_MODES];
2032 int choice = choice_store[info_mode]; /* always starts with 0 */
2036 if (button == MB_MENU_INITIALIZE)
2038 /* advance to first valid menu entry */
2039 while (choice < num_info_info &&
2040 info_info[choice].type & TYPE_SKIP_ENTRY)
2042 choice_store[info_mode] = choice;
2044 DrawCursorAndText_Info(choice, TRUE);
2048 else if (button == MB_MENU_LEAVE)
2050 for (y = 0; y < num_info_info; y++)
2052 if (info_info[y].type & TYPE_LEAVE_MENU)
2054 void (*menu_callback_function)(void) = info_info[y].value;
2058 menu_callback_function();
2060 break; /* absolutely needed because function changes 'info_info'! */
2067 if (mx || my) /* mouse input */
2069 x = (mx - mSX) / 32;
2070 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2072 else if (dx || dy) /* keyboard input */
2076 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2078 if (info_info[choice].type & menu_navigation_type ||
2079 info_info[choice].type & TYPE_ENTER_SCREEN ||
2080 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2081 info_info[choice].type & TYPE_YES_NO_AUTO)
2082 button = MB_MENU_CHOICE;
2087 /* jump to next non-empty menu entry (up or down) */
2088 while (y > 0 && y < num_info_info - 1 &&
2089 info_info[y].type & TYPE_SKIP_ENTRY)
2093 if (IN_VIS_MENU(x, y) &&
2094 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2100 PlaySound(SND_MENU_ITEM_ACTIVATING);
2102 DrawCursorAndText_Info(choice, FALSE);
2103 DrawCursorAndText_Info(y, TRUE);
2105 choice = choice_store[info_mode] = y;
2108 else if (!(info_info[y].type & TYPE_GHOSTED))
2110 PlaySound(SND_MENU_ITEM_SELECTING);
2112 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2114 void (*menu_callback_function)(void) = info_info[choice].value;
2116 FadeSetFromType(info_info[y].type);
2118 menu_callback_function();
2124 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2126 int ystart1 = mSY - SY + 100;
2127 int ystart2 = mSY - SY + 150;
2128 int ybottom = mSY - SY + SYSIZE - 20;
2130 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2132 FadeOut(REDRAW_FIELD);
2137 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2138 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2140 DrawTextSCentered(ybottom, FONT_TEXT_4,
2141 "Press any key or button for info menu");
2143 FadeIn(REDRAW_FIELD);
2146 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2148 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2149 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2150 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2151 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2152 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2153 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2154 int ystep = MENU_SCREEN_INFO_YSTEP;
2155 int element, action, direction;
2163 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2164 infoscreen_step[i] = infoscreen_frame[i] = 0;
2169 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2171 DrawTextSCentered(ybottom, FONT_TEXT_4,
2172 "Press any key or button for next page");
2178 while (helpanim_info[j].element != HELPANIM_LIST_END)
2180 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2185 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2194 j += infoscreen_step[i - start];
2196 element = helpanim_info[j].element;
2197 action = helpanim_info[j].action;
2198 direction = helpanim_info[j].direction;
2201 element = EL_UNKNOWN;
2203 if (action != -1 && direction != -1)
2204 graphic = el_act_dir2img(element, action, direction);
2205 else if (action != -1)
2206 graphic = el_act2img(element, action);
2207 else if (direction != -1)
2208 graphic = el_dir2img(element, direction);
2210 graphic = el2img(element);
2212 delay = helpanim_info[j++].delay;
2217 if (infoscreen_frame[i - start] == 0)
2220 infoscreen_frame[i - start] = delay - 1;
2224 sync_frame = delay - infoscreen_frame[i - start];
2225 infoscreen_frame[i - start]--;
2228 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2230 if (!infoscreen_frame[i - start])
2231 infoscreen_step[i - start] = 0;
2235 if (!infoscreen_frame[i - start])
2236 infoscreen_step[i - start]++;
2237 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2243 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2245 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2246 graphic, sync_frame, USE_MASKING);
2249 DrawInfoScreen_HelpText(element, action, direction, i - start);
2254 redraw_mask |= REDRAW_FIELD;
2259 static char *getHelpText(int element, int action, int direction)
2261 char token[MAX_LINE_LEN];
2263 strcpy(token, element_info[element].token_name);
2266 strcat(token, element_action_info[action].suffix);
2268 if (direction != -1)
2269 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2271 return getHashEntry(helptext_info, token);
2274 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2276 int font_nr = FONT_INFO_ELEMENTS;
2277 int font_width = getFontWidth(font_nr);
2278 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2279 int sy = mSY + 65 + 2 * 32 + 1;
2280 int ystep = TILEY + 4;
2281 int pad_x = sx - SX;
2282 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2283 int max_lines_per_text = 2;
2286 if (action != -1 && direction != -1) /* element.action.direction */
2287 text = getHelpText(element, action, direction);
2289 if (text == NULL && action != -1) /* element.action */
2290 text = getHelpText(element, action, -1);
2292 if (text == NULL && direction != -1) /* element.direction */
2293 text = getHelpText(element, -1, direction);
2295 if (text == NULL) /* base element */
2296 text = getHelpText(element, -1, -1);
2298 if (text == NULL) /* not found */
2299 text = "No description available";
2301 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2302 sy += getFontHeight(font_nr) / 2;
2304 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2305 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2306 TRUE, FALSE, FALSE);
2309 void DrawInfoScreen_TitleScreen()
2314 void HandleInfoScreen_TitleScreen(int button)
2316 HandleTitleScreen(0, 0, 0, 0, button);
2319 void DrawInfoScreen_Elements()
2321 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2323 FadeOut(REDRAW_FIELD);
2328 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2330 FadeIn(REDRAW_FIELD);
2335 void HandleInfoScreen_Elements(int button)
2337 static unsigned int info_delay = 0;
2338 static int num_anims;
2339 static int num_pages;
2341 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2344 if (button == MB_MENU_INITIALIZE)
2346 boolean new_element = TRUE;
2350 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2352 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2354 else if (new_element)
2357 new_element = FALSE;
2361 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2365 if (button == MB_MENU_LEAVE)
2367 PlaySound(SND_MENU_ITEM_SELECTING);
2369 info_mode = INFO_MODE_MAIN;
2374 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2376 if (button != MB_MENU_INITIALIZE)
2378 PlaySound(SND_MENU_ITEM_SELECTING);
2383 if (page >= num_pages)
2385 FadeSoundsAndMusic();
2387 info_mode = INFO_MODE_MAIN;
2388 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2394 FadeSetNextScreen();
2396 if (button != MB_MENU_INITIALIZE)
2397 FadeOut(REDRAW_FIELD);
2399 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2401 if (button != MB_MENU_INITIALIZE)
2402 FadeIn(REDRAW_FIELD);
2406 if (DelayReached(&info_delay, GameFrameDelay))
2407 if (page < num_pages)
2408 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2410 PlayMenuSoundIfLoop();
2414 void DrawInfoScreen_Music()
2416 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2418 FadeOut(REDRAW_FIELD);
2425 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2427 FadeIn(REDRAW_FIELD);
2430 void HandleInfoScreen_Music(int button)
2432 static struct MusicFileInfo *list = NULL;
2433 int ystart1 = mSY - SY + 100;
2434 int ystart2 = mSY - SY + 150;
2435 int ybottom = mSY - SY + SYSIZE - 20;
2438 if (button == MB_MENU_INITIALIZE)
2440 list = music_file_info;
2444 FadeSoundsAndMusic();
2449 DrawTextSCentered(ystart1, FONT_TEXT_1,
2450 "No music info for this level set.");
2452 DrawTextSCentered(ybottom, FONT_TEXT_4,
2453 "Press any key or button for info menu");
2459 if (button == MB_MENU_LEAVE)
2461 PlaySound(SND_MENU_ITEM_SELECTING);
2463 FadeSoundsAndMusic();
2465 info_mode = INFO_MODE_MAIN;
2470 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2474 if (button != MB_MENU_INITIALIZE)
2476 PlaySound(SND_MENU_ITEM_SELECTING);
2484 FadeSoundsAndMusic();
2486 info_mode = INFO_MODE_MAIN;
2487 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2492 FadeSoundsAndMusic();
2494 if (list != music_file_info)
2495 FadeSetNextScreen();
2497 if (button != MB_MENU_INITIALIZE)
2498 FadeOut(REDRAW_FIELD);
2505 int sound = list->music;
2507 if (sound_info[sound].loop)
2508 PlaySoundLoop(sound);
2512 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2516 PlayMusic(list->music);
2518 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2521 if (!strEqual(list->title, UNKNOWN_NAME))
2523 if (!strEqual(list->title_header, UNKNOWN_NAME))
2524 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2526 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2529 if (!strEqual(list->artist, UNKNOWN_NAME))
2531 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2532 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2534 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2536 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2539 if (!strEqual(list->album, UNKNOWN_NAME))
2541 if (!strEqual(list->album_header, UNKNOWN_NAME))
2542 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2544 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2546 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2549 if (!strEqual(list->year, UNKNOWN_NAME))
2551 if (!strEqual(list->year_header, UNKNOWN_NAME))
2552 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2554 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2556 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2559 DrawTextSCentered(ybottom, FONT_TEXT_4,
2560 "Press any key or button for next page");
2562 if (button != MB_MENU_INITIALIZE)
2563 FadeIn(REDRAW_FIELD);
2566 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2567 PlaySoundLoop(list->music);
2570 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2572 int ystart1 = mSY - SY + 100;
2573 int ystart2 = mSY - SY + 150;
2574 int ybottom = mSY - SY + SYSIZE - 20;
2580 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2584 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2585 "Special thanks to");
2586 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2588 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2590 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2591 "\"Boulder Dash\"");
2592 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2594 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2596 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2598 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2599 "First Star Software");
2601 else if (screen_nr == 1)
2603 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2604 "Special thanks to");
2605 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2606 "Klaus Heinz & Volker Wertich");
2607 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2609 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2610 "\"Emerald Mine\"");
2611 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2613 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2615 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2617 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2620 else if (screen_nr == 2)
2622 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2623 "Special thanks to");
2624 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2625 "Michael Stopp & Philip Jespersen");
2626 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2628 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2630 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2632 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2634 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2636 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2637 "Digital Integration");
2639 else if (screen_nr == 3)
2641 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2642 "Special thanks to");
2643 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2644 "Hiroyuki Imabayashi");
2645 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2647 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2649 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2651 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2653 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2655 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2658 else if (screen_nr == 4)
2660 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2661 "Special thanks to");
2662 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2664 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2666 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2667 "J\xfcrgen Bonhagen");
2668 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2669 "for the continuous creation");
2670 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2671 "of outstanding level sets");
2673 else if (screen_nr == 5)
2675 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2677 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2679 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2680 "for ideas and inspiration by");
2681 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2684 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2686 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2688 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2689 "for ideas and inspiration by");
2690 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2693 else if (screen_nr == 6)
2695 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2697 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2700 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2701 "for the code base used for the");
2702 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2703 "native Emerald Mine engine");
2705 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2706 "for the new Emerald Mine engine");
2709 else if (screen_nr == 7)
2711 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2713 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2715 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2716 "for the initial DOS port");
2718 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2720 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2722 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2723 "for some additional toons");
2725 else if (screen_nr == 8)
2727 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2728 "And not to forget:");
2729 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2731 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2732 "All those who contributed");
2733 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2734 "levels to this game");
2735 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2739 DrawTextSCentered(ybottom, FONT_TEXT_4,
2740 "Press any key or button for next page");
2743 void DrawInfoScreen_Credits()
2745 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2747 FadeSoundsAndMusic();
2749 FadeOut(REDRAW_FIELD);
2751 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2753 FadeIn(REDRAW_FIELD);
2756 void HandleInfoScreen_Credits(int button)
2758 static int screen_nr = 0;
2759 int num_screens = 9;
2761 if (button == MB_MENU_INITIALIZE)
2765 // DrawInfoScreen_CreditsScreen(screen_nr);
2768 if (button == MB_MENU_LEAVE)
2770 PlaySound(SND_MENU_ITEM_SELECTING);
2772 info_mode = INFO_MODE_MAIN;
2777 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2779 if (button != MB_MENU_INITIALIZE)
2781 PlaySound(SND_MENU_ITEM_SELECTING);
2786 if (screen_nr >= num_screens)
2788 FadeSoundsAndMusic();
2790 info_mode = INFO_MODE_MAIN;
2791 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2797 FadeSetNextScreen();
2799 if (button != MB_MENU_INITIALIZE)
2800 FadeOut(REDRAW_FIELD);
2802 DrawInfoScreen_CreditsScreen(screen_nr);
2804 if (button != MB_MENU_INITIALIZE)
2805 FadeIn(REDRAW_FIELD);
2809 PlayMenuSoundIfLoop();
2813 void DrawInfoScreen_Program()
2815 int ystart1 = mSY - SY + 100;
2816 int ystart2 = mSY - SY + 150;
2817 int ybottom = mSY - SY + SYSIZE - 20;
2820 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2822 FadeOut(REDRAW_FIELD);
2827 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2829 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2830 "This game is Freeware!");
2831 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2832 "If you like it, send e-mail to:");
2833 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2834 PROGRAM_EMAIL_STRING);
2835 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2836 "More information and levels:");
2837 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2838 PROGRAM_WEBSITE_STRING);
2839 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2840 "If you have created new levels,");
2841 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2842 "send them to me to include them!");
2843 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2846 DrawTextSCentered(ybottom, FONT_TEXT_4,
2847 "Press any key or button for info menu");
2849 FadeIn(REDRAW_FIELD);
2852 void HandleInfoScreen_Program(int button)
2854 if (button == MB_MENU_LEAVE)
2856 PlaySound(SND_MENU_ITEM_SELECTING);
2858 info_mode = INFO_MODE_MAIN;
2863 else if (button == MB_MENU_CHOICE)
2865 PlaySound(SND_MENU_ITEM_SELECTING);
2867 FadeSoundsAndMusic();
2869 info_mode = INFO_MODE_MAIN;
2870 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2874 PlayMenuSoundIfLoop();
2878 void DrawInfoScreen_Version()
2880 int font_header = FONT_TEXT_3;
2881 int font_text = FONT_TEXT_2;
2882 int xstep = getFontWidth(font_text);
2883 int ystep = getFontHeight(font_text);
2884 int ystart1 = mSY - SY + 100;
2885 int ystart2 = mSY - SY + 150;
2886 int ybottom = mSY - SY + SYSIZE - 20;
2887 int xstart1 = mSX - SX + 2 * xstep;
2888 int xstart2 = mSX - SX + 18 * xstep;
2889 int xstart3 = mSX - SX + 28 * xstep;
2890 SDL_version sdl_version_compiled;
2891 const SDL_version *sdl_version_linked;
2892 int driver_name_len = 10;
2893 #if defined(TARGET_SDL2)
2894 SDL_version sdl_version_linked_ext;
2895 const char *driver_name = NULL;
2897 char driver_name[driver_name_len];
2900 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2902 FadeOut(REDRAW_FIELD);
2907 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2909 DrawTextF(xstart1, ystart2, font_header, "Name");
2910 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2913 DrawTextF(xstart1, ystart2, font_header, "Version");
2914 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
2917 DrawTextF(xstart1, ystart2, font_header, "Platform");
2918 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2921 DrawTextF(xstart1, ystart2, font_header, "Target");
2922 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2925 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2926 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2928 ystart2 += 3 * ystep;
2929 DrawTextF(xstart1, ystart2, font_header, "Library");
2930 DrawTextF(xstart2, ystart2, font_header, "compiled");
2931 DrawTextF(xstart3, ystart2, font_header, "linked");
2933 SDL_VERSION(&sdl_version_compiled);
2934 #if defined(TARGET_SDL2)
2935 SDL_GetVersion(&sdl_version_linked_ext);
2936 sdl_version_linked = &sdl_version_linked_ext;
2938 sdl_version_linked = SDL_Linked_Version();
2941 ystart2 += 2 * ystep;
2942 DrawTextF(xstart1, ystart2, font_text, "SDL");
2943 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2944 sdl_version_compiled.major,
2945 sdl_version_compiled.minor,
2946 sdl_version_compiled.patch);
2947 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2948 sdl_version_linked->major,
2949 sdl_version_linked->minor,
2950 sdl_version_linked->patch);
2952 SDL_IMAGE_VERSION(&sdl_version_compiled);
2953 sdl_version_linked = IMG_Linked_Version();
2956 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2957 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2958 sdl_version_compiled.major,
2959 sdl_version_compiled.minor,
2960 sdl_version_compiled.patch);
2961 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2962 sdl_version_linked->major,
2963 sdl_version_linked->minor,
2964 sdl_version_linked->patch);
2966 SDL_MIXER_VERSION(&sdl_version_compiled);
2967 sdl_version_linked = Mix_Linked_Version();
2970 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2971 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2972 sdl_version_compiled.major,
2973 sdl_version_compiled.minor,
2974 sdl_version_compiled.patch);
2975 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2976 sdl_version_linked->major,
2977 sdl_version_linked->minor,
2978 sdl_version_linked->patch);
2980 SDL_NET_VERSION(&sdl_version_compiled);
2981 sdl_version_linked = SDLNet_Linked_Version();
2984 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2985 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2986 sdl_version_compiled.major,
2987 sdl_version_compiled.minor,
2988 sdl_version_compiled.patch);
2989 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2990 sdl_version_linked->major,
2991 sdl_version_linked->minor,
2992 sdl_version_linked->patch);
2994 ystart2 += 3 * ystep;
2995 DrawTextF(xstart1, ystart2, font_header, "Driver");
2996 DrawTextF(xstart2, ystart2, font_header, "Requested");
2997 DrawTextF(xstart3, ystart2, font_header, "Used");
2999 #if defined(TARGET_SDL2)
3000 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3002 SDL_VideoDriverName(driver_name, driver_name_len);
3005 ystart2 += 2 * ystep;
3006 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3007 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3008 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3010 #if defined(TARGET_SDL2)
3011 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3013 SDL_AudioDriverName(driver_name, driver_name_len);
3017 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3018 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3019 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3021 DrawTextSCentered(ybottom, FONT_TEXT_4,
3022 "Press any key or button for info menu");
3024 FadeIn(REDRAW_FIELD);
3027 void HandleInfoScreen_Version(int button)
3029 if (button == MB_MENU_LEAVE)
3031 PlaySound(SND_MENU_ITEM_SELECTING);
3033 info_mode = INFO_MODE_MAIN;
3038 else if (button == MB_MENU_CHOICE)
3040 PlaySound(SND_MENU_ITEM_SELECTING);
3042 FadeSoundsAndMusic();
3044 info_mode = INFO_MODE_MAIN;
3045 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3049 PlayMenuSoundIfLoop();
3053 void DrawInfoScreen_LevelSet()
3055 struct TitleMessageInfo *tmi = &readme;
3056 char *filename = getLevelSetInfoFilename();
3057 char *title = "Level Set Information:";
3058 int ystart1 = mSY - SY + 100;
3059 int ybottom = mSY - SY + SYSIZE - 20;
3061 if (filename == NULL)
3063 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3068 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3070 FadeOut(REDRAW_FIELD);
3075 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3077 /* if x position set to "-1", automatically determine by playfield width */
3079 tmi->x = SXSIZE / 2;
3081 /* if y position set to "-1", use static default value */
3085 /* if width set to "-1", automatically determine by playfield width */
3086 if (tmi->width == -1)
3087 tmi->width = SXSIZE - 2 * TILEX;
3089 /* if height set to "-1", automatically determine by playfield height */
3090 if (tmi->height == -1)
3091 tmi->height = SYSIZE - 20 - tmi->y - 10;
3093 /* if chars set to "-1", automatically determine by text and font width */
3094 if (tmi->chars == -1)
3095 tmi->chars = tmi->width / getFontWidth(tmi->font);
3097 tmi->width = tmi->chars * getFontWidth(tmi->font);
3099 /* if lines set to "-1", automatically determine by text and font height */
3100 if (tmi->lines == -1)
3101 tmi->lines = tmi->height / getFontHeight(tmi->font);
3103 tmi->height = tmi->lines * getFontHeight(tmi->font);
3105 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3106 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3107 tmi->autowrap, tmi->centered, tmi->parse_comments);
3109 DrawTextSCentered(ybottom, FONT_TEXT_4,
3110 "Press any key or button for info menu");
3112 FadeIn(REDRAW_FIELD);
3115 void HandleInfoScreen_LevelSet(int button)
3117 if (button == MB_MENU_LEAVE)
3119 PlaySound(SND_MENU_ITEM_SELECTING);
3121 info_mode = INFO_MODE_MAIN;
3126 else if (button == MB_MENU_CHOICE)
3128 PlaySound(SND_MENU_ITEM_SELECTING);
3130 FadeSoundsAndMusic();
3132 info_mode = INFO_MODE_MAIN;
3133 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3137 PlayMenuSoundIfLoop();
3141 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3143 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3145 if (info_mode == INFO_MODE_TITLE)
3146 DrawInfoScreen_TitleScreen();
3147 else if (info_mode == INFO_MODE_ELEMENTS)
3148 DrawInfoScreen_Elements();
3149 else if (info_mode == INFO_MODE_MUSIC)
3150 DrawInfoScreen_Music();
3151 else if (info_mode == INFO_MODE_CREDITS)
3152 DrawInfoScreen_Credits();
3153 else if (info_mode == INFO_MODE_PROGRAM)
3154 DrawInfoScreen_Program();
3155 else if (info_mode == INFO_MODE_VERSION)
3156 DrawInfoScreen_Version();
3157 else if (info_mode == INFO_MODE_LEVELSET)
3158 DrawInfoScreen_LevelSet();
3160 DrawInfoScreen_Main(fade_mask, do_fading);
3162 if (info_mode != INFO_MODE_MAIN &&
3163 info_mode != INFO_MODE_TITLE &&
3164 info_mode != INFO_MODE_MUSIC)
3171 void DrawAndFadeInInfoScreen(int fade_mask)
3173 DrawInfoScreenExt(fade_mask, TRUE);
3176 void DrawInfoScreen()
3178 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3181 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3183 if (info_mode == INFO_MODE_TITLE)
3184 HandleInfoScreen_TitleScreen(button);
3185 else if (info_mode == INFO_MODE_ELEMENTS)
3186 HandleInfoScreen_Elements(button);
3187 else if (info_mode == INFO_MODE_MUSIC)
3188 HandleInfoScreen_Music(button);
3189 else if (info_mode == INFO_MODE_CREDITS)
3190 HandleInfoScreen_Credits(button);
3191 else if (info_mode == INFO_MODE_PROGRAM)
3192 HandleInfoScreen_Program(button);
3193 else if (info_mode == INFO_MODE_VERSION)
3194 HandleInfoScreen_Version(button);
3195 else if (info_mode == INFO_MODE_LEVELSET)
3196 HandleInfoScreen_LevelSet(button);
3198 HandleInfoScreen_Main(mx, my, dx, dy, button);
3202 /* ========================================================================= */
3203 /* type name functions */
3204 /* ========================================================================= */
3206 void HandleTypeName(int newxpos, Key key)
3208 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3209 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3210 struct TextPosInfo *pos = mci->pos_input;
3211 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3212 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3213 static int xpos = 0;
3214 int font_nr = pos->font;
3215 int font_active_nr = FONT_ACTIVE(font_nr);
3216 int font_width = getFontWidth(font_active_nr);
3217 char key_char = getValidConfigValueChar(getCharFromKey(key));
3218 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3219 boolean is_active = TRUE;
3221 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3225 strcpy(last_player_name, setup.player_name);
3229 #if defined(TARGET_SDL2)
3230 SDL_StartTextInput();
3233 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3235 setup.player_name[xpos] = key_char;
3236 setup.player_name[xpos + 1] = 0;
3240 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3244 setup.player_name[xpos] = 0;
3246 else if (key == KSYM_Return && xpos > 0)
3252 game_status = GAME_MODE_MAIN;
3254 else if (key == KSYM_Escape)
3256 strcpy(setup.player_name, last_player_name);
3260 game_status = GAME_MODE_MAIN;
3265 pos->width = (strlen(setup.player_name) + 1) * font_width;
3266 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3268 DrawText(startx, starty, setup.player_name, font_active_nr);
3269 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3273 pos->width = strlen(setup.player_name) * font_width;
3274 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3276 DrawText(startx, starty, setup.player_name, font_nr);
3278 #if defined(TARGET_SDL2)
3279 SDL_StopTextInput();
3285 /* ========================================================================= */
3286 /* tree menu functions */
3287 /* ========================================================================= */
3289 static void DrawChooseTree(TreeInfo **ti_ptr)
3291 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3293 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3295 game_status = GAME_MODE_MAIN;
3297 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3304 FreeScreenGadgets();
3305 CreateScreenGadgets();
3307 CloseDoor(DOOR_CLOSE_2);
3313 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3314 MapScreenTreeGadgets(*ti_ptr);
3321 static void AdjustScrollbar(int id, int items_max, int items_visible,
3324 struct GadgetInfo *gi = screen_gadget[id];
3326 if (item_position > items_max - items_visible)
3327 item_position = items_max - items_visible;
3329 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3330 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3331 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3334 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3336 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3340 static void clearMenuListArea()
3342 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3344 /* correct scrollbar position if placed outside menu (playfield) area */
3345 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
3346 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
3348 /* clear menu list area, but not title or scrollbar */
3349 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3350 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
3353 static void drawChooseTreeList(int first_entry, int num_page_entries,
3357 char *title_string = NULL;
3358 int yoffset_sets = MENU_TITLE1_YPOS;
3359 int yoffset_setup = 16;
3360 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3361 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3362 int last_game_status = game_status; /* save current game status */
3364 title_string = ti->infotext;
3366 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3368 clearMenuListArea();
3370 for (i = 0; i < num_page_entries; i++)
3372 TreeInfo *node, *node_first;
3373 int entry_pos = first_entry + i;
3374 int xpos = MENU_SCREEN_START_XPOS;
3375 int ypos = MENU_SCREEN_START_YPOS + i;
3376 int startx = mSX + xpos * 32;
3377 int starty = mSY + ypos * 32;
3378 int font_nr = FONT_TEXT_1;
3379 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3380 int startx_text = startx + font_xoffset;
3381 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3382 int text_size = startx_scrollbar - startx_text;
3383 int max_buffer_len = text_size / getFontWidth(font_nr);
3384 char buffer[max_buffer_len + 1];
3386 node_first = getTreeInfoFirstGroupEntry(ti);
3387 node = getTreeInfoFromPos(node_first, entry_pos);
3389 strncpy(buffer, node->name, max_buffer_len);
3390 buffer[max_buffer_len] = '\0';
3392 DrawText(startx, starty, buffer, font_nr + node->color);
3394 if (node->parent_link)
3395 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3396 else if (node->level_group)
3397 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3399 initCursor(i, IMG_MENU_BUTTON);
3402 game_status = last_game_status; /* restore current game status */
3404 redraw_mask |= REDRAW_FIELD;
3407 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3409 TreeInfo *node, *node_first;
3410 int x, last_redraw_mask = redraw_mask;
3411 int ypos = MENU_TITLE2_YPOS;
3412 int font_nr = FONT_TITLE_2;
3414 if (ti->type == TREE_TYPE_LEVEL_NR)
3415 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3417 if (ti->type != TREE_TYPE_LEVEL_DIR)
3420 node_first = getTreeInfoFirstGroupEntry(ti);
3421 node = getTreeInfoFromPos(node_first, entry_pos);
3423 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3425 if (node->parent_link)
3426 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3427 node->node_parent->name);
3428 else if (node->level_group)
3429 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3431 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3432 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3433 node->levels, (node->levels > 1 ? "levels" : "level"),
3436 /* let BackToFront() redraw only what is needed */
3437 redraw_mask = last_redraw_mask | REDRAW_TILES;
3438 for (x = 0; x < SCR_FIELDX; x++)
3439 MarkTileDirty(x, 1);
3442 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3445 TreeInfo *ti = *ti_ptr;
3447 int y = ti->cl_cursor;
3448 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3449 int num_entries = numTreeInfoInGroup(ti);
3450 int num_page_entries;
3451 int last_game_status = game_status; /* save current game status */
3452 boolean position_set_by_scrollbar = (dx == 999);
3454 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3455 num_page_entries = num_entries;
3457 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3459 game_status = last_game_status; /* restore current game status */
3461 if (button == MB_MENU_INITIALIZE)
3463 int num_entries = numTreeInfoInGroup(ti);
3464 int entry_pos = posTreeInfo(ti);
3466 if (ti->cl_first == -1)
3468 /* only on initialization */
3469 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3470 ti->cl_cursor = entry_pos - ti->cl_first;
3472 else if (ti->cl_cursor >= num_page_entries ||
3473 (num_entries > num_page_entries &&
3474 num_entries - ti->cl_first < num_page_entries))
3476 /* only after change of list size (by custom graphic configuration) */
3477 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3478 ti->cl_cursor = entry_pos - ti->cl_first;
3481 if (position_set_by_scrollbar)
3484 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3487 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3488 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3489 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3493 else if (button == MB_MENU_LEAVE)
3497 PlaySound(SND_MENU_ITEM_SELECTING);
3499 if (ti->node_parent)
3501 *ti_ptr = ti->node_parent;
3502 DrawChooseTree(ti_ptr);
3504 else if (game_status == GAME_MODE_SETUP)
3506 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3507 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3509 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3510 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3511 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3512 execSetupGraphics();
3513 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3514 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3515 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3517 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3518 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3519 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3526 if (game_status == GAME_MODE_LEVELNR)
3528 int new_level_nr = atoi(level_number_current->identifier);
3530 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3533 game_status = GAME_MODE_MAIN;
3535 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3541 if (mx || my) /* mouse input */
3543 int last_game_status = game_status; /* save current game status */
3545 x = (mx - mSX) / 32;
3546 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3548 game_status = last_game_status; /* restore current game status */
3550 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3552 /* move cursor instead of scrolling when already at start/end of list */
3553 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3555 else if (dy == +1 * SCROLL_LINE &&
3556 ti->cl_first + num_page_entries == num_entries)
3559 /* handle scrolling screen one line or page */
3560 if (ti->cl_cursor + dy < 0 ||
3561 ti->cl_cursor + dy > num_page_entries - 1)
3563 boolean redraw = FALSE;
3565 if (ABS(dy) == SCROLL_PAGE)
3566 step = num_page_entries - 1;
3568 if (dy < 0 && ti->cl_first > 0)
3570 /* scroll page/line up */
3572 ti->cl_first -= step;
3573 if (ti->cl_first < 0)
3578 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3580 /* scroll page/line down */
3582 ti->cl_first += step;
3583 if (ti->cl_first + num_page_entries > num_entries)
3584 ti->cl_first = MAX(0, num_entries - num_page_entries);
3591 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3592 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3593 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3595 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3603 /* handle moving cursor one line */
3604 y = ti->cl_cursor + dy;
3609 TreeInfo *node_first, *node_cursor;
3610 int entry_pos = ti->cl_first + y;
3612 node_first = getTreeInfoFirstGroupEntry(ti);
3613 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3615 if (node_cursor->node_group)
3619 PlaySound(SND_MENU_ITEM_SELECTING);
3621 node_cursor->cl_first = ti->cl_first;
3622 node_cursor->cl_cursor = ti->cl_cursor;
3623 *ti_ptr = node_cursor->node_group;
3624 DrawChooseTree(ti_ptr);
3629 else if (dx == -1 && ti->node_parent)
3633 PlaySound(SND_MENU_ITEM_SELECTING);
3635 *ti_ptr = ti->node_parent;
3636 DrawChooseTree(ti_ptr);
3641 if (!anyScrollbarGadgetActive() &&
3642 IN_VIS_MENU(x, y) &&
3643 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3644 y >= 0 && y < num_page_entries)
3648 if (y != ti->cl_cursor)
3650 PlaySound(SND_MENU_ITEM_ACTIVATING);
3652 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3653 drawChooseTreeCursor(y, TRUE);
3654 drawChooseTreeInfo(ti->cl_first + y, ti);
3661 TreeInfo *node_first, *node_cursor;
3662 int entry_pos = ti->cl_first + y;
3664 PlaySound(SND_MENU_ITEM_SELECTING);
3666 node_first = getTreeInfoFirstGroupEntry(ti);
3667 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3669 if (node_cursor->node_group)
3673 node_cursor->cl_first = ti->cl_first;
3674 node_cursor->cl_cursor = ti->cl_cursor;
3675 *ti_ptr = node_cursor->node_group;
3676 DrawChooseTree(ti_ptr);
3678 else if (node_cursor->parent_link)
3682 *ti_ptr = node_cursor->node_parent;
3683 DrawChooseTree(ti_ptr);
3689 node_cursor->cl_first = ti->cl_first;
3690 node_cursor->cl_cursor = ti->cl_cursor;
3691 *ti_ptr = node_cursor;
3693 if (ti->type == TREE_TYPE_LEVEL_DIR)
3695 LoadLevelSetup_SeriesInfo();
3697 SaveLevelSetup_LastSeries();
3698 SaveLevelSetup_SeriesInfo();
3702 if (game_status == GAME_MODE_SETUP)
3704 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3705 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3707 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3708 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3709 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3710 execSetupGraphics();
3711 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3712 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3713 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3715 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3716 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3717 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3724 if (game_status == GAME_MODE_LEVELNR)
3726 int new_level_nr = atoi(level_number_current->identifier);
3728 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3731 game_status = GAME_MODE_MAIN;
3740 void DrawChooseLevelSet()
3742 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3744 DrawChooseTree(&leveldir_current);
3750 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3752 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3755 void DrawChooseLevelNr()
3759 if (level_number != NULL)
3761 freeTreeInfo(level_number);
3763 level_number = NULL;
3766 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3768 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3769 char identifier[32], name[32];
3772 /* temporarily load level info to get level name */
3773 LoadLevelInfoOnly(i);
3775 ti->node_top = &level_number;
3776 ti->sort_priority = 10000 + value;
3777 ti->color = (level.no_valid_file ? FC_BLUE :
3778 LevelStats_getSolved(i) ? FC_GREEN :
3779 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3781 sprintf(identifier, "%d", value);
3782 sprintf(name, "%03d: %s", value,
3783 (level.no_valid_file ? "(no file)" : level.name));
3785 setString(&ti->identifier, identifier);
3786 setString(&ti->name, name);
3787 setString(&ti->name_sorting, name);
3789 pushTreeInfo(&level_number, ti);
3792 /* sort level number values to start with lowest level number */
3793 sortTreeInfo(&level_number);
3795 /* set current level number to current level number */
3796 level_number_current =
3797 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3799 /* if that also fails, set current level number to first available level */
3800 if (level_number_current == NULL)
3801 level_number_current = level_number;
3803 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3805 DrawChooseTree(&level_number_current);
3811 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3813 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3816 void DrawHallOfFame(int highlight_position)
3818 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3821 FadeSoundsAndMusic();
3823 /* (this is needed when called from GameEnd() after winning a game) */
3824 KeyboardAutoRepeatOn();
3827 /* (this is needed when called from GameEnd() after winning a game) */
3828 SetDrawDeactivationMask(REDRAW_NONE);
3829 SetDrawBackgroundMask(REDRAW_FIELD);
3831 CloseDoor(DOOR_CLOSE_2);
3833 if (highlight_position < 0)
3834 LoadScore(level_nr);
3836 FadeSetEnterScreen();
3845 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3850 static void drawHallOfFameList(int first_entry, int highlight_position)
3854 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3857 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3858 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3859 "HighScores of Level %d", level_nr);
3861 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3863 int entry = first_entry + i;
3864 boolean active = (entry == highlight_position);
3865 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3866 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3867 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3868 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3869 int dx1 = 3 * getFontWidth(font_nr1);
3870 int dx2 = dx1 + getFontWidth(font_nr1);
3871 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
3872 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
3873 int sy = mSY + 64 + i * 32;
3875 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3876 DrawText(mSX + dx1, sy, ".", font_nr1);
3878 for (j = 0; j < num_dots; j++)
3879 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
3881 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3882 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3884 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3887 redraw_mask |= REDRAW_FIELD;
3890 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3892 static int first_entry = 0;
3893 static int highlight_position = 0;
3894 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3896 if (button == MB_MENU_INITIALIZE)
3899 highlight_position = mx;
3900 drawHallOfFameList(first_entry, highlight_position);
3905 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3906 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3910 if (first_entry > 0)
3912 first_entry -= step;
3913 if (first_entry < 0)
3916 drawHallOfFameList(first_entry, highlight_position);
3921 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3923 first_entry += step;
3924 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3925 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3927 drawHallOfFameList(first_entry, highlight_position);
3930 else if (button == MB_MENU_LEAVE)
3932 PlaySound(SND_MENU_ITEM_SELECTING);
3934 FadeSound(SND_BACKGROUND_SCORES);
3936 game_status = GAME_MODE_MAIN;
3940 else if (button == MB_MENU_CHOICE)
3942 PlaySound(SND_MENU_ITEM_SELECTING);
3944 FadeSound(SND_BACKGROUND_SCORES);
3946 game_status = GAME_MODE_MAIN;
3948 DrawAndFadeInMainMenu(REDRAW_FIELD);
3951 if (game_status == GAME_MODE_SCORES)
3952 PlayMenuSoundIfLoop();
3956 /* ========================================================================= */
3957 /* setup screen functions */
3958 /* ========================================================================= */
3960 static struct TokenInfo *setup_info;
3961 static int num_setup_info; /* number of setup entries shown on screen */
3962 static int max_setup_info; /* total number of setup entries in list */
3964 static char *screen_mode_text;
3965 static char *window_size_text;
3966 static char *scaling_type_text;
3967 static char *scroll_delay_text;
3968 static char *game_speed_text;
3969 static char *graphics_set_name;
3970 static char *sounds_set_name;
3971 static char *music_set_name;
3972 static char *volume_simple_text;
3973 static char *volume_loops_text;
3974 static char *volume_music_text;
3975 static char *touch_controls_text;
3976 static char *move_distance_text;
3977 static char *drop_distance_text;
3979 static void execSetupMain()
3981 setup_mode = SETUP_MODE_MAIN;
3986 static void execSetupGame_setGameSpeeds()
3988 if (game_speeds == NULL)
3992 for (i = 0; game_speeds_list[i].value != -1; i++)
3994 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3995 char identifier[32], name[32];
3996 int value = game_speeds_list[i].value;
3997 char *text = game_speeds_list[i].text;
3999 ti->node_top = &game_speeds;
4000 ti->sort_priority = 10000 - value;
4002 sprintf(identifier, "%d", value);
4003 sprintf(name, "%s", text);
4005 setString(&ti->identifier, identifier);
4006 setString(&ti->name, name);
4007 setString(&ti->name_sorting, name);
4008 setString(&ti->infotext, "Game Speed");
4010 pushTreeInfo(&game_speeds, ti);
4013 /* sort game speed values to start with slowest game speed */
4014 sortTreeInfo(&game_speeds);
4016 /* set current game speed to configured game speed value */
4017 game_speed_current =
4018 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4020 /* if that fails, set current game speed to reliable default value */
4021 if (game_speed_current == NULL)
4022 game_speed_current =
4023 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4025 /* if that also fails, set current game speed to first available speed */
4026 if (game_speed_current == NULL)
4027 game_speed_current = game_speeds;
4030 setup.game_frame_delay = atoi(game_speed_current->identifier);
4032 /* needed for displaying game speed text instead of identifier */
4033 game_speed_text = game_speed_current->name;
4036 static void execSetupGame_setScrollDelays()
4038 if (scroll_delays == NULL)
4042 for (i = 0; scroll_delays_list[i].value != -1; i++)
4044 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4045 char identifier[32], name[32];
4046 int value = scroll_delays_list[i].value;
4047 char *text = scroll_delays_list[i].text;
4049 ti->node_top = &scroll_delays;
4050 ti->sort_priority = value;
4052 sprintf(identifier, "%d", value);
4053 sprintf(name, "%s", text);
4055 setString(&ti->identifier, identifier);
4056 setString(&ti->name, name);
4057 setString(&ti->name_sorting, name);
4058 setString(&ti->infotext, "Scaling Type");
4060 pushTreeInfo(&scroll_delays, ti);
4063 /* sort scaling type values to start with lowest scaling type value */
4064 sortTreeInfo(&scroll_delays);
4066 /* set current scaling type value to configured scaling type value */
4067 scroll_delay_current =
4068 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4070 /* if that fails, set current scaling type to reliable default value */
4071 if (scroll_delay_current == NULL)
4072 scroll_delay_current =
4073 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4075 /* if that also fails, set current scaling type to first available value */
4076 if (scroll_delay_current == NULL)
4077 scroll_delay_current = scroll_delays;
4080 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4082 /* needed for displaying scaling type text instead of identifier */
4083 scroll_delay_text = scroll_delay_current->name;
4086 static void execSetupGame()
4088 execSetupGame_setGameSpeeds();
4089 execSetupGame_setScrollDelays();
4091 setup_mode = SETUP_MODE_GAME;
4096 static void execSetupChooseGameSpeed()
4098 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4103 static void execSetupChooseScrollDelay()
4105 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4110 static void execSetupEditor()
4112 setup_mode = SETUP_MODE_EDITOR;
4117 static void execSetupGraphics_setWindowSizes(boolean update_list)
4119 if (window_sizes != NULL && update_list)
4121 freeTreeInfo(window_sizes);
4123 window_sizes = NULL;
4126 if (window_sizes == NULL)
4128 boolean current_window_size_found = FALSE;
4131 for (i = 0; window_sizes_list[i].value != -1; i++)
4133 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4134 char identifier[32], name[32];
4135 int value = window_sizes_list[i].value;
4136 char *text = window_sizes_list[i].text;
4138 ti->node_top = &window_sizes;
4139 ti->sort_priority = value;
4141 sprintf(identifier, "%d", value);
4142 sprintf(name, "%s", text);
4144 setString(&ti->identifier, identifier);
4145 setString(&ti->name, name);
4146 setString(&ti->name_sorting, name);
4147 setString(&ti->infotext, "Window Scaling");
4149 pushTreeInfo(&window_sizes, ti);
4151 if (value == setup.window_scaling_percent)
4152 current_window_size_found = TRUE;
4155 if (!current_window_size_found)
4157 // add entry for non-preset window scaling value
4159 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4160 char identifier[32], name[32];
4161 int value = setup.window_scaling_percent;
4163 ti->node_top = &window_sizes;
4164 ti->sort_priority = value;
4166 sprintf(identifier, "%d", value);
4167 sprintf(name, "%d %% (Current)", value);
4169 setString(&ti->identifier, identifier);
4170 setString(&ti->name, name);
4171 setString(&ti->name_sorting, name);
4172 setString(&ti->infotext, "Window Scaling");
4174 pushTreeInfo(&window_sizes, ti);
4177 /* sort window size values to start with lowest window size value */
4178 sortTreeInfo(&window_sizes);
4180 /* set current window size value to configured window size value */
4181 window_size_current =
4182 getTreeInfoFromIdentifier(window_sizes,
4183 i_to_a(setup.window_scaling_percent));
4185 /* if that fails, set current window size to reliable default value */
4186 if (window_size_current == NULL)
4187 window_size_current =
4188 getTreeInfoFromIdentifier(window_sizes,
4189 i_to_a(STD_WINDOW_SCALING_PERCENT));
4191 /* if that also fails, set current window size to first available value */
4192 if (window_size_current == NULL)
4193 window_size_current = window_sizes;
4196 setup.window_scaling_percent = atoi(window_size_current->identifier);
4198 /* needed for displaying window size text instead of identifier */
4199 window_size_text = window_size_current->name;
4202 static void execSetupGraphics_setScalingTypes()
4204 if (scaling_types == NULL)
4208 for (i = 0; scaling_types_list[i].value != NULL; i++)
4210 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4211 char identifier[32], name[32];
4212 char *value = scaling_types_list[i].value;
4213 char *text = scaling_types_list[i].text;
4215 ti->node_top = &scaling_types;
4216 ti->sort_priority = i;
4218 sprintf(identifier, "%s", value);
4219 sprintf(name, "%s", text);
4221 setString(&ti->identifier, identifier);
4222 setString(&ti->name, name);
4223 setString(&ti->name_sorting, name);
4224 setString(&ti->infotext, "Anti-Aliasing");
4226 pushTreeInfo(&scaling_types, ti);
4229 /* sort scaling type values to start with lowest scaling type value */
4230 sortTreeInfo(&scaling_types);
4232 /* set current scaling type value to configured scaling type value */
4233 scaling_type_current =
4234 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4236 /* if that fails, set current scaling type to reliable default value */
4237 if (scaling_type_current == NULL)
4238 scaling_type_current =
4239 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4241 /* if that also fails, set current scaling type to first available value */
4242 if (scaling_type_current == NULL)
4243 scaling_type_current = scaling_types;
4246 setup.window_scaling_quality = scaling_type_current->identifier;
4248 /* needed for displaying scaling type text instead of identifier */
4249 scaling_type_text = scaling_type_current->name;
4252 static void execSetupGraphics_setScreenModes()
4254 // if (screen_modes == NULL && video.fullscreen_available)
4255 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4259 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4261 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4262 char identifier[32], name[32];
4263 int x = video.fullscreen_modes[i].width;
4264 int y = video.fullscreen_modes[i].height;
4267 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4269 ti->node_top = &screen_modes;
4270 ti->sort_priority = x * 10000 + y;
4272 sprintf(identifier, "%dx%d", x, y);
4273 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4275 setString(&ti->identifier, identifier);
4276 setString(&ti->name, name);
4277 setString(&ti->name_sorting, name);
4278 setString(&ti->infotext, "Fullscreen Mode");
4280 pushTreeInfo(&screen_modes, ti);
4283 /* sort fullscreen modes to start with lowest available screen resolution */
4284 sortTreeInfo(&screen_modes);
4286 /* set current screen mode for fullscreen mode to configured setup value */
4287 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4288 setup.fullscreen_mode);
4290 /* if that fails, set current screen mode to reliable default value */
4291 if (screen_mode_current == NULL)
4292 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4293 DEFAULT_FULLSCREEN_MODE);
4295 /* if that also fails, set current screen mode to first available mode */
4296 if (screen_mode_current == NULL)
4297 screen_mode_current = screen_modes;
4299 if (screen_mode_current == NULL)
4300 video.fullscreen_available = FALSE;
4303 // if (video.fullscreen_available)
4304 if (screen_mode_current != NULL)
4306 setup.fullscreen_mode = screen_mode_current->identifier;
4308 /* needed for displaying screen mode name instead of identifier */
4309 screen_mode_text = screen_mode_current->name;
4313 static void execSetupGraphics()
4315 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4317 // update "setup.window_scaling_percent" from list selection
4318 execSetupGraphics_setWindowSizes(FALSE);
4322 // update list selection from "setup.window_scaling_percent"
4323 execSetupGraphics_setWindowSizes(TRUE);
4326 execSetupGraphics_setScalingTypes();
4327 execSetupGraphics_setScreenModes();
4329 setup_mode = SETUP_MODE_GRAPHICS;
4333 #if defined(TARGET_SDL2)
4334 // window scaling may have changed at this point
4335 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4337 // window scaling quality may have changed at this point
4338 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4339 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4343 #if !defined(PLATFORM_ANDROID)
4344 #if defined(TARGET_SDL2)
4345 static void execSetupChooseWindowSize()
4347 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4352 static void execSetupChooseScalingType()
4354 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4359 static void execSetupChooseScreenMode()
4361 if (!video.fullscreen_available)
4364 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4371 static void execSetupChooseVolumeSimple()
4373 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4378 static void execSetupChooseVolumeLoops()
4380 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4385 static void execSetupChooseVolumeMusic()
4387 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4392 static void execSetupSound()
4394 if (volumes_simple == NULL)
4396 boolean current_volume_simple_found = FALSE;
4399 for (i = 0; volumes_list[i].value != -1; i++)
4401 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4402 char identifier[32], name[32];
4403 int value = volumes_list[i].value;
4404 char *text = volumes_list[i].text;
4406 ti->node_top = &volumes_simple;
4407 ti->sort_priority = value;
4409 sprintf(identifier, "%d", value);
4410 sprintf(name, "%s", text);
4412 setString(&ti->identifier, identifier);
4413 setString(&ti->name, name);
4414 setString(&ti->name_sorting, name);
4415 setString(&ti->infotext, "Sound Volume");
4417 pushTreeInfo(&volumes_simple, ti);
4419 if (value == setup.volume_simple)
4420 current_volume_simple_found = TRUE;
4423 if (!current_volume_simple_found)
4425 // add entry for non-preset volume value
4427 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4428 char identifier[32], name[32];
4429 int value = setup.volume_simple;
4431 ti->node_top = &volumes_simple;
4432 ti->sort_priority = value;
4434 sprintf(identifier, "%d", value);
4435 sprintf(name, "%d %% (Current)", value);
4437 setString(&ti->identifier, identifier);
4438 setString(&ti->name, name);
4439 setString(&ti->name_sorting, name);
4440 setString(&ti->infotext, "Sound Volume");
4442 pushTreeInfo(&volumes_simple, ti);
4445 /* sort volume values to start with lowest volume value */
4446 sortTreeInfo(&volumes_simple);
4448 /* set current volume value to configured volume value */
4449 volume_simple_current =
4450 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4452 /* if that fails, set current volume to reliable default value */
4453 if (volume_simple_current == NULL)
4454 volume_simple_current =
4455 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4457 /* if that also fails, set current volume to first available value */
4458 if (volume_simple_current == NULL)
4459 volume_simple_current = volumes_simple;
4462 if (volumes_loops == NULL)
4464 boolean current_volume_loops_found = FALSE;
4467 for (i = 0; volumes_list[i].value != -1; i++)
4469 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4470 char identifier[32], name[32];
4471 int value = volumes_list[i].value;
4472 char *text = volumes_list[i].text;
4474 ti->node_top = &volumes_loops;
4475 ti->sort_priority = value;
4477 sprintf(identifier, "%d", value);
4478 sprintf(name, "%s", text);
4480 setString(&ti->identifier, identifier);
4481 setString(&ti->name, name);
4482 setString(&ti->name_sorting, name);
4483 setString(&ti->infotext, "Loops Volume");
4485 pushTreeInfo(&volumes_loops, ti);
4487 if (value == setup.volume_loops)
4488 current_volume_loops_found = TRUE;
4491 if (!current_volume_loops_found)
4493 // add entry for non-preset volume value
4495 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4496 char identifier[32], name[32];
4497 int value = setup.volume_loops;
4499 ti->node_top = &volumes_loops;
4500 ti->sort_priority = value;
4502 sprintf(identifier, "%d", value);
4503 sprintf(name, "%d %% (Current)", value);
4505 setString(&ti->identifier, identifier);
4506 setString(&ti->name, name);
4507 setString(&ti->name_sorting, name);
4508 setString(&ti->infotext, "Loops Volume");
4510 pushTreeInfo(&volumes_loops, ti);
4513 /* sort volume values to start with lowest volume value */
4514 sortTreeInfo(&volumes_loops);
4516 /* set current volume value to configured volume value */
4517 volume_loops_current =
4518 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4520 /* if that fails, set current volume to reliable default value */
4521 if (volume_loops_current == NULL)
4522 volume_loops_current =
4523 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4525 /* if that also fails, set current volume to first available value */
4526 if (volume_loops_current == NULL)
4527 volume_loops_current = volumes_loops;
4530 if (volumes_music == NULL)
4532 boolean current_volume_music_found = FALSE;
4535 for (i = 0; volumes_list[i].value != -1; i++)
4537 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4538 char identifier[32], name[32];
4539 int value = volumes_list[i].value;
4540 char *text = volumes_list[i].text;
4542 ti->node_top = &volumes_music;
4543 ti->sort_priority = value;
4545 sprintf(identifier, "%d", value);
4546 sprintf(name, "%s", text);
4548 setString(&ti->identifier, identifier);
4549 setString(&ti->name, name);
4550 setString(&ti->name_sorting, name);
4551 setString(&ti->infotext, "Music Volume");
4553 pushTreeInfo(&volumes_music, ti);
4555 if (value == setup.volume_music)
4556 current_volume_music_found = TRUE;
4559 if (!current_volume_music_found)
4561 // add entry for non-preset volume value
4563 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4564 char identifier[32], name[32];
4565 int value = setup.volume_music;
4567 ti->node_top = &volumes_music;
4568 ti->sort_priority = value;
4570 sprintf(identifier, "%d", value);
4571 sprintf(name, "%d %% (Current)", value);
4573 setString(&ti->identifier, identifier);
4574 setString(&ti->name, name);
4575 setString(&ti->name_sorting, name);
4576 setString(&ti->infotext, "Music Volume");
4578 pushTreeInfo(&volumes_music, ti);
4581 /* sort volume values to start with lowest volume value */
4582 sortTreeInfo(&volumes_music);
4584 /* set current volume value to configured volume value */
4585 volume_music_current =
4586 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4588 /* if that fails, set current volume to reliable default value */
4589 if (volume_music_current == NULL)
4590 volume_music_current =
4591 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4593 /* if that also fails, set current volume to first available value */
4594 if (volume_music_current == NULL)
4595 volume_music_current = volumes_music;
4598 setup.volume_simple = atoi(volume_simple_current->identifier);
4599 setup.volume_loops = atoi(volume_loops_current->identifier);
4600 setup.volume_music = atoi(volume_music_current->identifier);
4602 /* needed for displaying volume text instead of identifier */
4603 volume_simple_text = volume_simple_current->name;
4604 volume_loops_text = volume_loops_current->name;
4605 volume_music_text = volume_music_current->name;
4607 setup_mode = SETUP_MODE_SOUND;
4612 static void execSetupChooseTouchControls()
4614 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4619 static void execSetupChooseMoveDistance()
4621 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4626 static void execSetupChooseDropDistance()
4628 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4633 static void execSetupTouch()
4635 if (touch_controls == NULL)
4639 for (i = 0; touch_controls_list[i].value != NULL; i++)
4641 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4642 char identifier[32], name[32];
4643 char *value = touch_controls_list[i].value;
4644 char *text = touch_controls_list[i].text;
4646 ti->node_top = &touch_controls;
4647 ti->sort_priority = i;
4649 sprintf(identifier, "%s", value);
4650 sprintf(name, "%s", text);
4652 setString(&ti->identifier, identifier);
4653 setString(&ti->name, name);
4654 setString(&ti->name_sorting, name);
4655 setString(&ti->infotext, "Control Type");
4657 pushTreeInfo(&touch_controls, ti);
4660 /* sort touch control values to start with lowest touch control value */
4661 sortTreeInfo(&touch_controls);
4663 /* set current touch control value to configured touch control value */
4664 touch_control_current =
4665 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4667 /* if that fails, set current touch control to reliable default value */
4668 if (touch_control_current == NULL)
4669 touch_control_current =
4670 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4672 /* if that also fails, set current touch control to first available value */
4673 if (touch_control_current == NULL)
4674 touch_control_current = touch_controls;
4677 if (move_distances == NULL)
4681 for (i = 0; distances_list[i].value != -1; i++)
4683 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4684 char identifier[32], name[32];
4685 int value = distances_list[i].value;
4686 char *text = distances_list[i].text;
4688 ti->node_top = &move_distances;
4689 ti->sort_priority = value;
4691 sprintf(identifier, "%d", value);
4692 sprintf(name, "%s", text);
4694 setString(&ti->identifier, identifier);
4695 setString(&ti->name, name);
4696 setString(&ti->name_sorting, name);
4697 setString(&ti->infotext, "Move Distance");
4699 pushTreeInfo(&move_distances, ti);
4702 /* sort distance values to start with lowest distance value */
4703 sortTreeInfo(&move_distances);
4705 /* set current distance value to configured distance value */
4706 move_distance_current =
4707 getTreeInfoFromIdentifier(move_distances,
4708 i_to_a(setup.touch.move_distance));
4710 /* if that fails, set current distance to reliable default value */
4711 if (move_distance_current == NULL)
4712 move_distance_current =
4713 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4715 /* if that also fails, set current distance to first available value */
4716 if (move_distance_current == NULL)
4717 move_distance_current = move_distances;
4720 if (drop_distances == NULL)
4724 for (i = 0; distances_list[i].value != -1; i++)
4726 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4727 char identifier[32], name[32];
4728 int value = distances_list[i].value;
4729 char *text = distances_list[i].text;
4731 ti->node_top = &drop_distances;
4732 ti->sort_priority = value;
4734 sprintf(identifier, "%d", value);
4735 sprintf(name, "%s", text);
4737 setString(&ti->identifier, identifier);
4738 setString(&ti->name, name);
4739 setString(&ti->name_sorting, name);
4740 setString(&ti->infotext, "Drop Distance");
4742 pushTreeInfo(&drop_distances, ti);
4745 /* sort distance values to start with lowest distance value */
4746 sortTreeInfo(&drop_distances);
4748 /* set current distance value to configured distance value */
4749 drop_distance_current =
4750 getTreeInfoFromIdentifier(drop_distances,
4751 i_to_a(setup.touch.drop_distance));
4753 /* if that fails, set current distance to reliable default value */
4754 if (drop_distance_current == NULL)
4755 drop_distance_current =
4756 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
4758 /* if that also fails, set current distance to first available value */
4759 if (drop_distance_current == NULL)
4760 drop_distance_current = drop_distances;
4763 setup.touch.control_type = touch_control_current->identifier;
4764 setup.touch.move_distance = atoi(move_distance_current->identifier);
4765 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
4767 /* needed for displaying volume text instead of identifier */
4768 touch_controls_text = touch_control_current->name;
4769 move_distance_text = move_distance_current->name;
4770 drop_distance_text = drop_distance_current->name;
4772 setup_mode = SETUP_MODE_TOUCH;
4777 static void execSetupArtwork()
4780 printf("::: '%s', '%s', '%s'\n",
4781 artwork.gfx_current->subdir,
4782 artwork.gfx_current->fullpath,
4783 artwork.gfx_current->basepath);
4786 setup.graphics_set = artwork.gfx_current->identifier;
4787 setup.sounds_set = artwork.snd_current->identifier;
4788 setup.music_set = artwork.mus_current->identifier;
4790 /* needed if last screen (setup choice) changed graphics, sounds or music */
4791 ReloadCustomArtwork(0);
4793 /* needed for displaying artwork name instead of artwork identifier */
4794 graphics_set_name = artwork.gfx_current->name;
4795 sounds_set_name = artwork.snd_current->name;
4796 music_set_name = artwork.mus_current->name;
4798 setup_mode = SETUP_MODE_ARTWORK;
4803 static void execSetupChooseGraphics()
4805 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4810 static void execSetupChooseSounds()
4812 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4817 static void execSetupChooseMusic()
4819 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4824 #if !defined(PLATFORM_ANDROID)
4825 static void execSetupInput()
4827 setup_mode = SETUP_MODE_INPUT;
4833 static void execSetupShortcuts()
4835 setup_mode = SETUP_MODE_SHORTCUTS;
4840 static void execSetupShortcuts1()
4842 setup_mode = SETUP_MODE_SHORTCUTS_1;
4847 static void execSetupShortcuts2()
4849 setup_mode = SETUP_MODE_SHORTCUTS_2;
4854 static void execSetupShortcuts3()
4856 setup_mode = SETUP_MODE_SHORTCUTS_3;
4861 static void execSetupShortcuts4()
4863 setup_mode = SETUP_MODE_SHORTCUTS_4;
4868 static void execSetupShortcuts5()
4870 setup_mode = SETUP_MODE_SHORTCUTS_5;
4875 static void execExitSetup()
4877 game_status = GAME_MODE_MAIN;
4879 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4882 static void execSaveAndExitSetup()
4888 static struct TokenInfo setup_info_main[] =
4890 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4891 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4892 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4893 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4894 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4895 #if !defined(PLATFORM_ANDROID)
4896 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4897 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4899 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4901 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4902 { TYPE_EMPTY, NULL, "" },
4903 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4904 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4909 static struct TokenInfo setup_info_game[] =
4911 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4912 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4913 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4914 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4915 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4916 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4917 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4918 { TYPE_STRING, &game_speed_text, "" },
4920 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4921 { TYPE_STRING, &scroll_delay_text, "" },
4923 { TYPE_EMPTY, NULL, "" },
4924 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4929 static struct TokenInfo setup_info_editor[] =
4932 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4933 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4934 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4935 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4936 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4937 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4938 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4939 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4941 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4942 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4943 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4945 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4947 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4948 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4949 { TYPE_EMPTY, NULL, "" },
4951 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4952 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4953 { TYPE_EMPTY, NULL, "" },
4955 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4956 { TYPE_EMPTY, NULL, "" },
4957 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4962 static struct TokenInfo setup_info_graphics[] =
4964 #if !defined(PLATFORM_ANDROID)
4965 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4966 #if defined(TARGET_SDL2)
4967 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4968 { TYPE_STRING, &window_size_text, "" },
4969 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4970 { TYPE_STRING, &scaling_type_text, "" },
4972 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4973 { TYPE_STRING, &screen_mode_text, "" },
4977 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4978 { TYPE_STRING, &scroll_delay_text, "" },
4980 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4981 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4982 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4983 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4984 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4985 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4986 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4987 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4988 { TYPE_EMPTY, NULL, "" },
4989 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4994 static struct TokenInfo setup_info_sound[] =
4996 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4997 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4998 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4999 { TYPE_EMPTY, NULL, "" },
5000 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5001 { TYPE_STRING, &volume_simple_text, "" },
5002 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5003 { TYPE_STRING, &volume_loops_text, "" },
5004 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5005 { TYPE_STRING, &volume_music_text, "" },
5006 { TYPE_EMPTY, NULL, "" },
5007 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5012 static struct TokenInfo setup_info_artwork[] =
5014 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5015 { TYPE_STRING, &graphics_set_name, "" },
5016 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5017 { TYPE_STRING, &sounds_set_name, "" },
5018 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5019 { TYPE_STRING, &music_set_name, "" },
5020 { TYPE_EMPTY, NULL, "" },
5021 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5022 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5023 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5024 { TYPE_EMPTY, NULL, "" },
5025 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5030 static struct TokenInfo setup_info_input[] =
5032 { TYPE_SWITCH, NULL, "Player:" },
5033 { TYPE_SWITCH, NULL, "Device:" },
5034 { TYPE_ENTER_MENU, NULL, "" },
5035 { TYPE_EMPTY, NULL, "" },
5036 { TYPE_EMPTY, NULL, "" },
5037 { TYPE_EMPTY, NULL, "" },
5038 { TYPE_EMPTY, NULL, "" },
5039 { TYPE_EMPTY, NULL, "" },
5040 { TYPE_EMPTY, NULL, "" },
5041 { TYPE_EMPTY, NULL, "" },
5042 { TYPE_EMPTY, NULL, "" },
5043 { TYPE_EMPTY, NULL, "" },
5044 { TYPE_EMPTY, NULL, "" },
5045 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5050 static struct TokenInfo setup_info_touch[] =
5052 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5053 { TYPE_STRING, &touch_controls_text, "" },
5054 { TYPE_EMPTY, NULL, "" },
5055 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5056 { TYPE_STRING, &move_distance_text, "" },
5057 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5058 { TYPE_STRING, &drop_distance_text, "" },
5059 { TYPE_EMPTY, NULL, "" },
5060 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5065 static struct TokenInfo setup_info_shortcuts[] =
5067 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5068 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5069 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5070 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5071 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5072 { TYPE_EMPTY, NULL, "" },
5073 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5078 static struct TokenInfo setup_info_shortcuts_1[] =
5080 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5081 { TYPE_KEY, &setup.shortcut.save_game, "" },
5082 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5083 { TYPE_KEY, &setup.shortcut.load_game, "" },
5084 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5085 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5086 { TYPE_EMPTY, NULL, "" },
5087 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5088 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5089 { TYPE_EMPTY, NULL, "" },
5090 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5095 static struct TokenInfo setup_info_shortcuts_2[] =
5097 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5098 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5099 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5100 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5101 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5102 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5103 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5104 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5105 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5106 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5107 { TYPE_EMPTY, NULL, "" },
5108 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5113 static struct TokenInfo setup_info_shortcuts_3[] =
5115 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5116 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5117 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5118 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5119 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5120 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5121 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5122 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5123 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5124 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5125 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5126 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5127 { TYPE_EMPTY, NULL, "" },
5128 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5133 static struct TokenInfo setup_info_shortcuts_4[] =
5135 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5136 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5137 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5138 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5139 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5140 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5141 { TYPE_EMPTY, NULL, "" },
5142 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5147 static struct TokenInfo setup_info_shortcuts_5[] =
5149 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5150 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5151 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5152 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5153 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5154 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5155 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5156 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5157 { TYPE_EMPTY, NULL, "" },
5158 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5163 static Key getSetupKey()
5165 Key key = KSYM_UNDEFINED;
5166 boolean got_key_event = FALSE;
5168 while (!got_key_event)
5170 if (PendingEvent()) /* got event */
5178 case EVENT_KEYPRESS:
5180 key = GetEventKey((KeyEvent *)&event, TRUE);
5182 /* press 'Escape' or 'Enter' to keep the existing key binding */
5183 if (key == KSYM_Escape || key == KSYM_Return)
5184 key = KSYM_UNDEFINED; /* keep old value */
5186 got_key_event = TRUE;
5190 case EVENT_KEYRELEASE:
5191 key_joystick_mapping = 0;
5195 HandleOtherEvents(&event);
5203 /* don't eat all CPU time */
5210 static int getSetupTextFont(int type)
5212 if (type & (TYPE_SWITCH |
5224 static int getSetupValueFont(int type, void *value)
5226 if (type & TYPE_KEY)
5227 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5228 else if (type & TYPE_STRING)
5229 return FONT_VALUE_2;
5230 else if (type & TYPE_ECS_AGA)
5231 return FONT_VALUE_1;
5232 else if (type & TYPE_BOOLEAN_STYLE)
5233 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5234 else if (type & TYPE_YES_NO_AUTO)
5235 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5236 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5238 return FONT_VALUE_1;
5241 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5243 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5244 struct TokenInfo *si = &setup_info[si_pos];
5245 boolean font_draw_xoffset_modified = FALSE;
5246 int font_draw_xoffset_old = -1;
5247 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5248 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5249 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5250 int xpos = menu_screen_value_xpos;
5251 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5252 int startx = mSX + xpos * 32;
5253 int starty = mSY + ypos * 32;
5254 int font_nr, font_width;
5255 int type = si->type;
5256 void *value = si->value;
5257 char *value_string = getSetupValue(type, value);
5260 if (value_string == NULL)
5263 if (type & TYPE_KEY)
5265 xpos = MENU_SCREEN_START_XPOS;
5267 if (type & TYPE_QUERY)
5268 value_string = "<press key>";
5270 else if (type & TYPE_STRING)
5272 int max_value_len = (SCR_FIELDX - 2) * 2;
5274 xpos = MENU_SCREEN_START_XPOS;
5276 if (strlen(value_string) > max_value_len)
5277 value_string[max_value_len] = '\0';
5279 else if (type & TYPE_YES_NO_AUTO)
5281 xpos = menu_screen_value_xpos - 1;
5284 startx = mSX + xpos * 32;
5285 starty = mSY + ypos * 32;
5286 font_nr = getSetupValueFont(type, value);
5287 font_width = getFontWidth(font_nr);
5289 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5290 if (setup_mode != SETUP_MODE_INPUT)
5292 int max_menu_text_length_big = (menu_screen_value_xpos -
5293 MENU_SCREEN_START_XPOS);
5294 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5295 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5296 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5297 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5298 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5299 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5300 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5301 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5302 boolean correct_font_draw_xoffset = FALSE;
5304 if (xpos == MENU_SCREEN_START_XPOS &&
5305 startx + font1_xoffset < text_startx + text_font_xoffset)
5306 correct_font_draw_xoffset = TRUE;
5308 if (xpos == menu_screen_value_xpos &&
5309 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5310 correct_font_draw_xoffset = TRUE;
5312 /* check if setup value would overlap with setup text when printed */
5313 /* (this can happen for extreme/wrong values for font draw offset) */
5314 if (correct_font_draw_xoffset)
5316 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5317 font_draw_xoffset_modified = TRUE;
5319 if (type & TYPE_KEY)
5320 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5321 else if (!(type & TYPE_STRING))
5322 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5323 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5327 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5328 DrawText(startx + i * font_width, starty, " ", font_nr);
5330 DrawText(startx, starty, value_string, font_nr);
5332 if (font_draw_xoffset_modified)
5333 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5336 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5338 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5339 struct TokenInfo *si = &setup_info[si_pos];
5341 if (si->type & TYPE_BOOLEAN_STYLE)
5343 *(boolean *)si->value ^= TRUE;
5345 else if (si->type & TYPE_YES_NO_AUTO)
5349 (*(int *)si->value == AUTO ? TRUE :
5350 *(int *)si->value == TRUE ? FALSE : AUTO) :
5351 (*(int *)si->value == TRUE ? AUTO :
5352 *(int *)si->value == AUTO ? FALSE : TRUE));
5354 else if (si->type & TYPE_KEY)
5358 si->type |= TYPE_QUERY;
5359 drawSetupValue(screen_pos, setup_info_pos_raw);
5360 si->type &= ~TYPE_QUERY;
5362 key = getSetupKey();
5363 if (key != KSYM_UNDEFINED)
5364 *(Key *)si->value = key;
5367 drawSetupValue(screen_pos, setup_info_pos_raw);
5369 // fullscreen state may have changed at this point
5370 if (si->value == &setup.fullscreen)
5371 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5374 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5377 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5378 struct TokenInfo *si = &setup_info[si_pos];
5379 int xpos = MENU_SCREEN_START_XPOS;
5380 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5381 int font_nr = getSetupTextFont(si->type);
5383 if (setup_info == setup_info_input)
5384 font_nr = FONT_MENU_1;
5387 font_nr = FONT_ACTIVE(font_nr);
5389 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5391 if (si->type & ~TYPE_SKIP_ENTRY)
5392 drawCursor(screen_pos, active);
5395 static void drawSetupInfoList(struct TokenInfo *setup_info,
5396 int first_entry, int num_page_entries)
5400 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5401 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5403 if (num_page_entries > max_setup_info)
5404 num_page_entries = max_setup_info;
5406 if (first_entry + num_page_entries > max_setup_info)
5409 clearMenuListArea();
5411 for (i = 0; i < num_page_entries; i++)
5413 int setup_info_pos = first_entry + i;
5414 struct TokenInfo *si = &setup_info[setup_info_pos];
5415 void *value_ptr = si->value;
5417 /* set some entries to "unchangeable" according to other variables */
5418 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5419 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5420 (value_ptr == &setup.sound_music && !audio.music_available) ||
5421 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5422 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5423 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5424 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5425 si->type |= TYPE_GHOSTED;
5427 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5428 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5429 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5430 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5431 else if (si->type & ~TYPE_SKIP_ENTRY)
5432 initCursor(i, IMG_MENU_BUTTON);
5434 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5436 if (si->type & TYPE_VALUE)
5437 drawSetupValue(i, setup_info_pos);
5441 static void DrawSetupScreen_Generic()
5443 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5444 boolean redraw_all = FALSE;
5445 char *title_string = NULL;
5450 FreeScreenGadgets();
5451 CreateScreenGadgets();
5453 CloseDoor(DOOR_CLOSE_2);
5455 if (redraw_mask & REDRAW_ALL)
5462 if (setup_mode == SETUP_MODE_MAIN)
5464 setup_info = setup_info_main;
5465 title_string = "Setup";
5467 else if (setup_mode == SETUP_MODE_GAME)
5469 setup_info = setup_info_game;
5470 title_string = "Setup Game";
5472 else if (setup_mode == SETUP_MODE_EDITOR)
5474 setup_info = setup_info_editor;
5475 title_string = "Setup Editor";
5477 else if (setup_mode == SETUP_MODE_GRAPHICS)
5479 setup_info = setup_info_graphics;
5480 title_string = "Setup Graphics";
5482 else if (setup_mode == SETUP_MODE_SOUND)
5484 setup_info = setup_info_sound;
5485 title_string = "Setup Sound";
5487 else if (setup_mode == SETUP_MODE_ARTWORK)
5489 setup_info = setup_info_artwork;
5490 title_string = "Custom Artwork";
5492 else if (setup_mode == SETUP_MODE_TOUCH)
5494 setup_info = setup_info_touch;
5495 title_string = "Setup Touch Ctrls";
5497 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5499 setup_info = setup_info_shortcuts;
5500 title_string = "Setup Shortcuts";
5502 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5504 setup_info = setup_info_shortcuts_1;
5505 title_string = "Setup Shortcuts";
5507 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5509 setup_info = setup_info_shortcuts_2;
5510 title_string = "Setup Shortcuts";
5512 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5514 setup_info = setup_info_shortcuts_3;
5515 title_string = "Setup Shortcuts";
5517 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5519 setup_info = setup_info_shortcuts_4;
5520 title_string = "Setup Shortcuts";
5522 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5524 setup_info = setup_info_shortcuts_5;
5525 title_string = "Setup Shortcuts";
5528 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5530 // determine maximal number of setup entries that can be displayed on screen
5532 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5535 // determine maximal number of setup entries available for this setup screen
5537 for (i = 0; setup_info[i].type != 0; i++)
5540 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5542 MapScreenGadgets(max_setup_info);
5545 redraw_mask = fade_mask = REDRAW_ALL;
5552 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5554 static int choice_store[MAX_SETUP_MODES];
5555 static int first_entry_store[MAX_SETUP_MODES];
5556 int choice = choice_store[setup_mode]; /* starts with 0 */
5557 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5559 int y = choice - first_entry;
5561 boolean position_set_by_scrollbar = (dx == 999);
5562 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5563 int num_page_entries;
5565 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5567 if (button == MB_MENU_INITIALIZE)
5569 /* advance to first valid menu entry */
5570 while (choice < num_setup_info &&
5571 setup_info[choice].type & TYPE_SKIP_ENTRY)
5574 if (position_set_by_scrollbar)
5575 first_entry = first_entry_store[setup_mode] = dy;
5577 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5578 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5580 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5582 if (choice < first_entry)
5584 choice = first_entry;
5586 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5589 else if (choice > first_entry + num_page_entries - 1)
5591 choice = first_entry + num_page_entries - 1;
5593 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5597 choice_store[setup_mode] = choice;
5599 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5603 else if (button == MB_MENU_LEAVE)
5607 PlaySound(SND_MENU_ITEM_SELECTING);
5609 for (i = 0; setup_info[i].type != 0; i++)
5611 if (setup_info[i].type & TYPE_LEAVE_MENU)
5613 void (*menu_callback_function)(void) = setup_info[i].value;
5617 menu_callback_function();
5619 break; /* absolutely needed because function changes 'setup_info'! */
5626 if (mx || my) /* mouse input */
5628 x = (mx - mSX) / 32;
5629 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5631 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5633 /* move cursor instead of scrolling when already at start/end of list */
5634 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5636 else if (dy == +1 * SCROLL_LINE &&
5637 first_entry + num_page_entries == max_setup_info)
5640 /* handle scrolling screen one line or page */
5642 y + dy > num_page_entries - 1)
5644 boolean redraw = FALSE;
5646 if (ABS(dy) == SCROLL_PAGE)
5647 step = num_page_entries - 1;
5649 if (dy < 0 && first_entry > 0)
5651 /* scroll page/line up */
5653 first_entry -= step;
5654 if (first_entry < 0)
5659 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5661 /* scroll page/line down */
5663 first_entry += step;
5664 if (first_entry + num_page_entries > max_setup_info)
5665 first_entry = MAX(0, max_setup_info - num_page_entries);
5672 choice += first_entry - first_entry_store[setup_mode];
5674 if (choice < first_entry)
5676 choice = first_entry;
5678 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5681 else if (choice > first_entry + num_page_entries - 1)
5683 choice = first_entry + num_page_entries - 1;
5685 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5688 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5692 if (choice < first_entry ||
5693 choice > first_entry + num_page_entries - 1)
5694 first_entry += SIGN(dy);
5697 first_entry_store[setup_mode] = first_entry;
5698 choice_store[setup_mode] = choice;
5700 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5702 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5704 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5705 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5713 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5715 if (setup_info[choice].type & menu_navigation_type ||
5716 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5717 setup_info[choice].type & TYPE_YES_NO_AUTO)
5718 button = MB_MENU_CHOICE;
5723 /* jump to next non-empty menu entry (up or down) */
5724 while (first_entry + y > 0 &&
5725 first_entry + y < max_setup_info - 1 &&
5726 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
5729 if (!IN_VIS_MENU(x, y))
5731 choice += y - y_old;
5733 if (choice < first_entry)
5734 first_entry = choice;
5735 else if (choice > first_entry + num_page_entries - 1)
5736 first_entry = choice - num_page_entries + 1;
5738 if (first_entry >= 0 &&
5739 first_entry + num_page_entries <= max_setup_info)
5741 first_entry_store[setup_mode] = first_entry;
5743 if (choice < first_entry)
5744 choice = first_entry;
5745 else if (choice > first_entry + num_page_entries - 1)
5746 choice = first_entry + num_page_entries - 1;
5748 choice_store[setup_mode] = choice;
5750 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5752 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5754 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5755 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5762 if (!anyScrollbarGadgetActive() &&
5763 IN_VIS_MENU(x, y) &&
5764 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
5765 y >= 0 && y < num_page_entries)
5769 if (first_entry + y != choice &&
5770 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
5772 PlaySound(SND_MENU_ITEM_ACTIVATING);
5774 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
5775 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
5777 choice = choice_store[setup_mode] = first_entry + y;
5780 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
5782 PlaySound(SND_MENU_ITEM_SELECTING);
5784 /* when selecting key headline, execute function for key value change */
5785 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
5786 setup_info[first_entry + y + 1].type & TYPE_KEY)
5789 /* when selecting string value, execute function for list selection */
5790 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
5791 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
5794 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
5796 void (*menu_callback_function)(void) =
5797 setup_info[first_entry + y].value;
5799 FadeSetFromType(setup_info[first_entry + y].type);
5801 menu_callback_function();
5805 if (setup_info[first_entry + y].type & TYPE_VALUE)
5806 changeSetupValue(y, first_entry + y, dx);
5812 void DrawSetupScreen_Input()
5816 FadeOut(REDRAW_FIELD);
5820 setup_info = setup_info_input;
5822 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5824 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5825 "Joysticks deactivated on this screen");
5827 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5829 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5830 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5831 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5832 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5833 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5834 initCursor(i, IMG_MENU_BUTTON);
5836 DrawCursorAndText_Setup(i, -1, FALSE);
5839 /* create gadgets for setup input menu screen */
5840 FreeScreenGadgets();
5841 CreateScreenGadgets();
5843 /* map gadgets for setup input menu screen */
5844 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5846 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5848 FadeIn(REDRAW_FIELD);
5853 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5855 if (device_name == NULL)
5858 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5861 if (strlen(device_name) > 1)
5863 char c1 = device_name[strlen(device_name) - 1];
5864 char c2 = device_name[strlen(device_name) - 2];
5866 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5867 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5870 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5871 strlen(device_name));
5874 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5877 static struct SetupKeyboardInfo custom_key;
5884 { &custom_key.left, "Joystick Left" },
5885 { &custom_key.right, "Joystick Right" },
5886 { &custom_key.up, "Joystick Up" },
5887 { &custom_key.down, "Joystick Down" },
5888 { &custom_key.snap, "Button 1" },
5889 { &custom_key.drop, "Button 2" }
5891 static char *joystick_name[MAX_PLAYERS] =
5898 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5902 custom_key = setup.input[player_nr].key;
5904 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5905 FONT_INPUT_1_ACTIVE);
5907 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5909 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5910 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5912 if (setup.input[player_nr].use_joystick)
5914 char *device_name = setup.input[player_nr].joy.device_name;
5915 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5916 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5918 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5919 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5923 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5924 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5927 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5929 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5930 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5931 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5932 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5934 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5935 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5936 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5937 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5938 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5939 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5941 for (i = 0; i < 6; i++)
5943 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5945 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5947 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5948 (setup.input[player_nr].use_joystick ?
5950 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5954 static int input_player_nr = 0;
5956 void HandleSetupScreen_Input_Player(int step, int direction)
5958 int old_player_nr = input_player_nr;
5961 new_player_nr = old_player_nr + step * direction;
5962 if (new_player_nr < 0)
5964 if (new_player_nr > MAX_PLAYERS - 1)
5965 new_player_nr = MAX_PLAYERS - 1;
5967 if (new_player_nr != old_player_nr)
5969 input_player_nr = new_player_nr;
5971 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5975 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5977 static int choice = 0;
5980 int pos_start = SETUPINPUT_SCREEN_POS_START;
5981 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5982 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5983 int pos_end = SETUPINPUT_SCREEN_POS_END;
5985 if (button == MB_MENU_INITIALIZE)
5987 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5989 DrawCursorAndText_Setup(choice, -1, TRUE);
5993 else if (button == MB_MENU_LEAVE)
5995 setup_mode = SETUP_MODE_MAIN;
6002 if (mx || my) /* mouse input */
6004 x = (mx - mSX) / 32;
6005 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6007 else if (dx || dy) /* keyboard input */
6009 if (dx && choice == 0)
6010 x = (dx < 0 ? 10 : 12);
6011 else if ((dx && choice == 1) ||
6012 (dx == +1 && choice == 2) ||
6013 (dx == -1 && choice == pos_end))
6014 button = MB_MENU_CHOICE;
6018 if (y >= pos_empty1 && y <= pos_empty2)
6019 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6022 if (y == 0 && dx != 0 && button)
6024 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6026 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6027 y >= pos_start && y <= pos_end &&
6028 !(y >= pos_empty1 && y <= pos_empty2))
6034 DrawCursorAndText_Setup(choice, -1, FALSE);
6035 DrawCursorAndText_Setup(y, -1, TRUE);
6037 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6046 char *device_name = setup.input[input_player_nr].joy.device_name;
6048 if (!setup.input[input_player_nr].use_joystick)
6050 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6052 setJoystickDeviceToNr(device_name, new_device_nr);
6053 setup.input[input_player_nr].use_joystick = TRUE;
6057 int device_nr = getJoystickNrFromDeviceName(device_name);
6058 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6060 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6061 setup.input[input_player_nr].use_joystick = FALSE;
6063 setJoystickDeviceToNr(device_name, new_device_nr);
6066 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6070 if (setup.input[input_player_nr].use_joystick)
6073 CalibrateJoystick(input_player_nr);
6076 CustomizeKeyboard(input_player_nr);
6078 else if (y == pos_end)
6084 setup_mode = SETUP_MODE_MAIN;
6091 void CustomizeKeyboard(int player_nr)
6095 boolean finished = FALSE;
6096 static struct SetupKeyboardInfo custom_key;
6101 } customize_step[] =
6103 { &custom_key.left, "Move Left" },
6104 { &custom_key.right, "Move Right" },
6105 { &custom_key.up, "Move Up" },
6106 { &custom_key.down, "Move Down" },
6107 { &custom_key.snap, "Snap Field" },
6108 { &custom_key.drop, "Drop Element" }
6111 /* read existing key bindings from player setup */
6112 custom_key = setup.input[player_nr].key;
6115 FadeOut(REDRAW_FIELD);
6119 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6122 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6123 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6124 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6125 "Key:", FONT_INPUT_1_ACTIVE);
6126 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6127 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6129 FadeIn(REDRAW_FIELD);
6135 if (PendingEvent()) /* got event */
6143 case EVENT_KEYPRESS:
6145 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6147 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6149 if (key == KSYM_Escape)
6150 FadeSkipNextFadeIn();
6156 /* all keys configured -- wait for "Escape" or "Return" key */
6160 /* press 'Enter' to keep the existing key binding */
6161 if (key == KSYM_Return)
6162 key = *customize_step[step_nr].key;
6164 /* check if key already used */
6165 for (i = 0; i < step_nr; i++)
6166 if (*customize_step[i].key == key)
6171 /* got new key binding */
6172 *customize_step[step_nr].key = key;
6173 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6175 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6176 getKeyNameFromKey(key), FONT_VALUE_1);
6179 /* un-highlight last query */
6180 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6181 customize_step[step_nr - 1].text, FONT_MENU_1);
6182 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6183 "Key:", FONT_MENU_1);
6185 /* press 'Enter' to leave */
6188 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6189 "Press Enter", FONT_TITLE_1);
6193 /* query next key binding */
6194 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6195 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6196 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6197 "Key:", FONT_INPUT_1_ACTIVE);
6198 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6199 getKeyNameFromKey(*customize_step[step_nr].key),
6204 case EVENT_KEYRELEASE:
6205 key_joystick_mapping = 0;
6209 HandleOtherEvents(&event);
6217 /* don't eat all CPU time */
6221 /* write new key bindings back to player setup */
6222 setup.input[player_nr].key = custom_key;
6225 DrawSetupScreen_Input();
6228 static boolean CalibrateJoystickMain(int player_nr)
6230 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6231 int new_joystick_xright = JOYSTICK_XMIDDLE;
6232 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6233 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6234 int new_joystick_xmiddle, new_joystick_ymiddle;
6236 int joystick_fd = joystick.fd[player_nr];
6237 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6238 boolean check[3][3];
6239 int check_remaining = 3 * 3;
6244 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6247 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6251 FadeOut(REDRAW_FIELD);
6255 for (y = 0; y < 3; y++)
6257 for (x = 0; x < 3; x++)
6259 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6260 check[x][y] = FALSE;
6264 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6265 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6266 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6267 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6268 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6269 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6270 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6272 joy_value = Joystick(player_nr);
6273 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6274 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6276 /* eventually uncalibrated center position (joystick could be uncentered) */
6277 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6280 new_joystick_xmiddle = joy_x;
6281 new_joystick_ymiddle = joy_y;
6283 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6285 FadeIn(REDRAW_FIELD);
6287 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6292 if (PendingEvent()) /* got event */
6300 case EVENT_KEYPRESS:
6301 switch (GetEventKey((KeyEvent *)&event, TRUE))
6304 if (check_remaining == 0)
6309 FadeSkipNextFadeIn();
6318 case EVENT_KEYRELEASE:
6319 key_joystick_mapping = 0;
6323 HandleOtherEvents(&event);
6328 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6331 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6332 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6333 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6334 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6336 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6337 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6338 setup.input[player_nr].joy.xright = new_joystick_xright;
6339 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6340 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6341 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6343 CheckJoystickData();
6345 joy_value = Joystick(player_nr);
6347 if (joy_value & JOY_BUTTON && check_remaining == 0)
6350 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6351 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6353 if (x != last_x || y != last_y)
6355 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6356 IMG_MENU_CALIBRATE_YELLOW, 0);
6357 DrawFixedGraphic(xpos + x, ypos + y,
6358 IMG_MENU_CALIBRATE_RED, 0);
6363 if (check_remaining > 0 && !check[x+1][y+1])
6365 check[x+1][y+1] = TRUE;
6373 /* don't eat all CPU time */
6377 /* calibrated center position (joystick should now be centered) */
6378 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6381 new_joystick_xmiddle = joy_x;
6382 new_joystick_ymiddle = joy_y;
6386 /* wait until the last pressed button was released */
6387 while (Joystick(player_nr) & JOY_BUTTON)
6389 if (PendingEvent()) /* got event */
6394 HandleOtherEvents(&event);
6403 void CalibrateJoystick(int player_nr)
6405 if (!CalibrateJoystickMain(player_nr))
6407 char *device_name = setup.input[player_nr].joy.device_name;
6408 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6409 int xpos = mSX - SX;
6410 int ypos = mSY - SY;
6414 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6415 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6418 Delay(2000); /* show error message for a short time */
6423 DrawSetupScreen_Input();
6426 void DrawSetupScreen()
6428 DeactivateJoystick();
6430 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6432 if (setup_mode == SETUP_MODE_INPUT)
6433 DrawSetupScreen_Input();
6434 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6435 DrawChooseTree(&game_speed_current);
6436 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6437 DrawChooseTree(&scroll_delay_current);
6438 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6439 DrawChooseTree(&screen_mode_current);
6440 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6441 DrawChooseTree(&window_size_current);
6442 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6443 DrawChooseTree(&scaling_type_current);
6444 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6445 DrawChooseTree(&artwork.gfx_current);
6446 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6447 DrawChooseTree(&artwork.snd_current);
6448 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6449 DrawChooseTree(&artwork.mus_current);
6450 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6451 DrawChooseTree(&volume_simple_current);
6452 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6453 DrawChooseTree(&volume_loops_current);
6454 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6455 DrawChooseTree(&volume_music_current);
6456 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6457 DrawChooseTree(&touch_control_current);
6458 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6459 DrawChooseTree(&move_distance_current);
6460 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6461 DrawChooseTree(&drop_distance_current);
6463 DrawSetupScreen_Generic();
6469 void RedrawSetupScreenAfterFullscreenToggle()
6471 if (setup_mode == SETUP_MODE_GRAPHICS ||
6472 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6474 // update list selection from "setup.window_scaling_percent"
6475 execSetupGraphics_setWindowSizes(TRUE);
6481 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6483 if (setup_mode == SETUP_MODE_INPUT)
6484 HandleSetupScreen_Input(mx, my, dx, dy, button);
6485 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6486 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6487 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6488 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6489 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6490 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6491 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6492 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6493 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6494 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6495 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6496 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6497 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6498 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6499 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6500 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6501 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6502 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6503 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6504 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6505 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6506 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6507 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6508 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6509 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6510 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6511 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6512 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6514 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6517 void HandleGameActions()
6519 if (game_status != GAME_MODE_PLAYING)
6522 GameActions(); /* main game loop */
6524 if (tape.auto_play && !tape.playing)
6525 AutoPlayTape(); /* continue automatically playing next tape */
6529 /* ---------- new screen button stuff -------------------------------------- */
6531 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6535 case SCREEN_CTRL_ID_PREV_LEVEL:
6536 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6537 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6540 case SCREEN_CTRL_ID_NEXT_LEVEL:
6541 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6542 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6545 case SCREEN_CTRL_ID_PREV_PLAYER:
6546 *x = mSX + TILEX * 10;
6547 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6550 case SCREEN_CTRL_ID_NEXT_PLAYER:
6551 *x = mSX + TILEX * 12;
6552 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6556 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6562 int gfx_unpressed, gfx_pressed;
6563 void (*get_gadget_position)(int *, int *, int);
6567 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6570 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6571 getScreenMenuButtonPos,
6572 SCREEN_CTRL_ID_PREV_LEVEL,
6577 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6578 getScreenMenuButtonPos,
6579 SCREEN_CTRL_ID_NEXT_LEVEL,
6584 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6585 getScreenMenuButtonPos,
6586 SCREEN_CTRL_ID_PREV_PLAYER,
6591 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6592 getScreenMenuButtonPos,
6593 SCREEN_CTRL_ID_NEXT_PLAYER,
6601 int gfx_unpressed, gfx_pressed;
6605 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6608 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6609 -1, -1, /* these values are not constant, but can change at runtime */
6610 SCREEN_CTRL_ID_SCROLL_UP,
6614 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6615 -1, -1, /* these values are not constant, but can change at runtime */
6616 SCREEN_CTRL_ID_SCROLL_DOWN,
6623 int gfx_unpressed, gfx_pressed;
6629 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6632 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6633 -1, -1, /* these values are not constant, but can change at runtime */
6634 -1, -1, /* these values are not constant, but can change at runtime */
6635 GD_TYPE_SCROLLBAR_VERTICAL,
6636 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6637 "scroll level series vertically"
6641 static void CreateScreenMenubuttons()
6643 struct GadgetInfo *gi;
6644 unsigned int event_mask;
6647 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6649 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6650 int gfx_unpressed, gfx_pressed;
6651 int x, y, width, height;
6652 int gd_x1, gd_x2, gd_y1, gd_y2;
6653 int id = menubutton_info[i].gadget_id;
6655 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6657 menubutton_info[i].get_gadget_position(&x, &y, id);
6659 width = SC_MENUBUTTON_XSIZE;
6660 height = SC_MENUBUTTON_YSIZE;
6662 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6663 gfx_pressed = menubutton_info[i].gfx_pressed;
6664 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6665 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6666 gd_x1 = graphic_info[gfx_unpressed].src_x;
6667 gd_y1 = graphic_info[gfx_unpressed].src_y;
6668 gd_x2 = graphic_info[gfx_pressed].src_x;
6669 gd_y2 = graphic_info[gfx_pressed].src_y;
6671 gi = CreateGadget(GDI_CUSTOM_ID, id,
6672 GDI_CUSTOM_TYPE_ID, i,
6673 GDI_INFO_TEXT, menubutton_info[i].infotext,
6678 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6679 GDI_STATE, GD_BUTTON_UNPRESSED,
6680 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6681 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6682 GDI_DIRECT_DRAW, FALSE,
6683 GDI_EVENT_MASK, event_mask,
6684 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6688 Error(ERR_EXIT, "cannot create gadget");
6690 screen_gadget[id] = gi;
6694 static void CreateScreenScrollbuttons()
6696 struct GadgetInfo *gi;
6697 unsigned int event_mask;
6700 /* these values are not constant, but can change at runtime */
6701 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6702 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6703 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6704 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6706 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6708 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6709 int gfx_unpressed, gfx_pressed;
6710 int x, y, width, height;
6711 int gd_x1, gd_x2, gd_y1, gd_y2;
6712 int id = scrollbutton_info[i].gadget_id;
6714 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6716 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6717 y = mSY + scrollbutton_info[i].y;
6718 width = SC_SCROLLBUTTON_XSIZE;
6719 height = SC_SCROLLBUTTON_YSIZE;
6721 /* correct scrollbar position if placed outside menu (playfield) area */
6722 if (x > SX + SC_SCROLL_UP_XPOS)
6723 x = SX + SC_SCROLL_UP_XPOS;
6725 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6726 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6727 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6729 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6730 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6731 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6732 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6733 gd_x1 = graphic_info[gfx_unpressed].src_x;
6734 gd_y1 = graphic_info[gfx_unpressed].src_y;
6735 gd_x2 = graphic_info[gfx_pressed].src_x;
6736 gd_y2 = graphic_info[gfx_pressed].src_y;
6738 gi = CreateGadget(GDI_CUSTOM_ID, id,
6739 GDI_CUSTOM_TYPE_ID, i,
6740 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6745 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6746 GDI_STATE, GD_BUTTON_UNPRESSED,
6747 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6748 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6749 GDI_DIRECT_DRAW, FALSE,
6750 GDI_EVENT_MASK, event_mask,
6751 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6755 Error(ERR_EXIT, "cannot create gadget");
6757 screen_gadget[id] = gi;
6761 static void CreateScreenScrollbars()
6765 /* these values are not constant, but can change at runtime */
6766 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6767 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6768 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6769 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6771 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6773 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6774 int gfx_unpressed, gfx_pressed;
6775 int x, y, width, height;
6776 int gd_x1, gd_x2, gd_y1, gd_y2;
6777 struct GadgetInfo *gi;
6778 int items_max, items_visible, item_position;
6779 unsigned int event_mask;
6780 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6781 int id = scrollbar_info[i].gadget_id;
6783 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6785 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6786 y = mSY + scrollbar_info[i].y;
6787 width = scrollbar_info[i].width;
6788 height = scrollbar_info[i].height;
6790 /* correct scrollbar position if placed outside menu (playfield) area */
6791 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6792 x = SX + SC_SCROLL_VERTICAL_XPOS;
6794 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6795 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6797 items_max = num_page_entries;
6798 items_visible = num_page_entries;
6801 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6802 gfx_pressed = scrollbar_info[i].gfx_pressed;
6803 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6804 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6805 gd_x1 = graphic_info[gfx_unpressed].src_x;
6806 gd_y1 = graphic_info[gfx_unpressed].src_y;
6807 gd_x2 = graphic_info[gfx_pressed].src_x;
6808 gd_y2 = graphic_info[gfx_pressed].src_y;
6810 gi = CreateGadget(GDI_CUSTOM_ID, id,
6811 GDI_CUSTOM_TYPE_ID, i,
6812 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6817 GDI_TYPE, scrollbar_info[i].type,
6818 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6819 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6820 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6821 GDI_WHEEL_AREA_X, SX,
6822 GDI_WHEEL_AREA_Y, SY,
6823 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6824 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6825 GDI_STATE, GD_BUTTON_UNPRESSED,
6826 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6827 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6828 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6829 GDI_DIRECT_DRAW, FALSE,
6830 GDI_EVENT_MASK, event_mask,
6831 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6835 Error(ERR_EXIT, "cannot create gadget");
6837 screen_gadget[id] = gi;
6841 void CreateScreenGadgets()
6843 int last_game_status = game_status; /* save current game status */
6845 CreateScreenMenubuttons();
6847 CreateScreenScrollbuttons();
6848 CreateScreenScrollbars();
6850 game_status = last_game_status; /* restore current game status */
6853 void FreeScreenGadgets()
6857 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6858 FreeGadget(screen_gadget[i]);
6861 void MapScreenMenuGadgets(int screen_mask)
6865 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6866 if (screen_mask & menubutton_info[i].screen_mask)
6867 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6870 void MapScreenGadgets(int num_entries)
6874 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6877 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6878 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6880 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6881 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6884 void MapScreenTreeGadgets(TreeInfo *ti)
6886 MapScreenGadgets(numTreeInfoInGroup(ti));
6889 static void HandleScreenGadgets(struct GadgetInfo *gi)
6891 int id = gi->custom_id;
6892 int button = gi->event.button;
6893 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6897 case SCREEN_CTRL_ID_PREV_LEVEL:
6898 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6901 case SCREEN_CTRL_ID_NEXT_LEVEL:
6902 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6905 case SCREEN_CTRL_ID_PREV_PLAYER:
6906 HandleSetupScreen_Input_Player(step, -1);
6909 case SCREEN_CTRL_ID_NEXT_PLAYER:
6910 HandleSetupScreen_Input_Player(step, +1);
6913 case SCREEN_CTRL_ID_SCROLL_UP:
6914 if (game_status == GAME_MODE_LEVELS)
6915 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6916 else if (game_status == GAME_MODE_LEVELNR)
6917 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6918 else if (game_status == GAME_MODE_SETUP)
6919 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6922 case SCREEN_CTRL_ID_SCROLL_DOWN:
6923 if (game_status == GAME_MODE_LEVELS)
6924 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6925 else if (game_status == GAME_MODE_LEVELNR)
6926 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6927 else if (game_status == GAME_MODE_SETUP)
6928 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6931 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6932 if (game_status == GAME_MODE_LEVELS)
6933 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6934 else if (game_status == GAME_MODE_LEVELNR)
6935 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6936 else if (game_status == GAME_MODE_SETUP)
6937 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);