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 7
49 #define SETUP_MODE_SHORTCUTS_1 8
50 #define SETUP_MODE_SHORTCUTS_2 9
51 #define SETUP_MODE_SHORTCUTS_3 10
52 #define SETUP_MODE_SHORTCUTS_4 11
53 #define SETUP_MODE_SHORTCUTS_5 12
55 /* sub-screens on the setup screen (generic) */
56 #define SETUP_MODE_CHOOSE_ARTWORK 13
57 #define SETUP_MODE_CHOOSE_OTHER 14
59 /* sub-screens on the setup screen (specific) */
60 #define SETUP_MODE_CHOOSE_GAME_SPEED 15
61 #define SETUP_MODE_CHOOSE_SCREEN_MODE 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_GRAPHICS 18
64 #define SETUP_MODE_CHOOSE_SOUNDS 19
65 #define SETUP_MODE_CHOOSE_MUSIC 20
66 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 21
67 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 22
68 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 23
70 #define MAX_SETUP_MODES 24
72 /* for input setup functions */
73 #define SETUPINPUT_SCREEN_POS_START 0
74 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
75 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
76 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
78 /* for various menu stuff */
79 #define MENU_SCREEN_START_XPOS 1
80 #define MENU_SCREEN_START_YPOS 2
81 #define MENU_SCREEN_VALUE_XPOS 14
82 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
83 #define MENU_TITLE1_YPOS 8
84 #define MENU_TITLE2_YPOS 46
85 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
86 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
87 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
88 MENU_SCREEN_START_XPOS)
89 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
91 /* buttons and scrollbars identifiers */
92 #define SCREEN_CTRL_ID_PREV_LEVEL 0
93 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
94 #define SCREEN_CTRL_ID_PREV_PLAYER 2
95 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
96 #define SCREEN_CTRL_ID_SCROLL_UP 4
97 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
98 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
100 #define NUM_SCREEN_GADGETS 7
102 #define NUM_SCREEN_MENUBUTTONS 4
103 #define NUM_SCREEN_SCROLLBUTTONS 2
104 #define NUM_SCREEN_SCROLLBARS 1
106 #define SCREEN_MASK_MAIN (1 << 0)
107 #define SCREEN_MASK_INPUT (1 << 1)
109 /* graphic position and size values for buttons and scrollbars */
110 #define SC_MENUBUTTON_XSIZE TILEX
111 #define SC_MENUBUTTON_YSIZE TILEY
113 #define SC_SCROLLBUTTON_XSIZE TILEX
114 #define SC_SCROLLBUTTON_YSIZE TILEY
116 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
118 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
119 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
120 SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
125 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
126 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
127 SC_SCROLLBUTTON_YSIZE)
129 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
130 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
131 SC_SCROLL_VERTICAL_YSIZE)
133 #define SC_BORDER_SIZE 14
136 /* forward declarations of internal functions */
137 static void HandleScreenGadgets(struct GadgetInfo *);
138 static void HandleSetupScreen_Generic(int, int, int, int, int);
139 static void HandleSetupScreen_Input(int, int, int, int, int);
140 static void CustomizeKeyboard(int);
141 static void CalibrateJoystick(int);
142 static void execSetupGame(void);
143 static void execSetupGraphics(void);
144 static void execSetupSound(void);
145 static void execSetupArtwork(void);
146 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
148 static void DrawChooseLevelSet(void);
149 static void DrawChooseLevelNr(void);
150 static void DrawInfoScreen(void);
151 static void DrawAndFadeInInfoScreen(int);
152 static void DrawSetupScreen(void);
154 static void DrawInfoScreenExt(int, int);
155 static void DrawInfoScreen_NotAvailable(char *, char *);
156 static void DrawInfoScreen_HelpAnim(int, int, boolean);
157 static void DrawInfoScreen_HelpText(int, int, int, int);
158 static void HandleInfoScreen_Main(int, int, int, int, int);
159 static void HandleInfoScreen_TitleScreen(int);
160 static void HandleInfoScreen_Elements(int);
161 static void HandleInfoScreen_Music(int);
162 static void HandleInfoScreen_Credits(int);
163 static void HandleInfoScreen_Program(int);
164 static void HandleInfoScreen_Version(int);
166 static void MapScreenMenuGadgets(int);
167 static void MapScreenTreeGadgets(TreeInfo *);
169 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
171 static int info_mode = INFO_MODE_MAIN;
172 static int setup_mode = SETUP_MODE_MAIN;
174 static TreeInfo *screen_modes = NULL;
175 static TreeInfo *screen_mode_current = NULL;
177 static TreeInfo *scroll_delays = NULL;
178 static TreeInfo *scroll_delay_current = NULL;
180 static TreeInfo *game_speeds = NULL;
181 static TreeInfo *game_speed_current = NULL;
183 static TreeInfo *volumes_simple = NULL;
184 static TreeInfo *volume_simple_current = NULL;
186 static TreeInfo *volumes_loops = NULL;
187 static TreeInfo *volume_loops_current = NULL;
189 static TreeInfo *volumes_music = NULL;
190 static TreeInfo *volume_music_current = NULL;
192 static TreeInfo *level_number = NULL;
193 static TreeInfo *level_number_current = NULL;
199 } game_speeds_list[] =
208 { 1000, "1/1s (Extremely Slow)" },
213 { 29, "1/35s (Original Supaplex)" },
215 { 20, "1/50s (Normal Speed)" },
216 { 14, "1/70s (Maximum Supaplex)" },
220 { 1, "1/1000s (Extremely Fast)" },
230 } scroll_delays_list[] =
232 { 0, "0 Tiles (No Scroll Delay)" },
235 { 3, "3 Tiles (Default)" },
240 { 8, "8 Tiles (Maximum Scroll Delay)"},
266 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
267 (s) <= GAME_MODE_SETUP ? (s) : \
268 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
269 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
271 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
272 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
273 (i) <= INFO_MODE_LEVELSET ? (i) : \
276 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
277 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
278 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
279 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
280 SETUP_MODE_CHOOSE_ARTWORK : \
281 SETUP_MODE_CHOOSE_OTHER)
283 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
284 menu.draw_xoffset[GAME_MODE_INFO] : \
285 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
286 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
287 menu.draw_yoffset[GAME_MODE_INFO] : \
288 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
290 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
291 menu.draw_xoffset[GAME_MODE_SETUP] : \
292 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
293 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
294 menu.draw_yoffset[GAME_MODE_SETUP] : \
295 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
297 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
298 DRAW_XOFFSET_INFO(info_mode) : \
299 (s) == GAME_MODE_SETUP ? \
300 DRAW_XOFFSET_SETUP(setup_mode) : \
301 menu.draw_xoffset[DRAW_MODE(s)])
302 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
303 DRAW_YOFFSET_INFO(info_mode) : \
304 (s) == GAME_MODE_SETUP ? \
305 DRAW_YOFFSET_SETUP(setup_mode) : \
306 menu.draw_yoffset[DRAW_MODE(s)])
308 #define mSX (SX + DRAW_XOFFSET(game_status))
309 #define mSY (SY + DRAW_YOFFSET(game_status))
311 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
312 menu.list_size[game_status] : \
313 MAX_MENU_ENTRIES_ON_SCREEN)
315 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
316 #define NUM_SCROLLBAR_BITMAPS 2
317 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
321 /* title display and control definitions */
323 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
324 2 * MAX_NUM_TITLE_MESSAGES)
326 static int num_title_screens = 0;
328 struct TitleControlInfo
336 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
338 /* main menu display and control definitions */
340 #define MAIN_CONTROL_NAME 0
341 #define MAIN_CONTROL_LEVELS 1
342 #define MAIN_CONTROL_SCORES 2
343 #define MAIN_CONTROL_EDITOR 3
344 #define MAIN_CONTROL_INFO 4
345 #define MAIN_CONTROL_GAME 5
346 #define MAIN_CONTROL_SETUP 6
347 #define MAIN_CONTROL_QUIT 7
348 #define MAIN_CONTROL_PREV_LEVEL 8
349 #define MAIN_CONTROL_NEXT_LEVEL 9
350 #define MAIN_CONTROL_FIRST_LEVEL 10
351 #define MAIN_CONTROL_LAST_LEVEL 11
352 #define MAIN_CONTROL_LEVEL_NUMBER 12
353 #define MAIN_CONTROL_LEVEL_INFO_1 13
354 #define MAIN_CONTROL_LEVEL_INFO_2 14
355 #define MAIN_CONTROL_LEVEL_NAME 15
356 #define MAIN_CONTROL_LEVEL_AUTHOR 16
357 #define MAIN_CONTROL_LEVEL_YEAR 17
358 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
359 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
360 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
361 #define MAIN_CONTROL_TITLE_1 21
362 #define MAIN_CONTROL_TITLE_2 22
363 #define MAIN_CONTROL_TITLE_3 23
365 static char str_main_text_name[10];
366 static char str_main_text_first_level[10];
367 static char str_main_text_last_level[10];
368 static char str_main_text_level_number[10];
370 static char *main_text_name = str_main_text_name;
371 static char *main_text_first_level = str_main_text_first_level;
372 static char *main_text_last_level = str_main_text_last_level;
373 static char *main_text_level_number = str_main_text_level_number;
374 static char *main_text_levels = "Levelset";
375 static char *main_text_scores = "Hall Of Fame";
376 static char *main_text_editor = "Level Creator";
377 static char *main_text_info = "Info Screen";
378 static char *main_text_game = "Start Game";
379 static char *main_text_setup = "Setup";
380 static char *main_text_quit = "Quit";
381 static char *main_text_level_name = level.name;
382 static char *main_text_level_author = level.author;
383 static char *main_text_level_year = NULL;
384 static char *main_text_level_imported_from = NULL;
385 static char *main_text_level_imported_by = NULL;
386 static char *main_text_level_tested_by = NULL;
387 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
388 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
389 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
391 struct MainControlInfo
395 struct MenuPosInfo *pos_button;
398 struct TextPosInfo *pos_text;
401 struct TextPosInfo *pos_input;
405 static struct MainControlInfo main_controls[] =
409 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
410 &menu.main.text.name, &main_text_name,
411 &menu.main.input.name, &setup.player_name,
415 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
416 &menu.main.text.levels, &main_text_levels,
421 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
422 &menu.main.text.scores, &main_text_scores,
427 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
428 &menu.main.text.editor, &main_text_editor,
433 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
434 &menu.main.text.info, &main_text_info,
439 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
440 &menu.main.text.game, &main_text_game,
445 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
446 &menu.main.text.setup, &main_text_setup,
451 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
452 &menu.main.text.quit, &main_text_quit,
456 /* (these two buttons are real gadgets) */
458 MAIN_CONTROL_PREV_LEVEL,
459 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
464 MAIN_CONTROL_NEXT_LEVEL,
465 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
471 MAIN_CONTROL_FIRST_LEVEL,
473 &menu.main.text.first_level, &main_text_first_level,
477 MAIN_CONTROL_LAST_LEVEL,
479 &menu.main.text.last_level, &main_text_last_level,
483 MAIN_CONTROL_LEVEL_NUMBER,
485 &menu.main.text.level_number, &main_text_level_number,
489 MAIN_CONTROL_LEVEL_INFO_1,
491 &menu.main.text.level_info_1, NULL,
495 MAIN_CONTROL_LEVEL_INFO_2,
497 &menu.main.text.level_info_2, NULL,
501 MAIN_CONTROL_LEVEL_NAME,
503 &menu.main.text.level_name, &main_text_level_name,
507 MAIN_CONTROL_LEVEL_AUTHOR,
509 &menu.main.text.level_author, &main_text_level_author,
513 MAIN_CONTROL_LEVEL_YEAR,
515 &menu.main.text.level_year, &main_text_level_year,
519 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
521 &menu.main.text.level_imported_from, &main_text_level_imported_from,
525 MAIN_CONTROL_LEVEL_IMPORTED_BY,
527 &menu.main.text.level_imported_by, &main_text_level_imported_by,
531 MAIN_CONTROL_LEVEL_TESTED_BY,
533 &menu.main.text.level_tested_by, &main_text_level_tested_by,
537 MAIN_CONTROL_TITLE_1,
539 &menu.main.text.title_1, &main_text_title_1,
543 MAIN_CONTROL_TITLE_2,
545 &menu.main.text.title_2, &main_text_title_2,
549 MAIN_CONTROL_TITLE_3,
551 &menu.main.text.title_3, &main_text_title_3,
564 static int getTitleScreenGraphic(int nr, boolean initial)
566 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
569 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
571 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
575 static int getTitleScreenGameMode(boolean initial)
577 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
581 static int getTitleMessageGameMode(boolean initial)
583 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
587 static int getTitleScreenBackground(boolean initial)
589 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
594 static int getTitleMessageBackground(int nr, boolean initial)
596 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
600 static int getTitleBackground(int nr, boolean initial, boolean is_image)
602 int base = (is_image ?
603 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
604 IMG_BACKGROUND_TITLESCREEN_1) :
605 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
606 IMG_BACKGROUND_TITLEMESSAGE_1));
607 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
608 IMG_BACKGROUND_TITLE);
609 int graphic_local = base + nr;
611 if (graphic_info[graphic_local].bitmap != NULL)
612 return graphic_local;
614 if (graphic_info[graphic_global].bitmap != NULL)
615 return graphic_global;
617 return IMG_UNDEFINED;
620 static int getTitleSound(struct TitleControlInfo *tci)
622 boolean is_image = tci->is_image;
623 int initial = tci->initial;
624 int nr = tci->local_nr;
625 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
626 int base = (is_image ?
627 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
628 SND_BACKGROUND_TITLESCREEN_1) :
629 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
630 SND_BACKGROUND_TITLEMESSAGE_1));
631 int sound_global = menu.sound[mode];
632 int sound_local = base + nr;
635 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
636 nr, initial, is_image,
637 sound_global, getSoundListEntry(sound_global)->filename,
638 sound_local, getSoundListEntry(sound_local)->filename);
641 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
644 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
647 return SND_UNDEFINED;
650 static int getTitleMusic(struct TitleControlInfo *tci)
652 boolean is_image = tci->is_image;
653 int initial = tci->initial;
654 int nr = tci->local_nr;
655 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
656 int base = (is_image ?
657 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
658 MUS_BACKGROUND_TITLESCREEN_1) :
659 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
660 MUS_BACKGROUND_TITLEMESSAGE_1));
661 int music_global = menu.music[mode];
662 int music_local = base + nr;
665 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
666 nr, initial, is_image,
667 music_global, getMusicListEntry(music_global)->filename,
668 music_local, getMusicListEntry(music_local)->filename);
671 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
674 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
677 return MUS_UNDEFINED;
680 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
682 boolean is_image = tci->is_image;
683 int initial = tci->initial;
684 int nr = tci->local_nr;
685 struct TitleFadingInfo ti;
689 int graphic = getTitleScreenGraphic(nr, initial);
691 /* initialize fading control values to default title config settings */
692 ti = (initial ? title_initial_default : title_default);
694 /* override default settings with image config settings, if defined */
695 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
696 ti.fade_mode = graphic_info[graphic].fade_mode;
697 if (graphic_info[graphic].fade_delay > -1)
698 ti.fade_delay = graphic_info[graphic].fade_delay;
699 if (graphic_info[graphic].post_delay > -1)
700 ti.post_delay = graphic_info[graphic].post_delay;
701 if (graphic_info[graphic].auto_delay > -1)
702 ti.auto_delay = graphic_info[graphic].auto_delay;
708 ti.fade_mode = titlemessage_initial[nr].fade_mode;
709 ti.fade_delay = titlemessage_initial[nr].fade_delay;
710 ti.post_delay = titlemessage_initial[nr].post_delay;
711 ti.auto_delay = titlemessage_initial[nr].auto_delay;
715 ti.fade_mode = titlemessage[nr].fade_mode;
716 ti.fade_delay = titlemessage[nr].fade_delay;
717 ti.post_delay = titlemessage[nr].post_delay;
718 ti.auto_delay = titlemessage[nr].auto_delay;
723 if (ti.anim_mode == ANIM_NONE)
724 ti.fade_delay = ti.post_delay = 0;
730 static int compareTitleControlInfo(const void *object1, const void *object2)
732 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
733 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
736 if (tci1->initial != tci2->initial)
737 compare_result = (tci1->initial ? -1 : +1);
738 else if (tci1->sort_priority != tci2->sort_priority)
739 compare_result = tci1->sort_priority - tci2->sort_priority;
740 else if (tci1->is_image != tci2->is_image)
741 compare_result = (tci1->is_image ? -1 : +1);
743 compare_result = tci1->local_nr - tci2->local_nr;
745 return compare_result;
748 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
750 int nr, int sort_priority)
752 title_controls[num_title_screens].is_image = is_image;
753 title_controls[num_title_screens].initial = initial;
754 title_controls[num_title_screens].local_nr = nr;
755 title_controls[num_title_screens].sort_priority = sort_priority;
760 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
764 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
766 int graphic = getTitleScreenGraphic(i, initial);
767 Bitmap *bitmap = graphic_info[graphic].bitmap;
768 int sort_priority = graphic_info[graphic].sort_priority;
771 /* skip images and messages (fonts!) when using forced custom graphics */
772 if (setup.override_level_graphics && !initial)
777 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
780 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
782 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
783 char *filename = getLevelSetTitleMessageFilename(i, initial);
784 int sort_priority = tmi->sort_priority;
787 /* skip images and messages (fonts!) when using forced custom graphics */
788 if (setup.override_level_graphics)
792 if (filename != NULL)
793 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
797 static void InitializeTitleControls(boolean show_title_initial)
799 num_title_screens = 0;
802 /* 1st step: initialize title screens for game start (only when starting) */
803 if (show_title_initial)
804 InitializeTitleControls_CheckTitleInfo(TRUE);
807 /* 2nd step: initialize title screens for current level set */
808 InitializeTitleControls_CheckTitleInfo(FALSE);
810 /* sort title screens according to sort_priority and title number */
811 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
812 compareTitleControlInfo);
815 static boolean visibleMenuPos(struct MenuPosInfo *pos)
817 return (pos != NULL && pos->x != -1 && pos->y != -1);
820 static boolean visibleTextPos(struct TextPosInfo *pos)
822 return (pos != NULL && pos->x != -1 && pos->y != -1);
825 static void InitializeMainControls()
827 boolean local_team_mode = (!options.network && setup.team_mode);
830 /* set main control text values to dynamically determined values */
831 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
833 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
834 menu.main.text.first_level.size));
835 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
836 menu.main.text.last_level.size));
837 strcpy(main_text_level_number, int2str(level_nr,
838 menu.main.text.level_number.size));
840 main_text_level_year = leveldir_current->year;
841 main_text_level_imported_from = leveldir_current->imported_from;
842 main_text_level_imported_by = leveldir_current->imported_by;
843 main_text_level_tested_by = leveldir_current->tested_by;
845 /* set main control screen positions to dynamically determined values */
846 for (i = 0; main_controls[i].nr != -1; i++)
848 struct MainControlInfo *mci = &main_controls[i];
850 struct MenuPosInfo *pos_button = mci->pos_button;
851 struct TextPosInfo *pos_text = mci->pos_text;
852 struct TextPosInfo *pos_input = mci->pos_input;
853 char *text = (mci->text ? *mci->text : NULL);
854 char *input = (mci->input ? *mci->input : NULL);
855 int button_graphic = mci->button_graphic;
857 int font_text = (pos_text ? pos_text->font : -1);
858 int font_input = (pos_input ? pos_input->font : -1);
860 int font_text = mci->font_text;
861 int font_input = mci->font_input;
864 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
865 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
866 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
867 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
868 int text_chars = (text != NULL ? strlen(text) : 0);
869 int input_chars = (input != NULL ? strlen(input) : 0);
872 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
874 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
875 int text_width = font_text_width * text_chars;
876 int text_height = font_text_height;
877 int input_width = font_input_width * input_chars;
878 int input_height = font_input_height;
880 if (nr == MAIN_CONTROL_NAME)
883 if (menu.main.input.name.x == -1)
884 menu.main.input.name.x = menu.main.text.name.x + text_width;
885 if (menu.main.input.name.y == -1)
886 menu.main.input.name.y = menu.main.text.name.y;
890 menu.main.input.name.width = input_width;
891 menu.main.input.name.height = input_height;
893 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
894 menu.main.input.name.height = font_input_height;
898 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
900 if (pos_button->width == 0)
901 pos_button->width = button_width;
902 if (pos_button->height == 0)
903 pos_button->height = button_height;
906 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
909 /* calculate size for non-clickable text -- needed for text alignment */
910 boolean calculate_text_size = (pos_button == NULL && text != NULL);
912 /* calculate width for non-clickable text -- needed for text alignment */
913 boolean calculate_text_width = (pos_button == NULL && text != NULL);
916 if (visibleMenuPos(pos_button))
918 if (pos_text->x == -1)
919 pos_text->x = pos_button->x + pos_button->width;
920 if (pos_text->y == -1)
921 pos_text->y = pos_button->y;
925 if (pos_text->width == -1 || calculate_text_size)
926 pos_text->width = text_width;
927 if (pos_text->height == -1 || calculate_text_size)
928 pos_text->height = text_height;
930 if (pos_text->width == -1 || calculate_text_width)
931 pos_text->width = text_width;
932 if (pos_text->height == -1)
933 pos_text->height = text_height;
937 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
939 if (visibleTextPos(pos_text))
941 if (pos_input->x == -1)
942 pos_input->x = pos_text->x + pos_text->width;
943 if (pos_input->y == -1)
944 pos_input->y = pos_text->y;
947 if (pos_input->width == -1)
948 pos_input->width = input_width;
949 if (pos_input->height == -1)
950 pos_input->height = input_height;
955 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
956 boolean active_input)
960 for (i = 0; main_controls[i].nr != -1; i++)
962 struct MainControlInfo *mci = &main_controls[i];
964 if (mci->nr == nr || nr == -1)
966 struct MenuPosInfo *pos_button = mci->pos_button;
967 struct TextPosInfo *pos_text = mci->pos_text;
968 struct TextPosInfo *pos_input = mci->pos_input;
969 char *text = (mci->text ? *mci->text : NULL);
970 char *input = (mci->input ? *mci->input : NULL);
971 int button_graphic = mci->button_graphic;
973 int font_text = (pos_text ? pos_text->font : -1);
974 int font_input = (pos_input ? pos_input->font : -1);
976 int font_text = mci->font_text;
977 int font_input = mci->font_input;
982 button_graphic = BUTTON_ACTIVE(button_graphic);
983 font_text = FONT_ACTIVE(font_text);
988 font_input = FONT_ACTIVE(font_input);
991 if (visibleMenuPos(pos_button))
993 struct MenuPosInfo *pos = pos_button;
994 int x = mSX + pos->x;
995 int y = mSY + pos->y;
997 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
998 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1001 if (visibleTextPos(pos_text) && text != NULL)
1003 struct TextPosInfo *pos = pos_text;
1004 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1005 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1008 /* (check why/if this is needed) */
1009 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1011 DrawText(x, y, text, font_text);
1014 if (visibleTextPos(pos_input) && input != NULL)
1016 struct TextPosInfo *pos = pos_input;
1017 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1018 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1021 /* (check why/if this is needed) */
1022 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1024 DrawText(x, y, input, font_input);
1030 static void DrawCursorAndText_Main(int nr, boolean active_text)
1032 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1036 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1038 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1042 static struct MainControlInfo *getMainControlInfo(int nr)
1046 for (i = 0; main_controls[i].nr != -1; i++)
1047 if (main_controls[i].nr == nr)
1048 return &main_controls[i];
1053 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1058 int rect_x = ALIGNED_TEXT_XPOS(rect);
1059 int rect_y = ALIGNED_TEXT_YPOS(rect);
1061 return (x >= rect_x && x < rect_x + rect->width &&
1062 y >= rect_y && y < rect_y + rect->height);
1065 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1070 int rect_x = ALIGNED_TEXT_XPOS(rect);
1071 int rect_y = ALIGNED_TEXT_YPOS(rect);
1074 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1075 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1076 (x >= rect_x && x < rect_x + rect->width &&
1077 y >= rect_y && y < rect_y + rect->height));
1080 return (x >= rect_x && x < rect_x + rect->width &&
1081 y >= rect_y && y < rect_y + rect->height);
1084 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1087 static int cursor_array[MAX_LEV_FIELDY];
1089 static int cursor_array[SCR_FIELDY];
1091 int x = mSX + TILEX * xpos;
1092 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1097 cursor_array[ypos] = graphic;
1099 graphic = cursor_array[ypos];
1103 graphic = BUTTON_ACTIVE(graphic);
1105 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1106 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1109 static void initCursor(int ypos, int graphic)
1111 drawCursorExt(0, ypos, FALSE, graphic);
1114 static void drawCursor(int ypos, boolean active)
1116 drawCursorExt(0, ypos, active, -1);
1119 static void drawCursorXY(int xpos, int ypos, int graphic)
1121 drawCursorExt(xpos, ypos, FALSE, graphic);
1124 static void drawChooseTreeCursor(int ypos, boolean active)
1126 int last_game_status = game_status; /* save current game status */
1129 /* force LEVELS draw offset on artwork setup screen */
1130 game_status = GAME_MODE_LEVELS;
1133 drawCursorExt(0, ypos, active, -1);
1135 game_status = last_game_status; /* restore current game status */
1140 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1141 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1145 static int getPrevlevelButtonPos()
1150 static int getCurrentLevelTextPos()
1152 return (getPrevlevelButtonPos() + 1);
1155 static int getNextLevelButtonPos()
1157 return getPrevlevelButtonPos() + 3 + 1;
1160 static int getLevelRangeTextPos()
1162 return getNextLevelButtonPos() + 1;
1166 int effectiveGameStatus()
1168 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1169 return GAME_MODE_TITLE;
1174 void DrawTitleScreenImage(int nr, boolean initial)
1176 int graphic = getTitleScreenGraphic(nr, initial);
1177 Bitmap *bitmap = graphic_info[graphic].bitmap;
1178 int width = graphic_info[graphic].width;
1179 int height = graphic_info[graphic].height;
1180 int src_x = graphic_info[graphic].src_x;
1181 int src_y = graphic_info[graphic].src_y;
1187 if (width > WIN_XSIZE)
1189 /* image width too large for window => center image horizontally */
1190 src_x = (width - WIN_XSIZE) / 2;
1194 if (height > WIN_YSIZE)
1196 /* image height too large for window => center image vertically */
1197 src_y = (height - WIN_YSIZE) / 2;
1201 /* always display title screens centered */
1202 dst_x = (WIN_XSIZE - width) / 2;
1203 dst_y = (WIN_YSIZE - height) / 2;
1205 SetDrawBackgroundMask(REDRAW_ALL);
1206 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1208 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1210 if (DrawingOnBackground(dst_x, dst_y))
1212 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1213 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1216 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1218 redraw_mask = REDRAW_ALL;
1221 void DrawTitleScreenMessage(int nr, boolean initial)
1223 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1224 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1225 int last_game_status = game_status; /* save current game status */
1227 if (filename == NULL)
1230 /* force TITLE font on title message screen */
1231 game_status = getTitleMessageGameMode(initial);
1233 /* if chars set to "-1", automatically determine by text and font width */
1234 if (tmi->chars == -1)
1235 tmi->chars = tmi->width / getFontWidth(tmi->font);
1237 tmi->width = tmi->chars * getFontWidth(tmi->font);
1239 /* if lines set to "-1", automatically determine by text and font height */
1240 if (tmi->lines == -1)
1241 tmi->lines = tmi->height / getFontHeight(tmi->font);
1243 tmi->height = tmi->lines * getFontHeight(tmi->font);
1245 SetDrawBackgroundMask(REDRAW_ALL);
1246 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1248 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1250 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1251 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1252 tmi->autowrap, tmi->centered, tmi->parse_comments);
1254 game_status = last_game_status; /* restore current game status */
1257 void DrawTitleScreen()
1259 KeyboardAutoRepeatOff();
1262 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1265 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1270 boolean CheckTitleScreen(boolean levelset_has_changed)
1272 static boolean show_title_initial = TRUE;
1273 boolean show_titlescreen = FALSE;
1275 /* needed to be able to skip title screen, if no image or message defined */
1276 InitializeTitleControls(show_title_initial);
1278 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1279 show_titlescreen = TRUE;
1281 /* show initial title images and messages only once at program start */
1282 show_title_initial = FALSE;
1284 return (show_titlescreen && num_title_screens > 0);
1287 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1289 static LevelDirTree *leveldir_last_valid = NULL;
1290 boolean levelset_has_changed = FALSE;
1292 FadeSetLeaveScreen();
1294 /* do not fade out here -- function may continue and fade on editor screen */
1297 FadeSoundsAndMusic();
1299 KeyboardAutoRepeatOn();
1302 SetDrawDeactivationMask(REDRAW_NONE);
1303 SetDrawBackgroundMask(REDRAW_FIELD);
1305 audio.sound_deactivated = FALSE;
1309 /* needed if last screen was the playing screen, invoked from level editor */
1310 if (level_editor_test_game)
1312 game_status = GAME_MODE_EDITOR;
1318 /* needed if last screen was the setup screen and fullscreen state changed */
1319 ToggleFullscreenIfNeeded();
1321 /* leveldir_current may be invalid (level group, parent link) */
1322 if (!validLevelSeries(leveldir_current))
1323 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1325 if (leveldir_current != leveldir_last_valid)
1326 levelset_has_changed = TRUE;
1328 /* store valid level series information */
1329 leveldir_last_valid = leveldir_current;
1331 init_last = init; /* switch to new busy animation */
1333 /* needed if last screen (level choice) changed graphics, sounds or music */
1334 ReloadCustomArtwork(0);
1336 if (redraw_mask & REDRAW_ALL)
1337 fade_mask = REDRAW_ALL;
1342 /* needed if last screen was the editor screen */
1343 UndrawSpecialEditorDoor();
1345 if (fade_mask == REDRAW_FIELD)
1351 /* needed if different viewport properties defined for menues */
1352 ChangeViewportPropertiesIfNeeded();
1355 #if defined(TARGET_SDL)
1356 SetDrawtoField(DRAW_BACKBUFFER);
1359 if (CheckTitleScreen(levelset_has_changed))
1361 game_status = GAME_MODE_TITLE;
1368 /* level_nr may have been set to value over handicap with level editor */
1369 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1370 level_nr = leveldir_current->handicap_level;
1372 LoadLevel(level_nr);
1373 LoadScore(level_nr);
1375 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1378 if (fade_mask == REDRAW_ALL)
1380 // int door_state = GetDoorState();
1384 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1390 InitializeMainControls();
1392 DrawCursorAndText_Main(-1, FALSE);
1393 DrawPreviewLevel(TRUE);
1395 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1398 if (TAPE_IS_EMPTY(tape))
1400 DrawCompleteVideoDisplay();
1405 /* create gadgets for main menu screen */
1406 FreeScreenGadgets();
1407 CreateScreenGadgets();
1409 /* map gadgets for main menu screen */
1411 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1414 if (fade_mask == REDRAW_ALL)
1416 int door_state = GetDoorState();
1418 // RedrawBackground();
1420 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1424 DrawMaskedBorder(REDRAW_ALL);
1430 /* update screen area with special editor door */
1431 redraw_mask |= REDRAW_ALL;
1435 SetMouseCursor(CURSOR_DEFAULT);
1439 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1442 void DrawAndFadeInMainMenu(int fade_mask)
1444 DrawMainMenuExt(fade_mask, TRUE);
1449 DrawMainMenuExt(REDRAW_ALL, FALSE);
1452 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1453 static void gotoTopLevelDir()
1455 /* move upwards to top level directory */
1456 while (leveldir_current->node_parent)
1458 /* write a "path" into level tree for easy navigation to last level */
1459 if (leveldir_current->node_parent->node_group->cl_first == -1)
1461 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1462 int leveldir_pos = posTreeInfo(leveldir_current);
1463 int num_page_entries;
1464 int cl_first, cl_cursor;
1466 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1467 num_page_entries = num_leveldirs;
1469 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1471 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1472 cl_cursor = leveldir_pos - cl_first;
1474 leveldir_current->node_parent->node_group->cl_first = cl_first;
1475 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1478 leveldir_current = leveldir_current->node_parent;
1483 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1485 static unsigned int title_delay = 0;
1486 static int title_screen_nr = 0;
1487 static int last_sound = -1, last_music = -1;
1488 boolean return_to_main_menu = FALSE;
1489 boolean use_fading_main_menu = TRUE;
1490 struct TitleControlInfo *tci;
1491 struct TitleFadingInfo fading_default;
1492 struct TitleFadingInfo fading_last = fading;
1493 struct TitleFadingInfo fading_next;
1496 if (button == MB_MENU_INITIALIZE)
1499 title_screen_nr = 0;
1500 tci = &title_controls[title_screen_nr];
1502 last_sound = SND_UNDEFINED;
1503 last_music = MUS_UNDEFINED;
1505 if (game_status == GAME_MODE_INFO)
1507 if (num_title_screens == 0)
1509 DrawInfoScreen_NotAvailable("Title screen information:",
1510 "No title screen for this level set.");
1515 FadeSoundsAndMusic();
1518 FadeOut(REDRAW_ALL);
1523 DrawTitleScreenImage(tci->local_nr, tci->initial);
1525 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1527 fading_default = (tci->initial ? title_initial_default : title_default);
1529 fading = fading_next = getTitleFading(tci);
1533 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1534 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1536 fading.fade_mode = FADE_MODE_FADE;
1537 fading.fade_delay = fading_default.fade_delay;
1540 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1541 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1542 fading.fade_mode = FADE_MODE_FADE;
1547 sound = getTitleSound(tci);
1548 music = getTitleMusic(tci);
1550 if (sound != last_sound)
1551 PlayMenuSoundExt(sound);
1552 if (music != last_music)
1553 PlayMenuMusicExt(music);
1559 SetMouseCursor(CURSOR_NONE);
1565 fading = fading_next;
1567 DelayReached(&title_delay, 0); /* reset delay counter */
1573 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1574 button = MB_MENU_CHOICE;
1576 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1577 button = MB_MENU_CHOICE;
1580 if (button == MB_MENU_LEAVE)
1582 return_to_main_menu = TRUE;
1583 use_fading_main_menu = FALSE;
1585 else if (button == MB_MENU_CHOICE)
1587 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1590 FadeOut(REDRAW_FIELD);
1593 FadeSetEnterScreen();
1595 info_mode = INFO_MODE_MAIN;
1596 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1602 tci = &title_controls[title_screen_nr];
1604 if (title_screen_nr < num_title_screens)
1606 sound = getTitleSound(tci);
1607 music = getTitleMusic(tci);
1609 if (sound == SND_UNDEFINED || sound != last_sound)
1611 if (music == MUS_UNDEFINED || music != last_music)
1615 FadeOut(REDRAW_ALL);
1619 DrawTitleScreenImage(tci->local_nr, tci->initial);
1621 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1623 fading_next = getTitleFading(tci);
1626 sound = getTitleSound(tci);
1627 music = getTitleMusic(tci);
1629 if (sound != last_sound)
1630 PlayMenuSoundExt(sound);
1631 if (music != last_music)
1632 PlayMenuMusicExt(music);
1639 /* last screen already faded out, next screen has no animation */
1640 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1641 fading_next.fade_mode == FADE_MODE_NONE)
1642 fading = fading_next;
1644 /* last screen already faded out, next screen has no animation */
1645 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1646 fading_next.fade_mode == FADE_MODE_NONE)
1647 fading = fading_next;
1654 fading = fading_next;
1656 DelayReached(&title_delay, 0); /* reset delay counter */
1660 FadeSoundsAndMusic();
1662 return_to_main_menu = TRUE;
1666 if (return_to_main_menu)
1672 SetMouseCursor(CURSOR_DEFAULT);
1674 if (game_status == GAME_MODE_INFO)
1677 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1680 info_mode = INFO_MODE_MAIN;
1681 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1683 else /* default: return to main menu */
1686 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1689 game_status = GAME_MODE_MAIN;
1690 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1695 void HandleMainMenu_SelectLevel(int step, int direction)
1697 int old_level_nr = level_nr;
1700 new_level_nr = old_level_nr + step * direction;
1701 if (new_level_nr < leveldir_current->first_level)
1702 new_level_nr = leveldir_current->first_level;
1703 if (new_level_nr > leveldir_current->last_level)
1704 new_level_nr = leveldir_current->last_level;
1706 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1708 /* skipping levels is only allowed when trying to skip single level */
1709 if (setup.skip_levels && step == 1 &&
1710 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1712 leveldir_current->handicap_level++;
1713 SaveLevelSetup_SeriesInfo();
1716 new_level_nr = leveldir_current->handicap_level;
1719 if (new_level_nr != old_level_nr)
1721 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1723 PlaySound(SND_MENU_ITEM_SELECTING);
1725 level_nr = new_level_nr;
1727 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1728 int2str(level_nr, menu.main.text.level_number.size),
1729 mci->pos_text->font);
1731 LoadLevel(level_nr);
1732 DrawPreviewLevel(TRUE);
1736 DrawCompleteVideoDisplay();
1738 /* needed because DrawPreviewLevel() takes some time */
1744 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1746 static int choice = MAIN_CONTROL_GAME;
1750 if (button == MB_MENU_INITIALIZE)
1752 DrawCursorAndText_Main(choice, TRUE);
1757 if (mx || my) /* mouse input */
1761 for (i = 0; main_controls[i].nr != -1; i++)
1764 printf("::: check click (%d, %d) for %d [%d] ...\n",
1765 mx - mSX, my - mSY, i, main_controls[i].nr);
1768 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1769 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1770 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1773 printf("::: inside %d\n", i);
1776 pos = main_controls[i].nr;
1782 else if (dx || dy) /* keyboard input */
1784 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1785 choice == MAIN_CONTROL_SETUP))
1786 button = MB_MENU_CHOICE;
1791 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1793 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1795 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1797 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1799 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1801 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1803 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1805 game_status = GAME_MODE_LEVELNR;
1807 DrawChooseLevelNr();
1809 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1815 PlaySound(SND_MENU_ITEM_ACTIVATING);
1817 DrawCursorAndText_Main(choice, FALSE);
1818 DrawCursorAndText_Main(pos, TRUE);
1825 PlaySound(SND_MENU_ITEM_SELECTING);
1827 if (pos == MAIN_CONTROL_NAME)
1829 game_status = GAME_MODE_PSEUDO_TYPENAME;
1831 HandleTypeName(strlen(setup.player_name), 0);
1833 else if (pos == MAIN_CONTROL_LEVELS)
1837 game_status = GAME_MODE_LEVELS;
1839 SaveLevelSetup_LastSeries();
1840 SaveLevelSetup_SeriesInfo();
1842 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1846 DrawChooseLevelSet();
1849 else if (pos == MAIN_CONTROL_SCORES)
1851 game_status = GAME_MODE_SCORES;
1855 else if (pos == MAIN_CONTROL_EDITOR)
1857 if (leveldir_current->readonly &&
1858 !strEqual(setup.player_name, "Artsoft"))
1859 Request("This level is read only !", REQ_CONFIRM);
1861 game_status = GAME_MODE_EDITOR;
1863 FadeSetEnterScreen();
1866 /* needed if different viewport properties defined for editor */
1867 ChangeViewportPropertiesIfNeeded();
1872 else if (pos == MAIN_CONTROL_INFO)
1874 game_status = GAME_MODE_INFO;
1875 info_mode = INFO_MODE_MAIN;
1879 else if (pos == MAIN_CONTROL_GAME)
1881 StartGameActions(options.network, setup.autorecord, level.random_seed);
1883 else if (pos == MAIN_CONTROL_SETUP)
1885 game_status = GAME_MODE_SETUP;
1886 setup_mode = SETUP_MODE_MAIN;
1890 else if (pos == MAIN_CONTROL_QUIT)
1892 SaveLevelSetup_LastSeries();
1893 SaveLevelSetup_SeriesInfo();
1895 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1896 game_status = GAME_MODE_QUIT;
1901 if (game_status == GAME_MODE_MAIN)
1903 DrawPreviewLevel(FALSE);
1909 /* ========================================================================= */
1910 /* info screen functions */
1911 /* ========================================================================= */
1913 static struct TokenInfo *info_info;
1914 static int num_info_info;
1916 static void execInfoTitleScreen()
1918 info_mode = INFO_MODE_TITLE;
1923 static void execInfoElements()
1925 info_mode = INFO_MODE_ELEMENTS;
1930 static void execInfoMusic()
1932 info_mode = INFO_MODE_MUSIC;
1937 static void execInfoCredits()
1939 info_mode = INFO_MODE_CREDITS;
1944 static void execInfoProgram()
1946 info_mode = INFO_MODE_PROGRAM;
1951 static void execInfoVersion()
1953 info_mode = INFO_MODE_VERSION;
1958 static void execInfoLevelSet()
1960 info_mode = INFO_MODE_LEVELSET;
1965 static void execExitInfo()
1967 game_status = GAME_MODE_MAIN;
1969 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1972 static struct TokenInfo info_info_main[] =
1974 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1975 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1976 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1977 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1978 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1979 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1980 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1981 { TYPE_EMPTY, NULL, "" },
1982 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1987 static void DrawCursorAndText_Info(int pos, boolean active)
1989 int xpos = MENU_SCREEN_START_XPOS;
1990 int ypos = MENU_SCREEN_START_YPOS + pos;
1991 int font_nr = FONT_MENU_1;
1994 font_nr = FONT_ACTIVE(font_nr);
1996 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1998 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1999 drawCursor(pos, active);
2002 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2007 CloseDoor(DOOR_CLOSE_2);
2009 /* (needed after displaying title screens which disable auto repeat) */
2010 KeyboardAutoRepeatOn();
2012 FadeSetLeaveScreen();
2019 if (fade_mask == REDRAW_ALL)
2023 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2029 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2031 info_info = info_info_main;
2035 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2037 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2040 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2041 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2042 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2043 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2044 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2045 initCursor(i, IMG_MENU_BUTTON);
2047 DrawCursorAndText_Info(i, FALSE);
2052 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2057 DrawMaskedBorder(fade_mask);
2064 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2066 static int choice_store[MAX_INFO_MODES];
2067 int choice = choice_store[info_mode]; /* always starts with 0 */
2071 if (button == MB_MENU_INITIALIZE)
2073 /* advance to first valid menu entry */
2074 while (choice < num_info_info &&
2075 info_info[choice].type & TYPE_SKIP_ENTRY)
2077 choice_store[info_mode] = choice;
2079 DrawCursorAndText_Info(choice, TRUE);
2083 else if (button == MB_MENU_LEAVE)
2085 for (y = 0; y < num_info_info; y++)
2087 if (info_info[y].type & TYPE_LEAVE_MENU)
2089 void (*menu_callback_function)(void) = info_info[y].value;
2093 menu_callback_function();
2095 break; /* absolutely needed because function changes 'info_info'! */
2102 if (mx || my) /* mouse input */
2104 x = (mx - mSX) / 32;
2105 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2107 else if (dx || dy) /* keyboard input */
2111 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2113 if (info_info[choice].type & menu_navigation_type ||
2114 info_info[choice].type & TYPE_ENTER_SCREEN ||
2115 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2116 info_info[choice].type & TYPE_YES_NO_AUTO)
2117 button = MB_MENU_CHOICE;
2122 /* jump to next non-empty menu entry (up or down) */
2123 while (y > 0 && y < num_info_info - 1 &&
2124 info_info[y].type & TYPE_SKIP_ENTRY)
2128 if (IN_VIS_FIELD(x, y) &&
2129 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2135 PlaySound(SND_MENU_ITEM_ACTIVATING);
2137 DrawCursorAndText_Info(choice, FALSE);
2138 DrawCursorAndText_Info(y, TRUE);
2140 choice = choice_store[info_mode] = y;
2143 else if (!(info_info[y].type & TYPE_GHOSTED))
2145 PlaySound(SND_MENU_ITEM_SELECTING);
2147 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2149 void (*menu_callback_function)(void) = info_info[choice].value;
2151 FadeSetFromType(info_info[y].type);
2153 menu_callback_function();
2159 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2161 int ystart1 = mSY - SY + 100;
2162 int ystart2 = mSY - SY + 150;
2163 int ybottom = mSY - SY + SYSIZE - 20;
2165 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2167 FadeOut(REDRAW_FIELD);
2172 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2173 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2175 DrawTextSCentered(ybottom, FONT_TEXT_4,
2176 "Press any key or button for info menu");
2178 FadeIn(REDRAW_FIELD);
2181 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2183 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2184 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2185 int xstart = mSX + 16;
2186 int ystart1 = mSY - SY + 100;
2187 int ystart2 = mSY + 64 + 2 * 32;
2188 int ybottom = mSY - SY + SYSIZE - 20;
2189 int ystep = TILEY + 4;
2190 int element, action, direction;
2198 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2199 infoscreen_step[i] = infoscreen_frame[i] = 0;
2204 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2206 DrawTextSCentered(ybottom, FONT_TEXT_4,
2207 "Press any key or button for next page");
2213 while (helpanim_info[j].element != HELPANIM_LIST_END)
2215 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2220 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2229 j += infoscreen_step[i - start];
2231 element = helpanim_info[j].element;
2232 action = helpanim_info[j].action;
2233 direction = helpanim_info[j].direction;
2236 element = EL_UNKNOWN;
2238 if (action != -1 && direction != -1)
2239 graphic = el_act_dir2img(element, action, direction);
2240 else if (action != -1)
2241 graphic = el_act2img(element, action);
2242 else if (direction != -1)
2243 graphic = el_dir2img(element, direction);
2245 graphic = el2img(element);
2247 delay = helpanim_info[j++].delay;
2252 if (infoscreen_frame[i - start] == 0)
2255 infoscreen_frame[i - start] = delay - 1;
2259 sync_frame = delay - infoscreen_frame[i - start];
2260 infoscreen_frame[i - start]--;
2263 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2265 if (!infoscreen_frame[i - start])
2266 infoscreen_step[i - start] = 0;
2270 if (!infoscreen_frame[i - start])
2271 infoscreen_step[i - start]++;
2272 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2278 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2280 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2281 graphic, sync_frame, USE_MASKING);
2284 DrawInfoScreen_HelpText(element, action, direction, i - start);
2289 redraw_mask |= REDRAW_FIELD;
2294 static char *getHelpText(int element, int action, int direction)
2296 char token[MAX_LINE_LEN];
2298 strcpy(token, element_info[element].token_name);
2301 strcat(token, element_action_info[action].suffix);
2303 if (direction != -1)
2304 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2306 return getHashEntry(helptext_info, token);
2309 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2311 int font_nr = FONT_INFO_ELEMENTS;
2312 int font_width = getFontWidth(font_nr);
2313 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2314 int sy = mSY + 65 + 2 * 32 + 1;
2315 int ystep = TILEY + 4;
2316 int pad_x = sx - SX;
2317 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2318 int max_lines_per_text = 2;
2321 if (action != -1 && direction != -1) /* element.action.direction */
2322 text = getHelpText(element, action, direction);
2324 if (text == NULL && action != -1) /* element.action */
2325 text = getHelpText(element, action, -1);
2327 if (text == NULL && direction != -1) /* element.direction */
2328 text = getHelpText(element, -1, direction);
2330 if (text == NULL) /* base element */
2331 text = getHelpText(element, -1, -1);
2333 if (text == NULL) /* not found */
2334 text = "No description available";
2336 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2337 sy += getFontHeight(font_nr) / 2;
2339 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2340 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2341 TRUE, FALSE, FALSE);
2344 void DrawInfoScreen_TitleScreen()
2349 void HandleInfoScreen_TitleScreen(int button)
2351 HandleTitleScreen(0, 0, 0, 0, button);
2354 void DrawInfoScreen_Elements()
2356 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2358 FadeOut(REDRAW_FIELD);
2363 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2365 FadeIn(REDRAW_FIELD);
2370 void HandleInfoScreen_Elements(int button)
2372 static unsigned int info_delay = 0;
2373 static int num_anims;
2374 static int num_pages;
2376 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2379 if (button == MB_MENU_INITIALIZE)
2381 boolean new_element = TRUE;
2385 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2387 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2389 else if (new_element)
2392 new_element = FALSE;
2396 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2400 if (button == MB_MENU_LEAVE)
2402 PlaySound(SND_MENU_ITEM_SELECTING);
2404 info_mode = INFO_MODE_MAIN;
2409 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2411 if (button != MB_MENU_INITIALIZE)
2413 PlaySound(SND_MENU_ITEM_SELECTING);
2418 if (page >= num_pages)
2420 FadeSoundsAndMusic();
2422 info_mode = INFO_MODE_MAIN;
2423 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2430 FadeSetNextScreen();
2433 if (button != MB_MENU_INITIALIZE)
2434 FadeOut(REDRAW_FIELD);
2436 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2438 if (button != MB_MENU_INITIALIZE)
2439 FadeIn(REDRAW_FIELD);
2443 if (DelayReached(&info_delay, GameFrameDelay))
2444 if (page < num_pages)
2445 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2447 PlayMenuSoundIfLoop();
2451 void DrawInfoScreen_Music()
2453 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2456 FadeOut(REDRAW_FIELD);
2464 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2467 FadeIn(REDRAW_FIELD);
2471 void HandleInfoScreen_Music(int button)
2473 static struct MusicFileInfo *list = NULL;
2474 int ystart1 = mSY - SY + 100;
2475 int ystart2 = mSY - SY + 150;
2476 int ybottom = mSY - SY + SYSIZE - 20;
2479 if (button == MB_MENU_INITIALIZE)
2481 list = music_file_info;
2485 FadeSoundsAndMusic();
2490 DrawTextSCentered(ystart1, FONT_TEXT_1,
2491 "No music info for this level set.");
2493 DrawTextSCentered(ybottom, FONT_TEXT_4,
2494 "Press any key or button for info menu");
2500 if (button == MB_MENU_LEAVE)
2502 PlaySound(SND_MENU_ITEM_SELECTING);
2504 FadeSoundsAndMusic();
2506 info_mode = INFO_MODE_MAIN;
2511 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2515 if (button != MB_MENU_INITIALIZE)
2517 PlaySound(SND_MENU_ITEM_SELECTING);
2525 FadeSoundsAndMusic();
2527 info_mode = INFO_MODE_MAIN;
2528 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2533 FadeSoundsAndMusic();
2536 if (list != music_file_info)
2537 FadeSetNextScreen();
2540 if (button != MB_MENU_INITIALIZE)
2541 FadeOut(REDRAW_FIELD);
2548 int sound = list->music;
2550 if (sound_info[sound].loop)
2551 PlaySoundLoop(sound);
2555 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2559 PlayMusic(list->music);
2561 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2564 if (!strEqual(list->title, UNKNOWN_NAME))
2566 if (!strEqual(list->title_header, UNKNOWN_NAME))
2567 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2569 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2572 if (!strEqual(list->artist, UNKNOWN_NAME))
2574 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2575 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2577 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2579 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2582 if (!strEqual(list->album, UNKNOWN_NAME))
2584 if (!strEqual(list->album_header, UNKNOWN_NAME))
2585 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2587 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2589 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2592 if (!strEqual(list->year, UNKNOWN_NAME))
2594 if (!strEqual(list->year_header, UNKNOWN_NAME))
2595 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2597 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2599 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2602 DrawTextSCentered(ybottom, FONT_TEXT_4,
2603 "Press any key or button for next page");
2605 if (button != MB_MENU_INITIALIZE)
2606 FadeIn(REDRAW_FIELD);
2609 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2610 PlaySoundLoop(list->music);
2613 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2615 int ystart1 = mSY - SY + 100;
2616 int ystart2 = mSY - SY + 150;
2617 int ybottom = mSY - SY + SYSIZE - 20;
2623 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2627 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2628 "Special thanks to");
2629 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2631 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2633 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2634 "\"Boulder Dash\"");
2635 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2637 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2639 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2641 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2642 "First Star Software");
2644 else if (screen_nr == 1)
2646 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2647 "Special thanks to");
2648 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2649 "Klaus Heinz & Volker Wertich");
2650 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2652 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2653 "\"Emerald Mine\"");
2654 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2656 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2658 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2660 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2663 else if (screen_nr == 2)
2665 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2666 "Special thanks to");
2667 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2668 "Michael Stopp & Philip Jespersen");
2669 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2671 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2673 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2675 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2677 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2679 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2680 "Digital Integration");
2682 else if (screen_nr == 3)
2684 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2685 "Special thanks to");
2686 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2687 "Hiroyuki Imabayashi");
2688 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2690 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2692 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2694 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2696 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2698 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2701 else if (screen_nr == 4)
2703 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2704 "Special thanks to");
2705 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2707 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2709 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2710 "Jürgen Bonhagen");
2711 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2712 "for the continuous creation");
2713 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2714 "of outstanding level sets");
2716 else if (screen_nr == 5)
2718 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2720 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2722 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2723 "for ideas and inspiration by");
2724 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2727 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2729 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2731 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2732 "for ideas and inspiration by");
2733 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2736 else if (screen_nr == 6)
2738 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2740 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2743 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2744 "for the code base used for the");
2745 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2746 "native Emerald Mine engine");
2748 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2749 "for the new Emerald Mine engine");
2752 else if (screen_nr == 7)
2754 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2756 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2758 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2759 "for the initial DOS port");
2761 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2763 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2765 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2766 "for some additional toons");
2768 else if (screen_nr == 8)
2770 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2771 "And not to forget:");
2772 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2774 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2775 "All those who contributed");
2776 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2777 "levels to this game");
2778 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2782 DrawTextSCentered(ybottom, FONT_TEXT_4,
2783 "Press any key or button for next page");
2786 void DrawInfoScreen_Credits()
2788 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2790 FadeSoundsAndMusic();
2793 FadeOut(REDRAW_FIELD);
2796 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2799 FadeIn(REDRAW_FIELD);
2803 void HandleInfoScreen_Credits(int button)
2805 static int screen_nr = 0;
2806 int num_screens = 9;
2808 if (button == MB_MENU_INITIALIZE)
2812 // DrawInfoScreen_CreditsScreen(screen_nr);
2815 if (button == MB_MENU_LEAVE)
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2819 info_mode = INFO_MODE_MAIN;
2824 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2826 if (button != MB_MENU_INITIALIZE)
2828 PlaySound(SND_MENU_ITEM_SELECTING);
2833 if (screen_nr >= num_screens)
2835 FadeSoundsAndMusic();
2837 info_mode = INFO_MODE_MAIN;
2838 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2845 FadeSetNextScreen();
2848 if (button != MB_MENU_INITIALIZE)
2849 FadeOut(REDRAW_FIELD);
2851 DrawInfoScreen_CreditsScreen(screen_nr);
2853 if (button != MB_MENU_INITIALIZE)
2854 FadeIn(REDRAW_FIELD);
2858 PlayMenuSoundIfLoop();
2862 void DrawInfoScreen_Program()
2864 int ystart1 = mSY - SY + 100;
2865 int ystart2 = mSY - SY + 150;
2866 int ybottom = mSY - SY + SYSIZE - 20;
2869 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2872 FadeOut(REDRAW_FIELD);
2878 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2880 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2881 "This game is Freeware!");
2882 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2883 "If you like it, send e-mail to:");
2884 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2885 PROGRAM_EMAIL_STRING);
2886 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2887 "or SnailMail to:");
2888 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2890 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2891 "Detmolder Strasse 189");
2892 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2894 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2896 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2897 "More information and levels:");
2898 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2899 PROGRAM_WEBSITE_STRING);
2900 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2901 "If you have created new levels,");
2902 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2903 "send them to me to include them!");
2904 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2907 DrawTextSCentered(ybottom, FONT_TEXT_4,
2908 "Press any key or button for info menu");
2911 FadeIn(REDRAW_FIELD);
2915 void HandleInfoScreen_Program(int button)
2917 if (button == MB_MENU_LEAVE)
2919 PlaySound(SND_MENU_ITEM_SELECTING);
2921 info_mode = INFO_MODE_MAIN;
2926 else if (button == MB_MENU_CHOICE)
2928 PlaySound(SND_MENU_ITEM_SELECTING);
2930 FadeSoundsAndMusic();
2933 FadeOut(REDRAW_FIELD);
2936 info_mode = INFO_MODE_MAIN;
2937 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2941 PlayMenuSoundIfLoop();
2945 void DrawInfoScreen_Version()
2947 int font_header = FONT_TEXT_3;
2948 int font_text = FONT_TEXT_2;
2949 int xstep = getFontWidth(font_text);
2950 int ystep = getFontHeight(font_text);
2951 int ystart1 = mSY - SY + 100;
2952 int ystart2 = mSY - SY + 150;
2953 int ybottom = mSY - SY + SYSIZE - 20;
2954 int xstart1 = mSX + 2 * xstep;
2955 int xstart2 = mSX + 19 * xstep;
2956 #if defined(TARGET_SDL)
2957 int xstart3 = mSX + 29 * xstep;
2958 SDL_version sdl_version_compiled;
2959 const SDL_version *sdl_version_linked;
2960 int driver_name_len = 8;
2961 char driver_name[driver_name_len];
2964 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2967 FadeOut(REDRAW_FIELD);
2973 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2975 DrawTextF(xstart1, ystart2, font_header, "Name");
2976 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2979 DrawTextF(xstart1, ystart2, font_header, "Version");
2980 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2983 DrawTextF(xstart1, ystart2, font_header, "Platform");
2984 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2987 DrawTextF(xstart1, ystart2, font_header, "Target");
2988 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2991 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2992 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2994 #if defined(TARGET_SDL)
2995 ystart2 += 3 * ystep;
2996 DrawTextF(xstart1, ystart2, font_header, "Library");
2997 DrawTextF(xstart2, ystart2, font_header, "compiled");
2998 DrawTextF(xstart3, ystart2, font_header, "linked");
3000 SDL_VERSION(&sdl_version_compiled);
3001 sdl_version_linked = SDL_Linked_Version();
3003 ystart2 += 2 * ystep;
3004 DrawTextF(xstart1, ystart2, font_text, "SDL");
3005 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3006 sdl_version_compiled.major,
3007 sdl_version_compiled.minor,
3008 sdl_version_compiled.patch);
3009 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3010 sdl_version_linked->major,
3011 sdl_version_linked->minor,
3012 sdl_version_linked->patch);
3014 SDL_IMAGE_VERSION(&sdl_version_compiled);
3015 sdl_version_linked = IMG_Linked_Version();
3018 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3019 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3020 sdl_version_compiled.major,
3021 sdl_version_compiled.minor,
3022 sdl_version_compiled.patch);
3023 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3024 sdl_version_linked->major,
3025 sdl_version_linked->minor,
3026 sdl_version_linked->patch);
3028 SDL_MIXER_VERSION(&sdl_version_compiled);
3029 sdl_version_linked = Mix_Linked_Version();
3032 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3033 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3034 sdl_version_compiled.major,
3035 sdl_version_compiled.minor,
3036 sdl_version_compiled.patch);
3037 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3038 sdl_version_linked->major,
3039 sdl_version_linked->minor,
3040 sdl_version_linked->patch);
3042 SDL_NET_VERSION(&sdl_version_compiled);
3043 sdl_version_linked = SDLNet_Linked_Version();
3046 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3047 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3048 sdl_version_compiled.major,
3049 sdl_version_compiled.minor,
3050 sdl_version_compiled.patch);
3051 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3052 sdl_version_linked->major,
3053 sdl_version_linked->minor,
3054 sdl_version_linked->patch);
3056 ystart2 += 3 * ystep;
3057 DrawTextF(xstart1, ystart2, font_header, "Driver");
3058 DrawTextF(xstart2, ystart2, font_header, "Requested");
3059 DrawTextF(xstart3, ystart2, font_header, "Used");
3061 SDL_VideoDriverName(driver_name, driver_name_len);
3063 ystart2 += 2 * ystep;
3064 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3065 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3066 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3068 SDL_AudioDriverName(driver_name, driver_name_len);
3071 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3072 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3073 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3076 DrawTextSCentered(ybottom, FONT_TEXT_4,
3077 "Press any key or button for info menu");
3080 FadeIn(REDRAW_FIELD);
3084 void HandleInfoScreen_Version(int button)
3086 if (button == MB_MENU_LEAVE)
3088 PlaySound(SND_MENU_ITEM_SELECTING);
3090 info_mode = INFO_MODE_MAIN;
3095 else if (button == MB_MENU_CHOICE)
3097 PlaySound(SND_MENU_ITEM_SELECTING);
3099 FadeSoundsAndMusic();
3102 FadeOut(REDRAW_FIELD);
3105 info_mode = INFO_MODE_MAIN;
3106 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3110 PlayMenuSoundIfLoop();
3114 void DrawInfoScreen_LevelSet()
3116 struct TitleMessageInfo *tmi = &readme;
3117 char *filename = getLevelSetInfoFilename();
3119 /* if chars set to "-1", automatically determine by text and font width */
3120 if (tmi->chars == -1)
3121 tmi->chars = tmi->width / getFontWidth(tmi->font);
3123 tmi->width = tmi->chars * getFontWidth(tmi->font);
3125 /* if lines set to "-1", automatically determine by text and font height */
3126 if (tmi->lines == -1)
3127 tmi->lines = tmi->height / getFontHeight(tmi->font);
3129 tmi->height = tmi->lines * getFontHeight(tmi->font);
3131 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3134 FadeOut(REDRAW_FIELD);
3140 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3142 if (filename != NULL)
3143 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3144 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3145 tmi->autowrap, tmi->centered, tmi->parse_comments);
3147 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3148 "No information for this level set.");
3150 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3151 "Press any key or button for info menu");
3154 FadeIn(REDRAW_FIELD);
3158 void HandleInfoScreen_LevelSet(int button)
3160 if (button == MB_MENU_LEAVE)
3162 PlaySound(SND_MENU_ITEM_SELECTING);
3164 info_mode = INFO_MODE_MAIN;
3169 else if (button == MB_MENU_CHOICE)
3171 PlaySound(SND_MENU_ITEM_SELECTING);
3173 FadeSoundsAndMusic();
3176 FadeOut(REDRAW_FIELD);
3179 info_mode = INFO_MODE_MAIN;
3180 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3184 PlayMenuSoundIfLoop();
3188 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3190 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3192 if (info_mode == INFO_MODE_TITLE)
3193 DrawInfoScreen_TitleScreen();
3194 else if (info_mode == INFO_MODE_ELEMENTS)
3195 DrawInfoScreen_Elements();
3196 else if (info_mode == INFO_MODE_MUSIC)
3197 DrawInfoScreen_Music();
3198 else if (info_mode == INFO_MODE_CREDITS)
3199 DrawInfoScreen_Credits();
3200 else if (info_mode == INFO_MODE_PROGRAM)
3201 DrawInfoScreen_Program();
3202 else if (info_mode == INFO_MODE_VERSION)
3203 DrawInfoScreen_Version();
3204 else if (info_mode == INFO_MODE_LEVELSET)
3205 DrawInfoScreen_LevelSet();
3207 DrawInfoScreen_Main(fade_mask, do_fading);
3209 if (info_mode != INFO_MODE_MAIN &&
3210 info_mode != INFO_MODE_TITLE &&
3211 info_mode != INFO_MODE_MUSIC)
3218 void DrawAndFadeInInfoScreen(int fade_mask)
3220 DrawInfoScreenExt(fade_mask, TRUE);
3223 void DrawInfoScreen()
3225 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3228 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3230 if (info_mode == INFO_MODE_TITLE)
3231 HandleInfoScreen_TitleScreen(button);
3232 else if (info_mode == INFO_MODE_ELEMENTS)
3233 HandleInfoScreen_Elements(button);
3234 else if (info_mode == INFO_MODE_MUSIC)
3235 HandleInfoScreen_Music(button);
3236 else if (info_mode == INFO_MODE_CREDITS)
3237 HandleInfoScreen_Credits(button);
3238 else if (info_mode == INFO_MODE_PROGRAM)
3239 HandleInfoScreen_Program(button);
3240 else if (info_mode == INFO_MODE_VERSION)
3241 HandleInfoScreen_Version(button);
3242 else if (info_mode == INFO_MODE_LEVELSET)
3243 HandleInfoScreen_LevelSet(button);
3245 HandleInfoScreen_Main(mx, my, dx, dy, button);
3251 /* ========================================================================= */
3252 /* type name functions */
3253 /* ========================================================================= */
3255 void HandleTypeName(int newxpos, Key key)
3257 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3258 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3259 struct TextPosInfo *pos = mci->pos_input;
3260 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3261 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3262 static int xpos = 0;
3263 int font_nr = pos->font;
3264 int font_active_nr = FONT_ACTIVE(font_nr);
3265 int font_width = getFontWidth(font_active_nr);
3266 char key_char = getValidConfigValueChar(getCharFromKey(key));
3267 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3268 boolean is_active = TRUE;
3270 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3274 strcpy(last_player_name, setup.player_name);
3278 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3280 setup.player_name[xpos] = key_char;
3281 setup.player_name[xpos + 1] = 0;
3285 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3289 setup.player_name[xpos] = 0;
3291 else if (key == KSYM_Return && xpos > 0)
3297 game_status = GAME_MODE_MAIN;
3299 else if (key == KSYM_Escape)
3301 strcpy(setup.player_name, last_player_name);
3305 game_status = GAME_MODE_MAIN;
3310 pos->width = (strlen(setup.player_name) + 1) * font_width;
3311 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3313 DrawText(startx, starty, setup.player_name, font_active_nr);
3314 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3318 pos->width = strlen(setup.player_name) * font_width;
3319 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3321 DrawText(startx, starty, setup.player_name, font_nr);
3326 /* ========================================================================= */
3327 /* tree menu functions */
3328 /* ========================================================================= */
3330 static void DrawChooseTree(TreeInfo **ti_ptr)
3334 FreeScreenGadgets();
3335 CreateScreenGadgets();
3337 CloseDoor(DOOR_CLOSE_2);
3340 FadeOut(REDRAW_FIELD);
3345 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3346 MapScreenTreeGadgets(*ti_ptr);
3349 FadeIn(REDRAW_FIELD);
3355 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3357 struct GadgetInfo *gi = screen_gadget[id];
3358 int items_max, items_visible, item_position;
3360 items_max = numTreeInfoInGroup(ti);
3361 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3362 item_position = first_entry;
3364 if (item_position > items_max - items_visible)
3365 item_position = items_max - items_visible;
3367 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3368 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3369 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3372 static void drawChooseTreeList(int first_entry, int num_page_entries,
3376 char *title_string = NULL;
3377 int yoffset_sets = MENU_TITLE1_YPOS;
3378 int yoffset_setup = 16;
3379 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3380 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3381 int last_game_status = game_status; /* save current game status */
3383 title_string = ti->infotext;
3385 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3388 /* force LEVELS font on artwork setup screen */
3389 game_status = GAME_MODE_LEVELS;
3393 /* clear tree list area, but not title or scrollbar */
3394 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3395 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3396 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3398 /* clear tree list area, but not title or scrollbar */
3399 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3400 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3401 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3404 for (i = 0; i < num_page_entries; i++)
3406 TreeInfo *node, *node_first;
3407 int entry_pos = first_entry + i;
3408 int xpos = MENU_SCREEN_START_XPOS;
3409 int ypos = MENU_SCREEN_START_YPOS + i;
3410 int startx = mSX + xpos * 32;
3411 int starty = mSY + ypos * 32;
3412 int font_nr = FONT_TEXT_1;
3413 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3414 int startx_text = startx + font_xoffset;
3415 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3416 int text_size = startx_scrollbar - startx_text;
3417 int max_buffer_len = text_size / getFontWidth(font_nr);
3418 char buffer[max_buffer_len + 1];
3420 node_first = getTreeInfoFirstGroupEntry(ti);
3421 node = getTreeInfoFromPos(node_first, entry_pos);
3423 strncpy(buffer, node->name, max_buffer_len);
3424 buffer[max_buffer_len] = '\0';
3426 DrawText(startx, starty, buffer, font_nr + node->color);
3428 if (node->parent_link)
3429 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3430 else if (node->level_group)
3431 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3433 initCursor(i, IMG_MENU_BUTTON);
3436 game_status = last_game_status; /* restore current game status */
3438 redraw_mask |= REDRAW_FIELD;
3441 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3443 TreeInfo *node, *node_first;
3444 int x, last_redraw_mask = redraw_mask;
3445 int ypos = MENU_TITLE2_YPOS;
3446 int font_nr = FONT_TITLE_2;
3448 if (ti->type == TREE_TYPE_LEVEL_NR)
3449 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3451 if (ti->type != TREE_TYPE_LEVEL_DIR)
3454 node_first = getTreeInfoFirstGroupEntry(ti);
3455 node = getTreeInfoFromPos(node_first, entry_pos);
3457 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3460 if (node->parent_link)
3461 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3462 node->node_parent->name);
3463 else if (node->level_group)
3464 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3466 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3467 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3468 node->levels, (node->levels > 1 ? "levels" : "level"),
3471 if (node->parent_link)
3472 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3474 else if (node->level_group)
3475 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3477 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3478 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3479 node->levels, node->class_desc);
3482 /* let BackToFront() redraw only what is needed */
3483 redraw_mask = last_redraw_mask | REDRAW_TILES;
3484 for (x = 0; x < SCR_FIELDX; x++)
3485 MarkTileDirty(x, 1);
3488 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3491 TreeInfo *ti = *ti_ptr;
3493 int y = ti->cl_cursor;
3494 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3495 int num_entries = numTreeInfoInGroup(ti);
3496 int num_page_entries;
3497 int last_game_status = game_status; /* save current game status */
3498 boolean position_set_by_scrollbar = (dx == 999);
3501 /* force LEVELS draw offset on choose level and artwork setup screen */
3502 game_status = GAME_MODE_LEVELS;
3505 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3506 num_page_entries = num_entries;
3508 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3510 game_status = last_game_status; /* restore current game status */
3512 if (button == MB_MENU_INITIALIZE)
3514 int num_entries = numTreeInfoInGroup(ti);
3515 int entry_pos = posTreeInfo(ti);
3517 if (ti->cl_first == -1)
3519 /* only on initialization */
3520 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3521 ti->cl_cursor = entry_pos - ti->cl_first;
3523 else if (ti->cl_cursor >= num_page_entries ||
3524 (num_entries > num_page_entries &&
3525 num_entries - ti->cl_first < num_page_entries))
3527 /* only after change of list size (by custom graphic configuration) */
3528 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3529 ti->cl_cursor = entry_pos - ti->cl_first;
3532 if (position_set_by_scrollbar)
3535 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3538 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3539 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3540 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3544 else if (button == MB_MENU_LEAVE)
3548 PlaySound(SND_MENU_ITEM_SELECTING);
3550 if (ti->node_parent)
3552 *ti_ptr = ti->node_parent;
3553 DrawChooseTree(ti_ptr);
3555 else if (game_status == GAME_MODE_SETUP)
3557 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3559 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3560 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3561 execSetupGraphics();
3562 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3563 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3564 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3571 if (game_status == GAME_MODE_LEVELNR)
3572 level_nr = atoi(level_number_current->identifier);
3574 game_status = GAME_MODE_MAIN;
3576 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3582 if (mx || my) /* mouse input */
3584 int last_game_status = game_status; /* save current game status */
3587 /* force LEVELS draw offset on artwork setup screen */
3588 game_status = GAME_MODE_LEVELS;
3591 x = (mx - mSX) / 32;
3592 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3594 game_status = last_game_status; /* restore current game status */
3596 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3598 /* move cursor instead of scrolling when already at start/end of list */
3599 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3601 else if (dy == +1 * SCROLL_LINE &&
3602 ti->cl_first + num_page_entries == num_entries)
3605 /* handle scrolling screen one line or page */
3606 if (ti->cl_cursor + dy < 0 ||
3607 ti->cl_cursor + dy > num_page_entries - 1)
3609 if (ABS(dy) == SCROLL_PAGE)
3610 step = num_page_entries - 1;
3612 if (dy < 0 && ti->cl_first > 0)
3614 /* scroll page/line up */
3616 ti->cl_first -= step;
3617 if (ti->cl_first < 0)
3620 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3621 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3622 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3624 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3627 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3629 /* scroll page/line down */
3631 ti->cl_first += step;
3632 if (ti->cl_first + num_page_entries > num_entries)
3633 ti->cl_first = MAX(0, num_entries - num_page_entries);
3635 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3636 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3637 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3639 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3646 /* handle moving cursor one line */
3647 y = ti->cl_cursor + dy;
3652 TreeInfo *node_first, *node_cursor;
3653 int entry_pos = ti->cl_first + y;
3655 node_first = getTreeInfoFirstGroupEntry(ti);
3656 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3658 if (node_cursor->node_group)
3662 PlaySound(SND_MENU_ITEM_SELECTING);
3664 node_cursor->cl_first = ti->cl_first;
3665 node_cursor->cl_cursor = ti->cl_cursor;
3666 *ti_ptr = node_cursor->node_group;
3667 DrawChooseTree(ti_ptr);
3672 else if (dx == -1 && ti->node_parent)
3676 PlaySound(SND_MENU_ITEM_SELECTING);
3678 *ti_ptr = ti->node_parent;
3679 DrawChooseTree(ti_ptr);
3684 if (!anyScrollbarGadgetActive() &&
3685 IN_VIS_FIELD(x, y) &&
3686 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3687 y >= 0 && y < num_page_entries)
3691 if (y != ti->cl_cursor)
3693 PlaySound(SND_MENU_ITEM_ACTIVATING);
3695 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3696 drawChooseTreeCursor(y, TRUE);
3697 drawChooseTreeInfo(ti->cl_first + y, ti);
3704 TreeInfo *node_first, *node_cursor;
3705 int entry_pos = ti->cl_first + y;
3707 PlaySound(SND_MENU_ITEM_SELECTING);
3709 node_first = getTreeInfoFirstGroupEntry(ti);
3710 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3712 if (node_cursor->node_group)
3716 node_cursor->cl_first = ti->cl_first;
3717 node_cursor->cl_cursor = ti->cl_cursor;
3718 *ti_ptr = node_cursor->node_group;
3719 DrawChooseTree(ti_ptr);
3721 else if (node_cursor->parent_link)
3725 *ti_ptr = node_cursor->node_parent;
3726 DrawChooseTree(ti_ptr);
3730 FadeSetEnterScreen();
3732 node_cursor->cl_first = ti->cl_first;
3733 node_cursor->cl_cursor = ti->cl_cursor;
3734 *ti_ptr = node_cursor;
3736 if (ti->type == TREE_TYPE_LEVEL_DIR)
3738 LoadLevelSetup_SeriesInfo();
3740 SaveLevelSetup_LastSeries();
3741 SaveLevelSetup_SeriesInfo();
3745 if (game_status == GAME_MODE_SETUP)
3747 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3749 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3750 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3751 execSetupGraphics();
3752 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3753 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3754 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3761 if (game_status == GAME_MODE_LEVELNR)
3762 level_nr = atoi(level_number_current->identifier);
3764 game_status = GAME_MODE_MAIN;
3773 void DrawChooseLevelSet()
3775 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3777 DrawChooseTree(&leveldir_current);
3783 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3785 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3790 void DrawChooseLevelNr()
3794 if (level_number != NULL)
3796 freeTreeInfo(level_number);
3798 level_number = NULL;
3801 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3803 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3804 char identifier[32], name[32];
3807 /* temporarily load level info to get level name */
3808 LoadLevelInfoOnly(i);
3810 ti->node_top = &level_number;
3811 ti->sort_priority = 10000 + value;
3812 ti->color = (level.no_valid_file ? FC_BLUE :
3813 LevelStats_getSolved(i) ? FC_GREEN :
3814 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3816 sprintf(identifier, "%d", value);
3817 sprintf(name, "%03d: %s", value,
3818 (level.no_valid_file ? "(no file)" : level.name));
3820 setString(&ti->identifier, identifier);
3821 setString(&ti->name, name);
3822 setString(&ti->name_sorting, name);
3824 pushTreeInfo(&level_number, ti);
3827 /* sort level number values to start with lowest level number */
3828 sortTreeInfo(&level_number);
3830 /* set current level number to current level number */
3831 level_number_current =
3832 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3834 /* if that also fails, set current level number to first available level */
3835 if (level_number_current == NULL)
3836 level_number_current = level_number;
3838 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3841 DrawChooseTree(&level_number_current);
3843 DrawChooseTree(&leveldir_current);
3850 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3853 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3855 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3861 void DrawHallOfFame(int highlight_position)
3864 FadeSoundsAndMusic();
3866 /* (this is needed when called from GameEnd() after winning a game) */
3867 KeyboardAutoRepeatOn();
3870 /* (this is needed when called from GameEnd() after winning a game) */
3871 SetDrawDeactivationMask(REDRAW_NONE);
3872 SetDrawBackgroundMask(REDRAW_FIELD);
3874 CloseDoor(DOOR_CLOSE_2);
3876 if (highlight_position < 0)
3877 LoadScore(level_nr);
3879 FadeSetEnterScreen();
3881 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3884 FadeOut(REDRAW_FIELD);
3892 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3895 FadeIn(REDRAW_FIELD);
3899 static void drawHallOfFameList(int first_entry, int highlight_position)
3903 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3906 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3907 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3908 "HighScores of Level %d", level_nr);
3910 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3912 int entry = first_entry + i;
3913 boolean active = (entry == highlight_position);
3914 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3915 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3916 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3917 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3918 int dx1 = 3 * getFontWidth(font_nr1);
3919 int dx2 = dx1 + getFontWidth(font_nr1);
3920 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3921 int sy = mSY + 64 + i * 32;
3923 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3924 DrawText(mSX + dx1, sy, ".", font_nr1);
3925 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3927 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3928 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3930 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3933 redraw_mask |= REDRAW_FIELD;
3936 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3938 static int first_entry = 0;
3939 static int highlight_position = 0;
3940 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3942 if (button == MB_MENU_INITIALIZE)
3945 highlight_position = mx;
3946 drawHallOfFameList(first_entry, highlight_position);
3951 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3952 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3956 if (first_entry > 0)
3958 first_entry -= step;
3959 if (first_entry < 0)
3962 drawHallOfFameList(first_entry, highlight_position);
3967 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3969 first_entry += step;
3970 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3971 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3973 drawHallOfFameList(first_entry, highlight_position);
3976 else if (button == MB_MENU_LEAVE)
3978 PlaySound(SND_MENU_ITEM_SELECTING);
3980 FadeSound(SND_BACKGROUND_SCORES);
3982 game_status = GAME_MODE_MAIN;
3986 else if (button == MB_MENU_CHOICE)
3988 PlaySound(SND_MENU_ITEM_SELECTING);
3990 FadeSound(SND_BACKGROUND_SCORES);
3993 FadeOut(REDRAW_FIELD);
3996 game_status = GAME_MODE_MAIN;
3998 DrawAndFadeInMainMenu(REDRAW_FIELD);
4001 if (game_status == GAME_MODE_SCORES)
4002 PlayMenuSoundIfLoop();
4008 /* ========================================================================= */
4009 /* setup screen functions */
4010 /* ========================================================================= */
4012 static struct TokenInfo *setup_info;
4013 static int num_setup_info;
4015 static char *screen_mode_text;
4016 static char *scroll_delay_text;
4017 static char *game_speed_text;
4018 static char *graphics_set_name;
4019 static char *sounds_set_name;
4020 static char *music_set_name;
4021 static char *volume_simple_text;
4022 static char *volume_loops_text;
4023 static char *volume_music_text;
4025 static void execSetupMain()
4027 setup_mode = SETUP_MODE_MAIN;
4032 static void execSetupGame()
4034 if (game_speeds == NULL)
4038 for (i = 0; game_speeds_list[i].value != -1; i++)
4040 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4041 char identifier[32], name[32];
4042 int value = game_speeds_list[i].value;
4043 char *text = game_speeds_list[i].text;
4045 ti->node_top = &game_speeds;
4046 ti->sort_priority = 10000 - value;
4048 sprintf(identifier, "%d", value);
4049 sprintf(name, "%s", text);
4051 setString(&ti->identifier, identifier);
4052 setString(&ti->name, name);
4053 setString(&ti->name_sorting, name);
4054 setString(&ti->infotext, "Game Speed");
4056 pushTreeInfo(&game_speeds, ti);
4059 /* sort game speed values to start with slowest game speed */
4060 sortTreeInfo(&game_speeds);
4062 /* set current game speed to configured game speed value */
4063 game_speed_current =
4064 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4066 /* if that fails, set current game speed to reliable default value */
4067 if (game_speed_current == NULL)
4068 game_speed_current =
4069 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4071 /* if that also fails, set current game speed to first available speed */
4072 if (game_speed_current == NULL)
4073 game_speed_current = game_speeds;
4076 setup.game_frame_delay = atoi(game_speed_current->identifier);
4078 /* needed for displaying game speed text instead of identifier */
4079 game_speed_text = game_speed_current->name;
4081 setup_mode = SETUP_MODE_GAME;
4086 static void execSetupChooseGameSpeed()
4088 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4093 static void execSetupEditor()
4095 setup_mode = SETUP_MODE_EDITOR;
4100 static void execSetupGraphics()
4102 if (video.fullscreen_available && screen_modes == NULL)
4106 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4108 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4109 char identifier[32], name[32];
4110 int x = video.fullscreen_modes[i].width;
4111 int y = video.fullscreen_modes[i].height;
4114 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4116 ti->node_top = &screen_modes;
4117 ti->sort_priority = x * 10000 + y;
4119 sprintf(identifier, "%dx%d", x, y);
4120 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4122 setString(&ti->identifier, identifier);
4123 setString(&ti->name, name);
4124 setString(&ti->name_sorting, name);
4125 setString(&ti->infotext, "Fullscreen Mode");
4127 pushTreeInfo(&screen_modes, ti);
4130 /* sort fullscreen modes to start with lowest available screen resolution */
4131 sortTreeInfo(&screen_modes);
4133 /* set current screen mode for fullscreen mode to configured setup value */
4134 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4135 setup.fullscreen_mode);
4137 /* if that fails, set current screen mode to reliable default value */
4138 if (screen_mode_current == NULL)
4139 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4140 DEFAULT_FULLSCREEN_MODE);
4142 /* if that also fails, set current screen mode to first available mode */
4143 if (screen_mode_current == NULL)
4144 screen_mode_current = screen_modes;
4146 if (screen_mode_current == NULL)
4147 video.fullscreen_available = FALSE;
4150 if (video.fullscreen_available)
4152 setup.fullscreen_mode = screen_mode_current->identifier;
4154 /* needed for displaying screen mode name instead of identifier */
4155 screen_mode_text = screen_mode_current->name;
4159 if (scroll_delays == NULL)
4163 for (i = 0; scroll_delays_list[i].value != -1; i++)
4165 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4166 char identifier[32], name[32];
4167 int value = scroll_delays_list[i].value;
4168 char *text = scroll_delays_list[i].text;
4170 ti->node_top = &scroll_delays;
4171 ti->sort_priority = value;
4173 sprintf(identifier, "%d", value);
4174 sprintf(name, "%s", text);
4176 setString(&ti->identifier, identifier);
4177 setString(&ti->name, name);
4178 setString(&ti->name_sorting, name);
4179 setString(&ti->infotext, "Scroll Delay");
4181 pushTreeInfo(&scroll_delays, ti);
4184 /* sort scroll delay values to start with lowest scroll delay value */
4185 sortTreeInfo(&scroll_delays);
4187 /* set current scroll delay value to configured scroll delay value */
4188 scroll_delay_current =
4189 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4191 /* if that fails, set current scroll delay to reliable default value */
4192 if (scroll_delay_current == NULL)
4193 scroll_delay_current =
4194 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4196 /* if that also fails, set current scroll delay to first available value */
4197 if (scroll_delay_current == NULL)
4198 scroll_delay_current = scroll_delays;
4201 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4203 /* needed for displaying scroll delay text instead of identifier */
4204 scroll_delay_text = scroll_delay_current->name;
4207 setup_mode = SETUP_MODE_GRAPHICS;
4212 static void execSetupChooseScreenMode()
4214 if (!video.fullscreen_available)
4217 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4222 static void execSetupChooseScrollDelay()
4224 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4229 static void execSetupChooseVolumeSimple()
4231 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4236 static void execSetupChooseVolumeLoops()
4238 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4243 static void execSetupChooseVolumeMusic()
4245 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4250 static void execSetupSound()
4253 if (volumes_simple == NULL)
4257 for (i = 0; volumes_list[i].value != -1; i++)
4259 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4260 char identifier[32], name[32];
4261 int value = volumes_list[i].value;
4262 char *text = volumes_list[i].text;
4264 ti->node_top = &volumes_simple;
4265 ti->sort_priority = value;
4267 sprintf(identifier, "%d", value);
4268 sprintf(name, "%s", text);
4270 setString(&ti->identifier, identifier);
4271 setString(&ti->name, name);
4272 setString(&ti->name_sorting, name);
4273 setString(&ti->infotext, "Sound Volume");
4275 pushTreeInfo(&volumes_simple, ti);
4278 /* sort volume values to start with lowest volume value */
4279 sortTreeInfo(&volumes_simple);
4281 /* set current volume value to configured volume value */
4282 volume_simple_current =
4283 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4285 /* if that fails, set current volume to reliable default value */
4286 if (volume_simple_current == NULL)
4287 volume_simple_current =
4288 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4290 /* if that also fails, set current volume to first available value */
4291 if (volume_simple_current == NULL)
4292 volume_simple_current = volumes_simple;
4295 if (volumes_loops == NULL)
4299 for (i = 0; volumes_list[i].value != -1; i++)
4301 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4302 char identifier[32], name[32];
4303 int value = volumes_list[i].value;
4304 char *text = volumes_list[i].text;
4306 ti->node_top = &volumes_loops;
4307 ti->sort_priority = value;
4309 sprintf(identifier, "%d", value);
4310 sprintf(name, "%s", text);
4312 setString(&ti->identifier, identifier);
4313 setString(&ti->name, name);
4314 setString(&ti->name_sorting, name);
4315 setString(&ti->infotext, "Loops Volume");
4317 pushTreeInfo(&volumes_loops, ti);
4320 /* sort volume values to start with lowest volume value */
4321 sortTreeInfo(&volumes_loops);
4323 /* set current volume value to configured volume value */
4324 volume_loops_current =
4325 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4327 /* if that fails, set current volume to reliable default value */
4328 if (volume_loops_current == NULL)
4329 volume_loops_current =
4330 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4332 /* if that also fails, set current volume to first available value */
4333 if (volume_loops_current == NULL)
4334 volume_loops_current = volumes_loops;
4337 if (volumes_music == NULL)
4341 for (i = 0; volumes_list[i].value != -1; i++)
4343 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4344 char identifier[32], name[32];
4345 int value = volumes_list[i].value;
4346 char *text = volumes_list[i].text;
4348 ti->node_top = &volumes_music;
4349 ti->sort_priority = value;
4351 sprintf(identifier, "%d", value);
4352 sprintf(name, "%s", text);
4354 setString(&ti->identifier, identifier);
4355 setString(&ti->name, name);
4356 setString(&ti->name_sorting, name);
4357 setString(&ti->infotext, "Music Volume");
4359 pushTreeInfo(&volumes_music, ti);
4362 /* sort volume values to start with lowest volume value */
4363 sortTreeInfo(&volumes_music);
4365 /* set current volume value to configured volume value */
4366 volume_music_current =
4367 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4369 /* if that fails, set current volume to reliable default value */
4370 if (volume_music_current == NULL)
4371 volume_music_current =
4372 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4374 /* if that also fails, set current volume to first available value */
4375 if (volume_music_current == NULL)
4376 volume_music_current = volumes_music;
4379 setup.volume_simple = atoi(volume_simple_current->identifier);
4380 setup.volume_loops = atoi(volume_loops_current->identifier);
4381 setup.volume_music = atoi(volume_music_current->identifier);
4383 /* needed for displaying volume text instead of identifier */
4384 volume_simple_text = volume_simple_current->name;
4385 volume_loops_text = volume_loops_current->name;
4386 volume_music_text = volume_music_current->name;
4389 setup_mode = SETUP_MODE_SOUND;
4394 static void execSetupArtwork()
4397 printf("::: '%s', '%s', '%s'\n",
4398 artwork.gfx_current->subdir,
4399 artwork.gfx_current->fullpath,
4400 artwork.gfx_current->basepath);
4403 setup.graphics_set = artwork.gfx_current->identifier;
4404 setup.sounds_set = artwork.snd_current->identifier;
4405 setup.music_set = artwork.mus_current->identifier;
4407 /* needed if last screen (setup choice) changed graphics, sounds or music */
4408 ReloadCustomArtwork(0);
4410 /* needed for displaying artwork name instead of artwork identifier */
4411 graphics_set_name = artwork.gfx_current->name;
4412 sounds_set_name = artwork.snd_current->name;
4413 music_set_name = artwork.mus_current->name;
4415 setup_mode = SETUP_MODE_ARTWORK;
4420 static void execSetupChooseGraphics()
4422 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4427 static void execSetupChooseSounds()
4429 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4434 static void execSetupChooseMusic()
4436 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4441 static void execSetupInput()
4443 setup_mode = SETUP_MODE_INPUT;
4448 static void execSetupShortcuts()
4450 setup_mode = SETUP_MODE_SHORTCUTS;
4455 static void execSetupShortcuts1()
4457 setup_mode = SETUP_MODE_SHORTCUTS_1;
4462 static void execSetupShortcuts2()
4464 setup_mode = SETUP_MODE_SHORTCUTS_2;
4469 static void execSetupShortcuts3()
4471 setup_mode = SETUP_MODE_SHORTCUTS_3;
4476 static void execSetupShortcuts4()
4478 setup_mode = SETUP_MODE_SHORTCUTS_4;
4483 static void execSetupShortcuts5()
4485 setup_mode = SETUP_MODE_SHORTCUTS_5;
4490 static void execExitSetup()
4492 game_status = GAME_MODE_MAIN;
4494 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4497 static void execSaveAndExitSetup()
4503 static struct TokenInfo setup_info_main[] =
4505 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4506 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4507 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4508 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4509 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4510 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4511 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4512 { TYPE_EMPTY, NULL, "" },
4513 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4514 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4519 static struct TokenInfo setup_info_game[] =
4521 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4522 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4523 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4524 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4525 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4526 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4527 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4528 { TYPE_STRING, &game_speed_text, "" },
4529 { TYPE_EMPTY, NULL, "" },
4530 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4535 static struct TokenInfo setup_info_editor[] =
4538 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4539 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4540 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4541 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4542 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4543 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4544 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4545 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4547 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4548 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4549 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4551 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4553 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4554 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4555 { TYPE_EMPTY, NULL, "" },
4557 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4558 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4559 { TYPE_EMPTY, NULL, "" },
4561 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4562 { TYPE_EMPTY, NULL, "" },
4563 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4568 static struct TokenInfo setup_info_graphics[] =
4570 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4571 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4572 { TYPE_STRING, &screen_mode_text, "" },
4574 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4576 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4577 { TYPE_STRING, &scroll_delay_text, "" },
4579 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4581 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4582 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4583 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4584 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4585 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4586 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4587 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4588 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4589 { TYPE_EMPTY, NULL, "" },
4590 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4595 static struct TokenInfo setup_info_sound[] =
4597 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4598 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4599 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4600 { TYPE_EMPTY, NULL, "" },
4601 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4602 { TYPE_STRING, &volume_simple_text, "" },
4603 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4604 { TYPE_STRING, &volume_loops_text, "" },
4605 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4606 { TYPE_STRING, &volume_music_text, "" },
4607 { TYPE_EMPTY, NULL, "" },
4608 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4613 static struct TokenInfo setup_info_artwork[] =
4615 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4616 { TYPE_STRING, &graphics_set_name, "" },
4617 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4618 { TYPE_STRING, &sounds_set_name, "" },
4619 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4620 { TYPE_STRING, &music_set_name, "" },
4621 { TYPE_EMPTY, NULL, "" },
4624 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4625 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4626 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4628 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4629 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4630 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4631 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4634 { TYPE_STRING, NULL, "Override Level Artwork:"},
4635 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4636 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4637 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4639 { TYPE_EMPTY, NULL, "" },
4640 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4645 static struct TokenInfo setup_info_input[] =
4647 { TYPE_SWITCH, NULL, "Player:" },
4648 { TYPE_SWITCH, NULL, "Device:" },
4649 { TYPE_ENTER_MENU, NULL, "" },
4650 { TYPE_EMPTY, NULL, "" },
4651 { TYPE_EMPTY, NULL, "" },
4652 { TYPE_EMPTY, NULL, "" },
4653 { TYPE_EMPTY, NULL, "" },
4654 { TYPE_EMPTY, NULL, "" },
4655 { TYPE_EMPTY, NULL, "" },
4656 { TYPE_EMPTY, NULL, "" },
4657 { TYPE_EMPTY, NULL, "" },
4658 { TYPE_EMPTY, NULL, "" },
4659 { TYPE_EMPTY, NULL, "" },
4660 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4665 static struct TokenInfo setup_info_shortcuts[] =
4667 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4668 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4669 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4670 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4671 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4672 { TYPE_EMPTY, NULL, "" },
4673 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4678 static struct TokenInfo setup_info_shortcuts_1[] =
4680 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4681 { TYPE_KEY, &setup.shortcut.save_game, "" },
4682 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4683 { TYPE_KEY, &setup.shortcut.load_game, "" },
4684 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4685 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4686 { TYPE_EMPTY, NULL, "" },
4687 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4688 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4689 { TYPE_EMPTY, NULL, "" },
4690 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4695 static struct TokenInfo setup_info_shortcuts_2[] =
4697 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4698 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4699 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4700 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4701 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4702 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4703 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4704 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4705 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4706 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4707 { TYPE_EMPTY, NULL, "" },
4708 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4713 static struct TokenInfo setup_info_shortcuts_3[] =
4715 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
4716 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4717 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
4718 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
4719 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
4720 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4721 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
4722 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4723 { TYPE_KEYTEXT, NULL, "Record Tape:", },
4724 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4725 { TYPE_KEYTEXT, NULL, "Play Tape:", },
4726 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4727 { TYPE_EMPTY, NULL, "" },
4728 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4733 static struct TokenInfo setup_info_shortcuts_4[] =
4735 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
4736 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4737 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
4738 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4739 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
4740 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4741 { TYPE_EMPTY, NULL, "" },
4742 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4747 static struct TokenInfo setup_info_shortcuts_5[] =
4749 { TYPE_KEYTEXT, NULL, "Snap Left:", },
4750 { TYPE_KEY, &setup.shortcut.snap_left, "" },
4751 { TYPE_KEYTEXT, NULL, "Snap Right:", },
4752 { TYPE_KEY, &setup.shortcut.snap_right, "" },
4753 { TYPE_KEYTEXT, NULL, "Snap Up:", },
4754 { TYPE_KEY, &setup.shortcut.snap_up, "" },
4755 { TYPE_KEYTEXT, NULL, "Snap Down:", },
4756 { TYPE_KEY, &setup.shortcut.snap_down, "" },
4757 { TYPE_EMPTY, NULL, "" },
4758 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4763 static Key getSetupKey()
4765 Key key = KSYM_UNDEFINED;
4766 boolean got_key_event = FALSE;
4768 while (!got_key_event)
4770 if (PendingEvent()) /* got event */
4778 case EVENT_KEYPRESS:
4780 key = GetEventKey((KeyEvent *)&event, TRUE);
4782 /* press 'Escape' or 'Enter' to keep the existing key binding */
4783 if (key == KSYM_Escape || key == KSYM_Return)
4784 key = KSYM_UNDEFINED; /* keep old value */
4786 got_key_event = TRUE;
4790 case EVENT_KEYRELEASE:
4791 key_joystick_mapping = 0;
4795 HandleOtherEvents(&event);
4803 /* don't eat all CPU time */
4810 static int getSetupTextFont(int type)
4812 if (type & (TYPE_SWITCH |
4824 static int getSetupValueFont(int type, void *value)
4826 if (type & TYPE_KEY)
4827 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4828 else if (type & TYPE_STRING)
4829 return FONT_VALUE_2;
4830 else if (type & TYPE_ECS_AGA)
4831 return FONT_VALUE_1;
4832 else if (type & TYPE_BOOLEAN_STYLE)
4833 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4834 else if (type & TYPE_YES_NO_AUTO)
4835 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4836 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4838 return FONT_VALUE_1;
4841 static void drawSetupValue(int pos)
4843 boolean font_draw_xoffset_modified = FALSE;
4844 int font_draw_xoffset_old = -1;
4845 int xpos = MENU_SCREEN_VALUE_XPOS;
4846 int ypos = MENU_SCREEN_START_YPOS + pos;
4847 int startx = mSX + xpos * 32;
4848 int starty = mSY + ypos * 32;
4849 int font_nr, font_width;
4853 int type = setup_info[pos].type;
4854 void *value = setup_info[pos].value;
4855 char *value_string = getSetupValue(type, value);
4860 if (value_string == NULL)
4863 if (type & TYPE_KEY)
4865 xpos = MENU_SCREEN_START_XPOS;
4867 if (type & TYPE_QUERY)
4868 value_string = "<press key>";
4870 else if (type & TYPE_STRING)
4872 int max_value_len = (SCR_FIELDX - 2) * 2;
4874 xpos = MENU_SCREEN_START_XPOS;
4876 if (strlen(value_string) > max_value_len)
4877 value_string[max_value_len] = '\0';
4879 else if (type & TYPE_YES_NO_AUTO)
4881 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4884 startx = mSX + xpos * 32;
4885 starty = mSY + ypos * 32;
4886 font_nr = getSetupValueFont(type, value);
4887 font_width = getFontWidth(font_nr);
4889 font_height = getFontHeight(font_nr);
4892 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4893 if (setup_mode != SETUP_MODE_INPUT)
4895 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4896 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4897 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4898 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4899 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4900 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4901 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4902 boolean correct_font_draw_xoffset = FALSE;
4904 if (xpos == MENU_SCREEN_START_XPOS &&
4905 startx + font1_xoffset < text_startx + text_font_xoffset)
4906 correct_font_draw_xoffset = TRUE;
4908 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4909 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4910 correct_font_draw_xoffset = TRUE;
4912 /* check if setup value would overlap with setup text when printed */
4913 /* (this can happen for extreme/wrong values for font draw offset) */
4914 if (correct_font_draw_xoffset)
4916 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4917 font_draw_xoffset_modified = TRUE;
4919 if (type & TYPE_KEY)
4920 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4921 else if (!(type & TYPE_STRING))
4922 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4923 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4928 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4930 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4931 DrawText(startx + i * font_width, starty, " ", font_nr);
4934 DrawText(startx, starty, value_string, font_nr);
4936 if (font_draw_xoffset_modified)
4937 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4940 static void changeSetupValue(int pos, int dx)
4942 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4944 *(boolean *)setup_info[pos].value ^= TRUE;
4946 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4948 *(int *)setup_info[pos].value =
4950 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4951 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4952 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4953 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4955 else if (setup_info[pos].type & TYPE_KEY)
4959 setup_info[pos].type |= TYPE_QUERY;
4960 drawSetupValue(pos);
4961 setup_info[pos].type &= ~TYPE_QUERY;
4963 key = getSetupKey();
4964 if (key != KSYM_UNDEFINED)
4965 *(Key *)setup_info[pos].value = key;
4968 drawSetupValue(pos);
4971 static void DrawCursorAndText_Setup(int pos, boolean active)
4973 int xpos = MENU_SCREEN_START_XPOS;
4974 int ypos = MENU_SCREEN_START_YPOS + pos;
4975 int font_nr = getSetupTextFont(setup_info[pos].type);
4977 if (setup_info == setup_info_input)
4978 font_nr = FONT_MENU_1;
4981 font_nr = FONT_ACTIVE(font_nr);
4983 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4985 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4986 drawCursor(pos, active);
4989 static void DrawSetupScreen_Generic()
4991 boolean redraw_all = FALSE;
4992 char *title_string = NULL;
4996 CloseDoor(DOOR_CLOSE_2);
4998 if (redraw_mask & REDRAW_ALL)
5002 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5003 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5004 int2str(0, redraw_mask)));
5008 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5009 FadeOut(redraw_mask);
5011 FadeOut(REDRAW_FIELD);
5016 if (setup_mode == SETUP_MODE_MAIN)
5018 setup_info = setup_info_main;
5019 title_string = "Setup";
5021 else if (setup_mode == SETUP_MODE_GAME)
5023 setup_info = setup_info_game;
5024 title_string = "Setup Game";
5026 else if (setup_mode == SETUP_MODE_EDITOR)
5028 setup_info = setup_info_editor;
5029 title_string = "Setup Editor";
5031 else if (setup_mode == SETUP_MODE_GRAPHICS)
5033 setup_info = setup_info_graphics;
5034 title_string = "Setup Graphics";
5036 else if (setup_mode == SETUP_MODE_SOUND)
5038 setup_info = setup_info_sound;
5039 title_string = "Setup Sound";
5041 else if (setup_mode == SETUP_MODE_ARTWORK)
5043 setup_info = setup_info_artwork;
5044 title_string = "Custom Artwork";
5046 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5048 setup_info = setup_info_shortcuts;
5049 title_string = "Setup Shortcuts";
5051 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5053 setup_info = setup_info_shortcuts_1;
5054 title_string = "Setup Shortcuts";
5056 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5058 setup_info = setup_info_shortcuts_2;
5059 title_string = "Setup Shortcuts";
5061 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5063 setup_info = setup_info_shortcuts_3;
5064 title_string = "Setup Shortcuts";
5066 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5068 setup_info = setup_info_shortcuts_4;
5069 title_string = "Setup Shortcuts";
5071 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5073 setup_info = setup_info_shortcuts_5;
5074 title_string = "Setup Shortcuts";
5077 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5081 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5083 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5086 void *value_ptr = setup_info[i].value;
5088 /* set some entries to "unchangeable" according to other variables */
5089 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5090 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5091 (value_ptr == &setup.sound_music && !audio.music_available) ||
5092 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5093 (value_ptr == &screen_mode_text && !video.fullscreen_available))
5094 setup_info[i].type |= TYPE_GHOSTED;
5096 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5097 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5098 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5099 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5100 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5101 initCursor(i, IMG_MENU_BUTTON);
5103 DrawCursorAndText_Setup(i, FALSE);
5105 if (setup_info[i].type & TYPE_VALUE)
5112 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5113 "Joysticks deactivated in setup menu");
5117 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5121 redraw_mask = REDRAW_ALL;
5124 FadeIn(redraw_mask);
5126 FadeIn(REDRAW_FIELD);
5131 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5135 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5137 static int choice_store[MAX_SETUP_MODES];
5138 int choice = choice_store[setup_mode]; /* always starts with 0 */
5142 if (button == MB_MENU_INITIALIZE)
5144 /* advance to first valid menu entry */
5145 while (choice < num_setup_info &&
5146 setup_info[choice].type & TYPE_SKIP_ENTRY)
5148 choice_store[setup_mode] = choice;
5150 DrawCursorAndText_Setup(choice, TRUE);
5154 else if (button == MB_MENU_LEAVE)
5156 PlaySound(SND_MENU_ITEM_SELECTING);
5158 for (y = 0; y < num_setup_info; y++)
5160 if (setup_info[y].type & TYPE_LEAVE_MENU)
5162 void (*menu_callback_function)(void) = setup_info[y].value;
5166 menu_callback_function();
5168 break; /* absolutely needed because function changes 'setup_info'! */
5175 if (mx || my) /* mouse input */
5177 x = (mx - mSX) / 32;
5178 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5180 else if (dx || dy) /* keyboard input */
5184 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5186 if (setup_info[choice].type & menu_navigation_type ||
5187 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5188 setup_info[choice].type & TYPE_YES_NO_AUTO)
5189 button = MB_MENU_CHOICE;
5194 /* jump to next non-empty menu entry (up or down) */
5195 while (y > 0 && y < num_setup_info - 1 &&
5196 setup_info[y].type & TYPE_SKIP_ENTRY)
5200 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5204 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5206 PlaySound(SND_MENU_ITEM_ACTIVATING);
5208 DrawCursorAndText_Setup(choice, FALSE);
5209 DrawCursorAndText_Setup(y, TRUE);
5211 choice = choice_store[setup_mode] = y;
5214 else if (!(setup_info[y].type & TYPE_GHOSTED))
5216 PlaySound(SND_MENU_ITEM_SELECTING);
5218 /* when selecting key headline, execute function for key value change */
5219 if (setup_info[y].type & TYPE_KEYTEXT &&
5220 setup_info[y + 1].type & TYPE_KEY)
5223 /* when selecting string value, execute function for list selection */
5224 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5225 setup_info[y - 1].type & TYPE_ENTER_LIST)
5228 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5230 void (*menu_callback_function)(void) = setup_info[y].value;
5232 FadeSetFromType(setup_info[y].type);
5234 menu_callback_function();
5238 if (setup_info[y].type & TYPE_VALUE)
5239 changeSetupValue(y, dx);
5245 void DrawSetupScreen_Input()
5250 FadeOut(REDRAW_FIELD);
5256 setup_info = setup_info_input;
5259 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5263 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5264 "Joysticks deactivated on this screen");
5266 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5267 "Joysticks deactivated on this screen");
5272 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5274 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5277 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5278 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5279 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5280 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5281 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5282 initCursor(i, IMG_MENU_BUTTON);
5284 DrawCursorAndText_Setup(i, FALSE);
5288 DeactivateJoystickForCalibration();
5293 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5294 "Joysticks deactivated on this screen");
5296 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5297 "Joysticks deactivated on this screen");
5301 /* create gadgets for setup input menu screen */
5302 FreeScreenGadgets();
5303 CreateScreenGadgets();
5305 /* map gadgets for setup input menu screen */
5306 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5308 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5311 FadeIn(REDRAW_FIELD);
5317 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5319 if (device_name == NULL)
5322 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5325 if (strlen(device_name) > 1)
5327 char c1 = device_name[strlen(device_name) - 1];
5328 char c2 = device_name[strlen(device_name) - 2];
5330 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5331 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5334 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5335 strlen(device_name));
5338 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5341 static struct SetupKeyboardInfo custom_key;
5348 { &custom_key.left, "Joystick Left" },
5349 { &custom_key.right, "Joystick Right" },
5350 { &custom_key.up, "Joystick Up" },
5351 { &custom_key.down, "Joystick Down" },
5352 { &custom_key.snap, "Button 1" },
5353 { &custom_key.drop, "Button 2" }
5355 static char *joystick_name[MAX_PLAYERS] =
5362 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5366 custom_key = setup.input[player_nr].key;
5368 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5369 FONT_INPUT_1_ACTIVE);
5371 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5373 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5374 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5376 if (setup.input[player_nr].use_joystick)
5378 char *device_name = setup.input[player_nr].joy.device_name;
5379 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5380 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5382 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5383 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5387 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5388 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5391 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5393 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5394 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5395 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5396 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5398 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5399 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5400 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5401 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5402 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5403 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5405 for (i = 0; i < 6; i++)
5407 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5409 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5411 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5412 (setup.input[player_nr].use_joystick ?
5414 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5418 static int input_player_nr = 0;
5420 void HandleSetupScreen_Input_Player(int step, int direction)
5422 int old_player_nr = input_player_nr;
5425 new_player_nr = old_player_nr + step * direction;
5426 if (new_player_nr < 0)
5428 if (new_player_nr > MAX_PLAYERS - 1)
5429 new_player_nr = MAX_PLAYERS - 1;
5431 if (new_player_nr != old_player_nr)
5433 input_player_nr = new_player_nr;
5435 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5439 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5441 static int choice = 0;
5444 int pos_start = SETUPINPUT_SCREEN_POS_START;
5445 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5446 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5447 int pos_end = SETUPINPUT_SCREEN_POS_END;
5449 if (button == MB_MENU_INITIALIZE)
5451 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5453 DrawCursorAndText_Setup(choice, TRUE);
5457 else if (button == MB_MENU_LEAVE)
5459 setup_mode = SETUP_MODE_MAIN;
5466 if (mx || my) /* mouse input */
5468 x = (mx - mSX) / 32;
5469 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5471 else if (dx || dy) /* keyboard input */
5473 if (dx && choice == 0)
5474 x = (dx < 0 ? 10 : 12);
5475 else if ((dx && choice == 1) ||
5476 (dx == +1 && choice == 2) ||
5477 (dx == -1 && choice == pos_end))
5478 button = MB_MENU_CHOICE;
5482 if (y >= pos_empty1 && y <= pos_empty2)
5483 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5486 if (y == 0 && dx != 0 && button)
5488 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5490 else if (IN_VIS_FIELD(x, y) &&
5491 y >= pos_start && y <= pos_end &&
5492 !(y >= pos_empty1 && y <= pos_empty2))
5498 DrawCursorAndText_Setup(choice, FALSE);
5499 DrawCursorAndText_Setup(y, TRUE);
5501 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5510 char *device_name = setup.input[input_player_nr].joy.device_name;
5512 if (!setup.input[input_player_nr].use_joystick)
5514 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5516 setJoystickDeviceToNr(device_name, new_device_nr);
5517 setup.input[input_player_nr].use_joystick = TRUE;
5521 int device_nr = getJoystickNrFromDeviceName(device_name);
5522 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5524 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5525 setup.input[input_player_nr].use_joystick = FALSE;
5527 setJoystickDeviceToNr(device_name, new_device_nr);
5530 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5534 if (setup.input[input_player_nr].use_joystick)
5537 CalibrateJoystick(input_player_nr);
5540 CustomizeKeyboard(input_player_nr);
5542 else if (y == pos_end)
5548 setup_mode = SETUP_MODE_MAIN;
5555 void CustomizeKeyboard(int player_nr)
5559 boolean finished = FALSE;
5560 static struct SetupKeyboardInfo custom_key;
5565 } customize_step[] =
5567 { &custom_key.left, "Move Left" },
5568 { &custom_key.right, "Move Right" },
5569 { &custom_key.up, "Move Up" },
5570 { &custom_key.down, "Move Down" },
5571 { &custom_key.snap, "Snap Field" },
5572 { &custom_key.drop, "Drop Element" }
5575 /* read existing key bindings from player setup */
5576 custom_key = setup.input[player_nr].key;
5579 FadeOut(REDRAW_FIELD);
5583 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5591 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5592 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5593 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5594 "Key:", FONT_INPUT_1_ACTIVE);
5595 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5596 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5599 FadeIn(REDRAW_FIELD);
5606 if (PendingEvent()) /* got event */
5614 case EVENT_KEYPRESS:
5616 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5618 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5620 if (key == KSYM_Escape)
5621 FadeSkipNextFadeIn();
5627 /* all keys configured -- wait for "Escape" or "Return" key */
5631 /* press 'Enter' to keep the existing key binding */
5632 if (key == KSYM_Return)
5633 key = *customize_step[step_nr].key;
5635 /* check if key already used */
5636 for (i = 0; i < step_nr; i++)
5637 if (*customize_step[i].key == key)
5642 /* got new key binding */
5643 *customize_step[step_nr].key = key;
5644 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5646 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5647 getKeyNameFromKey(key), FONT_VALUE_1);
5650 /* un-highlight last query */
5651 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5652 customize_step[step_nr - 1].text, FONT_MENU_1);
5653 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5654 "Key:", FONT_MENU_1);
5656 /* press 'Enter' to leave */
5659 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5660 "Press Enter", FONT_TITLE_1);
5664 /* query next key binding */
5665 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5666 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5667 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5668 "Key:", FONT_INPUT_1_ACTIVE);
5669 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5670 getKeyNameFromKey(*customize_step[step_nr].key),
5675 case EVENT_KEYRELEASE:
5676 key_joystick_mapping = 0;
5680 HandleOtherEvents(&event);
5688 /* don't eat all CPU time */
5692 /* write new key bindings back to player setup */
5693 setup.input[player_nr].key = custom_key;
5696 DrawSetupScreen_Input();
5699 static boolean CalibrateJoystickMain(int player_nr)
5701 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5702 int new_joystick_xright = JOYSTICK_XMIDDLE;
5703 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5704 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5705 int new_joystick_xmiddle, new_joystick_ymiddle;
5707 int joystick_fd = joystick.fd[player_nr];
5708 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5709 boolean check[3][3];
5710 int check_remaining = 3 * 3;
5715 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5718 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5722 FadeOut(REDRAW_FIELD);
5726 for (y = 0; y < 3; y++)
5728 for (x = 0; x < 3; x++)
5730 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5731 check[x][y] = FALSE;
5735 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5736 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5737 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5738 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5739 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5740 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5741 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5743 joy_value = Joystick(player_nr);
5744 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5745 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5747 /* eventually uncalibrated center position (joystick could be uncentered) */
5748 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5751 new_joystick_xmiddle = joy_x;
5752 new_joystick_ymiddle = joy_y;
5754 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5756 FadeIn(REDRAW_FIELD);
5758 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5763 if (PendingEvent()) /* got event */
5771 case EVENT_KEYPRESS:
5772 switch (GetEventKey((KeyEvent *)&event, TRUE))
5775 if (check_remaining == 0)
5780 FadeSkipNextFadeIn();
5789 case EVENT_KEYRELEASE:
5790 key_joystick_mapping = 0;
5794 HandleOtherEvents(&event);
5799 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5802 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5803 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5804 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5805 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5807 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5808 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5809 setup.input[player_nr].joy.xright = new_joystick_xright;
5810 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5811 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5812 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5814 CheckJoystickData();
5816 joy_value = Joystick(player_nr);
5818 if (joy_value & JOY_BUTTON && check_remaining == 0)
5821 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5822 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5824 if (x != last_x || y != last_y)
5826 DrawFixedGraphic(xpos + last_x, ypos + last_y,
5827 IMG_MENU_CALIBRATE_YELLOW, 0);
5828 DrawFixedGraphic(xpos + x, ypos + y,
5829 IMG_MENU_CALIBRATE_RED, 0);
5834 if (check_remaining > 0 && !check[x+1][y+1])
5836 check[x+1][y+1] = TRUE;
5842 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5843 setup.input[player_nr].joy.xleft,
5844 setup.input[player_nr].joy.xmiddle,
5845 setup.input[player_nr].joy.xright);
5846 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5847 setup.input[player_nr].joy.yupper,
5848 setup.input[player_nr].joy.ymiddle,
5849 setup.input[player_nr].joy.ylower);
5858 /* don't eat all CPU time */
5862 /* calibrated center position (joystick should now be centered) */
5863 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5866 new_joystick_xmiddle = joy_x;
5867 new_joystick_ymiddle = joy_y;
5872 DrawSetupScreen_Input();
5875 /* wait until the last pressed button was released */
5876 while (Joystick(player_nr) & JOY_BUTTON)
5878 if (PendingEvent()) /* got event */
5883 HandleOtherEvents(&event);
5892 void CalibrateJoystick(int player_nr)
5894 if (!CalibrateJoystickMain(player_nr))
5896 char *device_name = setup.input[player_nr].joy.device_name;
5897 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5898 int xpos = mSX - SX;
5899 int ypos = mSY - SY;
5903 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5904 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5907 Delay(2000); /* show error message for a short time */
5913 DrawSetupScreen_Input();
5917 void DrawSetupScreen()
5919 DeactivateJoystick();
5921 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5923 if (setup_mode == SETUP_MODE_INPUT)
5924 DrawSetupScreen_Input();
5925 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5926 DrawChooseTree(&game_speed_current);
5927 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5928 DrawChooseTree(&screen_mode_current);
5929 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5930 DrawChooseTree(&scroll_delay_current);
5931 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5932 DrawChooseTree(&artwork.gfx_current);
5933 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5934 DrawChooseTree(&artwork.snd_current);
5935 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5936 DrawChooseTree(&artwork.mus_current);
5937 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
5938 DrawChooseTree(&volume_simple_current);
5939 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
5940 DrawChooseTree(&volume_loops_current);
5941 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5942 DrawChooseTree(&volume_music_current);
5944 DrawSetupScreen_Generic();
5950 void RedrawSetupScreenAfterFullscreenToggle()
5952 if (setup_mode == SETUP_MODE_GRAPHICS)
5956 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5958 if (setup_mode == SETUP_MODE_INPUT)
5959 HandleSetupScreen_Input(mx, my, dx, dy, button);
5960 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5961 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5962 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5963 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5964 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5965 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5966 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5967 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5968 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5969 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5970 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5971 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5972 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
5973 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
5974 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
5975 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
5976 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5977 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
5979 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5984 void HandleGameActions()
5986 if (game_status != GAME_MODE_PLAYING)
5989 GameActions(); /* main game loop */
5991 if (tape.auto_play && !tape.playing)
5992 AutoPlayTape(); /* continue automatically playing next tape */
5996 /* ---------- new screen button stuff -------------------------------------- */
5998 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6003 case SCREEN_CTRL_ID_PREV_LEVEL:
6004 *x = mSX + menu.main.button.prev_level.x;
6005 *y = mSY + menu.main.button.prev_level.y;
6008 case SCREEN_CTRL_ID_NEXT_LEVEL:
6009 *x = mSX + menu.main.button.next_level.x;
6010 *y = mSY + menu.main.button.next_level.y;
6013 case SCREEN_CTRL_ID_PREV_LEVEL:
6014 *x = mSX + TILEX * getPrevlevelButtonPos();
6015 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6018 case SCREEN_CTRL_ID_NEXT_LEVEL:
6019 *x = mSX + TILEX * getNextLevelButtonPos();
6020 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6024 case SCREEN_CTRL_ID_PREV_PLAYER:
6025 *x = mSX + TILEX * 10;
6026 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6029 case SCREEN_CTRL_ID_NEXT_PLAYER:
6030 *x = mSX + TILEX * 12;
6031 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6035 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6041 int gfx_unpressed, gfx_pressed;
6042 void (*get_gadget_position)(int *, int *, int);
6046 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6049 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6050 getScreenMenuButtonPos,
6051 SCREEN_CTRL_ID_PREV_LEVEL,
6056 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6057 getScreenMenuButtonPos,
6058 SCREEN_CTRL_ID_NEXT_LEVEL,
6063 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6064 getScreenMenuButtonPos,
6065 SCREEN_CTRL_ID_PREV_PLAYER,
6070 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6071 getScreenMenuButtonPos,
6072 SCREEN_CTRL_ID_NEXT_PLAYER,
6080 int gfx_unpressed, gfx_pressed;
6084 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6087 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6089 -1, -1, /* these values are not constant, but can change at runtime */
6091 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6093 SCREEN_CTRL_ID_SCROLL_UP,
6097 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6099 -1, -1, /* these values are not constant, but can change at runtime */
6101 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6103 SCREEN_CTRL_ID_SCROLL_DOWN,
6110 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6111 Bitmap **gfx_unpressed, **gfx_pressed;
6113 int gfx_unpressed, gfx_pressed;
6120 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6123 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6124 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6126 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6129 -1, -1, /* these values are not constant, but can change at runtime */
6130 -1, -1, /* these values are not constant, but can change at runtime */
6132 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6133 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6135 GD_TYPE_SCROLLBAR_VERTICAL,
6136 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6137 "scroll level series vertically"
6141 static void CreateScreenMenubuttons()
6143 struct GadgetInfo *gi;
6144 unsigned int event_mask;
6147 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6149 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6150 int gfx_unpressed, gfx_pressed;
6151 int x, y, width, height;
6152 int gd_x1, gd_x2, gd_y1, gd_y2;
6153 int id = menubutton_info[i].gadget_id;
6155 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6157 menubutton_info[i].get_gadget_position(&x, &y, id);
6159 width = SC_MENUBUTTON_XSIZE;
6160 height = SC_MENUBUTTON_YSIZE;
6162 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6163 gfx_pressed = menubutton_info[i].gfx_pressed;
6164 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6165 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6166 gd_x1 = graphic_info[gfx_unpressed].src_x;
6167 gd_y1 = graphic_info[gfx_unpressed].src_y;
6168 gd_x2 = graphic_info[gfx_pressed].src_x;
6169 gd_y2 = graphic_info[gfx_pressed].src_y;
6171 gi = CreateGadget(GDI_CUSTOM_ID, id,
6172 GDI_CUSTOM_TYPE_ID, i,
6173 GDI_INFO_TEXT, menubutton_info[i].infotext,
6178 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6179 GDI_STATE, GD_BUTTON_UNPRESSED,
6180 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6181 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6182 GDI_DIRECT_DRAW, FALSE,
6183 GDI_EVENT_MASK, event_mask,
6184 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6188 Error(ERR_EXIT, "cannot create gadget");
6190 screen_gadget[id] = gi;
6194 static void CreateScreenScrollbuttons()
6196 struct GadgetInfo *gi;
6197 unsigned int event_mask;
6200 /* these values are not constant, but can change at runtime */
6201 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6202 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6203 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6204 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6206 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6208 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6209 int gfx_unpressed, gfx_pressed;
6210 int x, y, width, height;
6211 int gd_x1, gd_x2, gd_y1, gd_y2;
6212 int id = scrollbutton_info[i].gadget_id;
6214 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6216 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6217 y = mSY + scrollbutton_info[i].y;
6218 width = SC_SCROLLBUTTON_XSIZE;
6219 height = SC_SCROLLBUTTON_YSIZE;
6221 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6222 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6223 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6225 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6226 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6227 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6228 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6229 gd_x1 = graphic_info[gfx_unpressed].src_x;
6230 gd_y1 = graphic_info[gfx_unpressed].src_y;
6231 gd_x2 = graphic_info[gfx_pressed].src_x;
6232 gd_y2 = graphic_info[gfx_pressed].src_y;
6234 gi = CreateGadget(GDI_CUSTOM_ID, id,
6235 GDI_CUSTOM_TYPE_ID, i,
6236 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6241 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6242 GDI_STATE, GD_BUTTON_UNPRESSED,
6243 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6244 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6245 GDI_DIRECT_DRAW, FALSE,
6246 GDI_EVENT_MASK, event_mask,
6247 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6251 Error(ERR_EXIT, "cannot create gadget");
6253 screen_gadget[id] = gi;
6257 static void CreateScreenScrollbars()
6261 /* these values are not constant, but can change at runtime */
6262 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6263 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6264 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6265 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6267 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6269 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6270 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6271 int gfx_unpressed, gfx_pressed;
6273 int x, y, width, height;
6274 int gd_x1, gd_x2, gd_y1, gd_y2;
6275 struct GadgetInfo *gi;
6276 int items_max, items_visible, item_position;
6277 unsigned int event_mask;
6278 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6279 int id = scrollbar_info[i].gadget_id;
6281 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6283 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6284 y = mSY + scrollbar_info[i].y;
6285 width = scrollbar_info[i].width;
6286 height = scrollbar_info[i].height;
6288 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6289 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6291 items_max = num_page_entries;
6292 items_visible = num_page_entries;
6295 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6296 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6297 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6303 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6304 gfx_pressed = scrollbar_info[i].gfx_pressed;
6305 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6306 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6307 gd_x1 = graphic_info[gfx_unpressed].src_x;
6308 gd_y1 = graphic_info[gfx_unpressed].src_y;
6309 gd_x2 = graphic_info[gfx_pressed].src_x;
6310 gd_y2 = graphic_info[gfx_pressed].src_y;
6313 gi = CreateGadget(GDI_CUSTOM_ID, id,
6314 GDI_CUSTOM_TYPE_ID, i,
6315 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6320 GDI_TYPE, scrollbar_info[i].type,
6321 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6322 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6323 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6325 GDI_WHEEL_AREA_X, SX,
6326 GDI_WHEEL_AREA_Y, SY,
6327 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6328 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6330 GDI_WHEEL_AREA_X, 0,
6331 GDI_WHEEL_AREA_Y, 0,
6332 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6333 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6335 GDI_STATE, GD_BUTTON_UNPRESSED,
6336 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6337 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6338 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6339 GDI_DIRECT_DRAW, FALSE,
6340 GDI_EVENT_MASK, event_mask,
6341 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6345 Error(ERR_EXIT, "cannot create gadget");
6347 screen_gadget[id] = gi;
6351 void CreateScreenGadgets()
6353 int last_game_status = game_status; /* save current game status */
6355 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6358 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6360 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6362 /* copy pointers to clip mask and GC */
6363 scrollbar_bitmap[i]->clip_mask =
6364 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6365 scrollbar_bitmap[i]->stored_clip_gc =
6366 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6368 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6369 scrollbar_bitmap[i],
6370 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6371 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6372 TILEX, TILEY, 0, 0);
6376 CreateScreenMenubuttons();
6379 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6380 game_status = GAME_MODE_LEVELS;
6383 CreateScreenScrollbuttons();
6384 CreateScreenScrollbars();
6386 game_status = last_game_status; /* restore current game status */
6389 void FreeScreenGadgets()
6393 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6394 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6396 /* prevent freeing clip mask and GC twice */
6397 scrollbar_bitmap[i]->clip_mask = None;
6398 scrollbar_bitmap[i]->stored_clip_gc = None;
6400 FreeBitmap(scrollbar_bitmap[i]);
6404 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6405 FreeGadget(screen_gadget[i]);
6408 void MapScreenMenuGadgets(int screen_mask)
6412 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6413 if (screen_mask & menubutton_info[i].screen_mask)
6414 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6417 void MapScreenTreeGadgets(TreeInfo *ti)
6419 int num_entries = numTreeInfoInGroup(ti);
6422 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6425 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6426 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6428 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6429 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6432 static void HandleScreenGadgets(struct GadgetInfo *gi)
6434 int id = gi->custom_id;
6435 int button = gi->event.button;
6436 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6440 case SCREEN_CTRL_ID_PREV_LEVEL:
6441 HandleMainMenu_SelectLevel(step, -1);
6444 case SCREEN_CTRL_ID_NEXT_LEVEL:
6445 HandleMainMenu_SelectLevel(step, +1);
6448 case SCREEN_CTRL_ID_PREV_PLAYER:
6449 HandleSetupScreen_Input_Player(step, -1);
6452 case SCREEN_CTRL_ID_NEXT_PLAYER:
6453 HandleSetupScreen_Input_Player(step, +1);
6456 case SCREEN_CTRL_ID_SCROLL_UP:
6457 if (game_status == GAME_MODE_LEVELS)
6458 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6459 else if (game_status == GAME_MODE_LEVELNR)
6460 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6461 else if (game_status == GAME_MODE_SETUP)
6462 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6465 case SCREEN_CTRL_ID_SCROLL_DOWN:
6466 if (game_status == GAME_MODE_LEVELS)
6467 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6468 else if (game_status == GAME_MODE_LEVELNR)
6469 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6470 else if (game_status == GAME_MODE_SETUP)
6471 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6474 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6475 if (game_status == GAME_MODE_LEVELS)
6476 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6477 else if (game_status == GAME_MODE_LEVELNR)
6478 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6479 else if (game_status == GAME_MODE_SETUP)
6480 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);