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);
3295 FreeScreenGadgets();
3296 CreateScreenGadgets();
3298 CloseDoor(DOOR_CLOSE_2);
3304 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3305 MapScreenTreeGadgets(*ti_ptr);
3312 static void AdjustScrollbar(int id, int items_max, int items_visible,
3315 struct GadgetInfo *gi = screen_gadget[id];
3317 if (item_position > items_max - items_visible)
3318 item_position = items_max - items_visible;
3320 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3321 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3322 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3325 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3327 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3331 static void clearMenuListArea()
3333 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3335 /* correct scrollbar position if placed outside menu (playfield) area */
3336 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
3337 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
3339 /* clear menu list area, but not title or scrollbar */
3340 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3341 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
3344 static void drawChooseTreeList(int first_entry, int num_page_entries,
3348 char *title_string = NULL;
3349 int yoffset_sets = MENU_TITLE1_YPOS;
3350 int yoffset_setup = 16;
3351 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3352 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3353 int last_game_status = game_status; /* save current game status */
3355 title_string = ti->infotext;
3357 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3359 clearMenuListArea();
3361 for (i = 0; i < num_page_entries; i++)
3363 TreeInfo *node, *node_first;
3364 int entry_pos = first_entry + i;
3365 int xpos = MENU_SCREEN_START_XPOS;
3366 int ypos = MENU_SCREEN_START_YPOS + i;
3367 int startx = mSX + xpos * 32;
3368 int starty = mSY + ypos * 32;
3369 int font_nr = FONT_TEXT_1;
3370 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3371 int startx_text = startx + font_xoffset;
3372 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3373 int text_size = startx_scrollbar - startx_text;
3374 int max_buffer_len = text_size / getFontWidth(font_nr);
3375 char buffer[max_buffer_len + 1];
3377 node_first = getTreeInfoFirstGroupEntry(ti);
3378 node = getTreeInfoFromPos(node_first, entry_pos);
3380 strncpy(buffer, node->name, max_buffer_len);
3381 buffer[max_buffer_len] = '\0';
3383 DrawText(startx, starty, buffer, font_nr + node->color);
3385 if (node->parent_link)
3386 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3387 else if (node->level_group)
3388 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3390 initCursor(i, IMG_MENU_BUTTON);
3393 game_status = last_game_status; /* restore current game status */
3395 redraw_mask |= REDRAW_FIELD;
3398 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3400 TreeInfo *node, *node_first;
3401 int x, last_redraw_mask = redraw_mask;
3402 int ypos = MENU_TITLE2_YPOS;
3403 int font_nr = FONT_TITLE_2;
3405 if (ti->type == TREE_TYPE_LEVEL_NR)
3406 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3408 if (ti->type != TREE_TYPE_LEVEL_DIR)
3411 node_first = getTreeInfoFirstGroupEntry(ti);
3412 node = getTreeInfoFromPos(node_first, entry_pos);
3414 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3416 if (node->parent_link)
3417 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3418 node->node_parent->name);
3419 else if (node->level_group)
3420 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3422 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3423 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3424 node->levels, (node->levels > 1 ? "levels" : "level"),
3427 /* let BackToFront() redraw only what is needed */
3428 redraw_mask = last_redraw_mask | REDRAW_TILES;
3429 for (x = 0; x < SCR_FIELDX; x++)
3430 MarkTileDirty(x, 1);
3433 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3436 TreeInfo *ti = *ti_ptr;
3438 int y = ti->cl_cursor;
3439 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3440 int num_entries = numTreeInfoInGroup(ti);
3441 int num_page_entries;
3442 int last_game_status = game_status; /* save current game status */
3443 boolean position_set_by_scrollbar = (dx == 999);
3445 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3446 num_page_entries = num_entries;
3448 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3450 game_status = last_game_status; /* restore current game status */
3452 if (button == MB_MENU_INITIALIZE)
3454 int num_entries = numTreeInfoInGroup(ti);
3455 int entry_pos = posTreeInfo(ti);
3457 if (ti->cl_first == -1)
3459 /* only on initialization */
3460 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3461 ti->cl_cursor = entry_pos - ti->cl_first;
3463 else if (ti->cl_cursor >= num_page_entries ||
3464 (num_entries > num_page_entries &&
3465 num_entries - ti->cl_first < num_page_entries))
3467 /* only after change of list size (by custom graphic configuration) */
3468 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3469 ti->cl_cursor = entry_pos - ti->cl_first;
3472 if (position_set_by_scrollbar)
3475 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3478 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3479 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3480 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3484 else if (button == MB_MENU_LEAVE)
3488 PlaySound(SND_MENU_ITEM_SELECTING);
3490 if (ti->node_parent)
3492 *ti_ptr = ti->node_parent;
3493 DrawChooseTree(ti_ptr);
3495 else if (game_status == GAME_MODE_SETUP)
3497 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3498 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3500 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3501 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3502 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3503 execSetupGraphics();
3504 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3505 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3506 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3508 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3509 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3510 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3517 if (game_status == GAME_MODE_LEVELNR)
3519 int new_level_nr = atoi(level_number_current->identifier);
3521 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3524 game_status = GAME_MODE_MAIN;
3526 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3532 if (mx || my) /* mouse input */
3534 int last_game_status = game_status; /* save current game status */
3536 x = (mx - mSX) / 32;
3537 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3539 game_status = last_game_status; /* restore current game status */
3541 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3543 /* move cursor instead of scrolling when already at start/end of list */
3544 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3546 else if (dy == +1 * SCROLL_LINE &&
3547 ti->cl_first + num_page_entries == num_entries)
3550 /* handle scrolling screen one line or page */
3551 if (ti->cl_cursor + dy < 0 ||
3552 ti->cl_cursor + dy > num_page_entries - 1)
3554 boolean redraw = FALSE;
3556 if (ABS(dy) == SCROLL_PAGE)
3557 step = num_page_entries - 1;
3559 if (dy < 0 && ti->cl_first > 0)
3561 /* scroll page/line up */
3563 ti->cl_first -= step;
3564 if (ti->cl_first < 0)
3569 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3571 /* scroll page/line down */
3573 ti->cl_first += step;
3574 if (ti->cl_first + num_page_entries > num_entries)
3575 ti->cl_first = MAX(0, num_entries - num_page_entries);
3582 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3583 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3584 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3586 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3594 /* handle moving cursor one line */
3595 y = ti->cl_cursor + dy;
3600 TreeInfo *node_first, *node_cursor;
3601 int entry_pos = ti->cl_first + y;
3603 node_first = getTreeInfoFirstGroupEntry(ti);
3604 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3606 if (node_cursor->node_group)
3610 PlaySound(SND_MENU_ITEM_SELECTING);
3612 node_cursor->cl_first = ti->cl_first;
3613 node_cursor->cl_cursor = ti->cl_cursor;
3614 *ti_ptr = node_cursor->node_group;
3615 DrawChooseTree(ti_ptr);
3620 else if (dx == -1 && ti->node_parent)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 *ti_ptr = ti->node_parent;
3627 DrawChooseTree(ti_ptr);
3632 if (!anyScrollbarGadgetActive() &&
3633 IN_VIS_MENU(x, y) &&
3634 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3635 y >= 0 && y < num_page_entries)
3639 if (y != ti->cl_cursor)
3641 PlaySound(SND_MENU_ITEM_ACTIVATING);
3643 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3644 drawChooseTreeCursor(y, TRUE);
3645 drawChooseTreeInfo(ti->cl_first + y, ti);
3652 TreeInfo *node_first, *node_cursor;
3653 int entry_pos = ti->cl_first + y;
3655 PlaySound(SND_MENU_ITEM_SELECTING);
3657 node_first = getTreeInfoFirstGroupEntry(ti);
3658 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3660 if (node_cursor->node_group)
3664 node_cursor->cl_first = ti->cl_first;
3665 node_cursor->cl_cursor = ti->cl_cursor;
3666 *ti_ptr = node_cursor->node_group;
3667 DrawChooseTree(ti_ptr);
3669 else if (node_cursor->parent_link)
3673 *ti_ptr = node_cursor->node_parent;
3674 DrawChooseTree(ti_ptr);
3680 node_cursor->cl_first = ti->cl_first;
3681 node_cursor->cl_cursor = ti->cl_cursor;
3682 *ti_ptr = node_cursor;
3684 if (ti->type == TREE_TYPE_LEVEL_DIR)
3686 LoadLevelSetup_SeriesInfo();
3688 SaveLevelSetup_LastSeries();
3689 SaveLevelSetup_SeriesInfo();
3693 if (game_status == GAME_MODE_SETUP)
3695 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3696 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3698 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3699 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3700 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3701 execSetupGraphics();
3702 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3703 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3704 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3706 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3707 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3708 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3715 if (game_status == GAME_MODE_LEVELNR)
3717 int new_level_nr = atoi(level_number_current->identifier);
3719 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3722 game_status = GAME_MODE_MAIN;
3731 void DrawChooseLevelSet()
3733 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3735 DrawChooseTree(&leveldir_current);
3741 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3743 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3746 void DrawChooseLevelNr()
3750 if (level_number != NULL)
3752 freeTreeInfo(level_number);
3754 level_number = NULL;
3757 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3759 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3760 char identifier[32], name[32];
3763 /* temporarily load level info to get level name */
3764 LoadLevelInfoOnly(i);
3766 ti->node_top = &level_number;
3767 ti->sort_priority = 10000 + value;
3768 ti->color = (level.no_valid_file ? FC_BLUE :
3769 LevelStats_getSolved(i) ? FC_GREEN :
3770 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3772 sprintf(identifier, "%d", value);
3773 sprintf(name, "%03d: %s", value,
3774 (level.no_valid_file ? "(no file)" : level.name));
3776 setString(&ti->identifier, identifier);
3777 setString(&ti->name, name);
3778 setString(&ti->name_sorting, name);
3780 pushTreeInfo(&level_number, ti);
3783 /* sort level number values to start with lowest level number */
3784 sortTreeInfo(&level_number);
3786 /* set current level number to current level number */
3787 level_number_current =
3788 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3790 /* if that also fails, set current level number to first available level */
3791 if (level_number_current == NULL)
3792 level_number_current = level_number;
3794 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3796 DrawChooseTree(&level_number_current);
3802 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3804 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3807 void DrawHallOfFame(int highlight_position)
3809 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3812 FadeSoundsAndMusic();
3814 /* (this is needed when called from GameEnd() after winning a game) */
3815 KeyboardAutoRepeatOn();
3818 /* (this is needed when called from GameEnd() after winning a game) */
3819 SetDrawDeactivationMask(REDRAW_NONE);
3820 SetDrawBackgroundMask(REDRAW_FIELD);
3822 CloseDoor(DOOR_CLOSE_2);
3824 if (highlight_position < 0)
3825 LoadScore(level_nr);
3827 FadeSetEnterScreen();
3836 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3841 static void drawHallOfFameList(int first_entry, int highlight_position)
3845 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3848 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3849 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3850 "HighScores of Level %d", level_nr);
3852 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3854 int entry = first_entry + i;
3855 boolean active = (entry == highlight_position);
3856 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3857 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3858 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3859 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3860 int dx1 = 3 * getFontWidth(font_nr1);
3861 int dx2 = dx1 + getFontWidth(font_nr1);
3862 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
3863 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
3864 int sy = mSY + 64 + i * 32;
3866 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3867 DrawText(mSX + dx1, sy, ".", font_nr1);
3869 for (j = 0; j < num_dots; j++)
3870 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
3872 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3873 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3875 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3878 redraw_mask |= REDRAW_FIELD;
3881 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3883 static int first_entry = 0;
3884 static int highlight_position = 0;
3885 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3887 if (button == MB_MENU_INITIALIZE)
3890 highlight_position = mx;
3891 drawHallOfFameList(first_entry, highlight_position);
3896 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3897 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3901 if (first_entry > 0)
3903 first_entry -= step;
3904 if (first_entry < 0)
3907 drawHallOfFameList(first_entry, highlight_position);
3912 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3914 first_entry += step;
3915 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3916 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3918 drawHallOfFameList(first_entry, highlight_position);
3921 else if (button == MB_MENU_LEAVE)
3923 PlaySound(SND_MENU_ITEM_SELECTING);
3925 FadeSound(SND_BACKGROUND_SCORES);
3927 game_status = GAME_MODE_MAIN;
3931 else if (button == MB_MENU_CHOICE)
3933 PlaySound(SND_MENU_ITEM_SELECTING);
3935 FadeSound(SND_BACKGROUND_SCORES);
3937 game_status = GAME_MODE_MAIN;
3939 DrawAndFadeInMainMenu(REDRAW_FIELD);
3942 if (game_status == GAME_MODE_SCORES)
3943 PlayMenuSoundIfLoop();
3947 /* ========================================================================= */
3948 /* setup screen functions */
3949 /* ========================================================================= */
3951 static struct TokenInfo *setup_info;
3952 static int num_setup_info; /* number of setup entries shown on screen */
3953 static int max_setup_info; /* total number of setup entries in list */
3955 static char *screen_mode_text;
3956 static char *window_size_text;
3957 static char *scaling_type_text;
3958 static char *scroll_delay_text;
3959 static char *game_speed_text;
3960 static char *graphics_set_name;
3961 static char *sounds_set_name;
3962 static char *music_set_name;
3963 static char *volume_simple_text;
3964 static char *volume_loops_text;
3965 static char *volume_music_text;
3966 static char *touch_controls_text;
3967 static char *move_distance_text;
3968 static char *drop_distance_text;
3970 static void execSetupMain()
3972 setup_mode = SETUP_MODE_MAIN;
3977 static void execSetupGame_setGameSpeeds()
3979 if (game_speeds == NULL)
3983 for (i = 0; game_speeds_list[i].value != -1; i++)
3985 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3986 char identifier[32], name[32];
3987 int value = game_speeds_list[i].value;
3988 char *text = game_speeds_list[i].text;
3990 ti->node_top = &game_speeds;
3991 ti->sort_priority = 10000 - value;
3993 sprintf(identifier, "%d", value);
3994 sprintf(name, "%s", text);
3996 setString(&ti->identifier, identifier);
3997 setString(&ti->name, name);
3998 setString(&ti->name_sorting, name);
3999 setString(&ti->infotext, "Game Speed");
4001 pushTreeInfo(&game_speeds, ti);
4004 /* sort game speed values to start with slowest game speed */
4005 sortTreeInfo(&game_speeds);
4007 /* set current game speed to configured game speed value */
4008 game_speed_current =
4009 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4011 /* if that fails, set current game speed to reliable default value */
4012 if (game_speed_current == NULL)
4013 game_speed_current =
4014 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4016 /* if that also fails, set current game speed to first available speed */
4017 if (game_speed_current == NULL)
4018 game_speed_current = game_speeds;
4021 setup.game_frame_delay = atoi(game_speed_current->identifier);
4023 /* needed for displaying game speed text instead of identifier */
4024 game_speed_text = game_speed_current->name;
4027 static void execSetupGame_setScrollDelays()
4029 if (scroll_delays == NULL)
4033 for (i = 0; scroll_delays_list[i].value != -1; i++)
4035 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4036 char identifier[32], name[32];
4037 int value = scroll_delays_list[i].value;
4038 char *text = scroll_delays_list[i].text;
4040 ti->node_top = &scroll_delays;
4041 ti->sort_priority = value;
4043 sprintf(identifier, "%d", value);
4044 sprintf(name, "%s", text);
4046 setString(&ti->identifier, identifier);
4047 setString(&ti->name, name);
4048 setString(&ti->name_sorting, name);
4049 setString(&ti->infotext, "Scaling Type");
4051 pushTreeInfo(&scroll_delays, ti);
4054 /* sort scaling type values to start with lowest scaling type value */
4055 sortTreeInfo(&scroll_delays);
4057 /* set current scaling type value to configured scaling type value */
4058 scroll_delay_current =
4059 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4061 /* if that fails, set current scaling type to reliable default value */
4062 if (scroll_delay_current == NULL)
4063 scroll_delay_current =
4064 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4066 /* if that also fails, set current scaling type to first available value */
4067 if (scroll_delay_current == NULL)
4068 scroll_delay_current = scroll_delays;
4071 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4073 /* needed for displaying scaling type text instead of identifier */
4074 scroll_delay_text = scroll_delay_current->name;
4077 static void execSetupGame()
4079 execSetupGame_setGameSpeeds();
4080 execSetupGame_setScrollDelays();
4082 setup_mode = SETUP_MODE_GAME;
4087 static void execSetupChooseGameSpeed()
4089 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4094 static void execSetupChooseScrollDelay()
4096 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4101 static void execSetupEditor()
4103 setup_mode = SETUP_MODE_EDITOR;
4108 static void execSetupGraphics_setWindowSizes(boolean update_list)
4110 if (window_sizes != NULL && update_list)
4112 freeTreeInfo(window_sizes);
4114 window_sizes = NULL;
4117 if (window_sizes == NULL)
4119 boolean current_window_size_found = FALSE;
4122 for (i = 0; window_sizes_list[i].value != -1; i++)
4124 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4125 char identifier[32], name[32];
4126 int value = window_sizes_list[i].value;
4127 char *text = window_sizes_list[i].text;
4129 ti->node_top = &window_sizes;
4130 ti->sort_priority = value;
4132 sprintf(identifier, "%d", value);
4133 sprintf(name, "%s", text);
4135 setString(&ti->identifier, identifier);
4136 setString(&ti->name, name);
4137 setString(&ti->name_sorting, name);
4138 setString(&ti->infotext, "Window Scaling");
4140 pushTreeInfo(&window_sizes, ti);
4142 if (value == setup.window_scaling_percent)
4143 current_window_size_found = TRUE;
4146 if (!current_window_size_found)
4148 // add entry for non-preset window scaling value
4150 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4151 char identifier[32], name[32];
4152 int value = setup.window_scaling_percent;
4154 ti->node_top = &window_sizes;
4155 ti->sort_priority = value;
4157 sprintf(identifier, "%d", value);
4158 sprintf(name, "%d %% (Current)", value);
4160 setString(&ti->identifier, identifier);
4161 setString(&ti->name, name);
4162 setString(&ti->name_sorting, name);
4163 setString(&ti->infotext, "Window Scaling");
4165 pushTreeInfo(&window_sizes, ti);
4168 /* sort window size values to start with lowest window size value */
4169 sortTreeInfo(&window_sizes);
4171 /* set current window size value to configured window size value */
4172 window_size_current =
4173 getTreeInfoFromIdentifier(window_sizes,
4174 i_to_a(setup.window_scaling_percent));
4176 /* if that fails, set current window size to reliable default value */
4177 if (window_size_current == NULL)
4178 window_size_current =
4179 getTreeInfoFromIdentifier(window_sizes,
4180 i_to_a(STD_WINDOW_SCALING_PERCENT));
4182 /* if that also fails, set current window size to first available value */
4183 if (window_size_current == NULL)
4184 window_size_current = window_sizes;
4187 setup.window_scaling_percent = atoi(window_size_current->identifier);
4189 /* needed for displaying window size text instead of identifier */
4190 window_size_text = window_size_current->name;
4193 static void execSetupGraphics_setScalingTypes()
4195 if (scaling_types == NULL)
4199 for (i = 0; scaling_types_list[i].value != NULL; i++)
4201 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4202 char identifier[32], name[32];
4203 char *value = scaling_types_list[i].value;
4204 char *text = scaling_types_list[i].text;
4206 ti->node_top = &scaling_types;
4207 ti->sort_priority = i;
4209 sprintf(identifier, "%s", value);
4210 sprintf(name, "%s", text);
4212 setString(&ti->identifier, identifier);
4213 setString(&ti->name, name);
4214 setString(&ti->name_sorting, name);
4215 setString(&ti->infotext, "Anti-Aliasing");
4217 pushTreeInfo(&scaling_types, ti);
4220 /* sort scaling type values to start with lowest scaling type value */
4221 sortTreeInfo(&scaling_types);
4223 /* set current scaling type value to configured scaling type value */
4224 scaling_type_current =
4225 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4227 /* if that fails, set current scaling type to reliable default value */
4228 if (scaling_type_current == NULL)
4229 scaling_type_current =
4230 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4232 /* if that also fails, set current scaling type to first available value */
4233 if (scaling_type_current == NULL)
4234 scaling_type_current = scaling_types;
4237 setup.window_scaling_quality = scaling_type_current->identifier;
4239 /* needed for displaying scaling type text instead of identifier */
4240 scaling_type_text = scaling_type_current->name;
4243 static void execSetupGraphics_setScreenModes()
4245 // if (screen_modes == NULL && video.fullscreen_available)
4246 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4250 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4252 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4253 char identifier[32], name[32];
4254 int x = video.fullscreen_modes[i].width;
4255 int y = video.fullscreen_modes[i].height;
4258 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4260 ti->node_top = &screen_modes;
4261 ti->sort_priority = x * 10000 + y;
4263 sprintf(identifier, "%dx%d", x, y);
4264 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4266 setString(&ti->identifier, identifier);
4267 setString(&ti->name, name);
4268 setString(&ti->name_sorting, name);
4269 setString(&ti->infotext, "Fullscreen Mode");
4271 pushTreeInfo(&screen_modes, ti);
4274 /* sort fullscreen modes to start with lowest available screen resolution */
4275 sortTreeInfo(&screen_modes);
4277 /* set current screen mode for fullscreen mode to configured setup value */
4278 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4279 setup.fullscreen_mode);
4281 /* if that fails, set current screen mode to reliable default value */
4282 if (screen_mode_current == NULL)
4283 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4284 DEFAULT_FULLSCREEN_MODE);
4286 /* if that also fails, set current screen mode to first available mode */
4287 if (screen_mode_current == NULL)
4288 screen_mode_current = screen_modes;
4290 if (screen_mode_current == NULL)
4291 video.fullscreen_available = FALSE;
4294 // if (video.fullscreen_available)
4295 if (screen_mode_current != NULL)
4297 setup.fullscreen_mode = screen_mode_current->identifier;
4299 /* needed for displaying screen mode name instead of identifier */
4300 screen_mode_text = screen_mode_current->name;
4304 static void execSetupGraphics()
4306 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4308 // update "setup.window_scaling_percent" from list selection
4309 execSetupGraphics_setWindowSizes(FALSE);
4313 // update list selection from "setup.window_scaling_percent"
4314 execSetupGraphics_setWindowSizes(TRUE);
4317 execSetupGraphics_setScalingTypes();
4318 execSetupGraphics_setScreenModes();
4320 setup_mode = SETUP_MODE_GRAPHICS;
4324 #if defined(TARGET_SDL2)
4325 // window scaling may have changed at this point
4326 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4328 // window scaling quality may have changed at this point
4329 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4330 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4334 #if !defined(PLATFORM_ANDROID)
4335 #if defined(TARGET_SDL2)
4336 static void execSetupChooseWindowSize()
4338 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4343 static void execSetupChooseScalingType()
4345 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4350 static void execSetupChooseScreenMode()
4352 if (!video.fullscreen_available)
4355 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4362 static void execSetupChooseVolumeSimple()
4364 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4369 static void execSetupChooseVolumeLoops()
4371 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4376 static void execSetupChooseVolumeMusic()
4378 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4383 static void execSetupSound()
4385 if (volumes_simple == NULL)
4387 boolean current_volume_simple_found = FALSE;
4390 for (i = 0; volumes_list[i].value != -1; i++)
4392 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4393 char identifier[32], name[32];
4394 int value = volumes_list[i].value;
4395 char *text = volumes_list[i].text;
4397 ti->node_top = &volumes_simple;
4398 ti->sort_priority = value;
4400 sprintf(identifier, "%d", value);
4401 sprintf(name, "%s", text);
4403 setString(&ti->identifier, identifier);
4404 setString(&ti->name, name);
4405 setString(&ti->name_sorting, name);
4406 setString(&ti->infotext, "Sound Volume");
4408 pushTreeInfo(&volumes_simple, ti);
4410 if (value == setup.volume_simple)
4411 current_volume_simple_found = TRUE;
4414 if (!current_volume_simple_found)
4416 // add entry for non-preset volume value
4418 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4419 char identifier[32], name[32];
4420 int value = setup.volume_simple;
4422 ti->node_top = &volumes_simple;
4423 ti->sort_priority = value;
4425 sprintf(identifier, "%d", value);
4426 sprintf(name, "%d %% (Current)", value);
4428 setString(&ti->identifier, identifier);
4429 setString(&ti->name, name);
4430 setString(&ti->name_sorting, name);
4431 setString(&ti->infotext, "Sound Volume");
4433 pushTreeInfo(&volumes_simple, ti);
4436 /* sort volume values to start with lowest volume value */
4437 sortTreeInfo(&volumes_simple);
4439 /* set current volume value to configured volume value */
4440 volume_simple_current =
4441 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4443 /* if that fails, set current volume to reliable default value */
4444 if (volume_simple_current == NULL)
4445 volume_simple_current =
4446 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4448 /* if that also fails, set current volume to first available value */
4449 if (volume_simple_current == NULL)
4450 volume_simple_current = volumes_simple;
4453 if (volumes_loops == NULL)
4455 boolean current_volume_loops_found = FALSE;
4458 for (i = 0; volumes_list[i].value != -1; i++)
4460 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4461 char identifier[32], name[32];
4462 int value = volumes_list[i].value;
4463 char *text = volumes_list[i].text;
4465 ti->node_top = &volumes_loops;
4466 ti->sort_priority = value;
4468 sprintf(identifier, "%d", value);
4469 sprintf(name, "%s", text);
4471 setString(&ti->identifier, identifier);
4472 setString(&ti->name, name);
4473 setString(&ti->name_sorting, name);
4474 setString(&ti->infotext, "Loops Volume");
4476 pushTreeInfo(&volumes_loops, ti);
4478 if (value == setup.volume_loops)
4479 current_volume_loops_found = TRUE;
4482 if (!current_volume_loops_found)
4484 // add entry for non-preset volume value
4486 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4487 char identifier[32], name[32];
4488 int value = setup.volume_loops;
4490 ti->node_top = &volumes_loops;
4491 ti->sort_priority = value;
4493 sprintf(identifier, "%d", value);
4494 sprintf(name, "%d %% (Current)", value);
4496 setString(&ti->identifier, identifier);
4497 setString(&ti->name, name);
4498 setString(&ti->name_sorting, name);
4499 setString(&ti->infotext, "Loops Volume");
4501 pushTreeInfo(&volumes_loops, ti);
4504 /* sort volume values to start with lowest volume value */
4505 sortTreeInfo(&volumes_loops);
4507 /* set current volume value to configured volume value */
4508 volume_loops_current =
4509 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4511 /* if that fails, set current volume to reliable default value */
4512 if (volume_loops_current == NULL)
4513 volume_loops_current =
4514 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4516 /* if that also fails, set current volume to first available value */
4517 if (volume_loops_current == NULL)
4518 volume_loops_current = volumes_loops;
4521 if (volumes_music == NULL)
4523 boolean current_volume_music_found = FALSE;
4526 for (i = 0; volumes_list[i].value != -1; i++)
4528 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4529 char identifier[32], name[32];
4530 int value = volumes_list[i].value;
4531 char *text = volumes_list[i].text;
4533 ti->node_top = &volumes_music;
4534 ti->sort_priority = value;
4536 sprintf(identifier, "%d", value);
4537 sprintf(name, "%s", text);
4539 setString(&ti->identifier, identifier);
4540 setString(&ti->name, name);
4541 setString(&ti->name_sorting, name);
4542 setString(&ti->infotext, "Music Volume");
4544 pushTreeInfo(&volumes_music, ti);
4546 if (value == setup.volume_music)
4547 current_volume_music_found = TRUE;
4550 if (!current_volume_music_found)
4552 // add entry for non-preset volume value
4554 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4555 char identifier[32], name[32];
4556 int value = setup.volume_music;
4558 ti->node_top = &volumes_music;
4559 ti->sort_priority = value;
4561 sprintf(identifier, "%d", value);
4562 sprintf(name, "%d %% (Current)", value);
4564 setString(&ti->identifier, identifier);
4565 setString(&ti->name, name);
4566 setString(&ti->name_sorting, name);
4567 setString(&ti->infotext, "Music Volume");
4569 pushTreeInfo(&volumes_music, ti);
4572 /* sort volume values to start with lowest volume value */
4573 sortTreeInfo(&volumes_music);
4575 /* set current volume value to configured volume value */
4576 volume_music_current =
4577 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4579 /* if that fails, set current volume to reliable default value */
4580 if (volume_music_current == NULL)
4581 volume_music_current =
4582 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4584 /* if that also fails, set current volume to first available value */
4585 if (volume_music_current == NULL)
4586 volume_music_current = volumes_music;
4589 setup.volume_simple = atoi(volume_simple_current->identifier);
4590 setup.volume_loops = atoi(volume_loops_current->identifier);
4591 setup.volume_music = atoi(volume_music_current->identifier);
4593 /* needed for displaying volume text instead of identifier */
4594 volume_simple_text = volume_simple_current->name;
4595 volume_loops_text = volume_loops_current->name;
4596 volume_music_text = volume_music_current->name;
4598 setup_mode = SETUP_MODE_SOUND;
4603 static void execSetupChooseTouchControls()
4605 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4610 static void execSetupChooseMoveDistance()
4612 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4617 static void execSetupChooseDropDistance()
4619 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4624 static void execSetupTouch()
4626 if (touch_controls == NULL)
4630 for (i = 0; touch_controls_list[i].value != NULL; i++)
4632 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4633 char identifier[32], name[32];
4634 char *value = touch_controls_list[i].value;
4635 char *text = touch_controls_list[i].text;
4637 ti->node_top = &touch_controls;
4638 ti->sort_priority = i;
4640 sprintf(identifier, "%s", value);
4641 sprintf(name, "%s", text);
4643 setString(&ti->identifier, identifier);
4644 setString(&ti->name, name);
4645 setString(&ti->name_sorting, name);
4646 setString(&ti->infotext, "Control Type");
4648 pushTreeInfo(&touch_controls, ti);
4651 /* sort touch control values to start with lowest touch control value */
4652 sortTreeInfo(&touch_controls);
4654 /* set current touch control value to configured touch control value */
4655 touch_control_current =
4656 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4658 /* if that fails, set current touch control to reliable default value */
4659 if (touch_control_current == NULL)
4660 touch_control_current =
4661 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4663 /* if that also fails, set current touch control to first available value */
4664 if (touch_control_current == NULL)
4665 touch_control_current = touch_controls;
4668 if (move_distances == NULL)
4672 for (i = 0; distances_list[i].value != -1; i++)
4674 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4675 char identifier[32], name[32];
4676 int value = distances_list[i].value;
4677 char *text = distances_list[i].text;
4679 ti->node_top = &move_distances;
4680 ti->sort_priority = value;
4682 sprintf(identifier, "%d", value);
4683 sprintf(name, "%s", text);
4685 setString(&ti->identifier, identifier);
4686 setString(&ti->name, name);
4687 setString(&ti->name_sorting, name);
4688 setString(&ti->infotext, "Move Distance");
4690 pushTreeInfo(&move_distances, ti);
4693 /* sort distance values to start with lowest distance value */
4694 sortTreeInfo(&move_distances);
4696 /* set current distance value to configured distance value */
4697 move_distance_current =
4698 getTreeInfoFromIdentifier(move_distances,
4699 i_to_a(setup.touch.move_distance));
4701 /* if that fails, set current distance to reliable default value */
4702 if (move_distance_current == NULL)
4703 move_distance_current =
4704 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4706 /* if that also fails, set current distance to first available value */
4707 if (move_distance_current == NULL)
4708 move_distance_current = move_distances;
4711 if (drop_distances == NULL)
4715 for (i = 0; distances_list[i].value != -1; i++)
4717 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4718 char identifier[32], name[32];
4719 int value = distances_list[i].value;
4720 char *text = distances_list[i].text;
4722 ti->node_top = &drop_distances;
4723 ti->sort_priority = value;
4725 sprintf(identifier, "%d", value);
4726 sprintf(name, "%s", text);
4728 setString(&ti->identifier, identifier);
4729 setString(&ti->name, name);
4730 setString(&ti->name_sorting, name);
4731 setString(&ti->infotext, "Drop Distance");
4733 pushTreeInfo(&drop_distances, ti);
4736 /* sort distance values to start with lowest distance value */
4737 sortTreeInfo(&drop_distances);
4739 /* set current distance value to configured distance value */
4740 drop_distance_current =
4741 getTreeInfoFromIdentifier(drop_distances,
4742 i_to_a(setup.touch.drop_distance));
4744 /* if that fails, set current distance to reliable default value */
4745 if (drop_distance_current == NULL)
4746 drop_distance_current =
4747 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
4749 /* if that also fails, set current distance to first available value */
4750 if (drop_distance_current == NULL)
4751 drop_distance_current = drop_distances;
4754 setup.touch.control_type = touch_control_current->identifier;
4755 setup.touch.move_distance = atoi(move_distance_current->identifier);
4756 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
4758 /* needed for displaying volume text instead of identifier */
4759 touch_controls_text = touch_control_current->name;
4760 move_distance_text = move_distance_current->name;
4761 drop_distance_text = drop_distance_current->name;
4763 setup_mode = SETUP_MODE_TOUCH;
4768 static void execSetupArtwork()
4771 printf("::: '%s', '%s', '%s'\n",
4772 artwork.gfx_current->subdir,
4773 artwork.gfx_current->fullpath,
4774 artwork.gfx_current->basepath);
4777 setup.graphics_set = artwork.gfx_current->identifier;
4778 setup.sounds_set = artwork.snd_current->identifier;
4779 setup.music_set = artwork.mus_current->identifier;
4781 /* needed if last screen (setup choice) changed graphics, sounds or music */
4782 ReloadCustomArtwork(0);
4784 /* needed for displaying artwork name instead of artwork identifier */
4785 graphics_set_name = artwork.gfx_current->name;
4786 sounds_set_name = artwork.snd_current->name;
4787 music_set_name = artwork.mus_current->name;
4789 setup_mode = SETUP_MODE_ARTWORK;
4794 static void execSetupChooseGraphics()
4796 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4801 static void execSetupChooseSounds()
4803 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4808 static void execSetupChooseMusic()
4810 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4815 #if !defined(PLATFORM_ANDROID)
4816 static void execSetupInput()
4818 setup_mode = SETUP_MODE_INPUT;
4824 static void execSetupShortcuts()
4826 setup_mode = SETUP_MODE_SHORTCUTS;
4831 static void execSetupShortcuts1()
4833 setup_mode = SETUP_MODE_SHORTCUTS_1;
4838 static void execSetupShortcuts2()
4840 setup_mode = SETUP_MODE_SHORTCUTS_2;
4845 static void execSetupShortcuts3()
4847 setup_mode = SETUP_MODE_SHORTCUTS_3;
4852 static void execSetupShortcuts4()
4854 setup_mode = SETUP_MODE_SHORTCUTS_4;
4859 static void execSetupShortcuts5()
4861 setup_mode = SETUP_MODE_SHORTCUTS_5;
4866 static void execExitSetup()
4868 game_status = GAME_MODE_MAIN;
4870 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4873 static void execSaveAndExitSetup()
4879 static struct TokenInfo setup_info_main[] =
4881 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4882 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4883 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4884 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4885 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4886 #if !defined(PLATFORM_ANDROID)
4887 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4888 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4890 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4892 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4893 { TYPE_EMPTY, NULL, "" },
4894 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4895 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4900 static struct TokenInfo setup_info_game[] =
4902 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4903 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4904 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4905 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4906 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4907 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4908 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4909 { TYPE_STRING, &game_speed_text, "" },
4911 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4912 { TYPE_STRING, &scroll_delay_text, "" },
4914 { TYPE_EMPTY, NULL, "" },
4915 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4920 static struct TokenInfo setup_info_editor[] =
4923 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4924 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4925 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4926 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4927 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4928 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4929 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4930 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4932 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4933 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4934 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4936 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4938 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4939 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4940 { TYPE_EMPTY, NULL, "" },
4942 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4943 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4944 { TYPE_EMPTY, NULL, "" },
4946 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4947 { TYPE_EMPTY, NULL, "" },
4948 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4953 static struct TokenInfo setup_info_graphics[] =
4955 #if !defined(PLATFORM_ANDROID)
4956 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4957 #if defined(TARGET_SDL2)
4958 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4959 { TYPE_STRING, &window_size_text, "" },
4960 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4961 { TYPE_STRING, &scaling_type_text, "" },
4963 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4964 { TYPE_STRING, &screen_mode_text, "" },
4968 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4969 { TYPE_STRING, &scroll_delay_text, "" },
4971 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4972 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4973 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4974 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4975 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4976 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4977 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4978 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4979 { TYPE_EMPTY, NULL, "" },
4980 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4985 static struct TokenInfo setup_info_sound[] =
4987 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4988 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4989 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4990 { TYPE_EMPTY, NULL, "" },
4991 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4992 { TYPE_STRING, &volume_simple_text, "" },
4993 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4994 { TYPE_STRING, &volume_loops_text, "" },
4995 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4996 { TYPE_STRING, &volume_music_text, "" },
4997 { TYPE_EMPTY, NULL, "" },
4998 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5003 static struct TokenInfo setup_info_artwork[] =
5005 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5006 { TYPE_STRING, &graphics_set_name, "" },
5007 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5008 { TYPE_STRING, &sounds_set_name, "" },
5009 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5010 { TYPE_STRING, &music_set_name, "" },
5011 { TYPE_EMPTY, NULL, "" },
5012 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5013 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5014 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5015 { TYPE_EMPTY, NULL, "" },
5016 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5021 static struct TokenInfo setup_info_input[] =
5023 { TYPE_SWITCH, NULL, "Player:" },
5024 { TYPE_SWITCH, NULL, "Device:" },
5025 { TYPE_ENTER_MENU, NULL, "" },
5026 { TYPE_EMPTY, NULL, "" },
5027 { TYPE_EMPTY, NULL, "" },
5028 { TYPE_EMPTY, NULL, "" },
5029 { TYPE_EMPTY, NULL, "" },
5030 { TYPE_EMPTY, NULL, "" },
5031 { TYPE_EMPTY, NULL, "" },
5032 { TYPE_EMPTY, NULL, "" },
5033 { TYPE_EMPTY, NULL, "" },
5034 { TYPE_EMPTY, NULL, "" },
5035 { TYPE_EMPTY, NULL, "" },
5036 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5041 static struct TokenInfo setup_info_touch[] =
5043 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5044 { TYPE_STRING, &touch_controls_text, "" },
5045 { TYPE_EMPTY, NULL, "" },
5046 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5047 { TYPE_STRING, &move_distance_text, "" },
5048 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5049 { TYPE_STRING, &drop_distance_text, "" },
5050 { TYPE_EMPTY, NULL, "" },
5051 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5056 static struct TokenInfo setup_info_shortcuts[] =
5058 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5059 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5060 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5061 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5062 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5063 { TYPE_EMPTY, NULL, "" },
5064 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5069 static struct TokenInfo setup_info_shortcuts_1[] =
5071 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5072 { TYPE_KEY, &setup.shortcut.save_game, "" },
5073 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5074 { TYPE_KEY, &setup.shortcut.load_game, "" },
5075 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5076 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5077 { TYPE_EMPTY, NULL, "" },
5078 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5079 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5080 { TYPE_EMPTY, NULL, "" },
5081 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5086 static struct TokenInfo setup_info_shortcuts_2[] =
5088 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5089 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5090 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5091 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5092 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5093 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5094 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5095 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5096 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5097 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5098 { TYPE_EMPTY, NULL, "" },
5099 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5104 static struct TokenInfo setup_info_shortcuts_3[] =
5106 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5107 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5108 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5109 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5110 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5111 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5112 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5113 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5114 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5115 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5116 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5117 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5118 { TYPE_EMPTY, NULL, "" },
5119 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5124 static struct TokenInfo setup_info_shortcuts_4[] =
5126 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5127 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5128 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5129 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5130 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5131 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5132 { TYPE_EMPTY, NULL, "" },
5133 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5138 static struct TokenInfo setup_info_shortcuts_5[] =
5140 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5141 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5142 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5143 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5144 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5145 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5146 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5147 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5148 { TYPE_EMPTY, NULL, "" },
5149 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5154 static Key getSetupKey()
5156 Key key = KSYM_UNDEFINED;
5157 boolean got_key_event = FALSE;
5159 while (!got_key_event)
5161 if (PendingEvent()) /* got event */
5169 case EVENT_KEYPRESS:
5171 key = GetEventKey((KeyEvent *)&event, TRUE);
5173 /* press 'Escape' or 'Enter' to keep the existing key binding */
5174 if (key == KSYM_Escape || key == KSYM_Return)
5175 key = KSYM_UNDEFINED; /* keep old value */
5177 got_key_event = TRUE;
5181 case EVENT_KEYRELEASE:
5182 key_joystick_mapping = 0;
5186 HandleOtherEvents(&event);
5194 /* don't eat all CPU time */
5201 static int getSetupTextFont(int type)
5203 if (type & (TYPE_SWITCH |
5215 static int getSetupValueFont(int type, void *value)
5217 if (type & TYPE_KEY)
5218 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5219 else if (type & TYPE_STRING)
5220 return FONT_VALUE_2;
5221 else if (type & TYPE_ECS_AGA)
5222 return FONT_VALUE_1;
5223 else if (type & TYPE_BOOLEAN_STYLE)
5224 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5225 else if (type & TYPE_YES_NO_AUTO)
5226 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5227 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5229 return FONT_VALUE_1;
5232 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5234 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5235 struct TokenInfo *si = &setup_info[si_pos];
5236 boolean font_draw_xoffset_modified = FALSE;
5237 int font_draw_xoffset_old = -1;
5238 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5239 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5240 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5241 int xpos = menu_screen_value_xpos;
5242 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5243 int startx = mSX + xpos * 32;
5244 int starty = mSY + ypos * 32;
5245 int font_nr, font_width;
5246 int type = si->type;
5247 void *value = si->value;
5248 char *value_string = getSetupValue(type, value);
5251 if (value_string == NULL)
5254 if (type & TYPE_KEY)
5256 xpos = MENU_SCREEN_START_XPOS;
5258 if (type & TYPE_QUERY)
5259 value_string = "<press key>";
5261 else if (type & TYPE_STRING)
5263 int max_value_len = (SCR_FIELDX - 2) * 2;
5265 xpos = MENU_SCREEN_START_XPOS;
5267 if (strlen(value_string) > max_value_len)
5268 value_string[max_value_len] = '\0';
5270 else if (type & TYPE_YES_NO_AUTO)
5272 xpos = menu_screen_value_xpos - 1;
5275 startx = mSX + xpos * 32;
5276 starty = mSY + ypos * 32;
5277 font_nr = getSetupValueFont(type, value);
5278 font_width = getFontWidth(font_nr);
5280 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5281 if (setup_mode != SETUP_MODE_INPUT)
5283 int max_menu_text_length_big = (menu_screen_value_xpos -
5284 MENU_SCREEN_START_XPOS);
5285 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5286 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5287 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5288 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5289 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5290 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5291 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5292 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5293 boolean correct_font_draw_xoffset = FALSE;
5295 if (xpos == MENU_SCREEN_START_XPOS &&
5296 startx + font1_xoffset < text_startx + text_font_xoffset)
5297 correct_font_draw_xoffset = TRUE;
5299 if (xpos == menu_screen_value_xpos &&
5300 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5301 correct_font_draw_xoffset = TRUE;
5303 /* check if setup value would overlap with setup text when printed */
5304 /* (this can happen for extreme/wrong values for font draw offset) */
5305 if (correct_font_draw_xoffset)
5307 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5308 font_draw_xoffset_modified = TRUE;
5310 if (type & TYPE_KEY)
5311 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5312 else if (!(type & TYPE_STRING))
5313 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5314 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5318 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5319 DrawText(startx + i * font_width, starty, " ", font_nr);
5321 DrawText(startx, starty, value_string, font_nr);
5323 if (font_draw_xoffset_modified)
5324 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5327 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5329 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5330 struct TokenInfo *si = &setup_info[si_pos];
5332 if (si->type & TYPE_BOOLEAN_STYLE)
5334 *(boolean *)si->value ^= TRUE;
5336 else if (si->type & TYPE_YES_NO_AUTO)
5340 (*(int *)si->value == AUTO ? TRUE :
5341 *(int *)si->value == TRUE ? FALSE : AUTO) :
5342 (*(int *)si->value == TRUE ? AUTO :
5343 *(int *)si->value == AUTO ? FALSE : TRUE));
5345 else if (si->type & TYPE_KEY)
5349 si->type |= TYPE_QUERY;
5350 drawSetupValue(screen_pos, setup_info_pos_raw);
5351 si->type &= ~TYPE_QUERY;
5353 key = getSetupKey();
5354 if (key != KSYM_UNDEFINED)
5355 *(Key *)si->value = key;
5358 drawSetupValue(screen_pos, setup_info_pos_raw);
5360 // fullscreen state may have changed at this point
5361 if (si->value == &setup.fullscreen)
5362 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5365 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5368 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5369 struct TokenInfo *si = &setup_info[si_pos];
5370 int xpos = MENU_SCREEN_START_XPOS;
5371 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5372 int font_nr = getSetupTextFont(si->type);
5374 if (setup_info == setup_info_input)
5375 font_nr = FONT_MENU_1;
5378 font_nr = FONT_ACTIVE(font_nr);
5380 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5382 if (si->type & ~TYPE_SKIP_ENTRY)
5383 drawCursor(screen_pos, active);
5386 static void drawSetupInfoList(struct TokenInfo *setup_info,
5387 int first_entry, int num_page_entries)
5391 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5392 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5394 if (num_page_entries > max_setup_info)
5395 num_page_entries = max_setup_info;
5397 if (first_entry + num_page_entries > max_setup_info)
5400 clearMenuListArea();
5402 for (i = 0; i < num_page_entries; i++)
5404 int setup_info_pos = first_entry + i;
5405 struct TokenInfo *si = &setup_info[setup_info_pos];
5406 void *value_ptr = si->value;
5408 /* set some entries to "unchangeable" according to other variables */
5409 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5410 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5411 (value_ptr == &setup.sound_music && !audio.music_available) ||
5412 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5413 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5414 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5415 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5416 si->type |= TYPE_GHOSTED;
5418 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5419 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5420 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5421 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5422 else if (si->type & ~TYPE_SKIP_ENTRY)
5423 initCursor(i, IMG_MENU_BUTTON);
5425 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5427 if (si->type & TYPE_VALUE)
5428 drawSetupValue(i, setup_info_pos);
5432 static void DrawSetupScreen_Generic()
5434 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5435 boolean redraw_all = FALSE;
5436 char *title_string = NULL;
5441 FreeScreenGadgets();
5442 CreateScreenGadgets();
5444 CloseDoor(DOOR_CLOSE_2);
5446 if (redraw_mask & REDRAW_ALL)
5453 if (setup_mode == SETUP_MODE_MAIN)
5455 setup_info = setup_info_main;
5456 title_string = "Setup";
5458 else if (setup_mode == SETUP_MODE_GAME)
5460 setup_info = setup_info_game;
5461 title_string = "Setup Game";
5463 else if (setup_mode == SETUP_MODE_EDITOR)
5465 setup_info = setup_info_editor;
5466 title_string = "Setup Editor";
5468 else if (setup_mode == SETUP_MODE_GRAPHICS)
5470 setup_info = setup_info_graphics;
5471 title_string = "Setup Graphics";
5473 else if (setup_mode == SETUP_MODE_SOUND)
5475 setup_info = setup_info_sound;
5476 title_string = "Setup Sound";
5478 else if (setup_mode == SETUP_MODE_ARTWORK)
5480 setup_info = setup_info_artwork;
5481 title_string = "Custom Artwork";
5483 else if (setup_mode == SETUP_MODE_TOUCH)
5485 setup_info = setup_info_touch;
5486 title_string = "Setup Touch Ctrls";
5488 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5490 setup_info = setup_info_shortcuts;
5491 title_string = "Setup Shortcuts";
5493 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5495 setup_info = setup_info_shortcuts_1;
5496 title_string = "Setup Shortcuts";
5498 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5500 setup_info = setup_info_shortcuts_2;
5501 title_string = "Setup Shortcuts";
5503 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5505 setup_info = setup_info_shortcuts_3;
5506 title_string = "Setup Shortcuts";
5508 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5510 setup_info = setup_info_shortcuts_4;
5511 title_string = "Setup Shortcuts";
5513 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5515 setup_info = setup_info_shortcuts_5;
5516 title_string = "Setup Shortcuts";
5519 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5521 // determine maximal number of setup entries that can be displayed on screen
5523 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5526 // determine maximal number of setup entries available for this setup screen
5528 for (i = 0; setup_info[i].type != 0; i++)
5531 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5533 MapScreenGadgets(max_setup_info);
5536 redraw_mask = fade_mask = REDRAW_ALL;
5543 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5545 static int choice_store[MAX_SETUP_MODES];
5546 static int first_entry_store[MAX_SETUP_MODES];
5547 int choice = choice_store[setup_mode]; /* starts with 0 */
5548 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5550 int y = choice - first_entry;
5552 boolean position_set_by_scrollbar = (dx == 999);
5553 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5554 int num_page_entries;
5556 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5558 if (button == MB_MENU_INITIALIZE)
5560 /* advance to first valid menu entry */
5561 while (choice < num_setup_info &&
5562 setup_info[choice].type & TYPE_SKIP_ENTRY)
5565 if (position_set_by_scrollbar)
5566 first_entry = first_entry_store[setup_mode] = dy;
5568 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5569 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5571 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5573 if (choice < first_entry)
5575 choice = first_entry;
5577 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5580 else if (choice > first_entry + num_page_entries - 1)
5582 choice = first_entry + num_page_entries - 1;
5584 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5588 choice_store[setup_mode] = choice;
5590 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5594 else if (button == MB_MENU_LEAVE)
5598 PlaySound(SND_MENU_ITEM_SELECTING);
5600 for (i = 0; setup_info[i].type != 0; i++)
5602 if (setup_info[i].type & TYPE_LEAVE_MENU)
5604 void (*menu_callback_function)(void) = setup_info[i].value;
5608 menu_callback_function();
5610 break; /* absolutely needed because function changes 'setup_info'! */
5617 if (mx || my) /* mouse input */
5619 x = (mx - mSX) / 32;
5620 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5622 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5624 /* move cursor instead of scrolling when already at start/end of list */
5625 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5627 else if (dy == +1 * SCROLL_LINE &&
5628 first_entry + num_page_entries == max_setup_info)
5631 /* handle scrolling screen one line or page */
5633 y + dy > num_page_entries - 1)
5635 boolean redraw = FALSE;
5637 if (ABS(dy) == SCROLL_PAGE)
5638 step = num_page_entries - 1;
5640 if (dy < 0 && first_entry > 0)
5642 /* scroll page/line up */
5644 first_entry -= step;
5645 if (first_entry < 0)
5650 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5652 /* scroll page/line down */
5654 first_entry += step;
5655 if (first_entry + num_page_entries > max_setup_info)
5656 first_entry = MAX(0, max_setup_info - num_page_entries);
5663 choice += first_entry - first_entry_store[setup_mode];
5665 if (choice < first_entry)
5667 choice = first_entry;
5669 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5672 else if (choice > first_entry + num_page_entries - 1)
5674 choice = first_entry + num_page_entries - 1;
5676 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5679 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5683 if (choice < first_entry ||
5684 choice > first_entry + num_page_entries - 1)
5685 first_entry += SIGN(dy);
5688 first_entry_store[setup_mode] = first_entry;
5689 choice_store[setup_mode] = choice;
5691 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5693 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5695 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5696 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5704 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5706 if (setup_info[choice].type & menu_navigation_type ||
5707 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5708 setup_info[choice].type & TYPE_YES_NO_AUTO)
5709 button = MB_MENU_CHOICE;
5714 /* jump to next non-empty menu entry (up or down) */
5715 while (first_entry + y > 0 &&
5716 first_entry + y < max_setup_info - 1 &&
5717 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
5720 if (!IN_VIS_MENU(x, y))
5722 choice += y - y_old;
5724 if (choice < first_entry)
5725 first_entry = choice;
5726 else if (choice > first_entry + num_page_entries - 1)
5727 first_entry = choice - num_page_entries + 1;
5729 if (first_entry >= 0 &&
5730 first_entry + num_page_entries <= max_setup_info)
5732 first_entry_store[setup_mode] = first_entry;
5734 if (choice < first_entry)
5735 choice = first_entry;
5736 else if (choice > first_entry + num_page_entries - 1)
5737 choice = first_entry + num_page_entries - 1;
5739 choice_store[setup_mode] = choice;
5741 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5743 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5745 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5746 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5753 if (!anyScrollbarGadgetActive() &&
5754 IN_VIS_MENU(x, y) &&
5755 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
5756 y >= 0 && y < num_page_entries)
5760 if (first_entry + y != choice &&
5761 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
5763 PlaySound(SND_MENU_ITEM_ACTIVATING);
5765 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
5766 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
5768 choice = choice_store[setup_mode] = first_entry + y;
5771 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
5773 PlaySound(SND_MENU_ITEM_SELECTING);
5775 /* when selecting key headline, execute function for key value change */
5776 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
5777 setup_info[first_entry + y + 1].type & TYPE_KEY)
5780 /* when selecting string value, execute function for list selection */
5781 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
5782 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
5785 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
5787 void (*menu_callback_function)(void) =
5788 setup_info[first_entry + y].value;
5790 FadeSetFromType(setup_info[first_entry + y].type);
5792 menu_callback_function();
5796 if (setup_info[first_entry + y].type & TYPE_VALUE)
5797 changeSetupValue(y, first_entry + y, dx);
5803 void DrawSetupScreen_Input()
5807 FadeOut(REDRAW_FIELD);
5811 setup_info = setup_info_input;
5813 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5815 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5816 "Joysticks deactivated on this screen");
5818 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5820 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5821 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5822 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5823 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5824 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5825 initCursor(i, IMG_MENU_BUTTON);
5827 DrawCursorAndText_Setup(i, -1, FALSE);
5830 /* create gadgets for setup input menu screen */
5831 FreeScreenGadgets();
5832 CreateScreenGadgets();
5834 /* map gadgets for setup input menu screen */
5835 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5837 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5839 FadeIn(REDRAW_FIELD);
5844 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5846 if (device_name == NULL)
5849 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5852 if (strlen(device_name) > 1)
5854 char c1 = device_name[strlen(device_name) - 1];
5855 char c2 = device_name[strlen(device_name) - 2];
5857 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5858 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5861 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5862 strlen(device_name));
5865 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5868 static struct SetupKeyboardInfo custom_key;
5875 { &custom_key.left, "Joystick Left" },
5876 { &custom_key.right, "Joystick Right" },
5877 { &custom_key.up, "Joystick Up" },
5878 { &custom_key.down, "Joystick Down" },
5879 { &custom_key.snap, "Button 1" },
5880 { &custom_key.drop, "Button 2" }
5882 static char *joystick_name[MAX_PLAYERS] =
5889 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5893 custom_key = setup.input[player_nr].key;
5895 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5896 FONT_INPUT_1_ACTIVE);
5898 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5900 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5901 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5903 if (setup.input[player_nr].use_joystick)
5905 char *device_name = setup.input[player_nr].joy.device_name;
5906 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5907 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5909 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5910 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5914 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5915 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5918 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5920 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5921 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5922 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5923 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5925 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5926 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5927 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5928 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5929 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5930 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5932 for (i = 0; i < 6; i++)
5934 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5936 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5938 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5939 (setup.input[player_nr].use_joystick ?
5941 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5945 static int input_player_nr = 0;
5947 void HandleSetupScreen_Input_Player(int step, int direction)
5949 int old_player_nr = input_player_nr;
5952 new_player_nr = old_player_nr + step * direction;
5953 if (new_player_nr < 0)
5955 if (new_player_nr > MAX_PLAYERS - 1)
5956 new_player_nr = MAX_PLAYERS - 1;
5958 if (new_player_nr != old_player_nr)
5960 input_player_nr = new_player_nr;
5962 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5966 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5968 static int choice = 0;
5971 int pos_start = SETUPINPUT_SCREEN_POS_START;
5972 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5973 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5974 int pos_end = SETUPINPUT_SCREEN_POS_END;
5976 if (button == MB_MENU_INITIALIZE)
5978 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5980 DrawCursorAndText_Setup(choice, -1, TRUE);
5984 else if (button == MB_MENU_LEAVE)
5986 setup_mode = SETUP_MODE_MAIN;
5993 if (mx || my) /* mouse input */
5995 x = (mx - mSX) / 32;
5996 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5998 else if (dx || dy) /* keyboard input */
6000 if (dx && choice == 0)
6001 x = (dx < 0 ? 10 : 12);
6002 else if ((dx && choice == 1) ||
6003 (dx == +1 && choice == 2) ||
6004 (dx == -1 && choice == pos_end))
6005 button = MB_MENU_CHOICE;
6009 if (y >= pos_empty1 && y <= pos_empty2)
6010 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6013 if (y == 0 && dx != 0 && button)
6015 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6017 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6018 y >= pos_start && y <= pos_end &&
6019 !(y >= pos_empty1 && y <= pos_empty2))
6025 DrawCursorAndText_Setup(choice, -1, FALSE);
6026 DrawCursorAndText_Setup(y, -1, TRUE);
6028 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6037 char *device_name = setup.input[input_player_nr].joy.device_name;
6039 if (!setup.input[input_player_nr].use_joystick)
6041 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6043 setJoystickDeviceToNr(device_name, new_device_nr);
6044 setup.input[input_player_nr].use_joystick = TRUE;
6048 int device_nr = getJoystickNrFromDeviceName(device_name);
6049 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6051 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6052 setup.input[input_player_nr].use_joystick = FALSE;
6054 setJoystickDeviceToNr(device_name, new_device_nr);
6057 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6061 if (setup.input[input_player_nr].use_joystick)
6064 CalibrateJoystick(input_player_nr);
6067 CustomizeKeyboard(input_player_nr);
6069 else if (y == pos_end)
6075 setup_mode = SETUP_MODE_MAIN;
6082 void CustomizeKeyboard(int player_nr)
6086 boolean finished = FALSE;
6087 static struct SetupKeyboardInfo custom_key;
6092 } customize_step[] =
6094 { &custom_key.left, "Move Left" },
6095 { &custom_key.right, "Move Right" },
6096 { &custom_key.up, "Move Up" },
6097 { &custom_key.down, "Move Down" },
6098 { &custom_key.snap, "Snap Field" },
6099 { &custom_key.drop, "Drop Element" }
6102 /* read existing key bindings from player setup */
6103 custom_key = setup.input[player_nr].key;
6106 FadeOut(REDRAW_FIELD);
6110 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6113 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6114 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6115 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6116 "Key:", FONT_INPUT_1_ACTIVE);
6117 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6118 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6120 FadeIn(REDRAW_FIELD);
6126 if (PendingEvent()) /* got event */
6134 case EVENT_KEYPRESS:
6136 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6138 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6140 if (key == KSYM_Escape)
6141 FadeSkipNextFadeIn();
6147 /* all keys configured -- wait for "Escape" or "Return" key */
6151 /* press 'Enter' to keep the existing key binding */
6152 if (key == KSYM_Return)
6153 key = *customize_step[step_nr].key;
6155 /* check if key already used */
6156 for (i = 0; i < step_nr; i++)
6157 if (*customize_step[i].key == key)
6162 /* got new key binding */
6163 *customize_step[step_nr].key = key;
6164 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6166 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6167 getKeyNameFromKey(key), FONT_VALUE_1);
6170 /* un-highlight last query */
6171 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6172 customize_step[step_nr - 1].text, FONT_MENU_1);
6173 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6174 "Key:", FONT_MENU_1);
6176 /* press 'Enter' to leave */
6179 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6180 "Press Enter", FONT_TITLE_1);
6184 /* query next key binding */
6185 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6186 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6187 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6188 "Key:", FONT_INPUT_1_ACTIVE);
6189 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6190 getKeyNameFromKey(*customize_step[step_nr].key),
6195 case EVENT_KEYRELEASE:
6196 key_joystick_mapping = 0;
6200 HandleOtherEvents(&event);
6208 /* don't eat all CPU time */
6212 /* write new key bindings back to player setup */
6213 setup.input[player_nr].key = custom_key;
6216 DrawSetupScreen_Input();
6219 static boolean CalibrateJoystickMain(int player_nr)
6221 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6222 int new_joystick_xright = JOYSTICK_XMIDDLE;
6223 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6224 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6225 int new_joystick_xmiddle, new_joystick_ymiddle;
6227 int joystick_fd = joystick.fd[player_nr];
6228 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6229 boolean check[3][3];
6230 int check_remaining = 3 * 3;
6235 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6238 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6242 FadeOut(REDRAW_FIELD);
6246 for (y = 0; y < 3; y++)
6248 for (x = 0; x < 3; x++)
6250 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6251 check[x][y] = FALSE;
6255 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6256 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6257 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6258 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6259 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6260 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6261 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6263 joy_value = Joystick(player_nr);
6264 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6265 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6267 /* eventually uncalibrated center position (joystick could be uncentered) */
6268 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6271 new_joystick_xmiddle = joy_x;
6272 new_joystick_ymiddle = joy_y;
6274 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6276 FadeIn(REDRAW_FIELD);
6278 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6283 if (PendingEvent()) /* got event */
6291 case EVENT_KEYPRESS:
6292 switch (GetEventKey((KeyEvent *)&event, TRUE))
6295 if (check_remaining == 0)
6300 FadeSkipNextFadeIn();
6309 case EVENT_KEYRELEASE:
6310 key_joystick_mapping = 0;
6314 HandleOtherEvents(&event);
6319 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6322 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6323 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6324 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6325 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6327 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6328 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6329 setup.input[player_nr].joy.xright = new_joystick_xright;
6330 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6331 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6332 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6334 CheckJoystickData();
6336 joy_value = Joystick(player_nr);
6338 if (joy_value & JOY_BUTTON && check_remaining == 0)
6341 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6342 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6344 if (x != last_x || y != last_y)
6346 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6347 IMG_MENU_CALIBRATE_YELLOW, 0);
6348 DrawFixedGraphic(xpos + x, ypos + y,
6349 IMG_MENU_CALIBRATE_RED, 0);
6354 if (check_remaining > 0 && !check[x+1][y+1])
6356 check[x+1][y+1] = TRUE;
6364 /* don't eat all CPU time */
6368 /* calibrated center position (joystick should now be centered) */
6369 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6372 new_joystick_xmiddle = joy_x;
6373 new_joystick_ymiddle = joy_y;
6377 /* wait until the last pressed button was released */
6378 while (Joystick(player_nr) & JOY_BUTTON)
6380 if (PendingEvent()) /* got event */
6385 HandleOtherEvents(&event);
6394 void CalibrateJoystick(int player_nr)
6396 if (!CalibrateJoystickMain(player_nr))
6398 char *device_name = setup.input[player_nr].joy.device_name;
6399 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6400 int xpos = mSX - SX;
6401 int ypos = mSY - SY;
6405 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6406 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6409 Delay(2000); /* show error message for a short time */
6414 DrawSetupScreen_Input();
6417 void DrawSetupScreen()
6419 DeactivateJoystick();
6421 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6423 if (setup_mode == SETUP_MODE_INPUT)
6424 DrawSetupScreen_Input();
6425 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6426 DrawChooseTree(&game_speed_current);
6427 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6428 DrawChooseTree(&scroll_delay_current);
6429 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6430 DrawChooseTree(&screen_mode_current);
6431 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6432 DrawChooseTree(&window_size_current);
6433 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6434 DrawChooseTree(&scaling_type_current);
6435 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6436 DrawChooseTree(&artwork.gfx_current);
6437 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6438 DrawChooseTree(&artwork.snd_current);
6439 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6440 DrawChooseTree(&artwork.mus_current);
6441 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6442 DrawChooseTree(&volume_simple_current);
6443 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6444 DrawChooseTree(&volume_loops_current);
6445 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6446 DrawChooseTree(&volume_music_current);
6447 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6448 DrawChooseTree(&touch_control_current);
6449 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6450 DrawChooseTree(&move_distance_current);
6451 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6452 DrawChooseTree(&drop_distance_current);
6454 DrawSetupScreen_Generic();
6460 void RedrawSetupScreenAfterFullscreenToggle()
6462 if (setup_mode == SETUP_MODE_GRAPHICS ||
6463 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6465 // update list selection from "setup.window_scaling_percent"
6466 execSetupGraphics_setWindowSizes(TRUE);
6472 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6474 if (setup_mode == SETUP_MODE_INPUT)
6475 HandleSetupScreen_Input(mx, my, dx, dy, button);
6476 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6477 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6478 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6479 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6480 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6481 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6482 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6483 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6484 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6485 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6486 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6487 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6488 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6489 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6490 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6491 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6492 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6493 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6494 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6495 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6496 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6497 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6498 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6499 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6500 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6501 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6502 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6503 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6505 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6508 void HandleGameActions()
6510 if (game_status != GAME_MODE_PLAYING)
6513 GameActions(); /* main game loop */
6515 if (tape.auto_play && !tape.playing)
6516 AutoPlayTape(); /* continue automatically playing next tape */
6520 /* ---------- new screen button stuff -------------------------------------- */
6522 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6526 case SCREEN_CTRL_ID_PREV_LEVEL:
6527 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6528 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6531 case SCREEN_CTRL_ID_NEXT_LEVEL:
6532 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6533 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6536 case SCREEN_CTRL_ID_PREV_PLAYER:
6537 *x = mSX + TILEX * 10;
6538 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6541 case SCREEN_CTRL_ID_NEXT_PLAYER:
6542 *x = mSX + TILEX * 12;
6543 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6547 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6553 int gfx_unpressed, gfx_pressed;
6554 void (*get_gadget_position)(int *, int *, int);
6558 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6561 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6562 getScreenMenuButtonPos,
6563 SCREEN_CTRL_ID_PREV_LEVEL,
6568 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6569 getScreenMenuButtonPos,
6570 SCREEN_CTRL_ID_NEXT_LEVEL,
6575 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6576 getScreenMenuButtonPos,
6577 SCREEN_CTRL_ID_PREV_PLAYER,
6582 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6583 getScreenMenuButtonPos,
6584 SCREEN_CTRL_ID_NEXT_PLAYER,
6592 int gfx_unpressed, gfx_pressed;
6596 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6599 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6600 -1, -1, /* these values are not constant, but can change at runtime */
6601 SCREEN_CTRL_ID_SCROLL_UP,
6605 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6606 -1, -1, /* these values are not constant, but can change at runtime */
6607 SCREEN_CTRL_ID_SCROLL_DOWN,
6614 int gfx_unpressed, gfx_pressed;
6620 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6623 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6624 -1, -1, /* these values are not constant, but can change at runtime */
6625 -1, -1, /* these values are not constant, but can change at runtime */
6626 GD_TYPE_SCROLLBAR_VERTICAL,
6627 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6628 "scroll level series vertically"
6632 static void CreateScreenMenubuttons()
6634 struct GadgetInfo *gi;
6635 unsigned int event_mask;
6638 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6640 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6641 int gfx_unpressed, gfx_pressed;
6642 int x, y, width, height;
6643 int gd_x1, gd_x2, gd_y1, gd_y2;
6644 int id = menubutton_info[i].gadget_id;
6646 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6648 menubutton_info[i].get_gadget_position(&x, &y, id);
6650 width = SC_MENUBUTTON_XSIZE;
6651 height = SC_MENUBUTTON_YSIZE;
6653 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6654 gfx_pressed = menubutton_info[i].gfx_pressed;
6655 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6656 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6657 gd_x1 = graphic_info[gfx_unpressed].src_x;
6658 gd_y1 = graphic_info[gfx_unpressed].src_y;
6659 gd_x2 = graphic_info[gfx_pressed].src_x;
6660 gd_y2 = graphic_info[gfx_pressed].src_y;
6662 gi = CreateGadget(GDI_CUSTOM_ID, id,
6663 GDI_CUSTOM_TYPE_ID, i,
6664 GDI_INFO_TEXT, menubutton_info[i].infotext,
6669 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6670 GDI_STATE, GD_BUTTON_UNPRESSED,
6671 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6672 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6673 GDI_DIRECT_DRAW, FALSE,
6674 GDI_EVENT_MASK, event_mask,
6675 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6679 Error(ERR_EXIT, "cannot create gadget");
6681 screen_gadget[id] = gi;
6685 static void CreateScreenScrollbuttons()
6687 struct GadgetInfo *gi;
6688 unsigned int event_mask;
6691 /* these values are not constant, but can change at runtime */
6692 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6693 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6694 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6695 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6697 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6699 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6700 int gfx_unpressed, gfx_pressed;
6701 int x, y, width, height;
6702 int gd_x1, gd_x2, gd_y1, gd_y2;
6703 int id = scrollbutton_info[i].gadget_id;
6705 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6707 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6708 y = mSY + scrollbutton_info[i].y;
6709 width = SC_SCROLLBUTTON_XSIZE;
6710 height = SC_SCROLLBUTTON_YSIZE;
6712 /* correct scrollbar position if placed outside menu (playfield) area */
6713 if (x > SX + SC_SCROLL_UP_XPOS)
6714 x = SX + SC_SCROLL_UP_XPOS;
6716 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6717 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6718 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6720 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6721 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6722 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6723 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6724 gd_x1 = graphic_info[gfx_unpressed].src_x;
6725 gd_y1 = graphic_info[gfx_unpressed].src_y;
6726 gd_x2 = graphic_info[gfx_pressed].src_x;
6727 gd_y2 = graphic_info[gfx_pressed].src_y;
6729 gi = CreateGadget(GDI_CUSTOM_ID, id,
6730 GDI_CUSTOM_TYPE_ID, i,
6731 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6736 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6737 GDI_STATE, GD_BUTTON_UNPRESSED,
6738 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6739 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6740 GDI_DIRECT_DRAW, FALSE,
6741 GDI_EVENT_MASK, event_mask,
6742 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6746 Error(ERR_EXIT, "cannot create gadget");
6748 screen_gadget[id] = gi;
6752 static void CreateScreenScrollbars()
6756 /* these values are not constant, but can change at runtime */
6757 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6758 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6759 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6760 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6762 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6764 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6765 int gfx_unpressed, gfx_pressed;
6766 int x, y, width, height;
6767 int gd_x1, gd_x2, gd_y1, gd_y2;
6768 struct GadgetInfo *gi;
6769 int items_max, items_visible, item_position;
6770 unsigned int event_mask;
6771 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6772 int id = scrollbar_info[i].gadget_id;
6774 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6776 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6777 y = mSY + scrollbar_info[i].y;
6778 width = scrollbar_info[i].width;
6779 height = scrollbar_info[i].height;
6781 /* correct scrollbar position if placed outside menu (playfield) area */
6782 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6783 x = SX + SC_SCROLL_VERTICAL_XPOS;
6785 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6786 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6788 items_max = num_page_entries;
6789 items_visible = num_page_entries;
6792 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6793 gfx_pressed = scrollbar_info[i].gfx_pressed;
6794 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6795 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6796 gd_x1 = graphic_info[gfx_unpressed].src_x;
6797 gd_y1 = graphic_info[gfx_unpressed].src_y;
6798 gd_x2 = graphic_info[gfx_pressed].src_x;
6799 gd_y2 = graphic_info[gfx_pressed].src_y;
6801 gi = CreateGadget(GDI_CUSTOM_ID, id,
6802 GDI_CUSTOM_TYPE_ID, i,
6803 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6808 GDI_TYPE, scrollbar_info[i].type,
6809 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6810 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6811 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6812 GDI_WHEEL_AREA_X, SX,
6813 GDI_WHEEL_AREA_Y, SY,
6814 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6815 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6816 GDI_STATE, GD_BUTTON_UNPRESSED,
6817 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6818 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6819 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6820 GDI_DIRECT_DRAW, FALSE,
6821 GDI_EVENT_MASK, event_mask,
6822 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6826 Error(ERR_EXIT, "cannot create gadget");
6828 screen_gadget[id] = gi;
6832 void CreateScreenGadgets()
6834 int last_game_status = game_status; /* save current game status */
6836 CreateScreenMenubuttons();
6838 CreateScreenScrollbuttons();
6839 CreateScreenScrollbars();
6841 game_status = last_game_status; /* restore current game status */
6844 void FreeScreenGadgets()
6848 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6849 FreeGadget(screen_gadget[i]);
6852 void MapScreenMenuGadgets(int screen_mask)
6856 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6857 if (screen_mask & menubutton_info[i].screen_mask)
6858 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6861 void MapScreenGadgets(int num_entries)
6865 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6868 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6869 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6871 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6872 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6875 void MapScreenTreeGadgets(TreeInfo *ti)
6877 MapScreenGadgets(numTreeInfoInGroup(ti));
6880 static void HandleScreenGadgets(struct GadgetInfo *gi)
6882 int id = gi->custom_id;
6883 int button = gi->event.button;
6884 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6888 case SCREEN_CTRL_ID_PREV_LEVEL:
6889 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6892 case SCREEN_CTRL_ID_NEXT_LEVEL:
6893 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6896 case SCREEN_CTRL_ID_PREV_PLAYER:
6897 HandleSetupScreen_Input_Player(step, -1);
6900 case SCREEN_CTRL_ID_NEXT_PLAYER:
6901 HandleSetupScreen_Input_Player(step, +1);
6904 case SCREEN_CTRL_ID_SCROLL_UP:
6905 if (game_status == GAME_MODE_LEVELS)
6906 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6907 else if (game_status == GAME_MODE_LEVELNR)
6908 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6909 else if (game_status == GAME_MODE_SETUP)
6910 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6913 case SCREEN_CTRL_ID_SCROLL_DOWN:
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_VERTICAL:
6923 if (game_status == GAME_MODE_LEVELS)
6924 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6925 else if (game_status == GAME_MODE_LEVELNR)
6926 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6927 else if (game_status == GAME_MODE_SETUP)
6928 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);