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 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_SHORTCUTS_1 7
49 #define SETUP_MODE_SHORTCUTS_2 8
51 /* sub-screens on the setup screen (generic) */
52 #define SETUP_MODE_CHOOSE_ARTWORK 9
53 #define SETUP_MODE_CHOOSE_OTHER 10
55 /* sub-screens on the setup screen (specific) */
56 #define SETUP_MODE_CHOOSE_GAME_SPEED 11
57 #define SETUP_MODE_CHOOSE_SCREEN_MODE 12
58 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 13
59 #define SETUP_MODE_CHOOSE_GRAPHICS 14
60 #define SETUP_MODE_CHOOSE_SOUNDS 15
61 #define SETUP_MODE_CHOOSE_MUSIC 16
63 #define MAX_SETUP_MODES 17
65 /* for input setup functions */
66 #define SETUPINPUT_SCREEN_POS_START 0
67 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
68 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
69 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
71 /* for various menu stuff */
72 #define MENU_SCREEN_START_XPOS 1
73 #define MENU_SCREEN_START_YPOS 2
74 #define MENU_SCREEN_VALUE_XPOS 14
75 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
76 #define MENU_TITLE1_YPOS 8
77 #define MENU_TITLE2_YPOS 46
78 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
79 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
80 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
81 MENU_SCREEN_START_XPOS)
82 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
84 /* buttons and scrollbars identifiers */
85 #define SCREEN_CTRL_ID_PREV_LEVEL 0
86 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
87 #define SCREEN_CTRL_ID_PREV_PLAYER 2
88 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
89 #define SCREEN_CTRL_ID_SCROLL_UP 4
90 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
91 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
93 #define NUM_SCREEN_GADGETS 7
95 #define NUM_SCREEN_MENUBUTTONS 4
96 #define NUM_SCREEN_SCROLLBUTTONS 2
97 #define NUM_SCREEN_SCROLLBARS 1
99 #define SCREEN_MASK_MAIN (1 << 0)
100 #define SCREEN_MASK_INPUT (1 << 1)
102 /* graphic position and size values for buttons and scrollbars */
103 #define SC_MENUBUTTON_XSIZE TILEX
104 #define SC_MENUBUTTON_YSIZE TILEY
106 #define SC_SCROLLBUTTON_XSIZE TILEX
107 #define SC_SCROLLBUTTON_YSIZE TILEY
109 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
111 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
112 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
113 SC_SCROLLBUTTON_YSIZE)
115 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
118 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
119 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
120 SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
124 SC_SCROLL_VERTICAL_YSIZE)
126 #define SC_BORDER_SIZE 14
129 /* forward declarations of internal functions */
130 static void HandleScreenGadgets(struct GadgetInfo *);
131 static void HandleSetupScreen_Generic(int, int, int, int, int);
132 static void HandleSetupScreen_Input(int, int, int, int, int);
133 static void CustomizeKeyboard(int);
134 static void CalibrateJoystick(int);
135 static void execSetupGame(void);
136 static void execSetupGraphics(void);
137 static void execSetupArtwork(void);
138 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
140 static void DrawChooseLevel(void);
141 static void DrawInfoScreen(void);
142 static void DrawAndFadeInInfoScreen(int);
143 static void DrawSetupScreen(void);
145 static void DrawInfoScreenExt(int, int);
146 static void DrawInfoScreen_NotAvailable(char *, char *);
147 static void DrawInfoScreen_HelpAnim(int, int, boolean);
148 static void DrawInfoScreen_HelpText(int, int, int, int);
149 static void HandleInfoScreen_Main(int, int, int, int, int);
150 static void HandleInfoScreen_TitleScreen(int);
151 static void HandleInfoScreen_Elements(int);
152 static void HandleInfoScreen_Music(int);
153 static void HandleInfoScreen_Credits(int);
154 static void HandleInfoScreen_Program(int);
155 static void HandleInfoScreen_Version(int);
157 static void MapScreenMenuGadgets(int);
158 static void MapScreenTreeGadgets(TreeInfo *);
160 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
162 static int info_mode = INFO_MODE_MAIN;
163 static int setup_mode = SETUP_MODE_MAIN;
165 static TreeInfo *screen_modes = NULL;
166 static TreeInfo *screen_mode_current = NULL;
168 static TreeInfo *scroll_delays = NULL;
169 static TreeInfo *scroll_delay_current = NULL;
171 static TreeInfo *game_speeds = NULL;
172 static TreeInfo *game_speed_current = NULL;
178 } game_speeds_list[] =
187 { 1000, "1/1s (Extremely Slow)" },
192 { 29, "1/35s (Original Supaplex)" },
194 { 20, "1/50s (Normal Speed)" },
195 { 14, "1/70s (Maximum Supaplex)" },
199 { 1, "1/1000s (Extremely Fast)" },
209 } scroll_delays_list[] =
211 { 0, "0 Tiles (No Scroll Delay)" },
214 { 3, "3 Tiles (Default)" },
219 { 8, "8 Tiles (Maximum Scroll Delay)"},
224 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
225 (s) <= GAME_MODE_SETUP ? (s) : \
226 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
227 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
229 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
230 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
231 (i) <= INFO_MODE_LEVELSET ? (i) : \
234 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
235 (i) <= SETUP_MODE_SHORTCUTS_2 ? (i) : \
236 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
237 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
238 SETUP_MODE_CHOOSE_ARTWORK : \
239 SETUP_MODE_CHOOSE_OTHER)
241 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
242 menu.draw_xoffset[GAME_MODE_INFO] : \
243 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
244 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
245 menu.draw_yoffset[GAME_MODE_INFO] : \
246 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
248 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
249 menu.draw_xoffset[GAME_MODE_SETUP] : \
250 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
251 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
252 menu.draw_yoffset[GAME_MODE_SETUP] : \
253 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
255 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
256 DRAW_XOFFSET_INFO(info_mode) : \
257 (s) == GAME_MODE_SETUP ? \
258 DRAW_XOFFSET_SETUP(setup_mode) : \
259 menu.draw_xoffset[DRAW_MODE(s)])
260 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
261 DRAW_YOFFSET_INFO(info_mode) : \
262 (s) == GAME_MODE_SETUP ? \
263 DRAW_YOFFSET_SETUP(setup_mode) : \
264 menu.draw_yoffset[DRAW_MODE(s)])
266 #define mSX (SX + DRAW_XOFFSET(game_status))
267 #define mSY (SY + DRAW_YOFFSET(game_status))
269 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
270 menu.list_size[game_status] : \
271 MAX_MENU_ENTRIES_ON_SCREEN)
273 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
274 #define NUM_SCROLLBAR_BITMAPS 2
275 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
279 /* title display and control definitions */
281 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
282 2 * MAX_NUM_TITLE_MESSAGES)
284 static int num_title_screens = 0;
286 struct TitleControlInfo
294 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
296 /* main menu display and control definitions */
298 #define MAIN_CONTROL_NAME 0
299 #define MAIN_CONTROL_LEVELS 1
300 #define MAIN_CONTROL_SCORES 2
301 #define MAIN_CONTROL_EDITOR 3
302 #define MAIN_CONTROL_INFO 4
303 #define MAIN_CONTROL_GAME 5
304 #define MAIN_CONTROL_SETUP 6
305 #define MAIN_CONTROL_QUIT 7
306 #define MAIN_CONTROL_PREV_LEVEL 8
307 #define MAIN_CONTROL_NEXT_LEVEL 9
308 #define MAIN_CONTROL_FIRST_LEVEL 10
309 #define MAIN_CONTROL_LAST_LEVEL 11
310 #define MAIN_CONTROL_LEVEL_NUMBER 12
311 #define MAIN_CONTROL_LEVEL_INFO_1 13
312 #define MAIN_CONTROL_LEVEL_INFO_2 14
313 #define MAIN_CONTROL_LEVEL_NAME 15
314 #define MAIN_CONTROL_LEVEL_AUTHOR 16
315 #define MAIN_CONTROL_LEVEL_YEAR 17
316 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
317 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
318 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
319 #define MAIN_CONTROL_TITLE_1 21
320 #define MAIN_CONTROL_TITLE_2 22
321 #define MAIN_CONTROL_TITLE_3 23
323 static char str_main_text_name[10];
324 static char str_main_text_first_level[10];
325 static char str_main_text_last_level[10];
326 static char str_main_text_level_number[10];
328 static char *main_text_name = str_main_text_name;
329 static char *main_text_first_level = str_main_text_first_level;
330 static char *main_text_last_level = str_main_text_last_level;
331 static char *main_text_level_number = str_main_text_level_number;
332 static char *main_text_levels = "Levelset";
333 static char *main_text_scores = "Hall Of Fame";
334 static char *main_text_editor = "Level Creator";
335 static char *main_text_info = "Info Screen";
336 static char *main_text_game = "Start Game";
337 static char *main_text_setup = "Setup";
338 static char *main_text_quit = "Quit";
339 static char *main_text_level_name = level.name;
340 static char *main_text_level_author = level.author;
341 static char *main_text_level_year = NULL;
342 static char *main_text_level_imported_from = NULL;
343 static char *main_text_level_imported_by = NULL;
344 static char *main_text_level_tested_by = NULL;
345 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
346 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
347 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
349 struct MainControlInfo
353 struct MenuPosInfo *pos_button;
356 struct TextPosInfo *pos_text;
359 struct TextPosInfo *pos_input;
363 static struct MainControlInfo main_controls[] =
367 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
368 &menu.main.text.name, &main_text_name,
369 &menu.main.input.name, &setup.player_name,
373 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
374 &menu.main.text.levels, &main_text_levels,
379 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
380 &menu.main.text.scores, &main_text_scores,
385 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
386 &menu.main.text.editor, &main_text_editor,
391 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
392 &menu.main.text.info, &main_text_info,
397 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
398 &menu.main.text.game, &main_text_game,
403 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
404 &menu.main.text.setup, &main_text_setup,
409 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
410 &menu.main.text.quit, &main_text_quit,
414 /* (these two buttons are real gadgets) */
416 MAIN_CONTROL_PREV_LEVEL,
417 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
422 MAIN_CONTROL_NEXT_LEVEL,
423 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
429 MAIN_CONTROL_FIRST_LEVEL,
431 &menu.main.text.first_level, &main_text_first_level,
435 MAIN_CONTROL_LAST_LEVEL,
437 &menu.main.text.last_level, &main_text_last_level,
441 MAIN_CONTROL_LEVEL_NUMBER,
443 &menu.main.text.level_number, &main_text_level_number,
447 MAIN_CONTROL_LEVEL_INFO_1,
449 &menu.main.text.level_info_1, NULL,
453 MAIN_CONTROL_LEVEL_INFO_2,
455 &menu.main.text.level_info_2, NULL,
459 MAIN_CONTROL_LEVEL_NAME,
461 &menu.main.text.level_name, &main_text_level_name,
465 MAIN_CONTROL_LEVEL_AUTHOR,
467 &menu.main.text.level_author, &main_text_level_author,
471 MAIN_CONTROL_LEVEL_YEAR,
473 &menu.main.text.level_year, &main_text_level_year,
477 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
479 &menu.main.text.level_imported_from, &main_text_level_imported_from,
483 MAIN_CONTROL_LEVEL_IMPORTED_BY,
485 &menu.main.text.level_imported_by, &main_text_level_imported_by,
489 MAIN_CONTROL_LEVEL_TESTED_BY,
491 &menu.main.text.level_tested_by, &main_text_level_tested_by,
495 MAIN_CONTROL_TITLE_1,
497 &menu.main.text.title_1, &main_text_title_1,
501 MAIN_CONTROL_TITLE_2,
503 &menu.main.text.title_2, &main_text_title_2,
507 MAIN_CONTROL_TITLE_3,
509 &menu.main.text.title_3, &main_text_title_3,
522 static int getTitleScreenGraphic(int nr, boolean initial)
524 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
527 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
529 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
533 static int getTitleScreenGameMode(boolean initial)
535 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
539 static int getTitleMessageGameMode(boolean initial)
541 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
545 static int getTitleScreenBackground(boolean initial)
547 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
552 static int getTitleMessageBackground(int nr, boolean initial)
554 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
558 static int getTitleBackground(int nr, boolean initial, boolean is_image)
560 int base = (is_image ?
561 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
562 IMG_BACKGROUND_TITLESCREEN_1) :
563 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
564 IMG_BACKGROUND_TITLEMESSAGE_1));
565 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
566 IMG_BACKGROUND_TITLE);
567 int graphic_local = base + nr;
569 if (graphic_info[graphic_local].bitmap != NULL)
570 return graphic_local;
572 if (graphic_info[graphic_global].bitmap != NULL)
573 return graphic_global;
575 return IMG_UNDEFINED;
578 static int getTitleSound(struct TitleControlInfo *tci)
580 boolean is_image = tci->is_image;
581 int initial = tci->initial;
582 int nr = tci->local_nr;
583 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
584 int base = (is_image ?
585 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
586 SND_BACKGROUND_TITLESCREEN_1) :
587 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
588 SND_BACKGROUND_TITLEMESSAGE_1));
589 int sound_global = menu.sound[mode];
590 int sound_local = base + nr;
593 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
594 nr, initial, is_image,
595 sound_global, getSoundListEntry(sound_global)->filename,
596 sound_local, getSoundListEntry(sound_local)->filename);
599 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
602 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
605 return SND_UNDEFINED;
608 static int getTitleMusic(struct TitleControlInfo *tci)
610 boolean is_image = tci->is_image;
611 int initial = tci->initial;
612 int nr = tci->local_nr;
613 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
614 int base = (is_image ?
615 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
616 MUS_BACKGROUND_TITLESCREEN_1) :
617 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
618 MUS_BACKGROUND_TITLEMESSAGE_1));
619 int music_global = menu.music[mode];
620 int music_local = base + nr;
623 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
624 nr, initial, is_image,
625 music_global, getMusicListEntry(music_global)->filename,
626 music_local, getMusicListEntry(music_local)->filename);
629 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
632 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
635 return MUS_UNDEFINED;
638 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
640 boolean is_image = tci->is_image;
641 int initial = tci->initial;
642 int nr = tci->local_nr;
643 struct TitleFadingInfo ti;
647 int graphic = getTitleScreenGraphic(nr, initial);
649 /* initialize fading control values to default title config settings */
650 ti = (initial ? title_initial_default : title_default);
652 /* override default settings with image config settings, if defined */
653 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
654 ti.fade_mode = graphic_info[graphic].fade_mode;
655 if (graphic_info[graphic].fade_delay > -1)
656 ti.fade_delay = graphic_info[graphic].fade_delay;
657 if (graphic_info[graphic].post_delay > -1)
658 ti.post_delay = graphic_info[graphic].post_delay;
659 if (graphic_info[graphic].auto_delay > -1)
660 ti.auto_delay = graphic_info[graphic].auto_delay;
666 ti.fade_mode = titlemessage_initial[nr].fade_mode;
667 ti.fade_delay = titlemessage_initial[nr].fade_delay;
668 ti.post_delay = titlemessage_initial[nr].post_delay;
669 ti.auto_delay = titlemessage_initial[nr].auto_delay;
673 ti.fade_mode = titlemessage[nr].fade_mode;
674 ti.fade_delay = titlemessage[nr].fade_delay;
675 ti.post_delay = titlemessage[nr].post_delay;
676 ti.auto_delay = titlemessage[nr].auto_delay;
681 if (ti.anim_mode == ANIM_NONE)
682 ti.fade_delay = ti.post_delay = 0;
688 static int compareTitleControlInfo(const void *object1, const void *object2)
690 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
691 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
694 if (tci1->initial != tci2->initial)
695 compare_result = (tci1->initial ? -1 : +1);
696 else if (tci1->sort_priority != tci2->sort_priority)
697 compare_result = tci1->sort_priority - tci2->sort_priority;
698 else if (tci1->is_image != tci2->is_image)
699 compare_result = (tci1->is_image ? -1 : +1);
701 compare_result = tci1->local_nr - tci2->local_nr;
703 return compare_result;
706 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
708 int nr, int sort_priority)
710 title_controls[num_title_screens].is_image = is_image;
711 title_controls[num_title_screens].initial = initial;
712 title_controls[num_title_screens].local_nr = nr;
713 title_controls[num_title_screens].sort_priority = sort_priority;
718 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
722 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
724 int graphic = getTitleScreenGraphic(i, initial);
725 Bitmap *bitmap = graphic_info[graphic].bitmap;
726 int sort_priority = graphic_info[graphic].sort_priority;
729 /* skip images and messages (fonts!) when using forced custom graphics */
730 if (setup.override_level_graphics && !initial)
735 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
738 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
740 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
741 char *filename = getLevelSetTitleMessageFilename(i, initial);
742 int sort_priority = tmi->sort_priority;
745 /* skip images and messages (fonts!) when using forced custom graphics */
746 if (setup.override_level_graphics)
750 if (filename != NULL)
751 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
755 static void InitializeTitleControls(boolean show_title_initial)
757 num_title_screens = 0;
760 /* 1st step: initialize title screens for game start (only when starting) */
761 if (show_title_initial)
762 InitializeTitleControls_CheckTitleInfo(TRUE);
765 /* 2nd step: initialize title screens for current level set */
766 InitializeTitleControls_CheckTitleInfo(FALSE);
768 /* sort title screens according to sort_priority and title number */
769 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
770 compareTitleControlInfo);
773 static boolean visibleMenuPos(struct MenuPosInfo *pos)
775 return (pos != NULL && pos->x != -1 && pos->y != -1);
778 static boolean visibleTextPos(struct TextPosInfo *pos)
780 return (pos != NULL && pos->x != -1 && pos->y != -1);
783 static void InitializeMainControls()
785 boolean local_team_mode = (!options.network && setup.team_mode);
788 /* set main control text values to dynamically determined values */
789 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
791 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
792 menu.main.text.first_level.size));
793 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
794 menu.main.text.last_level.size));
795 strcpy(main_text_level_number, int2str(level_nr,
796 menu.main.text.level_number.size));
798 main_text_level_year = leveldir_current->year;
799 main_text_level_imported_from = leveldir_current->imported_from;
800 main_text_level_imported_by = leveldir_current->imported_by;
801 main_text_level_tested_by = leveldir_current->tested_by;
803 /* set main control screen positions to dynamically determined values */
804 for (i = 0; main_controls[i].nr != -1; i++)
806 struct MainControlInfo *mci = &main_controls[i];
808 struct MenuPosInfo *pos_button = mci->pos_button;
809 struct TextPosInfo *pos_text = mci->pos_text;
810 struct TextPosInfo *pos_input = mci->pos_input;
811 char *text = (mci->text ? *mci->text : NULL);
812 char *input = (mci->input ? *mci->input : NULL);
813 int button_graphic = mci->button_graphic;
815 int font_text = (pos_text ? pos_text->font : -1);
816 int font_input = (pos_input ? pos_input->font : -1);
818 int font_text = mci->font_text;
819 int font_input = mci->font_input;
822 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
823 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
824 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
825 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
826 int text_chars = (text != NULL ? strlen(text) : 0);
827 int input_chars = (input != NULL ? strlen(input) : 0);
830 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
832 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
833 int text_width = font_text_width * text_chars;
834 int text_height = font_text_height;
835 int input_width = font_input_width * input_chars;
836 int input_height = font_input_height;
838 if (nr == MAIN_CONTROL_NAME)
841 if (menu.main.input.name.x == -1)
842 menu.main.input.name.x = menu.main.text.name.x + text_width;
843 if (menu.main.input.name.y == -1)
844 menu.main.input.name.y = menu.main.text.name.y;
848 menu.main.input.name.width = input_width;
849 menu.main.input.name.height = input_height;
851 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
852 menu.main.input.name.height = font_input_height;
856 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
858 if (pos_button->width == 0)
859 pos_button->width = button_width;
860 if (pos_button->height == 0)
861 pos_button->height = button_height;
864 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
866 /* calculate width for non-clickable text -- needed for text alignment */
867 boolean calculate_text_width = (pos_button == NULL && text != NULL);
869 if (visibleMenuPos(pos_button))
871 if (pos_text->x == -1)
872 pos_text->x = pos_button->x + pos_button->width;
873 if (pos_text->y == -1)
874 pos_text->y = pos_button->y;
877 if (pos_text->width == -1 || calculate_text_width)
878 pos_text->width = text_width;
879 if (pos_text->height == -1)
880 pos_text->height = text_height;
883 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
885 if (visibleTextPos(pos_text))
887 if (pos_input->x == -1)
888 pos_input->x = pos_text->x + pos_text->width;
889 if (pos_input->y == -1)
890 pos_input->y = pos_text->y;
893 if (pos_input->width == -1)
894 pos_input->width = input_width;
895 if (pos_input->height == -1)
896 pos_input->height = input_height;
901 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
902 boolean active_input)
906 for (i = 0; main_controls[i].nr != -1; i++)
908 struct MainControlInfo *mci = &main_controls[i];
910 if (mci->nr == nr || nr == -1)
912 struct MenuPosInfo *pos_button = mci->pos_button;
913 struct TextPosInfo *pos_text = mci->pos_text;
914 struct TextPosInfo *pos_input = mci->pos_input;
915 char *text = (mci->text ? *mci->text : NULL);
916 char *input = (mci->input ? *mci->input : NULL);
917 int button_graphic = mci->button_graphic;
919 int font_text = (pos_text ? pos_text->font : -1);
920 int font_input = (pos_input ? pos_input->font : -1);
922 int font_text = mci->font_text;
923 int font_input = mci->font_input;
928 button_graphic = BUTTON_ACTIVE(button_graphic);
929 font_text = FONT_ACTIVE(font_text);
934 font_input = FONT_ACTIVE(font_input);
937 if (visibleMenuPos(pos_button))
939 struct MenuPosInfo *pos = pos_button;
940 int x = mSX + pos->x;
941 int y = mSY + pos->y;
943 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
944 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
947 if (visibleTextPos(pos_text) && text != NULL)
949 struct TextPosInfo *pos = pos_text;
950 int x = mSX + ALIGNED_TEXT_XPOS(pos);
951 int y = mSY + ALIGNED_TEXT_YPOS(pos);
954 /* (check why/if this is needed) */
955 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
957 DrawText(x, y, text, font_text);
960 if (visibleTextPos(pos_input) && input != NULL)
962 struct TextPosInfo *pos = pos_input;
963 int x = mSX + ALIGNED_TEXT_XPOS(pos);
964 int y = mSY + ALIGNED_TEXT_YPOS(pos);
967 /* (check why/if this is needed) */
968 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
970 DrawText(x, y, input, font_input);
976 static void DrawCursorAndText_Main(int nr, boolean active_text)
978 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
982 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
984 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
988 static struct MainControlInfo *getMainControlInfo(int nr)
992 for (i = 0; main_controls[i].nr != -1; i++)
993 if (main_controls[i].nr == nr)
994 return &main_controls[i];
999 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1004 int rect_x = ALIGNED_TEXT_XPOS(rect);
1005 int rect_y = ALIGNED_TEXT_YPOS(rect);
1007 return (x >= rect_x && x < rect_x + rect->width &&
1008 y >= rect_y && y < rect_y + rect->height);
1011 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1016 int rect_x = ALIGNED_TEXT_XPOS(rect);
1017 int rect_y = ALIGNED_TEXT_YPOS(rect);
1019 return (x >= rect_x && x < rect_x + rect->width &&
1020 y >= rect_y && y < rect_y + rect->height);
1023 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1025 static int cursor_array[SCR_FIELDY];
1026 int x = mSX + TILEX * xpos;
1027 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1032 cursor_array[ypos] = graphic;
1034 graphic = cursor_array[ypos];
1038 graphic = BUTTON_ACTIVE(graphic);
1040 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1041 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1044 static void initCursor(int ypos, int graphic)
1046 drawCursorExt(0, ypos, FALSE, graphic);
1049 static void drawCursor(int ypos, boolean active)
1051 drawCursorExt(0, ypos, active, -1);
1054 static void drawCursorXY(int xpos, int ypos, int graphic)
1056 drawCursorExt(xpos, ypos, FALSE, graphic);
1059 static void drawChooseTreeCursor(int ypos, boolean active)
1061 int last_game_status = game_status; /* save current game status */
1064 /* force LEVELS draw offset on artwork setup screen */
1065 game_status = GAME_MODE_LEVELS;
1068 drawCursorExt(0, ypos, active, -1);
1070 game_status = last_game_status; /* restore current game status */
1075 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1076 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1080 static int getPrevlevelButtonPos()
1085 static int getCurrentLevelTextPos()
1087 return (getPrevlevelButtonPos() + 1);
1090 static int getNextLevelButtonPos()
1092 return getPrevlevelButtonPos() + 3 + 1;
1095 static int getLevelRangeTextPos()
1097 return getNextLevelButtonPos() + 1;
1101 int effectiveGameStatus()
1103 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1104 return GAME_MODE_TITLE;
1109 void DrawTitleScreenImage(int nr, boolean initial)
1111 int graphic = getTitleScreenGraphic(nr, initial);
1112 Bitmap *bitmap = graphic_info[graphic].bitmap;
1113 int width = graphic_info[graphic].width;
1114 int height = graphic_info[graphic].height;
1115 int src_x = graphic_info[graphic].src_x;
1116 int src_y = graphic_info[graphic].src_y;
1122 if (width > WIN_XSIZE)
1124 /* image width too large for window => center image horizontally */
1125 src_x = (width - WIN_XSIZE) / 2;
1129 if (height > WIN_YSIZE)
1131 /* image height too large for window => center image vertically */
1132 src_y = (height - WIN_YSIZE) / 2;
1136 /* always display title screens centered */
1137 dst_x = (WIN_XSIZE - width) / 2;
1138 dst_y = (WIN_YSIZE - height) / 2;
1140 SetDrawBackgroundMask(REDRAW_ALL);
1141 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1143 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1145 if (DrawingOnBackground(dst_x, dst_y))
1147 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1148 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1151 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1153 redraw_mask = REDRAW_ALL;
1156 void DrawTitleScreenMessage(int nr, boolean initial)
1158 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1159 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1160 int last_game_status = game_status; /* save current game status */
1162 if (filename == NULL)
1165 /* force TITLE font on title message screen */
1166 game_status = getTitleMessageGameMode(initial);
1168 /* if chars set to "-1", automatically determine by text and font width */
1169 if (tmi->chars == -1)
1170 tmi->chars = tmi->width / getFontWidth(tmi->font);
1172 tmi->width = tmi->chars * getFontWidth(tmi->font);
1174 /* if lines set to "-1", automatically determine by text and font height */
1175 if (tmi->lines == -1)
1176 tmi->lines = tmi->height / getFontHeight(tmi->font);
1178 tmi->height = tmi->lines * getFontHeight(tmi->font);
1180 SetDrawBackgroundMask(REDRAW_ALL);
1181 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1183 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1185 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1186 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1187 tmi->autowrap, tmi->centered, tmi->parse_comments);
1189 game_status = last_game_status; /* restore current game status */
1192 void DrawTitleScreen()
1194 KeyboardAutoRepeatOff();
1197 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1200 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1205 boolean CheckTitleScreen(boolean levelset_has_changed)
1207 static boolean show_title_initial = TRUE;
1208 boolean show_titlescreen = FALSE;
1210 /* needed to be able to skip title screen, if no image or message defined */
1211 InitializeTitleControls(show_title_initial);
1213 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1214 show_titlescreen = TRUE;
1216 /* show initial title images and messages only once at program start */
1217 show_title_initial = FALSE;
1219 return (show_titlescreen && num_title_screens > 0);
1222 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1224 static LevelDirTree *leveldir_last_valid = NULL;
1225 boolean levelset_has_changed = FALSE;
1227 FadeSetLeaveScreen();
1229 /* do not fade out here -- function may continue and fade on editor screen */
1232 FadeSoundsAndMusic();
1234 KeyboardAutoRepeatOn();
1237 SetDrawDeactivationMask(REDRAW_NONE);
1238 SetDrawBackgroundMask(REDRAW_FIELD);
1240 audio.sound_deactivated = FALSE;
1244 /* needed if last screen was the playing screen, invoked from level editor */
1245 if (level_editor_test_game)
1247 game_status = GAME_MODE_EDITOR;
1253 /* needed if last screen was the setup screen and fullscreen state changed */
1254 ToggleFullscreenIfNeeded();
1256 /* leveldir_current may be invalid (level group, parent link) */
1257 if (!validLevelSeries(leveldir_current))
1258 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1260 if (leveldir_current != leveldir_last_valid)
1261 levelset_has_changed = TRUE;
1263 /* store valid level series information */
1264 leveldir_last_valid = leveldir_current;
1266 /* needed if last screen (level choice) changed graphics, sounds or music */
1267 ReloadCustomArtwork(0);
1269 if (redraw_mask & REDRAW_ALL)
1270 fade_mask = REDRAW_ALL;
1275 /* needed if last screen was the editor screen */
1276 UndrawSpecialEditorDoor();
1278 if (fade_mask == REDRAW_FIELD)
1283 #if defined(TARGET_SDL)
1284 SetDrawtoField(DRAW_BACKBUFFER);
1287 if (CheckTitleScreen(levelset_has_changed))
1289 game_status = GAME_MODE_TITLE;
1296 /* level_nr may have been set to value over handicap with level editor */
1297 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1298 level_nr = leveldir_current->handicap_level;
1300 LoadLevel(level_nr);
1301 LoadScore(level_nr);
1303 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1306 if (fade_mask == REDRAW_ALL)
1308 // int door_state = GetDoorState();
1312 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1318 InitializeMainControls();
1320 DrawCursorAndText_Main(-1, FALSE);
1321 DrawPreviewLevel(TRUE);
1323 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1326 if (TAPE_IS_EMPTY(tape))
1328 DrawCompleteVideoDisplay();
1333 /* create gadgets for main menu screen */
1334 FreeScreenGadgets();
1335 CreateScreenGadgets();
1337 /* map gadgets for main menu screen */
1339 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1342 if (fade_mask == REDRAW_ALL)
1344 int door_state = GetDoorState();
1346 // RedrawBackground();
1348 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1352 DrawMaskedBorder(REDRAW_ALL);
1358 /* update screen area with special editor door */
1359 redraw_mask |= REDRAW_ALL;
1363 SetMouseCursor(CURSOR_DEFAULT);
1367 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1370 void DrawAndFadeInMainMenu(int fade_mask)
1372 DrawMainMenuExt(fade_mask, TRUE);
1377 DrawMainMenuExt(REDRAW_ALL, FALSE);
1381 static void gotoTopLevelDir()
1383 /* move upwards to top level directory */
1384 while (leveldir_current->node_parent)
1386 /* write a "path" into level tree for easy navigation to last level */
1387 if (leveldir_current->node_parent->node_group->cl_first == -1)
1389 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1390 int leveldir_pos = posTreeInfo(leveldir_current);
1391 int num_page_entries;
1392 int cl_first, cl_cursor;
1394 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1395 num_page_entries = num_leveldirs;
1397 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1399 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1400 cl_cursor = leveldir_pos - cl_first;
1402 leveldir_current->node_parent->node_group->cl_first = cl_first;
1403 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1406 leveldir_current = leveldir_current->node_parent;
1411 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1413 static unsigned long title_delay = 0;
1414 static int title_screen_nr = 0;
1415 static int last_sound = -1, last_music = -1;
1416 boolean return_to_main_menu = FALSE;
1417 boolean use_fading_main_menu = TRUE;
1418 struct TitleControlInfo *tci;
1419 struct TitleFadingInfo fading_default;
1420 struct TitleFadingInfo fading_last = fading;
1421 struct TitleFadingInfo fading_next;
1424 if (button == MB_MENU_INITIALIZE)
1427 title_screen_nr = 0;
1428 tci = &title_controls[title_screen_nr];
1430 last_sound = SND_UNDEFINED;
1431 last_music = MUS_UNDEFINED;
1433 if (game_status == GAME_MODE_INFO)
1435 if (num_title_screens == 0)
1437 DrawInfoScreen_NotAvailable("Title screen information:",
1438 "No title screen for this level set.");
1443 FadeSoundsAndMusic();
1446 FadeOut(REDRAW_ALL);
1451 DrawTitleScreenImage(tci->local_nr, tci->initial);
1453 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1455 fading_default = (tci->initial ? title_initial_default : title_default);
1457 fading = fading_next = getTitleFading(tci);
1461 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1462 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1464 fading.fade_mode = FADE_MODE_FADE;
1465 fading.fade_delay = fading_default.fade_delay;
1468 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1469 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1470 fading.fade_mode = FADE_MODE_FADE;
1475 sound = getTitleSound(tci);
1476 music = getTitleMusic(tci);
1478 if (sound != last_sound)
1479 PlayMenuSoundExt(sound);
1480 if (music != last_music)
1481 PlayMenuMusicExt(music);
1487 SetMouseCursor(CURSOR_NONE);
1493 fading = fading_next;
1495 DelayReached(&title_delay, 0); /* reset delay counter */
1501 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1502 button = MB_MENU_CHOICE;
1504 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1505 button = MB_MENU_CHOICE;
1508 if (button == MB_MENU_LEAVE)
1510 return_to_main_menu = TRUE;
1511 use_fading_main_menu = FALSE;
1513 else if (button == MB_MENU_CHOICE)
1515 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1518 FadeOut(REDRAW_FIELD);
1521 FadeSetEnterScreen();
1523 info_mode = INFO_MODE_MAIN;
1524 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1530 tci = &title_controls[title_screen_nr];
1532 if (title_screen_nr < num_title_screens)
1534 sound = getTitleSound(tci);
1535 music = getTitleMusic(tci);
1537 if (sound == SND_UNDEFINED || sound != last_sound)
1539 if (music == MUS_UNDEFINED || music != last_music)
1543 FadeOut(REDRAW_ALL);
1547 DrawTitleScreenImage(tci->local_nr, tci->initial);
1549 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1551 fading_next = getTitleFading(tci);
1554 sound = getTitleSound(tci);
1555 music = getTitleMusic(tci);
1557 if (sound != last_sound)
1558 PlayMenuSoundExt(sound);
1559 if (music != last_music)
1560 PlayMenuMusicExt(music);
1567 /* last screen already faded out, next screen has no animation */
1568 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1569 fading_next.fade_mode == FADE_MODE_NONE)
1570 fading = fading_next;
1572 /* last screen already faded out, next screen has no animation */
1573 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1574 fading_next.fade_mode == FADE_MODE_NONE)
1575 fading = fading_next;
1582 fading = fading_next;
1584 DelayReached(&title_delay, 0); /* reset delay counter */
1588 FadeSoundsAndMusic();
1590 return_to_main_menu = TRUE;
1594 if (return_to_main_menu)
1600 SetMouseCursor(CURSOR_DEFAULT);
1602 if (game_status == GAME_MODE_INFO)
1605 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1608 info_mode = INFO_MODE_MAIN;
1609 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1611 else /* default: return to main menu */
1614 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1617 game_status = GAME_MODE_MAIN;
1618 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1623 void HandleMainMenu_SelectLevel(int step, int direction)
1625 int old_level_nr = level_nr;
1628 new_level_nr = old_level_nr + step * direction;
1629 if (new_level_nr < leveldir_current->first_level)
1630 new_level_nr = leveldir_current->first_level;
1631 if (new_level_nr > leveldir_current->last_level)
1632 new_level_nr = leveldir_current->last_level;
1634 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1636 /* skipping levels is only allowed when trying to skip single level */
1637 if (setup.skip_levels && step == 1 &&
1638 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1640 leveldir_current->handicap_level++;
1641 SaveLevelSetup_SeriesInfo();
1644 new_level_nr = leveldir_current->handicap_level;
1647 if (new_level_nr != old_level_nr)
1649 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1651 PlaySound(SND_MENU_ITEM_SELECTING);
1653 level_nr = new_level_nr;
1655 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1656 int2str(level_nr, menu.main.text.level_number.size),
1657 mci->pos_text->font);
1659 LoadLevel(level_nr);
1660 DrawPreviewLevel(TRUE);
1664 DrawCompleteVideoDisplay();
1666 /* needed because DrawPreviewLevel() takes some time */
1672 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1674 static int choice = MAIN_CONTROL_GAME;
1678 if (button == MB_MENU_INITIALIZE)
1680 DrawCursorAndText_Main(choice, TRUE);
1685 if (mx || my) /* mouse input */
1689 for (i = 0; main_controls[i].nr != -1; i++)
1691 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1692 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1693 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1695 pos = main_controls[i].nr;
1701 else if (dx || dy) /* keyboard input */
1703 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1704 choice == MAIN_CONTROL_SETUP))
1705 button = MB_MENU_CHOICE;
1710 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1712 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1714 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1720 PlaySound(SND_MENU_ITEM_ACTIVATING);
1722 DrawCursorAndText_Main(choice, FALSE);
1723 DrawCursorAndText_Main(pos, TRUE);
1730 PlaySound(SND_MENU_ITEM_SELECTING);
1732 if (pos == MAIN_CONTROL_NAME)
1734 game_status = GAME_MODE_PSEUDO_TYPENAME;
1736 HandleTypeName(strlen(setup.player_name), 0);
1738 else if (pos == MAIN_CONTROL_LEVELS)
1742 game_status = GAME_MODE_LEVELS;
1744 SaveLevelSetup_LastSeries();
1745 SaveLevelSetup_SeriesInfo();
1754 else if (pos == MAIN_CONTROL_SCORES)
1756 game_status = GAME_MODE_SCORES;
1760 else if (pos == MAIN_CONTROL_EDITOR)
1762 if (leveldir_current->readonly &&
1763 !strEqual(setup.player_name, "Artsoft"))
1764 Request("This level is read only !", REQ_CONFIRM);
1766 game_status = GAME_MODE_EDITOR;
1768 FadeSetEnterScreen();
1772 else if (pos == MAIN_CONTROL_INFO)
1774 game_status = GAME_MODE_INFO;
1775 info_mode = INFO_MODE_MAIN;
1779 else if (pos == MAIN_CONTROL_GAME)
1781 StartGameActions(options.network, setup.autorecord, level.random_seed);
1783 else if (pos == MAIN_CONTROL_SETUP)
1785 game_status = GAME_MODE_SETUP;
1786 setup_mode = SETUP_MODE_MAIN;
1790 else if (pos == MAIN_CONTROL_QUIT)
1792 SaveLevelSetup_LastSeries();
1793 SaveLevelSetup_SeriesInfo();
1795 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1796 game_status = GAME_MODE_QUIT;
1801 if (game_status == GAME_MODE_MAIN)
1803 DrawPreviewLevel(FALSE);
1809 /* ========================================================================= */
1810 /* info screen functions */
1811 /* ========================================================================= */
1813 static struct TokenInfo *info_info;
1814 static int num_info_info;
1816 static void execInfoTitleScreen()
1818 info_mode = INFO_MODE_TITLE;
1823 static void execInfoElements()
1825 info_mode = INFO_MODE_ELEMENTS;
1830 static void execInfoMusic()
1832 info_mode = INFO_MODE_MUSIC;
1837 static void execInfoCredits()
1839 info_mode = INFO_MODE_CREDITS;
1844 static void execInfoProgram()
1846 info_mode = INFO_MODE_PROGRAM;
1851 static void execInfoVersion()
1853 info_mode = INFO_MODE_VERSION;
1858 static void execInfoLevelSet()
1860 info_mode = INFO_MODE_LEVELSET;
1865 static void execExitInfo()
1867 game_status = GAME_MODE_MAIN;
1869 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1872 static struct TokenInfo info_info_main[] =
1874 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1875 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1876 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1877 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1878 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1879 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1880 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1881 { TYPE_EMPTY, NULL, "" },
1882 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1887 static void DrawCursorAndText_Info(int pos, boolean active)
1889 int xpos = MENU_SCREEN_START_XPOS;
1890 int ypos = MENU_SCREEN_START_YPOS + pos;
1891 int font_nr = FONT_MENU_1;
1894 font_nr = FONT_ACTIVE(font_nr);
1896 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1898 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1899 drawCursor(pos, active);
1902 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1907 CloseDoor(DOOR_CLOSE_2);
1909 /* (needed after displaying title screens which disable auto repeat) */
1910 KeyboardAutoRepeatOn();
1912 FadeSetLeaveScreen();
1919 if (fade_mask == REDRAW_ALL)
1923 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1929 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1931 info_info = info_info_main;
1935 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1937 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1940 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1941 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1942 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1943 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1944 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1945 initCursor(i, IMG_MENU_BUTTON);
1947 DrawCursorAndText_Info(i, FALSE);
1952 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1957 DrawMaskedBorder(fade_mask);
1964 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1966 static int choice_store[MAX_INFO_MODES];
1967 int choice = choice_store[info_mode]; /* always starts with 0 */
1971 if (button == MB_MENU_INITIALIZE)
1973 /* advance to first valid menu entry */
1974 while (choice < num_info_info &&
1975 info_info[choice].type & TYPE_SKIP_ENTRY)
1977 choice_store[info_mode] = choice;
1979 DrawCursorAndText_Info(choice, TRUE);
1983 else if (button == MB_MENU_LEAVE)
1985 for (y = 0; y < num_info_info; y++)
1987 if (info_info[y].type & TYPE_LEAVE_MENU)
1989 void (*menu_callback_function)(void) = info_info[y].value;
1993 menu_callback_function();
1995 break; /* absolutely needed because function changes 'info_info'! */
2002 if (mx || my) /* mouse input */
2004 x = (mx - mSX) / 32;
2005 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2007 else if (dx || dy) /* keyboard input */
2011 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2013 if (info_info[choice].type & menu_navigation_type ||
2014 info_info[choice].type & TYPE_ENTER_SCREEN ||
2015 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2016 info_info[choice].type & TYPE_YES_NO_AUTO)
2017 button = MB_MENU_CHOICE;
2022 /* jump to next non-empty menu entry (up or down) */
2023 while (y > 0 && y < num_info_info - 1 &&
2024 info_info[y].type & TYPE_SKIP_ENTRY)
2028 if (IN_VIS_FIELD(x, y) &&
2029 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2035 PlaySound(SND_MENU_ITEM_ACTIVATING);
2037 DrawCursorAndText_Info(choice, FALSE);
2038 DrawCursorAndText_Info(y, TRUE);
2040 choice = choice_store[info_mode] = y;
2043 else if (!(info_info[y].type & TYPE_GHOSTED))
2045 PlaySound(SND_MENU_ITEM_SELECTING);
2047 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2049 void (*menu_callback_function)(void) = info_info[choice].value;
2051 FadeSetFromType(info_info[y].type);
2053 menu_callback_function();
2059 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2061 int ystart1 = mSY - SY + 100;
2062 int ystart2 = mSY - SY + 150;
2063 int ybottom = mSY - SY + SYSIZE - 20;
2065 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2067 FadeOut(REDRAW_FIELD);
2072 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2073 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2075 DrawTextSCentered(ybottom, FONT_TEXT_4,
2076 "Press any key or button for info menu");
2078 FadeIn(REDRAW_FIELD);
2081 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2083 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2084 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2085 int xstart = mSX + 16;
2086 int ystart1 = mSY - SY + 100;
2087 int ystart2 = mSY + 64 + 2 * 32;
2088 int ybottom = mSY - SY + SYSIZE - 20;
2089 int ystep = TILEY + 4;
2090 int element, action, direction;
2098 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2099 infoscreen_step[i] = infoscreen_frame[i] = 0;
2104 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2106 DrawTextSCentered(ybottom, FONT_TEXT_4,
2107 "Press any key or button for next page");
2113 while (helpanim_info[j].element != HELPANIM_LIST_END)
2115 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2120 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2129 j += infoscreen_step[i - start];
2131 element = helpanim_info[j].element;
2132 action = helpanim_info[j].action;
2133 direction = helpanim_info[j].direction;
2136 element = EL_UNKNOWN;
2138 if (action != -1 && direction != -1)
2139 graphic = el_act_dir2img(element, action, direction);
2140 else if (action != -1)
2141 graphic = el_act2img(element, action);
2142 else if (direction != -1)
2143 graphic = el_dir2img(element, direction);
2145 graphic = el2img(element);
2147 delay = helpanim_info[j++].delay;
2152 if (infoscreen_frame[i - start] == 0)
2155 infoscreen_frame[i - start] = delay - 1;
2159 sync_frame = delay - infoscreen_frame[i - start];
2160 infoscreen_frame[i - start]--;
2163 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2165 if (!infoscreen_frame[i - start])
2166 infoscreen_step[i - start] = 0;
2170 if (!infoscreen_frame[i - start])
2171 infoscreen_step[i - start]++;
2172 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2178 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2180 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2181 graphic, sync_frame, USE_MASKING);
2184 DrawInfoScreen_HelpText(element, action, direction, i - start);
2189 redraw_mask |= REDRAW_FIELD;
2194 static char *getHelpText(int element, int action, int direction)
2196 char token[MAX_LINE_LEN];
2198 strcpy(token, element_info[element].token_name);
2201 strcat(token, element_action_info[action].suffix);
2203 if (direction != -1)
2204 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2206 return getHashEntry(helptext_info, token);
2209 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2211 int font_nr = FONT_INFO_ELEMENTS;
2212 int font_width = getFontWidth(font_nr);
2213 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2214 int sy = mSY + 65 + 2 * 32 + 1;
2215 int ystep = TILEY + 4;
2216 int pad_x = sx - SX;
2217 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2218 int max_lines_per_text = 2;
2221 if (action != -1 && direction != -1) /* element.action.direction */
2222 text = getHelpText(element, action, direction);
2224 if (text == NULL && action != -1) /* element.action */
2225 text = getHelpText(element, action, -1);
2227 if (text == NULL && direction != -1) /* element.direction */
2228 text = getHelpText(element, -1, direction);
2230 if (text == NULL) /* base element */
2231 text = getHelpText(element, -1, -1);
2233 if (text == NULL) /* not found */
2234 text = "No description available";
2236 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2237 sy += getFontHeight(font_nr) / 2;
2239 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2240 max_chars_per_line, -1, max_lines_per_text, -1,
2241 TRUE, FALSE, FALSE);
2244 void DrawInfoScreen_TitleScreen()
2249 void HandleInfoScreen_TitleScreen(int button)
2251 HandleTitleScreen(0, 0, 0, 0, button);
2254 void DrawInfoScreen_Elements()
2256 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2258 FadeOut(REDRAW_FIELD);
2263 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2265 FadeIn(REDRAW_FIELD);
2270 void HandleInfoScreen_Elements(int button)
2272 static unsigned long info_delay = 0;
2273 static int num_anims;
2274 static int num_pages;
2276 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2279 if (button == MB_MENU_INITIALIZE)
2281 boolean new_element = TRUE;
2285 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2287 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2289 else if (new_element)
2292 new_element = FALSE;
2296 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2300 if (button == MB_MENU_LEAVE)
2302 PlaySound(SND_MENU_ITEM_SELECTING);
2304 info_mode = INFO_MODE_MAIN;
2309 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2311 if (button != MB_MENU_INITIALIZE)
2313 PlaySound(SND_MENU_ITEM_SELECTING);
2318 if (page >= num_pages)
2320 FadeSoundsAndMusic();
2322 info_mode = INFO_MODE_MAIN;
2323 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2330 FadeSetNextScreen();
2333 if (button != MB_MENU_INITIALIZE)
2334 FadeOut(REDRAW_FIELD);
2336 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2338 if (button != MB_MENU_INITIALIZE)
2339 FadeIn(REDRAW_FIELD);
2343 if (DelayReached(&info_delay, GameFrameDelay))
2344 if (page < num_pages)
2345 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2347 PlayMenuSoundIfLoop();
2351 void DrawInfoScreen_Music()
2353 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2356 FadeOut(REDRAW_FIELD);
2364 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2367 FadeIn(REDRAW_FIELD);
2371 void HandleInfoScreen_Music(int button)
2373 static struct MusicFileInfo *list = NULL;
2374 int ystart1 = mSY - SY + 100;
2375 int ystart2 = mSY - SY + 150;
2376 int ybottom = mSY - SY + SYSIZE - 20;
2379 if (button == MB_MENU_INITIALIZE)
2381 list = music_file_info;
2385 FadeSoundsAndMusic();
2390 DrawTextSCentered(ystart1, FONT_TEXT_1,
2391 "No music info for this level set.");
2393 DrawTextSCentered(ybottom, FONT_TEXT_4,
2394 "Press any key or button for info menu");
2400 if (button == MB_MENU_LEAVE)
2402 PlaySound(SND_MENU_ITEM_SELECTING);
2404 FadeSoundsAndMusic();
2406 info_mode = INFO_MODE_MAIN;
2411 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2415 if (button != MB_MENU_INITIALIZE)
2417 PlaySound(SND_MENU_ITEM_SELECTING);
2425 FadeSoundsAndMusic();
2427 info_mode = INFO_MODE_MAIN;
2428 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2433 FadeSoundsAndMusic();
2436 if (list != music_file_info)
2437 FadeSetNextScreen();
2440 if (button != MB_MENU_INITIALIZE)
2441 FadeOut(REDRAW_FIELD);
2448 int sound = list->music;
2450 if (sound_info[sound].loop)
2451 PlaySoundLoop(sound);
2455 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2459 PlayMusic(list->music);
2461 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2464 if (!strEqual(list->title, UNKNOWN_NAME))
2466 if (!strEqual(list->title_header, UNKNOWN_NAME))
2467 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2469 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2472 if (!strEqual(list->artist, UNKNOWN_NAME))
2474 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2475 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2477 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2479 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2482 if (!strEqual(list->album, UNKNOWN_NAME))
2484 if (!strEqual(list->album_header, UNKNOWN_NAME))
2485 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2487 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2489 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2492 if (!strEqual(list->year, UNKNOWN_NAME))
2494 if (!strEqual(list->year_header, UNKNOWN_NAME))
2495 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2497 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2499 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2502 DrawTextSCentered(ybottom, FONT_TEXT_4,
2503 "Press any key or button for next page");
2505 if (button != MB_MENU_INITIALIZE)
2506 FadeIn(REDRAW_FIELD);
2509 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2510 PlaySoundLoop(list->music);
2513 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2515 int ystart1 = mSY - SY + 100;
2516 int ystart2 = mSY - SY + 150;
2517 int ybottom = mSY - SY + SYSIZE - 20;
2523 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2527 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2528 "Special thanks to");
2529 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2531 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2533 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2534 "\"Boulder Dash\"");
2535 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2537 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2539 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2541 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2542 "First Star Software");
2544 else if (screen_nr == 1)
2546 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2547 "Special thanks to");
2548 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2549 "Klaus Heinz & Volker Wertich");
2550 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2552 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2553 "\"Emerald Mine\"");
2554 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2556 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2558 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2560 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2563 else if (screen_nr == 2)
2565 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2566 "Special thanks to");
2567 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2568 "Michael Stopp & Philip Jespersen");
2569 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2571 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2573 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2575 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2577 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2579 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2580 "Digital Integration");
2582 else if (screen_nr == 3)
2584 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2585 "Special thanks to");
2586 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2587 "Hiroyuki Imabayashi");
2588 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2590 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2592 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2594 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2596 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2598 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2601 else if (screen_nr == 4)
2603 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2604 "Special thanks to");
2605 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2607 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2609 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2610 "Jürgen Bonhagen");
2611 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2612 "for the continuous creation");
2613 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2614 "of outstanding level sets");
2616 else if (screen_nr == 5)
2618 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2620 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2622 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2623 "for ideas and inspiration by");
2624 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2627 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2629 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2631 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2632 "for ideas and inspiration by");
2633 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2636 else if (screen_nr == 6)
2638 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2640 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2643 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2644 "for the code base used for the");
2645 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2646 "native Emerald Mine engine");
2648 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2649 "for the new Emerald Mine engine");
2652 else if (screen_nr == 7)
2654 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2656 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2658 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2659 "for the initial DOS port");
2661 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2663 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2665 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2666 "for some additional toons");
2668 else if (screen_nr == 8)
2670 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2671 "And not to forget:");
2672 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2674 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2675 "All those who contributed");
2676 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2677 "levels to this game");
2678 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2682 DrawTextSCentered(ybottom, FONT_TEXT_4,
2683 "Press any key or button for next page");
2686 void DrawInfoScreen_Credits()
2688 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2690 FadeSoundsAndMusic();
2693 FadeOut(REDRAW_FIELD);
2696 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2699 FadeIn(REDRAW_FIELD);
2703 void HandleInfoScreen_Credits(int button)
2705 static int screen_nr = 0;
2706 int num_screens = 9;
2708 if (button == MB_MENU_INITIALIZE)
2712 // DrawInfoScreen_CreditsScreen(screen_nr);
2715 if (button == MB_MENU_LEAVE)
2717 PlaySound(SND_MENU_ITEM_SELECTING);
2719 info_mode = INFO_MODE_MAIN;
2724 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2726 if (button != MB_MENU_INITIALIZE)
2728 PlaySound(SND_MENU_ITEM_SELECTING);
2733 if (screen_nr >= num_screens)
2735 FadeSoundsAndMusic();
2737 info_mode = INFO_MODE_MAIN;
2738 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2745 FadeSetNextScreen();
2748 if (button != MB_MENU_INITIALIZE)
2749 FadeOut(REDRAW_FIELD);
2751 DrawInfoScreen_CreditsScreen(screen_nr);
2753 if (button != MB_MENU_INITIALIZE)
2754 FadeIn(REDRAW_FIELD);
2758 PlayMenuSoundIfLoop();
2762 void DrawInfoScreen_Program()
2764 int ystart1 = mSY - SY + 100;
2765 int ystart2 = mSY - SY + 150;
2766 int ybottom = mSY - SY + SYSIZE - 20;
2769 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2772 FadeOut(REDRAW_FIELD);
2778 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2780 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2781 "This game is Freeware!");
2782 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2783 "If you like it, send e-mail to:");
2784 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2785 PROGRAM_EMAIL_STRING);
2786 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2787 "or SnailMail to:");
2788 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2790 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2791 "Detmolder Strasse 189");
2792 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2794 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2796 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2797 "More information and levels:");
2798 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2799 PROGRAM_WEBSITE_STRING);
2800 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2801 "If you have created new levels,");
2802 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2803 "send them to me to include them!");
2804 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2807 DrawTextSCentered(ybottom, FONT_TEXT_4,
2808 "Press any key or button for info menu");
2811 FadeIn(REDRAW_FIELD);
2815 void HandleInfoScreen_Program(int button)
2817 if (button == MB_MENU_LEAVE)
2819 PlaySound(SND_MENU_ITEM_SELECTING);
2821 info_mode = INFO_MODE_MAIN;
2826 else if (button == MB_MENU_CHOICE)
2828 PlaySound(SND_MENU_ITEM_SELECTING);
2830 FadeSoundsAndMusic();
2833 FadeOut(REDRAW_FIELD);
2836 info_mode = INFO_MODE_MAIN;
2837 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2841 PlayMenuSoundIfLoop();
2845 void DrawInfoScreen_Version()
2847 int font_header = FONT_TEXT_3;
2848 int font_text = FONT_TEXT_2;
2849 int xstep = getFontWidth(font_text);
2850 int ystep = getFontHeight(font_text);
2851 int ystart1 = mSY - SY + 100;
2852 int ystart2 = mSY - SY + 150;
2853 int ybottom = mSY - SY + SYSIZE - 20;
2854 int xstart1 = mSX + 2 * xstep;
2855 int xstart2 = mSX + 19 * xstep;
2856 #if defined(TARGET_SDL)
2857 int xstart3 = mSX + 29 * xstep;
2858 SDL_version sdl_version_compiled;
2859 const SDL_version *sdl_version_linked;
2860 int driver_name_len = 8;
2861 char driver_name[driver_name_len];
2864 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2867 FadeOut(REDRAW_FIELD);
2873 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2875 DrawTextF(xstart1, ystart2, font_header, "Name");
2876 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2879 DrawTextF(xstart1, ystart2, font_header, "Version");
2880 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2883 DrawTextF(xstart1, ystart2, font_header, "Platform");
2884 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2887 DrawTextF(xstart1, ystart2, font_header, "Target");
2888 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2891 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2892 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2894 #if defined(TARGET_SDL)
2895 ystart2 += 3 * ystep;
2896 DrawTextF(xstart1, ystart2, font_header, "Library");
2897 DrawTextF(xstart2, ystart2, font_header, "compiled");
2898 DrawTextF(xstart3, ystart2, font_header, "linked");
2900 SDL_VERSION(&sdl_version_compiled);
2901 sdl_version_linked = SDL_Linked_Version();
2903 ystart2 += 2 * ystep;
2904 DrawTextF(xstart1, ystart2, font_text, "SDL");
2905 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2906 sdl_version_compiled.major,
2907 sdl_version_compiled.minor,
2908 sdl_version_compiled.patch);
2909 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2910 sdl_version_linked->major,
2911 sdl_version_linked->minor,
2912 sdl_version_linked->patch);
2914 SDL_IMAGE_VERSION(&sdl_version_compiled);
2915 sdl_version_linked = IMG_Linked_Version();
2918 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2919 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2920 sdl_version_compiled.major,
2921 sdl_version_compiled.minor,
2922 sdl_version_compiled.patch);
2923 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2924 sdl_version_linked->major,
2925 sdl_version_linked->minor,
2926 sdl_version_linked->patch);
2928 SDL_MIXER_VERSION(&sdl_version_compiled);
2929 sdl_version_linked = Mix_Linked_Version();
2932 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2933 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2934 sdl_version_compiled.major,
2935 sdl_version_compiled.minor,
2936 sdl_version_compiled.patch);
2937 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2938 sdl_version_linked->major,
2939 sdl_version_linked->minor,
2940 sdl_version_linked->patch);
2942 SDL_NET_VERSION(&sdl_version_compiled);
2943 sdl_version_linked = SDLNet_Linked_Version();
2946 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2947 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2948 sdl_version_compiled.major,
2949 sdl_version_compiled.minor,
2950 sdl_version_compiled.patch);
2951 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2952 sdl_version_linked->major,
2953 sdl_version_linked->minor,
2954 sdl_version_linked->patch);
2956 ystart2 += 3 * ystep;
2957 DrawTextF(xstart1, ystart2, font_header, "Driver");
2958 DrawTextF(xstart2, ystart2, font_header, "Requested");
2959 DrawTextF(xstart3, ystart2, font_header, "Used");
2961 SDL_VideoDriverName(driver_name, driver_name_len);
2963 ystart2 += 2 * ystep;
2964 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2965 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2966 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2968 SDL_AudioDriverName(driver_name, driver_name_len);
2971 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2972 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2973 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2976 DrawTextSCentered(ybottom, FONT_TEXT_4,
2977 "Press any key or button for info menu");
2980 FadeIn(REDRAW_FIELD);
2984 void HandleInfoScreen_Version(int button)
2986 if (button == MB_MENU_LEAVE)
2988 PlaySound(SND_MENU_ITEM_SELECTING);
2990 info_mode = INFO_MODE_MAIN;
2995 else if (button == MB_MENU_CHOICE)
2997 PlaySound(SND_MENU_ITEM_SELECTING);
2999 FadeSoundsAndMusic();
3002 FadeOut(REDRAW_FIELD);
3005 info_mode = INFO_MODE_MAIN;
3006 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3010 PlayMenuSoundIfLoop();
3014 void DrawInfoScreen_LevelSet()
3016 struct TitleMessageInfo *tmi = &readme;
3017 char *filename = getLevelSetInfoFilename();
3019 /* if chars set to "-1", automatically determine by text and font width */
3020 if (tmi->chars == -1)
3021 tmi->chars = tmi->width / getFontWidth(tmi->font);
3023 tmi->width = tmi->chars * getFontWidth(tmi->font);
3025 /* if lines set to "-1", automatically determine by text and font height */
3026 if (tmi->lines == -1)
3027 tmi->lines = tmi->height / getFontHeight(tmi->font);
3029 tmi->height = tmi->lines * getFontHeight(tmi->font);
3031 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3034 FadeOut(REDRAW_FIELD);
3040 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3042 if (filename != NULL)
3043 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3044 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3045 tmi->autowrap, tmi->centered, tmi->parse_comments);
3047 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3048 "No information for this level set.");
3050 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3051 "Press any key or button for info menu");
3054 FadeIn(REDRAW_FIELD);
3058 void HandleInfoScreen_LevelSet(int button)
3060 if (button == MB_MENU_LEAVE)
3062 PlaySound(SND_MENU_ITEM_SELECTING);
3064 info_mode = INFO_MODE_MAIN;
3069 else if (button == MB_MENU_CHOICE)
3071 PlaySound(SND_MENU_ITEM_SELECTING);
3073 FadeSoundsAndMusic();
3076 FadeOut(REDRAW_FIELD);
3079 info_mode = INFO_MODE_MAIN;
3080 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3084 PlayMenuSoundIfLoop();
3088 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3090 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3092 if (info_mode == INFO_MODE_TITLE)
3093 DrawInfoScreen_TitleScreen();
3094 else if (info_mode == INFO_MODE_ELEMENTS)
3095 DrawInfoScreen_Elements();
3096 else if (info_mode == INFO_MODE_MUSIC)
3097 DrawInfoScreen_Music();
3098 else if (info_mode == INFO_MODE_CREDITS)
3099 DrawInfoScreen_Credits();
3100 else if (info_mode == INFO_MODE_PROGRAM)
3101 DrawInfoScreen_Program();
3102 else if (info_mode == INFO_MODE_VERSION)
3103 DrawInfoScreen_Version();
3104 else if (info_mode == INFO_MODE_LEVELSET)
3105 DrawInfoScreen_LevelSet();
3107 DrawInfoScreen_Main(fade_mask, do_fading);
3109 if (info_mode != INFO_MODE_MAIN &&
3110 info_mode != INFO_MODE_TITLE &&
3111 info_mode != INFO_MODE_MUSIC)
3118 void DrawAndFadeInInfoScreen(int fade_mask)
3120 DrawInfoScreenExt(fade_mask, TRUE);
3123 void DrawInfoScreen()
3125 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3128 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3130 if (info_mode == INFO_MODE_TITLE)
3131 HandleInfoScreen_TitleScreen(button);
3132 else if (info_mode == INFO_MODE_ELEMENTS)
3133 HandleInfoScreen_Elements(button);
3134 else if (info_mode == INFO_MODE_MUSIC)
3135 HandleInfoScreen_Music(button);
3136 else if (info_mode == INFO_MODE_CREDITS)
3137 HandleInfoScreen_Credits(button);
3138 else if (info_mode == INFO_MODE_PROGRAM)
3139 HandleInfoScreen_Program(button);
3140 else if (info_mode == INFO_MODE_VERSION)
3141 HandleInfoScreen_Version(button);
3142 else if (info_mode == INFO_MODE_LEVELSET)
3143 HandleInfoScreen_LevelSet(button);
3145 HandleInfoScreen_Main(mx, my, dx, dy, button);
3151 /* ========================================================================= */
3152 /* type name functions */
3153 /* ========================================================================= */
3155 void HandleTypeName(int newxpos, Key key)
3157 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3158 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3159 struct TextPosInfo *pos = mci->pos_input;
3160 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3161 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3162 static int xpos = 0;
3163 int font_nr = pos->font;
3164 int font_active_nr = FONT_ACTIVE(font_nr);
3165 int font_width = getFontWidth(font_active_nr);
3166 char key_char = getValidConfigValueChar(getCharFromKey(key));
3167 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3168 boolean is_active = TRUE;
3170 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3174 strcpy(last_player_name, setup.player_name);
3178 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3180 setup.player_name[xpos] = key_char;
3181 setup.player_name[xpos + 1] = 0;
3185 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3189 setup.player_name[xpos] = 0;
3191 else if (key == KSYM_Return && xpos > 0)
3197 game_status = GAME_MODE_MAIN;
3199 else if (key == KSYM_Escape)
3201 strcpy(setup.player_name, last_player_name);
3205 game_status = GAME_MODE_MAIN;
3210 pos->width = (strlen(setup.player_name) + 1) * font_width;
3211 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3213 DrawText(startx, starty, setup.player_name, font_active_nr);
3214 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3218 pos->width = strlen(setup.player_name) * font_width;
3219 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3221 DrawText(startx, starty, setup.player_name, font_nr);
3226 /* ========================================================================= */
3227 /* tree menu functions */
3228 /* ========================================================================= */
3230 static void DrawChooseTree(TreeInfo **ti_ptr)
3234 FreeScreenGadgets();
3235 CreateScreenGadgets();
3237 CloseDoor(DOOR_CLOSE_2);
3240 FadeOut(REDRAW_FIELD);
3245 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3246 MapScreenTreeGadgets(*ti_ptr);
3249 FadeIn(REDRAW_FIELD);
3255 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3257 struct GadgetInfo *gi = screen_gadget[id];
3258 int items_max, items_visible, item_position;
3260 items_max = numTreeInfoInGroup(ti);
3261 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3262 item_position = first_entry;
3264 if (item_position > items_max - items_visible)
3265 item_position = items_max - items_visible;
3267 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3268 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3269 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3272 static void drawChooseTreeList(int first_entry, int num_page_entries,
3276 char *title_string = NULL;
3277 int yoffset_sets = MENU_TITLE1_YPOS;
3278 int yoffset_setup = 16;
3279 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3281 int last_game_status = game_status; /* save current game status */
3283 title_string = ti->infotext;
3285 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3288 /* force LEVELS font on artwork setup screen */
3289 game_status = GAME_MODE_LEVELS;
3293 /* clear tree list area, but not title or scrollbar */
3294 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3295 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3296 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3298 /* clear tree list area, but not title or scrollbar */
3299 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3300 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3301 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3304 for (i = 0; i < num_page_entries; i++)
3306 TreeInfo *node, *node_first;
3307 int entry_pos = first_entry + i;
3308 int xpos = MENU_SCREEN_START_XPOS;
3309 int ypos = MENU_SCREEN_START_YPOS + i;
3310 int startx = mSX + xpos * 32;
3311 int starty = mSY + ypos * 32;
3312 int font_nr = FONT_TEXT_1;
3313 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3314 int startx_text = startx + font_xoffset;
3315 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3316 int text_size = startx_scrollbar - startx_text;
3317 int max_buffer_len = text_size / getFontWidth(font_nr);
3318 char buffer[max_buffer_len + 1];
3320 node_first = getTreeInfoFirstGroupEntry(ti);
3321 node = getTreeInfoFromPos(node_first, entry_pos);
3323 strncpy(buffer, node->name, max_buffer_len);
3324 buffer[max_buffer_len] = '\0';
3326 DrawText(startx, starty, buffer, font_nr + node->color);
3328 if (node->parent_link)
3329 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3330 else if (node->level_group)
3331 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3333 initCursor(i, IMG_MENU_BUTTON);
3336 game_status = last_game_status; /* restore current game status */
3338 redraw_mask |= REDRAW_FIELD;
3341 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3343 TreeInfo *node, *node_first;
3344 int x, last_redraw_mask = redraw_mask;
3345 int ypos = MENU_TITLE2_YPOS;
3346 int font_nr = FONT_TITLE_2;
3348 if (ti->type != TREE_TYPE_LEVEL_DIR)
3351 node_first = getTreeInfoFirstGroupEntry(ti);
3352 node = getTreeInfoFromPos(node_first, entry_pos);
3354 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3356 if (node->parent_link)
3357 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3359 else if (node->level_group)
3360 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3362 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3363 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3364 node->levels, node->class_desc);
3366 /* let BackToFront() redraw only what is needed */
3367 redraw_mask = last_redraw_mask | REDRAW_TILES;
3368 for (x = 0; x < SCR_FIELDX; x++)
3369 MarkTileDirty(x, 1);
3372 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3375 TreeInfo *ti = *ti_ptr;
3377 int y = ti->cl_cursor;
3378 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3379 int num_entries = numTreeInfoInGroup(ti);
3380 int num_page_entries;
3381 int last_game_status = game_status; /* save current game status */
3382 boolean position_set_by_scrollbar = (dx == 999);
3385 /* force LEVELS draw offset on choose level and artwork setup screen */
3386 game_status = GAME_MODE_LEVELS;
3389 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3390 num_page_entries = num_entries;
3392 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3394 game_status = last_game_status; /* restore current game status */
3396 if (button == MB_MENU_INITIALIZE)
3398 int num_entries = numTreeInfoInGroup(ti);
3399 int entry_pos = posTreeInfo(ti);
3401 if (ti->cl_first == -1)
3403 /* only on initialization */
3404 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3405 ti->cl_cursor = entry_pos - ti->cl_first;
3407 else if (ti->cl_cursor >= num_page_entries ||
3408 (num_entries > num_page_entries &&
3409 num_entries - ti->cl_first < num_page_entries))
3411 /* only after change of list size (by custom graphic configuration) */
3412 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3413 ti->cl_cursor = entry_pos - ti->cl_first;
3416 if (position_set_by_scrollbar)
3419 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3422 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3423 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3424 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3428 else if (button == MB_MENU_LEAVE)
3432 PlaySound(SND_MENU_ITEM_SELECTING);
3434 if (ti->node_parent)
3436 *ti_ptr = ti->node_parent;
3437 DrawChooseTree(ti_ptr);
3439 else if (game_status == GAME_MODE_SETUP)
3441 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3443 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3444 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3445 execSetupGraphics();
3451 game_status = GAME_MODE_MAIN;
3453 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3459 if (mx || my) /* mouse input */
3461 int last_game_status = game_status; /* save current game status */
3464 /* force LEVELS draw offset on artwork setup screen */
3465 game_status = GAME_MODE_LEVELS;
3468 x = (mx - mSX) / 32;
3469 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3471 game_status = last_game_status; /* restore current game status */
3473 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3475 /* move cursor instead of scrolling when already at start/end of list */
3476 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3478 else if (dy == +1 * SCROLL_LINE &&
3479 ti->cl_first + num_page_entries == num_entries)
3482 /* handle scrolling screen one line or page */
3483 if (ti->cl_cursor + dy < 0 ||
3484 ti->cl_cursor + dy > num_page_entries - 1)
3486 if (ABS(dy) == SCROLL_PAGE)
3487 step = num_page_entries - 1;
3489 if (dy < 0 && ti->cl_first > 0)
3491 /* scroll page/line up */
3493 ti->cl_first -= step;
3494 if (ti->cl_first < 0)
3497 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3498 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3499 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3501 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3504 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3506 /* scroll page/line down */
3508 ti->cl_first += step;
3509 if (ti->cl_first + num_page_entries > num_entries)
3510 ti->cl_first = MAX(0, num_entries - num_page_entries);
3512 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3513 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3514 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3516 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3523 /* handle moving cursor one line */
3524 y = ti->cl_cursor + dy;
3529 TreeInfo *node_first, *node_cursor;
3530 int entry_pos = ti->cl_first + y;
3532 node_first = getTreeInfoFirstGroupEntry(ti);
3533 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3535 if (node_cursor->node_group)
3539 PlaySound(SND_MENU_ITEM_SELECTING);
3541 node_cursor->cl_first = ti->cl_first;
3542 node_cursor->cl_cursor = ti->cl_cursor;
3543 *ti_ptr = node_cursor->node_group;
3544 DrawChooseTree(ti_ptr);
3549 else if (dx == -1 && ti->node_parent)
3553 PlaySound(SND_MENU_ITEM_SELECTING);
3555 *ti_ptr = ti->node_parent;
3556 DrawChooseTree(ti_ptr);
3561 if (!anyScrollbarGadgetActive() &&
3562 IN_VIS_FIELD(x, y) &&
3563 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3564 y >= 0 && y < num_page_entries)
3568 if (y != ti->cl_cursor)
3570 PlaySound(SND_MENU_ITEM_ACTIVATING);
3572 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3573 drawChooseTreeCursor(y, TRUE);
3574 drawChooseTreeInfo(ti->cl_first + y, ti);
3581 TreeInfo *node_first, *node_cursor;
3582 int entry_pos = ti->cl_first + y;
3584 PlaySound(SND_MENU_ITEM_SELECTING);
3586 node_first = getTreeInfoFirstGroupEntry(ti);
3587 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3589 if (node_cursor->node_group)
3593 node_cursor->cl_first = ti->cl_first;
3594 node_cursor->cl_cursor = ti->cl_cursor;
3595 *ti_ptr = node_cursor->node_group;
3596 DrawChooseTree(ti_ptr);
3598 else if (node_cursor->parent_link)
3602 *ti_ptr = node_cursor->node_parent;
3603 DrawChooseTree(ti_ptr);
3607 FadeSetEnterScreen();
3609 node_cursor->cl_first = ti->cl_first;
3610 node_cursor->cl_cursor = ti->cl_cursor;
3611 *ti_ptr = node_cursor;
3613 if (ti->type == TREE_TYPE_LEVEL_DIR)
3615 LoadLevelSetup_SeriesInfo();
3617 SaveLevelSetup_LastSeries();
3618 SaveLevelSetup_SeriesInfo();
3622 if (game_status == GAME_MODE_SETUP)
3624 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3626 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3627 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3628 execSetupGraphics();
3634 game_status = GAME_MODE_MAIN;
3642 void DrawChooseLevel()
3644 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3646 DrawChooseTree(&leveldir_current);
3652 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3654 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3659 void DrawHallOfFame(int highlight_position)
3662 FadeSoundsAndMusic();
3664 /* (this is needed when called from GameEnd() after winning a game) */
3665 KeyboardAutoRepeatOn();
3668 /* (this is needed when called from GameEnd() after winning a game) */
3669 SetDrawDeactivationMask(REDRAW_NONE);
3670 SetDrawBackgroundMask(REDRAW_FIELD);
3672 CloseDoor(DOOR_CLOSE_2);
3674 if (highlight_position < 0)
3675 LoadScore(level_nr);
3677 FadeSetEnterScreen();
3679 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3682 FadeOut(REDRAW_FIELD);
3690 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3693 FadeIn(REDRAW_FIELD);
3697 static void drawHallOfFameList(int first_entry, int highlight_position)
3701 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3704 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3705 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3706 "HighScores of Level %d", level_nr);
3708 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3710 int entry = first_entry + i;
3711 boolean active = (entry == highlight_position);
3712 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3713 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3714 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3715 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3716 int dx1 = 3 * getFontWidth(font_nr1);
3717 int dx2 = dx1 + getFontWidth(font_nr1);
3718 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3719 int sy = mSY + 64 + i * 32;
3721 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3722 DrawText(mSX + dx1, sy, ".", font_nr1);
3723 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3725 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3726 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3728 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3731 redraw_mask |= REDRAW_FIELD;
3734 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3736 static int first_entry = 0;
3737 static int highlight_position = 0;
3738 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3740 if (button == MB_MENU_INITIALIZE)
3743 highlight_position = mx;
3744 drawHallOfFameList(first_entry, highlight_position);
3749 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3750 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3754 if (first_entry > 0)
3756 first_entry -= step;
3757 if (first_entry < 0)
3760 drawHallOfFameList(first_entry, highlight_position);
3765 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3767 first_entry += step;
3768 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3769 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3771 drawHallOfFameList(first_entry, highlight_position);
3774 else if (button == MB_MENU_LEAVE)
3776 PlaySound(SND_MENU_ITEM_SELECTING);
3778 FadeSound(SND_BACKGROUND_SCORES);
3780 game_status = GAME_MODE_MAIN;
3784 else if (button == MB_MENU_CHOICE)
3786 PlaySound(SND_MENU_ITEM_SELECTING);
3788 FadeSound(SND_BACKGROUND_SCORES);
3791 FadeOut(REDRAW_FIELD);
3794 game_status = GAME_MODE_MAIN;
3796 DrawAndFadeInMainMenu(REDRAW_FIELD);
3799 if (game_status == GAME_MODE_SCORES)
3800 PlayMenuSoundIfLoop();
3806 /* ========================================================================= */
3807 /* setup screen functions */
3808 /* ========================================================================= */
3810 static struct TokenInfo *setup_info;
3811 static int num_setup_info;
3813 static char *screen_mode_text;
3814 static char *scroll_delay_text;
3815 static char *game_speed_text;
3816 static char *graphics_set_name;
3817 static char *sounds_set_name;
3818 static char *music_set_name;
3820 static void execSetupMain()
3822 setup_mode = SETUP_MODE_MAIN;
3827 static void execSetupGame()
3829 if (game_speeds == NULL)
3833 for (i = 0; game_speeds_list[i].value != -1; i++)
3835 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3836 char identifier[32], name[32];
3837 int value = game_speeds_list[i].value;
3838 char *text = game_speeds_list[i].text;
3840 ti->node_top = &game_speeds;
3841 ti->sort_priority = 10000 - value;
3843 sprintf(identifier, "%d", value);
3844 sprintf(name, "%s", text);
3846 setString(&ti->identifier, identifier);
3847 setString(&ti->name, name);
3848 setString(&ti->name_sorting, name);
3849 setString(&ti->infotext, "Game Speed");
3851 pushTreeInfo(&game_speeds, ti);
3854 /* sort game speed values to start with slowest game speed */
3855 sortTreeInfo(&game_speeds);
3857 /* set current game speed to configured game speed value */
3858 game_speed_current =
3859 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3861 /* if that fails, set current game speed to reliable default value */
3862 if (game_speed_current == NULL)
3863 game_speed_current =
3864 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3866 /* if that also fails, set current game speed to first available speed */
3867 if (game_speed_current == NULL)
3868 game_speed_current = game_speeds;
3871 setup.game_frame_delay = atoi(game_speed_current->identifier);
3873 /* needed for displaying game speed text instead of identifier */
3874 game_speed_text = game_speed_current->name;
3876 setup_mode = SETUP_MODE_GAME;
3881 static void execSetupChooseGameSpeed()
3883 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3888 static void execSetupEditor()
3890 setup_mode = SETUP_MODE_EDITOR;
3895 static void execSetupGraphics()
3897 if (video.fullscreen_available && screen_modes == NULL)
3901 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3903 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3904 char identifier[32], name[32];
3905 int x = video.fullscreen_modes[i].width;
3906 int y = video.fullscreen_modes[i].height;
3909 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3911 ti->node_top = &screen_modes;
3912 ti->sort_priority = x * 10000 + y;
3914 sprintf(identifier, "%dx%d", x, y);
3915 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3917 setString(&ti->identifier, identifier);
3918 setString(&ti->name, name);
3919 setString(&ti->name_sorting, name);
3920 setString(&ti->infotext, "Fullscreen Mode");
3922 pushTreeInfo(&screen_modes, ti);
3925 /* sort fullscreen modes to start with lowest available screen resolution */
3926 sortTreeInfo(&screen_modes);
3928 /* set current screen mode for fullscreen mode to configured setup value */
3929 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3930 setup.fullscreen_mode);
3932 /* if that fails, set current screen mode to reliable default value */
3933 if (screen_mode_current == NULL)
3934 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3935 DEFAULT_FULLSCREEN_MODE);
3937 /* if that also fails, set current screen mode to first available mode */
3938 if (screen_mode_current == NULL)
3939 screen_mode_current = screen_modes;
3941 if (screen_mode_current == NULL)
3942 video.fullscreen_available = FALSE;
3945 if (video.fullscreen_available)
3947 setup.fullscreen_mode = screen_mode_current->identifier;
3949 /* needed for displaying screen mode name instead of identifier */
3950 screen_mode_text = screen_mode_current->name;
3954 if (scroll_delays == NULL)
3958 for (i = 0; scroll_delays_list[i].value != -1; i++)
3960 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3961 char identifier[32], name[32];
3962 int value = scroll_delays_list[i].value;
3963 char *text = scroll_delays_list[i].text;
3965 ti->node_top = &scroll_delays;
3966 ti->sort_priority = value;
3968 sprintf(identifier, "%d", value);
3969 sprintf(name, "%s", text);
3971 setString(&ti->identifier, identifier);
3972 setString(&ti->name, name);
3973 setString(&ti->name_sorting, name);
3974 setString(&ti->infotext, "Scroll Delay");
3976 pushTreeInfo(&scroll_delays, ti);
3979 /* sort scroll delay values to start with lowest scroll delay value */
3980 sortTreeInfo(&scroll_delays);
3982 /* set current scroll delay value to configured scroll delay value */
3983 scroll_delay_current =
3984 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
3986 /* if that fails, set current scroll delay to reliable default value */
3987 if (scroll_delay_current == NULL)
3988 scroll_delay_current =
3989 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
3991 /* if that also fails, set current scroll delay to first available value */
3992 if (scroll_delay_current == NULL)
3993 scroll_delay_current = scroll_delays;
3996 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
3998 /* needed for displaying scroll delay text instead of identifier */
3999 scroll_delay_text = scroll_delay_current->name;
4002 setup_mode = SETUP_MODE_GRAPHICS;
4006 static void execSetupChooseScreenMode()
4008 if (!video.fullscreen_available)
4011 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4016 static void execSetupChooseScrollDelay()
4018 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4023 static void execSetupSound()
4025 setup_mode = SETUP_MODE_SOUND;
4030 static void execSetupArtwork()
4033 printf("::: '%s', '%s', '%s'\n",
4034 artwork.gfx_current->subdir,
4035 artwork.gfx_current->fullpath,
4036 artwork.gfx_current->basepath);
4039 setup.graphics_set = artwork.gfx_current->identifier;
4040 setup.sounds_set = artwork.snd_current->identifier;
4041 setup.music_set = artwork.mus_current->identifier;
4043 /* needed if last screen (setup choice) changed graphics, sounds or music */
4044 ReloadCustomArtwork(0);
4046 /* needed for displaying artwork name instead of artwork identifier */
4047 graphics_set_name = artwork.gfx_current->name;
4048 sounds_set_name = artwork.snd_current->name;
4049 music_set_name = artwork.mus_current->name;
4051 setup_mode = SETUP_MODE_ARTWORK;
4056 static void execSetupChooseGraphics()
4058 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4063 static void execSetupChooseSounds()
4065 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4070 static void execSetupChooseMusic()
4072 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4077 static void execSetupInput()
4079 setup_mode = SETUP_MODE_INPUT;
4084 static void execSetupShortcuts1()
4086 setup_mode = SETUP_MODE_SHORTCUTS_1;
4091 static void execSetupShortcuts2()
4093 setup_mode = SETUP_MODE_SHORTCUTS_2;
4098 static void execExitSetup()
4100 game_status = GAME_MODE_MAIN;
4102 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4105 static void execSaveAndExitSetup()
4111 static struct TokenInfo setup_info_main[] =
4113 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4114 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4115 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4116 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4117 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4118 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4119 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4120 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4121 { TYPE_EMPTY, NULL, "" },
4122 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4123 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4128 static struct TokenInfo setup_info_game[] =
4130 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4131 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4132 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4133 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4134 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4135 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4136 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4137 { TYPE_STRING, &game_speed_text, "" },
4138 { TYPE_EMPTY, NULL, "" },
4139 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4144 static struct TokenInfo setup_info_editor[] =
4147 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4148 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4149 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4150 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4151 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4152 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4153 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4154 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4156 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4157 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4158 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4160 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4162 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4163 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4164 { TYPE_EMPTY, NULL, "" },
4166 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4167 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4168 { TYPE_EMPTY, NULL, "" },
4170 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4171 { TYPE_EMPTY, NULL, "" },
4172 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4177 static struct TokenInfo setup_info_graphics[] =
4179 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4180 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4181 { TYPE_STRING, &screen_mode_text, "" },
4183 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4185 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4186 { TYPE_STRING, &scroll_delay_text, "" },
4188 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4190 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4191 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4192 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4193 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4194 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4195 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4196 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4197 { TYPE_EMPTY, NULL, "" },
4198 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4203 static struct TokenInfo setup_info_sound[] =
4205 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4206 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4207 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4208 { TYPE_EMPTY, NULL, "" },
4209 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4214 static struct TokenInfo setup_info_artwork[] =
4216 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4217 { TYPE_STRING, &graphics_set_name, "" },
4218 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4219 { TYPE_STRING, &sounds_set_name, "" },
4220 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4221 { TYPE_STRING, &music_set_name, "" },
4222 { TYPE_EMPTY, NULL, "" },
4225 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4226 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4227 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4229 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4230 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4231 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4232 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4235 { TYPE_STRING, NULL, "Override Level Artwork:"},
4236 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4237 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4238 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4240 { TYPE_EMPTY, NULL, "" },
4241 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4246 static struct TokenInfo setup_info_input[] =
4248 { TYPE_SWITCH, NULL, "Player:" },
4249 { TYPE_SWITCH, NULL, "Device:" },
4250 { TYPE_ENTER_MENU, NULL, "" },
4251 { TYPE_EMPTY, NULL, "" },
4252 { TYPE_EMPTY, NULL, "" },
4253 { TYPE_EMPTY, NULL, "" },
4254 { TYPE_EMPTY, NULL, "" },
4255 { TYPE_EMPTY, NULL, "" },
4256 { TYPE_EMPTY, NULL, "" },
4257 { TYPE_EMPTY, NULL, "" },
4258 { TYPE_EMPTY, NULL, "" },
4259 { TYPE_EMPTY, NULL, "" },
4260 { TYPE_EMPTY, NULL, "" },
4261 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4266 static struct TokenInfo setup_info_shortcuts_1[] =
4268 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4269 { TYPE_KEY, &setup.shortcut.save_game, "" },
4270 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4271 { TYPE_KEY, &setup.shortcut.load_game, "" },
4272 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4273 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4274 { TYPE_EMPTY, NULL, "" },
4275 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4276 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4277 { TYPE_EMPTY, NULL, "" },
4278 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4283 static struct TokenInfo setup_info_shortcuts_2[] =
4285 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4286 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4287 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4288 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4289 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4290 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4291 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4292 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4293 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4294 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4295 { TYPE_EMPTY, NULL, "" },
4296 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4301 static Key getSetupKey()
4303 Key key = KSYM_UNDEFINED;
4304 boolean got_key_event = FALSE;
4306 while (!got_key_event)
4308 if (PendingEvent()) /* got event */
4316 case EVENT_KEYPRESS:
4318 key = GetEventKey((KeyEvent *)&event, TRUE);
4320 /* press 'Escape' or 'Enter' to keep the existing key binding */
4321 if (key == KSYM_Escape || key == KSYM_Return)
4322 key = KSYM_UNDEFINED; /* keep old value */
4324 got_key_event = TRUE;
4328 case EVENT_KEYRELEASE:
4329 key_joystick_mapping = 0;
4333 HandleOtherEvents(&event);
4341 /* don't eat all CPU time */
4348 static int getSetupTextFont(int type)
4350 if (type & (TYPE_SWITCH |
4362 static int getSetupValueFont(int type, void *value)
4364 if (type & TYPE_KEY)
4365 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4366 else if (type & TYPE_STRING)
4367 return FONT_VALUE_2;
4368 else if (type & TYPE_ECS_AGA)
4369 return FONT_VALUE_1;
4370 else if (type & TYPE_BOOLEAN_STYLE)
4371 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4372 else if (type & TYPE_YES_NO_AUTO)
4373 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4374 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4376 return FONT_VALUE_1;
4379 static void drawSetupValue(int pos)
4381 boolean font_draw_xoffset_modified = FALSE;
4382 int font_draw_xoffset_old = -1;
4383 int xpos = MENU_SCREEN_VALUE_XPOS;
4384 int ypos = MENU_SCREEN_START_YPOS + pos;
4385 int startx = mSX + xpos * 32;
4386 int starty = mSY + ypos * 32;
4387 int font_nr, font_width, font_height;
4388 int type = setup_info[pos].type;
4389 void *value = setup_info[pos].value;
4390 char *value_string = getSetupValue(type, value);
4395 if (value_string == NULL)
4398 if (type & TYPE_KEY)
4400 xpos = MENU_SCREEN_START_XPOS;
4402 if (type & TYPE_QUERY)
4403 value_string = "<press key>";
4405 else if (type & TYPE_STRING)
4407 int max_value_len = (SCR_FIELDX - 2) * 2;
4409 xpos = MENU_SCREEN_START_XPOS;
4411 if (strlen(value_string) > max_value_len)
4412 value_string[max_value_len] = '\0';
4414 else if (type & TYPE_YES_NO_AUTO)
4416 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4419 startx = mSX + xpos * 32;
4420 starty = mSY + ypos * 32;
4421 font_nr = getSetupValueFont(type, value);
4422 font_width = getFontWidth(font_nr);
4423 font_height = getFontHeight(font_nr);
4425 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4426 if (setup_mode != SETUP_MODE_INPUT)
4428 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4429 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4430 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4431 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4432 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4433 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4434 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4435 boolean correct_font_draw_xoffset = FALSE;
4437 if (xpos == MENU_SCREEN_START_XPOS &&
4438 startx + font1_xoffset < text_startx + text_font_xoffset)
4439 correct_font_draw_xoffset = TRUE;
4441 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4442 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4443 correct_font_draw_xoffset = TRUE;
4445 /* check if setup value would overlap with setup text when printed */
4446 /* (this can happen for extreme/wrong values for font draw offset) */
4447 if (correct_font_draw_xoffset)
4449 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4450 font_draw_xoffset_modified = TRUE;
4452 if (type & TYPE_KEY)
4453 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4454 else if (!(type & TYPE_STRING))
4455 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4456 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4461 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4463 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4464 DrawText(startx + i * font_width, starty, " ", font_nr);
4467 DrawText(startx, starty, value_string, font_nr);
4469 if (font_draw_xoffset_modified)
4470 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4473 static void changeSetupValue(int pos, int dx)
4475 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4477 *(boolean *)setup_info[pos].value ^= TRUE;
4479 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4481 *(int *)setup_info[pos].value =
4483 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4484 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4485 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4486 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4488 else if (setup_info[pos].type & TYPE_KEY)
4492 setup_info[pos].type |= TYPE_QUERY;
4493 drawSetupValue(pos);
4494 setup_info[pos].type &= ~TYPE_QUERY;
4496 key = getSetupKey();
4497 if (key != KSYM_UNDEFINED)
4498 *(Key *)setup_info[pos].value = key;
4501 drawSetupValue(pos);
4504 static void DrawCursorAndText_Setup(int pos, boolean active)
4506 int xpos = MENU_SCREEN_START_XPOS;
4507 int ypos = MENU_SCREEN_START_YPOS + pos;
4508 int font_nr = getSetupTextFont(setup_info[pos].type);
4510 if (setup_info == setup_info_input)
4511 font_nr = FONT_MENU_1;
4514 font_nr = FONT_ACTIVE(font_nr);
4516 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4518 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4519 drawCursor(pos, active);
4522 static void DrawSetupScreen_Generic()
4524 boolean redraw_all = FALSE;
4525 char *title_string = NULL;
4529 CloseDoor(DOOR_CLOSE_2);
4531 if (redraw_mask & REDRAW_ALL)
4535 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4536 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4537 int2str(0, redraw_mask)));
4541 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4542 FadeOut(redraw_mask);
4544 FadeOut(REDRAW_FIELD);
4549 if (setup_mode == SETUP_MODE_MAIN)
4551 setup_info = setup_info_main;
4552 title_string = "Setup";
4554 else if (setup_mode == SETUP_MODE_GAME)
4556 setup_info = setup_info_game;
4557 title_string = "Setup Game";
4559 else if (setup_mode == SETUP_MODE_EDITOR)
4561 setup_info = setup_info_editor;
4562 title_string = "Setup Editor";
4564 else if (setup_mode == SETUP_MODE_GRAPHICS)
4566 setup_info = setup_info_graphics;
4567 title_string = "Setup Graphics";
4569 else if (setup_mode == SETUP_MODE_SOUND)
4571 setup_info = setup_info_sound;
4572 title_string = "Setup Sound";
4574 else if (setup_mode == SETUP_MODE_ARTWORK)
4576 setup_info = setup_info_artwork;
4577 title_string = "Custom Artwork";
4579 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4581 setup_info = setup_info_shortcuts_1;
4582 title_string = "Setup Shortcuts";
4584 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4586 setup_info = setup_info_shortcuts_2;
4587 title_string = "Setup Shortcuts";
4590 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4594 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4596 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4599 void *value_ptr = setup_info[i].value;
4601 /* set some entries to "unchangeable" according to other variables */
4602 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4603 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4604 (value_ptr == &setup.sound_music && !audio.music_available) ||
4605 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4606 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4607 setup_info[i].type |= TYPE_GHOSTED;
4609 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4610 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4611 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4612 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4613 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4614 initCursor(i, IMG_MENU_BUTTON);
4616 DrawCursorAndText_Setup(i, FALSE);
4618 if (setup_info[i].type & TYPE_VALUE)
4625 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4626 "Joysticks deactivated in setup menu");
4630 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4634 redraw_mask = REDRAW_ALL;
4637 FadeIn(redraw_mask);
4639 FadeIn(REDRAW_FIELD);
4644 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4648 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4650 static int choice_store[MAX_SETUP_MODES];
4651 int choice = choice_store[setup_mode]; /* always starts with 0 */
4655 if (button == MB_MENU_INITIALIZE)
4657 /* advance to first valid menu entry */
4658 while (choice < num_setup_info &&
4659 setup_info[choice].type & TYPE_SKIP_ENTRY)
4661 choice_store[setup_mode] = choice;
4663 DrawCursorAndText_Setup(choice, TRUE);
4667 else if (button == MB_MENU_LEAVE)
4669 PlaySound(SND_MENU_ITEM_SELECTING);
4671 for (y = 0; y < num_setup_info; y++)
4673 if (setup_info[y].type & TYPE_LEAVE_MENU)
4675 void (*menu_callback_function)(void) = setup_info[y].value;
4679 menu_callback_function();
4681 break; /* absolutely needed because function changes 'setup_info'! */
4688 if (mx || my) /* mouse input */
4690 x = (mx - mSX) / 32;
4691 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4693 else if (dx || dy) /* keyboard input */
4697 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4699 if (setup_info[choice].type & menu_navigation_type ||
4700 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4701 setup_info[choice].type & TYPE_YES_NO_AUTO)
4702 button = MB_MENU_CHOICE;
4707 /* jump to next non-empty menu entry (up or down) */
4708 while (y > 0 && y < num_setup_info - 1 &&
4709 setup_info[y].type & TYPE_SKIP_ENTRY)
4713 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4717 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4719 PlaySound(SND_MENU_ITEM_ACTIVATING);
4721 DrawCursorAndText_Setup(choice, FALSE);
4722 DrawCursorAndText_Setup(y, TRUE);
4724 choice = choice_store[setup_mode] = y;
4727 else if (!(setup_info[y].type & TYPE_GHOSTED))
4729 PlaySound(SND_MENU_ITEM_SELECTING);
4731 /* when selecting key headline, execute function for key value change */
4732 if (setup_info[y].type & TYPE_KEYTEXT &&
4733 setup_info[y + 1].type & TYPE_KEY)
4736 /* when selecting string value, execute function for list selection */
4737 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4738 setup_info[y - 1].type & TYPE_ENTER_LIST)
4741 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4743 void (*menu_callback_function)(void) = setup_info[y].value;
4745 FadeSetFromType(setup_info[y].type);
4747 menu_callback_function();
4751 if (setup_info[y].type & TYPE_VALUE)
4752 changeSetupValue(y, dx);
4758 void DrawSetupScreen_Input()
4763 FadeOut(REDRAW_FIELD);
4769 setup_info = setup_info_input;
4772 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4776 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4777 "Joysticks deactivated on this screen");
4779 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4780 "Joysticks deactivated on this screen");
4785 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4787 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4790 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4791 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4792 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4793 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4794 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4795 initCursor(i, IMG_MENU_BUTTON);
4797 DrawCursorAndText_Setup(i, FALSE);
4801 DeactivateJoystickForCalibration();
4806 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4807 "Joysticks deactivated on this screen");
4809 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4810 "Joysticks deactivated on this screen");
4814 /* create gadgets for setup input menu screen */
4815 FreeScreenGadgets();
4816 CreateScreenGadgets();
4818 /* map gadgets for setup input menu screen */
4819 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4821 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4824 FadeIn(REDRAW_FIELD);
4830 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4832 if (device_name == NULL)
4835 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4838 if (strlen(device_name) > 1)
4840 char c1 = device_name[strlen(device_name) - 1];
4841 char c2 = device_name[strlen(device_name) - 2];
4843 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4844 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4847 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4848 strlen(device_name));
4851 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4854 static struct SetupKeyboardInfo custom_key;
4861 { &custom_key.left, "Joystick Left" },
4862 { &custom_key.right, "Joystick Right" },
4863 { &custom_key.up, "Joystick Up" },
4864 { &custom_key.down, "Joystick Down" },
4865 { &custom_key.snap, "Button 1" },
4866 { &custom_key.drop, "Button 2" }
4868 static char *joystick_name[MAX_PLAYERS] =
4875 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4879 custom_key = setup.input[player_nr].key;
4881 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4882 FONT_INPUT_1_ACTIVE);
4884 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4886 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4887 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4889 if (setup.input[player_nr].use_joystick)
4891 char *device_name = setup.input[player_nr].joy.device_name;
4892 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4893 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4895 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4896 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4900 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4901 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4904 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4906 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4907 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4908 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4909 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4911 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4912 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4913 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4914 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4915 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4916 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4918 for (i = 0; i < 6; i++)
4920 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4922 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4924 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4925 (setup.input[player_nr].use_joystick ?
4927 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4931 static int input_player_nr = 0;
4933 void HandleSetupScreen_Input_Player(int step, int direction)
4935 int old_player_nr = input_player_nr;
4938 new_player_nr = old_player_nr + step * direction;
4939 if (new_player_nr < 0)
4941 if (new_player_nr > MAX_PLAYERS - 1)
4942 new_player_nr = MAX_PLAYERS - 1;
4944 if (new_player_nr != old_player_nr)
4946 input_player_nr = new_player_nr;
4948 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4952 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
4954 static int choice = 0;
4957 int pos_start = SETUPINPUT_SCREEN_POS_START;
4958 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
4959 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
4960 int pos_end = SETUPINPUT_SCREEN_POS_END;
4962 if (button == MB_MENU_INITIALIZE)
4964 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
4966 DrawCursorAndText_Setup(choice, TRUE);
4970 else if (button == MB_MENU_LEAVE)
4972 setup_mode = SETUP_MODE_MAIN;
4979 if (mx || my) /* mouse input */
4981 x = (mx - mSX) / 32;
4982 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4984 else if (dx || dy) /* keyboard input */
4986 if (dx && choice == 0)
4987 x = (dx < 0 ? 10 : 12);
4988 else if ((dx && choice == 1) ||
4989 (dx == +1 && choice == 2) ||
4990 (dx == -1 && choice == pos_end))
4991 button = MB_MENU_CHOICE;
4995 if (y >= pos_empty1 && y <= pos_empty2)
4996 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
4999 if (y == 0 && dx != 0 && button)
5001 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5003 else if (IN_VIS_FIELD(x, y) &&
5004 y >= pos_start && y <= pos_end &&
5005 !(y >= pos_empty1 && y <= pos_empty2))
5011 DrawCursorAndText_Setup(choice, FALSE);
5012 DrawCursorAndText_Setup(y, TRUE);
5014 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5023 char *device_name = setup.input[input_player_nr].joy.device_name;
5025 if (!setup.input[input_player_nr].use_joystick)
5027 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5029 setJoystickDeviceToNr(device_name, new_device_nr);
5030 setup.input[input_player_nr].use_joystick = TRUE;
5034 int device_nr = getJoystickNrFromDeviceName(device_name);
5035 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5037 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5038 setup.input[input_player_nr].use_joystick = FALSE;
5040 setJoystickDeviceToNr(device_name, new_device_nr);
5043 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5047 if (setup.input[input_player_nr].use_joystick)
5050 CalibrateJoystick(input_player_nr);
5053 CustomizeKeyboard(input_player_nr);
5055 else if (y == pos_end)
5061 setup_mode = SETUP_MODE_MAIN;
5068 void CustomizeKeyboard(int player_nr)
5072 boolean finished = FALSE;
5073 static struct SetupKeyboardInfo custom_key;
5078 } customize_step[] =
5080 { &custom_key.left, "Move Left" },
5081 { &custom_key.right, "Move Right" },
5082 { &custom_key.up, "Move Up" },
5083 { &custom_key.down, "Move Down" },
5084 { &custom_key.snap, "Snap Field" },
5085 { &custom_key.drop, "Drop Element" }
5088 /* read existing key bindings from player setup */
5089 custom_key = setup.input[player_nr].key;
5092 FadeOut(REDRAW_FIELD);
5096 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5104 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5105 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5106 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5107 "Key:", FONT_INPUT_1_ACTIVE);
5108 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5109 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5112 FadeIn(REDRAW_FIELD);
5119 if (PendingEvent()) /* got event */
5127 case EVENT_KEYPRESS:
5129 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5131 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5133 if (key == KSYM_Escape)
5134 FadeSkipNextFadeIn();
5140 /* all keys configured -- wait for "Escape" or "Return" key */
5144 /* press 'Enter' to keep the existing key binding */
5145 if (key == KSYM_Return)
5146 key = *customize_step[step_nr].key;
5148 /* check if key already used */
5149 for (i = 0; i < step_nr; i++)
5150 if (*customize_step[i].key == key)
5155 /* got new key binding */
5156 *customize_step[step_nr].key = key;
5157 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5159 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5160 getKeyNameFromKey(key), FONT_VALUE_1);
5163 /* un-highlight last query */
5164 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5165 customize_step[step_nr - 1].text, FONT_MENU_1);
5166 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5167 "Key:", FONT_MENU_1);
5169 /* press 'Enter' to leave */
5172 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5173 "Press Enter", FONT_TITLE_1);
5177 /* query next key binding */
5178 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5179 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5180 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5181 "Key:", FONT_INPUT_1_ACTIVE);
5182 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5183 getKeyNameFromKey(*customize_step[step_nr].key),
5188 case EVENT_KEYRELEASE:
5189 key_joystick_mapping = 0;
5193 HandleOtherEvents(&event);
5201 /* don't eat all CPU time */
5205 /* write new key bindings back to player setup */
5206 setup.input[player_nr].key = custom_key;
5209 DrawSetupScreen_Input();
5212 static boolean CalibrateJoystickMain(int player_nr)
5214 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5215 int new_joystick_xright = JOYSTICK_XMIDDLE;
5216 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5217 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5218 int new_joystick_xmiddle, new_joystick_ymiddle;
5220 int joystick_fd = joystick.fd[player_nr];
5221 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5222 boolean check[3][3];
5223 int check_remaining = 3 * 3;
5228 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5231 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5235 FadeOut(REDRAW_FIELD);
5239 for (y = 0; y < 3; y++)
5241 for (x = 0; x < 3; x++)
5243 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5244 check[x][y] = FALSE;
5248 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5249 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5250 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5251 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5252 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5253 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5254 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5256 joy_value = Joystick(player_nr);
5257 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5258 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5260 /* eventually uncalibrated center position (joystick could be uncentered) */
5261 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5264 new_joystick_xmiddle = joy_x;
5265 new_joystick_ymiddle = joy_y;
5267 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5269 FadeIn(REDRAW_FIELD);
5271 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5276 if (PendingEvent()) /* got event */
5284 case EVENT_KEYPRESS:
5285 switch (GetEventKey((KeyEvent *)&event, TRUE))
5288 if (check_remaining == 0)
5293 FadeSkipNextFadeIn();
5302 case EVENT_KEYRELEASE:
5303 key_joystick_mapping = 0;
5307 HandleOtherEvents(&event);
5312 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5315 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5316 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5317 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5318 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5320 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5321 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5322 setup.input[player_nr].joy.xright = new_joystick_xright;
5323 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5324 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5325 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5327 CheckJoystickData();
5329 joy_value = Joystick(player_nr);
5331 if (joy_value & JOY_BUTTON && check_remaining == 0)
5334 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5335 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5337 if (x != last_x || y != last_y)
5339 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5340 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5345 if (check_remaining > 0 && !check[x+1][y+1])
5347 check[x+1][y+1] = TRUE;
5353 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5354 setup.input[player_nr].joy.xleft,
5355 setup.input[player_nr].joy.xmiddle,
5356 setup.input[player_nr].joy.xright);
5357 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5358 setup.input[player_nr].joy.yupper,
5359 setup.input[player_nr].joy.ymiddle,
5360 setup.input[player_nr].joy.ylower);
5369 /* don't eat all CPU time */
5373 /* calibrated center position (joystick should now be centered) */
5374 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5377 new_joystick_xmiddle = joy_x;
5378 new_joystick_ymiddle = joy_y;
5383 DrawSetupScreen_Input();
5386 /* wait until the last pressed button was released */
5387 while (Joystick(player_nr) & JOY_BUTTON)
5389 if (PendingEvent()) /* got event */
5394 HandleOtherEvents(&event);
5403 void CalibrateJoystick(int player_nr)
5405 if (!CalibrateJoystickMain(player_nr))
5407 char *device_name = setup.input[player_nr].joy.device_name;
5408 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5409 int xpos = mSX - SX;
5410 int ypos = mSY - SY;
5414 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5415 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5418 Delay(2000); /* show error message for a short time */
5424 DrawSetupScreen_Input();
5428 void DrawSetupScreen()
5430 DeactivateJoystick();
5432 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5434 if (setup_mode == SETUP_MODE_INPUT)
5435 DrawSetupScreen_Input();
5436 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5437 DrawChooseTree(&game_speed_current);
5438 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5439 DrawChooseTree(&screen_mode_current);
5440 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5441 DrawChooseTree(&scroll_delay_current);
5442 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5443 DrawChooseTree(&artwork.gfx_current);
5444 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5445 DrawChooseTree(&artwork.snd_current);
5446 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5447 DrawChooseTree(&artwork.mus_current);
5449 DrawSetupScreen_Generic();
5455 void RedrawSetupScreenAfterFullscreenToggle()
5457 if (setup_mode == SETUP_MODE_GRAPHICS)
5461 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5463 if (setup_mode == SETUP_MODE_INPUT)
5464 HandleSetupScreen_Input(mx, my, dx, dy, button);
5465 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5466 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5467 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5468 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5469 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5470 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5471 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5472 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5473 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5474 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5475 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5476 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5478 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5483 void HandleGameActions()
5485 if (game_status != GAME_MODE_PLAYING)
5488 GameActions(); /* main game loop */
5490 if (tape.auto_play && !tape.playing)
5491 AutoPlayTape(); /* continue automatically playing next tape */
5495 /* ---------- new screen button stuff -------------------------------------- */
5497 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5502 case SCREEN_CTRL_ID_PREV_LEVEL:
5503 *x = mSX + menu.main.button.prev_level.x;
5504 *y = mSY + menu.main.button.prev_level.y;
5507 case SCREEN_CTRL_ID_NEXT_LEVEL:
5508 *x = mSX + menu.main.button.next_level.x;
5509 *y = mSY + menu.main.button.next_level.y;
5512 case SCREEN_CTRL_ID_PREV_LEVEL:
5513 *x = mSX + TILEX * getPrevlevelButtonPos();
5514 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5517 case SCREEN_CTRL_ID_NEXT_LEVEL:
5518 *x = mSX + TILEX * getNextLevelButtonPos();
5519 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5523 case SCREEN_CTRL_ID_PREV_PLAYER:
5524 *x = mSX + TILEX * 10;
5525 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5528 case SCREEN_CTRL_ID_NEXT_PLAYER:
5529 *x = mSX + TILEX * 12;
5530 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5534 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5540 int gfx_unpressed, gfx_pressed;
5541 void (*get_gadget_position)(int *, int *, int);
5545 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5548 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5549 getScreenMenuButtonPos,
5550 SCREEN_CTRL_ID_PREV_LEVEL,
5555 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5556 getScreenMenuButtonPos,
5557 SCREEN_CTRL_ID_NEXT_LEVEL,
5562 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5563 getScreenMenuButtonPos,
5564 SCREEN_CTRL_ID_PREV_PLAYER,
5569 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5570 getScreenMenuButtonPos,
5571 SCREEN_CTRL_ID_NEXT_PLAYER,
5579 int gfx_unpressed, gfx_pressed;
5583 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5586 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5587 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5588 SCREEN_CTRL_ID_SCROLL_UP,
5592 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5593 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5594 SCREEN_CTRL_ID_SCROLL_DOWN,
5601 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5602 Bitmap **gfx_unpressed, **gfx_pressed;
5604 int gfx_unpressed, gfx_pressed;
5611 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5614 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5615 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5617 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5619 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5620 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5621 GD_TYPE_SCROLLBAR_VERTICAL,
5622 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5623 "scroll level series vertically"
5627 static void CreateScreenMenubuttons()
5629 struct GadgetInfo *gi;
5630 unsigned long event_mask;
5633 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5635 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5636 int gfx_unpressed, gfx_pressed;
5637 int x, y, width, height;
5638 int gd_x1, gd_x2, gd_y1, gd_y2;
5639 int id = menubutton_info[i].gadget_id;
5641 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5643 menubutton_info[i].get_gadget_position(&x, &y, id);
5645 width = SC_MENUBUTTON_XSIZE;
5646 height = SC_MENUBUTTON_YSIZE;
5648 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5649 gfx_pressed = menubutton_info[i].gfx_pressed;
5650 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5651 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5652 gd_x1 = graphic_info[gfx_unpressed].src_x;
5653 gd_y1 = graphic_info[gfx_unpressed].src_y;
5654 gd_x2 = graphic_info[gfx_pressed].src_x;
5655 gd_y2 = graphic_info[gfx_pressed].src_y;
5657 gi = CreateGadget(GDI_CUSTOM_ID, id,
5658 GDI_CUSTOM_TYPE_ID, i,
5659 GDI_INFO_TEXT, menubutton_info[i].infotext,
5664 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5665 GDI_STATE, GD_BUTTON_UNPRESSED,
5666 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5667 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5668 GDI_DIRECT_DRAW, FALSE,
5669 GDI_EVENT_MASK, event_mask,
5670 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5674 Error(ERR_EXIT, "cannot create gadget");
5676 screen_gadget[id] = gi;
5680 static void CreateScreenScrollbuttons()
5682 struct GadgetInfo *gi;
5683 unsigned long event_mask;
5686 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5688 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5689 int gfx_unpressed, gfx_pressed;
5690 int x, y, width, height;
5691 int gd_x1, gd_x2, gd_y1, gd_y2;
5692 int id = scrollbutton_info[i].gadget_id;
5694 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5696 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5697 y = mSY + scrollbutton_info[i].y;
5698 width = SC_SCROLLBUTTON_XSIZE;
5699 height = SC_SCROLLBUTTON_YSIZE;
5701 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5702 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5703 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5705 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5706 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5707 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5708 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5709 gd_x1 = graphic_info[gfx_unpressed].src_x;
5710 gd_y1 = graphic_info[gfx_unpressed].src_y;
5711 gd_x2 = graphic_info[gfx_pressed].src_x;
5712 gd_y2 = graphic_info[gfx_pressed].src_y;
5714 gi = CreateGadget(GDI_CUSTOM_ID, id,
5715 GDI_CUSTOM_TYPE_ID, i,
5716 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5721 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5722 GDI_STATE, GD_BUTTON_UNPRESSED,
5723 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5724 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5725 GDI_DIRECT_DRAW, FALSE,
5726 GDI_EVENT_MASK, event_mask,
5727 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5731 Error(ERR_EXIT, "cannot create gadget");
5733 screen_gadget[id] = gi;
5737 static void CreateScreenScrollbars()
5741 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5743 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5744 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5745 int gfx_unpressed, gfx_pressed;
5747 int x, y, width, height;
5748 int gd_x1, gd_x2, gd_y1, gd_y2;
5749 struct GadgetInfo *gi;
5750 int items_max, items_visible, item_position;
5751 unsigned long event_mask;
5752 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5753 int id = scrollbar_info[i].gadget_id;
5755 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5757 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5758 y = mSY + scrollbar_info[i].y;
5759 width = scrollbar_info[i].width;
5760 height = scrollbar_info[i].height;
5762 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5763 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5765 items_max = num_page_entries;
5766 items_visible = num_page_entries;
5769 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5770 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5771 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5777 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5778 gfx_pressed = scrollbar_info[i].gfx_pressed;
5779 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5780 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5781 gd_x1 = graphic_info[gfx_unpressed].src_x;
5782 gd_y1 = graphic_info[gfx_unpressed].src_y;
5783 gd_x2 = graphic_info[gfx_pressed].src_x;
5784 gd_y2 = graphic_info[gfx_pressed].src_y;
5787 gi = CreateGadget(GDI_CUSTOM_ID, id,
5788 GDI_CUSTOM_TYPE_ID, i,
5789 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5794 GDI_TYPE, scrollbar_info[i].type,
5795 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5796 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5797 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5799 GDI_WHEEL_AREA_X, SX,
5800 GDI_WHEEL_AREA_Y, SY,
5801 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5802 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5804 GDI_WHEEL_AREA_X, 0,
5805 GDI_WHEEL_AREA_Y, 0,
5806 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5807 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5809 GDI_STATE, GD_BUTTON_UNPRESSED,
5810 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5811 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5812 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5813 GDI_DIRECT_DRAW, FALSE,
5814 GDI_EVENT_MASK, event_mask,
5815 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5819 Error(ERR_EXIT, "cannot create gadget");
5821 screen_gadget[id] = gi;
5825 void CreateScreenGadgets()
5827 int last_game_status = game_status; /* save current game status */
5829 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5832 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5834 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5836 /* copy pointers to clip mask and GC */
5837 scrollbar_bitmap[i]->clip_mask =
5838 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5839 scrollbar_bitmap[i]->stored_clip_gc =
5840 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5842 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5843 scrollbar_bitmap[i],
5844 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5845 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5846 TILEX, TILEY, 0, 0);
5850 CreateScreenMenubuttons();
5853 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5854 game_status = GAME_MODE_LEVELS;
5857 CreateScreenScrollbuttons();
5858 CreateScreenScrollbars();
5860 game_status = last_game_status; /* restore current game status */
5863 void FreeScreenGadgets()
5867 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5868 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5870 /* prevent freeing clip mask and GC twice */
5871 scrollbar_bitmap[i]->clip_mask = None;
5872 scrollbar_bitmap[i]->stored_clip_gc = None;
5874 FreeBitmap(scrollbar_bitmap[i]);
5878 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5879 FreeGadget(screen_gadget[i]);
5882 void MapScreenMenuGadgets(int screen_mask)
5886 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5887 if (screen_mask & menubutton_info[i].screen_mask)
5888 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5891 void MapScreenTreeGadgets(TreeInfo *ti)
5893 int num_entries = numTreeInfoInGroup(ti);
5896 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5899 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5900 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5902 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5903 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5906 static void HandleScreenGadgets(struct GadgetInfo *gi)
5908 int id = gi->custom_id;
5909 int button = gi->event.button;
5910 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5914 case SCREEN_CTRL_ID_PREV_LEVEL:
5915 HandleMainMenu_SelectLevel(step, -1);
5918 case SCREEN_CTRL_ID_NEXT_LEVEL:
5919 HandleMainMenu_SelectLevel(step, +1);
5922 case SCREEN_CTRL_ID_PREV_PLAYER:
5923 HandleSetupScreen_Input_Player(step, -1);
5926 case SCREEN_CTRL_ID_NEXT_PLAYER:
5927 HandleSetupScreen_Input_Player(step, +1);
5930 case SCREEN_CTRL_ID_SCROLL_UP:
5931 if (game_status == GAME_MODE_LEVELS)
5932 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5933 else if (game_status == GAME_MODE_SETUP)
5934 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5937 case SCREEN_CTRL_ID_SCROLL_DOWN:
5938 if (game_status == GAME_MODE_LEVELS)
5939 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5940 else if (game_status == GAME_MODE_SETUP)
5941 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5944 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5945 if (game_status == GAME_MODE_LEVELS)
5946 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5947 else if (game_status == GAME_MODE_SETUP)
5948 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);