1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
28 /* screens on the info screen */
29 #define INFO_MODE_MAIN 0
30 #define INFO_MODE_TITLE 1
31 #define INFO_MODE_ELEMENTS 2
32 #define INFO_MODE_MUSIC 3
33 #define INFO_MODE_CREDITS 4
34 #define INFO_MODE_PROGRAM 5
35 #define INFO_MODE_VERSION 6
36 #define INFO_MODE_LEVELSET 7
38 #define MAX_INFO_MODES 8
40 /* screens on the setup screen */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_SHORTCUTS_1 7
49 #define SETUP_MODE_SHORTCUTS_2 8
51 /* sub-screens on the setup screen (generic) */
52 #define SETUP_MODE_CHOOSE_ARTWORK 9
53 #define SETUP_MODE_CHOOSE_OTHER 10
55 /* sub-screens on the setup screen (specific) */
56 #define SETUP_MODE_CHOOSE_GAME_SPEED 11
57 #define SETUP_MODE_CHOOSE_SCREEN_MODE 12
58 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 13
59 #define SETUP_MODE_CHOOSE_GRAPHICS 14
60 #define SETUP_MODE_CHOOSE_SOUNDS 15
61 #define SETUP_MODE_CHOOSE_MUSIC 16
63 #define MAX_SETUP_MODES 17
65 /* for input setup functions */
66 #define SETUPINPUT_SCREEN_POS_START 0
67 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
68 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
69 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
71 /* for various menu stuff */
72 #define MENU_SCREEN_START_XPOS 1
73 #define MENU_SCREEN_START_YPOS 2
74 #define MENU_SCREEN_VALUE_XPOS 14
75 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
76 #define MENU_TITLE1_YPOS 8
77 #define MENU_TITLE2_YPOS 46
78 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
79 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
80 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
81 MENU_SCREEN_START_XPOS)
82 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
84 /* buttons and scrollbars identifiers */
85 #define SCREEN_CTRL_ID_PREV_LEVEL 0
86 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
87 #define SCREEN_CTRL_ID_PREV_PLAYER 2
88 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
89 #define SCREEN_CTRL_ID_SCROLL_UP 4
90 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
91 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
93 #define NUM_SCREEN_GADGETS 7
95 #define NUM_SCREEN_MENUBUTTONS 4
96 #define NUM_SCREEN_SCROLLBUTTONS 2
97 #define NUM_SCREEN_SCROLLBARS 1
99 #define SCREEN_MASK_MAIN (1 << 0)
100 #define SCREEN_MASK_INPUT (1 << 1)
102 /* graphic position and size values for buttons and scrollbars */
103 #define SC_MENUBUTTON_XSIZE TILEX
104 #define SC_MENUBUTTON_YSIZE TILEY
106 #define SC_SCROLLBUTTON_XSIZE TILEX
107 #define SC_SCROLLBUTTON_YSIZE TILEY
109 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
111 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
112 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
113 SC_SCROLLBUTTON_YSIZE)
115 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
118 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
119 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
120 SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
124 SC_SCROLL_VERTICAL_YSIZE)
126 #define SC_BORDER_SIZE 14
128 /* other useful macro definitions */
129 #define BUTTON_GRAPHIC_ACTIVE(g) \
130 (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE : \
131 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE : \
132 g == IMG_MENU_BUTTON_UP ? IMG_MENU_BUTTON_UP_ACTIVE : \
133 g == IMG_MENU_BUTTON_DOWN ? IMG_MENU_BUTTON_DOWN_ACTIVE : \
134 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE : \
135 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE : \
136 g == IMG_MENU_BUTTON_PREV_LEVEL ? IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE : \
137 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE : \
138 IMG_MENU_BUTTON_ACTIVE)
141 /* forward declarations of internal functions */
142 static void HandleScreenGadgets(struct GadgetInfo *);
143 static void HandleSetupScreen_Generic(int, int, int, int, int);
144 static void HandleSetupScreen_Input(int, int, int, int, int);
145 static void CustomizeKeyboard(int);
146 static void CalibrateJoystick(int);
147 static void execSetupGame(void);
148 static void execSetupGraphics(void);
149 static void execSetupArtwork(void);
150 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
152 static void DrawChooseLevel(void);
153 static void DrawInfoScreen(void);
154 static void DrawAndFadeInInfoScreen(int);
155 static void DrawSetupScreen(void);
157 static void DrawInfoScreenExt(int, int);
158 static void DrawInfoScreen_NotAvailable(char *, char *);
159 static void DrawInfoScreen_HelpAnim(int, int, boolean);
160 static void DrawInfoScreen_HelpText(int, int, int, int);
161 static void HandleInfoScreen_Main(int, int, int, int, int);
162 static void HandleInfoScreen_TitleScreen(int);
163 static void HandleInfoScreen_Elements(int);
164 static void HandleInfoScreen_Music(int);
165 static void HandleInfoScreen_Credits(int);
166 static void HandleInfoScreen_Program(int);
167 static void HandleInfoScreen_Version(int);
169 static void MapScreenMenuGadgets(int);
170 static void MapScreenTreeGadgets(TreeInfo *);
172 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
174 static int info_mode = INFO_MODE_MAIN;
175 static int setup_mode = SETUP_MODE_MAIN;
177 static TreeInfo *screen_modes = NULL;
178 static TreeInfo *screen_mode_current = NULL;
180 static TreeInfo *scroll_delays = NULL;
181 static TreeInfo *scroll_delay_current = NULL;
183 static TreeInfo *game_speeds = NULL;
184 static TreeInfo *game_speed_current = NULL;
190 } game_speeds_list[] =
199 { 1000, "1/1s (Extremely Slow)" },
204 { 29, "1/35s (Original Supaplex)" },
206 { 20, "1/50s (Normal Speed)" },
207 { 14, "1/70s (Maximum Supaplex)" },
211 { 1, "1/1000s (Extremely Fast)" },
221 } scroll_delays_list[] =
223 { 0, "0 Tiles (No Scroll Delay)" },
226 { 3, "3 Tiles (Default)" },
231 { 8, "8 Tiles (Maximum Scroll Delay)"},
236 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
237 (s) <= GAME_MODE_SETUP ? (s) : \
238 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
239 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
241 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
242 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
243 (i) <= INFO_MODE_LEVELSET ? (i) : \
246 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
247 (i) <= SETUP_MODE_SHORTCUTS_2 ? (i) : \
248 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
249 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
250 SETUP_MODE_CHOOSE_ARTWORK : \
251 SETUP_MODE_CHOOSE_OTHER)
253 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
254 menu.draw_xoffset[GAME_MODE_INFO] : \
255 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
256 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
257 menu.draw_yoffset[GAME_MODE_INFO] : \
258 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
260 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
261 menu.draw_xoffset[GAME_MODE_SETUP] : \
262 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
263 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
264 menu.draw_yoffset[GAME_MODE_SETUP] : \
265 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
267 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
268 DRAW_XOFFSET_INFO(info_mode) : \
269 (s) == GAME_MODE_SETUP ? \
270 DRAW_XOFFSET_SETUP(setup_mode) : \
271 menu.draw_xoffset[DRAW_MODE(s)])
272 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
273 DRAW_YOFFSET_INFO(info_mode) : \
274 (s) == GAME_MODE_SETUP ? \
275 DRAW_YOFFSET_SETUP(setup_mode) : \
276 menu.draw_yoffset[DRAW_MODE(s)])
278 #define mSX (SX + DRAW_XOFFSET(game_status))
279 #define mSY (SY + DRAW_YOFFSET(game_status))
281 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
282 menu.list_size[game_status] : \
283 MAX_MENU_ENTRIES_ON_SCREEN)
285 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
286 #define NUM_SCROLLBAR_BITMAPS 2
287 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
291 /* title display and control definitions */
293 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
294 2 * MAX_NUM_TITLE_MESSAGES)
296 static int num_title_screens = 0;
298 struct TitleControlInfo
306 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
308 /* main menu display and control definitions */
310 #define MAIN_CONTROL_NAME 0
311 #define MAIN_CONTROL_LEVELS 1
312 #define MAIN_CONTROL_SCORES 2
313 #define MAIN_CONTROL_EDITOR 3
314 #define MAIN_CONTROL_INFO 4
315 #define MAIN_CONTROL_GAME 5
316 #define MAIN_CONTROL_SETUP 6
317 #define MAIN_CONTROL_QUIT 7
318 #define MAIN_CONTROL_PREV_LEVEL 8
319 #define MAIN_CONTROL_NEXT_LEVEL 9
320 #define MAIN_CONTROL_FIRST_LEVEL 10
321 #define MAIN_CONTROL_LAST_LEVEL 11
322 #define MAIN_CONTROL_LEVEL_NUMBER 12
323 #define MAIN_CONTROL_LEVEL_INFO_1 13
324 #define MAIN_CONTROL_LEVEL_INFO_2 14
325 #define MAIN_CONTROL_LEVEL_NAME 15
326 #define MAIN_CONTROL_LEVEL_AUTHOR 16
327 #define MAIN_CONTROL_LEVEL_YEAR 17
328 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
329 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
330 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
331 #define MAIN_CONTROL_TITLE_1 21
332 #define MAIN_CONTROL_TITLE_2 22
333 #define MAIN_CONTROL_TITLE_3 23
335 static char str_main_text_name[10];
336 static char str_main_text_first_level[10];
337 static char str_main_text_last_level[10];
338 static char str_main_text_level_number[10];
340 static char *main_text_name = str_main_text_name;
341 static char *main_text_first_level = str_main_text_first_level;
342 static char *main_text_last_level = str_main_text_last_level;
343 static char *main_text_level_number = str_main_text_level_number;
344 static char *main_text_levels = "Levelset";
345 static char *main_text_scores = "Hall Of Fame";
346 static char *main_text_editor = "Level Creator";
347 static char *main_text_info = "Info Screen";
348 static char *main_text_game = "Start Game";
349 static char *main_text_setup = "Setup";
350 static char *main_text_quit = "Quit";
351 static char *main_text_level_name = level.name;
352 static char *main_text_level_author = level.author;
353 static char *main_text_level_year = NULL;
354 static char *main_text_level_imported_from = NULL;
355 static char *main_text_level_imported_by = NULL;
356 static char *main_text_level_tested_by = NULL;
357 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
358 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
359 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
361 struct MainControlInfo
365 struct MenuPosInfo *pos_button;
368 struct TextPosInfo *pos_text;
371 struct TextPosInfo *pos_input;
375 static struct MainControlInfo main_controls[] =
379 &menu.main.button.name, IMG_MENU_BUTTON,
380 &menu.main.text.name, &main_text_name,
381 &menu.main.input.name, &setup.player_name,
385 &menu.main.button.levels, IMG_MENU_BUTTON_ENTER_MENU,
386 &menu.main.text.levels, &main_text_levels,
391 &menu.main.button.scores, IMG_MENU_BUTTON,
392 &menu.main.text.scores, &main_text_scores,
397 &menu.main.button.editor, IMG_MENU_BUTTON,
398 &menu.main.text.editor, &main_text_editor,
403 &menu.main.button.info, IMG_MENU_BUTTON_ENTER_MENU,
404 &menu.main.text.info, &main_text_info,
409 &menu.main.button.game, IMG_MENU_BUTTON,
410 &menu.main.text.game, &main_text_game,
415 &menu.main.button.setup, IMG_MENU_BUTTON_ENTER_MENU,
416 &menu.main.text.setup, &main_text_setup,
421 &menu.main.button.quit, IMG_MENU_BUTTON,
422 &menu.main.text.quit, &main_text_quit,
426 /* (these two buttons are real gadgets) */
428 MAIN_CONTROL_PREV_LEVEL,
429 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
434 MAIN_CONTROL_NEXT_LEVEL,
435 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
441 MAIN_CONTROL_FIRST_LEVEL,
443 &menu.main.text.first_level, &main_text_first_level,
447 MAIN_CONTROL_LAST_LEVEL,
449 &menu.main.text.last_level, &main_text_last_level,
453 MAIN_CONTROL_LEVEL_NUMBER,
455 &menu.main.text.level_number, &main_text_level_number,
459 MAIN_CONTROL_LEVEL_INFO_1,
461 &menu.main.text.level_info_1, NULL,
465 MAIN_CONTROL_LEVEL_INFO_2,
467 &menu.main.text.level_info_2, NULL,
471 MAIN_CONTROL_LEVEL_NAME,
473 &menu.main.text.level_name, &main_text_level_name,
477 MAIN_CONTROL_LEVEL_AUTHOR,
479 &menu.main.text.level_author, &main_text_level_author,
483 MAIN_CONTROL_LEVEL_YEAR,
485 &menu.main.text.level_year, &main_text_level_year,
489 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
491 &menu.main.text.level_imported_from, &main_text_level_imported_from,
495 MAIN_CONTROL_LEVEL_IMPORTED_BY,
497 &menu.main.text.level_imported_by, &main_text_level_imported_by,
501 MAIN_CONTROL_LEVEL_TESTED_BY,
503 &menu.main.text.level_tested_by, &main_text_level_tested_by,
507 MAIN_CONTROL_TITLE_1,
509 &menu.main.text.title_1, &main_text_title_1,
513 MAIN_CONTROL_TITLE_2,
515 &menu.main.text.title_2, &main_text_title_2,
519 MAIN_CONTROL_TITLE_3,
521 &menu.main.text.title_3, &main_text_title_3,
534 static int getTitleScreenGraphic(int nr, boolean initial)
536 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
539 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
541 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
545 static int getTitleScreenGameMode(boolean initial)
547 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
551 static int getTitleMessageGameMode(boolean initial)
553 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
557 static int getTitleScreenBackground(boolean initial)
559 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
564 static int getTitleMessageBackground(int nr, boolean initial)
566 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
570 static int getTitleBackground(int nr, boolean initial, boolean is_image)
572 int base = (is_image ?
573 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
574 IMG_BACKGROUND_TITLESCREEN_1) :
575 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
576 IMG_BACKGROUND_TITLEMESSAGE_1));
577 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
578 IMG_BACKGROUND_TITLE);
579 int graphic_local = base + nr;
581 if (graphic_info[graphic_local].bitmap != NULL)
582 return graphic_local;
584 if (graphic_info[graphic_global].bitmap != NULL)
585 return graphic_global;
587 return IMG_UNDEFINED;
590 static int getTitleSound(struct TitleControlInfo *tci)
592 boolean is_image = tci->is_image;
593 int initial = tci->initial;
594 int nr = tci->local_nr;
595 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
596 int base = (is_image ?
597 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
598 SND_BACKGROUND_TITLESCREEN_1) :
599 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
600 SND_BACKGROUND_TITLEMESSAGE_1));
601 int sound_global = menu.sound[mode];
602 int sound_local = base + nr;
605 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
606 nr, initial, is_image,
607 sound_global, getSoundListEntry(sound_global)->filename,
608 sound_local, getSoundListEntry(sound_local)->filename);
611 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
614 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
617 return SND_UNDEFINED;
620 static int getTitleMusic(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 ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
628 MUS_BACKGROUND_TITLESCREEN_1) :
629 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
630 MUS_BACKGROUND_TITLEMESSAGE_1));
631 int music_global = menu.music[mode];
632 int music_local = base + nr;
635 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
636 nr, initial, is_image,
637 music_global, getMusicListEntry(music_global)->filename,
638 music_local, getMusicListEntry(music_local)->filename);
641 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
644 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
647 return MUS_UNDEFINED;
650 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
652 boolean is_image = tci->is_image;
653 int initial = tci->initial;
654 int nr = tci->local_nr;
655 struct TitleFadingInfo ti;
659 int graphic = getTitleScreenGraphic(nr, initial);
661 /* initialize fading control values to default title config settings */
662 ti = (initial ? title_initial_default : title_default);
664 /* override default settings with image config settings, if defined */
665 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
666 ti.fade_mode = graphic_info[graphic].fade_mode;
667 if (graphic_info[graphic].fade_delay > -1)
668 ti.fade_delay = graphic_info[graphic].fade_delay;
669 if (graphic_info[graphic].post_delay > -1)
670 ti.post_delay = graphic_info[graphic].post_delay;
671 if (graphic_info[graphic].auto_delay > -1)
672 ti.auto_delay = graphic_info[graphic].auto_delay;
678 ti.fade_mode = titlemessage_initial[nr].fade_mode;
679 ti.fade_delay = titlemessage_initial[nr].fade_delay;
680 ti.post_delay = titlemessage_initial[nr].post_delay;
681 ti.auto_delay = titlemessage_initial[nr].auto_delay;
685 ti.fade_mode = titlemessage[nr].fade_mode;
686 ti.fade_delay = titlemessage[nr].fade_delay;
687 ti.post_delay = titlemessage[nr].post_delay;
688 ti.auto_delay = titlemessage[nr].auto_delay;
693 if (ti.anim_mode == ANIM_NONE)
694 ti.fade_delay = ti.post_delay = 0;
700 static int compareTitleControlInfo(const void *object1, const void *object2)
702 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
703 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
706 if (tci1->initial != tci2->initial)
707 compare_result = (tci1->initial ? -1 : +1);
708 else if (tci1->sort_priority != tci2->sort_priority)
709 compare_result = tci1->sort_priority - tci2->sort_priority;
710 else if (tci1->is_image != tci2->is_image)
711 compare_result = (tci1->is_image ? -1 : +1);
713 compare_result = tci1->local_nr - tci2->local_nr;
715 return compare_result;
718 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
720 int nr, int sort_priority)
722 title_controls[num_title_screens].is_image = is_image;
723 title_controls[num_title_screens].initial = initial;
724 title_controls[num_title_screens].local_nr = nr;
725 title_controls[num_title_screens].sort_priority = sort_priority;
730 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
734 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
736 int graphic = getTitleScreenGraphic(i, initial);
737 Bitmap *bitmap = graphic_info[graphic].bitmap;
738 int sort_priority = graphic_info[graphic].sort_priority;
741 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
744 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
746 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
747 char *filename = getLevelSetTitleMessageFilename(i, initial);
748 int sort_priority = tmi->sort_priority;
750 if (filename != NULL)
751 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
755 static void InitializeTitleControls(boolean show_title_initial)
757 num_title_screens = 0;
759 if (show_title_initial)
760 InitializeTitleControls_CheckTitleInfo(TRUE);
762 InitializeTitleControls_CheckTitleInfo(FALSE);
764 /* sort title screens according to sort_priority and title number */
765 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
766 compareTitleControlInfo);
769 static boolean visibleMenuPos(struct MenuPosInfo *pos)
771 return (pos != NULL && pos->x != -1 && pos->y != -1);
774 static boolean visibleTextPos(struct TextPosInfo *pos)
776 return (pos != NULL && pos->x != -1 && pos->y != -1);
779 static void InitializeMainControls()
781 boolean local_team_mode = (!options.network && setup.team_mode);
784 /* set main control text values to dynamically determined values */
785 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
787 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
788 menu.main.text.first_level.size));
789 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
790 menu.main.text.last_level.size));
791 strcpy(main_text_level_number, int2str(level_nr,
792 menu.main.text.level_number.size));
794 main_text_level_year = leveldir_current->year;
795 main_text_level_imported_from = leveldir_current->imported_from;
796 main_text_level_imported_by = leveldir_current->imported_by;
797 main_text_level_tested_by = leveldir_current->tested_by;
799 /* set main control screen positions to dynamically determined values */
800 for (i = 0; main_controls[i].nr != -1; i++)
802 struct MainControlInfo *mci = &main_controls[i];
804 struct MenuPosInfo *pos_button = mci->pos_button;
805 struct TextPosInfo *pos_text = mci->pos_text;
806 struct TextPosInfo *pos_input = mci->pos_input;
807 char *text = (mci->text ? *mci->text : NULL);
808 char *input = (mci->input ? *mci->input : NULL);
809 int button_graphic = mci->button_graphic;
811 int font_text = (pos_text ? pos_text->font : -1);
812 int font_input = (pos_input ? pos_input->font : -1);
814 int font_text = mci->font_text;
815 int font_input = mci->font_input;
818 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
819 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
820 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
821 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
822 int text_chars = (text != NULL ? strlen(text) : 0);
823 int input_chars = (input != NULL ? strlen(input) : 0);
826 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
828 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
829 int text_width = font_text_width * text_chars;
830 int text_height = font_text_height;
831 int input_width = font_input_width * input_chars;
832 int input_height = font_input_height;
834 if (nr == MAIN_CONTROL_NAME)
837 if (menu.main.input.name.x == -1)
838 menu.main.input.name.x = menu.main.text.name.x + text_width;
839 if (menu.main.input.name.y == -1)
840 menu.main.input.name.y = menu.main.text.name.y;
844 menu.main.input.name.width = input_width;
845 menu.main.input.name.height = input_height;
847 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
848 menu.main.input.name.height = font_input_height;
852 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
854 if (pos_button->width == 0)
855 pos_button->width = button_width;
856 if (pos_button->height == 0)
857 pos_button->height = button_height;
860 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
862 /* calculate width for non-clickable text -- needed for text alignment */
863 boolean calculate_text_width = (pos_button == NULL && text != NULL);
865 if (visibleMenuPos(pos_button))
867 if (pos_text->x == -1)
868 pos_text->x = pos_button->x + pos_button->width;
869 if (pos_text->y == -1)
870 pos_text->y = pos_button->y;
873 if (pos_text->width == -1 || calculate_text_width)
874 pos_text->width = text_width;
875 if (pos_text->height == -1)
876 pos_text->height = text_height;
879 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
881 if (visibleTextPos(pos_text))
883 if (pos_input->x == -1)
884 pos_input->x = pos_text->x + pos_text->width;
885 if (pos_input->y == -1)
886 pos_input->y = pos_text->y;
889 if (pos_input->width == -1)
890 pos_input->width = input_width;
891 if (pos_input->height == -1)
892 pos_input->height = input_height;
897 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
898 boolean active_input)
902 for (i = 0; main_controls[i].nr != -1; i++)
904 struct MainControlInfo *mci = &main_controls[i];
906 if (mci->nr == nr || nr == -1)
908 struct MenuPosInfo *pos_button = mci->pos_button;
909 struct TextPosInfo *pos_text = mci->pos_text;
910 struct TextPosInfo *pos_input = mci->pos_input;
911 char *text = (mci->text ? *mci->text : NULL);
912 char *input = (mci->input ? *mci->input : NULL);
913 int button_graphic = mci->button_graphic;
915 int font_text = (pos_text ? pos_text->font : -1);
916 int font_input = (pos_input ? pos_input->font : -1);
918 int font_text = mci->font_text;
919 int font_input = mci->font_input;
924 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
925 font_text = FONT_ACTIVE(font_text);
930 font_input = FONT_ACTIVE(font_input);
933 if (visibleMenuPos(pos_button))
935 struct MenuPosInfo *pos = pos_button;
936 int x = mSX + pos->x;
937 int y = mSY + pos->y;
939 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
940 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
943 if (visibleTextPos(pos_text) && text != NULL)
945 struct TextPosInfo *pos = pos_text;
946 int x = mSX + ALIGNED_TEXT_XPOS(pos);
947 int y = mSY + ALIGNED_TEXT_YPOS(pos);
950 /* (check why/if this is needed) */
951 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
953 DrawText(x, y, text, font_text);
956 if (visibleTextPos(pos_input) && input != NULL)
958 struct TextPosInfo *pos = pos_input;
959 int x = mSX + ALIGNED_TEXT_XPOS(pos);
960 int y = mSY + ALIGNED_TEXT_YPOS(pos);
963 /* (check why/if this is needed) */
964 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
966 DrawText(x, y, input, font_input);
972 static void DrawCursorAndText_Main(int nr, boolean active_text)
974 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
978 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
980 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
984 static struct MainControlInfo *getMainControlInfo(int nr)
988 for (i = 0; main_controls[i].nr != -1; i++)
989 if (main_controls[i].nr == nr)
990 return &main_controls[i];
995 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1000 int rect_x = ALIGNED_TEXT_XPOS(rect);
1001 int rect_y = ALIGNED_TEXT_YPOS(rect);
1003 return (x >= rect_x && x < rect_x + rect->width &&
1004 y >= rect_y && y < rect_y + rect->height);
1007 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1012 int rect_x = ALIGNED_TEXT_XPOS(rect);
1013 int rect_y = ALIGNED_TEXT_YPOS(rect);
1015 return (x >= rect_x && x < rect_x + rect->width &&
1016 y >= rect_y && y < rect_y + rect->height);
1019 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1021 static int cursor_array[SCR_FIELDY];
1022 int x = mSX + TILEX * xpos;
1023 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1028 cursor_array[ypos] = graphic;
1030 graphic = cursor_array[ypos];
1034 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
1036 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1037 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1040 static void initCursor(int ypos, int graphic)
1042 drawCursorExt(0, ypos, FALSE, graphic);
1045 static void drawCursor(int ypos, boolean active)
1047 drawCursorExt(0, ypos, active, -1);
1050 static void drawCursorXY(int xpos, int ypos, int graphic)
1052 drawCursorExt(xpos, ypos, FALSE, graphic);
1055 static void drawChooseTreeCursor(int ypos, boolean active)
1057 int last_game_status = game_status; /* save current game status */
1060 /* force LEVELS draw offset on artwork setup screen */
1061 game_status = GAME_MODE_LEVELS;
1064 drawCursorExt(0, ypos, active, -1);
1066 game_status = last_game_status; /* restore current game status */
1071 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1072 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1076 static int getPrevlevelButtonPos()
1081 static int getCurrentLevelTextPos()
1083 return (getPrevlevelButtonPos() + 1);
1086 static int getNextLevelButtonPos()
1088 return getPrevlevelButtonPos() + 3 + 1;
1091 static int getLevelRangeTextPos()
1093 return getNextLevelButtonPos() + 1;
1097 int effectiveGameStatus()
1099 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1100 return GAME_MODE_TITLE;
1105 void DrawTitleScreenImage(int nr, boolean initial)
1107 int graphic = getTitleScreenGraphic(nr, initial);
1108 Bitmap *bitmap = graphic_info[graphic].bitmap;
1110 int width = graphic_info[graphic].width;
1111 int height = graphic_info[graphic].height;
1112 int src_x = graphic_info[graphic].src_x;
1113 int src_y = graphic_info[graphic].src_y;
1115 int width = graphic_info[graphic].src_image_width;
1116 int height = graphic_info[graphic].src_image_height;
1117 int src_x = 0, src_y = 0;
1124 if (width > WIN_XSIZE)
1126 /* image width too large for window => center image horizontally */
1127 src_x = (width - WIN_XSIZE) / 2;
1131 if (height > WIN_YSIZE)
1133 /* image height too large for window => center image vertically */
1134 src_y = (height - WIN_YSIZE) / 2;
1138 /* always display title screens centered */
1139 dst_x = (WIN_XSIZE - width) / 2;
1140 dst_y = (WIN_YSIZE - height) / 2;
1142 SetDrawBackgroundMask(REDRAW_ALL);
1143 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1145 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1147 if (DrawingOnBackground(dst_x, dst_y))
1148 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1150 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1152 redraw_mask = REDRAW_ALL;
1154 /* reset fading control values to default config settings */
1158 title = getTitleFading(nr, initial, TRUE);
1163 title.fade_delay_final = title.fade_delay;
1164 title.post_delay_final = title.post_delay;
1165 title.auto_delay_final = title.auto_delay;
1167 /* override default settings with image config settings, if defined */
1168 if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
1169 title.anim_mode = graphic_info[graphic].anim_mode;
1170 if (graphic_info[graphic].fade_delay > -1)
1171 title.fade_delay = graphic_info[graphic].fade_delay;
1172 if (graphic_info[graphic].post_delay > -1)
1173 title.post_delay = graphic_info[graphic].post_delay;
1174 if (graphic_info[graphic].auto_delay > -1)
1175 title.auto_delay = graphic_info[graphic].auto_delay;
1179 void DrawTitleScreenMessage(int nr, boolean initial)
1181 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1182 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1184 int font_nr = FONT_TEXT_1;
1188 int pad_y = 32 + 14;
1191 int max_chars_per_line;
1192 int max_lines_per_screen;
1194 int last_game_status = game_status; /* save current game status */
1196 if (filename == NULL)
1199 /* force TITLE font on title message screen */
1200 game_status = getTitleMessageGameMode(initial);
1202 /* if chars set to "-1", automatically determine by text and font width */
1203 if (tmi->chars == -1)
1204 tmi->chars = tmi->width / getFontWidth(tmi->font);
1206 tmi->width = tmi->chars * getFontWidth(tmi->font);
1208 /* if lines set to "-1", automatically determine by text and font height */
1209 if (tmi->lines == -1)
1210 tmi->lines = tmi->height / getFontHeight(tmi->font);
1212 tmi->height = tmi->lines * getFontHeight(tmi->font);
1214 SetDrawBackgroundMask(REDRAW_ALL);
1215 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1217 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1220 font_width = getFontWidth(font_nr);
1221 font_height = getFontHeight(font_nr);
1222 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1223 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1227 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1228 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1229 tmi->autowrap, tmi->centered, tmi->parse_comments);
1231 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1232 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1233 tmi->parse_comments);
1236 game_status = last_game_status; /* restore current game status */
1239 void DrawTitleScreen()
1241 KeyboardAutoRepeatOff();
1244 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1247 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1252 boolean CheckTitleScreen(boolean levelset_has_changed)
1254 static boolean show_title_initial = TRUE;
1255 boolean show_titlescreen = FALSE;
1257 /* needed to be able to skip title screen, if no image or message defined */
1258 InitializeTitleControls(show_title_initial);
1260 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1261 show_titlescreen = TRUE;
1263 /* show initial title images and messages only once at program start */
1264 show_title_initial = FALSE;
1266 return (show_titlescreen && num_title_screens > 0);
1269 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1271 static LevelDirTree *leveldir_last_valid = NULL;
1272 boolean levelset_has_changed = FALSE;
1274 boolean local_team_mode = (!options.network && setup.team_mode);
1275 char *name_text = (local_team_mode ? "Team:" : "Name:");
1276 int name_width, level_width;
1283 /* !!! CHANGE THIS !!! */
1284 title = title_default;
1289 int graphicA = element_info[EL_EM_DYNAMITE_ACTIVE].special_graphic[GFX_SPECIAL_ARG_EDITOR];
1290 int graphicB = element_info[EL_EM_DYNAMITE_ACTIVE].special_graphic[GFX_SPECIAL_ARG_PANEL];
1291 int graphic1 = element_info[EL_CONVEYOR_BELT_1_MIDDLE].special_graphic[GFX_SPECIAL_ARG_EDITOR];
1292 int graphic2 = element_info[EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE].special_graphic[GFX_SPECIAL_ARG_EDITOR];
1294 printf("::: %d [%d] -> %d, %d [%d, %d]\n",
1296 graphic_info[graphicA].src_x,
1297 graphic_info[graphicA].src_y,
1298 graphic1, graphic2);
1303 printf("::: %d, %d\n", fading.anim_mode == ANIM_CROSSFADE,
1304 redraw_mask == REDRAW_ALL);
1307 FadeSetLeaveScreen();
1310 FadeOut(redraw_mask);
1314 FadeSoundsAndMusic();
1316 KeyboardAutoRepeatOn();
1319 SetDrawDeactivationMask(REDRAW_NONE);
1320 SetDrawBackgroundMask(REDRAW_FIELD);
1322 audio.sound_deactivated = FALSE;
1326 /* needed if last screen was the playing screen, invoked from level editor */
1327 if (level_editor_test_game)
1329 game_status = GAME_MODE_EDITOR;
1335 /* needed if last screen was the editor screen */
1336 UndrawSpecialEditorDoor();
1338 /* needed if last screen was the setup screen and fullscreen state changed */
1339 ToggleFullscreenIfNeeded();
1341 /* leveldir_current may be invalid (level group, parent link) */
1342 if (!validLevelSeries(leveldir_current))
1343 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1345 if (leveldir_current != leveldir_last_valid)
1346 levelset_has_changed = TRUE;
1348 /* store valid level series information */
1349 leveldir_last_valid = leveldir_current;
1351 /* needed if last screen (level choice) changed graphics, sounds or music */
1352 ReloadCustomArtwork(0);
1354 #if defined(TARGET_SDL)
1355 SetDrawtoField(DRAW_BACKBUFFER);
1359 if (levelset_has_changed)
1360 fading = title_default;
1364 if (CheckTitleScreen(levelset_has_changed))
1366 game_status = GAME_MODE_TITLE;
1375 if (setup.show_titlescreen &&
1376 ((levelset_has_changed &&
1377 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1378 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1379 (show_title_initial &&
1380 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1381 getLevelSetMessageFilename(1, TRUE) != NULL))))
1383 game_status = GAME_MODE_TITLE;
1391 /* level_nr may have been set to value over handicap with level editor */
1392 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1393 level_nr = leveldir_current->handicap_level;
1395 LoadLevel(level_nr);
1397 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1400 FadeOut(redraw_mask);
1404 if (redraw_mask == REDRAW_ALL)
1407 int door_state = GetDoorState();
1412 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1416 OpenDoor(DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1418 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1427 InitializeMainControls();
1430 DrawCursorAndText_Main(-1, FALSE);
1432 for (i = 0; main_controls[i].nr != -1; i++)
1434 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1435 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1436 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1437 char *text = main_controls[i].text;
1438 char *input = main_controls[i].input;
1439 int button_graphic = main_controls[i].button_graphic;
1440 int font_text = main_controls[i].font_text;
1441 int font_input = main_controls[i].font_input;
1443 if (pos_button != NULL)
1444 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1447 if (pos_text != NULL && text != NULL)
1448 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1450 if (pos_input != NULL && input != NULL)
1451 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1459 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1460 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1461 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1462 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1463 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1464 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1465 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1466 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1468 /* calculated after (possible) reload of custom artwork */
1469 name_width = getTextWidth(name_text, FONT_MENU_1);
1470 level_width = 9 * 32;
1472 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1475 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1476 int2str(level_nr, 3), FONT_VALUE_1);
1479 int text_height = getFontHeight(FONT_TEXT_3);
1480 int xpos = getLevelRangeTextPos() * 32 + 8;
1481 int ypos2 = 3 * 32 + 16;
1482 int ypos1 = ypos2 - text_height;
1484 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1485 "%03d", leveldir_current->first_level);
1486 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1487 "%03d", leveldir_current->last_level);
1490 for (i = 0; i < 8; i++)
1491 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1494 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1497 DrawPreviewLevel(TRUE);
1499 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1502 if (TAPE_IS_EMPTY(tape))
1504 DrawCompleteVideoDisplay();
1509 /* create gadgets for main menu screen */
1510 FreeScreenGadgets();
1511 CreateScreenGadgets();
1514 BlitBitmap(drawto, window, VX, VY, VXSIZE, VYSIZE, VX, VY);
1518 /* map gadgets for main menu screen */
1520 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1522 DrawMaskedBorder(REDRAW_ALL);
1525 if (redraw_mask == REDRAW_ALL)
1527 int door_state = GetDoorState();
1529 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1535 game_status = GAME_MODE_PSEUDO_PREVIEW;
1537 DrawText(20, 400, "text_3.PREVIEW", FONT_TEXT_3);
1538 DrawText(20, 420, "text_4.PREVIEW", FONT_TEXT_4);
1540 game_status = GAME_MODE_MAIN;
1542 DrawText(20, 440, "text_3.MAIN", FONT_TEXT_3);
1543 DrawText(20, 460, "text_4.MAIN", FONT_TEXT_4);
1548 FadeIn(redraw_mask);
1553 else if (fading.anim_mode == ANIM_CROSSFADE)
1554 FadeCross(redraw_mask);
1556 FadeIn(redraw_mask);
1559 FadeIn(redraw_mask);
1568 fading = title_default;
1571 SetMouseCursor(CURSOR_DEFAULT);
1575 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1578 void DrawAndFadeInMainMenu(int redraw_mask)
1580 DrawMainMenuExt(redraw_mask, TRUE);
1585 DrawMainMenuExt(REDRAW_ALL, FALSE);
1589 static void gotoTopLevelDir()
1591 /* move upwards to top level directory */
1592 while (leveldir_current->node_parent)
1594 /* write a "path" into level tree for easy navigation to last level */
1595 if (leveldir_current->node_parent->node_group->cl_first == -1)
1597 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1598 int leveldir_pos = posTreeInfo(leveldir_current);
1599 int num_page_entries;
1600 int cl_first, cl_cursor;
1602 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1603 num_page_entries = num_leveldirs;
1605 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1607 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1608 cl_cursor = leveldir_pos - cl_first;
1610 leveldir_current->node_parent->node_group->cl_first = cl_first;
1611 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1614 leveldir_current = leveldir_current->node_parent;
1619 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1621 static unsigned long title_delay = 0;
1622 static int title_screen_nr = 0;
1623 static int last_sound = -1, last_music = -1;
1624 boolean return_to_main_menu = FALSE;
1625 boolean use_fading_main_menu = TRUE;
1628 boolean use_cross_fading = FALSE;
1630 boolean use_cross_fading = !show_title_initial; /* default */
1633 struct TitleControlInfo *tci;
1634 struct TitleFadingInfo fading_default;
1635 struct TitleFadingInfo fading_last = fading;
1636 struct TitleFadingInfo fading_next;
1639 if (button == MB_MENU_INITIALIZE)
1642 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1646 int last_game_status = game_status; /* save current game status */
1650 title_screen_nr = 0;
1651 tci = &title_controls[title_screen_nr];
1653 last_sound = SND_UNDEFINED;
1654 last_music = MUS_UNDEFINED;
1657 /* determine number of title screens to display (images and messages) */
1658 InitializeTitleControls();
1661 if (game_status == GAME_MODE_INFO)
1663 if (num_title_screens == 0)
1665 DrawInfoScreen_NotAvailable("Title screen information:",
1666 "No title screen for this level set.");
1669 /* use default settings for fading, but always disable auto delay */
1670 fading = title_default;
1671 fading.auto_delay = -1;
1677 FadeSoundsAndMusic();
1680 FadeOut(REDRAW_ALL);
1685 DrawTitleScreenImage(tci->local_nr, tci->initial);
1687 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1689 fading_default = (tci->initial ? title_initial_default : title_default);
1691 fading = fading_next = getTitleFading(tci);
1695 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1696 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1698 fading.fade_mode = FADE_MODE_FADE;
1699 fading.fade_delay = fading_default.fade_delay;
1702 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1703 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1704 fading.fade_mode = FADE_MODE_FADE;
1709 sound = getTitleSound(tci);
1710 music = getTitleMusic(tci);
1712 if (sound != last_sound)
1713 PlayMenuSoundExt(sound);
1714 if (music != last_music)
1715 PlayMenuMusicExt(music);
1721 SetMouseCursor(CURSOR_NONE);
1723 // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
1729 fading = fading_next;
1731 DelayReached(&title_delay, 0); /* reset delay counter */
1737 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1738 button = MB_MENU_CHOICE;
1740 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1741 button = MB_MENU_CHOICE;
1744 if (button == MB_MENU_LEAVE)
1746 return_to_main_menu = TRUE;
1747 use_fading_main_menu = FALSE;
1749 else if (button == MB_MENU_CHOICE)
1752 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1755 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1758 FadeOut(REDRAW_FIELD);
1761 FadeSetEnterScreen();
1763 info_mode = INFO_MODE_MAIN;
1764 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1770 tci = &title_controls[title_screen_nr];
1772 if (title_screen_nr < num_title_screens)
1776 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1783 graphic_info[getTitleScreenGraphic(tci->local_nr,
1784 tci->initial)].anim_mode;
1786 anim_mode = ANIM_FADE; /* ??? */
1788 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1789 anim_mode == ANIM_CROSSFADE ? TRUE :
1793 sound = getTitleSound(tci);
1794 music = getTitleMusic(tci);
1796 if (sound == SND_UNDEFINED || sound != last_sound)
1798 if (music == MUS_UNDEFINED || music != last_music)
1802 FadeOut(REDRAW_ALL);
1806 DrawTitleScreenImage(tci->local_nr, tci->initial);
1808 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1810 fading_next = getTitleFading(tci);
1813 sound = getTitleSound(tci);
1814 music = getTitleMusic(tci);
1816 if (sound != last_sound)
1817 PlayMenuSoundExt(sound);
1818 if (music != last_music)
1819 PlayMenuMusicExt(music);
1826 printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1830 /* last screen already faded out, next screen has no animation */
1831 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1832 fading_next.fade_mode == FADE_MODE_NONE)
1833 fading = fading_next;
1835 /* last screen already faded out, next screen has no animation */
1836 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1837 fading_next.fade_mode == FADE_MODE_NONE)
1838 fading = fading_next;
1845 fading = fading_next;
1847 DelayReached(&title_delay, 0); /* reset delay counter */
1851 FadeSoundsAndMusic();
1857 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1861 FadeOut(REDRAW_ALL);
1865 FadeOut(REDRAW_ALL);
1869 return_to_main_menu = TRUE;
1873 if (return_to_main_menu)
1879 SetMouseCursor(CURSOR_DEFAULT);
1881 if (game_status == GAME_MODE_INFO)
1884 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1887 info_mode = INFO_MODE_MAIN;
1888 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1890 else /* default: return to main menu */
1893 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1896 game_status = GAME_MODE_MAIN;
1897 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1902 void HandleMainMenu_SelectLevel(int step, int direction)
1904 int old_level_nr = level_nr;
1907 new_level_nr = old_level_nr + step * direction;
1908 if (new_level_nr < leveldir_current->first_level)
1909 new_level_nr = leveldir_current->first_level;
1910 if (new_level_nr > leveldir_current->last_level)
1911 new_level_nr = leveldir_current->last_level;
1913 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1915 /* skipping levels is only allowed when trying to skip single level */
1916 if (setup.skip_levels && step == 1 &&
1917 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1919 leveldir_current->handicap_level++;
1920 SaveLevelSetup_SeriesInfo();
1923 new_level_nr = leveldir_current->handicap_level;
1926 if (new_level_nr != old_level_nr)
1928 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1930 PlaySound(SND_MENU_ITEM_SELECTING);
1932 level_nr = new_level_nr;
1935 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1936 int2str(level_nr, menu.main.text.level_number.size),
1937 mci->pos_text->font);
1939 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1942 LoadLevel(level_nr);
1943 DrawPreviewLevel(TRUE);
1947 DrawCompleteVideoDisplay();
1949 /* needed because DrawPreviewLevel() takes some time */
1957 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1959 static int choice = MAIN_CONTROL_GAME;
1963 if (button == MB_MENU_INITIALIZE)
1965 DrawCursorAndText_Main(choice, TRUE);
1970 if (mx || my) /* mouse input */
1974 for (i = 0; main_controls[i].nr != -1; i++)
1976 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1977 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1978 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1980 pos = main_controls[i].nr;
1986 else if (dx || dy) /* keyboard input */
1988 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1989 choice == MAIN_CONTROL_SETUP))
1990 button = MB_MENU_CHOICE;
1995 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1997 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1999 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2005 PlaySound(SND_MENU_ITEM_ACTIVATING);
2007 DrawCursorAndText_Main(choice, FALSE);
2008 DrawCursorAndText_Main(pos, TRUE);
2015 PlaySound(SND_MENU_ITEM_SELECTING);
2017 if (pos == MAIN_CONTROL_NAME)
2019 game_status = GAME_MODE_PSEUDO_TYPENAME;
2021 HandleTypeName(strlen(setup.player_name), 0);
2023 else if (pos == MAIN_CONTROL_LEVELS)
2027 game_status = GAME_MODE_LEVELS;
2029 SaveLevelSetup_LastSeries();
2030 SaveLevelSetup_SeriesInfo();
2039 else if (pos == MAIN_CONTROL_SCORES)
2041 game_status = GAME_MODE_SCORES;
2045 else if (pos == MAIN_CONTROL_EDITOR)
2047 if (leveldir_current->readonly &&
2048 !strEqual(setup.player_name, "Artsoft"))
2049 Request("This level is read only !", REQ_CONFIRM);
2051 game_status = GAME_MODE_EDITOR;
2053 FadeSetEnterScreen();
2057 else if (pos == MAIN_CONTROL_INFO)
2059 game_status = GAME_MODE_INFO;
2060 info_mode = INFO_MODE_MAIN;
2063 fading = menu.navigation;
2068 else if (pos == MAIN_CONTROL_GAME)
2070 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2072 else if (pos == MAIN_CONTROL_SETUP)
2074 game_status = GAME_MODE_SETUP;
2075 setup_mode = SETUP_MODE_MAIN;
2079 else if (pos == MAIN_CONTROL_QUIT)
2081 SaveLevelSetup_LastSeries();
2082 SaveLevelSetup_SeriesInfo();
2084 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2085 game_status = GAME_MODE_QUIT;
2090 if (game_status == GAME_MODE_MAIN)
2092 DrawPreviewLevel(FALSE);
2099 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2101 static int choice = 5;
2105 if (button == MB_MENU_INITIALIZE)
2107 drawCursor(choice, TRUE);
2112 if (mx || my) /* mouse input */
2114 x = (mx - mSX) / 32;
2115 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2117 else if (dx || dy) /* keyboard input */
2119 if (dx && choice == 1)
2120 x = (dx < 0 ? 10 : 14);
2123 if (choice == 4 || choice == 6)
2124 button = MB_MENU_CHOICE;
2130 if (y == 1 && dx != 0 && button)
2132 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2134 else if (IN_VIS_FIELD(x, y) &&
2135 y >= 0 && y <= 7 && (y != 1 || x < 10))
2141 drawCursor(choice, FALSE);
2142 drawCursor(y, TRUE);
2151 game_status = GAME_MODE_PSEUDO_TYPENAME;
2152 HandleTypeName(strlen(setup.player_name), 0);
2158 game_status = GAME_MODE_LEVELS;
2160 SaveLevelSetup_LastSeries();
2161 SaveLevelSetup_SeriesInfo();
2172 game_status = GAME_MODE_SCORES;
2177 if (leveldir_current->readonly &&
2178 !strEqual(setup.player_name, "Artsoft"))
2179 Request("This level is read only !", REQ_CONFIRM);
2180 game_status = GAME_MODE_EDITOR;
2185 game_status = GAME_MODE_INFO;
2186 info_mode = INFO_MODE_MAIN;
2191 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2195 game_status = GAME_MODE_SETUP;
2196 setup_mode = SETUP_MODE_MAIN;
2202 SaveLevelSetup_LastSeries();
2203 SaveLevelSetup_SeriesInfo();
2205 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2206 game_status = GAME_MODE_QUIT;
2211 if (game_status == GAME_MODE_MAIN)
2213 DrawPreviewLevel(FALSE);
2221 /* ========================================================================= */
2222 /* info screen functions */
2223 /* ========================================================================= */
2225 static struct TokenInfo *info_info;
2226 static int num_info_info;
2228 static void execInfoTitleScreen()
2231 FadeSetEnterScreen();
2234 info_mode = INFO_MODE_TITLE;
2238 static void execInfoElements()
2241 FadeSetEnterScreen();
2244 info_mode = INFO_MODE_ELEMENTS;
2248 static void execInfoMusic()
2251 FadeSetEnterScreen();
2254 info_mode = INFO_MODE_MUSIC;
2258 static void execInfoCredits()
2261 FadeSetEnterScreen();
2264 info_mode = INFO_MODE_CREDITS;
2268 static void execInfoProgram()
2271 FadeSetEnterScreen();
2274 info_mode = INFO_MODE_PROGRAM;
2278 static void execInfoVersion()
2281 FadeSetEnterScreen();
2284 info_mode = INFO_MODE_VERSION;
2288 static void execInfoLevelSet()
2291 FadeSetEnterScreen();
2294 info_mode = INFO_MODE_LEVELSET;
2298 static void execExitInfo()
2304 game_status = GAME_MODE_MAIN;
2306 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2312 static struct TokenInfo info_info_main[] =
2314 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2315 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2316 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2317 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2318 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2319 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2320 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2321 { TYPE_EMPTY, NULL, "" },
2322 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2327 static void DrawCursorAndText_Info(int pos, boolean active)
2329 int xpos = MENU_SCREEN_START_XPOS;
2330 int ypos = MENU_SCREEN_START_YPOS + pos;
2331 int font_nr = FONT_MENU_1;
2334 font_nr = FONT_ACTIVE(font_nr);
2336 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2338 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2339 drawCursor(pos, active);
2342 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2347 CloseDoor(DOOR_CLOSE_2);
2349 /* (needed after displaying title screens which disable auto repeat) */
2350 KeyboardAutoRepeatOn();
2352 FadeSetLeaveScreen();
2355 FadeOut(redraw_mask);
2359 if (redraw_mask == REDRAW_ALL)
2362 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2368 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2370 info_info = info_info_main;
2373 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2376 int xpos = MENU_SCREEN_START_XPOS;
2377 int ypos = MENU_SCREEN_START_YPOS + i;
2378 int font_nr = FONT_MENU_1;
2381 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2382 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2383 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2384 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2385 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2386 initCursor(i, IMG_MENU_BUTTON);
2389 DrawCursorAndText_Info(i, FALSE);
2391 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2397 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2402 DrawMaskedBorder(redraw_mask);
2405 FadeIn(redraw_mask);
2410 else if (fading.anim_mode == ANIM_CROSSFADE)
2411 FadeCross(redraw_mask);
2413 FadeIn(redraw_mask);
2416 FadeIn(redraw_mask);
2425 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2427 static int choice_store[MAX_INFO_MODES];
2428 int choice = choice_store[info_mode]; /* always starts with 0 */
2432 if (button == MB_MENU_INITIALIZE)
2434 /* advance to first valid menu entry */
2435 while (choice < num_info_info &&
2436 info_info[choice].type & TYPE_SKIP_ENTRY)
2438 choice_store[info_mode] = choice;
2441 DrawCursorAndText_Info(choice, TRUE);
2443 drawCursor(choice, TRUE);
2448 else if (button == MB_MENU_LEAVE)
2450 for (y = 0; y < num_info_info; y++)
2452 if (info_info[y].type & TYPE_LEAVE_MENU)
2454 void (*menu_callback_function)(void) = info_info[y].value;
2458 menu_callback_function();
2460 break; /* absolutely needed because function changes 'info_info'! */
2467 if (mx || my) /* mouse input */
2469 x = (mx - mSX) / 32;
2470 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2472 else if (dx || dy) /* keyboard input */
2476 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2478 if (info_info[choice].type & menu_navigation_type ||
2479 info_info[choice].type & TYPE_ENTER_SCREEN ||
2480 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2481 button = MB_MENU_CHOICE;
2486 /* jump to next non-empty menu entry (up or down) */
2487 while (y > 0 && y < num_info_info - 1 &&
2488 info_info[y].type & TYPE_SKIP_ENTRY)
2492 if (IN_VIS_FIELD(x, y) &&
2493 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2499 PlaySound(SND_MENU_ITEM_ACTIVATING);
2502 DrawCursorAndText_Info(choice, FALSE);
2503 DrawCursorAndText_Info(y, TRUE);
2505 drawCursor(choice, FALSE);
2506 drawCursor(y, TRUE);
2509 choice = choice_store[info_mode] = y;
2512 else if (!(info_info[y].type & TYPE_GHOSTED))
2514 PlaySound(SND_MENU_ITEM_SELECTING);
2516 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2518 void (*menu_callback_function)(void) = info_info[choice].value;
2520 FadeSetFromType(info_info[y].type);
2522 menu_callback_function();
2528 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2531 int ystart1 = mSY - SY + 100;
2532 int ystart2 = mSY - SY + 150;
2533 int ybottom = mSY - SY + SYSIZE - 20;
2537 int ybottom = SYSIZE - 20;
2540 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2543 FadeOut(REDRAW_FIELD);
2549 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2550 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2552 DrawTextSCentered(ybottom, FONT_TEXT_4,
2553 "Press any key or button for info menu");
2556 FadeIn(REDRAW_FIELD);
2560 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2562 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2563 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2564 int xstart = mSX + 16;
2565 int ystart1 = mSY - SY + 100;
2566 int ystart2 = mSY + 64 + 2 * 32;
2567 int ybottom = mSY - SY + SYSIZE - 20;
2568 int ystep = TILEY + 4;
2569 int element, action, direction;
2577 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2578 infoscreen_step[i] = infoscreen_frame[i] = 0;
2583 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2585 DrawTextSCentered(ybottom, FONT_TEXT_4,
2586 "Press any key or button for next page");
2592 while (helpanim_info[j].element != HELPANIM_LIST_END)
2594 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2599 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2608 j += infoscreen_step[i - start];
2610 element = helpanim_info[j].element;
2611 action = helpanim_info[j].action;
2612 direction = helpanim_info[j].direction;
2615 element = EL_UNKNOWN;
2617 if (action != -1 && direction != -1)
2618 graphic = el_act_dir2img(element, action, direction);
2619 else if (action != -1)
2620 graphic = el_act2img(element, action);
2621 else if (direction != -1)
2622 graphic = el_dir2img(element, direction);
2624 graphic = el2img(element);
2626 delay = helpanim_info[j++].delay;
2631 if (infoscreen_frame[i - start] == 0)
2634 infoscreen_frame[i - start] = delay - 1;
2638 sync_frame = delay - infoscreen_frame[i - start];
2639 infoscreen_frame[i - start]--;
2642 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2644 if (!infoscreen_frame[i - start])
2645 infoscreen_step[i - start] = 0;
2649 if (!infoscreen_frame[i - start])
2650 infoscreen_step[i - start]++;
2651 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2657 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2659 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2660 graphic, sync_frame, USE_MASKING);
2663 DrawInfoScreen_HelpText(element, action, direction, i - start);
2668 redraw_mask |= REDRAW_FIELD;
2673 static char *getHelpText(int element, int action, int direction)
2675 char token[MAX_LINE_LEN];
2677 strcpy(token, element_info[element].token_name);
2680 strcat(token, element_action_info[action].suffix);
2682 if (direction != -1)
2683 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2685 return getHashEntry(helptext_info, token);
2688 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2691 int font_nr = FONT_INFO_ELEMENTS;
2693 int font_nr = FONT_LEVEL_NUMBER;
2695 int font_width = getFontWidth(font_nr);
2696 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2697 int sy = mSY + 65 + 2 * 32 + 1;
2698 int ystep = TILEY + 4;
2699 int pad_x = sx - SX;
2700 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2701 int max_lines_per_text = 2;
2704 if (action != -1 && direction != -1) /* element.action.direction */
2705 text = getHelpText(element, action, direction);
2707 if (text == NULL && action != -1) /* element.action */
2708 text = getHelpText(element, action, -1);
2710 if (text == NULL && direction != -1) /* element.direction */
2711 text = getHelpText(element, -1, direction);
2713 if (text == NULL) /* base element */
2714 text = getHelpText(element, -1, -1);
2716 if (text == NULL) /* not found */
2717 text = "No description available";
2719 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2720 sy += getFontHeight(font_nr) / 2;
2723 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2724 max_chars_per_line, -1, max_lines_per_text, -1,
2725 TRUE, FALSE, FALSE);
2727 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2728 max_chars_per_line, max_lines_per_text);
2732 void DrawInfoScreen_TitleScreen()
2737 void HandleInfoScreen_TitleScreen(int button)
2739 HandleTitleScreen(0, 0, 0, 0, button);
2742 void DrawInfoScreen_Elements()
2744 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2747 FadeOut(REDRAW_FIELD);
2753 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2756 FadeIn(REDRAW_FIELD);
2762 void HandleInfoScreen_Elements(int button)
2764 static unsigned long info_delay = 0;
2765 static int num_anims;
2766 static int num_pages;
2768 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2771 if (button == MB_MENU_INITIALIZE)
2773 boolean new_element = TRUE;
2777 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2779 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2781 else if (new_element)
2784 new_element = FALSE;
2788 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2792 if (button == MB_MENU_LEAVE)
2794 PlaySound(SND_MENU_ITEM_SELECTING);
2796 info_mode = INFO_MODE_MAIN;
2801 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2803 if (button != MB_MENU_INITIALIZE)
2805 PlaySound(SND_MENU_ITEM_SELECTING);
2810 if (page >= num_pages)
2812 FadeSoundsAndMusic();
2815 FadeOut(REDRAW_FIELD);
2818 info_mode = INFO_MODE_MAIN;
2819 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2824 if (button != MB_MENU_INITIALIZE)
2825 FadeCrossSaveBackbuffer();
2827 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2829 if (button != MB_MENU_INITIALIZE)
2830 FadeCross(REDRAW_FIELD);
2834 if (DelayReached(&info_delay, GameFrameDelay))
2835 if (page < num_pages)
2836 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2838 PlayMenuSoundIfLoop();
2842 void DrawInfoScreen_Music()
2844 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2847 FadeOut(REDRAW_FIELD);
2855 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2858 FadeIn(REDRAW_FIELD);
2862 void HandleInfoScreen_Music(int button)
2864 static struct MusicFileInfo *list = NULL;
2865 int ystart1 = mSY - SY + 100;
2866 int ystart2 = mSY - SY + 150;
2867 int ybottom = mSY - SY + SYSIZE - 20;
2870 if (button == MB_MENU_INITIALIZE)
2872 list = music_file_info;
2876 FadeSoundsAndMusic();
2881 DrawTextSCentered(ystart1, FONT_TEXT_1,
2882 "No music info for this level set.");
2884 DrawTextSCentered(ybottom, FONT_TEXT_4,
2885 "Press any key or button for info menu");
2891 if (button == MB_MENU_LEAVE)
2893 PlaySound(SND_MENU_ITEM_SELECTING);
2895 FadeSoundsAndMusic();
2897 info_mode = INFO_MODE_MAIN;
2902 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2906 if (button != MB_MENU_INITIALIZE)
2908 PlaySound(SND_MENU_ITEM_SELECTING);
2916 FadeSoundsAndMusic();
2919 FadeOut(REDRAW_FIELD);
2922 info_mode = INFO_MODE_MAIN;
2923 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2928 FadeSoundsAndMusic();
2930 if (button != MB_MENU_INITIALIZE)
2931 FadeCrossSaveBackbuffer();
2938 int sound = list->music;
2940 if (sound_info[sound].loop)
2941 PlaySoundLoop(sound);
2945 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2949 PlayMusic(list->music);
2951 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2954 if (!strEqual(list->title, UNKNOWN_NAME))
2956 if (!strEqual(list->title_header, UNKNOWN_NAME))
2957 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2959 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2962 if (!strEqual(list->artist, UNKNOWN_NAME))
2964 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2965 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2967 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2969 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2972 if (!strEqual(list->album, UNKNOWN_NAME))
2974 if (!strEqual(list->album_header, UNKNOWN_NAME))
2975 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2977 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2979 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2982 if (!strEqual(list->year, UNKNOWN_NAME))
2984 if (!strEqual(list->year_header, UNKNOWN_NAME))
2985 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2987 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2989 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2992 DrawTextSCentered(ybottom, FONT_TEXT_4,
2993 "Press any key or button for next page");
2995 if (button != MB_MENU_INITIALIZE)
2996 FadeCross(REDRAW_FIELD);
2999 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3000 PlaySoundLoop(list->music);
3003 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
3005 int ystart1 = mSY - SY + 100;
3006 int ystart2 = mSY - SY + 150;
3007 int ybottom = mSY - SY + SYSIZE - 20;
3016 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
3020 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3021 "Special thanks to");
3022 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3024 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3026 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3027 "\"Boulder Dash\"");
3028 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3030 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3032 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3034 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3035 "First Star Software");
3037 else if (screen_nr == 1)
3039 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3040 "Special thanks to");
3041 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3042 "Klaus Heinz & Volker Wertich");
3043 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3045 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3046 "\"Emerald Mine\"");
3047 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3049 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3051 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3053 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3056 else if (screen_nr == 2)
3058 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3059 "Special thanks to");
3060 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3061 "Michael Stopp & Philip Jespersen");
3062 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3064 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3066 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3068 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3070 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3072 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3073 "Digital Integration");
3075 else if (screen_nr == 3)
3077 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3078 "Special thanks to");
3079 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3080 "Hiroyuki Imabayashi");
3081 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3083 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3085 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3087 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3089 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3091 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3094 else if (screen_nr == 4)
3096 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3097 "Special thanks to");
3098 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3100 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3102 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3103 "Jürgen Bonhagen");
3104 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3105 "for the continuous creation");
3106 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3107 "of outstanding level sets");
3109 else if (screen_nr == 5)
3111 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3113 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3115 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3116 "for ideas and inspiration by");
3117 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3120 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3122 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3124 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3125 "for ideas and inspiration by");
3126 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3129 else if (screen_nr == 6)
3131 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3133 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3135 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3136 "for the new Emerald Mine engine");
3138 else if (screen_nr == 7)
3140 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3142 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3144 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3145 "for the initial DOS port");
3147 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3149 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3151 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3152 "for some additional toons");
3154 else if (screen_nr == 8)
3156 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3157 "And not to forget:");
3158 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3160 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3161 "All those who contributed");
3162 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3163 "levels to this game");
3164 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3174 DrawTextSCentered(ybottom, FONT_TEXT_4,
3175 "Press any key or button for next page");
3180 void DrawInfoScreen_Credits()
3182 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3184 FadeSoundsAndMusic();
3187 FadeOut(REDRAW_FIELD);
3190 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3193 FadeIn(REDRAW_FIELD);
3197 void HandleInfoScreen_Credits(int button)
3199 static int screen_nr = 0;
3201 if (button == MB_MENU_INITIALIZE)
3205 DrawInfoScreen_CreditsScreen(screen_nr);
3207 else if (button == MB_MENU_LEAVE)
3209 PlaySound(SND_MENU_ITEM_SELECTING);
3211 info_mode = INFO_MODE_MAIN;
3216 else if (button == MB_MENU_CHOICE)
3218 boolean show_screen;
3220 PlaySound(SND_MENU_ITEM_SELECTING);
3224 FadeCrossSaveBackbuffer();
3226 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3230 FadeCross(REDRAW_FIELD);
3234 FadeSoundsAndMusic();
3237 FadeOut(REDRAW_FIELD);
3240 info_mode = INFO_MODE_MAIN;
3241 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3246 PlayMenuSoundIfLoop();
3250 void DrawInfoScreen_Program()
3252 int ystart1 = mSY - SY + 100;
3253 int ystart2 = mSY - SY + 150;
3254 int ybottom = mSY - SY + SYSIZE - 20;
3257 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3260 FadeOut(REDRAW_FIELD);
3266 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3268 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3269 "This game is Freeware!");
3270 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3271 "If you like it, send e-mail to:");
3272 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3273 PROGRAM_EMAIL_STRING);
3274 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3275 "or SnailMail to:");
3276 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3278 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3279 "Detmolder Strasse 189");
3280 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3282 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3284 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3285 "More information and levels:");
3286 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3287 PROGRAM_WEBSITE_STRING);
3288 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3289 "If you have created new levels,");
3290 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3291 "send them to me to include them!");
3292 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3295 DrawTextSCentered(ybottom, FONT_TEXT_4,
3296 "Press any key or button for info menu");
3299 FadeIn(REDRAW_FIELD);
3303 void HandleInfoScreen_Program(int button)
3305 if (button == MB_MENU_LEAVE)
3307 PlaySound(SND_MENU_ITEM_SELECTING);
3309 info_mode = INFO_MODE_MAIN;
3314 else if (button == MB_MENU_CHOICE)
3316 PlaySound(SND_MENU_ITEM_SELECTING);
3318 FadeSoundsAndMusic();
3321 FadeOut(REDRAW_FIELD);
3324 info_mode = INFO_MODE_MAIN;
3325 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3329 PlayMenuSoundIfLoop();
3333 void DrawInfoScreen_Version()
3335 int font_header = FONT_TEXT_3;
3336 int font_text = FONT_TEXT_2;
3337 int xstep = getFontWidth(font_text);
3338 int ystep = getFontHeight(font_text);
3339 int ystart1 = mSY - SY + 100;
3340 int ystart2 = mSY - SY + 150;
3341 int ybottom = mSY - SY + SYSIZE - 20;
3342 int xstart1 = mSX + 2 * xstep;
3343 int xstart2 = mSX + 19 * xstep;
3344 #if defined(TARGET_SDL)
3345 int xstart3 = mSX + 29 * xstep;
3346 SDL_version sdl_version_compiled;
3347 const SDL_version *sdl_version_linked;
3348 int driver_name_len = 8;
3349 char driver_name[driver_name_len];
3352 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3355 FadeOut(REDRAW_FIELD);
3361 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3363 DrawTextF(xstart1, ystart2, font_header, "Name");
3364 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3367 DrawTextF(xstart1, ystart2, font_header, "Version");
3368 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3371 DrawTextF(xstart1, ystart2, font_header, "Platform");
3372 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3375 DrawTextF(xstart1, ystart2, font_header, "Target");
3376 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3379 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3380 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3382 #if defined(TARGET_SDL)
3383 ystart2 += 3 * ystep;
3384 DrawTextF(xstart1, ystart2, font_header, "Library");
3385 DrawTextF(xstart2, ystart2, font_header, "compiled");
3386 DrawTextF(xstart3, ystart2, font_header, "linked");
3388 SDL_VERSION(&sdl_version_compiled);
3389 sdl_version_linked = SDL_Linked_Version();
3391 ystart2 += 2 * ystep;
3392 DrawTextF(xstart1, ystart2, font_text, "SDL");
3393 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3394 sdl_version_compiled.major,
3395 sdl_version_compiled.minor,
3396 sdl_version_compiled.patch);
3397 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3398 sdl_version_linked->major,
3399 sdl_version_linked->minor,
3400 sdl_version_linked->patch);
3402 SDL_IMAGE_VERSION(&sdl_version_compiled);
3403 sdl_version_linked = IMG_Linked_Version();
3406 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3407 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3408 sdl_version_compiled.major,
3409 sdl_version_compiled.minor,
3410 sdl_version_compiled.patch);
3411 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3412 sdl_version_linked->major,
3413 sdl_version_linked->minor,
3414 sdl_version_linked->patch);
3416 SDL_MIXER_VERSION(&sdl_version_compiled);
3417 sdl_version_linked = Mix_Linked_Version();
3420 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3421 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3422 sdl_version_compiled.major,
3423 sdl_version_compiled.minor,
3424 sdl_version_compiled.patch);
3425 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3426 sdl_version_linked->major,
3427 sdl_version_linked->minor,
3428 sdl_version_linked->patch);
3430 SDL_NET_VERSION(&sdl_version_compiled);
3431 sdl_version_linked = SDLNet_Linked_Version();
3434 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3435 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3436 sdl_version_compiled.major,
3437 sdl_version_compiled.minor,
3438 sdl_version_compiled.patch);
3439 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3440 sdl_version_linked->major,
3441 sdl_version_linked->minor,
3442 sdl_version_linked->patch);
3444 ystart2 += 3 * ystep;
3445 DrawTextF(xstart1, ystart2, font_header, "Driver");
3446 DrawTextF(xstart2, ystart2, font_header, "Requested");
3447 DrawTextF(xstart3, ystart2, font_header, "Used");
3449 SDL_VideoDriverName(driver_name, driver_name_len);
3451 ystart2 += 2 * ystep;
3452 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3453 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3454 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3456 SDL_AudioDriverName(driver_name, driver_name_len);
3459 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3460 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3461 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3464 DrawTextSCentered(ybottom, FONT_TEXT_4,
3465 "Press any key or button for info menu");
3468 FadeIn(REDRAW_FIELD);
3472 void HandleInfoScreen_Version(int button)
3474 if (button == MB_MENU_LEAVE)
3476 PlaySound(SND_MENU_ITEM_SELECTING);
3478 info_mode = INFO_MODE_MAIN;
3483 else if (button == MB_MENU_CHOICE)
3485 PlaySound(SND_MENU_ITEM_SELECTING);
3487 FadeSoundsAndMusic();
3490 FadeOut(REDRAW_FIELD);
3493 info_mode = INFO_MODE_MAIN;
3494 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3498 PlayMenuSoundIfLoop();
3502 void DrawInfoScreen_LevelSet()
3504 struct TitleMessageInfo *tmi = &readme;
3505 char *filename = getLevelSetInfoFilename();
3507 /* if chars set to "-1", automatically determine by text and font width */
3508 if (tmi->chars == -1)
3509 tmi->chars = tmi->width / getFontWidth(tmi->font);
3511 tmi->width = tmi->chars * getFontWidth(tmi->font);
3513 /* if lines set to "-1", automatically determine by text and font height */
3514 if (tmi->lines == -1)
3515 tmi->lines = tmi->height / getFontHeight(tmi->font);
3517 tmi->height = tmi->lines * getFontHeight(tmi->font);
3519 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3522 FadeOut(REDRAW_FIELD);
3528 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3530 if (filename != NULL)
3531 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3532 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3533 tmi->autowrap, tmi->centered, tmi->parse_comments);
3535 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3536 "No information for this level set.");
3538 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3539 "Press any key or button for info menu");
3542 FadeIn(REDRAW_FIELD);
3546 void HandleInfoScreen_LevelSet(int button)
3548 if (button == MB_MENU_LEAVE)
3550 PlaySound(SND_MENU_ITEM_SELECTING);
3552 info_mode = INFO_MODE_MAIN;
3557 else if (button == MB_MENU_CHOICE)
3559 PlaySound(SND_MENU_ITEM_SELECTING);
3561 FadeSoundsAndMusic();
3564 FadeOut(REDRAW_FIELD);
3567 info_mode = INFO_MODE_MAIN;
3568 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3572 PlayMenuSoundIfLoop();
3576 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3578 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3580 if (info_mode == INFO_MODE_TITLE)
3581 DrawInfoScreen_TitleScreen();
3582 else if (info_mode == INFO_MODE_ELEMENTS)
3583 DrawInfoScreen_Elements();
3584 else if (info_mode == INFO_MODE_MUSIC)
3585 DrawInfoScreen_Music();
3586 else if (info_mode == INFO_MODE_CREDITS)
3587 DrawInfoScreen_Credits();
3588 else if (info_mode == INFO_MODE_PROGRAM)
3589 DrawInfoScreen_Program();
3590 else if (info_mode == INFO_MODE_VERSION)
3591 DrawInfoScreen_Version();
3592 else if (info_mode == INFO_MODE_LEVELSET)
3593 DrawInfoScreen_LevelSet();
3595 DrawInfoScreen_Main(redraw_mask, do_fading);
3597 if (info_mode != INFO_MODE_MAIN &&
3598 info_mode != INFO_MODE_TITLE &&
3599 info_mode != INFO_MODE_MUSIC)
3606 void DrawAndFadeInInfoScreen(int redraw_mask)
3608 DrawInfoScreenExt(redraw_mask, TRUE);
3611 void DrawInfoScreen()
3613 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3616 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3618 if (info_mode == INFO_MODE_TITLE)
3619 HandleInfoScreen_TitleScreen(button);
3620 else if (info_mode == INFO_MODE_ELEMENTS)
3621 HandleInfoScreen_Elements(button);
3622 else if (info_mode == INFO_MODE_MUSIC)
3623 HandleInfoScreen_Music(button);
3624 else if (info_mode == INFO_MODE_CREDITS)
3625 HandleInfoScreen_Credits(button);
3626 else if (info_mode == INFO_MODE_PROGRAM)
3627 HandleInfoScreen_Program(button);
3628 else if (info_mode == INFO_MODE_VERSION)
3629 HandleInfoScreen_Version(button);
3630 else if (info_mode == INFO_MODE_LEVELSET)
3631 HandleInfoScreen_LevelSet(button);
3633 HandleInfoScreen_Main(mx, my, dx, dy, button);
3639 /* ========================================================================= */
3640 /* type name functions */
3641 /* ========================================================================= */
3643 void HandleTypeName(int newxpos, Key key)
3645 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3646 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3648 struct TextPosInfo *pos = mci->pos_input;
3649 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3650 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3653 static int xpos = 0;
3655 static int xpos = 0, ypos = 2;
3657 int font_nr = pos->font;
3658 int font_active_nr = FONT_ACTIVE(font_nr);
3659 int font_width = getFontWidth(font_active_nr);
3662 int startx = mSX + mci->pos_input->x;
3663 int starty = mSY + mci->pos_input->y;
3666 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3667 int startx = mSX + 32 + name_width;
3668 int starty = mSY + ypos * 32;
3670 char key_char = getValidConfigValueChar(getCharFromKey(key));
3671 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3672 boolean is_active = TRUE;
3674 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3678 strcpy(last_player_name, setup.player_name);
3683 /* add one character width for added cursor character */
3684 pos->width += font_width;
3685 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3687 DrawText(startx, starty, setup.player_name, font_active_nr);
3688 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3691 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3693 setup.player_name[xpos] = key_char;
3694 setup.player_name[xpos + 1] = 0;
3699 /* add one character width for added name text character */
3700 pos->width += font_width;
3701 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3703 DrawText(startx, starty, setup.player_name, font_active_nr);
3704 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3707 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3711 setup.player_name[xpos] = 0;
3714 /* remove one character width for removed name text character */
3715 pos->width -= font_width;
3716 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3718 DrawText(startx, starty, setup.player_name, font_active_nr);
3719 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3722 else if (key == KSYM_Return && xpos > 0)
3725 /* remove one character width for removed cursor text character */
3726 pos->width -= font_width;
3727 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3729 DrawText(startx, starty, setup.player_name, font_nr);
3730 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3737 game_status = GAME_MODE_MAIN;
3739 else if (key == KSYM_Escape)
3741 strcpy(setup.player_name, last_player_name);
3745 game_status = GAME_MODE_MAIN;
3750 pos->width = (strlen(setup.player_name) + 1) * font_width;
3751 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3753 DrawText(startx, starty, setup.player_name, font_active_nr);
3754 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3758 pos->width = strlen(setup.player_name) * font_width;
3759 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3761 DrawText(startx, starty, setup.player_name, font_nr);
3766 /* ========================================================================= */
3767 /* tree menu functions */
3768 /* ========================================================================= */
3770 static void DrawChooseTree(TreeInfo **ti_ptr)
3774 FreeScreenGadgets();
3775 CreateScreenGadgets();
3777 CloseDoor(DOOR_CLOSE_2);
3780 FadeOut(REDRAW_FIELD);
3785 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3786 MapScreenTreeGadgets(*ti_ptr);
3789 FadeIn(REDRAW_FIELD);
3795 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3797 struct GadgetInfo *gi = screen_gadget[id];
3798 int items_max, items_visible, item_position;
3800 items_max = numTreeInfoInGroup(ti);
3801 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3802 item_position = first_entry;
3804 if (item_position > items_max - items_visible)
3805 item_position = items_max - items_visible;
3807 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3808 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3809 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3812 static void drawChooseTreeList(int first_entry, int num_page_entries,
3816 char *title_string = NULL;
3817 int yoffset_sets = MENU_TITLE1_YPOS;
3818 int yoffset_setup = 16;
3819 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3821 int last_game_status = game_status; /* save current game status */
3823 title_string = ti->infotext;
3825 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3828 /* force LEVELS font on artwork setup screen */
3829 game_status = GAME_MODE_LEVELS;
3833 /* clear tree list area, but not title or scrollbar */
3834 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3835 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3836 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3838 /* clear tree list area, but not title or scrollbar */
3839 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3840 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3841 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3844 for (i = 0; i < num_page_entries; i++)
3846 TreeInfo *node, *node_first;
3847 int entry_pos = first_entry + i;
3848 int xpos = MENU_SCREEN_START_XPOS;
3849 int ypos = MENU_SCREEN_START_YPOS + i;
3850 int startx = mSX + xpos * 32;
3851 int starty = mSY + ypos * 32;
3852 int font_nr = FONT_TEXT_1;
3853 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3854 int startx_text = startx + font_xoffset;
3855 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3856 int text_size = startx_scrollbar - startx_text;
3857 int max_buffer_len = text_size / getFontWidth(font_nr);
3858 char buffer[max_buffer_len + 1];
3860 node_first = getTreeInfoFirstGroupEntry(ti);
3861 node = getTreeInfoFromPos(node_first, entry_pos);
3863 strncpy(buffer, node->name, max_buffer_len);
3864 buffer[max_buffer_len] = '\0';
3866 DrawText(startx, starty, buffer, font_nr + node->color);
3868 if (node->parent_link)
3869 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3870 else if (node->level_group)
3871 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3873 initCursor(i, IMG_MENU_BUTTON);
3876 game_status = last_game_status; /* restore current game status */
3878 redraw_mask |= REDRAW_FIELD;
3881 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3883 TreeInfo *node, *node_first;
3884 int x, last_redraw_mask = redraw_mask;
3885 int ypos = MENU_TITLE2_YPOS;
3886 int font_nr = FONT_TITLE_2;
3888 if (ti->type != TREE_TYPE_LEVEL_DIR)
3891 node_first = getTreeInfoFirstGroupEntry(ti);
3892 node = getTreeInfoFromPos(node_first, entry_pos);
3894 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3896 if (node->parent_link)
3897 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3899 else if (node->level_group)
3900 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3902 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3903 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3904 node->levels, node->class_desc);
3906 /* let BackToFront() redraw only what is needed */
3907 redraw_mask = last_redraw_mask | REDRAW_TILES;
3908 for (x = 0; x < SCR_FIELDX; x++)
3909 MarkTileDirty(x, 1);
3912 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3915 TreeInfo *ti = *ti_ptr;
3917 int y = ti->cl_cursor;
3918 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3919 int num_entries = numTreeInfoInGroup(ti);
3920 int num_page_entries;
3921 int last_game_status = game_status; /* save current game status */
3922 boolean position_set_by_scrollbar = (dx == 999);
3925 /* force LEVELS draw offset on choose level and artwork setup screen */
3926 game_status = GAME_MODE_LEVELS;
3929 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3930 num_page_entries = num_entries;
3932 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3934 game_status = last_game_status; /* restore current game status */
3936 if (button == MB_MENU_INITIALIZE)
3938 int num_entries = numTreeInfoInGroup(ti);
3939 int entry_pos = posTreeInfo(ti);
3941 if (ti->cl_first == -1)
3943 /* only on initialization */
3944 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3945 ti->cl_cursor = entry_pos - ti->cl_first;
3947 else if (ti->cl_cursor >= num_page_entries ||
3948 (num_entries > num_page_entries &&
3949 num_entries - ti->cl_first < num_page_entries))
3951 /* only after change of list size (by custom graphic configuration) */
3952 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3953 ti->cl_cursor = entry_pos - ti->cl_first;
3956 if (position_set_by_scrollbar)
3959 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3962 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3963 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3964 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3968 else if (button == MB_MENU_LEAVE)
3972 PlaySound(SND_MENU_ITEM_SELECTING);
3974 if (ti->node_parent)
3976 *ti_ptr = ti->node_parent;
3977 DrawChooseTree(ti_ptr);
3979 else if (game_status == GAME_MODE_SETUP)
3981 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3983 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3984 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3985 execSetupGraphics();
3991 game_status = GAME_MODE_MAIN;
3993 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4002 if (mx || my) /* mouse input */
4004 int last_game_status = game_status; /* save current game status */
4007 /* force LEVELS draw offset on artwork setup screen */
4008 game_status = GAME_MODE_LEVELS;
4011 x = (mx - mSX) / 32;
4012 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4014 game_status = last_game_status; /* restore current game status */
4016 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4018 /* move cursor instead of scrolling when already at start/end of list */
4019 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4021 else if (dy == +1 * SCROLL_LINE &&
4022 ti->cl_first + num_page_entries == num_entries)
4025 /* handle scrolling screen one line or page */
4026 if (ti->cl_cursor + dy < 0 ||
4027 ti->cl_cursor + dy > num_page_entries - 1)
4029 if (ABS(dy) == SCROLL_PAGE)
4030 step = num_page_entries - 1;
4032 if (dy < 0 && ti->cl_first > 0)
4034 /* scroll page/line up */
4036 ti->cl_first -= step;
4037 if (ti->cl_first < 0)
4040 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4041 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4042 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4044 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4047 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4049 /* scroll page/line down */
4051 ti->cl_first += step;
4052 if (ti->cl_first + num_page_entries > num_entries)
4053 ti->cl_first = MAX(0, num_entries - num_page_entries);
4055 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4056 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4057 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4059 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4066 /* handle moving cursor one line */
4067 y = ti->cl_cursor + dy;
4072 TreeInfo *node_first, *node_cursor;
4073 int entry_pos = ti->cl_first + y;
4075 node_first = getTreeInfoFirstGroupEntry(ti);
4076 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4078 if (node_cursor->node_group)
4082 PlaySound(SND_MENU_ITEM_SELECTING);
4084 node_cursor->cl_first = ti->cl_first;
4085 node_cursor->cl_cursor = ti->cl_cursor;
4086 *ti_ptr = node_cursor->node_group;
4087 DrawChooseTree(ti_ptr);
4092 else if (dx == -1 && ti->node_parent)
4096 PlaySound(SND_MENU_ITEM_SELECTING);
4098 *ti_ptr = ti->node_parent;
4099 DrawChooseTree(ti_ptr);
4104 if (!anyScrollbarGadgetActive() &&
4105 IN_VIS_FIELD(x, y) &&
4106 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4107 y >= 0 && y < num_page_entries)
4111 if (y != ti->cl_cursor)
4113 PlaySound(SND_MENU_ITEM_ACTIVATING);
4115 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4116 drawChooseTreeCursor(y, TRUE);
4117 drawChooseTreeInfo(ti->cl_first + y, ti);
4124 TreeInfo *node_first, *node_cursor;
4125 int entry_pos = ti->cl_first + y;
4127 PlaySound(SND_MENU_ITEM_SELECTING);
4129 node_first = getTreeInfoFirstGroupEntry(ti);
4130 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4132 if (node_cursor->node_group)
4136 node_cursor->cl_first = ti->cl_first;
4137 node_cursor->cl_cursor = ti->cl_cursor;
4138 *ti_ptr = node_cursor->node_group;
4139 DrawChooseTree(ti_ptr);
4141 else if (node_cursor->parent_link)
4145 *ti_ptr = node_cursor->node_parent;
4146 DrawChooseTree(ti_ptr);
4150 FadeSetEnterScreen();
4152 node_cursor->cl_first = ti->cl_first;
4153 node_cursor->cl_cursor = ti->cl_cursor;
4154 *ti_ptr = node_cursor;
4156 if (ti->type == TREE_TYPE_LEVEL_DIR)
4158 LoadLevelSetup_SeriesInfo();
4160 SaveLevelSetup_LastSeries();
4161 SaveLevelSetup_SeriesInfo();
4165 if (game_status == GAME_MODE_SETUP)
4167 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4169 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4170 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4171 execSetupGraphics();
4177 game_status = GAME_MODE_MAIN;
4185 void DrawChooseLevel()
4187 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4189 DrawChooseTree(&leveldir_current);
4195 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4197 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4202 void DrawHallOfFame(int highlight_position)
4205 FadeSoundsAndMusic();
4207 /* (this is needed when called from GameEnd() after winning a game) */
4208 KeyboardAutoRepeatOn();
4211 /* (this is needed when called from GameEnd() after winning a game) */
4212 SetDrawDeactivationMask(REDRAW_NONE);
4213 SetDrawBackgroundMask(REDRAW_FIELD);
4215 CloseDoor(DOOR_CLOSE_2);
4217 if (highlight_position < 0)
4218 LoadScore(level_nr);
4220 FadeSetEnterScreen();
4222 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4225 FadeOut(REDRAW_FIELD);
4233 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4236 FadeIn(REDRAW_FIELD);
4240 static void drawHallOfFameList(int first_entry, int highlight_position)
4244 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4247 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4248 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4249 "HighScores of Level %d", level_nr);
4251 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4253 int entry = first_entry + i;
4254 boolean active = (entry == highlight_position);
4255 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4256 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4257 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4258 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4259 int dx1 = 3 * getFontWidth(font_nr1);
4260 int dx2 = dx1 + getFontWidth(font_nr1);
4261 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4262 int sy = mSY + 64 + i * 32;
4264 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4265 DrawText(mSX + dx1, sy, ".", font_nr1);
4266 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4268 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4269 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4271 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4274 redraw_mask |= REDRAW_FIELD;
4277 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4279 static int first_entry = 0;
4280 static int highlight_position = 0;
4281 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4283 if (button == MB_MENU_INITIALIZE)
4286 highlight_position = mx;
4287 drawHallOfFameList(first_entry, highlight_position);
4292 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4293 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4297 if (first_entry > 0)
4299 first_entry -= step;
4300 if (first_entry < 0)
4303 drawHallOfFameList(first_entry, highlight_position);
4308 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4310 first_entry += step;
4311 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4312 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4314 drawHallOfFameList(first_entry, highlight_position);
4317 else if (button == MB_MENU_LEAVE)
4319 PlaySound(SND_MENU_ITEM_SELECTING);
4321 FadeSound(SND_BACKGROUND_SCORES);
4323 game_status = GAME_MODE_MAIN;
4327 else if (button == MB_MENU_CHOICE)
4329 PlaySound(SND_MENU_ITEM_SELECTING);
4331 FadeSound(SND_BACKGROUND_SCORES);
4334 FadeOut(REDRAW_FIELD);
4337 game_status = GAME_MODE_MAIN;
4339 DrawAndFadeInMainMenu(REDRAW_FIELD);
4342 if (game_status == GAME_MODE_SCORES)
4343 PlayMenuSoundIfLoop();
4349 /* ========================================================================= */
4350 /* setup screen functions */
4351 /* ========================================================================= */
4353 static struct TokenInfo *setup_info;
4354 static int num_setup_info;
4356 static char *screen_mode_text;
4357 static char *scroll_delay_text;
4358 static char *game_speed_text;
4359 static char *graphics_set_name;
4360 static char *sounds_set_name;
4361 static char *music_set_name;
4363 static void execSetupMain()
4369 setup_mode = SETUP_MODE_MAIN;
4373 static void execSetupGame()
4379 if (game_speeds == NULL)
4383 for (i = 0; game_speeds_list[i].value != -1; i++)
4385 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4386 char identifier[32], name[32];
4387 int value = game_speeds_list[i].value;
4388 char *text = game_speeds_list[i].text;
4390 ti->node_top = &game_speeds;
4391 ti->sort_priority = 10000 - value;
4393 sprintf(identifier, "%d", value);
4394 sprintf(name, "%s", text);
4396 setString(&ti->identifier, identifier);
4397 setString(&ti->name, name);
4398 setString(&ti->name_sorting, name);
4399 setString(&ti->infotext, "Game Speed");
4401 pushTreeInfo(&game_speeds, ti);
4404 /* sort game speed values to start with slowest game speed */
4405 sortTreeInfo(&game_speeds);
4407 /* set current game speed to configured game speed value */
4408 game_speed_current =
4409 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4411 /* if that fails, set current game speed to reliable default value */
4412 if (game_speed_current == NULL)
4413 game_speed_current =
4414 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4416 /* if that also fails, set current game speed to first available speed */
4417 if (game_speed_current == NULL)
4418 game_speed_current = game_speeds;
4421 setup.game_frame_delay = atoi(game_speed_current->identifier);
4423 /* needed for displaying game speed text instead of identifier */
4424 game_speed_text = game_speed_current->name;
4426 setup_mode = SETUP_MODE_GAME;
4430 static void execSetupChooseGameSpeed()
4436 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4440 static void execSetupEditor()
4446 setup_mode = SETUP_MODE_EDITOR;
4450 static void execSetupGraphics()
4456 if (video.fullscreen_available && screen_modes == NULL)
4460 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4462 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4463 char identifier[32], name[32];
4464 int x = video.fullscreen_modes[i].width;
4465 int y = video.fullscreen_modes[i].height;
4468 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4470 ti->node_top = &screen_modes;
4471 ti->sort_priority = x * 10000 + y;
4473 sprintf(identifier, "%dx%d", x, y);
4474 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4476 setString(&ti->identifier, identifier);
4477 setString(&ti->name, name);
4478 setString(&ti->name_sorting, name);
4479 setString(&ti->infotext, "Fullscreen Mode");
4481 pushTreeInfo(&screen_modes, ti);
4484 /* sort fullscreen modes to start with lowest available screen resolution */
4485 sortTreeInfo(&screen_modes);
4487 /* set current screen mode for fullscreen mode to configured setup value */
4488 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4489 setup.fullscreen_mode);
4491 /* if that fails, set current screen mode to reliable default value */
4492 if (screen_mode_current == NULL)
4493 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4494 DEFAULT_FULLSCREEN_MODE);
4496 /* if that also fails, set current screen mode to first available mode */
4497 if (screen_mode_current == NULL)
4498 screen_mode_current = screen_modes;
4500 if (screen_mode_current == NULL)
4501 video.fullscreen_available = FALSE;
4504 if (video.fullscreen_available)
4506 setup.fullscreen_mode = screen_mode_current->identifier;
4508 /* needed for displaying screen mode name instead of identifier */
4509 screen_mode_text = screen_mode_current->name;
4513 if (scroll_delays == NULL)
4517 for (i = 0; scroll_delays_list[i].value != -1; i++)
4519 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4520 char identifier[32], name[32];
4521 int value = scroll_delays_list[i].value;
4522 char *text = scroll_delays_list[i].text;
4524 ti->node_top = &scroll_delays;
4525 ti->sort_priority = value;
4527 sprintf(identifier, "%d", value);
4528 sprintf(name, "%s", text);
4530 setString(&ti->identifier, identifier);
4531 setString(&ti->name, name);
4532 setString(&ti->name_sorting, name);
4533 setString(&ti->infotext, "Scroll Delay");
4535 pushTreeInfo(&scroll_delays, ti);
4538 /* sort scroll delay values to start with lowest scroll delay value */
4539 sortTreeInfo(&scroll_delays);
4541 /* set current scroll delay value to configured scroll delay value */
4542 scroll_delay_current =
4543 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4545 /* if that fails, set current scroll delay to reliable default value */
4546 if (scroll_delay_current == NULL)
4547 scroll_delay_current =
4548 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4550 /* if that also fails, set current scroll delay to first available value */
4551 if (scroll_delay_current == NULL)
4552 scroll_delay_current = scroll_delays;
4555 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4557 /* needed for displaying scroll delay text instead of identifier */
4558 scroll_delay_text = scroll_delay_current->name;
4561 setup_mode = SETUP_MODE_GRAPHICS;
4565 static void execSetupChooseScreenMode()
4571 if (!video.fullscreen_available)
4574 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4578 static void execSetupChooseScrollDelay()
4584 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4588 static void execSetupSound()
4594 setup_mode = SETUP_MODE_SOUND;
4598 static void execSetupArtwork()
4604 setup.graphics_set = artwork.gfx_current->identifier;
4605 setup.sounds_set = artwork.snd_current->identifier;
4606 setup.music_set = artwork.mus_current->identifier;
4608 /* needed if last screen (setup choice) changed graphics, sounds or music */
4609 ReloadCustomArtwork(0);
4611 /* needed for displaying artwork name instead of artwork identifier */
4612 graphics_set_name = artwork.gfx_current->name;
4613 sounds_set_name = artwork.snd_current->name;
4614 music_set_name = artwork.mus_current->name;
4616 setup_mode = SETUP_MODE_ARTWORK;
4620 static void execSetupChooseGraphics()
4626 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4630 static void execSetupChooseSounds()
4636 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4640 static void execSetupChooseMusic()
4646 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4650 static void execSetupInput()
4656 setup_mode = SETUP_MODE_INPUT;
4660 static void execSetupShortcuts1()
4666 setup_mode = SETUP_MODE_SHORTCUTS_1;
4670 static void execSetupShortcuts2()
4676 setup_mode = SETUP_MODE_SHORTCUTS_2;
4680 static void execExitSetup()
4686 game_status = GAME_MODE_MAIN;
4688 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4694 static void execSaveAndExitSetup()
4700 static struct TokenInfo setup_info_main[] =
4702 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4703 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4704 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4705 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4706 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4707 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4708 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4709 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4710 { TYPE_EMPTY, NULL, "" },
4711 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4712 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4717 static struct TokenInfo setup_info_game[] =
4719 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4720 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4721 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4722 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4723 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4724 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4725 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4726 { TYPE_STRING, &game_speed_text, "" },
4727 { TYPE_EMPTY, NULL, "" },
4728 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4733 static struct TokenInfo setup_info_editor[] =
4736 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4737 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4738 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4739 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4740 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4741 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4742 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4743 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4745 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4746 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4747 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4749 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4751 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4752 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4753 { TYPE_EMPTY, NULL, "" },
4755 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4756 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4757 { TYPE_EMPTY, NULL, "" },
4759 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4760 { TYPE_EMPTY, NULL, "" },
4761 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4766 static struct TokenInfo setup_info_graphics[] =
4768 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4769 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4770 { TYPE_STRING, &screen_mode_text, "" },
4772 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4774 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4775 { TYPE_STRING, &scroll_delay_text, "" },
4777 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4778 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4780 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4781 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4782 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4783 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4784 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4785 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4786 { TYPE_EMPTY, NULL, "" },
4787 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4792 static struct TokenInfo setup_info_sound[] =
4794 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4795 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4796 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4797 { TYPE_EMPTY, NULL, "" },
4798 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4803 static struct TokenInfo setup_info_artwork[] =
4805 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4806 { TYPE_STRING, &graphics_set_name, "" },
4807 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4808 { TYPE_STRING, &sounds_set_name, "" },
4809 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4810 { TYPE_STRING, &music_set_name, "" },
4811 { TYPE_EMPTY, NULL, "" },
4813 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4814 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4815 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4817 { TYPE_STRING, NULL, "Override Level Artwork:"},
4818 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4819 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4820 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4822 { TYPE_EMPTY, NULL, "" },
4823 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4828 static struct TokenInfo setup_info_input[] =
4830 { TYPE_SWITCH, NULL, "Player:" },
4831 { TYPE_SWITCH, NULL, "Device:" },
4832 { TYPE_ENTER_MENU, NULL, "" },
4833 { TYPE_EMPTY, NULL, "" },
4834 { TYPE_EMPTY, NULL, "" },
4835 { TYPE_EMPTY, NULL, "" },
4836 { TYPE_EMPTY, NULL, "" },
4837 { TYPE_EMPTY, NULL, "" },
4838 { TYPE_EMPTY, NULL, "" },
4839 { TYPE_EMPTY, NULL, "" },
4840 { TYPE_EMPTY, NULL, "" },
4841 { TYPE_EMPTY, NULL, "" },
4842 { TYPE_EMPTY, NULL, "" },
4843 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4848 static struct TokenInfo setup_info_shortcuts_1[] =
4850 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4851 { TYPE_KEY, &setup.shortcut.save_game, "" },
4852 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4853 { TYPE_KEY, &setup.shortcut.load_game, "" },
4854 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4855 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4856 { TYPE_EMPTY, NULL, "" },
4857 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4858 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4859 { TYPE_EMPTY, NULL, "" },
4860 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4865 static struct TokenInfo setup_info_shortcuts_2[] =
4867 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4868 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4869 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4870 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4871 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4872 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4873 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4874 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4875 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4876 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4877 { TYPE_EMPTY, NULL, "" },
4878 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4883 static Key getSetupKey()
4885 Key key = KSYM_UNDEFINED;
4886 boolean got_key_event = FALSE;
4888 while (!got_key_event)
4890 if (PendingEvent()) /* got event */
4898 case EVENT_KEYPRESS:
4900 key = GetEventKey((KeyEvent *)&event, TRUE);
4902 /* press 'Escape' or 'Enter' to keep the existing key binding */
4903 if (key == KSYM_Escape || key == KSYM_Return)
4904 key = KSYM_UNDEFINED; /* keep old value */
4906 got_key_event = TRUE;
4910 case EVENT_KEYRELEASE:
4911 key_joystick_mapping = 0;
4915 HandleOtherEvents(&event);
4923 /* don't eat all CPU time */
4930 static int getSetupTextFont(int type)
4932 if (type & (TYPE_SWITCH |
4943 static int getSetupValueFont(int type, void *value)
4945 if (type & TYPE_KEY)
4946 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4947 else if (type & TYPE_STRING)
4948 return FONT_VALUE_2;
4949 else if (type & TYPE_ECS_AGA)
4950 return FONT_VALUE_1;
4951 else if (type & TYPE_BOOLEAN_STYLE)
4952 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4954 return FONT_VALUE_1;
4957 static void drawSetupValue(int pos)
4959 boolean font_draw_xoffset_modified = FALSE;
4960 int font_draw_xoffset_old = -1;
4961 int xpos = MENU_SCREEN_VALUE_XPOS;
4962 int ypos = MENU_SCREEN_START_YPOS + pos;
4963 int startx = mSX + xpos * 32;
4964 int starty = mSY + ypos * 32;
4965 int font_nr, font_width;
4966 int type = setup_info[pos].type;
4967 void *value = setup_info[pos].value;
4968 char *value_string = getSetupValue(type, value);
4971 if (value_string == NULL)
4974 if (type & TYPE_KEY)
4976 xpos = MENU_SCREEN_START_XPOS;
4978 if (type & TYPE_QUERY)
4980 value_string = "<press key>";
4983 else if (type & TYPE_STRING)
4985 int max_value_len = (SCR_FIELDX - 2) * 2;
4987 xpos = MENU_SCREEN_START_XPOS;
4989 if (strlen(value_string) > max_value_len)
4990 value_string[max_value_len] = '\0';
4993 startx = mSX + xpos * 32;
4994 starty = mSY + ypos * 32;
4995 font_nr = getSetupValueFont(type, value);
4996 font_width = getFontWidth(font_nr);
4998 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4999 if (setup_mode != SETUP_MODE_INPUT)
5001 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5002 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5003 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5004 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5005 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5006 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5007 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5008 boolean correct_font_draw_xoffset = FALSE;
5010 if (xpos == MENU_SCREEN_START_XPOS &&
5011 startx + font1_xoffset < text_startx + text_font_xoffset)
5012 correct_font_draw_xoffset = TRUE;
5014 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5015 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5016 correct_font_draw_xoffset = TRUE;
5018 /* check if setup value would overlap with setup text when printed */
5019 /* (this can happen for extreme/wrong values for font draw offset) */
5020 if (correct_font_draw_xoffset)
5022 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5023 font_draw_xoffset_modified = TRUE;
5025 if (type & TYPE_KEY)
5026 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5027 else if (!(type & TYPE_STRING))
5028 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5029 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5033 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5034 DrawText(startx + i * font_width, starty, " ", font_nr);
5036 DrawText(startx, starty, value_string, font_nr);
5038 if (font_draw_xoffset_modified)
5039 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5042 static void changeSetupValue(int pos)
5044 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5046 *(boolean *)setup_info[pos].value ^= TRUE;
5048 else if (setup_info[pos].type & TYPE_KEY)
5052 setup_info[pos].type |= TYPE_QUERY;
5053 drawSetupValue(pos);
5054 setup_info[pos].type &= ~TYPE_QUERY;
5056 key = getSetupKey();
5057 if (key != KSYM_UNDEFINED)
5058 *(Key *)setup_info[pos].value = key;
5061 drawSetupValue(pos);
5064 static void DrawCursorAndText_Setup(int pos, boolean active)
5066 int xpos = MENU_SCREEN_START_XPOS;
5067 int ypos = MENU_SCREEN_START_YPOS + pos;
5068 int font_nr = getSetupTextFont(setup_info[pos].type);
5070 if (setup_info == setup_info_input)
5071 font_nr = FONT_MENU_1;
5074 font_nr = FONT_ACTIVE(font_nr);
5076 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5078 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5079 drawCursor(pos, active);
5082 static void DrawSetupScreen_Generic()
5084 char *title_string = NULL;
5088 CloseDoor(DOOR_CLOSE_2);
5091 FadeOut(REDRAW_FIELD);
5096 if (setup_mode == SETUP_MODE_MAIN)
5098 setup_info = setup_info_main;
5099 title_string = "Setup";
5101 else if (setup_mode == SETUP_MODE_GAME)
5103 setup_info = setup_info_game;
5104 title_string = "Setup Game";
5106 else if (setup_mode == SETUP_MODE_EDITOR)
5108 setup_info = setup_info_editor;
5109 title_string = "Setup Editor";
5111 else if (setup_mode == SETUP_MODE_GRAPHICS)
5113 setup_info = setup_info_graphics;
5114 title_string = "Setup Graphics";
5116 else if (setup_mode == SETUP_MODE_SOUND)
5118 setup_info = setup_info_sound;
5119 title_string = "Setup Sound";
5121 else if (setup_mode == SETUP_MODE_ARTWORK)
5123 setup_info = setup_info_artwork;
5124 title_string = "Custom Artwork";
5126 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5128 setup_info = setup_info_shortcuts_1;
5129 title_string = "Setup Shortcuts";
5131 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5133 setup_info = setup_info_shortcuts_2;
5134 title_string = "Setup Shortcuts";
5137 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5140 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5142 void *value_ptr = setup_info[i].value;
5145 int xpos = MENU_SCREEN_START_XPOS;
5146 int ypos = MENU_SCREEN_START_YPOS + i;
5150 /* set some entries to "unchangeable" according to other variables */
5151 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5152 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5153 (value_ptr == &setup.sound_music && !audio.music_available) ||
5154 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5155 (value_ptr == &screen_mode_text && !video.fullscreen_available))
5156 setup_info[i].type |= TYPE_GHOSTED;
5158 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5159 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5160 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5161 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5162 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5163 initCursor(i, IMG_MENU_BUTTON);
5166 DrawCursorAndText_Setup(i, FALSE);
5168 font_nr = getSetupTextFont(setup_info[i].type);
5170 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5173 if (setup_info[i].type & TYPE_VALUE)
5180 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5181 "Joysticks deactivated in setup menu");
5185 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5189 FadeIn(REDRAW_FIELD);
5194 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5198 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5200 static int choice_store[MAX_SETUP_MODES];
5201 int choice = choice_store[setup_mode]; /* always starts with 0 */
5205 if (button == MB_MENU_INITIALIZE)
5207 /* advance to first valid menu entry */
5208 while (choice < num_setup_info &&
5209 setup_info[choice].type & TYPE_SKIP_ENTRY)
5211 choice_store[setup_mode] = choice;
5214 DrawCursorAndText_Setup(choice, TRUE);
5216 drawCursor(choice, TRUE);
5221 else if (button == MB_MENU_LEAVE)
5223 PlaySound(SND_MENU_ITEM_SELECTING);
5225 for (y = 0; y < num_setup_info; y++)
5227 if (setup_info[y].type & TYPE_LEAVE_MENU)
5229 void (*menu_callback_function)(void) = setup_info[y].value;
5233 menu_callback_function();
5235 break; /* absolutely needed because function changes 'setup_info'! */
5242 if (mx || my) /* mouse input */
5244 x = (mx - mSX) / 32;
5245 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5247 else if (dx || dy) /* keyboard input */
5251 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5253 if (setup_info[choice].type & menu_navigation_type ||
5254 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5255 button = MB_MENU_CHOICE;
5260 /* jump to next non-empty menu entry (up or down) */
5261 while (y > 0 && y < num_setup_info - 1 &&
5262 setup_info[y].type & TYPE_SKIP_ENTRY)
5266 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5270 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5272 PlaySound(SND_MENU_ITEM_ACTIVATING);
5275 DrawCursorAndText_Setup(choice, FALSE);
5276 DrawCursorAndText_Setup(y, TRUE);
5278 drawCursor(choice, FALSE);
5279 drawCursor(y, TRUE);
5282 choice = choice_store[setup_mode] = y;
5285 else if (!(setup_info[y].type & TYPE_GHOSTED))
5287 PlaySound(SND_MENU_ITEM_SELECTING);
5289 /* when selecting key headline, execute function for key value change */
5290 if (setup_info[y].type & TYPE_KEYTEXT &&
5291 setup_info[y + 1].type & TYPE_KEY)
5294 /* when selecting string value, execute function for list selection */
5295 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5296 setup_info[y - 1].type & TYPE_ENTER_LIST)
5299 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5301 void (*menu_callback_function)(void) = setup_info[y].value;
5303 FadeSetFromType(setup_info[y].type);
5305 menu_callback_function();
5309 if (setup_info[y].type & TYPE_VALUE)
5310 changeSetupValue(y);
5316 void DrawSetupScreen_Input()
5323 FadeOut(REDRAW_FIELD);
5329 setup_info = setup_info_input;
5332 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5335 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5337 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5338 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5339 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5340 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5341 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5342 initCursor(i, IMG_MENU_BUTTON);
5344 DrawCursorAndText_Setup(i, FALSE);
5347 initCursor(0, IMG_MENU_BUTTON);
5348 initCursor(1, IMG_MENU_BUTTON);
5349 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
5350 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5352 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
5353 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
5354 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
5358 DeactivateJoystickForCalibration();
5361 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5362 "Joysticks deactivated on this screen");
5365 /* create gadgets for setup input menu screen */
5366 FreeScreenGadgets();
5367 CreateScreenGadgets();
5369 /* map gadgets for setup input menu screen */
5370 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5372 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5375 FadeIn(REDRAW_FIELD);
5381 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5383 if (device_name == NULL)
5386 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5389 if (strlen(device_name) > 1)
5391 char c1 = device_name[strlen(device_name) - 1];
5392 char c2 = device_name[strlen(device_name) - 2];
5394 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5395 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5398 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5399 strlen(device_name));
5402 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5405 static struct SetupKeyboardInfo custom_key;
5412 { &custom_key.left, "Joystick Left" },
5413 { &custom_key.right, "Joystick Right" },
5414 { &custom_key.up, "Joystick Up" },
5415 { &custom_key.down, "Joystick Down" },
5416 { &custom_key.snap, "Button 1" },
5417 { &custom_key.drop, "Button 2" }
5419 static char *joystick_name[MAX_PLAYERS] =
5426 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5430 custom_key = setup.input[player_nr].key;
5432 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5433 FONT_INPUT_1_ACTIVE);
5435 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5437 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5438 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5440 if (setup.input[player_nr].use_joystick)
5442 char *device_name = setup.input[player_nr].joy.device_name;
5443 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5444 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5446 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5447 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5451 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5452 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5455 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5457 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5458 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5459 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5460 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5462 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5463 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5464 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5465 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5466 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5467 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5469 for (i = 0; i < 6; i++)
5471 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5473 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5475 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5476 (setup.input[player_nr].use_joystick ?
5478 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5482 static int input_player_nr = 0;
5484 void HandleSetupScreen_Input_Player(int step, int direction)
5486 int old_player_nr = input_player_nr;
5489 new_player_nr = old_player_nr + step * direction;
5490 if (new_player_nr < 0)
5492 if (new_player_nr > MAX_PLAYERS - 1)
5493 new_player_nr = MAX_PLAYERS - 1;
5495 if (new_player_nr != old_player_nr)
5497 input_player_nr = new_player_nr;
5499 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5503 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5505 static int choice = 0;
5508 int pos_start = SETUPINPUT_SCREEN_POS_START;
5509 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5510 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5511 int pos_end = SETUPINPUT_SCREEN_POS_END;
5513 if (button == MB_MENU_INITIALIZE)
5515 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5518 DrawCursorAndText_Setup(choice, TRUE);
5520 drawCursor(choice, TRUE);
5525 else if (button == MB_MENU_LEAVE)
5527 setup_mode = SETUP_MODE_MAIN;
5534 if (mx || my) /* mouse input */
5536 x = (mx - mSX) / 32;
5537 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5539 else if (dx || dy) /* keyboard input */
5541 if (dx && choice == 0)
5542 x = (dx < 0 ? 10 : 12);
5543 else if ((dx && choice == 1) ||
5544 (dx == +1 && choice == 2) ||
5545 (dx == -1 && choice == pos_end))
5546 button = MB_MENU_CHOICE;
5550 if (y >= pos_empty1 && y <= pos_empty2)
5551 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5554 if (y == 0 && dx != 0 && button)
5556 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5558 else if (IN_VIS_FIELD(x, y) &&
5559 y >= pos_start && y <= pos_end &&
5560 !(y >= pos_empty1 && y <= pos_empty2))
5567 DrawCursorAndText_Setup(choice, FALSE);
5568 DrawCursorAndText_Setup(y, TRUE);
5570 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5572 drawCursor(choice, FALSE);
5573 drawCursor(y, TRUE);
5583 char *device_name = setup.input[input_player_nr].joy.device_name;
5585 if (!setup.input[input_player_nr].use_joystick)
5587 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5589 setJoystickDeviceToNr(device_name, new_device_nr);
5590 setup.input[input_player_nr].use_joystick = TRUE;
5594 int device_nr = getJoystickNrFromDeviceName(device_name);
5595 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5597 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5598 setup.input[input_player_nr].use_joystick = FALSE;
5600 setJoystickDeviceToNr(device_name, new_device_nr);
5603 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5607 if (setup.input[input_player_nr].use_joystick)
5610 CalibrateJoystick(input_player_nr);
5613 CustomizeKeyboard(input_player_nr);
5615 else if (y == pos_end)
5621 setup_mode = SETUP_MODE_MAIN;
5628 void CustomizeKeyboard(int player_nr)
5632 boolean finished = FALSE;
5633 static struct SetupKeyboardInfo custom_key;
5638 } customize_step[] =
5640 { &custom_key.left, "Move Left" },
5641 { &custom_key.right, "Move Right" },
5642 { &custom_key.up, "Move Up" },
5643 { &custom_key.down, "Move Down" },
5644 { &custom_key.snap, "Snap Field" },
5645 { &custom_key.drop, "Drop Element" }
5648 /* read existing key bindings from player setup */
5649 custom_key = setup.input[player_nr].key;
5652 FadeOut(REDRAW_FIELD);
5656 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5664 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5665 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5666 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5667 "Key:", FONT_INPUT_1_ACTIVE);
5668 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5669 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5672 FadeIn(REDRAW_FIELD);
5679 if (PendingEvent()) /* got event */
5687 case EVENT_KEYPRESS:
5689 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5691 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5693 if (key == KSYM_Escape)
5694 FadeSkipNextFadeIn();
5700 /* all keys configured -- wait for "Escape" or "Return" key */
5704 /* press 'Enter' to keep the existing key binding */
5705 if (key == KSYM_Return)
5706 key = *customize_step[step_nr].key;
5708 /* check if key already used */
5709 for (i = 0; i < step_nr; i++)
5710 if (*customize_step[i].key == key)
5715 /* got new key binding */
5716 *customize_step[step_nr].key = key;
5717 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5719 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5720 getKeyNameFromKey(key), FONT_VALUE_1);
5723 /* un-highlight last query */
5724 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5725 customize_step[step_nr - 1].text, FONT_MENU_1);
5726 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5727 "Key:", FONT_MENU_1);
5729 /* press 'Enter' to leave */
5732 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5733 "Press Enter", FONT_TITLE_1);
5737 /* query next key binding */
5738 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5739 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5740 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5741 "Key:", FONT_INPUT_1_ACTIVE);
5742 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5743 getKeyNameFromKey(*customize_step[step_nr].key),
5748 case EVENT_KEYRELEASE:
5749 key_joystick_mapping = 0;
5753 HandleOtherEvents(&event);
5761 /* don't eat all CPU time */
5765 /* write new key bindings back to player setup */
5766 setup.input[player_nr].key = custom_key;
5769 DrawSetupScreen_Input();
5772 static boolean CalibrateJoystickMain(int player_nr)
5774 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5775 int new_joystick_xright = JOYSTICK_XMIDDLE;
5776 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5777 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5778 int new_joystick_xmiddle, new_joystick_ymiddle;
5780 int joystick_fd = joystick.fd[player_nr];
5781 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5782 boolean check[3][3];
5783 int check_remaining = 3 * 3;
5788 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5791 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5795 FadeOut(REDRAW_FIELD);
5799 for (y = 0; y < 3; y++)
5801 for (x = 0; x < 3; x++)
5803 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5804 check[x][y] = FALSE;
5808 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5809 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5810 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5811 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5812 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5813 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5814 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5816 joy_value = Joystick(player_nr);
5817 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5818 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5820 /* eventually uncalibrated center position (joystick could be uncentered) */
5821 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5824 new_joystick_xmiddle = joy_x;
5825 new_joystick_ymiddle = joy_y;
5827 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5830 FadeIn(REDRAW_FIELD);
5835 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5840 if (PendingEvent()) /* got event */
5848 case EVENT_KEYPRESS:
5849 switch (GetEventKey((KeyEvent *)&event, TRUE))
5852 if (check_remaining == 0)
5857 FadeSkipNextFadeIn();
5866 case EVENT_KEYRELEASE:
5867 key_joystick_mapping = 0;
5871 HandleOtherEvents(&event);
5876 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5879 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5880 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5881 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5882 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5884 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5885 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5886 setup.input[player_nr].joy.xright = new_joystick_xright;
5887 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5888 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5889 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5891 CheckJoystickData();
5893 joy_value = Joystick(player_nr);
5895 if (joy_value & JOY_BUTTON && check_remaining == 0)
5898 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5899 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5901 if (x != last_x || y != last_y)
5903 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5904 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5909 if (check_remaining > 0 && !check[x+1][y+1])
5911 check[x+1][y+1] = TRUE;
5917 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5918 setup.input[player_nr].joy.xleft,
5919 setup.input[player_nr].joy.xmiddle,
5920 setup.input[player_nr].joy.xright);
5921 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5922 setup.input[player_nr].joy.yupper,
5923 setup.input[player_nr].joy.ymiddle,
5924 setup.input[player_nr].joy.ylower);
5933 /* don't eat all CPU time */
5937 /* calibrated center position (joystick should now be centered) */
5938 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5941 new_joystick_xmiddle = joy_x;
5942 new_joystick_ymiddle = joy_y;
5947 DrawSetupScreen_Input();
5950 /* wait until the last pressed button was released */
5951 while (Joystick(player_nr) & JOY_BUTTON)
5953 if (PendingEvent()) /* got event */
5958 HandleOtherEvents(&event);
5967 void CalibrateJoystick(int player_nr)
5969 if (!CalibrateJoystickMain(player_nr))
5971 char *device_name = setup.input[player_nr].joy.device_name;
5972 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5973 int xpos = mSX - SX;
5974 int ypos = mSY - SY;
5978 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5979 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5982 Delay(2000); /* show error message for a short time */
5988 DrawSetupScreen_Input();
5992 void DrawSetupScreen()
5994 DeactivateJoystick();
5996 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5998 if (setup_mode == SETUP_MODE_INPUT)
5999 DrawSetupScreen_Input();
6000 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6001 DrawChooseTree(&game_speed_current);
6002 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6003 DrawChooseTree(&screen_mode_current);
6004 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6005 DrawChooseTree(&scroll_delay_current);
6006 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6007 DrawChooseTree(&artwork.gfx_current);
6008 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6009 DrawChooseTree(&artwork.snd_current);
6010 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6011 DrawChooseTree(&artwork.mus_current);
6013 DrawSetupScreen_Generic();
6019 void RedrawSetupScreenAfterFullscreenToggle()
6021 if (setup_mode == SETUP_MODE_GRAPHICS)
6025 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6027 if (setup_mode == SETUP_MODE_INPUT)
6028 HandleSetupScreen_Input(mx, my, dx, dy, button);
6029 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6030 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6031 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6032 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6033 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6034 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6035 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6036 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6037 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6038 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6039 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6040 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6042 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6047 void HandleGameActions()
6049 if (game_status != GAME_MODE_PLAYING)
6052 GameActions(); /* main game loop */
6054 if (tape.auto_play && !tape.playing)
6055 AutoPlayTape(); /* continue automatically playing next tape */
6059 /* ---------- new screen button stuff -------------------------------------- */
6061 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6066 case SCREEN_CTRL_ID_PREV_LEVEL:
6067 *x = mSX + menu.main.button.prev_level.x;
6068 *y = mSY + menu.main.button.prev_level.y;
6071 case SCREEN_CTRL_ID_NEXT_LEVEL:
6072 *x = mSX + menu.main.button.next_level.x;
6073 *y = mSY + menu.main.button.next_level.y;
6076 case SCREEN_CTRL_ID_PREV_LEVEL:
6077 *x = mSX + TILEX * getPrevlevelButtonPos();
6078 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6081 case SCREEN_CTRL_ID_NEXT_LEVEL:
6082 *x = mSX + TILEX * getNextLevelButtonPos();
6083 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6087 case SCREEN_CTRL_ID_PREV_PLAYER:
6088 *x = mSX + TILEX * 10;
6089 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6092 case SCREEN_CTRL_ID_NEXT_PLAYER:
6093 *x = mSX + TILEX * 12;
6094 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6098 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6104 int gfx_unpressed, gfx_pressed;
6105 void (*get_gadget_position)(int *, int *, int);
6109 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6112 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6113 getScreenMenuButtonPos,
6114 SCREEN_CTRL_ID_PREV_LEVEL,
6119 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6120 getScreenMenuButtonPos,
6121 SCREEN_CTRL_ID_NEXT_LEVEL,
6126 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6127 getScreenMenuButtonPos,
6128 SCREEN_CTRL_ID_PREV_PLAYER,
6133 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6134 getScreenMenuButtonPos,
6135 SCREEN_CTRL_ID_NEXT_PLAYER,
6143 int gfx_unpressed, gfx_pressed;
6147 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6150 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6151 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6152 SCREEN_CTRL_ID_SCROLL_UP,
6156 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6157 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6158 SCREEN_CTRL_ID_SCROLL_DOWN,
6165 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6166 Bitmap **gfx_unpressed, **gfx_pressed;
6168 int gfx_unpressed, gfx_pressed;
6175 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6178 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6179 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6181 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6183 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6184 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6185 GD_TYPE_SCROLLBAR_VERTICAL,
6186 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6187 "scroll level series vertically"
6191 static void CreateScreenMenubuttons()
6193 struct GadgetInfo *gi;
6194 unsigned long event_mask;
6197 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6199 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6200 int gfx_unpressed, gfx_pressed;
6201 int x, y, width, height;
6202 int gd_x1, gd_x2, gd_y1, gd_y2;
6203 int id = menubutton_info[i].gadget_id;
6205 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6207 menubutton_info[i].get_gadget_position(&x, &y, id);
6209 width = SC_MENUBUTTON_XSIZE;
6210 height = SC_MENUBUTTON_YSIZE;
6212 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6213 gfx_pressed = menubutton_info[i].gfx_pressed;
6214 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6215 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6216 gd_x1 = graphic_info[gfx_unpressed].src_x;
6217 gd_y1 = graphic_info[gfx_unpressed].src_y;
6218 gd_x2 = graphic_info[gfx_pressed].src_x;
6219 gd_y2 = graphic_info[gfx_pressed].src_y;
6221 gi = CreateGadget(GDI_CUSTOM_ID, id,
6222 GDI_CUSTOM_TYPE_ID, i,
6223 GDI_INFO_TEXT, menubutton_info[i].infotext,
6228 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6229 GDI_STATE, GD_BUTTON_UNPRESSED,
6230 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6231 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6232 GDI_DIRECT_DRAW, FALSE,
6233 GDI_EVENT_MASK, event_mask,
6234 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6238 Error(ERR_EXIT, "cannot create gadget");
6240 screen_gadget[id] = gi;
6244 static void CreateScreenScrollbuttons()
6246 struct GadgetInfo *gi;
6247 unsigned long event_mask;
6250 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6252 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6253 int gfx_unpressed, gfx_pressed;
6254 int x, y, width, height;
6255 int gd_x1, gd_x2, gd_y1, gd_y2;
6256 int id = scrollbutton_info[i].gadget_id;
6258 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6260 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6261 y = mSY + scrollbutton_info[i].y;
6262 width = SC_SCROLLBUTTON_XSIZE;
6263 height = SC_SCROLLBUTTON_YSIZE;
6265 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6266 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6267 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6269 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6270 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6271 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6272 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6273 gd_x1 = graphic_info[gfx_unpressed].src_x;
6274 gd_y1 = graphic_info[gfx_unpressed].src_y;
6275 gd_x2 = graphic_info[gfx_pressed].src_x;
6276 gd_y2 = graphic_info[gfx_pressed].src_y;
6278 gi = CreateGadget(GDI_CUSTOM_ID, id,
6279 GDI_CUSTOM_TYPE_ID, i,
6280 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6285 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6286 GDI_STATE, GD_BUTTON_UNPRESSED,
6287 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6288 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6289 GDI_DIRECT_DRAW, FALSE,
6290 GDI_EVENT_MASK, event_mask,
6291 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6295 Error(ERR_EXIT, "cannot create gadget");
6297 screen_gadget[id] = gi;
6301 static void CreateScreenScrollbars()
6305 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6307 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6308 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6309 int gfx_unpressed, gfx_pressed;
6311 int x, y, width, height;
6312 int gd_x1, gd_x2, gd_y1, gd_y2;
6313 struct GadgetInfo *gi;
6314 int items_max, items_visible, item_position;
6315 unsigned long event_mask;
6316 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6317 int id = scrollbar_info[i].gadget_id;
6319 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6321 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6322 y = mSY + scrollbar_info[i].y;
6323 width = scrollbar_info[i].width;
6324 height = scrollbar_info[i].height;
6326 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6327 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6329 items_max = num_page_entries;
6330 items_visible = num_page_entries;
6333 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6334 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6335 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6341 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6342 gfx_pressed = scrollbar_info[i].gfx_pressed;
6343 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6344 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6345 gd_x1 = graphic_info[gfx_unpressed].src_x;
6346 gd_y1 = graphic_info[gfx_unpressed].src_y;
6347 gd_x2 = graphic_info[gfx_pressed].src_x;
6348 gd_y2 = graphic_info[gfx_pressed].src_y;
6351 gi = CreateGadget(GDI_CUSTOM_ID, id,
6352 GDI_CUSTOM_TYPE_ID, i,
6353 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6358 GDI_TYPE, scrollbar_info[i].type,
6359 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6360 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6361 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6363 GDI_WHEEL_AREA_X, SX,
6364 GDI_WHEEL_AREA_Y, SY,
6365 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6366 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6368 GDI_WHEEL_AREA_X, 0,
6369 GDI_WHEEL_AREA_Y, 0,
6370 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6371 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6373 GDI_STATE, GD_BUTTON_UNPRESSED,
6374 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6375 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6376 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6377 GDI_DIRECT_DRAW, FALSE,
6378 GDI_EVENT_MASK, event_mask,
6379 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6383 Error(ERR_EXIT, "cannot create gadget");
6385 screen_gadget[id] = gi;
6389 void CreateScreenGadgets()
6391 int last_game_status = game_status; /* save current game status */
6393 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6396 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6398 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6400 /* copy pointers to clip mask and GC */
6401 scrollbar_bitmap[i]->clip_mask =
6402 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6403 scrollbar_bitmap[i]->stored_clip_gc =
6404 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6406 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6407 scrollbar_bitmap[i],
6408 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6409 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6410 TILEX, TILEY, 0, 0);
6414 CreateScreenMenubuttons();
6417 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6418 game_status = GAME_MODE_LEVELS;
6421 CreateScreenScrollbuttons();
6422 CreateScreenScrollbars();
6424 game_status = last_game_status; /* restore current game status */
6427 void FreeScreenGadgets()
6431 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6432 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6434 /* prevent freeing clip mask and GC twice */
6435 scrollbar_bitmap[i]->clip_mask = None;
6436 scrollbar_bitmap[i]->stored_clip_gc = None;
6438 FreeBitmap(scrollbar_bitmap[i]);
6442 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6443 FreeGadget(screen_gadget[i]);
6446 void MapScreenMenuGadgets(int screen_mask)
6450 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6451 if (screen_mask & menubutton_info[i].screen_mask)
6452 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6455 void MapScreenTreeGadgets(TreeInfo *ti)
6457 int num_entries = numTreeInfoInGroup(ti);
6460 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6463 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6464 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6466 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6467 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6470 static void HandleScreenGadgets(struct GadgetInfo *gi)
6472 int id = gi->custom_id;
6473 int button = gi->event.button;
6474 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6478 case SCREEN_CTRL_ID_PREV_LEVEL:
6479 HandleMainMenu_SelectLevel(step, -1);
6482 case SCREEN_CTRL_ID_NEXT_LEVEL:
6483 HandleMainMenu_SelectLevel(step, +1);
6486 case SCREEN_CTRL_ID_PREV_PLAYER:
6487 HandleSetupScreen_Input_Player(step, -1);
6490 case SCREEN_CTRL_ID_NEXT_PLAYER:
6491 HandleSetupScreen_Input_Player(step, +1);
6494 case SCREEN_CTRL_ID_SCROLL_UP:
6495 if (game_status == GAME_MODE_LEVELS)
6496 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6497 else if (game_status == GAME_MODE_SETUP)
6498 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6501 case SCREEN_CTRL_ID_SCROLL_DOWN:
6502 if (game_status == GAME_MODE_LEVELS)
6503 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6504 else if (game_status == GAME_MODE_SETUP)
6505 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6508 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6509 if (game_status == GAME_MODE_LEVELS)
6510 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6511 else if (game_status == GAME_MODE_SETUP)
6512 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);