1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
28 /* screens on the info screen */
29 #define INFO_MODE_MAIN 0
30 #define INFO_MODE_TITLE 1
31 #define INFO_MODE_ELEMENTS 2
32 #define INFO_MODE_MUSIC 3
33 #define INFO_MODE_CREDITS 4
34 #define INFO_MODE_PROGRAM 5
35 #define INFO_MODE_VERSION 6
36 #define INFO_MODE_LEVELSET 7
38 #define MAX_INFO_MODES 8
40 /* screens on the setup screen */
41 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
42 /* (should also match corresponding entries in src/conf_gfx.c) */
43 #define SETUP_MODE_MAIN 0
44 #define SETUP_MODE_GAME 1
45 #define SETUP_MODE_EDITOR 2
46 #define SETUP_MODE_GRAPHICS 3
47 #define SETUP_MODE_SOUND 4
48 #define SETUP_MODE_ARTWORK 5
49 #define SETUP_MODE_INPUT 6
50 #define SETUP_MODE_SHORTCUTS 7
51 #define SETUP_MODE_SHORTCUTS_1 8
52 #define SETUP_MODE_SHORTCUTS_2 9
53 #define SETUP_MODE_SHORTCUTS_3 10
54 #define SETUP_MODE_SHORTCUTS_4 11
55 #define SETUP_MODE_SHORTCUTS_5 12
57 /* sub-screens on the setup screen (generic) */
58 #define SETUP_MODE_CHOOSE_ARTWORK 13
59 #define SETUP_MODE_CHOOSE_OTHER 14
61 /* sub-screens on the setup screen (specific) */
62 #define SETUP_MODE_CHOOSE_GAME_SPEED 15
63 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 16
64 #define SETUP_MODE_CHOOSE_SCREEN_MODE 17
65 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 18
66 #define SETUP_MODE_CHOOSE_SCALING_TYPE 19
67 #define SETUP_MODE_CHOOSE_GRAPHICS 20
68 #define SETUP_MODE_CHOOSE_SOUNDS 21
69 #define SETUP_MODE_CHOOSE_MUSIC 22
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 23
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 24
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 25
74 #define MAX_SETUP_MODES 26
76 /* for input setup functions */
77 #define SETUPINPUT_SCREEN_POS_START 0
78 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
79 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
80 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
82 /* for various menu stuff */
83 #define MENU_SCREEN_START_XPOS 1
84 #define MENU_SCREEN_START_YPOS 2
86 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
87 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
89 #define MENU_SCREEN_VALUE_XPOS 14
90 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
104 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
105 MENU_SCREEN_INFO_YSTEP, \
106 MAX_INFO_ELEMENTS_ON_SCREEN)
108 #define NUM_INFO_ELEMENTS_ON_SCREEN 10
110 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
112 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
113 MENU_SCREEN_START_XPOS)
114 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
117 /* buttons and scrollbars identifiers */
118 #define SCREEN_CTRL_ID_PREV_LEVEL 0
119 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
120 #define SCREEN_CTRL_ID_PREV_PLAYER 2
121 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
122 #define SCREEN_CTRL_ID_SCROLL_UP 4
123 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
124 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
126 #define NUM_SCREEN_GADGETS 7
128 #define NUM_SCREEN_MENUBUTTONS 4
129 #define NUM_SCREEN_SCROLLBUTTONS 2
130 #define NUM_SCREEN_SCROLLBARS 1
132 #define SCREEN_MASK_MAIN (1 << 0)
133 #define SCREEN_MASK_INPUT (1 << 1)
135 /* graphic position and size values for buttons and scrollbars */
136 #define SC_MENUBUTTON_XSIZE TILEX
137 #define SC_MENUBUTTON_YSIZE TILEY
139 #define SC_SCROLLBUTTON_XSIZE TILEX
140 #define SC_SCROLLBUTTON_YSIZE TILEY
142 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
144 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
145 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
146 SC_SCROLLBUTTON_YSIZE)
148 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
149 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
151 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
152 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
153 SC_SCROLLBUTTON_YSIZE)
155 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
156 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
157 SC_SCROLL_VERTICAL_YSIZE)
159 #define SC_BORDER_SIZE 14
162 /* forward declarations of internal functions */
163 static void HandleScreenGadgets(struct GadgetInfo *);
164 static void HandleSetupScreen_Generic(int, int, int, int, int);
165 static void HandleSetupScreen_Input(int, int, int, int, int);
166 static void CustomizeKeyboard(int);
167 static void CalibrateJoystick(int);
168 static void execSetupGame(void);
169 static void execSetupGraphics(void);
170 static void execSetupSound(void);
171 static void execSetupArtwork(void);
172 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
174 static void DrawChooseLevelSet(void);
175 static void DrawChooseLevelNr(void);
176 static void DrawInfoScreen(void);
177 static void DrawAndFadeInInfoScreen(int);
178 static void DrawSetupScreen(void);
180 static void DrawInfoScreenExt(int, int);
181 static void DrawInfoScreen_NotAvailable(char *, char *);
182 static void DrawInfoScreen_HelpAnim(int, int, boolean);
183 static void DrawInfoScreen_HelpText(int, int, int, int);
184 static void HandleInfoScreen_Main(int, int, int, int, int);
185 static void HandleInfoScreen_TitleScreen(int);
186 static void HandleInfoScreen_Elements(int);
187 static void HandleInfoScreen_Music(int);
188 static void HandleInfoScreen_Credits(int);
189 static void HandleInfoScreen_Program(int);
190 static void HandleInfoScreen_Version(int);
192 static void MapScreenMenuGadgets(int);
193 static void MapScreenGadgets(int);
194 static void MapScreenTreeGadgets(TreeInfo *);
196 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
198 static int info_mode = INFO_MODE_MAIN;
199 static int setup_mode = SETUP_MODE_MAIN;
201 static TreeInfo *screen_modes = NULL;
202 static TreeInfo *screen_mode_current = NULL;
204 static TreeInfo *window_sizes = NULL;
205 static TreeInfo *window_size_current = NULL;
207 static TreeInfo *scaling_types = NULL;
208 static TreeInfo *scaling_type_current = NULL;
210 static TreeInfo *scroll_delays = NULL;
211 static TreeInfo *scroll_delay_current = NULL;
213 static TreeInfo *game_speeds = NULL;
214 static TreeInfo *game_speed_current = NULL;
216 static TreeInfo *volumes_simple = NULL;
217 static TreeInfo *volume_simple_current = NULL;
219 static TreeInfo *volumes_loops = NULL;
220 static TreeInfo *volume_loops_current = NULL;
222 static TreeInfo *volumes_music = NULL;
223 static TreeInfo *volume_music_current = NULL;
225 static TreeInfo *level_number = NULL;
226 static TreeInfo *level_number_current = NULL;
232 } window_sizes_list[] =
237 { 100, "100 % (Default)" },
254 } scaling_types_list[] =
256 { SCALING_QUALITY_NEAREST, "None" },
257 { SCALING_QUALITY_LINEAR, "Linear" },
258 { SCALING_QUALITY_BEST, "Anisotropic" },
267 } game_speeds_list[] =
276 { 1000, "1/1s (Extremely Slow)" },
281 { 29, "1/35s (Original Supaplex)" },
283 { 20, "1/50s (Normal Speed)" },
284 { 14, "1/70s (Maximum Supaplex)" },
288 { 1, "1/1000s (Extremely Fast)" },
298 } scroll_delays_list[] =
300 { 0, "0 Tiles (No Scroll Delay)" },
303 { 3, "3 Tiles (Default)" },
308 { 8, "8 Tiles (Maximum Scroll Delay)"},
334 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
335 (s) <= GAME_MODE_SETUP ? (s) : \
336 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
337 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
339 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
340 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
341 (i) <= INFO_MODE_LEVELSET ? (i) : \
344 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
345 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
346 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
347 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
348 SETUP_MODE_CHOOSE_ARTWORK : \
349 SETUP_MODE_CHOOSE_OTHER)
351 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
352 menu.draw_xoffset[GAME_MODE_INFO] : \
353 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
354 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
355 menu.draw_yoffset[GAME_MODE_INFO] : \
356 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
358 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
359 menu.draw_xoffset[GAME_MODE_SETUP] : \
360 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
361 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
362 menu.draw_yoffset[GAME_MODE_SETUP] : \
363 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
365 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
366 DRAW_XOFFSET_INFO(info_mode) : \
367 (s) == GAME_MODE_SETUP ? \
368 DRAW_XOFFSET_SETUP(setup_mode) : \
369 menu.draw_xoffset[DRAW_MODE(s)])
370 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
371 DRAW_YOFFSET_INFO(info_mode) : \
372 (s) == GAME_MODE_SETUP ? \
373 DRAW_YOFFSET_SETUP(setup_mode) : \
374 menu.draw_yoffset[DRAW_MODE(s)])
376 #define mSX (SX + DRAW_XOFFSET(game_status))
377 #define mSY (SY + DRAW_YOFFSET(game_status))
379 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
380 menu.list_size[game_status] : \
381 MAX_MENU_ENTRIES_ON_SCREEN)
383 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
384 #define NUM_SCROLLBAR_BITMAPS 2
385 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
389 /* title display and control definitions */
391 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
392 2 * MAX_NUM_TITLE_MESSAGES)
394 static int num_title_screens = 0;
396 struct TitleControlInfo
404 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
406 /* main menu display and control definitions */
408 #define MAIN_CONTROL_NAME 0
409 #define MAIN_CONTROL_LEVELS 1
410 #define MAIN_CONTROL_SCORES 2
411 #define MAIN_CONTROL_EDITOR 3
412 #define MAIN_CONTROL_INFO 4
413 #define MAIN_CONTROL_GAME 5
414 #define MAIN_CONTROL_SETUP 6
415 #define MAIN_CONTROL_QUIT 7
416 #define MAIN_CONTROL_PREV_LEVEL 8
417 #define MAIN_CONTROL_NEXT_LEVEL 9
418 #define MAIN_CONTROL_FIRST_LEVEL 10
419 #define MAIN_CONTROL_LAST_LEVEL 11
420 #define MAIN_CONTROL_LEVEL_NUMBER 12
421 #define MAIN_CONTROL_LEVEL_INFO_1 13
422 #define MAIN_CONTROL_LEVEL_INFO_2 14
423 #define MAIN_CONTROL_LEVEL_NAME 15
424 #define MAIN_CONTROL_LEVEL_AUTHOR 16
425 #define MAIN_CONTROL_LEVEL_YEAR 17
426 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
427 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
428 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
429 #define MAIN_CONTROL_TITLE_1 21
430 #define MAIN_CONTROL_TITLE_2 22
431 #define MAIN_CONTROL_TITLE_3 23
433 static char str_main_text_name[10];
434 static char str_main_text_first_level[10];
435 static char str_main_text_last_level[10];
436 static char str_main_text_level_number[10];
438 static char *main_text_name = str_main_text_name;
439 static char *main_text_first_level = str_main_text_first_level;
440 static char *main_text_last_level = str_main_text_last_level;
441 static char *main_text_level_number = str_main_text_level_number;
442 static char *main_text_levels = "Levelset";
443 static char *main_text_scores = "Hall Of Fame";
444 static char *main_text_editor = "Level Creator";
445 static char *main_text_info = "Info Screen";
446 static char *main_text_game = "Start Game";
447 static char *main_text_setup = "Setup";
448 static char *main_text_quit = "Quit";
449 static char *main_text_level_name = level.name;
450 static char *main_text_level_author = level.author;
451 static char *main_text_level_year = NULL;
452 static char *main_text_level_imported_from = NULL;
453 static char *main_text_level_imported_by = NULL;
454 static char *main_text_level_tested_by = NULL;
455 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
456 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
457 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
459 struct MainControlInfo
463 struct MenuPosInfo *pos_button;
466 struct TextPosInfo *pos_text;
469 struct TextPosInfo *pos_input;
473 static struct MainControlInfo main_controls[] =
477 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
478 &menu.main.text.name, &main_text_name,
479 &menu.main.input.name, &setup.player_name,
483 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
484 &menu.main.text.levels, &main_text_levels,
489 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
490 &menu.main.text.scores, &main_text_scores,
495 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
496 &menu.main.text.editor, &main_text_editor,
501 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
502 &menu.main.text.info, &main_text_info,
507 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
508 &menu.main.text.game, &main_text_game,
513 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
514 &menu.main.text.setup, &main_text_setup,
519 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
520 &menu.main.text.quit, &main_text_quit,
524 /* (these two buttons are real gadgets) */
526 MAIN_CONTROL_PREV_LEVEL,
527 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
532 MAIN_CONTROL_NEXT_LEVEL,
533 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
539 MAIN_CONTROL_FIRST_LEVEL,
541 &menu.main.text.first_level, &main_text_first_level,
545 MAIN_CONTROL_LAST_LEVEL,
547 &menu.main.text.last_level, &main_text_last_level,
551 MAIN_CONTROL_LEVEL_NUMBER,
553 &menu.main.text.level_number, &main_text_level_number,
557 MAIN_CONTROL_LEVEL_INFO_1,
559 &menu.main.text.level_info_1, NULL,
563 MAIN_CONTROL_LEVEL_INFO_2,
565 &menu.main.text.level_info_2, NULL,
569 MAIN_CONTROL_LEVEL_NAME,
571 &menu.main.text.level_name, &main_text_level_name,
575 MAIN_CONTROL_LEVEL_AUTHOR,
577 &menu.main.text.level_author, &main_text_level_author,
581 MAIN_CONTROL_LEVEL_YEAR,
583 &menu.main.text.level_year, &main_text_level_year,
587 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
589 &menu.main.text.level_imported_from, &main_text_level_imported_from,
593 MAIN_CONTROL_LEVEL_IMPORTED_BY,
595 &menu.main.text.level_imported_by, &main_text_level_imported_by,
599 MAIN_CONTROL_LEVEL_TESTED_BY,
601 &menu.main.text.level_tested_by, &main_text_level_tested_by,
605 MAIN_CONTROL_TITLE_1,
607 &menu.main.text.title_1, &main_text_title_1,
611 MAIN_CONTROL_TITLE_2,
613 &menu.main.text.title_2, &main_text_title_2,
617 MAIN_CONTROL_TITLE_3,
619 &menu.main.text.title_3, &main_text_title_3,
632 static int getTitleScreenGraphic(int nr, boolean initial)
634 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
637 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
639 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
643 static int getTitleScreenGameMode(boolean initial)
645 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
649 static int getTitleMessageGameMode(boolean initial)
651 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
655 static int getTitleScreenBackground(boolean initial)
657 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
662 static int getTitleMessageBackground(int nr, boolean initial)
664 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
668 static int getTitleBackground(int nr, boolean initial, boolean is_image)
670 int base = (is_image ?
671 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
672 IMG_BACKGROUND_TITLESCREEN_1) :
673 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
674 IMG_BACKGROUND_TITLEMESSAGE_1));
675 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
676 IMG_BACKGROUND_TITLE);
677 int graphic_local = base + nr;
679 if (graphic_info[graphic_local].bitmap != NULL)
680 return graphic_local;
682 if (graphic_info[graphic_global].bitmap != NULL)
683 return graphic_global;
685 return IMG_UNDEFINED;
688 static int getTitleSound(struct TitleControlInfo *tci)
690 boolean is_image = tci->is_image;
691 int initial = tci->initial;
692 int nr = tci->local_nr;
693 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
694 int base = (is_image ?
695 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
696 SND_BACKGROUND_TITLESCREEN_1) :
697 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
698 SND_BACKGROUND_TITLEMESSAGE_1));
699 int sound_global = menu.sound[mode];
700 int sound_local = base + nr;
703 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
704 nr, initial, is_image,
705 sound_global, getSoundListEntry(sound_global)->filename,
706 sound_local, getSoundListEntry(sound_local)->filename);
709 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
712 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
715 return SND_UNDEFINED;
718 static int getTitleMusic(struct TitleControlInfo *tci)
720 boolean is_image = tci->is_image;
721 int initial = tci->initial;
722 int nr = tci->local_nr;
723 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
724 int base = (is_image ?
725 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
726 MUS_BACKGROUND_TITLESCREEN_1) :
727 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
728 MUS_BACKGROUND_TITLEMESSAGE_1));
729 int music_global = menu.music[mode];
730 int music_local = base + nr;
733 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
734 nr, initial, is_image,
735 music_global, getMusicListEntry(music_global)->filename,
736 music_local, getMusicListEntry(music_local)->filename);
739 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
742 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
745 return MUS_UNDEFINED;
748 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
750 boolean is_image = tci->is_image;
751 int initial = tci->initial;
752 int nr = tci->local_nr;
753 struct TitleFadingInfo ti;
757 int graphic = getTitleScreenGraphic(nr, initial);
759 /* initialize fading control values to default title config settings */
760 ti = (initial ? title_initial_default : title_default);
762 /* override default settings with image config settings, if defined */
763 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
764 ti.fade_mode = graphic_info[graphic].fade_mode;
765 if (graphic_info[graphic].fade_delay > -1)
766 ti.fade_delay = graphic_info[graphic].fade_delay;
767 if (graphic_info[graphic].post_delay > -1)
768 ti.post_delay = graphic_info[graphic].post_delay;
769 if (graphic_info[graphic].auto_delay > -1)
770 ti.auto_delay = graphic_info[graphic].auto_delay;
776 ti.fade_mode = titlemessage_initial[nr].fade_mode;
777 ti.fade_delay = titlemessage_initial[nr].fade_delay;
778 ti.post_delay = titlemessage_initial[nr].post_delay;
779 ti.auto_delay = titlemessage_initial[nr].auto_delay;
783 ti.fade_mode = titlemessage[nr].fade_mode;
784 ti.fade_delay = titlemessage[nr].fade_delay;
785 ti.post_delay = titlemessage[nr].post_delay;
786 ti.auto_delay = titlemessage[nr].auto_delay;
791 if (ti.anim_mode == ANIM_NONE)
792 ti.fade_delay = ti.post_delay = 0;
798 static int compareTitleControlInfo(const void *object1, const void *object2)
800 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
801 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
804 if (tci1->initial != tci2->initial)
805 compare_result = (tci1->initial ? -1 : +1);
806 else if (tci1->sort_priority != tci2->sort_priority)
807 compare_result = tci1->sort_priority - tci2->sort_priority;
808 else if (tci1->is_image != tci2->is_image)
809 compare_result = (tci1->is_image ? -1 : +1);
811 compare_result = tci1->local_nr - tci2->local_nr;
813 return compare_result;
816 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
818 int nr, int sort_priority)
820 title_controls[num_title_screens].is_image = is_image;
821 title_controls[num_title_screens].initial = initial;
822 title_controls[num_title_screens].local_nr = nr;
823 title_controls[num_title_screens].sort_priority = sort_priority;
828 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
832 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
834 int graphic = getTitleScreenGraphic(i, initial);
835 Bitmap *bitmap = graphic_info[graphic].bitmap;
836 int sort_priority = graphic_info[graphic].sort_priority;
839 /* skip images and messages (fonts!) when using forced custom graphics */
840 if (setup.override_level_graphics && !initial)
845 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
848 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
850 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
851 char *filename = getLevelSetTitleMessageFilename(i, initial);
852 int sort_priority = tmi->sort_priority;
855 /* skip images and messages (fonts!) when using forced custom graphics */
856 if (setup.override_level_graphics)
860 if (filename != NULL)
861 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
865 static void InitializeTitleControls(boolean show_title_initial)
867 num_title_screens = 0;
870 /* 1st step: initialize title screens for game start (only when starting) */
871 if (show_title_initial)
872 InitializeTitleControls_CheckTitleInfo(TRUE);
875 /* 2nd step: initialize title screens for current level set */
876 InitializeTitleControls_CheckTitleInfo(FALSE);
878 /* sort title screens according to sort_priority and title number */
879 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
880 compareTitleControlInfo);
883 static boolean visibleMenuPos(struct MenuPosInfo *pos)
885 return (pos != NULL && pos->x != -1 && pos->y != -1);
888 static boolean visibleTextPos(struct TextPosInfo *pos)
890 return (pos != NULL && pos->x != -1 && pos->y != -1);
893 static void InitializeMainControls()
895 boolean local_team_mode = (!options.network && setup.team_mode);
898 /* set main control text values to dynamically determined values */
899 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
901 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
902 menu.main.text.first_level.size));
903 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
904 menu.main.text.last_level.size));
905 strcpy(main_text_level_number, int2str(level_nr,
906 menu.main.text.level_number.size));
908 main_text_level_year = leveldir_current->year;
909 main_text_level_imported_from = leveldir_current->imported_from;
910 main_text_level_imported_by = leveldir_current->imported_by;
911 main_text_level_tested_by = leveldir_current->tested_by;
913 /* set main control screen positions to dynamically determined values */
914 for (i = 0; main_controls[i].nr != -1; i++)
916 struct MainControlInfo *mci = &main_controls[i];
918 struct MenuPosInfo *pos_button = mci->pos_button;
919 struct TextPosInfo *pos_text = mci->pos_text;
920 struct TextPosInfo *pos_input = mci->pos_input;
921 char *text = (mci->text ? *mci->text : NULL);
922 char *input = (mci->input ? *mci->input : NULL);
923 int button_graphic = mci->button_graphic;
925 int font_text = (pos_text ? pos_text->font : -1);
926 int font_input = (pos_input ? pos_input->font : -1);
928 int font_text = mci->font_text;
929 int font_input = mci->font_input;
932 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
933 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
934 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
935 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
936 int text_chars = (text != NULL ? strlen(text) : 0);
937 int input_chars = (input != NULL ? strlen(input) : 0);
940 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
942 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
943 int text_width = font_text_width * text_chars;
944 int text_height = font_text_height;
945 int input_width = font_input_width * input_chars;
946 int input_height = font_input_height;
948 if (nr == MAIN_CONTROL_NAME)
951 if (menu.main.input.name.x == -1)
952 menu.main.input.name.x = menu.main.text.name.x + text_width;
953 if (menu.main.input.name.y == -1)
954 menu.main.input.name.y = menu.main.text.name.y;
958 menu.main.input.name.width = input_width;
959 menu.main.input.name.height = input_height;
961 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
962 menu.main.input.name.height = font_input_height;
966 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
968 if (pos_button->width == 0)
969 pos_button->width = button_width;
970 if (pos_button->height == 0)
971 pos_button->height = button_height;
974 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
977 /* calculate size for non-clickable text -- needed for text alignment */
978 boolean calculate_text_size = (pos_button == NULL && text != NULL);
980 /* calculate width for non-clickable text -- needed for text alignment */
981 boolean calculate_text_width = (pos_button == NULL && text != NULL);
984 if (visibleMenuPos(pos_button))
986 if (pos_text->x == -1)
987 pos_text->x = pos_button->x + pos_button->width;
988 if (pos_text->y == -1)
989 pos_text->y = pos_button->y;
993 if (pos_text->width == -1 || calculate_text_size)
994 pos_text->width = text_width;
995 if (pos_text->height == -1 || calculate_text_size)
996 pos_text->height = text_height;
998 if (pos_text->width == -1 || calculate_text_width)
999 pos_text->width = text_width;
1000 if (pos_text->height == -1)
1001 pos_text->height = text_height;
1005 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1007 if (visibleTextPos(pos_text))
1009 if (pos_input->x == -1)
1010 pos_input->x = pos_text->x + pos_text->width;
1011 if (pos_input->y == -1)
1012 pos_input->y = pos_text->y;
1015 if (pos_input->width == -1)
1016 pos_input->width = input_width;
1017 if (pos_input->height == -1)
1018 pos_input->height = input_height;
1023 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1024 boolean active_input)
1028 for (i = 0; main_controls[i].nr != -1; i++)
1030 struct MainControlInfo *mci = &main_controls[i];
1032 if (mci->nr == nr || nr == -1)
1034 struct MenuPosInfo *pos_button = mci->pos_button;
1035 struct TextPosInfo *pos_text = mci->pos_text;
1036 struct TextPosInfo *pos_input = mci->pos_input;
1037 char *text = (mci->text ? *mci->text : NULL);
1038 char *input = (mci->input ? *mci->input : NULL);
1039 int button_graphic = mci->button_graphic;
1041 int font_text = (pos_text ? pos_text->font : -1);
1042 int font_input = (pos_input ? pos_input->font : -1);
1044 int font_text = mci->font_text;
1045 int font_input = mci->font_input;
1050 button_graphic = BUTTON_ACTIVE(button_graphic);
1051 font_text = FONT_ACTIVE(font_text);
1056 font_input = FONT_ACTIVE(font_input);
1059 if (visibleMenuPos(pos_button))
1061 struct MenuPosInfo *pos = pos_button;
1062 int x = mSX + pos->x;
1063 int y = mSY + pos->y;
1065 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1066 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1069 if (visibleTextPos(pos_text) && text != NULL)
1071 struct TextPosInfo *pos = pos_text;
1072 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1073 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1076 /* (check why/if this is needed) */
1077 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1079 DrawText(x, y, text, font_text);
1082 if (visibleTextPos(pos_input) && input != NULL)
1084 struct TextPosInfo *pos = pos_input;
1085 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1086 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1089 /* (check why/if this is needed) */
1090 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1092 DrawText(x, y, input, font_input);
1098 static void DrawCursorAndText_Main(int nr, boolean active_text)
1100 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1104 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1106 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1110 static struct MainControlInfo *getMainControlInfo(int nr)
1114 for (i = 0; main_controls[i].nr != -1; i++)
1115 if (main_controls[i].nr == nr)
1116 return &main_controls[i];
1121 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1126 int rect_x = ALIGNED_TEXT_XPOS(rect);
1127 int rect_y = ALIGNED_TEXT_YPOS(rect);
1129 return (x >= rect_x && x < rect_x + rect->width &&
1130 y >= rect_y && y < rect_y + rect->height);
1133 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1138 int rect_x = ALIGNED_TEXT_XPOS(rect);
1139 int rect_y = ALIGNED_TEXT_YPOS(rect);
1142 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1143 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1144 (x >= rect_x && x < rect_x + rect->width &&
1145 y >= rect_y && y < rect_y + rect->height));
1148 return (x >= rect_x && x < rect_x + rect->width &&
1149 y >= rect_y && y < rect_y + rect->height);
1152 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1155 static int cursor_array[MAX_LEV_FIELDY];
1157 static int cursor_array[SCR_FIELDY];
1159 int x = mSX + TILEX * xpos;
1160 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1165 cursor_array[ypos] = graphic;
1167 graphic = cursor_array[ypos];
1171 graphic = BUTTON_ACTIVE(graphic);
1173 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1174 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1177 static void initCursor(int ypos, int graphic)
1179 drawCursorExt(0, ypos, FALSE, graphic);
1182 static void drawCursor(int ypos, boolean active)
1184 drawCursorExt(0, ypos, active, -1);
1187 static void drawCursorXY(int xpos, int ypos, int graphic)
1189 drawCursorExt(xpos, ypos, FALSE, graphic);
1192 static void drawChooseTreeCursor(int ypos, boolean active)
1194 int last_game_status = game_status; /* save current game status */
1197 /* force LEVELS draw offset on artwork setup screen */
1198 game_status = GAME_MODE_LEVELS;
1201 drawCursorExt(0, ypos, active, -1);
1203 game_status = last_game_status; /* restore current game status */
1208 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1209 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1213 static int getPrevlevelButtonPos()
1218 static int getCurrentLevelTextPos()
1220 return (getPrevlevelButtonPos() + 1);
1223 static int getNextLevelButtonPos()
1225 return getPrevlevelButtonPos() + 3 + 1;
1228 static int getLevelRangeTextPos()
1230 return getNextLevelButtonPos() + 1;
1234 int effectiveGameStatus()
1236 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1237 return GAME_MODE_TITLE;
1242 void DrawTitleScreenImage(int nr, boolean initial)
1244 int graphic = getTitleScreenGraphic(nr, initial);
1245 Bitmap *bitmap = graphic_info[graphic].bitmap;
1246 int width = graphic_info[graphic].width;
1247 int height = graphic_info[graphic].height;
1248 int src_x = graphic_info[graphic].src_x;
1249 int src_y = graphic_info[graphic].src_y;
1255 if (width > WIN_XSIZE)
1257 /* image width too large for window => center image horizontally */
1258 src_x = (width - WIN_XSIZE) / 2;
1262 if (height > WIN_YSIZE)
1264 /* image height too large for window => center image vertically */
1265 src_y = (height - WIN_YSIZE) / 2;
1269 /* always display title screens centered */
1270 dst_x = (WIN_XSIZE - width) / 2;
1271 dst_y = (WIN_YSIZE - height) / 2;
1273 SetDrawBackgroundMask(REDRAW_ALL);
1274 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1276 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1278 if (DrawingOnBackground(dst_x, dst_y))
1280 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1281 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1284 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1286 redraw_mask = REDRAW_ALL;
1289 void DrawTitleScreenMessage(int nr, boolean initial)
1291 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1292 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1293 int last_game_status = game_status; /* save current game status */
1295 if (filename == NULL)
1298 /* force TITLE font on title message screen */
1299 game_status = getTitleMessageGameMode(initial);
1301 /* if chars set to "-1", automatically determine by text and font width */
1302 if (tmi->chars == -1)
1303 tmi->chars = tmi->width / getFontWidth(tmi->font);
1305 tmi->width = tmi->chars * getFontWidth(tmi->font);
1307 /* if lines set to "-1", automatically determine by text and font height */
1308 if (tmi->lines == -1)
1309 tmi->lines = tmi->height / getFontHeight(tmi->font);
1311 tmi->height = tmi->lines * getFontHeight(tmi->font);
1313 SetDrawBackgroundMask(REDRAW_ALL);
1314 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1316 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1318 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1319 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1320 tmi->autowrap, tmi->centered, tmi->parse_comments);
1322 game_status = last_game_status; /* restore current game status */
1325 void DrawTitleScreen()
1327 KeyboardAutoRepeatOff();
1330 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1333 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1338 boolean CheckTitleScreen(boolean levelset_has_changed)
1340 static boolean show_title_initial = TRUE;
1341 boolean show_titlescreen = FALSE;
1343 /* needed to be able to skip title screen, if no image or message defined */
1344 InitializeTitleControls(show_title_initial);
1346 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1347 show_titlescreen = TRUE;
1349 /* show initial title images and messages only once at program start */
1350 show_title_initial = FALSE;
1352 return (show_titlescreen && num_title_screens > 0);
1355 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1357 static LevelDirTree *leveldir_last_valid = NULL;
1358 boolean levelset_has_changed = FALSE;
1360 LimitScreenUpdates(FALSE);
1362 FadeSetLeaveScreen();
1364 /* do not fade out here -- function may continue and fade on editor screen */
1367 FadeSoundsAndMusic();
1369 KeyboardAutoRepeatOn();
1372 SetDrawDeactivationMask(REDRAW_NONE);
1373 SetDrawBackgroundMask(REDRAW_FIELD);
1375 audio.sound_deactivated = FALSE;
1379 /* needed if last screen was the playing screen, invoked from level editor */
1380 if (level_editor_test_game)
1382 game_status = GAME_MODE_EDITOR;
1388 /* needed if last screen was the setup screen and fullscreen state changed */
1389 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1390 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1392 /* leveldir_current may be invalid (level group, parent link) */
1393 if (!validLevelSeries(leveldir_current))
1394 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1396 if (leveldir_current != leveldir_last_valid)
1397 levelset_has_changed = TRUE;
1399 /* store valid level series information */
1400 leveldir_last_valid = leveldir_current;
1402 init_last = init; /* switch to new busy animation */
1404 /* needed if last screen (level choice) changed graphics, sounds or music */
1405 ReloadCustomArtwork(0);
1407 if (redraw_mask & REDRAW_ALL)
1408 fade_mask = REDRAW_ALL;
1414 /* needed if last screen was the editor screen */
1415 UndrawSpecialEditorDoor();
1419 if (fade_mask == REDRAW_FIELD)
1425 /* needed if different viewport properties defined for menues */
1426 ChangeViewportPropertiesIfNeeded();
1430 /* needed if last screen was the editor screen */
1431 UndrawSpecialEditorDoor();
1434 #if defined(TARGET_SDL)
1435 SetDrawtoField(DRAW_BACKBUFFER);
1438 if (CheckTitleScreen(levelset_has_changed))
1440 game_status = GAME_MODE_TITLE;
1447 /* level_nr may have been set to value over handicap with level editor */
1448 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1449 level_nr = leveldir_current->handicap_level;
1451 LoadLevel(level_nr);
1452 LoadScore(level_nr);
1454 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1457 if (fade_mask == REDRAW_ALL)
1459 // int door_state = GetDoorState();
1463 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1469 InitializeMainControls();
1471 DrawCursorAndText_Main(-1, FALSE);
1472 DrawPreviewLevelInitial();
1474 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1477 if (TAPE_IS_EMPTY(tape))
1479 DrawCompleteVideoDisplay();
1484 /* create gadgets for main menu screen */
1485 FreeScreenGadgets();
1486 CreateScreenGadgets();
1488 /* map gadgets for main menu screen */
1490 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1493 /* copy actual game door content to door double buffer for OpenDoor() */
1494 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1498 if (fade_mask == REDRAW_ALL)
1500 int door_state = GetDoorState();
1502 // RedrawBackground();
1504 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1508 DrawMaskedBorder(REDRAW_ALL);
1514 /* update screen area with special editor door */
1515 redraw_mask |= REDRAW_ALL;
1519 SetMouseCursor(CURSOR_DEFAULT);
1523 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1526 void DrawAndFadeInMainMenu(int fade_mask)
1528 DrawMainMenuExt(fade_mask, TRUE);
1533 DrawMainMenuExt(REDRAW_ALL, FALSE);
1536 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1537 static void gotoTopLevelDir()
1539 /* move upwards to top level directory */
1540 while (leveldir_current->node_parent)
1542 /* write a "path" into level tree for easy navigation to last level */
1543 if (leveldir_current->node_parent->node_group->cl_first == -1)
1545 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1546 int leveldir_pos = posTreeInfo(leveldir_current);
1547 int num_page_entries;
1548 int cl_first, cl_cursor;
1550 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1551 num_page_entries = num_leveldirs;
1553 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1555 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1556 cl_cursor = leveldir_pos - cl_first;
1558 leveldir_current->node_parent->node_group->cl_first = cl_first;
1559 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1562 leveldir_current = leveldir_current->node_parent;
1567 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1569 static unsigned int title_delay = 0;
1570 static int title_screen_nr = 0;
1571 static int last_sound = -1, last_music = -1;
1572 boolean return_to_main_menu = FALSE;
1573 boolean use_fading_main_menu = TRUE;
1574 struct TitleControlInfo *tci;
1575 struct TitleFadingInfo fading_default;
1576 struct TitleFadingInfo fading_last = fading;
1577 struct TitleFadingInfo fading_next;
1580 if (button == MB_MENU_INITIALIZE)
1583 title_screen_nr = 0;
1584 tci = &title_controls[title_screen_nr];
1586 last_sound = SND_UNDEFINED;
1587 last_music = MUS_UNDEFINED;
1589 if (game_status == GAME_MODE_INFO)
1591 if (num_title_screens == 0)
1593 DrawInfoScreen_NotAvailable("Title screen information:",
1594 "No title screen for this level set.");
1599 FadeSoundsAndMusic();
1602 FadeOut(REDRAW_ALL);
1607 DrawTitleScreenImage(tci->local_nr, tci->initial);
1609 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1611 fading_default = (tci->initial ? title_initial_default : title_default);
1613 fading = fading_next = getTitleFading(tci);
1617 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1618 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1620 fading.fade_mode = FADE_MODE_FADE;
1621 fading.fade_delay = fading_default.fade_delay;
1624 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1625 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1626 fading.fade_mode = FADE_MODE_FADE;
1631 sound = getTitleSound(tci);
1632 music = getTitleMusic(tci);
1634 if (sound != last_sound)
1635 PlayMenuSoundExt(sound);
1636 if (music != last_music)
1637 PlayMenuMusicExt(music);
1643 SetMouseCursor(CURSOR_NONE);
1649 fading = fading_next;
1651 DelayReached(&title_delay, 0); /* reset delay counter */
1657 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1658 button = MB_MENU_CHOICE;
1660 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1661 button = MB_MENU_CHOICE;
1664 if (button == MB_MENU_LEAVE)
1666 return_to_main_menu = TRUE;
1667 use_fading_main_menu = FALSE;
1669 else if (button == MB_MENU_CHOICE)
1671 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1674 FadeOut(REDRAW_FIELD);
1677 FadeSetEnterScreen();
1679 info_mode = INFO_MODE_MAIN;
1680 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1686 tci = &title_controls[title_screen_nr];
1688 if (title_screen_nr < num_title_screens)
1690 sound = getTitleSound(tci);
1691 music = getTitleMusic(tci);
1693 if (sound == SND_UNDEFINED || sound != last_sound)
1695 if (music == MUS_UNDEFINED || music != last_music)
1699 FadeOut(REDRAW_ALL);
1703 DrawTitleScreenImage(tci->local_nr, tci->initial);
1705 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1707 fading_next = getTitleFading(tci);
1710 sound = getTitleSound(tci);
1711 music = getTitleMusic(tci);
1713 if (sound != last_sound)
1714 PlayMenuSoundExt(sound);
1715 if (music != last_music)
1716 PlayMenuMusicExt(music);
1723 /* last screen already faded out, next screen has no animation */
1724 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1725 fading_next.fade_mode == FADE_MODE_NONE)
1726 fading = fading_next;
1728 /* last screen already faded out, next screen has no animation */
1729 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1730 fading_next.fade_mode == FADE_MODE_NONE)
1731 fading = fading_next;
1738 fading = fading_next;
1740 DelayReached(&title_delay, 0); /* reset delay counter */
1744 FadeSoundsAndMusic();
1746 return_to_main_menu = TRUE;
1750 if (return_to_main_menu)
1756 SetMouseCursor(CURSOR_DEFAULT);
1758 if (game_status == GAME_MODE_INFO)
1761 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1764 info_mode = INFO_MODE_MAIN;
1765 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1767 else /* default: return to main menu */
1770 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1773 game_status = GAME_MODE_MAIN;
1774 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1779 void HandleMainMenu_SelectLevel(int step, int direction)
1781 int old_level_nr = level_nr;
1784 new_level_nr = old_level_nr + step * direction;
1785 if (new_level_nr < leveldir_current->first_level)
1786 new_level_nr = leveldir_current->first_level;
1787 if (new_level_nr > leveldir_current->last_level)
1788 new_level_nr = leveldir_current->last_level;
1790 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1792 /* skipping levels is only allowed when trying to skip single level */
1793 if (setup.skip_levels && step == 1 &&
1794 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1796 leveldir_current->handicap_level++;
1797 SaveLevelSetup_SeriesInfo();
1800 new_level_nr = leveldir_current->handicap_level;
1803 if (new_level_nr != old_level_nr)
1805 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1807 PlaySound(SND_MENU_ITEM_SELECTING);
1809 level_nr = new_level_nr;
1811 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1812 int2str(level_nr, menu.main.text.level_number.size),
1813 mci->pos_text->font);
1815 LoadLevel(level_nr);
1816 DrawPreviewLevelInitial();
1820 DrawCompleteVideoDisplay();
1822 /* needed because DrawPreviewLevelInitial() takes some time */
1828 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1830 static int choice = MAIN_CONTROL_GAME;
1834 if (button == MB_MENU_INITIALIZE)
1836 DrawCursorAndText_Main(choice, TRUE);
1841 if (mx || my) /* mouse input */
1845 for (i = 0; main_controls[i].nr != -1; i++)
1848 printf("::: check click (%d, %d) for %d [%d] ...\n",
1849 mx - mSX, my - mSY, i, main_controls[i].nr);
1852 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1853 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1854 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1857 printf("::: inside %d\n", i);
1860 pos = main_controls[i].nr;
1866 else if (dx || dy) /* keyboard input */
1868 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1869 choice == MAIN_CONTROL_SETUP))
1870 button = MB_MENU_CHOICE;
1875 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1877 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1879 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1881 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1883 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1885 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1887 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1889 game_status = GAME_MODE_LEVELNR;
1892 ChangeViewportPropertiesIfNeeded();
1895 DrawChooseLevelNr();
1897 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1903 PlaySound(SND_MENU_ITEM_ACTIVATING);
1905 DrawCursorAndText_Main(choice, FALSE);
1906 DrawCursorAndText_Main(pos, TRUE);
1913 PlaySound(SND_MENU_ITEM_SELECTING);
1915 if (pos == MAIN_CONTROL_NAME)
1917 game_status = GAME_MODE_PSEUDO_TYPENAME;
1919 HandleTypeName(strlen(setup.player_name), 0);
1921 else if (pos == MAIN_CONTROL_LEVELS)
1925 game_status = GAME_MODE_LEVELS;
1927 SaveLevelSetup_LastSeries();
1928 SaveLevelSetup_SeriesInfo();
1930 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1935 ChangeViewportPropertiesIfNeeded();
1938 DrawChooseLevelSet();
1941 else if (pos == MAIN_CONTROL_SCORES)
1943 game_status = GAME_MODE_SCORES;
1946 ChangeViewportPropertiesIfNeeded();
1951 else if (pos == MAIN_CONTROL_EDITOR)
1953 if (leveldir_current->readonly &&
1954 !strEqual(setup.player_name, "Artsoft"))
1955 Request("This level is read only!", REQ_CONFIRM);
1957 CloseDoor(DOOR_CLOSE_2);
1959 game_status = GAME_MODE_EDITOR;
1961 FadeSetEnterScreen();
1964 /* needed if different viewport properties defined for editor */
1965 ChangeViewportPropertiesIfNeeded();
1970 else if (pos == MAIN_CONTROL_INFO)
1972 game_status = GAME_MODE_INFO;
1973 info_mode = INFO_MODE_MAIN;
1976 ChangeViewportPropertiesIfNeeded();
1981 else if (pos == MAIN_CONTROL_GAME)
1983 StartGameActions(options.network, setup.autorecord, level.random_seed);
1985 else if (pos == MAIN_CONTROL_SETUP)
1987 game_status = GAME_MODE_SETUP;
1988 setup_mode = SETUP_MODE_MAIN;
1991 ChangeViewportPropertiesIfNeeded();
1996 else if (pos == MAIN_CONTROL_QUIT)
1998 SaveLevelSetup_LastSeries();
1999 SaveLevelSetup_SeriesInfo();
2001 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2002 game_status = GAME_MODE_QUIT;
2008 if (game_status == GAME_MODE_MAIN)
2010 DrawPreviewLevelAnimation();
2017 /* ========================================================================= */
2018 /* info screen functions */
2019 /* ========================================================================= */
2021 static struct TokenInfo *info_info;
2022 static int num_info_info;
2024 static void execInfoTitleScreen()
2026 info_mode = INFO_MODE_TITLE;
2031 static void execInfoElements()
2033 info_mode = INFO_MODE_ELEMENTS;
2038 static void execInfoMusic()
2040 info_mode = INFO_MODE_MUSIC;
2045 static void execInfoCredits()
2047 info_mode = INFO_MODE_CREDITS;
2052 static void execInfoProgram()
2054 info_mode = INFO_MODE_PROGRAM;
2059 static void execInfoVersion()
2061 info_mode = INFO_MODE_VERSION;
2066 static void execInfoLevelSet()
2068 info_mode = INFO_MODE_LEVELSET;
2073 static void execExitInfo()
2075 game_status = GAME_MODE_MAIN;
2077 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2080 static struct TokenInfo info_info_main[] =
2082 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2083 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2084 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2085 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2086 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2087 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2088 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2089 { TYPE_EMPTY, NULL, "" },
2090 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2095 static void DrawCursorAndText_Info(int pos, boolean active)
2097 int xpos = MENU_SCREEN_START_XPOS;
2098 int ypos = MENU_SCREEN_START_YPOS + pos;
2099 int font_nr = FONT_MENU_1;
2102 font_nr = FONT_ACTIVE(font_nr);
2104 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2106 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2107 drawCursor(pos, active);
2110 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2115 CloseDoor(DOOR_CLOSE_2);
2117 /* (needed after displaying title screens which disable auto repeat) */
2118 KeyboardAutoRepeatOn();
2120 FadeSetLeaveScreen();
2127 if (fade_mask == REDRAW_ALL)
2131 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2137 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2139 info_info = info_info_main;
2143 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2145 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2148 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2149 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2150 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2151 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2152 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2153 initCursor(i, IMG_MENU_BUTTON);
2155 DrawCursorAndText_Info(i, FALSE);
2160 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2165 DrawMaskedBorder(fade_mask);
2172 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2174 static int choice_store[MAX_INFO_MODES];
2175 int choice = choice_store[info_mode]; /* always starts with 0 */
2179 if (button == MB_MENU_INITIALIZE)
2181 /* advance to first valid menu entry */
2182 while (choice < num_info_info &&
2183 info_info[choice].type & TYPE_SKIP_ENTRY)
2185 choice_store[info_mode] = choice;
2187 DrawCursorAndText_Info(choice, TRUE);
2191 else if (button == MB_MENU_LEAVE)
2193 for (y = 0; y < num_info_info; y++)
2195 if (info_info[y].type & TYPE_LEAVE_MENU)
2197 void (*menu_callback_function)(void) = info_info[y].value;
2201 menu_callback_function();
2203 break; /* absolutely needed because function changes 'info_info'! */
2210 if (mx || my) /* mouse input */
2212 x = (mx - mSX) / 32;
2213 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2215 else if (dx || dy) /* keyboard input */
2219 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2221 if (info_info[choice].type & menu_navigation_type ||
2222 info_info[choice].type & TYPE_ENTER_SCREEN ||
2223 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2224 info_info[choice].type & TYPE_YES_NO_AUTO)
2225 button = MB_MENU_CHOICE;
2230 /* jump to next non-empty menu entry (up or down) */
2231 while (y > 0 && y < num_info_info - 1 &&
2232 info_info[y].type & TYPE_SKIP_ENTRY)
2236 if (IN_VIS_FIELD(x, y) &&
2237 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2243 PlaySound(SND_MENU_ITEM_ACTIVATING);
2245 DrawCursorAndText_Info(choice, FALSE);
2246 DrawCursorAndText_Info(y, TRUE);
2248 choice = choice_store[info_mode] = y;
2251 else if (!(info_info[y].type & TYPE_GHOSTED))
2253 PlaySound(SND_MENU_ITEM_SELECTING);
2255 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2257 void (*menu_callback_function)(void) = info_info[choice].value;
2259 FadeSetFromType(info_info[y].type);
2261 menu_callback_function();
2267 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2269 int ystart1 = mSY - SY + 100;
2270 int ystart2 = mSY - SY + 150;
2271 int ybottom = mSY - SY + SYSIZE - 20;
2273 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2275 FadeOut(REDRAW_FIELD);
2280 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2281 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2283 DrawTextSCentered(ybottom, FONT_TEXT_4,
2284 "Press any key or button for info menu");
2286 FadeIn(REDRAW_FIELD);
2289 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2291 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2292 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2293 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2294 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2295 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2296 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2297 int ystep = MENU_SCREEN_INFO_YSTEP;
2298 int element, action, direction;
2306 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2307 infoscreen_step[i] = infoscreen_frame[i] = 0;
2312 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2314 DrawTextSCentered(ybottom, FONT_TEXT_4,
2315 "Press any key or button for next page");
2321 while (helpanim_info[j].element != HELPANIM_LIST_END)
2323 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2328 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2337 j += infoscreen_step[i - start];
2339 element = helpanim_info[j].element;
2340 action = helpanim_info[j].action;
2341 direction = helpanim_info[j].direction;
2344 element = EL_UNKNOWN;
2346 if (action != -1 && direction != -1)
2347 graphic = el_act_dir2img(element, action, direction);
2348 else if (action != -1)
2349 graphic = el_act2img(element, action);
2350 else if (direction != -1)
2351 graphic = el_dir2img(element, direction);
2353 graphic = el2img(element);
2355 delay = helpanim_info[j++].delay;
2360 if (infoscreen_frame[i - start] == 0)
2363 infoscreen_frame[i - start] = delay - 1;
2367 sync_frame = delay - infoscreen_frame[i - start];
2368 infoscreen_frame[i - start]--;
2371 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2373 if (!infoscreen_frame[i - start])
2374 infoscreen_step[i - start] = 0;
2378 if (!infoscreen_frame[i - start])
2379 infoscreen_step[i - start]++;
2380 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2386 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2388 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2389 graphic, sync_frame, USE_MASKING);
2392 DrawInfoScreen_HelpText(element, action, direction, i - start);
2397 redraw_mask |= REDRAW_FIELD;
2402 static char *getHelpText(int element, int action, int direction)
2404 char token[MAX_LINE_LEN];
2406 strcpy(token, element_info[element].token_name);
2409 strcat(token, element_action_info[action].suffix);
2411 if (direction != -1)
2412 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2414 return getHashEntry(helptext_info, token);
2417 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2419 int font_nr = FONT_INFO_ELEMENTS;
2420 int font_width = getFontWidth(font_nr);
2421 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2422 int sy = mSY + 65 + 2 * 32 + 1;
2423 int ystep = TILEY + 4;
2424 int pad_x = sx - SX;
2425 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2426 int max_lines_per_text = 2;
2429 if (action != -1 && direction != -1) /* element.action.direction */
2430 text = getHelpText(element, action, direction);
2432 if (text == NULL && action != -1) /* element.action */
2433 text = getHelpText(element, action, -1);
2435 if (text == NULL && direction != -1) /* element.direction */
2436 text = getHelpText(element, -1, direction);
2438 if (text == NULL) /* base element */
2439 text = getHelpText(element, -1, -1);
2441 if (text == NULL) /* not found */
2442 text = "No description available";
2444 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2445 sy += getFontHeight(font_nr) / 2;
2447 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2448 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2449 TRUE, FALSE, FALSE);
2452 void DrawInfoScreen_TitleScreen()
2457 void HandleInfoScreen_TitleScreen(int button)
2459 HandleTitleScreen(0, 0, 0, 0, button);
2462 void DrawInfoScreen_Elements()
2464 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2466 FadeOut(REDRAW_FIELD);
2471 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2473 FadeIn(REDRAW_FIELD);
2478 void HandleInfoScreen_Elements(int button)
2480 static unsigned int info_delay = 0;
2481 static int num_anims;
2482 static int num_pages;
2484 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2487 if (button == MB_MENU_INITIALIZE)
2489 boolean new_element = TRUE;
2493 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2495 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2497 else if (new_element)
2500 new_element = FALSE;
2504 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2508 if (button == MB_MENU_LEAVE)
2510 PlaySound(SND_MENU_ITEM_SELECTING);
2512 info_mode = INFO_MODE_MAIN;
2517 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2519 if (button != MB_MENU_INITIALIZE)
2521 PlaySound(SND_MENU_ITEM_SELECTING);
2526 if (page >= num_pages)
2528 FadeSoundsAndMusic();
2530 info_mode = INFO_MODE_MAIN;
2531 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2538 FadeSetNextScreen();
2541 if (button != MB_MENU_INITIALIZE)
2542 FadeOut(REDRAW_FIELD);
2544 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2546 if (button != MB_MENU_INITIALIZE)
2547 FadeIn(REDRAW_FIELD);
2551 if (DelayReached(&info_delay, GameFrameDelay))
2552 if (page < num_pages)
2553 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2555 PlayMenuSoundIfLoop();
2559 void DrawInfoScreen_Music()
2561 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2564 FadeOut(REDRAW_FIELD);
2572 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2575 FadeIn(REDRAW_FIELD);
2579 void HandleInfoScreen_Music(int button)
2581 static struct MusicFileInfo *list = NULL;
2582 int ystart1 = mSY - SY + 100;
2583 int ystart2 = mSY - SY + 150;
2584 int ybottom = mSY - SY + SYSIZE - 20;
2587 if (button == MB_MENU_INITIALIZE)
2589 list = music_file_info;
2593 FadeSoundsAndMusic();
2598 DrawTextSCentered(ystart1, FONT_TEXT_1,
2599 "No music info for this level set.");
2601 DrawTextSCentered(ybottom, FONT_TEXT_4,
2602 "Press any key or button for info menu");
2608 if (button == MB_MENU_LEAVE)
2610 PlaySound(SND_MENU_ITEM_SELECTING);
2612 FadeSoundsAndMusic();
2614 info_mode = INFO_MODE_MAIN;
2619 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2623 if (button != MB_MENU_INITIALIZE)
2625 PlaySound(SND_MENU_ITEM_SELECTING);
2633 FadeSoundsAndMusic();
2635 info_mode = INFO_MODE_MAIN;
2636 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2641 FadeSoundsAndMusic();
2644 if (list != music_file_info)
2645 FadeSetNextScreen();
2648 if (button != MB_MENU_INITIALIZE)
2649 FadeOut(REDRAW_FIELD);
2656 int sound = list->music;
2658 if (sound_info[sound].loop)
2659 PlaySoundLoop(sound);
2663 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2667 PlayMusic(list->music);
2669 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2672 if (!strEqual(list->title, UNKNOWN_NAME))
2674 if (!strEqual(list->title_header, UNKNOWN_NAME))
2675 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2677 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2680 if (!strEqual(list->artist, UNKNOWN_NAME))
2682 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2683 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2685 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2687 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2690 if (!strEqual(list->album, UNKNOWN_NAME))
2692 if (!strEqual(list->album_header, UNKNOWN_NAME))
2693 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2695 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2697 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2700 if (!strEqual(list->year, UNKNOWN_NAME))
2702 if (!strEqual(list->year_header, UNKNOWN_NAME))
2703 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2705 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2707 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2710 DrawTextSCentered(ybottom, FONT_TEXT_4,
2711 "Press any key or button for next page");
2713 if (button != MB_MENU_INITIALIZE)
2714 FadeIn(REDRAW_FIELD);
2717 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2718 PlaySoundLoop(list->music);
2721 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2723 int ystart1 = mSY - SY + 100;
2724 int ystart2 = mSY - SY + 150;
2725 int ybottom = mSY - SY + SYSIZE - 20;
2731 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2735 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2736 "Special thanks to");
2737 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2739 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2741 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2742 "\"Boulder Dash\"");
2743 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2745 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2747 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2749 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2750 "First Star Software");
2752 else if (screen_nr == 1)
2754 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2755 "Special thanks to");
2756 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2757 "Klaus Heinz & Volker Wertich");
2758 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2760 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2761 "\"Emerald Mine\"");
2762 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2764 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2766 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2768 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2771 else if (screen_nr == 2)
2773 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2774 "Special thanks to");
2775 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2776 "Michael Stopp & Philip Jespersen");
2777 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2779 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2781 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2783 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2785 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2787 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2788 "Digital Integration");
2790 else if (screen_nr == 3)
2792 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2793 "Special thanks to");
2794 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2795 "Hiroyuki Imabayashi");
2796 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2798 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2800 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2802 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2804 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2806 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2809 else if (screen_nr == 4)
2811 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2812 "Special thanks to");
2813 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2815 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2817 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2818 "Jürgen Bonhagen");
2819 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2820 "for the continuous creation");
2821 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2822 "of outstanding level sets");
2824 else if (screen_nr == 5)
2826 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2828 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2830 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2831 "for ideas and inspiration by");
2832 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2835 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2837 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2839 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2840 "for ideas and inspiration by");
2841 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2844 else if (screen_nr == 6)
2846 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2848 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2851 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2852 "for the code base used for the");
2853 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2854 "native Emerald Mine engine");
2856 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2857 "for the new Emerald Mine engine");
2860 else if (screen_nr == 7)
2862 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2864 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2866 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2867 "for the initial DOS port");
2869 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2871 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2873 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2874 "for some additional toons");
2876 else if (screen_nr == 8)
2878 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2879 "And not to forget:");
2880 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2882 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2883 "All those who contributed");
2884 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2885 "levels to this game");
2886 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2890 DrawTextSCentered(ybottom, FONT_TEXT_4,
2891 "Press any key or button for next page");
2894 void DrawInfoScreen_Credits()
2896 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2898 FadeSoundsAndMusic();
2901 FadeOut(REDRAW_FIELD);
2904 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2907 FadeIn(REDRAW_FIELD);
2911 void HandleInfoScreen_Credits(int button)
2913 static int screen_nr = 0;
2914 int num_screens = 9;
2916 if (button == MB_MENU_INITIALIZE)
2920 // DrawInfoScreen_CreditsScreen(screen_nr);
2923 if (button == MB_MENU_LEAVE)
2925 PlaySound(SND_MENU_ITEM_SELECTING);
2927 info_mode = INFO_MODE_MAIN;
2932 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2934 if (button != MB_MENU_INITIALIZE)
2936 PlaySound(SND_MENU_ITEM_SELECTING);
2941 if (screen_nr >= num_screens)
2943 FadeSoundsAndMusic();
2945 info_mode = INFO_MODE_MAIN;
2946 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2953 FadeSetNextScreen();
2956 if (button != MB_MENU_INITIALIZE)
2957 FadeOut(REDRAW_FIELD);
2959 DrawInfoScreen_CreditsScreen(screen_nr);
2961 if (button != MB_MENU_INITIALIZE)
2962 FadeIn(REDRAW_FIELD);
2966 PlayMenuSoundIfLoop();
2970 void DrawInfoScreen_Program()
2972 int ystart1 = mSY - SY + 100;
2973 int ystart2 = mSY - SY + 150;
2974 int ybottom = mSY - SY + SYSIZE - 20;
2977 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2980 FadeOut(REDRAW_FIELD);
2986 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2988 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2989 "This game is Freeware!");
2990 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2991 "If you like it, send e-mail to:");
2992 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2993 PROGRAM_EMAIL_STRING);
2995 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2996 "More information and levels:");
2997 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2998 PROGRAM_WEBSITE_STRING);
2999 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3000 "If you have created new levels,");
3001 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3002 "send them to me to include them!");
3003 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3006 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3007 "or SnailMail to:");
3008 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3010 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3011 "Detmolder Strasse 189");
3012 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3016 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3017 "More information and levels:");
3018 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3019 PROGRAM_WEBSITE_STRING);
3020 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3021 "If you have created new levels,");
3022 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3023 "send them to me to include them!");
3024 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3028 DrawTextSCentered(ybottom, FONT_TEXT_4,
3029 "Press any key or button for info menu");
3032 FadeIn(REDRAW_FIELD);
3036 void HandleInfoScreen_Program(int button)
3038 if (button == MB_MENU_LEAVE)
3040 PlaySound(SND_MENU_ITEM_SELECTING);
3042 info_mode = INFO_MODE_MAIN;
3047 else if (button == MB_MENU_CHOICE)
3049 PlaySound(SND_MENU_ITEM_SELECTING);
3051 FadeSoundsAndMusic();
3054 FadeOut(REDRAW_FIELD);
3057 info_mode = INFO_MODE_MAIN;
3058 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3062 PlayMenuSoundIfLoop();
3066 void DrawInfoScreen_Version()
3068 int font_header = FONT_TEXT_3;
3069 int font_text = FONT_TEXT_2;
3070 int xstep = getFontWidth(font_text);
3071 int ystep = getFontHeight(font_text);
3072 int ystart1 = mSY - SY + 100;
3073 int ystart2 = mSY - SY + 150;
3074 int ybottom = mSY - SY + SYSIZE - 20;
3075 int xstart1 = mSX - SX + 2 * xstep;
3076 int xstart2 = mSX - SX + 18 * xstep;
3077 #if defined(TARGET_SDL)
3078 int xstart3 = mSX - SX + 28 * xstep;
3079 SDL_version sdl_version_compiled;
3080 const SDL_version *sdl_version_linked;
3081 int driver_name_len = 10;
3082 #if defined(TARGET_SDL2)
3083 SDL_version sdl_version_linked_ext;
3084 const char *driver_name = NULL;
3086 char driver_name[driver_name_len];
3090 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3093 FadeOut(REDRAW_FIELD);
3099 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3101 DrawTextF(xstart1, ystart2, font_header, "Name");
3102 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3105 DrawTextF(xstart1, ystart2, font_header, "Version");
3106 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3109 DrawTextF(xstart1, ystart2, font_header, "Platform");
3110 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3113 DrawTextF(xstart1, ystart2, font_header, "Target");
3114 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3117 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3118 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3120 #if defined(TARGET_SDL)
3121 ystart2 += 3 * ystep;
3122 DrawTextF(xstart1, ystart2, font_header, "Library");
3123 DrawTextF(xstart2, ystart2, font_header, "compiled");
3124 DrawTextF(xstart3, ystart2, font_header, "linked");
3126 SDL_VERSION(&sdl_version_compiled);
3127 #if defined(TARGET_SDL2)
3128 SDL_GetVersion(&sdl_version_linked_ext);
3129 sdl_version_linked = &sdl_version_linked_ext;
3131 sdl_version_linked = SDL_Linked_Version();
3134 ystart2 += 2 * ystep;
3135 DrawTextF(xstart1, ystart2, font_text, "SDL");
3136 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3137 sdl_version_compiled.major,
3138 sdl_version_compiled.minor,
3139 sdl_version_compiled.patch);
3140 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3141 sdl_version_linked->major,
3142 sdl_version_linked->minor,
3143 sdl_version_linked->patch);
3145 SDL_IMAGE_VERSION(&sdl_version_compiled);
3146 sdl_version_linked = IMG_Linked_Version();
3149 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3150 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3151 sdl_version_compiled.major,
3152 sdl_version_compiled.minor,
3153 sdl_version_compiled.patch);
3154 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3155 sdl_version_linked->major,
3156 sdl_version_linked->minor,
3157 sdl_version_linked->patch);
3159 SDL_MIXER_VERSION(&sdl_version_compiled);
3160 sdl_version_linked = Mix_Linked_Version();
3163 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3164 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3165 sdl_version_compiled.major,
3166 sdl_version_compiled.minor,
3167 sdl_version_compiled.patch);
3168 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3169 sdl_version_linked->major,
3170 sdl_version_linked->minor,
3171 sdl_version_linked->patch);
3173 SDL_NET_VERSION(&sdl_version_compiled);
3174 sdl_version_linked = SDLNet_Linked_Version();
3177 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3178 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3179 sdl_version_compiled.major,
3180 sdl_version_compiled.minor,
3181 sdl_version_compiled.patch);
3182 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3183 sdl_version_linked->major,
3184 sdl_version_linked->minor,
3185 sdl_version_linked->patch);
3187 ystart2 += 3 * ystep;
3188 DrawTextF(xstart1, ystart2, font_header, "Driver");
3189 DrawTextF(xstart2, ystart2, font_header, "Requested");
3190 DrawTextF(xstart3, ystart2, font_header, "Used");
3192 #if defined(TARGET_SDL2)
3193 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3195 SDL_VideoDriverName(driver_name, driver_name_len);
3198 ystart2 += 2 * ystep;
3199 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3200 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3201 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3203 #if defined(TARGET_SDL2)
3204 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3206 SDL_AudioDriverName(driver_name, driver_name_len);
3210 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3211 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3212 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3215 DrawTextSCentered(ybottom, FONT_TEXT_4,
3216 "Press any key or button for info menu");
3219 FadeIn(REDRAW_FIELD);
3223 void HandleInfoScreen_Version(int button)
3225 if (button == MB_MENU_LEAVE)
3227 PlaySound(SND_MENU_ITEM_SELECTING);
3229 info_mode = INFO_MODE_MAIN;
3234 else if (button == MB_MENU_CHOICE)
3236 PlaySound(SND_MENU_ITEM_SELECTING);
3238 FadeSoundsAndMusic();
3241 FadeOut(REDRAW_FIELD);
3244 info_mode = INFO_MODE_MAIN;
3245 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3249 PlayMenuSoundIfLoop();
3253 void DrawInfoScreen_LevelSet()
3255 struct TitleMessageInfo *tmi = &readme;
3256 char *filename = getLevelSetInfoFilename();
3258 /* if chars set to "-1", automatically determine by text and font width */
3259 if (tmi->chars == -1)
3260 tmi->chars = tmi->width / getFontWidth(tmi->font);
3262 tmi->width = tmi->chars * getFontWidth(tmi->font);
3264 /* if lines set to "-1", automatically determine by text and font height */
3265 if (tmi->lines == -1)
3266 tmi->lines = tmi->height / getFontHeight(tmi->font);
3268 tmi->height = tmi->lines * getFontHeight(tmi->font);
3270 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3273 FadeOut(REDRAW_FIELD);
3279 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3281 if (filename != NULL)
3282 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3283 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3284 tmi->autowrap, tmi->centered, tmi->parse_comments);
3286 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3287 "No information for this level set.");
3289 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3290 "Press any key or button for info menu");
3293 FadeIn(REDRAW_FIELD);
3297 void HandleInfoScreen_LevelSet(int button)
3299 if (button == MB_MENU_LEAVE)
3301 PlaySound(SND_MENU_ITEM_SELECTING);
3303 info_mode = INFO_MODE_MAIN;
3308 else if (button == MB_MENU_CHOICE)
3310 PlaySound(SND_MENU_ITEM_SELECTING);
3312 FadeSoundsAndMusic();
3315 FadeOut(REDRAW_FIELD);
3318 info_mode = INFO_MODE_MAIN;
3319 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3323 PlayMenuSoundIfLoop();
3327 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3329 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3331 if (info_mode == INFO_MODE_TITLE)
3332 DrawInfoScreen_TitleScreen();
3333 else if (info_mode == INFO_MODE_ELEMENTS)
3334 DrawInfoScreen_Elements();
3335 else if (info_mode == INFO_MODE_MUSIC)
3336 DrawInfoScreen_Music();
3337 else if (info_mode == INFO_MODE_CREDITS)
3338 DrawInfoScreen_Credits();
3339 else if (info_mode == INFO_MODE_PROGRAM)
3340 DrawInfoScreen_Program();
3341 else if (info_mode == INFO_MODE_VERSION)
3342 DrawInfoScreen_Version();
3343 else if (info_mode == INFO_MODE_LEVELSET)
3344 DrawInfoScreen_LevelSet();
3346 DrawInfoScreen_Main(fade_mask, do_fading);
3348 if (info_mode != INFO_MODE_MAIN &&
3349 info_mode != INFO_MODE_TITLE &&
3350 info_mode != INFO_MODE_MUSIC)
3357 void DrawAndFadeInInfoScreen(int fade_mask)
3359 DrawInfoScreenExt(fade_mask, TRUE);
3362 void DrawInfoScreen()
3364 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3367 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3369 if (info_mode == INFO_MODE_TITLE)
3370 HandleInfoScreen_TitleScreen(button);
3371 else if (info_mode == INFO_MODE_ELEMENTS)
3372 HandleInfoScreen_Elements(button);
3373 else if (info_mode == INFO_MODE_MUSIC)
3374 HandleInfoScreen_Music(button);
3375 else if (info_mode == INFO_MODE_CREDITS)
3376 HandleInfoScreen_Credits(button);
3377 else if (info_mode == INFO_MODE_PROGRAM)
3378 HandleInfoScreen_Program(button);
3379 else if (info_mode == INFO_MODE_VERSION)
3380 HandleInfoScreen_Version(button);
3381 else if (info_mode == INFO_MODE_LEVELSET)
3382 HandleInfoScreen_LevelSet(button);
3384 HandleInfoScreen_Main(mx, my, dx, dy, button);
3392 /* ========================================================================= */
3393 /* type name functions */
3394 /* ========================================================================= */
3396 void HandleTypeName(int newxpos, Key key)
3398 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3399 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3400 struct TextPosInfo *pos = mci->pos_input;
3401 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3402 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3403 static int xpos = 0;
3404 int font_nr = pos->font;
3405 int font_active_nr = FONT_ACTIVE(font_nr);
3406 int font_width = getFontWidth(font_active_nr);
3407 char key_char = getValidConfigValueChar(getCharFromKey(key));
3408 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3409 boolean is_active = TRUE;
3411 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3415 strcpy(last_player_name, setup.player_name);
3419 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3421 setup.player_name[xpos] = key_char;
3422 setup.player_name[xpos + 1] = 0;
3426 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3430 setup.player_name[xpos] = 0;
3432 else if (key == KSYM_Return && xpos > 0)
3438 game_status = GAME_MODE_MAIN;
3440 else if (key == KSYM_Escape)
3442 strcpy(setup.player_name, last_player_name);
3446 game_status = GAME_MODE_MAIN;
3451 pos->width = (strlen(setup.player_name) + 1) * font_width;
3452 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3454 DrawText(startx, starty, setup.player_name, font_active_nr);
3455 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3459 pos->width = strlen(setup.player_name) * font_width;
3460 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3462 DrawText(startx, starty, setup.player_name, font_nr);
3467 /* ========================================================================= */
3468 /* tree menu functions */
3469 /* ========================================================================= */
3471 static void DrawChooseTree(TreeInfo **ti_ptr)
3475 FreeScreenGadgets();
3476 CreateScreenGadgets();
3478 CloseDoor(DOOR_CLOSE_2);
3481 FadeOut(REDRAW_FIELD);
3486 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3487 MapScreenTreeGadgets(*ti_ptr);
3490 FadeIn(REDRAW_FIELD);
3496 static void AdjustScrollbar(int id, int items_max, int items_visible,
3499 struct GadgetInfo *gi = screen_gadget[id];
3501 if (item_position > items_max - items_visible)
3502 item_position = items_max - items_visible;
3504 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3505 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3506 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3509 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3512 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3515 struct GadgetInfo *gi = screen_gadget[id];
3516 int items_max, items_visible, item_position;
3518 items_max = numTreeInfoInGroup(ti);
3519 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3520 item_position = first_entry;
3522 if (item_position > items_max - items_visible)
3523 item_position = items_max - items_visible;
3525 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3526 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3527 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3531 static void drawChooseTreeList(int first_entry, int num_page_entries,
3535 char *title_string = NULL;
3536 int yoffset_sets = MENU_TITLE1_YPOS;
3537 int yoffset_setup = 16;
3538 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3539 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3540 int last_game_status = game_status; /* save current game status */
3542 title_string = ti->infotext;
3544 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3547 /* force LEVELS font on artwork setup screen */
3548 game_status = GAME_MODE_LEVELS;
3552 /* clear tree list area, but not title or scrollbar */
3553 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3554 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3555 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3557 /* clear tree list area, but not title or scrollbar */
3558 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3559 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3560 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3563 for (i = 0; i < num_page_entries; i++)
3565 TreeInfo *node, *node_first;
3566 int entry_pos = first_entry + i;
3567 int xpos = MENU_SCREEN_START_XPOS;
3568 int ypos = MENU_SCREEN_START_YPOS + i;
3569 int startx = mSX + xpos * 32;
3570 int starty = mSY + ypos * 32;
3571 int font_nr = FONT_TEXT_1;
3572 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3573 int startx_text = startx + font_xoffset;
3574 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3575 int text_size = startx_scrollbar - startx_text;
3576 int max_buffer_len = text_size / getFontWidth(font_nr);
3577 char buffer[max_buffer_len + 1];
3579 node_first = getTreeInfoFirstGroupEntry(ti);
3580 node = getTreeInfoFromPos(node_first, entry_pos);
3582 strncpy(buffer, node->name, max_buffer_len);
3583 buffer[max_buffer_len] = '\0';
3585 DrawText(startx, starty, buffer, font_nr + node->color);
3587 if (node->parent_link)
3588 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3589 else if (node->level_group)
3590 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3592 initCursor(i, IMG_MENU_BUTTON);
3595 game_status = last_game_status; /* restore current game status */
3597 redraw_mask |= REDRAW_FIELD;
3600 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3602 TreeInfo *node, *node_first;
3603 int x, last_redraw_mask = redraw_mask;
3604 int ypos = MENU_TITLE2_YPOS;
3605 int font_nr = FONT_TITLE_2;
3607 if (ti->type == TREE_TYPE_LEVEL_NR)
3608 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3610 if (ti->type != TREE_TYPE_LEVEL_DIR)
3613 node_first = getTreeInfoFirstGroupEntry(ti);
3614 node = getTreeInfoFromPos(node_first, entry_pos);
3616 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3619 if (node->parent_link)
3620 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3621 node->node_parent->name);
3622 else if (node->level_group)
3623 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3625 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3626 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3627 node->levels, (node->levels > 1 ? "levels" : "level"),
3630 if (node->parent_link)
3631 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3633 else if (node->level_group)
3634 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3636 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3637 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3638 node->levels, node->class_desc);
3641 /* let BackToFront() redraw only what is needed */
3642 redraw_mask = last_redraw_mask | REDRAW_TILES;
3643 for (x = 0; x < SCR_FIELDX; x++)
3644 MarkTileDirty(x, 1);
3647 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3650 TreeInfo *ti = *ti_ptr;
3652 int y = ti->cl_cursor;
3653 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3654 int num_entries = numTreeInfoInGroup(ti);
3655 int num_page_entries;
3656 int last_game_status = game_status; /* save current game status */
3657 boolean position_set_by_scrollbar = (dx == 999);
3660 /* force LEVELS draw offset on choose level and artwork setup screen */
3661 game_status = GAME_MODE_LEVELS;
3664 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3665 num_page_entries = num_entries;
3667 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3669 game_status = last_game_status; /* restore current game status */
3671 if (button == MB_MENU_INITIALIZE)
3673 int num_entries = numTreeInfoInGroup(ti);
3674 int entry_pos = posTreeInfo(ti);
3676 if (ti->cl_first == -1)
3678 /* only on initialization */
3679 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3680 ti->cl_cursor = entry_pos - ti->cl_first;
3682 else if (ti->cl_cursor >= num_page_entries ||
3683 (num_entries > num_page_entries &&
3684 num_entries - ti->cl_first < num_page_entries))
3686 /* only after change of list size (by custom graphic configuration) */
3687 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3688 ti->cl_cursor = entry_pos - ti->cl_first;
3691 if (position_set_by_scrollbar)
3694 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3697 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3698 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3699 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3703 else if (button == MB_MENU_LEAVE)
3707 PlaySound(SND_MENU_ITEM_SELECTING);
3709 if (ti->node_parent)
3711 *ti_ptr = ti->node_parent;
3712 DrawChooseTree(ti_ptr);
3714 else if (game_status == GAME_MODE_SETUP)
3716 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3717 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3719 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3720 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3721 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3722 execSetupGraphics();
3723 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3724 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3725 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3732 if (game_status == GAME_MODE_LEVELNR)
3733 level_nr = atoi(level_number_current->identifier);
3735 game_status = GAME_MODE_MAIN;
3737 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3743 if (mx || my) /* mouse input */
3745 int last_game_status = game_status; /* save current game status */
3748 /* force LEVELS draw offset on artwork setup screen */
3749 game_status = GAME_MODE_LEVELS;
3752 x = (mx - mSX) / 32;
3753 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3755 game_status = last_game_status; /* restore current game status */
3757 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3759 /* move cursor instead of scrolling when already at start/end of list */
3760 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3762 else if (dy == +1 * SCROLL_LINE &&
3763 ti->cl_first + num_page_entries == num_entries)
3766 /* handle scrolling screen one line or page */
3767 if (ti->cl_cursor + dy < 0 ||
3768 ti->cl_cursor + dy > num_page_entries - 1)
3771 boolean redraw = FALSE;
3773 if (ABS(dy) == SCROLL_PAGE)
3774 step = num_page_entries - 1;
3776 if (dy < 0 && ti->cl_first > 0)
3778 /* scroll page/line up */
3780 ti->cl_first -= step;
3781 if (ti->cl_first < 0)
3786 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3788 /* scroll page/line down */
3790 ti->cl_first += step;
3791 if (ti->cl_first + num_page_entries > num_entries)
3792 ti->cl_first = MAX(0, num_entries - num_page_entries);
3799 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3800 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3801 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3803 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3809 if (ABS(dy) == SCROLL_PAGE)
3810 step = num_page_entries - 1;
3812 if (dy < 0 && ti->cl_first > 0)
3814 /* scroll page/line up */
3816 ti->cl_first -= step;
3817 if (ti->cl_first < 0)
3820 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3821 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3822 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3824 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3827 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3829 /* scroll page/line down */
3831 ti->cl_first += step;
3832 if (ti->cl_first + num_page_entries > num_entries)
3833 ti->cl_first = MAX(0, num_entries - num_page_entries);
3835 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3836 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3837 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3839 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3847 /* handle moving cursor one line */
3848 y = ti->cl_cursor + dy;
3853 TreeInfo *node_first, *node_cursor;
3854 int entry_pos = ti->cl_first + y;
3856 node_first = getTreeInfoFirstGroupEntry(ti);
3857 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3859 if (node_cursor->node_group)
3863 PlaySound(SND_MENU_ITEM_SELECTING);
3865 node_cursor->cl_first = ti->cl_first;
3866 node_cursor->cl_cursor = ti->cl_cursor;
3867 *ti_ptr = node_cursor->node_group;
3868 DrawChooseTree(ti_ptr);
3873 else if (dx == -1 && ti->node_parent)
3877 PlaySound(SND_MENU_ITEM_SELECTING);
3879 *ti_ptr = ti->node_parent;
3880 DrawChooseTree(ti_ptr);
3885 if (!anyScrollbarGadgetActive() &&
3886 IN_VIS_FIELD(x, y) &&
3887 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3888 y >= 0 && y < num_page_entries)
3891 printf("::: TEST/HandleChooseTree [%d, %d, %d, %d]\n", Counter(),
3892 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
3897 if (y != ti->cl_cursor)
3899 PlaySound(SND_MENU_ITEM_ACTIVATING);
3901 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3902 drawChooseTreeCursor(y, TRUE);
3903 drawChooseTreeInfo(ti->cl_first + y, ti);
3910 TreeInfo *node_first, *node_cursor;
3911 int entry_pos = ti->cl_first + y;
3913 PlaySound(SND_MENU_ITEM_SELECTING);
3915 node_first = getTreeInfoFirstGroupEntry(ti);
3916 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3918 if (node_cursor->node_group)
3922 node_cursor->cl_first = ti->cl_first;
3923 node_cursor->cl_cursor = ti->cl_cursor;
3924 *ti_ptr = node_cursor->node_group;
3925 DrawChooseTree(ti_ptr);
3927 else if (node_cursor->parent_link)
3931 *ti_ptr = node_cursor->node_parent;
3932 DrawChooseTree(ti_ptr);
3939 FadeSetEnterScreen();
3942 node_cursor->cl_first = ti->cl_first;
3943 node_cursor->cl_cursor = ti->cl_cursor;
3944 *ti_ptr = node_cursor;
3946 if (ti->type == TREE_TYPE_LEVEL_DIR)
3948 LoadLevelSetup_SeriesInfo();
3950 SaveLevelSetup_LastSeries();
3951 SaveLevelSetup_SeriesInfo();
3955 if (game_status == GAME_MODE_SETUP)
3957 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3958 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3960 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3961 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3962 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3963 execSetupGraphics();
3964 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3965 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3966 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3973 if (game_status == GAME_MODE_LEVELNR)
3974 level_nr = atoi(level_number_current->identifier);
3976 game_status = GAME_MODE_MAIN;
3985 void DrawChooseLevelSet()
3987 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3989 DrawChooseTree(&leveldir_current);
3995 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3997 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4004 void DrawChooseLevelNr()
4008 if (level_number != NULL)
4010 freeTreeInfo(level_number);
4012 level_number = NULL;
4015 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4017 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4018 char identifier[32], name[32];
4021 /* temporarily load level info to get level name */
4022 LoadLevelInfoOnly(i);
4024 ti->node_top = &level_number;
4025 ti->sort_priority = 10000 + value;
4026 ti->color = (level.no_valid_file ? FC_BLUE :
4027 LevelStats_getSolved(i) ? FC_GREEN :
4028 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4030 sprintf(identifier, "%d", value);
4031 sprintf(name, "%03d: %s", value,
4032 (level.no_valid_file ? "(no file)" : level.name));
4034 setString(&ti->identifier, identifier);
4035 setString(&ti->name, name);
4036 setString(&ti->name_sorting, name);
4038 pushTreeInfo(&level_number, ti);
4041 /* sort level number values to start with lowest level number */
4042 sortTreeInfo(&level_number);
4044 /* set current level number to current level number */
4045 level_number_current =
4046 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4048 /* if that also fails, set current level number to first available level */
4049 if (level_number_current == NULL)
4050 level_number_current = level_number;
4052 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4055 DrawChooseTree(&level_number_current);
4057 DrawChooseTree(&leveldir_current);
4064 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4067 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4069 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4077 void DrawHallOfFame(int highlight_position)
4080 FadeSoundsAndMusic();
4082 /* (this is needed when called from GameEnd() after winning a game) */
4083 KeyboardAutoRepeatOn();
4086 /* (this is needed when called from GameEnd() after winning a game) */
4087 SetDrawDeactivationMask(REDRAW_NONE);
4088 SetDrawBackgroundMask(REDRAW_FIELD);
4090 CloseDoor(DOOR_CLOSE_2);
4092 if (highlight_position < 0)
4093 LoadScore(level_nr);
4095 FadeSetEnterScreen();
4097 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4100 FadeOut(REDRAW_FIELD);
4108 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4111 FadeIn(REDRAW_FIELD);
4115 static void drawHallOfFameList(int first_entry, int highlight_position)
4119 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4122 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4123 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4124 "HighScores of Level %d", level_nr);
4126 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4128 int entry = first_entry + i;
4129 boolean active = (entry == highlight_position);
4130 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4131 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4132 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4133 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4134 int dx1 = 3 * getFontWidth(font_nr1);
4135 int dx2 = dx1 + getFontWidth(font_nr1);
4137 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
4138 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4140 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4142 int sy = mSY + 64 + i * 32;
4144 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4145 DrawText(mSX + dx1, sy, ".", font_nr1);
4147 for (j = 0; j < num_dots; j++)
4148 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4150 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4153 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4154 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4156 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4159 redraw_mask |= REDRAW_FIELD;
4162 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4164 static int first_entry = 0;
4165 static int highlight_position = 0;
4166 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4168 if (button == MB_MENU_INITIALIZE)
4171 highlight_position = mx;
4172 drawHallOfFameList(first_entry, highlight_position);
4177 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4178 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4182 if (first_entry > 0)
4184 first_entry -= step;
4185 if (first_entry < 0)
4188 drawHallOfFameList(first_entry, highlight_position);
4193 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4195 first_entry += step;
4196 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4197 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4199 drawHallOfFameList(first_entry, highlight_position);
4202 else if (button == MB_MENU_LEAVE)
4204 PlaySound(SND_MENU_ITEM_SELECTING);
4206 FadeSound(SND_BACKGROUND_SCORES);
4208 game_status = GAME_MODE_MAIN;
4212 else if (button == MB_MENU_CHOICE)
4214 PlaySound(SND_MENU_ITEM_SELECTING);
4216 FadeSound(SND_BACKGROUND_SCORES);
4219 FadeOut(REDRAW_FIELD);
4222 game_status = GAME_MODE_MAIN;
4224 DrawAndFadeInMainMenu(REDRAW_FIELD);
4227 if (game_status == GAME_MODE_SCORES)
4228 PlayMenuSoundIfLoop();
4236 /* ========================================================================= */
4237 /* setup screen functions */
4238 /* ========================================================================= */
4240 static struct TokenInfo *setup_info;
4241 static int num_setup_info; /* number of setup entries shown on screen */
4242 static int max_setup_info; /* total number of setup entries in list */
4244 static char *screen_mode_text;
4245 static char *window_size_text;
4246 static char *scaling_type_text;
4247 static char *scroll_delay_text;
4248 static char *game_speed_text;
4249 static char *graphics_set_name;
4250 static char *sounds_set_name;
4251 static char *music_set_name;
4252 static char *volume_simple_text;
4253 static char *volume_loops_text;
4254 static char *volume_music_text;
4256 static void execSetupMain()
4258 setup_mode = SETUP_MODE_MAIN;
4263 static void execSetupGame_setGameSpeeds()
4265 if (game_speeds == NULL)
4269 for (i = 0; game_speeds_list[i].value != -1; i++)
4271 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4272 char identifier[32], name[32];
4273 int value = game_speeds_list[i].value;
4274 char *text = game_speeds_list[i].text;
4276 ti->node_top = &game_speeds;
4277 ti->sort_priority = 10000 - value;
4279 sprintf(identifier, "%d", value);
4280 sprintf(name, "%s", text);
4282 setString(&ti->identifier, identifier);
4283 setString(&ti->name, name);
4284 setString(&ti->name_sorting, name);
4285 setString(&ti->infotext, "Game Speed");
4287 pushTreeInfo(&game_speeds, ti);
4290 /* sort game speed values to start with slowest game speed */
4291 sortTreeInfo(&game_speeds);
4293 /* set current game speed to configured game speed value */
4294 game_speed_current =
4295 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4297 /* if that fails, set current game speed to reliable default value */
4298 if (game_speed_current == NULL)
4299 game_speed_current =
4300 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4302 /* if that also fails, set current game speed to first available speed */
4303 if (game_speed_current == NULL)
4304 game_speed_current = game_speeds;
4307 setup.game_frame_delay = atoi(game_speed_current->identifier);
4309 /* needed for displaying game speed text instead of identifier */
4310 game_speed_text = game_speed_current->name;
4313 static void execSetupGame_setScrollDelays()
4315 if (scroll_delays == NULL)
4319 for (i = 0; scroll_delays_list[i].value != -1; i++)
4321 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4322 char identifier[32], name[32];
4323 int value = scroll_delays_list[i].value;
4324 char *text = scroll_delays_list[i].text;
4326 ti->node_top = &scroll_delays;
4327 ti->sort_priority = value;
4329 sprintf(identifier, "%d", value);
4330 sprintf(name, "%s", text);
4332 setString(&ti->identifier, identifier);
4333 setString(&ti->name, name);
4334 setString(&ti->name_sorting, name);
4335 setString(&ti->infotext, "Scaling Type");
4337 pushTreeInfo(&scroll_delays, ti);
4340 /* sort scaling type values to start with lowest scaling type value */
4341 sortTreeInfo(&scroll_delays);
4343 /* set current scaling type value to configured scaling type value */
4344 scroll_delay_current =
4345 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4347 /* if that fails, set current scaling type to reliable default value */
4348 if (scroll_delay_current == NULL)
4349 scroll_delay_current =
4350 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4352 /* if that also fails, set current scaling type to first available value */
4353 if (scroll_delay_current == NULL)
4354 scroll_delay_current = scroll_delays;
4357 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4359 /* needed for displaying scaling type text instead of identifier */
4360 scroll_delay_text = scroll_delay_current->name;
4363 static void execSetupGame()
4365 execSetupGame_setGameSpeeds();
4366 execSetupGame_setScrollDelays();
4368 setup_mode = SETUP_MODE_GAME;
4373 static void execSetupChooseGameSpeed()
4375 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4380 static void execSetupChooseScrollDelay()
4382 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4387 static void execSetupEditor()
4389 setup_mode = SETUP_MODE_EDITOR;
4394 static void execSetupGraphics_setWindowSizes(boolean update_list)
4396 if (window_sizes != NULL && update_list)
4398 freeTreeInfo(window_sizes);
4400 window_sizes = NULL;
4403 if (window_sizes == NULL)
4405 boolean current_window_size_found = FALSE;
4408 for (i = 0; window_sizes_list[i].value != -1; i++)
4410 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4411 char identifier[32], name[32];
4412 int value = window_sizes_list[i].value;
4413 char *text = window_sizes_list[i].text;
4415 ti->node_top = &window_sizes;
4416 ti->sort_priority = value;
4418 sprintf(identifier, "%d", value);
4419 sprintf(name, "%s", text);
4421 setString(&ti->identifier, identifier);
4422 setString(&ti->name, name);
4423 setString(&ti->name_sorting, name);
4424 setString(&ti->infotext, "Window Scaling");
4426 pushTreeInfo(&window_sizes, ti);
4428 if (value == setup.window_scaling_percent)
4429 current_window_size_found = TRUE;
4432 if (!current_window_size_found)
4434 // add entry for non-preset window scaling value
4436 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4437 char identifier[32], name[32];
4438 int value = setup.window_scaling_percent;
4440 ti->node_top = &window_sizes;
4441 ti->sort_priority = value;
4443 sprintf(identifier, "%d", value);
4444 sprintf(name, "%d %% (Current)", value);
4446 setString(&ti->identifier, identifier);
4447 setString(&ti->name, name);
4448 setString(&ti->name_sorting, name);
4449 setString(&ti->infotext, "Window Scaling");
4451 pushTreeInfo(&window_sizes, ti);
4454 /* sort window size values to start with lowest window size value */
4455 sortTreeInfo(&window_sizes);
4457 /* set current window size value to configured window size value */
4458 window_size_current =
4459 getTreeInfoFromIdentifier(window_sizes,
4460 i_to_a(setup.window_scaling_percent));
4462 /* if that fails, set current window size to reliable default value */
4463 if (window_size_current == NULL)
4464 window_size_current =
4465 getTreeInfoFromIdentifier(window_sizes,
4466 i_to_a(STD_WINDOW_SCALING_PERCENT));
4468 /* if that also fails, set current window size to first available value */
4469 if (window_size_current == NULL)
4470 window_size_current = window_sizes;
4473 setup.window_scaling_percent = atoi(window_size_current->identifier);
4475 /* needed for displaying window size text instead of identifier */
4476 window_size_text = window_size_current->name;
4479 static void execSetupGraphics_setScalingTypes()
4481 if (scaling_types == NULL)
4485 for (i = 0; scaling_types_list[i].value != NULL; i++)
4487 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4488 char identifier[32], name[32];
4489 char *value = scaling_types_list[i].value;
4490 char *text = scaling_types_list[i].text;
4492 ti->node_top = &scaling_types;
4493 ti->sort_priority = i;
4495 sprintf(identifier, "%s", value);
4496 sprintf(name, "%s", text);
4498 setString(&ti->identifier, identifier);
4499 setString(&ti->name, name);
4500 setString(&ti->name_sorting, name);
4501 setString(&ti->infotext, "Anti-Aliasing");
4503 pushTreeInfo(&scaling_types, ti);
4506 /* sort scaling type values to start with lowest scaling type value */
4507 sortTreeInfo(&scaling_types);
4509 /* set current scaling type value to configured scaling type value */
4510 scaling_type_current =
4511 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4513 /* if that fails, set current scaling type to reliable default value */
4514 if (scaling_type_current == NULL)
4515 scaling_type_current =
4516 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4518 /* if that also fails, set current scaling type to first available value */
4519 if (scaling_type_current == NULL)
4520 scaling_type_current = scaling_types;
4523 setup.window_scaling_quality = scaling_type_current->identifier;
4525 /* needed for displaying scaling type text instead of identifier */
4526 scaling_type_text = scaling_type_current->name;
4529 static void execSetupGraphics_setScreenModes()
4531 // if (screen_modes == NULL && video.fullscreen_available)
4532 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4536 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4538 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4539 char identifier[32], name[32];
4540 int x = video.fullscreen_modes[i].width;
4541 int y = video.fullscreen_modes[i].height;
4544 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4546 ti->node_top = &screen_modes;
4547 ti->sort_priority = x * 10000 + y;
4549 sprintf(identifier, "%dx%d", x, y);
4550 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4552 setString(&ti->identifier, identifier);
4553 setString(&ti->name, name);
4554 setString(&ti->name_sorting, name);
4555 setString(&ti->infotext, "Fullscreen Mode");
4557 pushTreeInfo(&screen_modes, ti);
4560 /* sort fullscreen modes to start with lowest available screen resolution */
4561 sortTreeInfo(&screen_modes);
4563 /* set current screen mode for fullscreen mode to configured setup value */
4564 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4565 setup.fullscreen_mode);
4567 /* if that fails, set current screen mode to reliable default value */
4568 if (screen_mode_current == NULL)
4569 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4570 DEFAULT_FULLSCREEN_MODE);
4572 /* if that also fails, set current screen mode to first available mode */
4573 if (screen_mode_current == NULL)
4574 screen_mode_current = screen_modes;
4576 if (screen_mode_current == NULL)
4577 video.fullscreen_available = FALSE;
4580 // if (video.fullscreen_available)
4581 if (screen_mode_current != NULL)
4583 setup.fullscreen_mode = screen_mode_current->identifier;
4585 /* needed for displaying screen mode name instead of identifier */
4586 screen_mode_text = screen_mode_current->name;
4590 static void execSetupGraphics()
4592 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4594 // update "setup.window_scaling_percent" from list selection
4595 execSetupGraphics_setWindowSizes(FALSE);
4599 // update list selection from "setup.window_scaling_percent"
4600 execSetupGraphics_setWindowSizes(TRUE);
4603 execSetupGraphics_setScalingTypes();
4604 execSetupGraphics_setScreenModes();
4606 setup_mode = SETUP_MODE_GRAPHICS;
4610 #if defined(TARGET_SDL2)
4611 // window scaling may have changed at this point
4612 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4614 // window scaling quality may have changed at this point
4615 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4616 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4620 #if !defined(PLATFORM_ANDROID)
4621 #if defined(TARGET_SDL2)
4622 static void execSetupChooseWindowSize()
4625 if (!video.window_scaling_available)
4629 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4634 static void execSetupChooseScalingType()
4636 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4641 static void execSetupChooseScreenMode()
4643 if (!video.fullscreen_available)
4646 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4653 static void execSetupChooseVolumeSimple()
4655 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4660 static void execSetupChooseVolumeLoops()
4662 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4667 static void execSetupChooseVolumeMusic()
4669 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4674 static void execSetupSound()
4677 if (volumes_simple == NULL)
4681 for (i = 0; volumes_list[i].value != -1; i++)
4683 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4684 char identifier[32], name[32];
4685 int value = volumes_list[i].value;
4686 char *text = volumes_list[i].text;
4688 ti->node_top = &volumes_simple;
4689 ti->sort_priority = value;
4691 sprintf(identifier, "%d", value);
4692 sprintf(name, "%s", text);
4694 setString(&ti->identifier, identifier);
4695 setString(&ti->name, name);
4696 setString(&ti->name_sorting, name);
4697 setString(&ti->infotext, "Sound Volume");
4699 pushTreeInfo(&volumes_simple, ti);
4702 /* sort volume values to start with lowest volume value */
4703 sortTreeInfo(&volumes_simple);
4705 /* set current volume value to configured volume value */
4706 volume_simple_current =
4707 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4709 /* if that fails, set current volume to reliable default value */
4710 if (volume_simple_current == NULL)
4711 volume_simple_current =
4712 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4714 /* if that also fails, set current volume to first available value */
4715 if (volume_simple_current == NULL)
4716 volume_simple_current = volumes_simple;
4719 if (volumes_loops == NULL)
4723 for (i = 0; volumes_list[i].value != -1; i++)
4725 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4726 char identifier[32], name[32];
4727 int value = volumes_list[i].value;
4728 char *text = volumes_list[i].text;
4730 ti->node_top = &volumes_loops;
4731 ti->sort_priority = value;
4733 sprintf(identifier, "%d", value);
4734 sprintf(name, "%s", text);
4736 setString(&ti->identifier, identifier);
4737 setString(&ti->name, name);
4738 setString(&ti->name_sorting, name);
4739 setString(&ti->infotext, "Loops Volume");
4741 pushTreeInfo(&volumes_loops, ti);
4744 /* sort volume values to start with lowest volume value */
4745 sortTreeInfo(&volumes_loops);
4747 /* set current volume value to configured volume value */
4748 volume_loops_current =
4749 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4751 /* if that fails, set current volume to reliable default value */
4752 if (volume_loops_current == NULL)
4753 volume_loops_current =
4754 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4756 /* if that also fails, set current volume to first available value */
4757 if (volume_loops_current == NULL)
4758 volume_loops_current = volumes_loops;
4761 if (volumes_music == NULL)
4765 for (i = 0; volumes_list[i].value != -1; i++)
4767 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4768 char identifier[32], name[32];
4769 int value = volumes_list[i].value;
4770 char *text = volumes_list[i].text;
4772 ti->node_top = &volumes_music;
4773 ti->sort_priority = value;
4775 sprintf(identifier, "%d", value);
4776 sprintf(name, "%s", text);
4778 setString(&ti->identifier, identifier);
4779 setString(&ti->name, name);
4780 setString(&ti->name_sorting, name);
4781 setString(&ti->infotext, "Music Volume");
4783 pushTreeInfo(&volumes_music, ti);
4786 /* sort volume values to start with lowest volume value */
4787 sortTreeInfo(&volumes_music);
4789 /* set current volume value to configured volume value */
4790 volume_music_current =
4791 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4793 /* if that fails, set current volume to reliable default value */
4794 if (volume_music_current == NULL)
4795 volume_music_current =
4796 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4798 /* if that also fails, set current volume to first available value */
4799 if (volume_music_current == NULL)
4800 volume_music_current = volumes_music;
4803 setup.volume_simple = atoi(volume_simple_current->identifier);
4804 setup.volume_loops = atoi(volume_loops_current->identifier);
4805 setup.volume_music = atoi(volume_music_current->identifier);
4807 /* needed for displaying volume text instead of identifier */
4808 volume_simple_text = volume_simple_current->name;
4809 volume_loops_text = volume_loops_current->name;
4810 volume_music_text = volume_music_current->name;
4813 setup_mode = SETUP_MODE_SOUND;
4818 static void execSetupArtwork()
4821 printf("::: '%s', '%s', '%s'\n",
4822 artwork.gfx_current->subdir,
4823 artwork.gfx_current->fullpath,
4824 artwork.gfx_current->basepath);
4827 setup.graphics_set = artwork.gfx_current->identifier;
4828 setup.sounds_set = artwork.snd_current->identifier;
4829 setup.music_set = artwork.mus_current->identifier;
4831 /* needed if last screen (setup choice) changed graphics, sounds or music */
4832 ReloadCustomArtwork(0);
4834 /* needed for displaying artwork name instead of artwork identifier */
4835 graphics_set_name = artwork.gfx_current->name;
4836 sounds_set_name = artwork.snd_current->name;
4837 music_set_name = artwork.mus_current->name;
4839 setup_mode = SETUP_MODE_ARTWORK;
4844 static void execSetupChooseGraphics()
4846 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4851 static void execSetupChooseSounds()
4853 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4858 static void execSetupChooseMusic()
4860 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4865 static void execSetupInput()
4867 setup_mode = SETUP_MODE_INPUT;
4872 static void execSetupShortcuts()
4874 setup_mode = SETUP_MODE_SHORTCUTS;
4879 static void execSetupShortcuts1()
4881 setup_mode = SETUP_MODE_SHORTCUTS_1;
4886 static void execSetupShortcuts2()
4888 setup_mode = SETUP_MODE_SHORTCUTS_2;
4893 static void execSetupShortcuts3()
4895 setup_mode = SETUP_MODE_SHORTCUTS_3;
4900 static void execSetupShortcuts4()
4902 setup_mode = SETUP_MODE_SHORTCUTS_4;
4907 static void execSetupShortcuts5()
4909 setup_mode = SETUP_MODE_SHORTCUTS_5;
4914 static void execExitSetup()
4916 game_status = GAME_MODE_MAIN;
4918 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4921 static void execSaveAndExitSetup()
4927 static struct TokenInfo setup_info_main[] =
4929 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4930 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4931 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4932 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4933 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4934 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4935 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4936 { TYPE_EMPTY, NULL, "" },
4937 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4938 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4943 static struct TokenInfo setup_info_game[] =
4945 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4946 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4947 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4948 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4949 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4950 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4951 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4952 { TYPE_STRING, &game_speed_text, "" },
4954 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4955 { TYPE_STRING, &scroll_delay_text, "" },
4957 { TYPE_EMPTY, NULL, "" },
4958 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4963 static struct TokenInfo setup_info_editor[] =
4966 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4967 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4968 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4969 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4970 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4971 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4972 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4973 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4975 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4976 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4977 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4979 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4981 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4982 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4983 { TYPE_EMPTY, NULL, "" },
4985 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4986 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4987 { TYPE_EMPTY, NULL, "" },
4989 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4990 { TYPE_EMPTY, NULL, "" },
4991 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4996 static struct TokenInfo setup_info_graphics[] =
4998 #if !defined(PLATFORM_ANDROID)
4999 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5000 #if defined(TARGET_SDL2)
5001 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5002 { TYPE_STRING, &window_size_text, "" },
5004 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5005 { TYPE_STRING, &scaling_type_text, "" },
5008 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5009 { TYPE_STRING, &screen_mode_text, "" },
5013 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
5016 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
5017 { TYPE_STRING, &scroll_delay_text, "" },
5020 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
5022 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5023 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5024 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5025 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5026 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5027 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5028 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5029 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5030 { TYPE_EMPTY, NULL, "" },
5031 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5036 static struct TokenInfo setup_info_sound[] =
5038 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5039 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5040 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5041 { TYPE_EMPTY, NULL, "" },
5042 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5043 { TYPE_STRING, &volume_simple_text, "" },
5044 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5045 { TYPE_STRING, &volume_loops_text, "" },
5046 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5047 { TYPE_STRING, &volume_music_text, "" },
5048 { TYPE_EMPTY, NULL, "" },
5049 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5054 static struct TokenInfo setup_info_artwork[] =
5056 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5057 { TYPE_STRING, &graphics_set_name, "" },
5058 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5059 { TYPE_STRING, &sounds_set_name, "" },
5060 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5061 { TYPE_STRING, &music_set_name, "" },
5062 { TYPE_EMPTY, NULL, "" },
5065 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5066 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5067 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5069 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
5070 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
5071 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
5072 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
5075 { TYPE_STRING, NULL, "Override Level Artwork:"},
5076 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
5077 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
5078 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
5080 { TYPE_EMPTY, NULL, "" },
5081 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5086 static struct TokenInfo setup_info_input[] =
5088 { TYPE_SWITCH, NULL, "Player:" },
5089 { TYPE_SWITCH, NULL, "Device:" },
5090 { TYPE_ENTER_MENU, NULL, "" },
5091 { TYPE_EMPTY, NULL, "" },
5092 { TYPE_EMPTY, NULL, "" },
5093 { TYPE_EMPTY, NULL, "" },
5094 { TYPE_EMPTY, NULL, "" },
5095 { TYPE_EMPTY, NULL, "" },
5096 { TYPE_EMPTY, NULL, "" },
5097 { TYPE_EMPTY, NULL, "" },
5098 { TYPE_EMPTY, NULL, "" },
5099 { TYPE_EMPTY, NULL, "" },
5100 { TYPE_EMPTY, NULL, "" },
5101 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5106 static struct TokenInfo setup_info_shortcuts[] =
5108 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5109 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5110 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5111 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5112 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5113 { TYPE_EMPTY, NULL, "" },
5114 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5119 static struct TokenInfo setup_info_shortcuts_1[] =
5121 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5122 { TYPE_KEY, &setup.shortcut.save_game, "" },
5123 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5124 { TYPE_KEY, &setup.shortcut.load_game, "" },
5125 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5126 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5127 { TYPE_EMPTY, NULL, "" },
5128 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5129 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5130 { TYPE_EMPTY, NULL, "" },
5131 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5136 static struct TokenInfo setup_info_shortcuts_2[] =
5138 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5139 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5140 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5141 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5142 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5143 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5144 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5145 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5146 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5147 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5148 { TYPE_EMPTY, NULL, "" },
5149 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5154 static struct TokenInfo setup_info_shortcuts_3[] =
5156 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5157 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5158 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5159 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5160 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5161 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5162 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5163 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5164 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5165 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5166 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5167 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5168 { TYPE_EMPTY, NULL, "" },
5169 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5174 static struct TokenInfo setup_info_shortcuts_4[] =
5176 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5177 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5178 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5179 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5180 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5181 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5182 { TYPE_EMPTY, NULL, "" },
5183 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5188 static struct TokenInfo setup_info_shortcuts_5[] =
5190 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5191 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5192 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5193 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5194 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5195 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5196 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5197 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5198 { TYPE_EMPTY, NULL, "" },
5199 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5204 static Key getSetupKey()
5206 Key key = KSYM_UNDEFINED;
5207 boolean got_key_event = FALSE;
5209 while (!got_key_event)
5211 if (PendingEvent()) /* got event */
5219 case EVENT_KEYPRESS:
5221 key = GetEventKey((KeyEvent *)&event, TRUE);
5223 /* press 'Escape' or 'Enter' to keep the existing key binding */
5224 if (key == KSYM_Escape || key == KSYM_Return)
5225 key = KSYM_UNDEFINED; /* keep old value */
5227 got_key_event = TRUE;
5231 case EVENT_KEYRELEASE:
5232 key_joystick_mapping = 0;
5236 HandleOtherEvents(&event);
5244 /* don't eat all CPU time */
5251 static int getSetupTextFont(int type)
5253 if (type & (TYPE_SWITCH |
5265 static int getSetupValueFont(int type, void *value)
5267 if (type & TYPE_KEY)
5268 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5269 else if (type & TYPE_STRING)
5270 return FONT_VALUE_2;
5271 else if (type & TYPE_ECS_AGA)
5272 return FONT_VALUE_1;
5273 else if (type & TYPE_BOOLEAN_STYLE)
5274 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5275 else if (type & TYPE_YES_NO_AUTO)
5276 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5277 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5279 return FONT_VALUE_1;
5283 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5285 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5286 struct TokenInfo *si = &setup_info[si_pos];
5287 boolean font_draw_xoffset_modified = FALSE;
5288 int font_draw_xoffset_old = -1;
5289 int xoffset = (num_setup_info < max_setup_info ? -1 * 1 : 0);
5290 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5291 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5292 int xpos = menu_screen_value_xpos;
5293 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5294 int startx = mSX + xpos * 32;
5295 int starty = mSY + ypos * 32;
5296 int font_nr, font_width;
5300 int type = si->type;
5301 void *value = si->value;
5302 char *value_string = getSetupValue(type, value);
5307 if (value_string == NULL)
5310 if (type & TYPE_KEY)
5312 xpos = MENU_SCREEN_START_XPOS;
5314 if (type & TYPE_QUERY)
5315 value_string = "<press key>";
5317 else if (type & TYPE_STRING)
5319 int max_value_len = (SCR_FIELDX - 2) * 2;
5321 xpos = MENU_SCREEN_START_XPOS;
5323 if (strlen(value_string) > max_value_len)
5324 value_string[max_value_len] = '\0';
5326 else if (type & TYPE_YES_NO_AUTO)
5328 xpos = menu_screen_value_xpos - 1;
5331 startx = mSX + xpos * 32;
5332 starty = mSY + ypos * 32;
5333 font_nr = getSetupValueFont(type, value);
5334 font_width = getFontWidth(font_nr);
5336 font_height = getFontHeight(font_nr);
5339 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5340 if (1 && setup_mode != SETUP_MODE_INPUT)
5342 int max_menu_text_length_big = (menu_screen_value_xpos -
5343 MENU_SCREEN_START_XPOS);
5344 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5345 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5346 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5347 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5348 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5349 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5350 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5351 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5352 boolean correct_font_draw_xoffset = FALSE;
5354 if (xpos == MENU_SCREEN_START_XPOS &&
5355 startx + font1_xoffset < text_startx + text_font_xoffset)
5356 correct_font_draw_xoffset = TRUE;
5358 if (xpos == menu_screen_value_xpos &&
5359 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5360 correct_font_draw_xoffset = TRUE;
5362 /* check if setup value would overlap with setup text when printed */
5363 /* (this can happen for extreme/wrong values for font draw offset) */
5364 if (correct_font_draw_xoffset)
5366 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5367 font_draw_xoffset_modified = TRUE;
5369 if (type & TYPE_KEY)
5370 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5371 else if (!(type & TYPE_STRING))
5372 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5373 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5378 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5380 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5381 DrawText(startx + i * font_width, starty, " ", font_nr);
5384 // printf("::: startx == %d\n", startx);
5386 DrawText(startx, starty, value_string, font_nr);
5388 if (font_draw_xoffset_modified)
5389 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5394 static void drawSetupValue(int pos)
5396 boolean font_draw_xoffset_modified = FALSE;
5397 int font_draw_xoffset_old = -1;
5398 int xpos = MENU_SCREEN_VALUE_XPOS;
5399 int ypos = MENU_SCREEN_START_YPOS + pos;
5400 int startx = mSX + xpos * 32;
5401 int starty = mSY + ypos * 32;
5402 int font_nr, font_width;
5406 int type = setup_info[pos].type;
5407 void *value = setup_info[pos].value;
5408 char *value_string = getSetupValue(type, value);
5413 if (value_string == NULL)
5416 if (type & TYPE_KEY)
5418 xpos = MENU_SCREEN_START_XPOS;
5420 if (type & TYPE_QUERY)
5421 value_string = "<press key>";
5423 else if (type & TYPE_STRING)
5425 int max_value_len = (SCR_FIELDX - 2) * 2;
5427 xpos = MENU_SCREEN_START_XPOS;
5429 if (strlen(value_string) > max_value_len)
5430 value_string[max_value_len] = '\0';
5432 else if (type & TYPE_YES_NO_AUTO)
5434 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5437 startx = mSX + xpos * 32;
5438 starty = mSY + ypos * 32;
5439 font_nr = getSetupValueFont(type, value);
5440 font_width = getFontWidth(font_nr);
5442 font_height = getFontHeight(font_nr);
5445 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5446 if (setup_mode != SETUP_MODE_INPUT)
5448 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5449 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5450 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5451 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5452 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5453 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5454 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5455 boolean correct_font_draw_xoffset = FALSE;
5457 if (xpos == MENU_SCREEN_START_XPOS &&
5458 startx + font1_xoffset < text_startx + text_font_xoffset)
5459 correct_font_draw_xoffset = TRUE;
5461 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5462 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5463 correct_font_draw_xoffset = TRUE;
5465 /* check if setup value would overlap with setup text when printed */
5466 /* (this can happen for extreme/wrong values for font draw offset) */
5467 if (correct_font_draw_xoffset)
5469 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5470 font_draw_xoffset_modified = TRUE;
5472 if (type & TYPE_KEY)
5473 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5474 else if (!(type & TYPE_STRING))
5475 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5476 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5481 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5483 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5484 DrawText(startx + i * font_width, starty, " ", font_nr);
5487 DrawText(startx, starty, value_string, font_nr);
5489 if (font_draw_xoffset_modified)
5490 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5495 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5497 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5498 struct TokenInfo *si = &setup_info[si_pos];
5500 if (si->type & TYPE_BOOLEAN_STYLE)
5502 *(boolean *)si->value ^= TRUE;
5504 else if (si->type & TYPE_YES_NO_AUTO)
5508 (*(int *)si->value == AUTO ? TRUE :
5509 *(int *)si->value == TRUE ? FALSE : AUTO) :
5510 (*(int *)si->value == TRUE ? AUTO :
5511 *(int *)si->value == AUTO ? FALSE : TRUE));
5513 else if (si->type & TYPE_KEY)
5517 si->type |= TYPE_QUERY;
5518 drawSetupValue(screen_pos, setup_info_pos_raw);
5519 si->type &= ~TYPE_QUERY;
5521 key = getSetupKey();
5522 if (key != KSYM_UNDEFINED)
5523 *(Key *)si->value = key;
5526 drawSetupValue(screen_pos, setup_info_pos_raw);
5528 // fullscreen state may have changed at this point
5529 if (si->value == &setup.fullscreen)
5530 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5535 static void changeSetupValue(int pos, int dx)
5537 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5539 *(boolean *)setup_info[pos].value ^= TRUE;
5541 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5543 *(int *)setup_info[pos].value =
5545 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5546 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5547 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5548 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5550 else if (setup_info[pos].type & TYPE_KEY)
5554 setup_info[pos].type |= TYPE_QUERY;
5555 drawSetupValue(pos, -1);
5556 setup_info[pos].type &= ~TYPE_QUERY;
5558 key = getSetupKey();
5559 if (key != KSYM_UNDEFINED)
5560 *(Key *)setup_info[pos].value = key;
5563 drawSetupValue(pos, -1);
5565 // fullscreen state may have changed at this point
5566 if (setup_info[pos].value == &setup.fullscreen)
5567 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5572 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5575 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5576 struct TokenInfo *si = &setup_info[si_pos];
5577 int xpos = MENU_SCREEN_START_XPOS;
5578 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5579 int font_nr = getSetupTextFont(si->type);
5581 if (setup_info == setup_info_input)
5582 font_nr = FONT_MENU_1;
5585 font_nr = FONT_ACTIVE(font_nr);
5587 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5589 if (si->type & ~TYPE_SKIP_ENTRY)
5590 drawCursor(screen_pos, active);
5593 static void DrawCursorAndText_Setup(int pos, boolean active)
5595 int xpos = MENU_SCREEN_START_XPOS;
5596 int ypos = MENU_SCREEN_START_YPOS + pos;
5597 int font_nr = getSetupTextFont(setup_info[pos].type);
5599 if (setup_info == setup_info_input)
5600 font_nr = FONT_MENU_1;
5603 font_nr = FONT_ACTIVE(font_nr);
5605 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5607 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5608 drawCursor(pos, active);
5612 static void drawSetupInfoList(struct TokenInfo *setup_info,
5613 int first_entry, int num_page_entries)
5617 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5618 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5620 if (num_page_entries > max_setup_info)
5621 num_page_entries = max_setup_info;
5623 if (first_entry + num_page_entries > max_setup_info)
5627 /* clear tree list area, but not title or scrollbar */
5628 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
5629 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
5630 NUM_MENU_ENTRIES_ON_SCREEN * 32);
5633 for (i = 0; i < num_page_entries; i++)
5635 int setup_info_pos = first_entry + i;
5636 struct TokenInfo *si = &setup_info[setup_info_pos];
5637 void *value_ptr = si->value;
5639 /* set some entries to "unchangeable" according to other variables */
5640 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5641 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5642 (value_ptr == &setup.sound_music && !audio.music_available) ||
5643 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5644 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5645 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5646 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5647 si->type |= TYPE_GHOSTED;
5649 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5650 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5651 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5652 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5653 else if (si->type & ~TYPE_SKIP_ENTRY)
5654 initCursor(i, IMG_MENU_BUTTON);
5656 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5658 if (si->type & TYPE_VALUE)
5659 drawSetupValue(i, setup_info_pos);
5663 static void DrawSetupScreen_Generic()
5665 boolean redraw_all = FALSE;
5666 char *title_string = NULL;
5672 FreeScreenGadgets();
5673 CreateScreenGadgets();
5676 CloseDoor(DOOR_CLOSE_2);
5678 if (redraw_mask & REDRAW_ALL)
5682 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5683 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5684 int2str(0, redraw_mask)));
5688 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5689 FadeOut(redraw_mask);
5691 FadeOut(REDRAW_FIELD);
5696 if (setup_mode == SETUP_MODE_MAIN)
5698 setup_info = setup_info_main;
5699 title_string = "Setup";
5701 else if (setup_mode == SETUP_MODE_GAME)
5703 setup_info = setup_info_game;
5704 title_string = "Setup Game";
5706 else if (setup_mode == SETUP_MODE_EDITOR)
5708 setup_info = setup_info_editor;
5709 title_string = "Setup Editor";
5711 else if (setup_mode == SETUP_MODE_GRAPHICS)
5713 setup_info = setup_info_graphics;
5714 title_string = "Setup Graphics";
5716 else if (setup_mode == SETUP_MODE_SOUND)
5718 setup_info = setup_info_sound;
5719 title_string = "Setup Sound";
5721 else if (setup_mode == SETUP_MODE_ARTWORK)
5723 setup_info = setup_info_artwork;
5724 title_string = "Custom Artwork";
5726 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5728 setup_info = setup_info_shortcuts;
5729 title_string = "Setup Shortcuts";
5731 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5733 setup_info = setup_info_shortcuts_1;
5734 title_string = "Setup Shortcuts";
5736 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5738 setup_info = setup_info_shortcuts_2;
5739 title_string = "Setup Shortcuts";
5741 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5743 setup_info = setup_info_shortcuts_3;
5744 title_string = "Setup Shortcuts";
5746 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5748 setup_info = setup_info_shortcuts_4;
5749 title_string = "Setup Shortcuts";
5751 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5753 setup_info = setup_info_shortcuts_5;
5754 title_string = "Setup Shortcuts";
5757 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5762 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5766 for (i = 0; setup_info[i].type != 0; i++)
5770 drawSetupInfoList(setup_info, 0, NUM_MENU_ENTRIES_ON_SCREEN);
5777 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5779 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5782 void *value_ptr = setup_info[i].value;
5784 /* set some entries to "unchangeable" according to other variables */
5785 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5786 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5787 (value_ptr == &setup.sound_music && !audio.music_available) ||
5788 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5789 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5790 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5791 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5792 setup_info[i].type |= TYPE_GHOSTED;
5794 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5795 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5796 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5797 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5798 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5799 initCursor(i, IMG_MENU_BUTTON);
5801 DrawCursorAndText_Setup(i, FALSE);
5803 if (setup_info[i].type & TYPE_VALUE)
5811 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5812 "Joysticks deactivated in setup menu");
5816 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5820 MapScreenGadgets(max_setup_info);
5824 redraw_mask = REDRAW_ALL;
5827 FadeIn(redraw_mask);
5829 FadeIn(REDRAW_FIELD);
5834 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5838 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5840 static int choice_store[MAX_SETUP_MODES];
5841 static int first_entry_store[MAX_SETUP_MODES];
5842 int choice = choice_store[setup_mode]; /* starts with 0 */
5843 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5846 int y = choice - first_entry;
5851 boolean position_set_by_scrollbar = (dx == 999);
5853 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5854 int num_page_entries;
5856 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5859 if (button == MB_MENU_INITIALIZE)
5861 /* advance to first valid menu entry */
5862 while (choice < num_setup_info &&
5863 setup_info[choice].type & TYPE_SKIP_ENTRY)
5866 choice_store[setup_mode] = choice;
5870 if (position_set_by_scrollbar)
5871 first_entry = first_entry_store[setup_mode] = dy;
5873 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5874 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5876 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5880 if (choice < first_entry)
5881 choice = first_entry;
5882 else if (choice > first_entry + num_page_entries - 1)
5883 choice = first_entry + num_page_entries - 1;
5885 choice_store[setup_mode] = choice;
5887 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5889 DrawCursorAndText_Setup(choice, -1, TRUE);
5894 else if (button == MB_MENU_LEAVE)
5898 PlaySound(SND_MENU_ITEM_SELECTING);
5900 for (i = 0; setup_info[i].type != 0; i++)
5902 if (setup_info[i].type & TYPE_LEAVE_MENU)
5904 void (*menu_callback_function)(void) = setup_info[i].value;
5908 menu_callback_function();
5910 break; /* absolutely needed because function changes 'setup_info'! */
5917 if (mx || my) /* mouse input */
5919 x = (mx - mSX) / 32;
5920 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5923 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5925 else if (dx || dy) /* keyboard input */
5928 /* move cursor instead of scrolling when already at start/end of list */
5929 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5931 else if (dy == +1 * SCROLL_LINE &&
5932 first_entry + num_page_entries == max_setup_info)
5935 /* handle scrolling screen one line or page */
5937 y + dy > num_page_entries - 1)
5939 boolean redraw = FALSE;
5941 if (ABS(dy) == SCROLL_PAGE)
5942 step = num_page_entries - 1;
5944 if (dy < 0 && first_entry > 0)
5946 /* scroll page/line up */
5948 first_entry -= step;
5949 if (first_entry < 0)
5954 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5956 /* scroll page/line down */
5958 first_entry += step;
5959 if (first_entry + num_page_entries > max_setup_info)
5960 first_entry = MAX(0, max_setup_info - num_page_entries);
5967 choice += first_entry - first_entry_store[setup_mode];
5969 first_entry_store[setup_mode] = first_entry;
5971 if (choice < first_entry)
5972 choice = first_entry;
5973 else if (choice > first_entry + num_page_entries - 1)
5974 choice = first_entry + num_page_entries - 1;
5976 choice_store[setup_mode] = choice;
5978 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5980 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5982 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5983 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5991 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5993 if (setup_info[choice].type & menu_navigation_type ||
5994 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5995 setup_info[choice].type & TYPE_YES_NO_AUTO)
5996 button = MB_MENU_CHOICE;
6006 /* jump to next non-empty menu entry (up or down) */
6007 while (y > 0 && y < num_setup_info - 1 &&
6008 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6011 if (!IN_VIS_FIELD(x, y))
6013 first_entry += y - y_old;
6015 if (first_entry >= 0 &&
6016 first_entry + num_page_entries <= max_setup_info)
6018 first_entry_store[setup_mode] = first_entry;
6020 if (choice < first_entry)
6021 choice = first_entry;
6022 else if (choice > first_entry + num_page_entries - 1)
6023 choice = first_entry + num_page_entries - 1;
6025 choice_store[setup_mode] = choice;
6027 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6029 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6031 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6032 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6040 if (!anyScrollbarGadgetActive() &&
6041 IN_VIS_FIELD(x, y) &&
6042 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
6043 y >= 0 && y < num_page_entries)
6045 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
6049 printf("::: TEST/HandleSetupScreen_Generic [%d, %d, %d, %d]\n", Counter(),
6050 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
6056 if (first_entry + y != choice &&
6057 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
6059 PlaySound(SND_MENU_ITEM_ACTIVATING);
6061 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
6062 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
6064 choice = choice_store[setup_mode] = first_entry + y;
6067 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
6069 PlaySound(SND_MENU_ITEM_ACTIVATING);
6071 DrawCursorAndText_Setup(choice, -1, FALSE);
6072 DrawCursorAndText_Setup(y, -1, TRUE);
6074 choice = choice_store[setup_mode] = y;
6079 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
6081 PlaySound(SND_MENU_ITEM_SELECTING);
6083 /* when selecting key headline, execute function for key value change */
6084 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
6085 setup_info[first_entry + y + 1].type & TYPE_KEY)
6088 /* when selecting string value, execute function for list selection */
6089 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
6090 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
6093 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
6095 void (*menu_callback_function)(void) =
6096 setup_info[first_entry + y].value;
6098 FadeSetFromType(setup_info[first_entry + y].type);
6100 menu_callback_function();
6104 if (setup_info[first_entry + y].type & TYPE_VALUE)
6105 changeSetupValue(y, first_entry + y, dx);
6109 else if (!(setup_info[y].type & TYPE_GHOSTED))
6111 PlaySound(SND_MENU_ITEM_SELECTING);
6113 /* when selecting key headline, execute function for key value change */
6114 if (setup_info[y].type & TYPE_KEYTEXT &&
6115 setup_info[y + 1].type & TYPE_KEY)
6118 /* when selecting string value, execute function for list selection */
6119 if (setup_info[y].type & TYPE_STRING && y > 0 &&
6120 setup_info[y - 1].type & TYPE_ENTER_LIST)
6123 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
6125 void (*menu_callback_function)(void) = setup_info[y].value;
6127 FadeSetFromType(setup_info[y].type);
6129 menu_callback_function();
6133 if (setup_info[y].type & TYPE_VALUE)
6134 changeSetupValue(y, dx);
6141 void DrawSetupScreen_Input()
6146 FadeOut(REDRAW_FIELD);
6152 setup_info = setup_info_input;
6155 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
6159 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6160 "Joysticks deactivated on this screen");
6162 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6163 "Joysticks deactivated on this screen");
6168 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6170 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6173 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6174 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6175 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6176 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6177 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6178 initCursor(i, IMG_MENU_BUTTON);
6180 DrawCursorAndText_Setup(i, -1, FALSE);
6184 DeactivateJoystickForCalibration();
6189 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6190 "Joysticks deactivated on this screen");
6192 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6193 "Joysticks deactivated on this screen");
6197 /* create gadgets for setup input menu screen */
6198 FreeScreenGadgets();
6199 CreateScreenGadgets();
6201 /* map gadgets for setup input menu screen */
6202 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6204 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6207 FadeIn(REDRAW_FIELD);
6213 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6215 if (device_name == NULL)
6218 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6221 if (strlen(device_name) > 1)
6223 char c1 = device_name[strlen(device_name) - 1];
6224 char c2 = device_name[strlen(device_name) - 2];
6226 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6227 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6230 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6231 strlen(device_name));
6234 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6237 static struct SetupKeyboardInfo custom_key;
6244 { &custom_key.left, "Joystick Left" },
6245 { &custom_key.right, "Joystick Right" },
6246 { &custom_key.up, "Joystick Up" },
6247 { &custom_key.down, "Joystick Down" },
6248 { &custom_key.snap, "Button 1" },
6249 { &custom_key.drop, "Button 2" }
6251 static char *joystick_name[MAX_PLAYERS] =
6258 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6262 custom_key = setup.input[player_nr].key;
6264 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6265 FONT_INPUT_1_ACTIVE);
6267 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6269 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6270 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6272 if (setup.input[player_nr].use_joystick)
6274 char *device_name = setup.input[player_nr].joy.device_name;
6275 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6276 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6278 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6279 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6283 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6284 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6287 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6289 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6290 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6291 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6292 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6294 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6295 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6296 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6297 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6298 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6299 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6301 for (i = 0; i < 6; i++)
6303 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6305 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6307 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6308 (setup.input[player_nr].use_joystick ?
6310 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6314 static int input_player_nr = 0;
6316 void HandleSetupScreen_Input_Player(int step, int direction)
6318 int old_player_nr = input_player_nr;
6321 new_player_nr = old_player_nr + step * direction;
6322 if (new_player_nr < 0)
6324 if (new_player_nr > MAX_PLAYERS - 1)
6325 new_player_nr = MAX_PLAYERS - 1;
6327 if (new_player_nr != old_player_nr)
6329 input_player_nr = new_player_nr;
6331 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6335 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6337 static int choice = 0;
6340 int pos_start = SETUPINPUT_SCREEN_POS_START;
6341 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6342 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6343 int pos_end = SETUPINPUT_SCREEN_POS_END;
6345 if (button == MB_MENU_INITIALIZE)
6347 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6349 DrawCursorAndText_Setup(choice, -1, TRUE);
6353 else if (button == MB_MENU_LEAVE)
6355 setup_mode = SETUP_MODE_MAIN;
6362 if (mx || my) /* mouse input */
6364 x = (mx - mSX) / 32;
6365 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6367 else if (dx || dy) /* keyboard input */
6369 if (dx && choice == 0)
6370 x = (dx < 0 ? 10 : 12);
6371 else if ((dx && choice == 1) ||
6372 (dx == +1 && choice == 2) ||
6373 (dx == -1 && choice == pos_end))
6374 button = MB_MENU_CHOICE;
6378 if (y >= pos_empty1 && y <= pos_empty2)
6379 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6382 if (y == 0 && dx != 0 && button)
6384 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6386 else if (IN_VIS_FIELD(x, y) &&
6387 y >= pos_start && y <= pos_end &&
6388 !(y >= pos_empty1 && y <= pos_empty2))
6394 DrawCursorAndText_Setup(choice, -1, FALSE);
6395 DrawCursorAndText_Setup(y, -1, TRUE);
6397 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6406 char *device_name = setup.input[input_player_nr].joy.device_name;
6408 if (!setup.input[input_player_nr].use_joystick)
6410 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6412 setJoystickDeviceToNr(device_name, new_device_nr);
6413 setup.input[input_player_nr].use_joystick = TRUE;
6417 int device_nr = getJoystickNrFromDeviceName(device_name);
6418 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6420 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6421 setup.input[input_player_nr].use_joystick = FALSE;
6423 setJoystickDeviceToNr(device_name, new_device_nr);
6426 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6430 if (setup.input[input_player_nr].use_joystick)
6433 CalibrateJoystick(input_player_nr);
6436 CustomizeKeyboard(input_player_nr);
6438 else if (y == pos_end)
6444 setup_mode = SETUP_MODE_MAIN;
6451 void CustomizeKeyboard(int player_nr)
6455 boolean finished = FALSE;
6456 static struct SetupKeyboardInfo custom_key;
6461 } customize_step[] =
6463 { &custom_key.left, "Move Left" },
6464 { &custom_key.right, "Move Right" },
6465 { &custom_key.up, "Move Up" },
6466 { &custom_key.down, "Move Down" },
6467 { &custom_key.snap, "Snap Field" },
6468 { &custom_key.drop, "Drop Element" }
6471 /* read existing key bindings from player setup */
6472 custom_key = setup.input[player_nr].key;
6475 FadeOut(REDRAW_FIELD);
6479 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6487 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6488 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6489 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6490 "Key:", FONT_INPUT_1_ACTIVE);
6491 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6492 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6495 FadeIn(REDRAW_FIELD);
6502 if (PendingEvent()) /* got event */
6510 case EVENT_KEYPRESS:
6512 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6514 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6516 if (key == KSYM_Escape)
6517 FadeSkipNextFadeIn();
6523 /* all keys configured -- wait for "Escape" or "Return" key */
6527 /* press 'Enter' to keep the existing key binding */
6528 if (key == KSYM_Return)
6529 key = *customize_step[step_nr].key;
6531 /* check if key already used */
6532 for (i = 0; i < step_nr; i++)
6533 if (*customize_step[i].key == key)
6538 /* got new key binding */
6539 *customize_step[step_nr].key = key;
6540 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6542 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6543 getKeyNameFromKey(key), FONT_VALUE_1);
6546 /* un-highlight last query */
6547 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6548 customize_step[step_nr - 1].text, FONT_MENU_1);
6549 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6550 "Key:", FONT_MENU_1);
6552 /* press 'Enter' to leave */
6555 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6556 "Press Enter", FONT_TITLE_1);
6560 /* query next key binding */
6561 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6562 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6563 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6564 "Key:", FONT_INPUT_1_ACTIVE);
6565 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6566 getKeyNameFromKey(*customize_step[step_nr].key),
6571 case EVENT_KEYRELEASE:
6572 key_joystick_mapping = 0;
6576 HandleOtherEvents(&event);
6584 /* don't eat all CPU time */
6588 /* write new key bindings back to player setup */
6589 setup.input[player_nr].key = custom_key;
6592 DrawSetupScreen_Input();
6595 static boolean CalibrateJoystickMain(int player_nr)
6597 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6598 int new_joystick_xright = JOYSTICK_XMIDDLE;
6599 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6600 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6601 int new_joystick_xmiddle, new_joystick_ymiddle;
6603 int joystick_fd = joystick.fd[player_nr];
6604 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6605 boolean check[3][3];
6606 int check_remaining = 3 * 3;
6611 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6614 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6618 FadeOut(REDRAW_FIELD);
6622 for (y = 0; y < 3; y++)
6624 for (x = 0; x < 3; x++)
6626 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6627 check[x][y] = FALSE;
6631 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6632 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6633 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6634 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6635 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6636 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6637 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6639 joy_value = Joystick(player_nr);
6640 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6641 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6643 /* eventually uncalibrated center position (joystick could be uncentered) */
6644 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6647 new_joystick_xmiddle = joy_x;
6648 new_joystick_ymiddle = joy_y;
6650 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6652 FadeIn(REDRAW_FIELD);
6654 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6659 if (PendingEvent()) /* got event */
6667 case EVENT_KEYPRESS:
6668 switch (GetEventKey((KeyEvent *)&event, TRUE))
6671 if (check_remaining == 0)
6676 FadeSkipNextFadeIn();
6685 case EVENT_KEYRELEASE:
6686 key_joystick_mapping = 0;
6690 HandleOtherEvents(&event);
6695 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6698 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6699 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6700 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6701 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6703 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6704 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6705 setup.input[player_nr].joy.xright = new_joystick_xright;
6706 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6707 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6708 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6710 CheckJoystickData();
6712 joy_value = Joystick(player_nr);
6714 if (joy_value & JOY_BUTTON && check_remaining == 0)
6717 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6718 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6720 if (x != last_x || y != last_y)
6722 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6723 IMG_MENU_CALIBRATE_YELLOW, 0);
6724 DrawFixedGraphic(xpos + x, ypos + y,
6725 IMG_MENU_CALIBRATE_RED, 0);
6730 if (check_remaining > 0 && !check[x+1][y+1])
6732 check[x+1][y+1] = TRUE;
6738 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6739 setup.input[player_nr].joy.xleft,
6740 setup.input[player_nr].joy.xmiddle,
6741 setup.input[player_nr].joy.xright);
6742 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6743 setup.input[player_nr].joy.yupper,
6744 setup.input[player_nr].joy.ymiddle,
6745 setup.input[player_nr].joy.ylower);
6754 /* don't eat all CPU time */
6758 /* calibrated center position (joystick should now be centered) */
6759 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6762 new_joystick_xmiddle = joy_x;
6763 new_joystick_ymiddle = joy_y;
6768 DrawSetupScreen_Input();
6771 /* wait until the last pressed button was released */
6772 while (Joystick(player_nr) & JOY_BUTTON)
6774 if (PendingEvent()) /* got event */
6779 HandleOtherEvents(&event);
6788 void CalibrateJoystick(int player_nr)
6790 if (!CalibrateJoystickMain(player_nr))
6792 char *device_name = setup.input[player_nr].joy.device_name;
6793 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6794 int xpos = mSX - SX;
6795 int ypos = mSY - SY;
6799 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6800 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6803 Delay(2000); /* show error message for a short time */
6809 DrawSetupScreen_Input();
6813 void DrawSetupScreen()
6815 DeactivateJoystick();
6817 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6819 if (setup_mode == SETUP_MODE_INPUT)
6820 DrawSetupScreen_Input();
6821 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6822 DrawChooseTree(&game_speed_current);
6823 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6824 DrawChooseTree(&scroll_delay_current);
6825 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6826 DrawChooseTree(&screen_mode_current);
6827 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6828 DrawChooseTree(&window_size_current);
6829 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6830 DrawChooseTree(&scaling_type_current);
6831 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6832 DrawChooseTree(&artwork.gfx_current);
6833 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6834 DrawChooseTree(&artwork.snd_current);
6835 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6836 DrawChooseTree(&artwork.mus_current);
6837 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6838 DrawChooseTree(&volume_simple_current);
6839 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6840 DrawChooseTree(&volume_loops_current);
6841 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6842 DrawChooseTree(&volume_music_current);
6844 DrawSetupScreen_Generic();
6850 void RedrawSetupScreenAfterFullscreenToggle()
6853 if (setup_mode == SETUP_MODE_GRAPHICS ||
6854 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6856 // update list selection from "setup.window_scaling_percent"
6857 execSetupGraphics_setWindowSizes(TRUE);
6862 if (setup_mode == SETUP_MODE_GRAPHICS)
6867 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6869 if (setup_mode == SETUP_MODE_INPUT)
6870 HandleSetupScreen_Input(mx, my, dx, dy, button);
6871 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6872 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6873 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6874 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6875 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6876 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6877 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6878 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6879 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6880 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6881 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6882 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6883 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6884 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6885 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6886 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6887 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6888 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6889 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6890 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6891 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6892 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6894 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6901 void HandleGameActions()
6903 if (game_status != GAME_MODE_PLAYING)
6906 GameActions(); /* main game loop */
6908 if (tape.auto_play && !tape.playing)
6909 AutoPlayTape(); /* continue automatically playing next tape */
6913 /* ---------- new screen button stuff -------------------------------------- */
6915 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6920 case SCREEN_CTRL_ID_PREV_LEVEL:
6921 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6922 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6925 case SCREEN_CTRL_ID_NEXT_LEVEL:
6926 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6927 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6930 case SCREEN_CTRL_ID_PREV_LEVEL:
6931 *x = mSX + TILEX * getPrevlevelButtonPos();
6932 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6935 case SCREEN_CTRL_ID_NEXT_LEVEL:
6936 *x = mSX + TILEX * getNextLevelButtonPos();
6937 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6941 case SCREEN_CTRL_ID_PREV_PLAYER:
6942 *x = mSX + TILEX * 10;
6943 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6946 case SCREEN_CTRL_ID_NEXT_PLAYER:
6947 *x = mSX + TILEX * 12;
6948 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6952 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6958 int gfx_unpressed, gfx_pressed;
6959 void (*get_gadget_position)(int *, int *, int);
6963 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6966 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6967 getScreenMenuButtonPos,
6968 SCREEN_CTRL_ID_PREV_LEVEL,
6973 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6974 getScreenMenuButtonPos,
6975 SCREEN_CTRL_ID_NEXT_LEVEL,
6980 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6981 getScreenMenuButtonPos,
6982 SCREEN_CTRL_ID_PREV_PLAYER,
6987 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6988 getScreenMenuButtonPos,
6989 SCREEN_CTRL_ID_NEXT_PLAYER,
6997 int gfx_unpressed, gfx_pressed;
7001 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7004 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7006 -1, -1, /* these values are not constant, but can change at runtime */
7008 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
7010 SCREEN_CTRL_ID_SCROLL_UP,
7014 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7016 -1, -1, /* these values are not constant, but can change at runtime */
7018 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
7020 SCREEN_CTRL_ID_SCROLL_DOWN,
7027 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7028 Bitmap **gfx_unpressed, **gfx_pressed;
7030 int gfx_unpressed, gfx_pressed;
7037 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7040 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7041 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
7043 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7046 -1, -1, /* these values are not constant, but can change at runtime */
7047 -1, -1, /* these values are not constant, but can change at runtime */
7049 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
7050 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
7052 GD_TYPE_SCROLLBAR_VERTICAL,
7053 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7054 "scroll level series vertically"
7058 static void CreateScreenMenubuttons()
7060 struct GadgetInfo *gi;
7061 unsigned int event_mask;
7064 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7066 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7067 int gfx_unpressed, gfx_pressed;
7068 int x, y, width, height;
7069 int gd_x1, gd_x2, gd_y1, gd_y2;
7070 int id = menubutton_info[i].gadget_id;
7072 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7074 menubutton_info[i].get_gadget_position(&x, &y, id);
7076 width = SC_MENUBUTTON_XSIZE;
7077 height = SC_MENUBUTTON_YSIZE;
7079 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7080 gfx_pressed = menubutton_info[i].gfx_pressed;
7081 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7082 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7083 gd_x1 = graphic_info[gfx_unpressed].src_x;
7084 gd_y1 = graphic_info[gfx_unpressed].src_y;
7085 gd_x2 = graphic_info[gfx_pressed].src_x;
7086 gd_y2 = graphic_info[gfx_pressed].src_y;
7088 gi = CreateGadget(GDI_CUSTOM_ID, id,
7089 GDI_CUSTOM_TYPE_ID, i,
7090 GDI_INFO_TEXT, menubutton_info[i].infotext,
7095 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7096 GDI_STATE, GD_BUTTON_UNPRESSED,
7097 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7098 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7099 GDI_DIRECT_DRAW, FALSE,
7100 GDI_EVENT_MASK, event_mask,
7101 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7105 Error(ERR_EXIT, "cannot create gadget");
7107 screen_gadget[id] = gi;
7111 static void CreateScreenScrollbuttons()
7113 struct GadgetInfo *gi;
7114 unsigned int event_mask;
7117 /* these values are not constant, but can change at runtime */
7118 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7119 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7120 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7121 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7123 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7125 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7126 int gfx_unpressed, gfx_pressed;
7127 int x, y, width, height;
7128 int gd_x1, gd_x2, gd_y1, gd_y2;
7129 int id = scrollbutton_info[i].gadget_id;
7131 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7133 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7134 y = mSY + scrollbutton_info[i].y;
7135 width = SC_SCROLLBUTTON_XSIZE;
7136 height = SC_SCROLLBUTTON_YSIZE;
7138 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7139 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7140 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7142 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7143 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7144 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7145 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7146 gd_x1 = graphic_info[gfx_unpressed].src_x;
7147 gd_y1 = graphic_info[gfx_unpressed].src_y;
7148 gd_x2 = graphic_info[gfx_pressed].src_x;
7149 gd_y2 = graphic_info[gfx_pressed].src_y;
7151 gi = CreateGadget(GDI_CUSTOM_ID, id,
7152 GDI_CUSTOM_TYPE_ID, i,
7153 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7158 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7159 GDI_STATE, GD_BUTTON_UNPRESSED,
7160 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7161 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7162 GDI_DIRECT_DRAW, FALSE,
7163 GDI_EVENT_MASK, event_mask,
7164 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7168 Error(ERR_EXIT, "cannot create gadget");
7170 screen_gadget[id] = gi;
7174 static void CreateScreenScrollbars()
7178 /* these values are not constant, but can change at runtime */
7179 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7180 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7181 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7182 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7184 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7186 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7187 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7188 int gfx_unpressed, gfx_pressed;
7190 int x, y, width, height;
7191 int gd_x1, gd_x2, gd_y1, gd_y2;
7192 struct GadgetInfo *gi;
7193 int items_max, items_visible, item_position;
7194 unsigned int event_mask;
7195 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7196 int id = scrollbar_info[i].gadget_id;
7198 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7200 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7201 y = mSY + scrollbar_info[i].y;
7202 width = scrollbar_info[i].width;
7203 height = scrollbar_info[i].height;
7205 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7206 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7208 items_max = num_page_entries;
7209 items_visible = num_page_entries;
7212 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7213 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
7214 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
7220 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7221 gfx_pressed = scrollbar_info[i].gfx_pressed;
7222 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7223 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7224 gd_x1 = graphic_info[gfx_unpressed].src_x;
7225 gd_y1 = graphic_info[gfx_unpressed].src_y;
7226 gd_x2 = graphic_info[gfx_pressed].src_x;
7227 gd_y2 = graphic_info[gfx_pressed].src_y;
7230 gi = CreateGadget(GDI_CUSTOM_ID, id,
7231 GDI_CUSTOM_TYPE_ID, i,
7232 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7237 GDI_TYPE, scrollbar_info[i].type,
7238 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7239 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7240 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7242 GDI_WHEEL_AREA_X, SX,
7243 GDI_WHEEL_AREA_Y, SY,
7244 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7245 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7247 GDI_WHEEL_AREA_X, 0,
7248 GDI_WHEEL_AREA_Y, 0,
7249 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
7250 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
7252 GDI_STATE, GD_BUTTON_UNPRESSED,
7253 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7254 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7255 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7256 GDI_DIRECT_DRAW, FALSE,
7257 GDI_EVENT_MASK, event_mask,
7258 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7262 Error(ERR_EXIT, "cannot create gadget");
7264 screen_gadget[id] = gi;
7268 void CreateScreenGadgets()
7270 int last_game_status = game_status; /* save current game status */
7272 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7275 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
7277 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
7279 /* copy pointers to clip mask and GC */
7280 scrollbar_bitmap[i]->clip_mask =
7281 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
7282 scrollbar_bitmap[i]->stored_clip_gc =
7283 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
7285 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
7286 scrollbar_bitmap[i],
7287 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
7288 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
7289 TILEX, TILEY, 0, 0);
7293 CreateScreenMenubuttons();
7296 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
7297 game_status = GAME_MODE_LEVELS;
7300 CreateScreenScrollbuttons();
7301 CreateScreenScrollbars();
7303 game_status = last_game_status; /* restore current game status */
7306 void FreeScreenGadgets()
7310 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7311 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
7313 /* prevent freeing clip mask and GC twice */
7314 scrollbar_bitmap[i]->clip_mask = None;
7315 scrollbar_bitmap[i]->stored_clip_gc = None;
7317 FreeBitmap(scrollbar_bitmap[i]);
7321 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7322 FreeGadget(screen_gadget[i]);
7325 void MapScreenMenuGadgets(int screen_mask)
7329 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7330 if (screen_mask & menubutton_info[i].screen_mask)
7331 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7334 void MapScreenGadgets(int num_entries)
7338 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7341 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7342 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7344 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7345 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7348 void MapScreenTreeGadgets(TreeInfo *ti)
7351 MapScreenGadgets(numTreeInfoInGroup(ti));
7353 int num_entries = numTreeInfoInGroup(ti);
7356 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7359 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7360 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7362 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7363 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7367 static void HandleScreenGadgets(struct GadgetInfo *gi)
7369 int id = gi->custom_id;
7370 int button = gi->event.button;
7371 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7375 case SCREEN_CTRL_ID_PREV_LEVEL:
7376 HandleMainMenu_SelectLevel(step, -1);
7379 case SCREEN_CTRL_ID_NEXT_LEVEL:
7380 HandleMainMenu_SelectLevel(step, +1);
7383 case SCREEN_CTRL_ID_PREV_PLAYER:
7384 HandleSetupScreen_Input_Player(step, -1);
7387 case SCREEN_CTRL_ID_NEXT_PLAYER:
7388 HandleSetupScreen_Input_Player(step, +1);
7391 case SCREEN_CTRL_ID_SCROLL_UP:
7392 if (game_status == GAME_MODE_LEVELS)
7393 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7394 else if (game_status == GAME_MODE_LEVELNR)
7395 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7396 else if (game_status == GAME_MODE_SETUP)
7397 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7400 case SCREEN_CTRL_ID_SCROLL_DOWN:
7401 if (game_status == GAME_MODE_LEVELS)
7402 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7403 else if (game_status == GAME_MODE_LEVELNR)
7404 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7405 else if (game_status == GAME_MODE_SETUP)
7406 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7409 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7410 if (game_status == GAME_MODE_LEVELS)
7411 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7412 else if (game_status == GAME_MODE_LEVELNR)
7413 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7414 else if (game_status == GAME_MODE_SETUP)
7415 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);