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
88 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
89 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
91 #define MENU_SCREEN_VALUE_XPOS 14
92 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
94 #define MENU_TITLE1_YPOS 8
95 #define MENU_TITLE2_YPOS 46
96 #define MENU_SCREEN_INFO_XSTART 16
97 #define MENU_SCREEN_INFO_YSTART1 100
98 #define MENU_SCREEN_INFO_YSTART2 128
99 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
100 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
101 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
102 MENU_SCREEN_INFO_YSTART2 - \
104 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
106 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
107 MENU_SCREEN_INFO_YSTEP, \
108 MAX_INFO_ELEMENTS_ON_SCREEN)
110 #define NUM_INFO_ELEMENTS_ON_SCREEN 10
112 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
114 #define MAX_MENU_TEXT_LENGTH_BIG 13
115 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
117 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
118 MENU_SCREEN_START_XPOS)
119 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
122 /* buttons and scrollbars identifiers */
123 #define SCREEN_CTRL_ID_PREV_LEVEL 0
124 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
125 #define SCREEN_CTRL_ID_PREV_PLAYER 2
126 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
127 #define SCREEN_CTRL_ID_SCROLL_UP 4
128 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
129 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
131 #define NUM_SCREEN_GADGETS 7
133 #define NUM_SCREEN_MENUBUTTONS 4
134 #define NUM_SCREEN_SCROLLBUTTONS 2
135 #define NUM_SCREEN_SCROLLBARS 1
137 #define SCREEN_MASK_MAIN (1 << 0)
138 #define SCREEN_MASK_INPUT (1 << 1)
140 /* graphic position and size values for buttons and scrollbars */
141 #define SC_MENUBUTTON_XSIZE TILEX
142 #define SC_MENUBUTTON_YSIZE TILEY
144 #define SC_SCROLLBUTTON_XSIZE TILEX
145 #define SC_SCROLLBUTTON_YSIZE TILEY
147 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
149 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
150 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
151 SC_SCROLLBUTTON_YSIZE)
153 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
154 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
156 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
157 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
158 SC_SCROLLBUTTON_YSIZE)
160 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
161 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
162 SC_SCROLL_VERTICAL_YSIZE)
164 #define SC_BORDER_SIZE 14
167 /* forward declarations of internal functions */
168 static void HandleScreenGadgets(struct GadgetInfo *);
169 static void HandleSetupScreen_Generic(int, int, int, int, int);
170 static void HandleSetupScreen_Input(int, int, int, int, int);
171 static void CustomizeKeyboard(int);
172 static void CalibrateJoystick(int);
173 static void execSetupGame(void);
174 static void execSetupGraphics(void);
175 static void execSetupSound(void);
176 static void execSetupTouch(void);
177 static void execSetupArtwork(void);
178 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
180 static void DrawChooseLevelSet(void);
181 static void DrawChooseLevelNr(void);
182 static void DrawInfoScreen(void);
183 static void DrawAndFadeInInfoScreen(int);
184 static void DrawSetupScreen(void);
186 static void DrawInfoScreenExt(int, int);
187 static void DrawInfoScreen_NotAvailable(char *, char *);
188 static void DrawInfoScreen_HelpAnim(int, int, boolean);
189 static void DrawInfoScreen_HelpText(int, int, int, int);
190 static void HandleInfoScreen_Main(int, int, int, int, int);
191 static void HandleInfoScreen_TitleScreen(int);
192 static void HandleInfoScreen_Elements(int);
193 static void HandleInfoScreen_Music(int);
194 static void HandleInfoScreen_Credits(int);
195 static void HandleInfoScreen_Program(int);
196 static void HandleInfoScreen_Version(int);
198 static void MapScreenMenuGadgets(int);
199 static void MapScreenGadgets(int);
200 static void MapScreenTreeGadgets(TreeInfo *);
202 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
204 static int info_mode = INFO_MODE_MAIN;
205 static int setup_mode = SETUP_MODE_MAIN;
207 static TreeInfo *screen_modes = NULL;
208 static TreeInfo *screen_mode_current = NULL;
210 static TreeInfo *window_sizes = NULL;
211 static TreeInfo *window_size_current = NULL;
213 static TreeInfo *scaling_types = NULL;
214 static TreeInfo *scaling_type_current = NULL;
216 static TreeInfo *scroll_delays = NULL;
217 static TreeInfo *scroll_delay_current = NULL;
219 static TreeInfo *game_speeds = NULL;
220 static TreeInfo *game_speed_current = NULL;
222 static TreeInfo *volumes_simple = NULL;
223 static TreeInfo *volume_simple_current = NULL;
225 static TreeInfo *volumes_loops = NULL;
226 static TreeInfo *volume_loops_current = NULL;
228 static TreeInfo *volumes_music = NULL;
229 static TreeInfo *volume_music_current = NULL;
231 static TreeInfo *touch_controls = NULL;
232 static TreeInfo *touch_control_current = NULL;
234 static TreeInfo *move_distances = NULL;
235 static TreeInfo *move_distance_current = NULL;
237 static TreeInfo *drop_distances = NULL;
238 static TreeInfo *drop_distance_current = NULL;
240 static TreeInfo *level_number = NULL;
241 static TreeInfo *level_number_current = NULL;
247 } window_sizes_list[] =
252 { 100, "100 % (Default)" },
269 } scaling_types_list[] =
271 { SCALING_QUALITY_NEAREST, "None" },
272 { SCALING_QUALITY_LINEAR, "Linear" },
273 { SCALING_QUALITY_BEST, "Anisotropic" },
282 } game_speeds_list[] =
291 { 1000, "1/1s (Extremely Slow)" },
296 { 29, "1/35s (Original Supaplex)" },
298 { 20, "1/50s (Normal Speed)" },
299 { 14, "1/70s (Maximum Supaplex)" },
303 { 1, "1/1000s (Extremely Fast)" },
313 } scroll_delays_list[] =
315 { 0, "0 Tiles (No Scroll Delay)" },
318 { 3, "3 Tiles (Default)" },
323 { 8, "8 Tiles (Maximum Scroll Delay)"},
353 } touch_controls_list[] =
355 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
356 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
380 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
381 (s) <= GAME_MODE_SETUP ? (s) : \
382 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
383 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
385 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
386 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
387 (i) <= INFO_MODE_LEVELSET ? (i) : \
390 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
391 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
392 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
393 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
394 SETUP_MODE_CHOOSE_ARTWORK : \
395 SETUP_MODE_CHOOSE_OTHER)
397 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
398 menu.draw_xoffset[GAME_MODE_INFO] : \
399 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
400 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
401 menu.draw_yoffset[GAME_MODE_INFO] : \
402 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
404 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
405 menu.draw_xoffset[GAME_MODE_SETUP] : \
406 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
407 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
408 menu.draw_yoffset[GAME_MODE_SETUP] : \
409 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
411 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
412 DRAW_XOFFSET_INFO(info_mode) : \
413 (s) == GAME_MODE_SETUP ? \
414 DRAW_XOFFSET_SETUP(setup_mode) : \
415 menu.draw_xoffset[DRAW_MODE(s)])
416 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
417 DRAW_YOFFSET_INFO(info_mode) : \
418 (s) == GAME_MODE_SETUP ? \
419 DRAW_YOFFSET_SETUP(setup_mode) : \
420 menu.draw_yoffset[DRAW_MODE(s)])
422 #define mSX (SX + DRAW_XOFFSET(game_status))
423 #define mSY (SY + DRAW_YOFFSET(game_status))
425 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
426 menu.list_size[game_status] : \
427 MAX_MENU_ENTRIES_ON_SCREEN)
430 /* title display and control definitions */
432 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
433 2 * MAX_NUM_TITLE_MESSAGES)
435 static int num_title_screens = 0;
437 struct TitleControlInfo
445 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
447 /* main menu display and control definitions */
449 #define MAIN_CONTROL_NAME 0
450 #define MAIN_CONTROL_LEVELS 1
451 #define MAIN_CONTROL_SCORES 2
452 #define MAIN_CONTROL_EDITOR 3
453 #define MAIN_CONTROL_INFO 4
454 #define MAIN_CONTROL_GAME 5
455 #define MAIN_CONTROL_SETUP 6
456 #define MAIN_CONTROL_QUIT 7
457 #define MAIN_CONTROL_PREV_LEVEL 8
458 #define MAIN_CONTROL_NEXT_LEVEL 9
459 #define MAIN_CONTROL_FIRST_LEVEL 10
460 #define MAIN_CONTROL_LAST_LEVEL 11
461 #define MAIN_CONTROL_LEVEL_NUMBER 12
462 #define MAIN_CONTROL_LEVEL_INFO_1 13
463 #define MAIN_CONTROL_LEVEL_INFO_2 14
464 #define MAIN_CONTROL_LEVEL_NAME 15
465 #define MAIN_CONTROL_LEVEL_AUTHOR 16
466 #define MAIN_CONTROL_LEVEL_YEAR 17
467 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
468 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
469 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
470 #define MAIN_CONTROL_TITLE_1 21
471 #define MAIN_CONTROL_TITLE_2 22
472 #define MAIN_CONTROL_TITLE_3 23
474 static char str_main_text_name[10];
475 static char str_main_text_first_level[10];
476 static char str_main_text_last_level[10];
477 static char str_main_text_level_number[10];
479 static char *main_text_name = str_main_text_name;
480 static char *main_text_first_level = str_main_text_first_level;
481 static char *main_text_last_level = str_main_text_last_level;
482 static char *main_text_level_number = str_main_text_level_number;
483 static char *main_text_levels = "Levelset";
484 static char *main_text_scores = "Hall Of Fame";
485 static char *main_text_editor = "Level Creator";
486 static char *main_text_info = "Info Screen";
487 static char *main_text_game = "Start Game";
488 static char *main_text_setup = "Setup";
489 static char *main_text_quit = "Quit";
490 static char *main_text_level_name = level.name;
491 static char *main_text_level_author = level.author;
492 static char *main_text_level_year = NULL;
493 static char *main_text_level_imported_from = NULL;
494 static char *main_text_level_imported_by = NULL;
495 static char *main_text_level_tested_by = NULL;
496 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
497 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
498 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
500 struct MainControlInfo
504 struct MenuPosInfo *pos_button;
507 struct TextPosInfo *pos_text;
510 struct TextPosInfo *pos_input;
514 static struct MainControlInfo main_controls[] =
518 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
519 &menu.main.text.name, &main_text_name,
520 &menu.main.input.name, &setup.player_name,
524 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
525 &menu.main.text.levels, &main_text_levels,
530 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
531 &menu.main.text.scores, &main_text_scores,
536 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
537 &menu.main.text.editor, &main_text_editor,
542 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
543 &menu.main.text.info, &main_text_info,
548 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
549 &menu.main.text.game, &main_text_game,
554 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
555 &menu.main.text.setup, &main_text_setup,
560 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
561 &menu.main.text.quit, &main_text_quit,
565 /* (these two buttons are real gadgets) */
567 MAIN_CONTROL_PREV_LEVEL,
568 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
573 MAIN_CONTROL_NEXT_LEVEL,
574 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
580 MAIN_CONTROL_FIRST_LEVEL,
582 &menu.main.text.first_level, &main_text_first_level,
586 MAIN_CONTROL_LAST_LEVEL,
588 &menu.main.text.last_level, &main_text_last_level,
592 MAIN_CONTROL_LEVEL_NUMBER,
594 &menu.main.text.level_number, &main_text_level_number,
598 MAIN_CONTROL_LEVEL_INFO_1,
600 &menu.main.text.level_info_1, NULL,
604 MAIN_CONTROL_LEVEL_INFO_2,
606 &menu.main.text.level_info_2, NULL,
610 MAIN_CONTROL_LEVEL_NAME,
612 &menu.main.text.level_name, &main_text_level_name,
616 MAIN_CONTROL_LEVEL_AUTHOR,
618 &menu.main.text.level_author, &main_text_level_author,
622 MAIN_CONTROL_LEVEL_YEAR,
624 &menu.main.text.level_year, &main_text_level_year,
628 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
630 &menu.main.text.level_imported_from, &main_text_level_imported_from,
634 MAIN_CONTROL_LEVEL_IMPORTED_BY,
636 &menu.main.text.level_imported_by, &main_text_level_imported_by,
640 MAIN_CONTROL_LEVEL_TESTED_BY,
642 &menu.main.text.level_tested_by, &main_text_level_tested_by,
646 MAIN_CONTROL_TITLE_1,
648 &menu.main.text.title_1, &main_text_title_1,
652 MAIN_CONTROL_TITLE_2,
654 &menu.main.text.title_2, &main_text_title_2,
658 MAIN_CONTROL_TITLE_3,
660 &menu.main.text.title_3, &main_text_title_3,
673 static int getTitleScreenGraphic(int nr, boolean initial)
675 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
678 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
680 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
684 static int getTitleScreenGameMode(boolean initial)
686 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
690 static int getTitleMessageGameMode(boolean initial)
692 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
696 static int getTitleScreenBackground(boolean initial)
698 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
703 static int getTitleMessageBackground(int nr, boolean initial)
705 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
709 static int getTitleBackground(int nr, boolean initial, boolean is_image)
711 int base = (is_image ?
712 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
713 IMG_BACKGROUND_TITLESCREEN_1) :
714 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
715 IMG_BACKGROUND_TITLEMESSAGE_1));
716 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
717 IMG_BACKGROUND_TITLE);
718 int graphic_local = base + nr;
720 if (graphic_info[graphic_local].bitmap != NULL)
721 return graphic_local;
723 if (graphic_info[graphic_global].bitmap != NULL)
724 return graphic_global;
726 return IMG_UNDEFINED;
729 static int getTitleSound(struct TitleControlInfo *tci)
731 boolean is_image = tci->is_image;
732 int initial = tci->initial;
733 int nr = tci->local_nr;
734 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
735 int base = (is_image ?
736 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
737 SND_BACKGROUND_TITLESCREEN_1) :
738 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
739 SND_BACKGROUND_TITLEMESSAGE_1));
740 int sound_global = menu.sound[mode];
741 int sound_local = base + nr;
744 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
745 nr, initial, is_image,
746 sound_global, getSoundListEntry(sound_global)->filename,
747 sound_local, getSoundListEntry(sound_local)->filename);
750 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
753 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
756 return SND_UNDEFINED;
759 static int getTitleMusic(struct TitleControlInfo *tci)
761 boolean is_image = tci->is_image;
762 int initial = tci->initial;
763 int nr = tci->local_nr;
764 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
765 int base = (is_image ?
766 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
767 MUS_BACKGROUND_TITLESCREEN_1) :
768 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
769 MUS_BACKGROUND_TITLEMESSAGE_1));
770 int music_global = menu.music[mode];
771 int music_local = base + nr;
774 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
775 nr, initial, is_image,
776 music_global, getMusicListEntry(music_global)->filename,
777 music_local, getMusicListEntry(music_local)->filename);
780 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
783 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
786 return MUS_UNDEFINED;
789 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
791 boolean is_image = tci->is_image;
792 int initial = tci->initial;
793 int nr = tci->local_nr;
794 struct TitleFadingInfo ti;
798 int graphic = getTitleScreenGraphic(nr, initial);
800 /* initialize fading control values to default title config settings */
801 ti = (initial ? title_initial_default : title_default);
803 /* override default settings with image config settings, if defined */
804 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
805 ti.fade_mode = graphic_info[graphic].fade_mode;
806 if (graphic_info[graphic].fade_delay > -1)
807 ti.fade_delay = graphic_info[graphic].fade_delay;
808 if (graphic_info[graphic].post_delay > -1)
809 ti.post_delay = graphic_info[graphic].post_delay;
810 if (graphic_info[graphic].auto_delay > -1)
811 ti.auto_delay = graphic_info[graphic].auto_delay;
817 ti.fade_mode = titlemessage_initial[nr].fade_mode;
818 ti.fade_delay = titlemessage_initial[nr].fade_delay;
819 ti.post_delay = titlemessage_initial[nr].post_delay;
820 ti.auto_delay = titlemessage_initial[nr].auto_delay;
824 ti.fade_mode = titlemessage[nr].fade_mode;
825 ti.fade_delay = titlemessage[nr].fade_delay;
826 ti.post_delay = titlemessage[nr].post_delay;
827 ti.auto_delay = titlemessage[nr].auto_delay;
832 if (ti.anim_mode == ANIM_NONE)
833 ti.fade_delay = ti.post_delay = 0;
839 static int compareTitleControlInfo(const void *object1, const void *object2)
841 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
842 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
845 if (tci1->initial != tci2->initial)
846 compare_result = (tci1->initial ? -1 : +1);
847 else if (tci1->sort_priority != tci2->sort_priority)
848 compare_result = tci1->sort_priority - tci2->sort_priority;
849 else if (tci1->is_image != tci2->is_image)
850 compare_result = (tci1->is_image ? -1 : +1);
852 compare_result = tci1->local_nr - tci2->local_nr;
854 return compare_result;
857 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
859 int nr, int sort_priority)
861 title_controls[num_title_screens].is_image = is_image;
862 title_controls[num_title_screens].initial = initial;
863 title_controls[num_title_screens].local_nr = nr;
864 title_controls[num_title_screens].sort_priority = sort_priority;
869 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
873 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
875 int graphic = getTitleScreenGraphic(i, initial);
876 Bitmap *bitmap = graphic_info[graphic].bitmap;
877 int sort_priority = graphic_info[graphic].sort_priority;
880 /* skip images and messages (fonts!) when using forced custom graphics */
881 if (setup.override_level_graphics && !initial)
886 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
889 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
891 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
892 char *filename = getLevelSetTitleMessageFilename(i, initial);
893 int sort_priority = tmi->sort_priority;
896 /* skip images and messages (fonts!) when using forced custom graphics */
897 if (setup.override_level_graphics)
901 if (filename != NULL)
902 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
906 static void InitializeTitleControls(boolean show_title_initial)
908 num_title_screens = 0;
911 /* 1st step: initialize title screens for game start (only when starting) */
912 if (show_title_initial)
913 InitializeTitleControls_CheckTitleInfo(TRUE);
916 /* 2nd step: initialize title screens for current level set */
917 InitializeTitleControls_CheckTitleInfo(FALSE);
919 /* sort title screens according to sort_priority and title number */
920 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
921 compareTitleControlInfo);
924 static boolean visibleMenuPos(struct MenuPosInfo *pos)
926 return (pos != NULL && pos->x != -1 && pos->y != -1);
929 static boolean visibleTextPos(struct TextPosInfo *pos)
931 return (pos != NULL && pos->x != -1 && pos->y != -1);
934 static void InitializeMainControls()
936 boolean local_team_mode = (!options.network && setup.team_mode);
939 /* set main control text values to dynamically determined values */
940 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
942 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
943 menu.main.text.first_level.size));
944 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
945 menu.main.text.last_level.size));
946 strcpy(main_text_level_number, int2str(level_nr,
947 menu.main.text.level_number.size));
949 main_text_level_year = leveldir_current->year;
950 main_text_level_imported_from = leveldir_current->imported_from;
951 main_text_level_imported_by = leveldir_current->imported_by;
952 main_text_level_tested_by = leveldir_current->tested_by;
954 /* set main control screen positions to dynamically determined values */
955 for (i = 0; main_controls[i].nr != -1; i++)
957 struct MainControlInfo *mci = &main_controls[i];
959 struct MenuPosInfo *pos_button = mci->pos_button;
960 struct TextPosInfo *pos_text = mci->pos_text;
961 struct TextPosInfo *pos_input = mci->pos_input;
962 char *text = (mci->text ? *mci->text : NULL);
963 char *input = (mci->input ? *mci->input : NULL);
964 int button_graphic = mci->button_graphic;
966 int font_text = (pos_text ? pos_text->font : -1);
967 int font_input = (pos_input ? pos_input->font : -1);
969 int font_text = mci->font_text;
970 int font_input = mci->font_input;
973 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
974 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
975 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
976 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
977 int text_chars = (text != NULL ? strlen(text) : 0);
978 int input_chars = (input != NULL ? strlen(input) : 0);
981 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
983 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
984 int text_width = font_text_width * text_chars;
985 int text_height = font_text_height;
986 int input_width = font_input_width * input_chars;
987 int input_height = font_input_height;
989 if (nr == MAIN_CONTROL_NAME)
992 if (menu.main.input.name.x == -1)
993 menu.main.input.name.x = menu.main.text.name.x + text_width;
994 if (menu.main.input.name.y == -1)
995 menu.main.input.name.y = menu.main.text.name.y;
999 menu.main.input.name.width = input_width;
1000 menu.main.input.name.height = input_height;
1002 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
1003 menu.main.input.name.height = font_input_height;
1007 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1009 if (pos_button->width == 0)
1010 pos_button->width = button_width;
1011 if (pos_button->height == 0)
1012 pos_button->height = button_height;
1015 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1018 /* calculate size for non-clickable text -- needed for text alignment */
1019 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1021 /* calculate width for non-clickable text -- needed for text alignment */
1022 boolean calculate_text_width = (pos_button == NULL && text != NULL);
1025 if (visibleMenuPos(pos_button))
1027 if (pos_text->x == -1)
1028 pos_text->x = pos_button->x + pos_button->width;
1029 if (pos_text->y == -1)
1030 pos_text->y = pos_button->y;
1034 if (pos_text->width == -1 || calculate_text_size)
1035 pos_text->width = text_width;
1036 if (pos_text->height == -1 || calculate_text_size)
1037 pos_text->height = text_height;
1039 if (pos_text->width == -1 || calculate_text_width)
1040 pos_text->width = text_width;
1041 if (pos_text->height == -1)
1042 pos_text->height = text_height;
1046 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1048 if (visibleTextPos(pos_text))
1050 if (pos_input->x == -1)
1051 pos_input->x = pos_text->x + pos_text->width;
1052 if (pos_input->y == -1)
1053 pos_input->y = pos_text->y;
1056 if (pos_input->width == -1)
1057 pos_input->width = input_width;
1058 if (pos_input->height == -1)
1059 pos_input->height = input_height;
1064 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1065 boolean active_input)
1069 for (i = 0; main_controls[i].nr != -1; i++)
1071 struct MainControlInfo *mci = &main_controls[i];
1073 if (mci->nr == nr || nr == -1)
1075 struct MenuPosInfo *pos_button = mci->pos_button;
1076 struct TextPosInfo *pos_text = mci->pos_text;
1077 struct TextPosInfo *pos_input = mci->pos_input;
1078 char *text = (mci->text ? *mci->text : NULL);
1079 char *input = (mci->input ? *mci->input : NULL);
1080 int button_graphic = mci->button_graphic;
1082 int font_text = (pos_text ? pos_text->font : -1);
1083 int font_input = (pos_input ? pos_input->font : -1);
1085 int font_text = mci->font_text;
1086 int font_input = mci->font_input;
1091 button_graphic = BUTTON_ACTIVE(button_graphic);
1092 font_text = FONT_ACTIVE(font_text);
1097 font_input = FONT_ACTIVE(font_input);
1100 if (visibleMenuPos(pos_button))
1102 struct MenuPosInfo *pos = pos_button;
1103 int x = mSX + pos->x;
1104 int y = mSY + pos->y;
1106 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1107 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1110 if (visibleTextPos(pos_text) && text != NULL)
1112 struct TextPosInfo *pos = pos_text;
1113 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1114 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1117 /* (check why/if this is needed) */
1118 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1120 DrawText(x, y, text, font_text);
1123 if (visibleTextPos(pos_input) && input != NULL)
1125 struct TextPosInfo *pos = pos_input;
1126 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1127 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1130 /* (check why/if this is needed) */
1131 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1133 DrawText(x, y, input, font_input);
1139 static void DrawCursorAndText_Main(int nr, boolean active_text)
1141 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1145 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1147 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1151 static struct MainControlInfo *getMainControlInfo(int nr)
1155 for (i = 0; main_controls[i].nr != -1; i++)
1156 if (main_controls[i].nr == nr)
1157 return &main_controls[i];
1162 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1167 int rect_x = ALIGNED_TEXT_XPOS(rect);
1168 int rect_y = ALIGNED_TEXT_YPOS(rect);
1170 return (x >= rect_x && x < rect_x + rect->width &&
1171 y >= rect_y && y < rect_y + rect->height);
1174 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1179 int rect_x = ALIGNED_TEXT_XPOS(rect);
1180 int rect_y = ALIGNED_TEXT_YPOS(rect);
1183 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1184 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1185 (x >= rect_x && x < rect_x + rect->width &&
1186 y >= rect_y && y < rect_y + rect->height));
1189 return (x >= rect_x && x < rect_x + rect->width &&
1190 y >= rect_y && y < rect_y + rect->height);
1193 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1196 static int cursor_array[MAX_LEV_FIELDY];
1198 static int cursor_array[SCR_FIELDY];
1200 int x = mSX + TILEX * xpos;
1201 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1206 cursor_array[ypos] = graphic;
1208 graphic = cursor_array[ypos];
1212 graphic = BUTTON_ACTIVE(graphic);
1214 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1215 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1218 static void initCursor(int ypos, int graphic)
1220 drawCursorExt(0, ypos, FALSE, graphic);
1223 static void drawCursor(int ypos, boolean active)
1225 drawCursorExt(0, ypos, active, -1);
1228 static void drawCursorXY(int xpos, int ypos, int graphic)
1230 drawCursorExt(xpos, ypos, FALSE, graphic);
1233 static void drawChooseTreeCursor(int ypos, boolean active)
1235 int last_game_status = game_status; /* save current game status */
1238 /* force LEVELS draw offset on artwork setup screen */
1239 game_status = GAME_MODE_LEVELS;
1242 drawCursorExt(0, ypos, active, -1);
1244 game_status = last_game_status; /* restore current game status */
1249 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1250 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1254 static int getPrevlevelButtonPos()
1259 static int getCurrentLevelTextPos()
1261 return (getPrevlevelButtonPos() + 1);
1264 static int getNextLevelButtonPos()
1266 return getPrevlevelButtonPos() + 3 + 1;
1269 static int getLevelRangeTextPos()
1271 return getNextLevelButtonPos() + 1;
1275 int effectiveGameStatus()
1277 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1278 return GAME_MODE_TITLE;
1283 void DrawTitleScreenImage(int nr, boolean initial)
1285 int graphic = getTitleScreenGraphic(nr, initial);
1286 Bitmap *bitmap = graphic_info[graphic].bitmap;
1287 int width = graphic_info[graphic].width;
1288 int height = graphic_info[graphic].height;
1289 int src_x = graphic_info[graphic].src_x;
1290 int src_y = graphic_info[graphic].src_y;
1296 if (width > WIN_XSIZE)
1298 /* image width too large for window => center image horizontally */
1299 src_x = (width - WIN_XSIZE) / 2;
1303 if (height > WIN_YSIZE)
1305 /* image height too large for window => center image vertically */
1306 src_y = (height - WIN_YSIZE) / 2;
1310 /* always display title screens centered */
1311 dst_x = (WIN_XSIZE - width) / 2;
1312 dst_y = (WIN_YSIZE - height) / 2;
1314 SetDrawBackgroundMask(REDRAW_ALL);
1315 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1317 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1319 if (DrawingOnBackground(dst_x, dst_y))
1321 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1322 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1325 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1327 redraw_mask = REDRAW_ALL;
1330 void DrawTitleScreenMessage(int nr, boolean initial)
1332 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1333 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1334 int last_game_status = game_status; /* save current game status */
1336 if (filename == NULL)
1339 /* force TITLE font on title message screen */
1340 game_status = getTitleMessageGameMode(initial);
1342 /* if chars set to "-1", automatically determine by text and font width */
1343 if (tmi->chars == -1)
1344 tmi->chars = tmi->width / getFontWidth(tmi->font);
1346 tmi->width = tmi->chars * getFontWidth(tmi->font);
1348 /* if lines set to "-1", automatically determine by text and font height */
1349 if (tmi->lines == -1)
1350 tmi->lines = tmi->height / getFontHeight(tmi->font);
1352 tmi->height = tmi->lines * getFontHeight(tmi->font);
1354 SetDrawBackgroundMask(REDRAW_ALL);
1355 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1357 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1359 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1360 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1361 tmi->autowrap, tmi->centered, tmi->parse_comments);
1363 game_status = last_game_status; /* restore current game status */
1366 void DrawTitleScreen()
1368 KeyboardAutoRepeatOff();
1371 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1374 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1379 boolean CheckTitleScreen(boolean levelset_has_changed)
1381 static boolean show_title_initial = TRUE;
1382 boolean show_titlescreen = FALSE;
1384 /* needed to be able to skip title screen, if no image or message defined */
1385 InitializeTitleControls(show_title_initial);
1387 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1388 show_titlescreen = TRUE;
1390 /* show initial title images and messages only once at program start */
1391 show_title_initial = FALSE;
1393 return (show_titlescreen && num_title_screens > 0);
1396 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1398 static LevelDirTree *leveldir_last_valid = NULL;
1399 boolean levelset_has_changed = FALSE;
1401 LimitScreenUpdates(FALSE);
1403 FadeSetLeaveScreen();
1405 /* do not fade out here -- function may continue and fade on editor screen */
1408 FadeSoundsAndMusic();
1410 KeyboardAutoRepeatOn();
1413 SetDrawDeactivationMask(REDRAW_NONE);
1414 SetDrawBackgroundMask(REDRAW_FIELD);
1416 audio.sound_deactivated = FALSE;
1420 /* needed if last screen was the playing screen, invoked from level editor */
1421 if (level_editor_test_game)
1423 game_status = GAME_MODE_EDITOR;
1429 /* needed if last screen was the setup screen and fullscreen state changed */
1430 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1431 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1433 /* leveldir_current may be invalid (level group, parent link) */
1434 if (!validLevelSeries(leveldir_current))
1435 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1437 if (leveldir_current != leveldir_last_valid)
1438 levelset_has_changed = TRUE;
1440 /* store valid level series information */
1441 leveldir_last_valid = leveldir_current;
1443 init_last = init; /* switch to new busy animation */
1445 /* needed if last screen (level choice) changed graphics, sounds or music */
1446 ReloadCustomArtwork(0);
1448 if (redraw_mask & REDRAW_ALL)
1449 fade_mask = REDRAW_ALL;
1455 /* needed if last screen was the editor screen */
1456 UndrawSpecialEditorDoor();
1460 if (fade_mask == REDRAW_FIELD)
1466 /* needed if different viewport properties defined for menues */
1467 ChangeViewportPropertiesIfNeeded();
1471 /* needed if last screen was the editor screen */
1472 UndrawSpecialEditorDoor();
1475 #if defined(TARGET_SDL)
1476 SetDrawtoField(DRAW_BACKBUFFER);
1479 if (CheckTitleScreen(levelset_has_changed))
1481 game_status = GAME_MODE_TITLE;
1488 /* level_nr may have been set to value over handicap with level editor */
1489 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1490 level_nr = leveldir_current->handicap_level;
1492 LoadLevel(level_nr);
1493 LoadScore(level_nr);
1495 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1498 if (fade_mask == REDRAW_ALL)
1500 // int door_state = GetDoorState();
1504 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1510 InitializeMainControls();
1512 DrawCursorAndText_Main(-1, FALSE);
1513 DrawPreviewLevelInitial();
1515 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1518 if (TAPE_IS_EMPTY(tape))
1520 DrawCompleteVideoDisplay();
1525 /* create gadgets for main menu screen */
1526 FreeScreenGadgets();
1527 CreateScreenGadgets();
1529 /* map gadgets for main menu screen */
1531 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1534 /* copy actual game door content to door double buffer for OpenDoor() */
1535 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1539 // if (fade_mask == REDRAW_ALL)
1540 // (always redraw current door state)
1542 int door_state = GetDoorState();
1544 // RedrawBackground();
1546 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1551 redraw_mask |= REDRAW_ALL;
1556 DrawMaskedBorder(REDRAW_ALL);
1562 /* update screen area with special editor door */
1563 redraw_mask |= REDRAW_ALL;
1567 SetMouseCursor(CURSOR_DEFAULT);
1571 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1574 void DrawAndFadeInMainMenu(int fade_mask)
1576 DrawMainMenuExt(fade_mask, TRUE);
1581 DrawMainMenuExt(REDRAW_ALL, FALSE);
1584 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1585 static void gotoTopLevelDir()
1587 /* move upwards to top level directory */
1588 while (leveldir_current->node_parent)
1590 /* write a "path" into level tree for easy navigation to last level */
1591 if (leveldir_current->node_parent->node_group->cl_first == -1)
1593 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1594 int leveldir_pos = posTreeInfo(leveldir_current);
1595 int num_page_entries;
1596 int cl_first, cl_cursor;
1598 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1599 num_page_entries = num_leveldirs;
1601 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1603 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1604 cl_cursor = leveldir_pos - cl_first;
1606 leveldir_current->node_parent->node_group->cl_first = cl_first;
1607 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1610 leveldir_current = leveldir_current->node_parent;
1615 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1617 static unsigned int title_delay = 0;
1618 static int title_screen_nr = 0;
1619 static int last_sound = -1, last_music = -1;
1620 boolean return_to_main_menu = FALSE;
1621 boolean use_fading_main_menu = TRUE;
1622 struct TitleControlInfo *tci;
1623 struct TitleFadingInfo fading_default;
1624 struct TitleFadingInfo fading_last = fading;
1625 struct TitleFadingInfo fading_next;
1628 if (button == MB_MENU_INITIALIZE)
1631 title_screen_nr = 0;
1632 tci = &title_controls[title_screen_nr];
1634 last_sound = SND_UNDEFINED;
1635 last_music = MUS_UNDEFINED;
1637 if (game_status == GAME_MODE_INFO)
1639 if (num_title_screens == 0)
1641 DrawInfoScreen_NotAvailable("Title screen information:",
1642 "No title screen for this level set.");
1647 FadeSoundsAndMusic();
1650 FadeOut(REDRAW_ALL);
1655 DrawTitleScreenImage(tci->local_nr, tci->initial);
1657 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1659 fading_default = (tci->initial ? title_initial_default : title_default);
1661 fading = fading_next = getTitleFading(tci);
1665 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1666 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1668 fading.fade_mode = FADE_MODE_FADE;
1669 fading.fade_delay = fading_default.fade_delay;
1672 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1673 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1674 fading.fade_mode = FADE_MODE_FADE;
1679 sound = getTitleSound(tci);
1680 music = getTitleMusic(tci);
1682 if (sound != last_sound)
1683 PlayMenuSoundExt(sound);
1684 if (music != last_music)
1685 PlayMenuMusicExt(music);
1691 SetMouseCursor(CURSOR_NONE);
1697 fading = fading_next;
1699 DelayReached(&title_delay, 0); /* reset delay counter */
1705 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1706 button = MB_MENU_CHOICE;
1708 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1709 button = MB_MENU_CHOICE;
1712 if (button == MB_MENU_LEAVE)
1714 return_to_main_menu = TRUE;
1715 use_fading_main_menu = FALSE;
1717 else if (button == MB_MENU_CHOICE)
1719 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1722 FadeOut(REDRAW_FIELD);
1725 FadeSetEnterScreen();
1727 info_mode = INFO_MODE_MAIN;
1728 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1734 tci = &title_controls[title_screen_nr];
1736 if (title_screen_nr < num_title_screens)
1738 sound = getTitleSound(tci);
1739 music = getTitleMusic(tci);
1741 if (sound == SND_UNDEFINED || sound != last_sound)
1743 if (music == MUS_UNDEFINED || music != last_music)
1747 FadeOut(REDRAW_ALL);
1751 DrawTitleScreenImage(tci->local_nr, tci->initial);
1753 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1755 fading_next = getTitleFading(tci);
1758 sound = getTitleSound(tci);
1759 music = getTitleMusic(tci);
1761 if (sound != last_sound)
1762 PlayMenuSoundExt(sound);
1763 if (music != last_music)
1764 PlayMenuMusicExt(music);
1771 /* last screen already faded out, next screen has no animation */
1772 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1773 fading_next.fade_mode == FADE_MODE_NONE)
1774 fading = fading_next;
1776 /* last screen already faded out, next screen has no animation */
1777 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1778 fading_next.fade_mode == FADE_MODE_NONE)
1779 fading = fading_next;
1786 fading = fading_next;
1788 DelayReached(&title_delay, 0); /* reset delay counter */
1792 FadeSoundsAndMusic();
1794 return_to_main_menu = TRUE;
1798 if (return_to_main_menu)
1804 SetMouseCursor(CURSOR_DEFAULT);
1806 if (game_status == GAME_MODE_INFO)
1809 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1812 info_mode = INFO_MODE_MAIN;
1813 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1815 else /* default: return to main menu */
1818 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1821 game_status = GAME_MODE_MAIN;
1822 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1827 void HandleMainMenu_SelectLevel(int step, int direction)
1829 int old_level_nr = level_nr;
1832 new_level_nr = old_level_nr + step * direction;
1833 if (new_level_nr < leveldir_current->first_level)
1834 new_level_nr = leveldir_current->first_level;
1835 if (new_level_nr > leveldir_current->last_level)
1836 new_level_nr = leveldir_current->last_level;
1838 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1840 /* skipping levels is only allowed when trying to skip single level */
1841 if (setup.skip_levels && step == 1 &&
1842 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1844 leveldir_current->handicap_level++;
1845 SaveLevelSetup_SeriesInfo();
1848 new_level_nr = leveldir_current->handicap_level;
1851 if (new_level_nr != old_level_nr)
1853 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1855 PlaySound(SND_MENU_ITEM_SELECTING);
1857 level_nr = new_level_nr;
1859 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1860 int2str(level_nr, menu.main.text.level_number.size),
1861 mci->pos_text->font);
1863 LoadLevel(level_nr);
1864 DrawPreviewLevelInitial();
1868 DrawCompleteVideoDisplay();
1870 /* needed because DrawPreviewLevelInitial() takes some time */
1876 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1878 static int choice = MAIN_CONTROL_GAME;
1882 if (button == MB_MENU_INITIALIZE)
1884 DrawCursorAndText_Main(choice, TRUE);
1889 if (mx || my) /* mouse input */
1893 for (i = 0; main_controls[i].nr != -1; i++)
1896 printf("::: check click (%d, %d) for %d [%d] ...\n",
1897 mx - mSX, my - mSY, i, main_controls[i].nr);
1900 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1901 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1902 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1905 printf("::: inside %d\n", i);
1908 pos = main_controls[i].nr;
1914 else if (dx || dy) /* keyboard input */
1916 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1917 choice == MAIN_CONTROL_SETUP))
1918 button = MB_MENU_CHOICE;
1923 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1925 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1927 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1929 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1931 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1933 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1935 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1937 game_status = GAME_MODE_LEVELNR;
1940 ChangeViewportPropertiesIfNeeded();
1943 DrawChooseLevelNr();
1945 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1951 PlaySound(SND_MENU_ITEM_ACTIVATING);
1953 DrawCursorAndText_Main(choice, FALSE);
1954 DrawCursorAndText_Main(pos, TRUE);
1961 PlaySound(SND_MENU_ITEM_SELECTING);
1963 if (pos == MAIN_CONTROL_NAME)
1965 game_status = GAME_MODE_PSEUDO_TYPENAME;
1967 HandleTypeName(strlen(setup.player_name), 0);
1969 else if (pos == MAIN_CONTROL_LEVELS)
1973 game_status = GAME_MODE_LEVELS;
1975 SaveLevelSetup_LastSeries();
1976 SaveLevelSetup_SeriesInfo();
1978 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1983 ChangeViewportPropertiesIfNeeded();
1986 DrawChooseLevelSet();
1989 else if (pos == MAIN_CONTROL_SCORES)
1991 game_status = GAME_MODE_SCORES;
1994 ChangeViewportPropertiesIfNeeded();
1999 else if (pos == MAIN_CONTROL_EDITOR)
2001 if (leveldir_current->readonly &&
2002 !strEqual(setup.player_name, "Artsoft"))
2003 Request("This level is read only!", REQ_CONFIRM);
2005 CloseDoor(DOOR_CLOSE_2);
2007 game_status = GAME_MODE_EDITOR;
2009 FadeSetEnterScreen();
2012 /* needed if different viewport properties defined for editor */
2013 ChangeViewportPropertiesIfNeeded();
2018 else if (pos == MAIN_CONTROL_INFO)
2020 game_status = GAME_MODE_INFO;
2021 info_mode = INFO_MODE_MAIN;
2024 ChangeViewportPropertiesIfNeeded();
2029 else if (pos == MAIN_CONTROL_GAME)
2031 StartGameActions(options.network, setup.autorecord, level.random_seed);
2033 else if (pos == MAIN_CONTROL_SETUP)
2035 game_status = GAME_MODE_SETUP;
2036 setup_mode = SETUP_MODE_MAIN;
2039 ChangeViewportPropertiesIfNeeded();
2044 else if (pos == MAIN_CONTROL_QUIT)
2046 SaveLevelSetup_LastSeries();
2047 SaveLevelSetup_SeriesInfo();
2049 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2050 game_status = GAME_MODE_QUIT;
2056 if (game_status == GAME_MODE_MAIN)
2058 DrawPreviewLevelAnimation();
2065 /* ========================================================================= */
2066 /* info screen functions */
2067 /* ========================================================================= */
2069 static struct TokenInfo *info_info;
2070 static int num_info_info;
2072 static void execInfoTitleScreen()
2074 info_mode = INFO_MODE_TITLE;
2079 static void execInfoElements()
2081 info_mode = INFO_MODE_ELEMENTS;
2086 static void execInfoMusic()
2088 info_mode = INFO_MODE_MUSIC;
2093 static void execInfoCredits()
2095 info_mode = INFO_MODE_CREDITS;
2100 static void execInfoProgram()
2102 info_mode = INFO_MODE_PROGRAM;
2107 static void execInfoVersion()
2109 info_mode = INFO_MODE_VERSION;
2114 static void execInfoLevelSet()
2116 info_mode = INFO_MODE_LEVELSET;
2121 static void execExitInfo()
2123 game_status = GAME_MODE_MAIN;
2125 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2128 static struct TokenInfo info_info_main[] =
2130 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2131 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2132 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2133 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2134 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2135 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2136 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2137 { TYPE_EMPTY, NULL, "" },
2138 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2143 static void DrawCursorAndText_Info(int pos, boolean active)
2145 int xpos = MENU_SCREEN_START_XPOS;
2146 int ypos = MENU_SCREEN_START_YPOS + pos;
2147 int font_nr = FONT_MENU_1;
2150 font_nr = FONT_ACTIVE(font_nr);
2152 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2154 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2155 drawCursor(pos, active);
2158 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2163 CloseDoor(DOOR_CLOSE_2);
2165 /* (needed after displaying title screens which disable auto repeat) */
2166 KeyboardAutoRepeatOn();
2168 FadeSetLeaveScreen();
2175 if (fade_mask == REDRAW_ALL)
2179 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2185 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2187 info_info = info_info_main;
2191 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2193 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2196 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2197 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2198 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2199 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2200 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2201 initCursor(i, IMG_MENU_BUTTON);
2203 DrawCursorAndText_Info(i, FALSE);
2208 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2213 DrawMaskedBorder(fade_mask);
2220 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2222 static int choice_store[MAX_INFO_MODES];
2223 int choice = choice_store[info_mode]; /* always starts with 0 */
2227 if (button == MB_MENU_INITIALIZE)
2229 /* advance to first valid menu entry */
2230 while (choice < num_info_info &&
2231 info_info[choice].type & TYPE_SKIP_ENTRY)
2233 choice_store[info_mode] = choice;
2235 DrawCursorAndText_Info(choice, TRUE);
2239 else if (button == MB_MENU_LEAVE)
2241 for (y = 0; y < num_info_info; y++)
2243 if (info_info[y].type & TYPE_LEAVE_MENU)
2245 void (*menu_callback_function)(void) = info_info[y].value;
2249 menu_callback_function();
2251 break; /* absolutely needed because function changes 'info_info'! */
2258 if (mx || my) /* mouse input */
2260 x = (mx - mSX) / 32;
2261 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2263 else if (dx || dy) /* keyboard input */
2267 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2269 if (info_info[choice].type & menu_navigation_type ||
2270 info_info[choice].type & TYPE_ENTER_SCREEN ||
2271 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2272 info_info[choice].type & TYPE_YES_NO_AUTO)
2273 button = MB_MENU_CHOICE;
2278 /* jump to next non-empty menu entry (up or down) */
2279 while (y > 0 && y < num_info_info - 1 &&
2280 info_info[y].type & TYPE_SKIP_ENTRY)
2284 if (IN_VIS_FIELD(x, y) &&
2285 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2291 PlaySound(SND_MENU_ITEM_ACTIVATING);
2293 DrawCursorAndText_Info(choice, FALSE);
2294 DrawCursorAndText_Info(y, TRUE);
2296 choice = choice_store[info_mode] = y;
2299 else if (!(info_info[y].type & TYPE_GHOSTED))
2301 PlaySound(SND_MENU_ITEM_SELECTING);
2303 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2305 void (*menu_callback_function)(void) = info_info[choice].value;
2307 FadeSetFromType(info_info[y].type);
2309 menu_callback_function();
2315 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2317 int ystart1 = mSY - SY + 100;
2318 int ystart2 = mSY - SY + 150;
2319 int ybottom = mSY - SY + SYSIZE - 20;
2321 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2323 FadeOut(REDRAW_FIELD);
2328 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2329 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2331 DrawTextSCentered(ybottom, FONT_TEXT_4,
2332 "Press any key or button for info menu");
2334 FadeIn(REDRAW_FIELD);
2337 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2339 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2340 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2341 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2342 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2343 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2344 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2345 int ystep = MENU_SCREEN_INFO_YSTEP;
2346 int element, action, direction;
2354 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2355 infoscreen_step[i] = infoscreen_frame[i] = 0;
2360 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2362 DrawTextSCentered(ybottom, FONT_TEXT_4,
2363 "Press any key or button for next page");
2369 while (helpanim_info[j].element != HELPANIM_LIST_END)
2371 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2376 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2385 j += infoscreen_step[i - start];
2387 element = helpanim_info[j].element;
2388 action = helpanim_info[j].action;
2389 direction = helpanim_info[j].direction;
2392 element = EL_UNKNOWN;
2394 if (action != -1 && direction != -1)
2395 graphic = el_act_dir2img(element, action, direction);
2396 else if (action != -1)
2397 graphic = el_act2img(element, action);
2398 else if (direction != -1)
2399 graphic = el_dir2img(element, direction);
2401 graphic = el2img(element);
2403 delay = helpanim_info[j++].delay;
2408 if (infoscreen_frame[i - start] == 0)
2411 infoscreen_frame[i - start] = delay - 1;
2415 sync_frame = delay - infoscreen_frame[i - start];
2416 infoscreen_frame[i - start]--;
2419 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2421 if (!infoscreen_frame[i - start])
2422 infoscreen_step[i - start] = 0;
2426 if (!infoscreen_frame[i - start])
2427 infoscreen_step[i - start]++;
2428 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2434 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2436 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2437 graphic, sync_frame, USE_MASKING);
2440 DrawInfoScreen_HelpText(element, action, direction, i - start);
2445 redraw_mask |= REDRAW_FIELD;
2450 static char *getHelpText(int element, int action, int direction)
2452 char token[MAX_LINE_LEN];
2454 strcpy(token, element_info[element].token_name);
2457 strcat(token, element_action_info[action].suffix);
2459 if (direction != -1)
2460 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2462 return getHashEntry(helptext_info, token);
2465 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2467 int font_nr = FONT_INFO_ELEMENTS;
2468 int font_width = getFontWidth(font_nr);
2469 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2470 int sy = mSY + 65 + 2 * 32 + 1;
2471 int ystep = TILEY + 4;
2472 int pad_x = sx - SX;
2473 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2474 int max_lines_per_text = 2;
2477 if (action != -1 && direction != -1) /* element.action.direction */
2478 text = getHelpText(element, action, direction);
2480 if (text == NULL && action != -1) /* element.action */
2481 text = getHelpText(element, action, -1);
2483 if (text == NULL && direction != -1) /* element.direction */
2484 text = getHelpText(element, -1, direction);
2486 if (text == NULL) /* base element */
2487 text = getHelpText(element, -1, -1);
2489 if (text == NULL) /* not found */
2490 text = "No description available";
2492 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2493 sy += getFontHeight(font_nr) / 2;
2495 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2496 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2497 TRUE, FALSE, FALSE);
2500 void DrawInfoScreen_TitleScreen()
2505 void HandleInfoScreen_TitleScreen(int button)
2507 HandleTitleScreen(0, 0, 0, 0, button);
2510 void DrawInfoScreen_Elements()
2512 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2514 FadeOut(REDRAW_FIELD);
2519 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2521 FadeIn(REDRAW_FIELD);
2526 void HandleInfoScreen_Elements(int button)
2528 static unsigned int info_delay = 0;
2529 static int num_anims;
2530 static int num_pages;
2532 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2535 if (button == MB_MENU_INITIALIZE)
2537 boolean new_element = TRUE;
2541 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2543 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2545 else if (new_element)
2548 new_element = FALSE;
2552 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2556 if (button == MB_MENU_LEAVE)
2558 PlaySound(SND_MENU_ITEM_SELECTING);
2560 info_mode = INFO_MODE_MAIN;
2565 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2567 if (button != MB_MENU_INITIALIZE)
2569 PlaySound(SND_MENU_ITEM_SELECTING);
2574 if (page >= num_pages)
2576 FadeSoundsAndMusic();
2578 info_mode = INFO_MODE_MAIN;
2579 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2586 FadeSetNextScreen();
2589 if (button != MB_MENU_INITIALIZE)
2590 FadeOut(REDRAW_FIELD);
2592 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2594 if (button != MB_MENU_INITIALIZE)
2595 FadeIn(REDRAW_FIELD);
2599 if (DelayReached(&info_delay, GameFrameDelay))
2600 if (page < num_pages)
2601 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2603 PlayMenuSoundIfLoop();
2607 void DrawInfoScreen_Music()
2609 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2612 FadeOut(REDRAW_FIELD);
2620 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2623 FadeIn(REDRAW_FIELD);
2627 void HandleInfoScreen_Music(int button)
2629 static struct MusicFileInfo *list = NULL;
2630 int ystart1 = mSY - SY + 100;
2631 int ystart2 = mSY - SY + 150;
2632 int ybottom = mSY - SY + SYSIZE - 20;
2635 if (button == MB_MENU_INITIALIZE)
2637 list = music_file_info;
2641 FadeSoundsAndMusic();
2646 DrawTextSCentered(ystart1, FONT_TEXT_1,
2647 "No music info for this level set.");
2649 DrawTextSCentered(ybottom, FONT_TEXT_4,
2650 "Press any key or button for info menu");
2656 if (button == MB_MENU_LEAVE)
2658 PlaySound(SND_MENU_ITEM_SELECTING);
2660 FadeSoundsAndMusic();
2662 info_mode = INFO_MODE_MAIN;
2667 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2671 if (button != MB_MENU_INITIALIZE)
2673 PlaySound(SND_MENU_ITEM_SELECTING);
2681 FadeSoundsAndMusic();
2683 info_mode = INFO_MODE_MAIN;
2684 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2689 FadeSoundsAndMusic();
2692 if (list != music_file_info)
2693 FadeSetNextScreen();
2696 if (button != MB_MENU_INITIALIZE)
2697 FadeOut(REDRAW_FIELD);
2704 int sound = list->music;
2706 if (sound_info[sound].loop)
2707 PlaySoundLoop(sound);
2711 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2715 PlayMusic(list->music);
2717 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2720 if (!strEqual(list->title, UNKNOWN_NAME))
2722 if (!strEqual(list->title_header, UNKNOWN_NAME))
2723 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2725 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2728 if (!strEqual(list->artist, UNKNOWN_NAME))
2730 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2731 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2733 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2735 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2738 if (!strEqual(list->album, UNKNOWN_NAME))
2740 if (!strEqual(list->album_header, UNKNOWN_NAME))
2741 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2743 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2745 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2748 if (!strEqual(list->year, UNKNOWN_NAME))
2750 if (!strEqual(list->year_header, UNKNOWN_NAME))
2751 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2753 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2755 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2758 DrawTextSCentered(ybottom, FONT_TEXT_4,
2759 "Press any key or button for next page");
2761 if (button != MB_MENU_INITIALIZE)
2762 FadeIn(REDRAW_FIELD);
2765 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2766 PlaySoundLoop(list->music);
2769 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2771 int ystart1 = mSY - SY + 100;
2772 int ystart2 = mSY - SY + 150;
2773 int ybottom = mSY - SY + SYSIZE - 20;
2779 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2783 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2784 "Special thanks to");
2785 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2787 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2789 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2790 "\"Boulder Dash\"");
2791 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2793 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2795 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2797 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2798 "First Star Software");
2800 else if (screen_nr == 1)
2802 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2803 "Special thanks to");
2804 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2805 "Klaus Heinz & Volker Wertich");
2806 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2808 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2809 "\"Emerald Mine\"");
2810 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2812 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2814 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2816 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2819 else if (screen_nr == 2)
2821 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2822 "Special thanks to");
2823 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2824 "Michael Stopp & Philip Jespersen");
2825 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2827 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2829 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2831 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2833 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2835 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2836 "Digital Integration");
2838 else if (screen_nr == 3)
2840 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2841 "Special thanks to");
2842 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2843 "Hiroyuki Imabayashi");
2844 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2846 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2848 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2850 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2852 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2854 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2857 else if (screen_nr == 4)
2859 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2860 "Special thanks to");
2861 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2863 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2865 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2866 "Jürgen Bonhagen");
2867 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2868 "for the continuous creation");
2869 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2870 "of outstanding level sets");
2872 else if (screen_nr == 5)
2874 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2876 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2878 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2879 "for ideas and inspiration by");
2880 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2883 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2885 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2887 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2888 "for ideas and inspiration by");
2889 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2892 else if (screen_nr == 6)
2894 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2896 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2899 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2900 "for the code base used for the");
2901 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2902 "native Emerald Mine engine");
2904 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2905 "for the new Emerald Mine engine");
2908 else if (screen_nr == 7)
2910 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2912 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2914 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2915 "for the initial DOS port");
2917 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2919 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2921 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2922 "for some additional toons");
2924 else if (screen_nr == 8)
2926 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2927 "And not to forget:");
2928 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2930 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2931 "All those who contributed");
2932 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2933 "levels to this game");
2934 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2938 DrawTextSCentered(ybottom, FONT_TEXT_4,
2939 "Press any key or button for next page");
2942 void DrawInfoScreen_Credits()
2944 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2946 FadeSoundsAndMusic();
2949 FadeOut(REDRAW_FIELD);
2952 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2955 FadeIn(REDRAW_FIELD);
2959 void HandleInfoScreen_Credits(int button)
2961 static int screen_nr = 0;
2962 int num_screens = 9;
2964 if (button == MB_MENU_INITIALIZE)
2968 // DrawInfoScreen_CreditsScreen(screen_nr);
2971 if (button == MB_MENU_LEAVE)
2973 PlaySound(SND_MENU_ITEM_SELECTING);
2975 info_mode = INFO_MODE_MAIN;
2980 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2982 if (button != MB_MENU_INITIALIZE)
2984 PlaySound(SND_MENU_ITEM_SELECTING);
2989 if (screen_nr >= num_screens)
2991 FadeSoundsAndMusic();
2993 info_mode = INFO_MODE_MAIN;
2994 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3001 FadeSetNextScreen();
3004 if (button != MB_MENU_INITIALIZE)
3005 FadeOut(REDRAW_FIELD);
3007 DrawInfoScreen_CreditsScreen(screen_nr);
3009 if (button != MB_MENU_INITIALIZE)
3010 FadeIn(REDRAW_FIELD);
3014 PlayMenuSoundIfLoop();
3018 void DrawInfoScreen_Program()
3020 int ystart1 = mSY - SY + 100;
3021 int ystart2 = mSY - SY + 150;
3022 int ybottom = mSY - SY + SYSIZE - 20;
3025 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3028 FadeOut(REDRAW_FIELD);
3034 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3036 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3037 "This game is Freeware!");
3038 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3039 "If you like it, send e-mail to:");
3040 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3041 PROGRAM_EMAIL_STRING);
3043 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3044 "More information and levels:");
3045 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3046 PROGRAM_WEBSITE_STRING);
3047 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3048 "If you have created new levels,");
3049 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3050 "send them to me to include them!");
3051 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3054 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3055 "or SnailMail to:");
3056 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3058 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3059 "Detmolder Strasse 189");
3060 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3062 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3064 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3065 "More information and levels:");
3066 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3067 PROGRAM_WEBSITE_STRING);
3068 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3069 "If you have created new levels,");
3070 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3071 "send them to me to include them!");
3072 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3076 DrawTextSCentered(ybottom, FONT_TEXT_4,
3077 "Press any key or button for info menu");
3080 FadeIn(REDRAW_FIELD);
3084 void HandleInfoScreen_Program(int button)
3086 if (button == MB_MENU_LEAVE)
3088 PlaySound(SND_MENU_ITEM_SELECTING);
3090 info_mode = INFO_MODE_MAIN;
3095 else if (button == MB_MENU_CHOICE)
3097 PlaySound(SND_MENU_ITEM_SELECTING);
3099 FadeSoundsAndMusic();
3102 FadeOut(REDRAW_FIELD);
3105 info_mode = INFO_MODE_MAIN;
3106 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3110 PlayMenuSoundIfLoop();
3114 void DrawInfoScreen_Version()
3116 int font_header = FONT_TEXT_3;
3117 int font_text = FONT_TEXT_2;
3118 int xstep = getFontWidth(font_text);
3119 int ystep = getFontHeight(font_text);
3120 int ystart1 = mSY - SY + 100;
3121 int ystart2 = mSY - SY + 150;
3122 int ybottom = mSY - SY + SYSIZE - 20;
3123 int xstart1 = mSX - SX + 2 * xstep;
3124 int xstart2 = mSX - SX + 18 * xstep;
3125 #if defined(TARGET_SDL)
3126 int xstart3 = mSX - SX + 28 * xstep;
3127 SDL_version sdl_version_compiled;
3128 const SDL_version *sdl_version_linked;
3129 int driver_name_len = 10;
3130 #if defined(TARGET_SDL2)
3131 SDL_version sdl_version_linked_ext;
3132 const char *driver_name = NULL;
3134 char driver_name[driver_name_len];
3138 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3141 FadeOut(REDRAW_FIELD);
3147 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3149 DrawTextF(xstart1, ystart2, font_header, "Name");
3150 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3153 DrawTextF(xstart1, ystart2, font_header, "Version");
3154 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3157 DrawTextF(xstart1, ystart2, font_header, "Platform");
3158 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3161 DrawTextF(xstart1, ystart2, font_header, "Target");
3162 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3165 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3166 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3168 #if defined(TARGET_SDL)
3169 ystart2 += 3 * ystep;
3170 DrawTextF(xstart1, ystart2, font_header, "Library");
3171 DrawTextF(xstart2, ystart2, font_header, "compiled");
3172 DrawTextF(xstart3, ystart2, font_header, "linked");
3174 SDL_VERSION(&sdl_version_compiled);
3175 #if defined(TARGET_SDL2)
3176 SDL_GetVersion(&sdl_version_linked_ext);
3177 sdl_version_linked = &sdl_version_linked_ext;
3179 sdl_version_linked = SDL_Linked_Version();
3182 ystart2 += 2 * ystep;
3183 DrawTextF(xstart1, ystart2, font_text, "SDL");
3184 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3185 sdl_version_compiled.major,
3186 sdl_version_compiled.minor,
3187 sdl_version_compiled.patch);
3188 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3189 sdl_version_linked->major,
3190 sdl_version_linked->minor,
3191 sdl_version_linked->patch);
3193 SDL_IMAGE_VERSION(&sdl_version_compiled);
3194 sdl_version_linked = IMG_Linked_Version();
3197 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3198 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3199 sdl_version_compiled.major,
3200 sdl_version_compiled.minor,
3201 sdl_version_compiled.patch);
3202 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3203 sdl_version_linked->major,
3204 sdl_version_linked->minor,
3205 sdl_version_linked->patch);
3207 SDL_MIXER_VERSION(&sdl_version_compiled);
3208 sdl_version_linked = Mix_Linked_Version();
3211 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3212 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3213 sdl_version_compiled.major,
3214 sdl_version_compiled.minor,
3215 sdl_version_compiled.patch);
3216 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3217 sdl_version_linked->major,
3218 sdl_version_linked->minor,
3219 sdl_version_linked->patch);
3221 SDL_NET_VERSION(&sdl_version_compiled);
3222 sdl_version_linked = SDLNet_Linked_Version();
3225 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3226 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3227 sdl_version_compiled.major,
3228 sdl_version_compiled.minor,
3229 sdl_version_compiled.patch);
3230 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3231 sdl_version_linked->major,
3232 sdl_version_linked->minor,
3233 sdl_version_linked->patch);
3235 ystart2 += 3 * ystep;
3236 DrawTextF(xstart1, ystart2, font_header, "Driver");
3237 DrawTextF(xstart2, ystart2, font_header, "Requested");
3238 DrawTextF(xstart3, ystart2, font_header, "Used");
3240 #if defined(TARGET_SDL2)
3241 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3243 SDL_VideoDriverName(driver_name, driver_name_len);
3246 ystart2 += 2 * ystep;
3247 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3248 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3249 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3251 #if defined(TARGET_SDL2)
3252 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3254 SDL_AudioDriverName(driver_name, driver_name_len);
3258 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3259 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3260 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3263 DrawTextSCentered(ybottom, FONT_TEXT_4,
3264 "Press any key or button for info menu");
3267 FadeIn(REDRAW_FIELD);
3271 void HandleInfoScreen_Version(int button)
3273 if (button == MB_MENU_LEAVE)
3275 PlaySound(SND_MENU_ITEM_SELECTING);
3277 info_mode = INFO_MODE_MAIN;
3282 else if (button == MB_MENU_CHOICE)
3284 PlaySound(SND_MENU_ITEM_SELECTING);
3286 FadeSoundsAndMusic();
3289 FadeOut(REDRAW_FIELD);
3292 info_mode = INFO_MODE_MAIN;
3293 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3297 PlayMenuSoundIfLoop();
3301 void DrawInfoScreen_LevelSet()
3303 struct TitleMessageInfo *tmi = &readme;
3304 char *filename = getLevelSetInfoFilename();
3306 /* if chars set to "-1", automatically determine by text and font width */
3307 if (tmi->chars == -1)
3308 tmi->chars = tmi->width / getFontWidth(tmi->font);
3310 tmi->width = tmi->chars * getFontWidth(tmi->font);
3312 /* if lines set to "-1", automatically determine by text and font height */
3313 if (tmi->lines == -1)
3314 tmi->lines = tmi->height / getFontHeight(tmi->font);
3316 tmi->height = tmi->lines * getFontHeight(tmi->font);
3318 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3321 FadeOut(REDRAW_FIELD);
3327 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3329 if (filename != NULL)
3330 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3331 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3332 tmi->autowrap, tmi->centered, tmi->parse_comments);
3334 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3335 "No information for this level set.");
3337 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3338 "Press any key or button for info menu");
3341 FadeIn(REDRAW_FIELD);
3345 void HandleInfoScreen_LevelSet(int button)
3347 if (button == MB_MENU_LEAVE)
3349 PlaySound(SND_MENU_ITEM_SELECTING);
3351 info_mode = INFO_MODE_MAIN;
3356 else if (button == MB_MENU_CHOICE)
3358 PlaySound(SND_MENU_ITEM_SELECTING);
3360 FadeSoundsAndMusic();
3363 FadeOut(REDRAW_FIELD);
3366 info_mode = INFO_MODE_MAIN;
3367 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3371 PlayMenuSoundIfLoop();
3375 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3377 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3379 if (info_mode == INFO_MODE_TITLE)
3380 DrawInfoScreen_TitleScreen();
3381 else if (info_mode == INFO_MODE_ELEMENTS)
3382 DrawInfoScreen_Elements();
3383 else if (info_mode == INFO_MODE_MUSIC)
3384 DrawInfoScreen_Music();
3385 else if (info_mode == INFO_MODE_CREDITS)
3386 DrawInfoScreen_Credits();
3387 else if (info_mode == INFO_MODE_PROGRAM)
3388 DrawInfoScreen_Program();
3389 else if (info_mode == INFO_MODE_VERSION)
3390 DrawInfoScreen_Version();
3391 else if (info_mode == INFO_MODE_LEVELSET)
3392 DrawInfoScreen_LevelSet();
3394 DrawInfoScreen_Main(fade_mask, do_fading);
3396 if (info_mode != INFO_MODE_MAIN &&
3397 info_mode != INFO_MODE_TITLE &&
3398 info_mode != INFO_MODE_MUSIC)
3405 void DrawAndFadeInInfoScreen(int fade_mask)
3407 DrawInfoScreenExt(fade_mask, TRUE);
3410 void DrawInfoScreen()
3412 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3415 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3417 if (info_mode == INFO_MODE_TITLE)
3418 HandleInfoScreen_TitleScreen(button);
3419 else if (info_mode == INFO_MODE_ELEMENTS)
3420 HandleInfoScreen_Elements(button);
3421 else if (info_mode == INFO_MODE_MUSIC)
3422 HandleInfoScreen_Music(button);
3423 else if (info_mode == INFO_MODE_CREDITS)
3424 HandleInfoScreen_Credits(button);
3425 else if (info_mode == INFO_MODE_PROGRAM)
3426 HandleInfoScreen_Program(button);
3427 else if (info_mode == INFO_MODE_VERSION)
3428 HandleInfoScreen_Version(button);
3429 else if (info_mode == INFO_MODE_LEVELSET)
3430 HandleInfoScreen_LevelSet(button);
3432 HandleInfoScreen_Main(mx, my, dx, dy, button);
3440 /* ========================================================================= */
3441 /* type name functions */
3442 /* ========================================================================= */
3444 void HandleTypeName(int newxpos, Key key)
3446 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3447 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3448 struct TextPosInfo *pos = mci->pos_input;
3449 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3450 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3451 static int xpos = 0;
3452 int font_nr = pos->font;
3453 int font_active_nr = FONT_ACTIVE(font_nr);
3454 int font_width = getFontWidth(font_active_nr);
3455 char key_char = getValidConfigValueChar(getCharFromKey(key));
3456 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3457 boolean is_active = TRUE;
3459 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3463 strcpy(last_player_name, setup.player_name);
3467 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3469 setup.player_name[xpos] = key_char;
3470 setup.player_name[xpos + 1] = 0;
3474 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3478 setup.player_name[xpos] = 0;
3480 else if (key == KSYM_Return && xpos > 0)
3486 game_status = GAME_MODE_MAIN;
3488 else if (key == KSYM_Escape)
3490 strcpy(setup.player_name, last_player_name);
3494 game_status = GAME_MODE_MAIN;
3499 pos->width = (strlen(setup.player_name) + 1) * font_width;
3500 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3502 DrawText(startx, starty, setup.player_name, font_active_nr);
3503 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3507 pos->width = strlen(setup.player_name) * font_width;
3508 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3510 DrawText(startx, starty, setup.player_name, font_nr);
3515 /* ========================================================================= */
3516 /* tree menu functions */
3517 /* ========================================================================= */
3519 static void DrawChooseTree(TreeInfo **ti_ptr)
3523 FreeScreenGadgets();
3524 CreateScreenGadgets();
3526 CloseDoor(DOOR_CLOSE_2);
3529 FadeOut(REDRAW_FIELD);
3534 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3535 MapScreenTreeGadgets(*ti_ptr);
3538 FadeIn(REDRAW_FIELD);
3544 static void AdjustScrollbar(int id, int items_max, int items_visible,
3547 struct GadgetInfo *gi = screen_gadget[id];
3549 if (item_position > items_max - items_visible)
3550 item_position = items_max - items_visible;
3552 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3553 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3554 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3557 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3560 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3563 struct GadgetInfo *gi = screen_gadget[id];
3564 int items_max, items_visible, item_position;
3566 items_max = numTreeInfoInGroup(ti);
3567 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3568 item_position = first_entry;
3570 if (item_position > items_max - items_visible)
3571 item_position = items_max - items_visible;
3573 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3574 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3575 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3579 static void drawChooseTreeList(int first_entry, int num_page_entries,
3583 char *title_string = NULL;
3584 int yoffset_sets = MENU_TITLE1_YPOS;
3585 int yoffset_setup = 16;
3586 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3587 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3588 int last_game_status = game_status; /* save current game status */
3590 title_string = ti->infotext;
3592 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3595 /* force LEVELS font on artwork setup screen */
3596 game_status = GAME_MODE_LEVELS;
3600 /* clear tree list area, but not title or scrollbar */
3601 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3602 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3603 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3605 /* clear tree list area, but not title or scrollbar */
3606 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3607 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3608 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3611 for (i = 0; i < num_page_entries; i++)
3613 TreeInfo *node, *node_first;
3614 int entry_pos = first_entry + i;
3615 int xpos = MENU_SCREEN_START_XPOS;
3616 int ypos = MENU_SCREEN_START_YPOS + i;
3617 int startx = mSX + xpos * 32;
3618 int starty = mSY + ypos * 32;
3619 int font_nr = FONT_TEXT_1;
3620 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3621 int startx_text = startx + font_xoffset;
3622 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3623 int text_size = startx_scrollbar - startx_text;
3624 int max_buffer_len = text_size / getFontWidth(font_nr);
3625 char buffer[max_buffer_len + 1];
3627 node_first = getTreeInfoFirstGroupEntry(ti);
3628 node = getTreeInfoFromPos(node_first, entry_pos);
3630 strncpy(buffer, node->name, max_buffer_len);
3631 buffer[max_buffer_len] = '\0';
3633 DrawText(startx, starty, buffer, font_nr + node->color);
3635 if (node->parent_link)
3636 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3637 else if (node->level_group)
3638 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3640 initCursor(i, IMG_MENU_BUTTON);
3643 game_status = last_game_status; /* restore current game status */
3645 redraw_mask |= REDRAW_FIELD;
3648 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3650 TreeInfo *node, *node_first;
3651 int x, last_redraw_mask = redraw_mask;
3652 int ypos = MENU_TITLE2_YPOS;
3653 int font_nr = FONT_TITLE_2;
3655 if (ti->type == TREE_TYPE_LEVEL_NR)
3656 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3658 if (ti->type != TREE_TYPE_LEVEL_DIR)
3661 node_first = getTreeInfoFirstGroupEntry(ti);
3662 node = getTreeInfoFromPos(node_first, entry_pos);
3664 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3667 if (node->parent_link)
3668 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3669 node->node_parent->name);
3670 else if (node->level_group)
3671 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3673 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3674 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3675 node->levels, (node->levels > 1 ? "levels" : "level"),
3678 if (node->parent_link)
3679 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3681 else if (node->level_group)
3682 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3684 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3685 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3686 node->levels, node->class_desc);
3689 /* let BackToFront() redraw only what is needed */
3690 redraw_mask = last_redraw_mask | REDRAW_TILES;
3691 for (x = 0; x < SCR_FIELDX; x++)
3692 MarkTileDirty(x, 1);
3695 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3698 TreeInfo *ti = *ti_ptr;
3700 int y = ti->cl_cursor;
3701 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3702 int num_entries = numTreeInfoInGroup(ti);
3703 int num_page_entries;
3704 int last_game_status = game_status; /* save current game status */
3705 boolean position_set_by_scrollbar = (dx == 999);
3708 /* force LEVELS draw offset on choose level and artwork setup screen */
3709 game_status = GAME_MODE_LEVELS;
3712 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3713 num_page_entries = num_entries;
3715 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3717 game_status = last_game_status; /* restore current game status */
3719 if (button == MB_MENU_INITIALIZE)
3721 int num_entries = numTreeInfoInGroup(ti);
3722 int entry_pos = posTreeInfo(ti);
3724 if (ti->cl_first == -1)
3726 /* only on initialization */
3727 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3728 ti->cl_cursor = entry_pos - ti->cl_first;
3730 else if (ti->cl_cursor >= num_page_entries ||
3731 (num_entries > num_page_entries &&
3732 num_entries - ti->cl_first < num_page_entries))
3734 /* only after change of list size (by custom graphic configuration) */
3735 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3736 ti->cl_cursor = entry_pos - ti->cl_first;
3739 if (position_set_by_scrollbar)
3742 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3745 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3746 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3747 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3751 else if (button == MB_MENU_LEAVE)
3755 PlaySound(SND_MENU_ITEM_SELECTING);
3757 if (ti->node_parent)
3759 *ti_ptr = ti->node_parent;
3760 DrawChooseTree(ti_ptr);
3762 else if (game_status == GAME_MODE_SETUP)
3764 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3765 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3767 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3768 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3769 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3770 execSetupGraphics();
3771 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3772 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3773 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3775 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3776 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3777 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3784 if (game_status == GAME_MODE_LEVELNR)
3785 level_nr = atoi(level_number_current->identifier);
3787 game_status = GAME_MODE_MAIN;
3789 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3795 if (mx || my) /* mouse input */
3797 int last_game_status = game_status; /* save current game status */
3800 /* force LEVELS draw offset on artwork setup screen */
3801 game_status = GAME_MODE_LEVELS;
3804 x = (mx - mSX) / 32;
3805 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3807 game_status = last_game_status; /* restore current game status */
3809 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3811 /* move cursor instead of scrolling when already at start/end of list */
3812 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3814 else if (dy == +1 * SCROLL_LINE &&
3815 ti->cl_first + num_page_entries == num_entries)
3818 /* handle scrolling screen one line or page */
3819 if (ti->cl_cursor + dy < 0 ||
3820 ti->cl_cursor + dy > num_page_entries - 1)
3823 boolean redraw = FALSE;
3825 if (ABS(dy) == SCROLL_PAGE)
3826 step = num_page_entries - 1;
3828 if (dy < 0 && ti->cl_first > 0)
3830 /* scroll page/line up */
3832 ti->cl_first -= step;
3833 if (ti->cl_first < 0)
3838 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3840 /* scroll page/line down */
3842 ti->cl_first += step;
3843 if (ti->cl_first + num_page_entries > num_entries)
3844 ti->cl_first = MAX(0, num_entries - num_page_entries);
3851 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3852 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3853 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3855 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3861 if (ABS(dy) == SCROLL_PAGE)
3862 step = num_page_entries - 1;
3864 if (dy < 0 && ti->cl_first > 0)
3866 /* scroll page/line up */
3868 ti->cl_first -= step;
3869 if (ti->cl_first < 0)
3872 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3873 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3874 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3876 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3879 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3881 /* scroll page/line down */
3883 ti->cl_first += step;
3884 if (ti->cl_first + num_page_entries > num_entries)
3885 ti->cl_first = MAX(0, num_entries - num_page_entries);
3887 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3888 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3889 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3891 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3899 /* handle moving cursor one line */
3900 y = ti->cl_cursor + dy;
3905 TreeInfo *node_first, *node_cursor;
3906 int entry_pos = ti->cl_first + y;
3908 node_first = getTreeInfoFirstGroupEntry(ti);
3909 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3911 if (node_cursor->node_group)
3915 PlaySound(SND_MENU_ITEM_SELECTING);
3917 node_cursor->cl_first = ti->cl_first;
3918 node_cursor->cl_cursor = ti->cl_cursor;
3919 *ti_ptr = node_cursor->node_group;
3920 DrawChooseTree(ti_ptr);
3925 else if (dx == -1 && ti->node_parent)
3929 PlaySound(SND_MENU_ITEM_SELECTING);
3931 *ti_ptr = ti->node_parent;
3932 DrawChooseTree(ti_ptr);
3937 if (!anyScrollbarGadgetActive() &&
3938 IN_VIS_FIELD(x, y) &&
3939 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3940 y >= 0 && y < num_page_entries)
3943 printf("::: TEST/HandleChooseTree [%d, %d, %d, %d]\n", Counter(),
3944 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
3949 if (y != ti->cl_cursor)
3951 PlaySound(SND_MENU_ITEM_ACTIVATING);
3953 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3954 drawChooseTreeCursor(y, TRUE);
3955 drawChooseTreeInfo(ti->cl_first + y, ti);
3962 TreeInfo *node_first, *node_cursor;
3963 int entry_pos = ti->cl_first + y;
3965 PlaySound(SND_MENU_ITEM_SELECTING);
3967 node_first = getTreeInfoFirstGroupEntry(ti);
3968 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3970 if (node_cursor->node_group)
3974 node_cursor->cl_first = ti->cl_first;
3975 node_cursor->cl_cursor = ti->cl_cursor;
3976 *ti_ptr = node_cursor->node_group;
3977 DrawChooseTree(ti_ptr);
3979 else if (node_cursor->parent_link)
3983 *ti_ptr = node_cursor->node_parent;
3984 DrawChooseTree(ti_ptr);
3991 FadeSetEnterScreen();
3994 node_cursor->cl_first = ti->cl_first;
3995 node_cursor->cl_cursor = ti->cl_cursor;
3996 *ti_ptr = node_cursor;
3998 if (ti->type == TREE_TYPE_LEVEL_DIR)
4000 LoadLevelSetup_SeriesInfo();
4002 SaveLevelSetup_LastSeries();
4003 SaveLevelSetup_SeriesInfo();
4007 if (game_status == GAME_MODE_SETUP)
4009 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4010 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4012 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4013 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4014 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4015 execSetupGraphics();
4016 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4017 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4018 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4020 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4021 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4022 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4029 if (game_status == GAME_MODE_LEVELNR)
4030 level_nr = atoi(level_number_current->identifier);
4032 game_status = GAME_MODE_MAIN;
4041 void DrawChooseLevelSet()
4043 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4045 DrawChooseTree(&leveldir_current);
4051 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4053 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4060 void DrawChooseLevelNr()
4064 if (level_number != NULL)
4066 freeTreeInfo(level_number);
4068 level_number = NULL;
4071 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4073 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4074 char identifier[32], name[32];
4077 /* temporarily load level info to get level name */
4078 LoadLevelInfoOnly(i);
4080 ti->node_top = &level_number;
4081 ti->sort_priority = 10000 + value;
4082 ti->color = (level.no_valid_file ? FC_BLUE :
4083 LevelStats_getSolved(i) ? FC_GREEN :
4084 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4086 sprintf(identifier, "%d", value);
4087 sprintf(name, "%03d: %s", value,
4088 (level.no_valid_file ? "(no file)" : level.name));
4090 setString(&ti->identifier, identifier);
4091 setString(&ti->name, name);
4092 setString(&ti->name_sorting, name);
4094 pushTreeInfo(&level_number, ti);
4097 /* sort level number values to start with lowest level number */
4098 sortTreeInfo(&level_number);
4100 /* set current level number to current level number */
4101 level_number_current =
4102 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4104 /* if that also fails, set current level number to first available level */
4105 if (level_number_current == NULL)
4106 level_number_current = level_number;
4108 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4111 DrawChooseTree(&level_number_current);
4113 DrawChooseTree(&leveldir_current);
4120 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4123 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4125 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4133 void DrawHallOfFame(int highlight_position)
4136 FadeSoundsAndMusic();
4138 /* (this is needed when called from GameEnd() after winning a game) */
4139 KeyboardAutoRepeatOn();
4142 /* (this is needed when called from GameEnd() after winning a game) */
4143 SetDrawDeactivationMask(REDRAW_NONE);
4144 SetDrawBackgroundMask(REDRAW_FIELD);
4146 CloseDoor(DOOR_CLOSE_2);
4148 if (highlight_position < 0)
4149 LoadScore(level_nr);
4151 FadeSetEnterScreen();
4153 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4156 FadeOut(REDRAW_FIELD);
4164 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4167 FadeIn(REDRAW_FIELD);
4171 static void drawHallOfFameList(int first_entry, int highlight_position)
4175 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4178 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4179 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4180 "HighScores of Level %d", level_nr);
4182 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4184 int entry = first_entry + i;
4185 boolean active = (entry == highlight_position);
4186 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4187 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4188 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4189 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4190 int dx1 = 3 * getFontWidth(font_nr1);
4191 int dx2 = dx1 + getFontWidth(font_nr1);
4193 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
4194 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4196 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4198 int sy = mSY + 64 + i * 32;
4200 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4201 DrawText(mSX + dx1, sy, ".", font_nr1);
4203 for (j = 0; j < num_dots; j++)
4204 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4206 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4209 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4210 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4212 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4215 redraw_mask |= REDRAW_FIELD;
4218 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4220 static int first_entry = 0;
4221 static int highlight_position = 0;
4222 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4224 if (button == MB_MENU_INITIALIZE)
4227 highlight_position = mx;
4228 drawHallOfFameList(first_entry, highlight_position);
4233 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4234 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4238 if (first_entry > 0)
4240 first_entry -= step;
4241 if (first_entry < 0)
4244 drawHallOfFameList(first_entry, highlight_position);
4249 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4251 first_entry += step;
4252 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4253 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4255 drawHallOfFameList(first_entry, highlight_position);
4258 else if (button == MB_MENU_LEAVE)
4260 PlaySound(SND_MENU_ITEM_SELECTING);
4262 FadeSound(SND_BACKGROUND_SCORES);
4264 game_status = GAME_MODE_MAIN;
4268 else if (button == MB_MENU_CHOICE)
4270 PlaySound(SND_MENU_ITEM_SELECTING);
4272 FadeSound(SND_BACKGROUND_SCORES);
4275 FadeOut(REDRAW_FIELD);
4278 game_status = GAME_MODE_MAIN;
4280 DrawAndFadeInMainMenu(REDRAW_FIELD);
4283 if (game_status == GAME_MODE_SCORES)
4284 PlayMenuSoundIfLoop();
4292 /* ========================================================================= */
4293 /* setup screen functions */
4294 /* ========================================================================= */
4296 static struct TokenInfo *setup_info;
4297 static int num_setup_info; /* number of setup entries shown on screen */
4298 static int max_setup_info; /* total number of setup entries in list */
4300 static char *screen_mode_text;
4301 static char *window_size_text;
4302 static char *scaling_type_text;
4303 static char *scroll_delay_text;
4304 static char *game_speed_text;
4305 static char *graphics_set_name;
4306 static char *sounds_set_name;
4307 static char *music_set_name;
4308 static char *volume_simple_text;
4309 static char *volume_loops_text;
4310 static char *volume_music_text;
4311 static char *touch_controls_text;
4312 static char *move_distance_text;
4313 static char *drop_distance_text;
4315 static void execSetupMain()
4317 setup_mode = SETUP_MODE_MAIN;
4322 static void execSetupGame_setGameSpeeds()
4324 if (game_speeds == NULL)
4328 for (i = 0; game_speeds_list[i].value != -1; i++)
4330 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4331 char identifier[32], name[32];
4332 int value = game_speeds_list[i].value;
4333 char *text = game_speeds_list[i].text;
4335 ti->node_top = &game_speeds;
4336 ti->sort_priority = 10000 - value;
4338 sprintf(identifier, "%d", value);
4339 sprintf(name, "%s", text);
4341 setString(&ti->identifier, identifier);
4342 setString(&ti->name, name);
4343 setString(&ti->name_sorting, name);
4344 setString(&ti->infotext, "Game Speed");
4346 pushTreeInfo(&game_speeds, ti);
4349 /* sort game speed values to start with slowest game speed */
4350 sortTreeInfo(&game_speeds);
4352 /* set current game speed to configured game speed value */
4353 game_speed_current =
4354 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4356 /* if that fails, set current game speed to reliable default value */
4357 if (game_speed_current == NULL)
4358 game_speed_current =
4359 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4361 /* if that also fails, set current game speed to first available speed */
4362 if (game_speed_current == NULL)
4363 game_speed_current = game_speeds;
4366 setup.game_frame_delay = atoi(game_speed_current->identifier);
4368 /* needed for displaying game speed text instead of identifier */
4369 game_speed_text = game_speed_current->name;
4372 static void execSetupGame_setScrollDelays()
4374 if (scroll_delays == NULL)
4378 for (i = 0; scroll_delays_list[i].value != -1; i++)
4380 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4381 char identifier[32], name[32];
4382 int value = scroll_delays_list[i].value;
4383 char *text = scroll_delays_list[i].text;
4385 ti->node_top = &scroll_delays;
4386 ti->sort_priority = value;
4388 sprintf(identifier, "%d", value);
4389 sprintf(name, "%s", text);
4391 setString(&ti->identifier, identifier);
4392 setString(&ti->name, name);
4393 setString(&ti->name_sorting, name);
4394 setString(&ti->infotext, "Scaling Type");
4396 pushTreeInfo(&scroll_delays, ti);
4399 /* sort scaling type values to start with lowest scaling type value */
4400 sortTreeInfo(&scroll_delays);
4402 /* set current scaling type value to configured scaling type value */
4403 scroll_delay_current =
4404 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4406 /* if that fails, set current scaling type to reliable default value */
4407 if (scroll_delay_current == NULL)
4408 scroll_delay_current =
4409 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4411 /* if that also fails, set current scaling type to first available value */
4412 if (scroll_delay_current == NULL)
4413 scroll_delay_current = scroll_delays;
4416 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4418 /* needed for displaying scaling type text instead of identifier */
4419 scroll_delay_text = scroll_delay_current->name;
4422 static void execSetupGame()
4424 execSetupGame_setGameSpeeds();
4425 execSetupGame_setScrollDelays();
4427 setup_mode = SETUP_MODE_GAME;
4432 static void execSetupChooseGameSpeed()
4434 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4439 static void execSetupChooseScrollDelay()
4441 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4446 static void execSetupEditor()
4448 setup_mode = SETUP_MODE_EDITOR;
4453 static void execSetupGraphics_setWindowSizes(boolean update_list)
4455 if (window_sizes != NULL && update_list)
4457 freeTreeInfo(window_sizes);
4459 window_sizes = NULL;
4462 if (window_sizes == NULL)
4464 boolean current_window_size_found = FALSE;
4467 for (i = 0; window_sizes_list[i].value != -1; i++)
4469 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4470 char identifier[32], name[32];
4471 int value = window_sizes_list[i].value;
4472 char *text = window_sizes_list[i].text;
4474 ti->node_top = &window_sizes;
4475 ti->sort_priority = value;
4477 sprintf(identifier, "%d", value);
4478 sprintf(name, "%s", text);
4480 setString(&ti->identifier, identifier);
4481 setString(&ti->name, name);
4482 setString(&ti->name_sorting, name);
4483 setString(&ti->infotext, "Window Scaling");
4485 pushTreeInfo(&window_sizes, ti);
4487 if (value == setup.window_scaling_percent)
4488 current_window_size_found = TRUE;
4491 if (!current_window_size_found)
4493 // add entry for non-preset window scaling value
4495 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4496 char identifier[32], name[32];
4497 int value = setup.window_scaling_percent;
4499 ti->node_top = &window_sizes;
4500 ti->sort_priority = value;
4502 sprintf(identifier, "%d", value);
4503 sprintf(name, "%d %% (Current)", value);
4505 setString(&ti->identifier, identifier);
4506 setString(&ti->name, name);
4507 setString(&ti->name_sorting, name);
4508 setString(&ti->infotext, "Window Scaling");
4510 pushTreeInfo(&window_sizes, ti);
4513 /* sort window size values to start with lowest window size value */
4514 sortTreeInfo(&window_sizes);
4516 /* set current window size value to configured window size value */
4517 window_size_current =
4518 getTreeInfoFromIdentifier(window_sizes,
4519 i_to_a(setup.window_scaling_percent));
4521 /* if that fails, set current window size to reliable default value */
4522 if (window_size_current == NULL)
4523 window_size_current =
4524 getTreeInfoFromIdentifier(window_sizes,
4525 i_to_a(STD_WINDOW_SCALING_PERCENT));
4527 /* if that also fails, set current window size to first available value */
4528 if (window_size_current == NULL)
4529 window_size_current = window_sizes;
4532 setup.window_scaling_percent = atoi(window_size_current->identifier);
4534 /* needed for displaying window size text instead of identifier */
4535 window_size_text = window_size_current->name;
4538 static void execSetupGraphics_setScalingTypes()
4540 if (scaling_types == NULL)
4544 for (i = 0; scaling_types_list[i].value != NULL; i++)
4546 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4547 char identifier[32], name[32];
4548 char *value = scaling_types_list[i].value;
4549 char *text = scaling_types_list[i].text;
4551 ti->node_top = &scaling_types;
4552 ti->sort_priority = i;
4554 sprintf(identifier, "%s", value);
4555 sprintf(name, "%s", text);
4557 setString(&ti->identifier, identifier);
4558 setString(&ti->name, name);
4559 setString(&ti->name_sorting, name);
4560 setString(&ti->infotext, "Anti-Aliasing");
4562 pushTreeInfo(&scaling_types, ti);
4565 /* sort scaling type values to start with lowest scaling type value */
4566 sortTreeInfo(&scaling_types);
4568 /* set current scaling type value to configured scaling type value */
4569 scaling_type_current =
4570 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4572 /* if that fails, set current scaling type to reliable default value */
4573 if (scaling_type_current == NULL)
4574 scaling_type_current =
4575 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4577 /* if that also fails, set current scaling type to first available value */
4578 if (scaling_type_current == NULL)
4579 scaling_type_current = scaling_types;
4582 setup.window_scaling_quality = scaling_type_current->identifier;
4584 /* needed for displaying scaling type text instead of identifier */
4585 scaling_type_text = scaling_type_current->name;
4588 static void execSetupGraphics_setScreenModes()
4590 // if (screen_modes == NULL && video.fullscreen_available)
4591 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4595 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4597 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4598 char identifier[32], name[32];
4599 int x = video.fullscreen_modes[i].width;
4600 int y = video.fullscreen_modes[i].height;
4603 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4605 ti->node_top = &screen_modes;
4606 ti->sort_priority = x * 10000 + y;
4608 sprintf(identifier, "%dx%d", x, y);
4609 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4611 setString(&ti->identifier, identifier);
4612 setString(&ti->name, name);
4613 setString(&ti->name_sorting, name);
4614 setString(&ti->infotext, "Fullscreen Mode");
4616 pushTreeInfo(&screen_modes, ti);
4619 /* sort fullscreen modes to start with lowest available screen resolution */
4620 sortTreeInfo(&screen_modes);
4622 /* set current screen mode for fullscreen mode to configured setup value */
4623 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4624 setup.fullscreen_mode);
4626 /* if that fails, set current screen mode to reliable default value */
4627 if (screen_mode_current == NULL)
4628 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4629 DEFAULT_FULLSCREEN_MODE);
4631 /* if that also fails, set current screen mode to first available mode */
4632 if (screen_mode_current == NULL)
4633 screen_mode_current = screen_modes;
4635 if (screen_mode_current == NULL)
4636 video.fullscreen_available = FALSE;
4639 // if (video.fullscreen_available)
4640 if (screen_mode_current != NULL)
4642 setup.fullscreen_mode = screen_mode_current->identifier;
4644 /* needed for displaying screen mode name instead of identifier */
4645 screen_mode_text = screen_mode_current->name;
4649 static void execSetupGraphics()
4651 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4653 // update "setup.window_scaling_percent" from list selection
4654 execSetupGraphics_setWindowSizes(FALSE);
4658 // update list selection from "setup.window_scaling_percent"
4659 execSetupGraphics_setWindowSizes(TRUE);
4662 execSetupGraphics_setScalingTypes();
4663 execSetupGraphics_setScreenModes();
4665 setup_mode = SETUP_MODE_GRAPHICS;
4669 #if defined(TARGET_SDL2)
4670 // window scaling may have changed at this point
4671 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4673 // window scaling quality may have changed at this point
4674 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4675 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4679 #if !defined(PLATFORM_ANDROID)
4680 #if defined(TARGET_SDL2)
4681 static void execSetupChooseWindowSize()
4684 if (!video.window_scaling_available)
4688 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4693 static void execSetupChooseScalingType()
4695 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4700 static void execSetupChooseScreenMode()
4702 if (!video.fullscreen_available)
4705 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4712 static void execSetupChooseVolumeSimple()
4714 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4719 static void execSetupChooseVolumeLoops()
4721 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4726 static void execSetupChooseVolumeMusic()
4728 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4733 static void execSetupSound()
4736 if (volumes_simple == NULL)
4740 for (i = 0; volumes_list[i].value != -1; i++)
4742 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4743 char identifier[32], name[32];
4744 int value = volumes_list[i].value;
4745 char *text = volumes_list[i].text;
4747 ti->node_top = &volumes_simple;
4748 ti->sort_priority = value;
4750 sprintf(identifier, "%d", value);
4751 sprintf(name, "%s", text);
4753 setString(&ti->identifier, identifier);
4754 setString(&ti->name, name);
4755 setString(&ti->name_sorting, name);
4756 setString(&ti->infotext, "Sound Volume");
4758 pushTreeInfo(&volumes_simple, ti);
4761 /* sort volume values to start with lowest volume value */
4762 sortTreeInfo(&volumes_simple);
4764 /* set current volume value to configured volume value */
4765 volume_simple_current =
4766 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4768 /* if that fails, set current volume to reliable default value */
4769 if (volume_simple_current == NULL)
4770 volume_simple_current =
4771 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4773 /* if that also fails, set current volume to first available value */
4774 if (volume_simple_current == NULL)
4775 volume_simple_current = volumes_simple;
4778 if (volumes_loops == NULL)
4782 for (i = 0; volumes_list[i].value != -1; i++)
4784 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4785 char identifier[32], name[32];
4786 int value = volumes_list[i].value;
4787 char *text = volumes_list[i].text;
4789 ti->node_top = &volumes_loops;
4790 ti->sort_priority = value;
4792 sprintf(identifier, "%d", value);
4793 sprintf(name, "%s", text);
4795 setString(&ti->identifier, identifier);
4796 setString(&ti->name, name);
4797 setString(&ti->name_sorting, name);
4798 setString(&ti->infotext, "Loops Volume");
4800 pushTreeInfo(&volumes_loops, ti);
4803 /* sort volume values to start with lowest volume value */
4804 sortTreeInfo(&volumes_loops);
4806 /* set current volume value to configured volume value */
4807 volume_loops_current =
4808 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4810 /* if that fails, set current volume to reliable default value */
4811 if (volume_loops_current == NULL)
4812 volume_loops_current =
4813 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4815 /* if that also fails, set current volume to first available value */
4816 if (volume_loops_current == NULL)
4817 volume_loops_current = volumes_loops;
4820 if (volumes_music == NULL)
4824 for (i = 0; volumes_list[i].value != -1; i++)
4826 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4827 char identifier[32], name[32];
4828 int value = volumes_list[i].value;
4829 char *text = volumes_list[i].text;
4831 ti->node_top = &volumes_music;
4832 ti->sort_priority = value;
4834 sprintf(identifier, "%d", value);
4835 sprintf(name, "%s", text);
4837 setString(&ti->identifier, identifier);
4838 setString(&ti->name, name);
4839 setString(&ti->name_sorting, name);
4840 setString(&ti->infotext, "Music Volume");
4842 pushTreeInfo(&volumes_music, ti);
4845 /* sort volume values to start with lowest volume value */
4846 sortTreeInfo(&volumes_music);
4848 /* set current volume value to configured volume value */
4849 volume_music_current =
4850 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4852 /* if that fails, set current volume to reliable default value */
4853 if (volume_music_current == NULL)
4854 volume_music_current =
4855 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4857 /* if that also fails, set current volume to first available value */
4858 if (volume_music_current == NULL)
4859 volume_music_current = volumes_music;
4862 setup.volume_simple = atoi(volume_simple_current->identifier);
4863 setup.volume_loops = atoi(volume_loops_current->identifier);
4864 setup.volume_music = atoi(volume_music_current->identifier);
4866 /* needed for displaying volume text instead of identifier */
4867 volume_simple_text = volume_simple_current->name;
4868 volume_loops_text = volume_loops_current->name;
4869 volume_music_text = volume_music_current->name;
4872 setup_mode = SETUP_MODE_SOUND;
4877 static void execSetupChooseTouchControls()
4879 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4884 static void execSetupChooseMoveDistance()
4886 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4891 static void execSetupChooseDropDistance()
4893 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4898 static void execSetupTouch()
4901 if (touch_controls == NULL)
4905 for (i = 0; touch_controls_list[i].value != NULL; i++)
4907 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4908 char identifier[32], name[32];
4909 char *value = touch_controls_list[i].value;
4910 char *text = touch_controls_list[i].text;
4912 ti->node_top = &touch_controls;
4913 ti->sort_priority = i;
4915 sprintf(identifier, "%s", value);
4916 sprintf(name, "%s", text);
4918 setString(&ti->identifier, identifier);
4919 setString(&ti->name, name);
4920 setString(&ti->name_sorting, name);
4921 setString(&ti->infotext, "Control Type");
4923 pushTreeInfo(&touch_controls, ti);
4926 /* sort touch control values to start with lowest touch control value */
4927 sortTreeInfo(&touch_controls);
4929 /* set current touch control value to configured touch control value */
4930 touch_control_current =
4931 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4933 /* if that fails, set current touch control to reliable default value */
4934 if (touch_control_current == NULL)
4935 touch_control_current =
4936 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4938 /* if that also fails, set current touch control to first available value */
4939 if (touch_control_current == NULL)
4940 touch_control_current = touch_controls;
4943 if (move_distances == NULL)
4947 for (i = 0; distances_list[i].value != -1; i++)
4949 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4950 char identifier[32], name[32];
4951 int value = distances_list[i].value;
4952 char *text = distances_list[i].text;
4954 ti->node_top = &move_distances;
4955 ti->sort_priority = value;
4957 sprintf(identifier, "%d", value);
4958 sprintf(name, "%s", text);
4960 setString(&ti->identifier, identifier);
4961 setString(&ti->name, name);
4962 setString(&ti->name_sorting, name);
4963 setString(&ti->infotext, "Move Distance");
4965 pushTreeInfo(&move_distances, ti);
4968 /* sort distance values to start with lowest distance value */
4969 sortTreeInfo(&move_distances);
4971 /* set current distance value to configured distance value */
4972 move_distance_current =
4973 getTreeInfoFromIdentifier(move_distances,
4974 i_to_a(setup.touch.move_distance));
4976 /* if that fails, set current distance to reliable default value */
4977 if (move_distance_current == NULL)
4978 move_distance_current =
4979 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4981 /* if that also fails, set current distance to first available value */
4982 if (move_distance_current == NULL)
4983 move_distance_current = move_distances;
4986 if (drop_distances == NULL)
4990 for (i = 0; distances_list[i].value != -1; i++)
4992 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4993 char identifier[32], name[32];
4994 int value = distances_list[i].value;
4995 char *text = distances_list[i].text;
4997 ti->node_top = &drop_distances;
4998 ti->sort_priority = value;
5000 sprintf(identifier, "%d", value);
5001 sprintf(name, "%s", text);
5003 setString(&ti->identifier, identifier);
5004 setString(&ti->name, name);
5005 setString(&ti->name_sorting, name);
5006 setString(&ti->infotext, "Drop Distance");
5008 pushTreeInfo(&drop_distances, ti);
5011 /* sort distance values to start with lowest distance value */
5012 sortTreeInfo(&drop_distances);
5014 /* set current distance value to configured distance value */
5015 drop_distance_current =
5016 getTreeInfoFromIdentifier(drop_distances,
5017 i_to_a(setup.touch.drop_distance));
5019 /* if that fails, set current distance to reliable default value */
5020 if (drop_distance_current == NULL)
5021 drop_distance_current =
5022 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5024 /* if that also fails, set current distance to first available value */
5025 if (drop_distance_current == NULL)
5026 drop_distance_current = drop_distances;
5029 setup.touch.control_type = touch_control_current->identifier;
5030 setup.touch.move_distance = atoi(move_distance_current->identifier);
5031 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5033 /* needed for displaying volume text instead of identifier */
5034 touch_controls_text = touch_control_current->name;
5035 move_distance_text = move_distance_current->name;
5036 drop_distance_text = drop_distance_current->name;
5039 setup_mode = SETUP_MODE_TOUCH;
5044 static void execSetupArtwork()
5047 printf("::: '%s', '%s', '%s'\n",
5048 artwork.gfx_current->subdir,
5049 artwork.gfx_current->fullpath,
5050 artwork.gfx_current->basepath);
5053 setup.graphics_set = artwork.gfx_current->identifier;
5054 setup.sounds_set = artwork.snd_current->identifier;
5055 setup.music_set = artwork.mus_current->identifier;
5057 /* needed if last screen (setup choice) changed graphics, sounds or music */
5058 ReloadCustomArtwork(0);
5060 /* needed for displaying artwork name instead of artwork identifier */
5061 graphics_set_name = artwork.gfx_current->name;
5062 sounds_set_name = artwork.snd_current->name;
5063 music_set_name = artwork.mus_current->name;
5065 setup_mode = SETUP_MODE_ARTWORK;
5070 static void execSetupChooseGraphics()
5072 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5077 static void execSetupChooseSounds()
5079 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5084 static void execSetupChooseMusic()
5086 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5091 static void execSetupInput()
5093 setup_mode = SETUP_MODE_INPUT;
5098 static void execSetupShortcuts()
5100 setup_mode = SETUP_MODE_SHORTCUTS;
5105 static void execSetupShortcuts1()
5107 setup_mode = SETUP_MODE_SHORTCUTS_1;
5112 static void execSetupShortcuts2()
5114 setup_mode = SETUP_MODE_SHORTCUTS_2;
5119 static void execSetupShortcuts3()
5121 setup_mode = SETUP_MODE_SHORTCUTS_3;
5126 static void execSetupShortcuts4()
5128 setup_mode = SETUP_MODE_SHORTCUTS_4;
5133 static void execSetupShortcuts5()
5135 setup_mode = SETUP_MODE_SHORTCUTS_5;
5140 static void execExitSetup()
5142 game_status = GAME_MODE_MAIN;
5144 DrawMainMenuExt(REDRAW_FIELD, FALSE);
5147 static void execSaveAndExitSetup()
5153 static struct TokenInfo setup_info_main[] =
5155 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5156 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5157 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5158 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5159 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5160 #if !defined(PLATFORM_ANDROID)
5161 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5162 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5164 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5166 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5167 { TYPE_EMPTY, NULL, "" },
5168 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5169 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5174 static struct TokenInfo setup_info_game[] =
5176 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5177 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5178 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5179 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5180 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5181 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5182 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5183 { TYPE_STRING, &game_speed_text, "" },
5185 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5186 { TYPE_STRING, &scroll_delay_text, "" },
5188 { TYPE_EMPTY, NULL, "" },
5189 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5194 static struct TokenInfo setup_info_editor[] =
5197 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5198 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5199 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5200 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5201 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5202 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5203 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5204 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5206 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5207 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5208 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5210 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5212 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5213 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5214 { TYPE_EMPTY, NULL, "" },
5216 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5217 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5218 { TYPE_EMPTY, NULL, "" },
5220 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5221 { TYPE_EMPTY, NULL, "" },
5222 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5227 static struct TokenInfo setup_info_graphics[] =
5229 #if !defined(PLATFORM_ANDROID)
5230 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5231 #if defined(TARGET_SDL2)
5232 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5233 { TYPE_STRING, &window_size_text, "" },
5235 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5236 { TYPE_STRING, &scaling_type_text, "" },
5239 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5240 { TYPE_STRING, &screen_mode_text, "" },
5244 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
5247 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5248 { TYPE_STRING, &scroll_delay_text, "" },
5251 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
5253 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5254 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5255 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5256 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5257 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5258 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5259 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5260 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5261 { TYPE_EMPTY, NULL, "" },
5262 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5267 static struct TokenInfo setup_info_sound[] =
5269 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5270 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5271 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5272 { TYPE_EMPTY, NULL, "" },
5273 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5274 { TYPE_STRING, &volume_simple_text, "" },
5275 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5276 { TYPE_STRING, &volume_loops_text, "" },
5277 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5278 { TYPE_STRING, &volume_music_text, "" },
5279 { TYPE_EMPTY, NULL, "" },
5280 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5285 static struct TokenInfo setup_info_artwork[] =
5287 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5288 { TYPE_STRING, &graphics_set_name, "" },
5289 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5290 { TYPE_STRING, &sounds_set_name, "" },
5291 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5292 { TYPE_STRING, &music_set_name, "" },
5293 { TYPE_EMPTY, NULL, "" },
5296 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5297 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5298 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5300 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
5301 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
5302 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
5303 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
5306 { TYPE_STRING, NULL, "Override Level Artwork:"},
5307 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
5308 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
5309 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
5311 { TYPE_EMPTY, NULL, "" },
5312 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5317 static struct TokenInfo setup_info_input[] =
5319 { TYPE_SWITCH, NULL, "Player:" },
5320 { TYPE_SWITCH, NULL, "Device:" },
5321 { TYPE_ENTER_MENU, NULL, "" },
5322 { TYPE_EMPTY, NULL, "" },
5323 { TYPE_EMPTY, NULL, "" },
5324 { TYPE_EMPTY, NULL, "" },
5325 { TYPE_EMPTY, NULL, "" },
5326 { TYPE_EMPTY, NULL, "" },
5327 { TYPE_EMPTY, NULL, "" },
5328 { TYPE_EMPTY, NULL, "" },
5329 { TYPE_EMPTY, NULL, "" },
5330 { TYPE_EMPTY, NULL, "" },
5331 { TYPE_EMPTY, NULL, "" },
5332 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5337 static struct TokenInfo setup_info_touch[] =
5339 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5340 { TYPE_STRING, &touch_controls_text, "" },
5341 { TYPE_EMPTY, NULL, "" },
5342 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5343 { TYPE_STRING, &move_distance_text, "" },
5344 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5345 { TYPE_STRING, &drop_distance_text, "" },
5346 { TYPE_EMPTY, NULL, "" },
5347 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5352 static struct TokenInfo setup_info_shortcuts[] =
5354 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5355 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5356 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5357 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5358 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5359 { TYPE_EMPTY, NULL, "" },
5360 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5365 static struct TokenInfo setup_info_shortcuts_1[] =
5367 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5368 { TYPE_KEY, &setup.shortcut.save_game, "" },
5369 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5370 { TYPE_KEY, &setup.shortcut.load_game, "" },
5371 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5372 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5373 { TYPE_EMPTY, NULL, "" },
5374 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5375 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5376 { TYPE_EMPTY, NULL, "" },
5377 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5382 static struct TokenInfo setup_info_shortcuts_2[] =
5384 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5385 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5386 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5387 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5388 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5389 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5390 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5391 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5392 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5393 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5394 { TYPE_EMPTY, NULL, "" },
5395 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5400 static struct TokenInfo setup_info_shortcuts_3[] =
5402 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5403 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5404 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5405 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5406 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5407 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5408 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5409 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5410 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5411 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5412 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5413 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5414 { TYPE_EMPTY, NULL, "" },
5415 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5420 static struct TokenInfo setup_info_shortcuts_4[] =
5422 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5423 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5424 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5425 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5426 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5427 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5428 { TYPE_EMPTY, NULL, "" },
5429 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5434 static struct TokenInfo setup_info_shortcuts_5[] =
5436 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5437 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5438 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5439 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5440 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5441 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5442 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5443 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5444 { TYPE_EMPTY, NULL, "" },
5445 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5450 static Key getSetupKey()
5452 Key key = KSYM_UNDEFINED;
5453 boolean got_key_event = FALSE;
5455 while (!got_key_event)
5457 if (PendingEvent()) /* got event */
5465 case EVENT_KEYPRESS:
5467 key = GetEventKey((KeyEvent *)&event, TRUE);
5469 /* press 'Escape' or 'Enter' to keep the existing key binding */
5470 if (key == KSYM_Escape || key == KSYM_Return)
5471 key = KSYM_UNDEFINED; /* keep old value */
5473 got_key_event = TRUE;
5477 case EVENT_KEYRELEASE:
5478 key_joystick_mapping = 0;
5482 HandleOtherEvents(&event);
5490 /* don't eat all CPU time */
5497 static int getSetupTextFont(int type)
5499 if (type & (TYPE_SWITCH |
5511 static int getSetupValueFont(int type, void *value)
5513 if (type & TYPE_KEY)
5514 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5515 else if (type & TYPE_STRING)
5516 return FONT_VALUE_2;
5517 else if (type & TYPE_ECS_AGA)
5518 return FONT_VALUE_1;
5519 else if (type & TYPE_BOOLEAN_STYLE)
5520 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5521 else if (type & TYPE_YES_NO_AUTO)
5522 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5523 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5525 return FONT_VALUE_1;
5529 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5531 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5532 struct TokenInfo *si = &setup_info[si_pos];
5533 boolean font_draw_xoffset_modified = FALSE;
5534 int font_draw_xoffset_old = -1;
5535 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5536 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5537 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5538 int xpos = menu_screen_value_xpos;
5539 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5540 int startx = mSX + xpos * 32;
5541 int starty = mSY + ypos * 32;
5542 int font_nr, font_width;
5546 int type = si->type;
5547 void *value = si->value;
5548 char *value_string = getSetupValue(type, value);
5553 if (value_string == NULL)
5556 if (type & TYPE_KEY)
5558 xpos = MENU_SCREEN_START_XPOS;
5560 if (type & TYPE_QUERY)
5561 value_string = "<press key>";
5563 else if (type & TYPE_STRING)
5565 int max_value_len = (SCR_FIELDX - 2) * 2;
5567 xpos = MENU_SCREEN_START_XPOS;
5569 if (strlen(value_string) > max_value_len)
5570 value_string[max_value_len] = '\0';
5572 else if (type & TYPE_YES_NO_AUTO)
5574 xpos = menu_screen_value_xpos - 1;
5577 startx = mSX + xpos * 32;
5578 starty = mSY + ypos * 32;
5579 font_nr = getSetupValueFont(type, value);
5580 font_width = getFontWidth(font_nr);
5582 font_height = getFontHeight(font_nr);
5586 if (menu_screen_value_xpos < 1 + MAX_MENU_TEXT_LENGTH_BIG)
5590 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5591 if (setup_mode != SETUP_MODE_INPUT)
5593 int max_menu_text_length_big = (menu_screen_value_xpos -
5594 MENU_SCREEN_START_XPOS);
5595 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5596 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5597 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5598 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5599 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5600 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5601 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5602 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5603 boolean correct_font_draw_xoffset = FALSE;
5605 if (xpos == MENU_SCREEN_START_XPOS &&
5606 startx + font1_xoffset < text_startx + text_font_xoffset)
5607 correct_font_draw_xoffset = TRUE;
5609 if (xpos == menu_screen_value_xpos &&
5610 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5611 correct_font_draw_xoffset = TRUE;
5613 /* check if setup value would overlap with setup text when printed */
5614 /* (this can happen for extreme/wrong values for font draw offset) */
5615 if (correct_font_draw_xoffset)
5617 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5618 font_draw_xoffset_modified = TRUE;
5620 if (type & TYPE_KEY)
5621 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5622 else if (!(type & TYPE_STRING))
5623 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5624 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5629 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5631 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5632 DrawText(startx + i * font_width, starty, " ", font_nr);
5635 // printf("::: startx == %d\n", startx);
5637 DrawText(startx, starty, value_string, font_nr);
5639 if (font_draw_xoffset_modified)
5640 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5645 static void drawSetupValue(int pos)
5647 boolean font_draw_xoffset_modified = FALSE;
5648 int font_draw_xoffset_old = -1;
5649 int xpos = MENU_SCREEN_VALUE_XPOS;
5650 int ypos = MENU_SCREEN_START_YPOS + pos;
5651 int startx = mSX + xpos * 32;
5652 int starty = mSY + ypos * 32;
5653 int font_nr, font_width;
5657 int type = setup_info[pos].type;
5658 void *value = setup_info[pos].value;
5659 char *value_string = getSetupValue(type, value);
5664 if (value_string == NULL)
5667 if (type & TYPE_KEY)
5669 xpos = MENU_SCREEN_START_XPOS;
5671 if (type & TYPE_QUERY)
5672 value_string = "<press key>";
5674 else if (type & TYPE_STRING)
5676 int max_value_len = (SCR_FIELDX - 2) * 2;
5678 xpos = MENU_SCREEN_START_XPOS;
5680 if (strlen(value_string) > max_value_len)
5681 value_string[max_value_len] = '\0';
5683 else if (type & TYPE_YES_NO_AUTO)
5685 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5688 startx = mSX + xpos * 32;
5689 starty = mSY + ypos * 32;
5690 font_nr = getSetupValueFont(type, value);
5691 font_width = getFontWidth(font_nr);
5693 font_height = getFontHeight(font_nr);
5696 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5697 if (setup_mode != SETUP_MODE_INPUT)
5699 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5700 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5701 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5702 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5703 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5704 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5705 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5706 boolean correct_font_draw_xoffset = FALSE;
5708 if (xpos == MENU_SCREEN_START_XPOS &&
5709 startx + font1_xoffset < text_startx + text_font_xoffset)
5710 correct_font_draw_xoffset = TRUE;
5712 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5713 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5714 correct_font_draw_xoffset = TRUE;
5716 /* check if setup value would overlap with setup text when printed */
5717 /* (this can happen for extreme/wrong values for font draw offset) */
5718 if (correct_font_draw_xoffset)
5720 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5721 font_draw_xoffset_modified = TRUE;
5723 if (type & TYPE_KEY)
5724 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5725 else if (!(type & TYPE_STRING))
5726 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5727 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5732 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5734 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5735 DrawText(startx + i * font_width, starty, " ", font_nr);
5738 DrawText(startx, starty, value_string, font_nr);
5740 if (font_draw_xoffset_modified)
5741 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5746 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5748 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5749 struct TokenInfo *si = &setup_info[si_pos];
5751 if (si->type & TYPE_BOOLEAN_STYLE)
5753 *(boolean *)si->value ^= TRUE;
5755 else if (si->type & TYPE_YES_NO_AUTO)
5759 (*(int *)si->value == AUTO ? TRUE :
5760 *(int *)si->value == TRUE ? FALSE : AUTO) :
5761 (*(int *)si->value == TRUE ? AUTO :
5762 *(int *)si->value == AUTO ? FALSE : TRUE));
5764 else if (si->type & TYPE_KEY)
5768 si->type |= TYPE_QUERY;
5769 drawSetupValue(screen_pos, setup_info_pos_raw);
5770 si->type &= ~TYPE_QUERY;
5772 key = getSetupKey();
5773 if (key != KSYM_UNDEFINED)
5774 *(Key *)si->value = key;
5777 drawSetupValue(screen_pos, setup_info_pos_raw);
5779 // fullscreen state may have changed at this point
5780 if (si->value == &setup.fullscreen)
5781 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5786 static void changeSetupValue(int pos, int dx)
5788 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5790 *(boolean *)setup_info[pos].value ^= TRUE;
5792 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5794 *(int *)setup_info[pos].value =
5796 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5797 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5798 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5799 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5801 else if (setup_info[pos].type & TYPE_KEY)
5805 setup_info[pos].type |= TYPE_QUERY;
5806 drawSetupValue(pos, -1);
5807 setup_info[pos].type &= ~TYPE_QUERY;
5809 key = getSetupKey();
5810 if (key != KSYM_UNDEFINED)
5811 *(Key *)setup_info[pos].value = key;
5814 drawSetupValue(pos, -1);
5816 // fullscreen state may have changed at this point
5817 if (setup_info[pos].value == &setup.fullscreen)
5818 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5823 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5826 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5827 struct TokenInfo *si = &setup_info[si_pos];
5828 int xpos = MENU_SCREEN_START_XPOS;
5829 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5830 int font_nr = getSetupTextFont(si->type);
5832 if (setup_info == setup_info_input)
5833 font_nr = FONT_MENU_1;
5836 font_nr = FONT_ACTIVE(font_nr);
5838 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5840 if (si->type & ~TYPE_SKIP_ENTRY)
5841 drawCursor(screen_pos, active);
5844 static void DrawCursorAndText_Setup(int pos, boolean active)
5846 int xpos = MENU_SCREEN_START_XPOS;
5847 int ypos = MENU_SCREEN_START_YPOS + pos;
5848 int font_nr = getSetupTextFont(setup_info[pos].type);
5850 if (setup_info == setup_info_input)
5851 font_nr = FONT_MENU_1;
5854 font_nr = FONT_ACTIVE(font_nr);
5856 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5858 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5859 drawCursor(pos, active);
5863 static void drawSetupInfoList(struct TokenInfo *setup_info,
5864 int first_entry, int num_page_entries)
5868 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5869 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5871 if (num_page_entries > max_setup_info)
5872 num_page_entries = max_setup_info;
5874 if (first_entry + num_page_entries > max_setup_info)
5878 /* clear tree list area, but not title or scrollbar */
5879 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
5880 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
5881 NUM_MENU_ENTRIES_ON_SCREEN * 32);
5884 for (i = 0; i < num_page_entries; i++)
5886 int setup_info_pos = first_entry + i;
5887 struct TokenInfo *si = &setup_info[setup_info_pos];
5888 void *value_ptr = si->value;
5890 /* set some entries to "unchangeable" according to other variables */
5891 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5892 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5893 (value_ptr == &setup.sound_music && !audio.music_available) ||
5894 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5895 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5896 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5897 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5898 si->type |= TYPE_GHOSTED;
5900 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5901 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5902 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5903 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5904 else if (si->type & ~TYPE_SKIP_ENTRY)
5905 initCursor(i, IMG_MENU_BUTTON);
5907 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5909 if (si->type & TYPE_VALUE)
5910 drawSetupValue(i, setup_info_pos);
5914 static void DrawSetupScreen_Generic()
5916 boolean redraw_all = FALSE;
5917 char *title_string = NULL;
5923 FreeScreenGadgets();
5924 CreateScreenGadgets();
5927 CloseDoor(DOOR_CLOSE_2);
5929 if (redraw_mask & REDRAW_ALL)
5933 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5934 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5935 int2str(0, redraw_mask)));
5939 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5940 FadeOut(redraw_mask);
5942 FadeOut(REDRAW_FIELD);
5947 if (setup_mode == SETUP_MODE_MAIN)
5949 setup_info = setup_info_main;
5950 title_string = "Setup";
5952 else if (setup_mode == SETUP_MODE_GAME)
5954 setup_info = setup_info_game;
5955 title_string = "Setup Game";
5957 else if (setup_mode == SETUP_MODE_EDITOR)
5959 setup_info = setup_info_editor;
5960 title_string = "Setup Editor";
5962 else if (setup_mode == SETUP_MODE_GRAPHICS)
5964 setup_info = setup_info_graphics;
5965 title_string = "Setup Graphics";
5967 else if (setup_mode == SETUP_MODE_SOUND)
5969 setup_info = setup_info_sound;
5970 title_string = "Setup Sound";
5972 else if (setup_mode == SETUP_MODE_ARTWORK)
5974 setup_info = setup_info_artwork;
5975 title_string = "Custom Artwork";
5977 else if (setup_mode == SETUP_MODE_TOUCH)
5979 setup_info = setup_info_touch;
5980 title_string = "Setup Touch Ctrls";
5982 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5984 setup_info = setup_info_shortcuts;
5985 title_string = "Setup Shortcuts";
5987 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5989 setup_info = setup_info_shortcuts_1;
5990 title_string = "Setup Shortcuts";
5992 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5994 setup_info = setup_info_shortcuts_2;
5995 title_string = "Setup Shortcuts";
5997 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5999 setup_info = setup_info_shortcuts_3;
6000 title_string = "Setup Shortcuts";
6002 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6004 setup_info = setup_info_shortcuts_4;
6005 title_string = "Setup Shortcuts";
6007 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6009 setup_info = setup_info_shortcuts_5;
6010 title_string = "Setup Shortcuts";
6013 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6018 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6022 for (i = 0; setup_info[i].type != 0; i++)
6026 drawSetupInfoList(setup_info, 0, NUM_MENU_ENTRIES_ON_SCREEN);
6033 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6035 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6038 void *value_ptr = setup_info[i].value;
6040 /* set some entries to "unchangeable" according to other variables */
6041 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
6042 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
6043 (value_ptr == &setup.sound_music && !audio.music_available) ||
6044 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
6045 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
6046 (value_ptr == &window_size_text && !video.window_scaling_available) ||
6047 (value_ptr == &scaling_type_text && !video.window_scaling_available))
6048 setup_info[i].type |= TYPE_GHOSTED;
6050 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6051 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6052 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6053 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6054 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6055 initCursor(i, IMG_MENU_BUTTON);
6057 DrawCursorAndText_Setup(i, FALSE);
6059 if (setup_info[i].type & TYPE_VALUE)
6067 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6068 "Joysticks deactivated in setup menu");
6072 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6076 MapScreenGadgets(max_setup_info);
6080 redraw_mask = REDRAW_ALL;
6083 FadeIn(redraw_mask);
6085 FadeIn(REDRAW_FIELD);
6090 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6094 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6096 static int choice_store[MAX_SETUP_MODES];
6097 static int first_entry_store[MAX_SETUP_MODES];
6098 int choice = choice_store[setup_mode]; /* starts with 0 */
6099 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
6102 int y = choice - first_entry;
6107 boolean position_set_by_scrollbar = (dx == 999);
6109 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6110 int num_page_entries;
6112 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
6115 if (button == MB_MENU_INITIALIZE)
6117 /* advance to first valid menu entry */
6118 while (choice < num_setup_info &&
6119 setup_info[choice].type & TYPE_SKIP_ENTRY)
6122 choice_store[setup_mode] = choice;
6126 if (position_set_by_scrollbar)
6127 first_entry = first_entry_store[setup_mode] = dy;
6129 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6130 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6132 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6136 if (choice < first_entry)
6138 choice = first_entry;
6140 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6143 else if (choice > first_entry + num_page_entries - 1)
6145 choice = first_entry + num_page_entries - 1;
6147 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6151 choice_store[setup_mode] = choice;
6153 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6155 DrawCursorAndText_Setup(choice, -1, TRUE);
6160 else if (button == MB_MENU_LEAVE)
6164 PlaySound(SND_MENU_ITEM_SELECTING);
6166 for (i = 0; setup_info[i].type != 0; i++)
6168 if (setup_info[i].type & TYPE_LEAVE_MENU)
6170 void (*menu_callback_function)(void) = setup_info[i].value;
6174 menu_callback_function();
6176 break; /* absolutely needed because function changes 'setup_info'! */
6183 if (mx || my) /* mouse input */
6185 x = (mx - mSX) / 32;
6186 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6189 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
6191 else if (dx || dy) /* keyboard input */
6194 /* move cursor instead of scrolling when already at start/end of list */
6195 if (dy == -1 * SCROLL_LINE && first_entry == 0)
6197 else if (dy == +1 * SCROLL_LINE &&
6198 first_entry + num_page_entries == max_setup_info)
6201 /* handle scrolling screen one line or page */
6203 y + dy > num_page_entries - 1)
6205 boolean redraw = FALSE;
6207 if (ABS(dy) == SCROLL_PAGE)
6208 step = num_page_entries - 1;
6210 if (dy < 0 && first_entry > 0)
6212 /* scroll page/line up */
6214 first_entry -= step;
6215 if (first_entry < 0)
6220 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
6222 /* scroll page/line down */
6224 first_entry += step;
6225 if (first_entry + num_page_entries > max_setup_info)
6226 first_entry = MAX(0, max_setup_info - num_page_entries);
6233 choice += first_entry - first_entry_store[setup_mode];
6235 if (choice < first_entry)
6237 choice = first_entry;
6239 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6242 else if (choice > first_entry + num_page_entries - 1)
6244 choice = first_entry + num_page_entries - 1;
6246 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6250 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6254 if (choice < first_entry ||
6255 choice > first_entry + num_page_entries - 1)
6256 first_entry += SIGN(dy);
6260 // printf("::: MARK 1: %d\n", first_entry);
6262 first_entry_store[setup_mode] = first_entry;
6263 choice_store[setup_mode] = choice;
6265 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6267 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6269 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6270 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6278 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
6280 if (setup_info[choice].type & menu_navigation_type ||
6281 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
6282 setup_info[choice].type & TYPE_YES_NO_AUTO)
6283 button = MB_MENU_CHOICE;
6293 /* jump to next non-empty menu entry (up or down) */
6295 while (first_entry + y > 0 &&
6296 first_entry + y < max_setup_info - 1 &&
6297 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6300 while (y > 0 && y < num_setup_info - 1 &&
6301 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6305 if (!IN_VIS_FIELD(x, y))
6307 choice += y - y_old;
6309 if (choice < first_entry)
6310 first_entry = choice;
6311 else if (choice > first_entry + num_page_entries - 1)
6312 first_entry = choice - num_page_entries + 1;
6314 first_entry += y - y_old;
6317 if (first_entry >= 0 &&
6318 first_entry + num_page_entries <= max_setup_info)
6320 first_entry_store[setup_mode] = first_entry;
6322 if (choice < first_entry)
6323 choice = first_entry;
6324 else if (choice > first_entry + num_page_entries - 1)
6325 choice = first_entry + num_page_entries - 1;
6327 choice_store[setup_mode] = choice;
6329 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6331 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6333 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6334 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6342 if (!anyScrollbarGadgetActive() &&
6343 IN_VIS_FIELD(x, y) &&
6344 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
6345 y >= 0 && y < num_page_entries)
6347 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
6351 printf("::: TEST/HandleSetupScreen_Generic [%d, %d, %d, %d]\n", Counter(),
6352 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
6358 if (first_entry + y != choice &&
6359 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
6361 PlaySound(SND_MENU_ITEM_ACTIVATING);
6363 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
6364 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
6366 choice = choice_store[setup_mode] = first_entry + y;
6369 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
6371 PlaySound(SND_MENU_ITEM_ACTIVATING);
6373 DrawCursorAndText_Setup(choice, -1, FALSE);
6374 DrawCursorAndText_Setup(y, -1, TRUE);
6376 choice = choice_store[setup_mode] = y;
6381 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
6383 PlaySound(SND_MENU_ITEM_SELECTING);
6385 /* when selecting key headline, execute function for key value change */
6386 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
6387 setup_info[first_entry + y + 1].type & TYPE_KEY)
6390 /* when selecting string value, execute function for list selection */
6391 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
6392 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
6395 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
6397 void (*menu_callback_function)(void) =
6398 setup_info[first_entry + y].value;
6400 FadeSetFromType(setup_info[first_entry + y].type);
6402 menu_callback_function();
6406 if (setup_info[first_entry + y].type & TYPE_VALUE)
6407 changeSetupValue(y, first_entry + y, dx);
6411 else if (!(setup_info[y].type & TYPE_GHOSTED))
6413 PlaySound(SND_MENU_ITEM_SELECTING);
6415 /* when selecting key headline, execute function for key value change */
6416 if (setup_info[y].type & TYPE_KEYTEXT &&
6417 setup_info[y + 1].type & TYPE_KEY)
6420 /* when selecting string value, execute function for list selection */
6421 if (setup_info[y].type & TYPE_STRING && y > 0 &&
6422 setup_info[y - 1].type & TYPE_ENTER_LIST)
6425 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
6427 void (*menu_callback_function)(void) = setup_info[y].value;
6429 FadeSetFromType(setup_info[y].type);
6431 menu_callback_function();
6435 if (setup_info[y].type & TYPE_VALUE)
6436 changeSetupValue(y, dx);
6443 void DrawSetupScreen_Input()
6448 FadeOut(REDRAW_FIELD);
6454 setup_info = setup_info_input;
6457 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
6461 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6462 "Joysticks deactivated on this screen");
6464 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6465 "Joysticks deactivated on this screen");
6470 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6472 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6475 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6476 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6477 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6478 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6479 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6480 initCursor(i, IMG_MENU_BUTTON);
6482 DrawCursorAndText_Setup(i, -1, FALSE);
6486 DeactivateJoystickForCalibration();
6491 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6492 "Joysticks deactivated on this screen");
6494 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6495 "Joysticks deactivated on this screen");
6499 /* create gadgets for setup input menu screen */
6500 FreeScreenGadgets();
6501 CreateScreenGadgets();
6503 /* map gadgets for setup input menu screen */
6504 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6506 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6509 FadeIn(REDRAW_FIELD);
6515 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6517 if (device_name == NULL)
6520 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6523 if (strlen(device_name) > 1)
6525 char c1 = device_name[strlen(device_name) - 1];
6526 char c2 = device_name[strlen(device_name) - 2];
6528 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6529 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6532 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6533 strlen(device_name));
6536 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6539 static struct SetupKeyboardInfo custom_key;
6546 { &custom_key.left, "Joystick Left" },
6547 { &custom_key.right, "Joystick Right" },
6548 { &custom_key.up, "Joystick Up" },
6549 { &custom_key.down, "Joystick Down" },
6550 { &custom_key.snap, "Button 1" },
6551 { &custom_key.drop, "Button 2" }
6553 static char *joystick_name[MAX_PLAYERS] =
6560 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6564 custom_key = setup.input[player_nr].key;
6566 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6567 FONT_INPUT_1_ACTIVE);
6569 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6571 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6572 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6574 if (setup.input[player_nr].use_joystick)
6576 char *device_name = setup.input[player_nr].joy.device_name;
6577 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6578 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6580 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6581 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6585 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6586 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6589 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6591 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6592 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6593 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6594 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6596 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6597 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6598 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6599 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6600 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6601 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6603 for (i = 0; i < 6; i++)
6605 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6607 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6609 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6610 (setup.input[player_nr].use_joystick ?
6612 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6616 static int input_player_nr = 0;
6618 void HandleSetupScreen_Input_Player(int step, int direction)
6620 int old_player_nr = input_player_nr;
6623 new_player_nr = old_player_nr + step * direction;
6624 if (new_player_nr < 0)
6626 if (new_player_nr > MAX_PLAYERS - 1)
6627 new_player_nr = MAX_PLAYERS - 1;
6629 if (new_player_nr != old_player_nr)
6631 input_player_nr = new_player_nr;
6633 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6637 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6639 static int choice = 0;
6642 int pos_start = SETUPINPUT_SCREEN_POS_START;
6643 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6644 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6645 int pos_end = SETUPINPUT_SCREEN_POS_END;
6647 if (button == MB_MENU_INITIALIZE)
6649 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6651 DrawCursorAndText_Setup(choice, -1, TRUE);
6655 else if (button == MB_MENU_LEAVE)
6657 setup_mode = SETUP_MODE_MAIN;
6664 if (mx || my) /* mouse input */
6666 x = (mx - mSX) / 32;
6667 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6669 else if (dx || dy) /* keyboard input */
6671 if (dx && choice == 0)
6672 x = (dx < 0 ? 10 : 12);
6673 else if ((dx && choice == 1) ||
6674 (dx == +1 && choice == 2) ||
6675 (dx == -1 && choice == pos_end))
6676 button = MB_MENU_CHOICE;
6680 if (y >= pos_empty1 && y <= pos_empty2)
6681 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6684 if (y == 0 && dx != 0 && button)
6686 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6688 else if (IN_VIS_FIELD(x, y) &&
6689 y >= pos_start && y <= pos_end &&
6690 !(y >= pos_empty1 && y <= pos_empty2))
6696 DrawCursorAndText_Setup(choice, -1, FALSE);
6697 DrawCursorAndText_Setup(y, -1, TRUE);
6699 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6708 char *device_name = setup.input[input_player_nr].joy.device_name;
6710 if (!setup.input[input_player_nr].use_joystick)
6712 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6714 setJoystickDeviceToNr(device_name, new_device_nr);
6715 setup.input[input_player_nr].use_joystick = TRUE;
6719 int device_nr = getJoystickNrFromDeviceName(device_name);
6720 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6722 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6723 setup.input[input_player_nr].use_joystick = FALSE;
6725 setJoystickDeviceToNr(device_name, new_device_nr);
6728 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6732 if (setup.input[input_player_nr].use_joystick)
6735 CalibrateJoystick(input_player_nr);
6738 CustomizeKeyboard(input_player_nr);
6740 else if (y == pos_end)
6746 setup_mode = SETUP_MODE_MAIN;
6753 void CustomizeKeyboard(int player_nr)
6757 boolean finished = FALSE;
6758 static struct SetupKeyboardInfo custom_key;
6763 } customize_step[] =
6765 { &custom_key.left, "Move Left" },
6766 { &custom_key.right, "Move Right" },
6767 { &custom_key.up, "Move Up" },
6768 { &custom_key.down, "Move Down" },
6769 { &custom_key.snap, "Snap Field" },
6770 { &custom_key.drop, "Drop Element" }
6773 /* read existing key bindings from player setup */
6774 custom_key = setup.input[player_nr].key;
6777 FadeOut(REDRAW_FIELD);
6781 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6789 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6790 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6791 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6792 "Key:", FONT_INPUT_1_ACTIVE);
6793 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6794 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6797 FadeIn(REDRAW_FIELD);
6804 if (PendingEvent()) /* got event */
6812 case EVENT_KEYPRESS:
6814 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6816 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6818 if (key == KSYM_Escape)
6819 FadeSkipNextFadeIn();
6825 /* all keys configured -- wait for "Escape" or "Return" key */
6829 /* press 'Enter' to keep the existing key binding */
6830 if (key == KSYM_Return)
6831 key = *customize_step[step_nr].key;
6833 /* check if key already used */
6834 for (i = 0; i < step_nr; i++)
6835 if (*customize_step[i].key == key)
6840 /* got new key binding */
6841 *customize_step[step_nr].key = key;
6842 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6844 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6845 getKeyNameFromKey(key), FONT_VALUE_1);
6848 /* un-highlight last query */
6849 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6850 customize_step[step_nr - 1].text, FONT_MENU_1);
6851 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6852 "Key:", FONT_MENU_1);
6854 /* press 'Enter' to leave */
6857 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6858 "Press Enter", FONT_TITLE_1);
6862 /* query next key binding */
6863 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6864 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6865 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6866 "Key:", FONT_INPUT_1_ACTIVE);
6867 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6868 getKeyNameFromKey(*customize_step[step_nr].key),
6873 case EVENT_KEYRELEASE:
6874 key_joystick_mapping = 0;
6878 HandleOtherEvents(&event);
6886 /* don't eat all CPU time */
6890 /* write new key bindings back to player setup */
6891 setup.input[player_nr].key = custom_key;
6894 DrawSetupScreen_Input();
6897 static boolean CalibrateJoystickMain(int player_nr)
6899 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6900 int new_joystick_xright = JOYSTICK_XMIDDLE;
6901 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6902 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6903 int new_joystick_xmiddle, new_joystick_ymiddle;
6905 int joystick_fd = joystick.fd[player_nr];
6906 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6907 boolean check[3][3];
6908 int check_remaining = 3 * 3;
6913 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6916 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6920 FadeOut(REDRAW_FIELD);
6924 for (y = 0; y < 3; y++)
6926 for (x = 0; x < 3; x++)
6928 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6929 check[x][y] = FALSE;
6933 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6934 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6935 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6936 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6937 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6938 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6939 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6941 joy_value = Joystick(player_nr);
6942 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6943 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6945 /* eventually uncalibrated center position (joystick could be uncentered) */
6946 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6949 new_joystick_xmiddle = joy_x;
6950 new_joystick_ymiddle = joy_y;
6952 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6954 FadeIn(REDRAW_FIELD);
6956 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6961 if (PendingEvent()) /* got event */
6969 case EVENT_KEYPRESS:
6970 switch (GetEventKey((KeyEvent *)&event, TRUE))
6973 if (check_remaining == 0)
6978 FadeSkipNextFadeIn();
6987 case EVENT_KEYRELEASE:
6988 key_joystick_mapping = 0;
6992 HandleOtherEvents(&event);
6997 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
7000 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
7001 new_joystick_xright = MAX(new_joystick_xright, joy_x);
7002 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
7003 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
7005 setup.input[player_nr].joy.xleft = new_joystick_xleft;
7006 setup.input[player_nr].joy.yupper = new_joystick_yupper;
7007 setup.input[player_nr].joy.xright = new_joystick_xright;
7008 setup.input[player_nr].joy.ylower = new_joystick_ylower;
7009 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
7010 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
7012 CheckJoystickData();
7014 joy_value = Joystick(player_nr);
7016 if (joy_value & JOY_BUTTON && check_remaining == 0)
7019 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
7020 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
7022 if (x != last_x || y != last_y)
7024 DrawFixedGraphic(xpos + last_x, ypos + last_y,
7025 IMG_MENU_CALIBRATE_YELLOW, 0);
7026 DrawFixedGraphic(xpos + x, ypos + y,
7027 IMG_MENU_CALIBRATE_RED, 0);
7032 if (check_remaining > 0 && !check[x+1][y+1])
7034 check[x+1][y+1] = TRUE;
7040 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
7041 setup.input[player_nr].joy.xleft,
7042 setup.input[player_nr].joy.xmiddle,
7043 setup.input[player_nr].joy.xright);
7044 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
7045 setup.input[player_nr].joy.yupper,
7046 setup.input[player_nr].joy.ymiddle,
7047 setup.input[player_nr].joy.ylower);
7056 /* don't eat all CPU time */
7060 /* calibrated center position (joystick should now be centered) */
7061 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
7064 new_joystick_xmiddle = joy_x;
7065 new_joystick_ymiddle = joy_y;
7070 DrawSetupScreen_Input();
7073 /* wait until the last pressed button was released */
7074 while (Joystick(player_nr) & JOY_BUTTON)
7076 if (PendingEvent()) /* got event */
7081 HandleOtherEvents(&event);
7090 void CalibrateJoystick(int player_nr)
7092 if (!CalibrateJoystickMain(player_nr))
7094 char *device_name = setup.input[player_nr].joy.device_name;
7095 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7096 int xpos = mSX - SX;
7097 int ypos = mSY - SY;
7101 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
7102 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
7105 Delay(2000); /* show error message for a short time */
7111 DrawSetupScreen_Input();
7115 void DrawSetupScreen()
7117 DeactivateJoystick();
7119 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7121 if (setup_mode == SETUP_MODE_INPUT)
7122 DrawSetupScreen_Input();
7123 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7124 DrawChooseTree(&game_speed_current);
7125 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7126 DrawChooseTree(&scroll_delay_current);
7127 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
7128 DrawChooseTree(&screen_mode_current);
7129 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7130 DrawChooseTree(&window_size_current);
7131 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7132 DrawChooseTree(&scaling_type_current);
7133 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7134 DrawChooseTree(&artwork.gfx_current);
7135 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7136 DrawChooseTree(&artwork.snd_current);
7137 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7138 DrawChooseTree(&artwork.mus_current);
7139 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7140 DrawChooseTree(&volume_simple_current);
7141 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7142 DrawChooseTree(&volume_loops_current);
7143 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7144 DrawChooseTree(&volume_music_current);
7145 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7146 DrawChooseTree(&touch_control_current);
7147 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7148 DrawChooseTree(&move_distance_current);
7149 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7150 DrawChooseTree(&drop_distance_current);
7152 DrawSetupScreen_Generic();
7158 void RedrawSetupScreenAfterFullscreenToggle()
7161 if (setup_mode == SETUP_MODE_GRAPHICS ||
7162 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7164 // update list selection from "setup.window_scaling_percent"
7165 execSetupGraphics_setWindowSizes(TRUE);
7170 if (setup_mode == SETUP_MODE_GRAPHICS)
7175 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7177 if (setup_mode == SETUP_MODE_INPUT)
7178 HandleSetupScreen_Input(mx, my, dx, dy, button);
7179 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7180 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7181 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7182 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7183 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
7184 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
7185 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7186 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7187 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7188 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7189 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7190 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7191 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7192 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7193 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7194 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7195 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7196 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7197 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7198 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7199 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7200 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7201 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7202 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7203 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7204 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7205 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7206 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7208 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7215 void HandleGameActions()
7217 if (game_status != GAME_MODE_PLAYING)
7220 GameActions(); /* main game loop */
7222 if (tape.auto_play && !tape.playing)
7223 AutoPlayTape(); /* continue automatically playing next tape */
7227 /* ---------- new screen button stuff -------------------------------------- */
7229 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7234 case SCREEN_CTRL_ID_PREV_LEVEL:
7235 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7236 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7239 case SCREEN_CTRL_ID_NEXT_LEVEL:
7240 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7241 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7244 case SCREEN_CTRL_ID_PREV_LEVEL:
7245 *x = mSX + TILEX * getPrevlevelButtonPos();
7246 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
7249 case SCREEN_CTRL_ID_NEXT_LEVEL:
7250 *x = mSX + TILEX * getNextLevelButtonPos();
7251 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
7255 case SCREEN_CTRL_ID_PREV_PLAYER:
7256 *x = mSX + TILEX * 10;
7257 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7260 case SCREEN_CTRL_ID_NEXT_PLAYER:
7261 *x = mSX + TILEX * 12;
7262 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7266 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7272 int gfx_unpressed, gfx_pressed;
7273 void (*get_gadget_position)(int *, int *, int);
7277 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7280 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7281 getScreenMenuButtonPos,
7282 SCREEN_CTRL_ID_PREV_LEVEL,
7287 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7288 getScreenMenuButtonPos,
7289 SCREEN_CTRL_ID_NEXT_LEVEL,
7294 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7295 getScreenMenuButtonPos,
7296 SCREEN_CTRL_ID_PREV_PLAYER,
7301 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7302 getScreenMenuButtonPos,
7303 SCREEN_CTRL_ID_NEXT_PLAYER,
7311 int gfx_unpressed, gfx_pressed;
7315 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7318 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7320 -1, -1, /* these values are not constant, but can change at runtime */
7322 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
7324 SCREEN_CTRL_ID_SCROLL_UP,
7328 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7330 -1, -1, /* these values are not constant, but can change at runtime */
7332 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
7334 SCREEN_CTRL_ID_SCROLL_DOWN,
7341 int gfx_unpressed, gfx_pressed;
7347 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7350 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7352 -1, -1, /* these values are not constant, but can change at runtime */
7353 -1, -1, /* these values are not constant, but can change at runtime */
7355 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
7356 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
7358 GD_TYPE_SCROLLBAR_VERTICAL,
7359 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7360 "scroll level series vertically"
7364 static void CreateScreenMenubuttons()
7366 struct GadgetInfo *gi;
7367 unsigned int event_mask;
7370 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7372 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7373 int gfx_unpressed, gfx_pressed;
7374 int x, y, width, height;
7375 int gd_x1, gd_x2, gd_y1, gd_y2;
7376 int id = menubutton_info[i].gadget_id;
7378 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7380 menubutton_info[i].get_gadget_position(&x, &y, id);
7382 width = SC_MENUBUTTON_XSIZE;
7383 height = SC_MENUBUTTON_YSIZE;
7385 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7386 gfx_pressed = menubutton_info[i].gfx_pressed;
7387 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7388 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7389 gd_x1 = graphic_info[gfx_unpressed].src_x;
7390 gd_y1 = graphic_info[gfx_unpressed].src_y;
7391 gd_x2 = graphic_info[gfx_pressed].src_x;
7392 gd_y2 = graphic_info[gfx_pressed].src_y;
7394 gi = CreateGadget(GDI_CUSTOM_ID, id,
7395 GDI_CUSTOM_TYPE_ID, i,
7396 GDI_INFO_TEXT, menubutton_info[i].infotext,
7401 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7402 GDI_STATE, GD_BUTTON_UNPRESSED,
7403 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7404 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7405 GDI_DIRECT_DRAW, FALSE,
7406 GDI_EVENT_MASK, event_mask,
7407 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7411 Error(ERR_EXIT, "cannot create gadget");
7413 screen_gadget[id] = gi;
7417 static void CreateScreenScrollbuttons()
7419 struct GadgetInfo *gi;
7420 unsigned int event_mask;
7423 /* these values are not constant, but can change at runtime */
7424 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7425 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7426 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7427 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7429 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7431 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7432 int gfx_unpressed, gfx_pressed;
7433 int x, y, width, height;
7434 int gd_x1, gd_x2, gd_y1, gd_y2;
7435 int id = scrollbutton_info[i].gadget_id;
7437 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7439 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7440 y = mSY + scrollbutton_info[i].y;
7441 width = SC_SCROLLBUTTON_XSIZE;
7442 height = SC_SCROLLBUTTON_YSIZE;
7444 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7445 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7446 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7448 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7449 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7450 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7451 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7452 gd_x1 = graphic_info[gfx_unpressed].src_x;
7453 gd_y1 = graphic_info[gfx_unpressed].src_y;
7454 gd_x2 = graphic_info[gfx_pressed].src_x;
7455 gd_y2 = graphic_info[gfx_pressed].src_y;
7457 gi = CreateGadget(GDI_CUSTOM_ID, id,
7458 GDI_CUSTOM_TYPE_ID, i,
7459 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7464 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7465 GDI_STATE, GD_BUTTON_UNPRESSED,
7466 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7467 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7468 GDI_DIRECT_DRAW, FALSE,
7469 GDI_EVENT_MASK, event_mask,
7470 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7474 Error(ERR_EXIT, "cannot create gadget");
7476 screen_gadget[id] = gi;
7480 static void CreateScreenScrollbars()
7484 /* these values are not constant, but can change at runtime */
7485 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7486 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7487 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7488 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7490 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7492 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7493 int gfx_unpressed, gfx_pressed;
7494 int x, y, width, height;
7495 int gd_x1, gd_x2, gd_y1, gd_y2;
7496 struct GadgetInfo *gi;
7497 int items_max, items_visible, item_position;
7498 unsigned int event_mask;
7499 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7500 int id = scrollbar_info[i].gadget_id;
7502 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7504 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7505 y = mSY + scrollbar_info[i].y;
7506 width = scrollbar_info[i].width;
7507 height = scrollbar_info[i].height;
7509 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7510 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7512 items_max = num_page_entries;
7513 items_visible = num_page_entries;
7516 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7517 gfx_pressed = scrollbar_info[i].gfx_pressed;
7518 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7519 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7520 gd_x1 = graphic_info[gfx_unpressed].src_x;
7521 gd_y1 = graphic_info[gfx_unpressed].src_y;
7522 gd_x2 = graphic_info[gfx_pressed].src_x;
7523 gd_y2 = graphic_info[gfx_pressed].src_y;
7525 gi = CreateGadget(GDI_CUSTOM_ID, id,
7526 GDI_CUSTOM_TYPE_ID, i,
7527 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7532 GDI_TYPE, scrollbar_info[i].type,
7533 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7534 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7535 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7537 GDI_WHEEL_AREA_X, SX,
7538 GDI_WHEEL_AREA_Y, SY,
7539 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7540 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7542 GDI_WHEEL_AREA_X, 0,
7543 GDI_WHEEL_AREA_Y, 0,
7544 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
7545 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
7547 GDI_STATE, GD_BUTTON_UNPRESSED,
7548 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7549 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7550 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7551 GDI_DIRECT_DRAW, FALSE,
7552 GDI_EVENT_MASK, event_mask,
7553 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7557 Error(ERR_EXIT, "cannot create gadget");
7559 screen_gadget[id] = gi;
7563 void CreateScreenGadgets()
7565 int last_game_status = game_status; /* save current game status */
7567 CreateScreenMenubuttons();
7570 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
7571 game_status = GAME_MODE_LEVELS;
7574 CreateScreenScrollbuttons();
7575 CreateScreenScrollbars();
7577 game_status = last_game_status; /* restore current game status */
7580 void FreeScreenGadgets()
7584 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7585 FreeGadget(screen_gadget[i]);
7588 void MapScreenMenuGadgets(int screen_mask)
7592 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7593 if (screen_mask & menubutton_info[i].screen_mask)
7594 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7597 void MapScreenGadgets(int num_entries)
7601 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7604 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7605 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7607 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7608 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7611 void MapScreenTreeGadgets(TreeInfo *ti)
7614 MapScreenGadgets(numTreeInfoInGroup(ti));
7616 int num_entries = numTreeInfoInGroup(ti);
7619 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7622 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7623 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7625 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7626 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7630 static void HandleScreenGadgets(struct GadgetInfo *gi)
7632 int id = gi->custom_id;
7633 int button = gi->event.button;
7634 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7638 case SCREEN_CTRL_ID_PREV_LEVEL:
7639 HandleMainMenu_SelectLevel(step, -1);
7642 case SCREEN_CTRL_ID_NEXT_LEVEL:
7643 HandleMainMenu_SelectLevel(step, +1);
7646 case SCREEN_CTRL_ID_PREV_PLAYER:
7647 HandleSetupScreen_Input_Player(step, -1);
7650 case SCREEN_CTRL_ID_NEXT_PLAYER:
7651 HandleSetupScreen_Input_Player(step, +1);
7654 case SCREEN_CTRL_ID_SCROLL_UP:
7655 if (game_status == GAME_MODE_LEVELS)
7656 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7657 else if (game_status == GAME_MODE_LEVELNR)
7658 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7659 else if (game_status == GAME_MODE_SETUP)
7660 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7663 case SCREEN_CTRL_ID_SCROLL_DOWN:
7664 if (game_status == GAME_MODE_LEVELS)
7665 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7666 else if (game_status == GAME_MODE_LEVELNR)
7667 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7668 else if (game_status == GAME_MODE_SETUP)
7669 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7672 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7673 if (game_status == GAME_MODE_LEVELS)
7674 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7675 else if (game_status == GAME_MODE_LEVELNR)
7676 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7677 else if (game_status == GAME_MODE_SETUP)
7678 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);