1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
28 /* screens on the info screen */
29 #define INFO_MODE_MAIN 0
30 #define INFO_MODE_TITLE 1
31 #define INFO_MODE_ELEMENTS 2
32 #define INFO_MODE_MUSIC 3
33 #define INFO_MODE_CREDITS 4
34 #define INFO_MODE_PROGRAM 5
35 #define INFO_MODE_VERSION 6
36 #define INFO_MODE_LEVELSET 7
38 #define MAX_INFO_MODES 8
40 /* screens on the setup screen */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_SHORTCUTS 7
49 #define SETUP_MODE_SHORTCUTS_1 8
50 #define SETUP_MODE_SHORTCUTS_2 9
51 #define SETUP_MODE_SHORTCUTS_3 10
52 #define SETUP_MODE_SHORTCUTS_4 11
53 #define SETUP_MODE_SHORTCUTS_5 12
55 /* sub-screens on the setup screen (generic) */
56 #define SETUP_MODE_CHOOSE_ARTWORK 13
57 #define SETUP_MODE_CHOOSE_OTHER 14
59 /* sub-screens on the setup screen (specific) */
60 #define SETUP_MODE_CHOOSE_GAME_SPEED 15
61 #define SETUP_MODE_CHOOSE_SCREEN_MODE 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_GRAPHICS 18
64 #define SETUP_MODE_CHOOSE_SOUNDS 19
65 #define SETUP_MODE_CHOOSE_MUSIC 20
67 #define MAX_SETUP_MODES 21
69 /* for input setup functions */
70 #define SETUPINPUT_SCREEN_POS_START 0
71 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
72 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
73 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
75 /* for various menu stuff */
76 #define MENU_SCREEN_START_XPOS 1
77 #define MENU_SCREEN_START_YPOS 2
78 #define MENU_SCREEN_VALUE_XPOS 14
79 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
80 #define MENU_TITLE1_YPOS 8
81 #define MENU_TITLE2_YPOS 46
82 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
83 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
84 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
85 MENU_SCREEN_START_XPOS)
86 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
88 /* buttons and scrollbars identifiers */
89 #define SCREEN_CTRL_ID_PREV_LEVEL 0
90 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
91 #define SCREEN_CTRL_ID_PREV_PLAYER 2
92 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
93 #define SCREEN_CTRL_ID_SCROLL_UP 4
94 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
95 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
97 #define NUM_SCREEN_GADGETS 7
99 #define NUM_SCREEN_MENUBUTTONS 4
100 #define NUM_SCREEN_SCROLLBUTTONS 2
101 #define NUM_SCREEN_SCROLLBARS 1
103 #define SCREEN_MASK_MAIN (1 << 0)
104 #define SCREEN_MASK_INPUT (1 << 1)
106 /* graphic position and size values for buttons and scrollbars */
107 #define SC_MENUBUTTON_XSIZE TILEX
108 #define SC_MENUBUTTON_YSIZE TILEY
110 #define SC_SCROLLBUTTON_XSIZE TILEX
111 #define SC_SCROLLBUTTON_YSIZE TILEY
113 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
115 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
116 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
117 SC_SCROLLBUTTON_YSIZE)
119 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
120 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
124 SC_SCROLLBUTTON_YSIZE)
126 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
127 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
128 SC_SCROLL_VERTICAL_YSIZE)
130 #define SC_BORDER_SIZE 14
133 /* forward declarations of internal functions */
134 static void HandleScreenGadgets(struct GadgetInfo *);
135 static void HandleSetupScreen_Generic(int, int, int, int, int);
136 static void HandleSetupScreen_Input(int, int, int, int, int);
137 static void CustomizeKeyboard(int);
138 static void CalibrateJoystick(int);
139 static void execSetupGame(void);
140 static void execSetupGraphics(void);
141 static void execSetupArtwork(void);
142 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
144 static void DrawChooseLevelSet(void);
145 static void DrawChooseLevelNr(void);
146 static void DrawInfoScreen(void);
147 static void DrawAndFadeInInfoScreen(int);
148 static void DrawSetupScreen(void);
150 static void DrawInfoScreenExt(int, int);
151 static void DrawInfoScreen_NotAvailable(char *, char *);
152 static void DrawInfoScreen_HelpAnim(int, int, boolean);
153 static void DrawInfoScreen_HelpText(int, int, int, int);
154 static void HandleInfoScreen_Main(int, int, int, int, int);
155 static void HandleInfoScreen_TitleScreen(int);
156 static void HandleInfoScreen_Elements(int);
157 static void HandleInfoScreen_Music(int);
158 static void HandleInfoScreen_Credits(int);
159 static void HandleInfoScreen_Program(int);
160 static void HandleInfoScreen_Version(int);
162 static void MapScreenMenuGadgets(int);
163 static void MapScreenTreeGadgets(TreeInfo *);
165 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
167 static int info_mode = INFO_MODE_MAIN;
168 static int setup_mode = SETUP_MODE_MAIN;
170 static TreeInfo *screen_modes = NULL;
171 static TreeInfo *screen_mode_current = NULL;
173 static TreeInfo *scroll_delays = NULL;
174 static TreeInfo *scroll_delay_current = NULL;
176 static TreeInfo *game_speeds = NULL;
177 static TreeInfo *game_speed_current = NULL;
179 static TreeInfo *level_number = NULL;
180 static TreeInfo *level_number_current = NULL;
186 } game_speeds_list[] =
195 { 1000, "1/1s (Extremely Slow)" },
200 { 29, "1/35s (Original Supaplex)" },
202 { 20, "1/50s (Normal Speed)" },
203 { 14, "1/70s (Maximum Supaplex)" },
207 { 1, "1/1000s (Extremely Fast)" },
217 } scroll_delays_list[] =
219 { 0, "0 Tiles (No Scroll Delay)" },
222 { 3, "3 Tiles (Default)" },
227 { 8, "8 Tiles (Maximum Scroll Delay)"},
232 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
233 (s) <= GAME_MODE_SETUP ? (s) : \
234 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
235 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
237 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
238 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
239 (i) <= INFO_MODE_LEVELSET ? (i) : \
242 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
243 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
244 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
245 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
246 SETUP_MODE_CHOOSE_ARTWORK : \
247 SETUP_MODE_CHOOSE_OTHER)
249 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
250 menu.draw_xoffset[GAME_MODE_INFO] : \
251 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
252 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
253 menu.draw_yoffset[GAME_MODE_INFO] : \
254 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
256 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
257 menu.draw_xoffset[GAME_MODE_SETUP] : \
258 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
259 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
260 menu.draw_yoffset[GAME_MODE_SETUP] : \
261 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
263 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
264 DRAW_XOFFSET_INFO(info_mode) : \
265 (s) == GAME_MODE_SETUP ? \
266 DRAW_XOFFSET_SETUP(setup_mode) : \
267 menu.draw_xoffset[DRAW_MODE(s)])
268 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
269 DRAW_YOFFSET_INFO(info_mode) : \
270 (s) == GAME_MODE_SETUP ? \
271 DRAW_YOFFSET_SETUP(setup_mode) : \
272 menu.draw_yoffset[DRAW_MODE(s)])
274 #define mSX (SX + DRAW_XOFFSET(game_status))
275 #define mSY (SY + DRAW_YOFFSET(game_status))
277 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
278 menu.list_size[game_status] : \
279 MAX_MENU_ENTRIES_ON_SCREEN)
281 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
282 #define NUM_SCROLLBAR_BITMAPS 2
283 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
287 /* title display and control definitions */
289 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
290 2 * MAX_NUM_TITLE_MESSAGES)
292 static int num_title_screens = 0;
294 struct TitleControlInfo
302 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
304 /* main menu display and control definitions */
306 #define MAIN_CONTROL_NAME 0
307 #define MAIN_CONTROL_LEVELS 1
308 #define MAIN_CONTROL_SCORES 2
309 #define MAIN_CONTROL_EDITOR 3
310 #define MAIN_CONTROL_INFO 4
311 #define MAIN_CONTROL_GAME 5
312 #define MAIN_CONTROL_SETUP 6
313 #define MAIN_CONTROL_QUIT 7
314 #define MAIN_CONTROL_PREV_LEVEL 8
315 #define MAIN_CONTROL_NEXT_LEVEL 9
316 #define MAIN_CONTROL_FIRST_LEVEL 10
317 #define MAIN_CONTROL_LAST_LEVEL 11
318 #define MAIN_CONTROL_LEVEL_NUMBER 12
319 #define MAIN_CONTROL_LEVEL_INFO_1 13
320 #define MAIN_CONTROL_LEVEL_INFO_2 14
321 #define MAIN_CONTROL_LEVEL_NAME 15
322 #define MAIN_CONTROL_LEVEL_AUTHOR 16
323 #define MAIN_CONTROL_LEVEL_YEAR 17
324 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
325 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
326 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
327 #define MAIN_CONTROL_TITLE_1 21
328 #define MAIN_CONTROL_TITLE_2 22
329 #define MAIN_CONTROL_TITLE_3 23
331 static char str_main_text_name[10];
332 static char str_main_text_first_level[10];
333 static char str_main_text_last_level[10];
334 static char str_main_text_level_number[10];
336 static char *main_text_name = str_main_text_name;
337 static char *main_text_first_level = str_main_text_first_level;
338 static char *main_text_last_level = str_main_text_last_level;
339 static char *main_text_level_number = str_main_text_level_number;
340 static char *main_text_levels = "Levelset";
341 static char *main_text_scores = "Hall Of Fame";
342 static char *main_text_editor = "Level Creator";
343 static char *main_text_info = "Info Screen";
344 static char *main_text_game = "Start Game";
345 static char *main_text_setup = "Setup";
346 static char *main_text_quit = "Quit";
347 static char *main_text_level_name = level.name;
348 static char *main_text_level_author = level.author;
349 static char *main_text_level_year = NULL;
350 static char *main_text_level_imported_from = NULL;
351 static char *main_text_level_imported_by = NULL;
352 static char *main_text_level_tested_by = NULL;
353 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
354 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
355 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
357 struct MainControlInfo
361 struct MenuPosInfo *pos_button;
364 struct TextPosInfo *pos_text;
367 struct TextPosInfo *pos_input;
371 static struct MainControlInfo main_controls[] =
375 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
376 &menu.main.text.name, &main_text_name,
377 &menu.main.input.name, &setup.player_name,
381 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
382 &menu.main.text.levels, &main_text_levels,
387 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
388 &menu.main.text.scores, &main_text_scores,
393 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
394 &menu.main.text.editor, &main_text_editor,
399 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
400 &menu.main.text.info, &main_text_info,
405 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
406 &menu.main.text.game, &main_text_game,
411 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
412 &menu.main.text.setup, &main_text_setup,
417 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
418 &menu.main.text.quit, &main_text_quit,
422 /* (these two buttons are real gadgets) */
424 MAIN_CONTROL_PREV_LEVEL,
425 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
430 MAIN_CONTROL_NEXT_LEVEL,
431 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
437 MAIN_CONTROL_FIRST_LEVEL,
439 &menu.main.text.first_level, &main_text_first_level,
443 MAIN_CONTROL_LAST_LEVEL,
445 &menu.main.text.last_level, &main_text_last_level,
449 MAIN_CONTROL_LEVEL_NUMBER,
451 &menu.main.text.level_number, &main_text_level_number,
455 MAIN_CONTROL_LEVEL_INFO_1,
457 &menu.main.text.level_info_1, NULL,
461 MAIN_CONTROL_LEVEL_INFO_2,
463 &menu.main.text.level_info_2, NULL,
467 MAIN_CONTROL_LEVEL_NAME,
469 &menu.main.text.level_name, &main_text_level_name,
473 MAIN_CONTROL_LEVEL_AUTHOR,
475 &menu.main.text.level_author, &main_text_level_author,
479 MAIN_CONTROL_LEVEL_YEAR,
481 &menu.main.text.level_year, &main_text_level_year,
485 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
487 &menu.main.text.level_imported_from, &main_text_level_imported_from,
491 MAIN_CONTROL_LEVEL_IMPORTED_BY,
493 &menu.main.text.level_imported_by, &main_text_level_imported_by,
497 MAIN_CONTROL_LEVEL_TESTED_BY,
499 &menu.main.text.level_tested_by, &main_text_level_tested_by,
503 MAIN_CONTROL_TITLE_1,
505 &menu.main.text.title_1, &main_text_title_1,
509 MAIN_CONTROL_TITLE_2,
511 &menu.main.text.title_2, &main_text_title_2,
515 MAIN_CONTROL_TITLE_3,
517 &menu.main.text.title_3, &main_text_title_3,
530 static int getTitleScreenGraphic(int nr, boolean initial)
532 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
535 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
537 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
541 static int getTitleScreenGameMode(boolean initial)
543 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
547 static int getTitleMessageGameMode(boolean initial)
549 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
553 static int getTitleScreenBackground(boolean initial)
555 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
560 static int getTitleMessageBackground(int nr, boolean initial)
562 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
566 static int getTitleBackground(int nr, boolean initial, boolean is_image)
568 int base = (is_image ?
569 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
570 IMG_BACKGROUND_TITLESCREEN_1) :
571 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
572 IMG_BACKGROUND_TITLEMESSAGE_1));
573 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
574 IMG_BACKGROUND_TITLE);
575 int graphic_local = base + nr;
577 if (graphic_info[graphic_local].bitmap != NULL)
578 return graphic_local;
580 if (graphic_info[graphic_global].bitmap != NULL)
581 return graphic_global;
583 return IMG_UNDEFINED;
586 static int getTitleSound(struct TitleControlInfo *tci)
588 boolean is_image = tci->is_image;
589 int initial = tci->initial;
590 int nr = tci->local_nr;
591 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
592 int base = (is_image ?
593 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
594 SND_BACKGROUND_TITLESCREEN_1) :
595 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
596 SND_BACKGROUND_TITLEMESSAGE_1));
597 int sound_global = menu.sound[mode];
598 int sound_local = base + nr;
601 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
602 nr, initial, is_image,
603 sound_global, getSoundListEntry(sound_global)->filename,
604 sound_local, getSoundListEntry(sound_local)->filename);
607 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
610 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
613 return SND_UNDEFINED;
616 static int getTitleMusic(struct TitleControlInfo *tci)
618 boolean is_image = tci->is_image;
619 int initial = tci->initial;
620 int nr = tci->local_nr;
621 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
622 int base = (is_image ?
623 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
624 MUS_BACKGROUND_TITLESCREEN_1) :
625 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
626 MUS_BACKGROUND_TITLEMESSAGE_1));
627 int music_global = menu.music[mode];
628 int music_local = base + nr;
631 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
632 nr, initial, is_image,
633 music_global, getMusicListEntry(music_global)->filename,
634 music_local, getMusicListEntry(music_local)->filename);
637 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
640 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
643 return MUS_UNDEFINED;
646 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
648 boolean is_image = tci->is_image;
649 int initial = tci->initial;
650 int nr = tci->local_nr;
651 struct TitleFadingInfo ti;
655 int graphic = getTitleScreenGraphic(nr, initial);
657 /* initialize fading control values to default title config settings */
658 ti = (initial ? title_initial_default : title_default);
660 /* override default settings with image config settings, if defined */
661 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
662 ti.fade_mode = graphic_info[graphic].fade_mode;
663 if (graphic_info[graphic].fade_delay > -1)
664 ti.fade_delay = graphic_info[graphic].fade_delay;
665 if (graphic_info[graphic].post_delay > -1)
666 ti.post_delay = graphic_info[graphic].post_delay;
667 if (graphic_info[graphic].auto_delay > -1)
668 ti.auto_delay = graphic_info[graphic].auto_delay;
674 ti.fade_mode = titlemessage_initial[nr].fade_mode;
675 ti.fade_delay = titlemessage_initial[nr].fade_delay;
676 ti.post_delay = titlemessage_initial[nr].post_delay;
677 ti.auto_delay = titlemessage_initial[nr].auto_delay;
681 ti.fade_mode = titlemessage[nr].fade_mode;
682 ti.fade_delay = titlemessage[nr].fade_delay;
683 ti.post_delay = titlemessage[nr].post_delay;
684 ti.auto_delay = titlemessage[nr].auto_delay;
689 if (ti.anim_mode == ANIM_NONE)
690 ti.fade_delay = ti.post_delay = 0;
696 static int compareTitleControlInfo(const void *object1, const void *object2)
698 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
699 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
702 if (tci1->initial != tci2->initial)
703 compare_result = (tci1->initial ? -1 : +1);
704 else if (tci1->sort_priority != tci2->sort_priority)
705 compare_result = tci1->sort_priority - tci2->sort_priority;
706 else if (tci1->is_image != tci2->is_image)
707 compare_result = (tci1->is_image ? -1 : +1);
709 compare_result = tci1->local_nr - tci2->local_nr;
711 return compare_result;
714 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
716 int nr, int sort_priority)
718 title_controls[num_title_screens].is_image = is_image;
719 title_controls[num_title_screens].initial = initial;
720 title_controls[num_title_screens].local_nr = nr;
721 title_controls[num_title_screens].sort_priority = sort_priority;
726 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
730 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
732 int graphic = getTitleScreenGraphic(i, initial);
733 Bitmap *bitmap = graphic_info[graphic].bitmap;
734 int sort_priority = graphic_info[graphic].sort_priority;
737 /* skip images and messages (fonts!) when using forced custom graphics */
738 if (setup.override_level_graphics && !initial)
743 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
746 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
748 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
749 char *filename = getLevelSetTitleMessageFilename(i, initial);
750 int sort_priority = tmi->sort_priority;
753 /* skip images and messages (fonts!) when using forced custom graphics */
754 if (setup.override_level_graphics)
758 if (filename != NULL)
759 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
763 static void InitializeTitleControls(boolean show_title_initial)
765 num_title_screens = 0;
768 /* 1st step: initialize title screens for game start (only when starting) */
769 if (show_title_initial)
770 InitializeTitleControls_CheckTitleInfo(TRUE);
773 /* 2nd step: initialize title screens for current level set */
774 InitializeTitleControls_CheckTitleInfo(FALSE);
776 /* sort title screens according to sort_priority and title number */
777 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
778 compareTitleControlInfo);
781 static boolean visibleMenuPos(struct MenuPosInfo *pos)
783 return (pos != NULL && pos->x != -1 && pos->y != -1);
786 static boolean visibleTextPos(struct TextPosInfo *pos)
788 return (pos != NULL && pos->x != -1 && pos->y != -1);
791 static void InitializeMainControls()
793 boolean local_team_mode = (!options.network && setup.team_mode);
796 /* set main control text values to dynamically determined values */
797 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
799 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
800 menu.main.text.first_level.size));
801 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
802 menu.main.text.last_level.size));
803 strcpy(main_text_level_number, int2str(level_nr,
804 menu.main.text.level_number.size));
806 main_text_level_year = leveldir_current->year;
807 main_text_level_imported_from = leveldir_current->imported_from;
808 main_text_level_imported_by = leveldir_current->imported_by;
809 main_text_level_tested_by = leveldir_current->tested_by;
811 /* set main control screen positions to dynamically determined values */
812 for (i = 0; main_controls[i].nr != -1; i++)
814 struct MainControlInfo *mci = &main_controls[i];
816 struct MenuPosInfo *pos_button = mci->pos_button;
817 struct TextPosInfo *pos_text = mci->pos_text;
818 struct TextPosInfo *pos_input = mci->pos_input;
819 char *text = (mci->text ? *mci->text : NULL);
820 char *input = (mci->input ? *mci->input : NULL);
821 int button_graphic = mci->button_graphic;
823 int font_text = (pos_text ? pos_text->font : -1);
824 int font_input = (pos_input ? pos_input->font : -1);
826 int font_text = mci->font_text;
827 int font_input = mci->font_input;
830 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
831 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
832 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
833 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
834 int text_chars = (text != NULL ? strlen(text) : 0);
835 int input_chars = (input != NULL ? strlen(input) : 0);
838 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
840 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
841 int text_width = font_text_width * text_chars;
842 int text_height = font_text_height;
843 int input_width = font_input_width * input_chars;
844 int input_height = font_input_height;
846 if (nr == MAIN_CONTROL_NAME)
849 if (menu.main.input.name.x == -1)
850 menu.main.input.name.x = menu.main.text.name.x + text_width;
851 if (menu.main.input.name.y == -1)
852 menu.main.input.name.y = menu.main.text.name.y;
856 menu.main.input.name.width = input_width;
857 menu.main.input.name.height = input_height;
859 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
860 menu.main.input.name.height = font_input_height;
864 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
866 if (pos_button->width == 0)
867 pos_button->width = button_width;
868 if (pos_button->height == 0)
869 pos_button->height = button_height;
872 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
875 /* calculate size for non-clickable text -- needed for text alignment */
876 boolean calculate_text_size = (pos_button == NULL && text != NULL);
878 /* calculate width for non-clickable text -- needed for text alignment */
879 boolean calculate_text_width = (pos_button == NULL && text != NULL);
882 if (visibleMenuPos(pos_button))
884 if (pos_text->x == -1)
885 pos_text->x = pos_button->x + pos_button->width;
886 if (pos_text->y == -1)
887 pos_text->y = pos_button->y;
891 if (pos_text->width == -1 || calculate_text_size)
892 pos_text->width = text_width;
893 if (pos_text->height == -1 || calculate_text_size)
894 pos_text->height = text_height;
896 if (pos_text->width == -1 || calculate_text_width)
897 pos_text->width = text_width;
898 if (pos_text->height == -1)
899 pos_text->height = text_height;
903 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
905 if (visibleTextPos(pos_text))
907 if (pos_input->x == -1)
908 pos_input->x = pos_text->x + pos_text->width;
909 if (pos_input->y == -1)
910 pos_input->y = pos_text->y;
913 if (pos_input->width == -1)
914 pos_input->width = input_width;
915 if (pos_input->height == -1)
916 pos_input->height = input_height;
921 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
922 boolean active_input)
926 for (i = 0; main_controls[i].nr != -1; i++)
928 struct MainControlInfo *mci = &main_controls[i];
930 if (mci->nr == nr || nr == -1)
932 struct MenuPosInfo *pos_button = mci->pos_button;
933 struct TextPosInfo *pos_text = mci->pos_text;
934 struct TextPosInfo *pos_input = mci->pos_input;
935 char *text = (mci->text ? *mci->text : NULL);
936 char *input = (mci->input ? *mci->input : NULL);
937 int button_graphic = mci->button_graphic;
939 int font_text = (pos_text ? pos_text->font : -1);
940 int font_input = (pos_input ? pos_input->font : -1);
942 int font_text = mci->font_text;
943 int font_input = mci->font_input;
948 button_graphic = BUTTON_ACTIVE(button_graphic);
949 font_text = FONT_ACTIVE(font_text);
954 font_input = FONT_ACTIVE(font_input);
957 if (visibleMenuPos(pos_button))
959 struct MenuPosInfo *pos = pos_button;
960 int x = mSX + pos->x;
961 int y = mSY + pos->y;
963 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
964 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
967 if (visibleTextPos(pos_text) && text != NULL)
969 struct TextPosInfo *pos = pos_text;
970 int x = mSX + ALIGNED_TEXT_XPOS(pos);
971 int y = mSY + ALIGNED_TEXT_YPOS(pos);
974 /* (check why/if this is needed) */
975 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
977 DrawText(x, y, text, font_text);
980 if (visibleTextPos(pos_input) && input != NULL)
982 struct TextPosInfo *pos = pos_input;
983 int x = mSX + ALIGNED_TEXT_XPOS(pos);
984 int y = mSY + ALIGNED_TEXT_YPOS(pos);
987 /* (check why/if this is needed) */
988 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
990 DrawText(x, y, input, font_input);
996 static void DrawCursorAndText_Main(int nr, boolean active_text)
998 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1002 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1004 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1008 static struct MainControlInfo *getMainControlInfo(int nr)
1012 for (i = 0; main_controls[i].nr != -1; i++)
1013 if (main_controls[i].nr == nr)
1014 return &main_controls[i];
1019 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1024 int rect_x = ALIGNED_TEXT_XPOS(rect);
1025 int rect_y = ALIGNED_TEXT_YPOS(rect);
1027 return (x >= rect_x && x < rect_x + rect->width &&
1028 y >= rect_y && y < rect_y + rect->height);
1031 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1036 int rect_x = ALIGNED_TEXT_XPOS(rect);
1037 int rect_y = ALIGNED_TEXT_YPOS(rect);
1040 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1041 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1042 (x >= rect_x && x < rect_x + rect->width &&
1043 y >= rect_y && y < rect_y + rect->height));
1046 return (x >= rect_x && x < rect_x + rect->width &&
1047 y >= rect_y && y < rect_y + rect->height);
1050 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1053 static int cursor_array[MAX_LEV_FIELDY];
1055 static int cursor_array[SCR_FIELDY];
1057 int x = mSX + TILEX * xpos;
1058 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1063 cursor_array[ypos] = graphic;
1065 graphic = cursor_array[ypos];
1069 graphic = BUTTON_ACTIVE(graphic);
1071 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1072 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1075 static void initCursor(int ypos, int graphic)
1077 drawCursorExt(0, ypos, FALSE, graphic);
1080 static void drawCursor(int ypos, boolean active)
1082 drawCursorExt(0, ypos, active, -1);
1085 static void drawCursorXY(int xpos, int ypos, int graphic)
1087 drawCursorExt(xpos, ypos, FALSE, graphic);
1090 static void drawChooseTreeCursor(int ypos, boolean active)
1092 int last_game_status = game_status; /* save current game status */
1095 /* force LEVELS draw offset on artwork setup screen */
1096 game_status = GAME_MODE_LEVELS;
1099 drawCursorExt(0, ypos, active, -1);
1101 game_status = last_game_status; /* restore current game status */
1106 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1107 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1111 static int getPrevlevelButtonPos()
1116 static int getCurrentLevelTextPos()
1118 return (getPrevlevelButtonPos() + 1);
1121 static int getNextLevelButtonPos()
1123 return getPrevlevelButtonPos() + 3 + 1;
1126 static int getLevelRangeTextPos()
1128 return getNextLevelButtonPos() + 1;
1132 int effectiveGameStatus()
1134 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1135 return GAME_MODE_TITLE;
1140 void DrawTitleScreenImage(int nr, boolean initial)
1142 int graphic = getTitleScreenGraphic(nr, initial);
1143 Bitmap *bitmap = graphic_info[graphic].bitmap;
1144 int width = graphic_info[graphic].width;
1145 int height = graphic_info[graphic].height;
1146 int src_x = graphic_info[graphic].src_x;
1147 int src_y = graphic_info[graphic].src_y;
1153 if (width > WIN_XSIZE)
1155 /* image width too large for window => center image horizontally */
1156 src_x = (width - WIN_XSIZE) / 2;
1160 if (height > WIN_YSIZE)
1162 /* image height too large for window => center image vertically */
1163 src_y = (height - WIN_YSIZE) / 2;
1167 /* always display title screens centered */
1168 dst_x = (WIN_XSIZE - width) / 2;
1169 dst_y = (WIN_YSIZE - height) / 2;
1171 SetDrawBackgroundMask(REDRAW_ALL);
1172 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1174 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1176 if (DrawingOnBackground(dst_x, dst_y))
1178 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1179 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1182 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1184 redraw_mask = REDRAW_ALL;
1187 void DrawTitleScreenMessage(int nr, boolean initial)
1189 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1190 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1191 int last_game_status = game_status; /* save current game status */
1193 if (filename == NULL)
1196 /* force TITLE font on title message screen */
1197 game_status = getTitleMessageGameMode(initial);
1199 /* if chars set to "-1", automatically determine by text and font width */
1200 if (tmi->chars == -1)
1201 tmi->chars = tmi->width / getFontWidth(tmi->font);
1203 tmi->width = tmi->chars * getFontWidth(tmi->font);
1205 /* if lines set to "-1", automatically determine by text and font height */
1206 if (tmi->lines == -1)
1207 tmi->lines = tmi->height / getFontHeight(tmi->font);
1209 tmi->height = tmi->lines * getFontHeight(tmi->font);
1211 SetDrawBackgroundMask(REDRAW_ALL);
1212 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1214 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1216 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1217 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1218 tmi->autowrap, tmi->centered, tmi->parse_comments);
1220 game_status = last_game_status; /* restore current game status */
1223 void DrawTitleScreen()
1225 KeyboardAutoRepeatOff();
1228 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1231 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1236 boolean CheckTitleScreen(boolean levelset_has_changed)
1238 static boolean show_title_initial = TRUE;
1239 boolean show_titlescreen = FALSE;
1241 /* needed to be able to skip title screen, if no image or message defined */
1242 InitializeTitleControls(show_title_initial);
1244 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1245 show_titlescreen = TRUE;
1247 /* show initial title images and messages only once at program start */
1248 show_title_initial = FALSE;
1250 return (show_titlescreen && num_title_screens > 0);
1253 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1255 static LevelDirTree *leveldir_last_valid = NULL;
1256 boolean levelset_has_changed = FALSE;
1258 FadeSetLeaveScreen();
1260 /* do not fade out here -- function may continue and fade on editor screen */
1263 FadeSoundsAndMusic();
1265 KeyboardAutoRepeatOn();
1268 SetDrawDeactivationMask(REDRAW_NONE);
1269 SetDrawBackgroundMask(REDRAW_FIELD);
1271 audio.sound_deactivated = FALSE;
1275 /* needed if last screen was the playing screen, invoked from level editor */
1276 if (level_editor_test_game)
1278 game_status = GAME_MODE_EDITOR;
1284 /* needed if last screen was the setup screen and fullscreen state changed */
1285 ToggleFullscreenIfNeeded();
1287 /* leveldir_current may be invalid (level group, parent link) */
1288 if (!validLevelSeries(leveldir_current))
1289 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1291 if (leveldir_current != leveldir_last_valid)
1292 levelset_has_changed = TRUE;
1294 /* store valid level series information */
1295 leveldir_last_valid = leveldir_current;
1297 init_last = init; /* switch to new busy animation */
1299 /* needed if last screen (level choice) changed graphics, sounds or music */
1300 ReloadCustomArtwork(0);
1302 if (redraw_mask & REDRAW_ALL)
1303 fade_mask = REDRAW_ALL;
1308 /* needed if last screen was the editor screen */
1309 UndrawSpecialEditorDoor();
1311 if (fade_mask == REDRAW_FIELD)
1317 /* needed if different viewport properties defined for menues */
1318 ChangeViewportPropertiesIfNeeded();
1321 #if defined(TARGET_SDL)
1322 SetDrawtoField(DRAW_BACKBUFFER);
1325 if (CheckTitleScreen(levelset_has_changed))
1327 game_status = GAME_MODE_TITLE;
1334 /* level_nr may have been set to value over handicap with level editor */
1335 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1336 level_nr = leveldir_current->handicap_level;
1338 LoadLevel(level_nr);
1339 LoadScore(level_nr);
1341 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1344 if (fade_mask == REDRAW_ALL)
1346 // int door_state = GetDoorState();
1350 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1356 InitializeMainControls();
1358 DrawCursorAndText_Main(-1, FALSE);
1359 DrawPreviewLevel(TRUE);
1361 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1364 if (TAPE_IS_EMPTY(tape))
1366 DrawCompleteVideoDisplay();
1371 /* create gadgets for main menu screen */
1372 FreeScreenGadgets();
1373 CreateScreenGadgets();
1375 /* map gadgets for main menu screen */
1377 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1380 if (fade_mask == REDRAW_ALL)
1382 int door_state = GetDoorState();
1384 // RedrawBackground();
1386 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1390 DrawMaskedBorder(REDRAW_ALL);
1396 /* update screen area with special editor door */
1397 redraw_mask |= REDRAW_ALL;
1401 SetMouseCursor(CURSOR_DEFAULT);
1405 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1408 void DrawAndFadeInMainMenu(int fade_mask)
1410 DrawMainMenuExt(fade_mask, TRUE);
1415 DrawMainMenuExt(REDRAW_ALL, FALSE);
1418 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1419 static void gotoTopLevelDir()
1421 /* move upwards to top level directory */
1422 while (leveldir_current->node_parent)
1424 /* write a "path" into level tree for easy navigation to last level */
1425 if (leveldir_current->node_parent->node_group->cl_first == -1)
1427 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1428 int leveldir_pos = posTreeInfo(leveldir_current);
1429 int num_page_entries;
1430 int cl_first, cl_cursor;
1432 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1433 num_page_entries = num_leveldirs;
1435 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1437 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1438 cl_cursor = leveldir_pos - cl_first;
1440 leveldir_current->node_parent->node_group->cl_first = cl_first;
1441 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1444 leveldir_current = leveldir_current->node_parent;
1449 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1451 static unsigned long title_delay = 0;
1452 static int title_screen_nr = 0;
1453 static int last_sound = -1, last_music = -1;
1454 boolean return_to_main_menu = FALSE;
1455 boolean use_fading_main_menu = TRUE;
1456 struct TitleControlInfo *tci;
1457 struct TitleFadingInfo fading_default;
1458 struct TitleFadingInfo fading_last = fading;
1459 struct TitleFadingInfo fading_next;
1462 if (button == MB_MENU_INITIALIZE)
1465 title_screen_nr = 0;
1466 tci = &title_controls[title_screen_nr];
1468 last_sound = SND_UNDEFINED;
1469 last_music = MUS_UNDEFINED;
1471 if (game_status == GAME_MODE_INFO)
1473 if (num_title_screens == 0)
1475 DrawInfoScreen_NotAvailable("Title screen information:",
1476 "No title screen for this level set.");
1481 FadeSoundsAndMusic();
1484 FadeOut(REDRAW_ALL);
1489 DrawTitleScreenImage(tci->local_nr, tci->initial);
1491 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1493 fading_default = (tci->initial ? title_initial_default : title_default);
1495 fading = fading_next = getTitleFading(tci);
1499 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1500 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1502 fading.fade_mode = FADE_MODE_FADE;
1503 fading.fade_delay = fading_default.fade_delay;
1506 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1507 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1508 fading.fade_mode = FADE_MODE_FADE;
1513 sound = getTitleSound(tci);
1514 music = getTitleMusic(tci);
1516 if (sound != last_sound)
1517 PlayMenuSoundExt(sound);
1518 if (music != last_music)
1519 PlayMenuMusicExt(music);
1525 SetMouseCursor(CURSOR_NONE);
1531 fading = fading_next;
1533 DelayReached(&title_delay, 0); /* reset delay counter */
1539 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1540 button = MB_MENU_CHOICE;
1542 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1543 button = MB_MENU_CHOICE;
1546 if (button == MB_MENU_LEAVE)
1548 return_to_main_menu = TRUE;
1549 use_fading_main_menu = FALSE;
1551 else if (button == MB_MENU_CHOICE)
1553 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1556 FadeOut(REDRAW_FIELD);
1559 FadeSetEnterScreen();
1561 info_mode = INFO_MODE_MAIN;
1562 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1568 tci = &title_controls[title_screen_nr];
1570 if (title_screen_nr < num_title_screens)
1572 sound = getTitleSound(tci);
1573 music = getTitleMusic(tci);
1575 if (sound == SND_UNDEFINED || sound != last_sound)
1577 if (music == MUS_UNDEFINED || music != last_music)
1581 FadeOut(REDRAW_ALL);
1585 DrawTitleScreenImage(tci->local_nr, tci->initial);
1587 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1589 fading_next = getTitleFading(tci);
1592 sound = getTitleSound(tci);
1593 music = getTitleMusic(tci);
1595 if (sound != last_sound)
1596 PlayMenuSoundExt(sound);
1597 if (music != last_music)
1598 PlayMenuMusicExt(music);
1605 /* last screen already faded out, next screen has no animation */
1606 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1607 fading_next.fade_mode == FADE_MODE_NONE)
1608 fading = fading_next;
1610 /* last screen already faded out, next screen has no animation */
1611 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1612 fading_next.fade_mode == FADE_MODE_NONE)
1613 fading = fading_next;
1620 fading = fading_next;
1622 DelayReached(&title_delay, 0); /* reset delay counter */
1626 FadeSoundsAndMusic();
1628 return_to_main_menu = TRUE;
1632 if (return_to_main_menu)
1638 SetMouseCursor(CURSOR_DEFAULT);
1640 if (game_status == GAME_MODE_INFO)
1643 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1646 info_mode = INFO_MODE_MAIN;
1647 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1649 else /* default: return to main menu */
1652 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1655 game_status = GAME_MODE_MAIN;
1656 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1661 void HandleMainMenu_SelectLevel(int step, int direction)
1663 int old_level_nr = level_nr;
1666 new_level_nr = old_level_nr + step * direction;
1667 if (new_level_nr < leveldir_current->first_level)
1668 new_level_nr = leveldir_current->first_level;
1669 if (new_level_nr > leveldir_current->last_level)
1670 new_level_nr = leveldir_current->last_level;
1672 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1674 /* skipping levels is only allowed when trying to skip single level */
1675 if (setup.skip_levels && step == 1 &&
1676 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1678 leveldir_current->handicap_level++;
1679 SaveLevelSetup_SeriesInfo();
1682 new_level_nr = leveldir_current->handicap_level;
1685 if (new_level_nr != old_level_nr)
1687 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1689 PlaySound(SND_MENU_ITEM_SELECTING);
1691 level_nr = new_level_nr;
1693 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1694 int2str(level_nr, menu.main.text.level_number.size),
1695 mci->pos_text->font);
1697 LoadLevel(level_nr);
1698 DrawPreviewLevel(TRUE);
1702 DrawCompleteVideoDisplay();
1704 /* needed because DrawPreviewLevel() takes some time */
1710 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1712 static int choice = MAIN_CONTROL_GAME;
1716 if (button == MB_MENU_INITIALIZE)
1718 DrawCursorAndText_Main(choice, TRUE);
1723 if (mx || my) /* mouse input */
1727 for (i = 0; main_controls[i].nr != -1; i++)
1730 printf("::: check click (%d, %d) for %d [%d] ...\n",
1731 mx - mSX, my - mSY, i, main_controls[i].nr);
1734 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1735 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1736 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1739 printf("::: inside %d\n", i);
1742 pos = main_controls[i].nr;
1748 else if (dx || dy) /* keyboard input */
1750 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1751 choice == MAIN_CONTROL_SETUP))
1752 button = MB_MENU_CHOICE;
1757 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1759 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1761 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1763 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1765 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1767 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1769 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1771 game_status = GAME_MODE_LEVELNR;
1773 DrawChooseLevelNr();
1775 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1781 PlaySound(SND_MENU_ITEM_ACTIVATING);
1783 DrawCursorAndText_Main(choice, FALSE);
1784 DrawCursorAndText_Main(pos, TRUE);
1791 PlaySound(SND_MENU_ITEM_SELECTING);
1793 if (pos == MAIN_CONTROL_NAME)
1795 game_status = GAME_MODE_PSEUDO_TYPENAME;
1797 HandleTypeName(strlen(setup.player_name), 0);
1799 else if (pos == MAIN_CONTROL_LEVELS)
1803 game_status = GAME_MODE_LEVELS;
1805 SaveLevelSetup_LastSeries();
1806 SaveLevelSetup_SeriesInfo();
1808 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1812 DrawChooseLevelSet();
1815 else if (pos == MAIN_CONTROL_SCORES)
1817 game_status = GAME_MODE_SCORES;
1821 else if (pos == MAIN_CONTROL_EDITOR)
1823 if (leveldir_current->readonly &&
1824 !strEqual(setup.player_name, "Artsoft"))
1825 Request("This level is read only !", REQ_CONFIRM);
1827 game_status = GAME_MODE_EDITOR;
1829 FadeSetEnterScreen();
1832 /* needed if different viewport properties defined for editor */
1833 ChangeViewportPropertiesIfNeeded();
1838 else if (pos == MAIN_CONTROL_INFO)
1840 game_status = GAME_MODE_INFO;
1841 info_mode = INFO_MODE_MAIN;
1845 else if (pos == MAIN_CONTROL_GAME)
1847 StartGameActions(options.network, setup.autorecord, level.random_seed);
1849 else if (pos == MAIN_CONTROL_SETUP)
1851 game_status = GAME_MODE_SETUP;
1852 setup_mode = SETUP_MODE_MAIN;
1856 else if (pos == MAIN_CONTROL_QUIT)
1858 SaveLevelSetup_LastSeries();
1859 SaveLevelSetup_SeriesInfo();
1861 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1862 game_status = GAME_MODE_QUIT;
1867 if (game_status == GAME_MODE_MAIN)
1869 DrawPreviewLevel(FALSE);
1875 /* ========================================================================= */
1876 /* info screen functions */
1877 /* ========================================================================= */
1879 static struct TokenInfo *info_info;
1880 static int num_info_info;
1882 static void execInfoTitleScreen()
1884 info_mode = INFO_MODE_TITLE;
1889 static void execInfoElements()
1891 info_mode = INFO_MODE_ELEMENTS;
1896 static void execInfoMusic()
1898 info_mode = INFO_MODE_MUSIC;
1903 static void execInfoCredits()
1905 info_mode = INFO_MODE_CREDITS;
1910 static void execInfoProgram()
1912 info_mode = INFO_MODE_PROGRAM;
1917 static void execInfoVersion()
1919 info_mode = INFO_MODE_VERSION;
1924 static void execInfoLevelSet()
1926 info_mode = INFO_MODE_LEVELSET;
1931 static void execExitInfo()
1933 game_status = GAME_MODE_MAIN;
1935 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1938 static struct TokenInfo info_info_main[] =
1940 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1941 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1942 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1943 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1944 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1945 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1946 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1947 { TYPE_EMPTY, NULL, "" },
1948 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1953 static void DrawCursorAndText_Info(int pos, boolean active)
1955 int xpos = MENU_SCREEN_START_XPOS;
1956 int ypos = MENU_SCREEN_START_YPOS + pos;
1957 int font_nr = FONT_MENU_1;
1960 font_nr = FONT_ACTIVE(font_nr);
1962 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1964 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1965 drawCursor(pos, active);
1968 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1973 CloseDoor(DOOR_CLOSE_2);
1975 /* (needed after displaying title screens which disable auto repeat) */
1976 KeyboardAutoRepeatOn();
1978 FadeSetLeaveScreen();
1985 if (fade_mask == REDRAW_ALL)
1989 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1995 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1997 info_info = info_info_main;
2001 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2003 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2006 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2007 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2008 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2009 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2010 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2011 initCursor(i, IMG_MENU_BUTTON);
2013 DrawCursorAndText_Info(i, FALSE);
2018 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2023 DrawMaskedBorder(fade_mask);
2030 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2032 static int choice_store[MAX_INFO_MODES];
2033 int choice = choice_store[info_mode]; /* always starts with 0 */
2037 if (button == MB_MENU_INITIALIZE)
2039 /* advance to first valid menu entry */
2040 while (choice < num_info_info &&
2041 info_info[choice].type & TYPE_SKIP_ENTRY)
2043 choice_store[info_mode] = choice;
2045 DrawCursorAndText_Info(choice, TRUE);
2049 else if (button == MB_MENU_LEAVE)
2051 for (y = 0; y < num_info_info; y++)
2053 if (info_info[y].type & TYPE_LEAVE_MENU)
2055 void (*menu_callback_function)(void) = info_info[y].value;
2059 menu_callback_function();
2061 break; /* absolutely needed because function changes 'info_info'! */
2068 if (mx || my) /* mouse input */
2070 x = (mx - mSX) / 32;
2071 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2073 else if (dx || dy) /* keyboard input */
2077 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2079 if (info_info[choice].type & menu_navigation_type ||
2080 info_info[choice].type & TYPE_ENTER_SCREEN ||
2081 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2082 info_info[choice].type & TYPE_YES_NO_AUTO)
2083 button = MB_MENU_CHOICE;
2088 /* jump to next non-empty menu entry (up or down) */
2089 while (y > 0 && y < num_info_info - 1 &&
2090 info_info[y].type & TYPE_SKIP_ENTRY)
2094 if (IN_VIS_FIELD(x, y) &&
2095 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2101 PlaySound(SND_MENU_ITEM_ACTIVATING);
2103 DrawCursorAndText_Info(choice, FALSE);
2104 DrawCursorAndText_Info(y, TRUE);
2106 choice = choice_store[info_mode] = y;
2109 else if (!(info_info[y].type & TYPE_GHOSTED))
2111 PlaySound(SND_MENU_ITEM_SELECTING);
2113 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2115 void (*menu_callback_function)(void) = info_info[choice].value;
2117 FadeSetFromType(info_info[y].type);
2119 menu_callback_function();
2125 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2127 int ystart1 = mSY - SY + 100;
2128 int ystart2 = mSY - SY + 150;
2129 int ybottom = mSY - SY + SYSIZE - 20;
2131 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2133 FadeOut(REDRAW_FIELD);
2138 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2139 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2141 DrawTextSCentered(ybottom, FONT_TEXT_4,
2142 "Press any key or button for info menu");
2144 FadeIn(REDRAW_FIELD);
2147 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2149 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2150 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2151 int xstart = mSX + 16;
2152 int ystart1 = mSY - SY + 100;
2153 int ystart2 = mSY + 64 + 2 * 32;
2154 int ybottom = mSY - SY + SYSIZE - 20;
2155 int ystep = TILEY + 4;
2156 int element, action, direction;
2164 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2165 infoscreen_step[i] = infoscreen_frame[i] = 0;
2170 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2172 DrawTextSCentered(ybottom, FONT_TEXT_4,
2173 "Press any key or button for next page");
2179 while (helpanim_info[j].element != HELPANIM_LIST_END)
2181 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2186 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2195 j += infoscreen_step[i - start];
2197 element = helpanim_info[j].element;
2198 action = helpanim_info[j].action;
2199 direction = helpanim_info[j].direction;
2202 element = EL_UNKNOWN;
2204 if (action != -1 && direction != -1)
2205 graphic = el_act_dir2img(element, action, direction);
2206 else if (action != -1)
2207 graphic = el_act2img(element, action);
2208 else if (direction != -1)
2209 graphic = el_dir2img(element, direction);
2211 graphic = el2img(element);
2213 delay = helpanim_info[j++].delay;
2218 if (infoscreen_frame[i - start] == 0)
2221 infoscreen_frame[i - start] = delay - 1;
2225 sync_frame = delay - infoscreen_frame[i - start];
2226 infoscreen_frame[i - start]--;
2229 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2231 if (!infoscreen_frame[i - start])
2232 infoscreen_step[i - start] = 0;
2236 if (!infoscreen_frame[i - start])
2237 infoscreen_step[i - start]++;
2238 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2244 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2246 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2247 graphic, sync_frame, USE_MASKING);
2250 DrawInfoScreen_HelpText(element, action, direction, i - start);
2255 redraw_mask |= REDRAW_FIELD;
2260 static char *getHelpText(int element, int action, int direction)
2262 char token[MAX_LINE_LEN];
2264 strcpy(token, element_info[element].token_name);
2267 strcat(token, element_action_info[action].suffix);
2269 if (direction != -1)
2270 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2272 return getHashEntry(helptext_info, token);
2275 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2277 int font_nr = FONT_INFO_ELEMENTS;
2278 int font_width = getFontWidth(font_nr);
2279 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2280 int sy = mSY + 65 + 2 * 32 + 1;
2281 int ystep = TILEY + 4;
2282 int pad_x = sx - SX;
2283 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2284 int max_lines_per_text = 2;
2287 if (action != -1 && direction != -1) /* element.action.direction */
2288 text = getHelpText(element, action, direction);
2290 if (text == NULL && action != -1) /* element.action */
2291 text = getHelpText(element, action, -1);
2293 if (text == NULL && direction != -1) /* element.direction */
2294 text = getHelpText(element, -1, direction);
2296 if (text == NULL) /* base element */
2297 text = getHelpText(element, -1, -1);
2299 if (text == NULL) /* not found */
2300 text = "No description available";
2302 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2303 sy += getFontHeight(font_nr) / 2;
2305 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2306 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2307 TRUE, FALSE, FALSE);
2310 void DrawInfoScreen_TitleScreen()
2315 void HandleInfoScreen_TitleScreen(int button)
2317 HandleTitleScreen(0, 0, 0, 0, button);
2320 void DrawInfoScreen_Elements()
2322 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2324 FadeOut(REDRAW_FIELD);
2329 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2331 FadeIn(REDRAW_FIELD);
2336 void HandleInfoScreen_Elements(int button)
2338 static unsigned long info_delay = 0;
2339 static int num_anims;
2340 static int num_pages;
2342 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2345 if (button == MB_MENU_INITIALIZE)
2347 boolean new_element = TRUE;
2351 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2353 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2355 else if (new_element)
2358 new_element = FALSE;
2362 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2366 if (button == MB_MENU_LEAVE)
2368 PlaySound(SND_MENU_ITEM_SELECTING);
2370 info_mode = INFO_MODE_MAIN;
2375 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2377 if (button != MB_MENU_INITIALIZE)
2379 PlaySound(SND_MENU_ITEM_SELECTING);
2384 if (page >= num_pages)
2386 FadeSoundsAndMusic();
2388 info_mode = INFO_MODE_MAIN;
2389 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2396 FadeSetNextScreen();
2399 if (button != MB_MENU_INITIALIZE)
2400 FadeOut(REDRAW_FIELD);
2402 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2404 if (button != MB_MENU_INITIALIZE)
2405 FadeIn(REDRAW_FIELD);
2409 if (DelayReached(&info_delay, GameFrameDelay))
2410 if (page < num_pages)
2411 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2413 PlayMenuSoundIfLoop();
2417 void DrawInfoScreen_Music()
2419 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2422 FadeOut(REDRAW_FIELD);
2430 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2433 FadeIn(REDRAW_FIELD);
2437 void HandleInfoScreen_Music(int button)
2439 static struct MusicFileInfo *list = NULL;
2440 int ystart1 = mSY - SY + 100;
2441 int ystart2 = mSY - SY + 150;
2442 int ybottom = mSY - SY + SYSIZE - 20;
2445 if (button == MB_MENU_INITIALIZE)
2447 list = music_file_info;
2451 FadeSoundsAndMusic();
2456 DrawTextSCentered(ystart1, FONT_TEXT_1,
2457 "No music info for this level set.");
2459 DrawTextSCentered(ybottom, FONT_TEXT_4,
2460 "Press any key or button for info menu");
2466 if (button == MB_MENU_LEAVE)
2468 PlaySound(SND_MENU_ITEM_SELECTING);
2470 FadeSoundsAndMusic();
2472 info_mode = INFO_MODE_MAIN;
2477 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2481 if (button != MB_MENU_INITIALIZE)
2483 PlaySound(SND_MENU_ITEM_SELECTING);
2491 FadeSoundsAndMusic();
2493 info_mode = INFO_MODE_MAIN;
2494 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2499 FadeSoundsAndMusic();
2502 if (list != music_file_info)
2503 FadeSetNextScreen();
2506 if (button != MB_MENU_INITIALIZE)
2507 FadeOut(REDRAW_FIELD);
2514 int sound = list->music;
2516 if (sound_info[sound].loop)
2517 PlaySoundLoop(sound);
2521 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2525 PlayMusic(list->music);
2527 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2530 if (!strEqual(list->title, UNKNOWN_NAME))
2532 if (!strEqual(list->title_header, UNKNOWN_NAME))
2533 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2535 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2538 if (!strEqual(list->artist, UNKNOWN_NAME))
2540 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2541 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2543 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2545 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2548 if (!strEqual(list->album, UNKNOWN_NAME))
2550 if (!strEqual(list->album_header, UNKNOWN_NAME))
2551 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2553 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2555 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2558 if (!strEqual(list->year, UNKNOWN_NAME))
2560 if (!strEqual(list->year_header, UNKNOWN_NAME))
2561 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2563 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2565 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2568 DrawTextSCentered(ybottom, FONT_TEXT_4,
2569 "Press any key or button for next page");
2571 if (button != MB_MENU_INITIALIZE)
2572 FadeIn(REDRAW_FIELD);
2575 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2576 PlaySoundLoop(list->music);
2579 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2581 int ystart1 = mSY - SY + 100;
2582 int ystart2 = mSY - SY + 150;
2583 int ybottom = mSY - SY + SYSIZE - 20;
2589 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2593 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2594 "Special thanks to");
2595 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2597 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2599 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2600 "\"Boulder Dash\"");
2601 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2603 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2605 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2607 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2608 "First Star Software");
2610 else if (screen_nr == 1)
2612 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2613 "Special thanks to");
2614 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2615 "Klaus Heinz & Volker Wertich");
2616 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2618 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2619 "\"Emerald Mine\"");
2620 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2622 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2624 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2626 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2629 else if (screen_nr == 2)
2631 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2632 "Special thanks to");
2633 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2634 "Michael Stopp & Philip Jespersen");
2635 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2637 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2639 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2641 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2643 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2645 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2646 "Digital Integration");
2648 else if (screen_nr == 3)
2650 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2651 "Special thanks to");
2652 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2653 "Hiroyuki Imabayashi");
2654 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2656 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2658 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2660 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2662 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2664 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2667 else if (screen_nr == 4)
2669 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2670 "Special thanks to");
2671 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2673 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2675 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2676 "Jürgen Bonhagen");
2677 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2678 "for the continuous creation");
2679 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2680 "of outstanding level sets");
2682 else if (screen_nr == 5)
2684 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2686 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2688 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2689 "for ideas and inspiration by");
2690 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2693 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2695 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2697 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2698 "for ideas and inspiration by");
2699 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2702 else if (screen_nr == 6)
2704 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2706 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2709 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2710 "for the code base used for the");
2711 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2712 "native Emerald Mine engine");
2714 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2715 "for the new Emerald Mine engine");
2718 else if (screen_nr == 7)
2720 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2722 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2724 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2725 "for the initial DOS port");
2727 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2729 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2731 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2732 "for some additional toons");
2734 else if (screen_nr == 8)
2736 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2737 "And not to forget:");
2738 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2740 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2741 "All those who contributed");
2742 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2743 "levels to this game");
2744 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2748 DrawTextSCentered(ybottom, FONT_TEXT_4,
2749 "Press any key or button for next page");
2752 void DrawInfoScreen_Credits()
2754 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2756 FadeSoundsAndMusic();
2759 FadeOut(REDRAW_FIELD);
2762 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2765 FadeIn(REDRAW_FIELD);
2769 void HandleInfoScreen_Credits(int button)
2771 static int screen_nr = 0;
2772 int num_screens = 9;
2774 if (button == MB_MENU_INITIALIZE)
2778 // DrawInfoScreen_CreditsScreen(screen_nr);
2781 if (button == MB_MENU_LEAVE)
2783 PlaySound(SND_MENU_ITEM_SELECTING);
2785 info_mode = INFO_MODE_MAIN;
2790 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2792 if (button != MB_MENU_INITIALIZE)
2794 PlaySound(SND_MENU_ITEM_SELECTING);
2799 if (screen_nr >= num_screens)
2801 FadeSoundsAndMusic();
2803 info_mode = INFO_MODE_MAIN;
2804 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2811 FadeSetNextScreen();
2814 if (button != MB_MENU_INITIALIZE)
2815 FadeOut(REDRAW_FIELD);
2817 DrawInfoScreen_CreditsScreen(screen_nr);
2819 if (button != MB_MENU_INITIALIZE)
2820 FadeIn(REDRAW_FIELD);
2824 PlayMenuSoundIfLoop();
2828 void DrawInfoScreen_Program()
2830 int ystart1 = mSY - SY + 100;
2831 int ystart2 = mSY - SY + 150;
2832 int ybottom = mSY - SY + SYSIZE - 20;
2835 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2838 FadeOut(REDRAW_FIELD);
2844 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2846 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2847 "This game is Freeware!");
2848 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2849 "If you like it, send e-mail to:");
2850 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2851 PROGRAM_EMAIL_STRING);
2852 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2853 "or SnailMail to:");
2854 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2856 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2857 "Detmolder Strasse 189");
2858 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2860 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2862 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2863 "More information and levels:");
2864 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2865 PROGRAM_WEBSITE_STRING);
2866 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2867 "If you have created new levels,");
2868 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2869 "send them to me to include them!");
2870 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2873 DrawTextSCentered(ybottom, FONT_TEXT_4,
2874 "Press any key or button for info menu");
2877 FadeIn(REDRAW_FIELD);
2881 void HandleInfoScreen_Program(int button)
2883 if (button == MB_MENU_LEAVE)
2885 PlaySound(SND_MENU_ITEM_SELECTING);
2887 info_mode = INFO_MODE_MAIN;
2892 else if (button == MB_MENU_CHOICE)
2894 PlaySound(SND_MENU_ITEM_SELECTING);
2896 FadeSoundsAndMusic();
2899 FadeOut(REDRAW_FIELD);
2902 info_mode = INFO_MODE_MAIN;
2903 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2907 PlayMenuSoundIfLoop();
2911 void DrawInfoScreen_Version()
2913 int font_header = FONT_TEXT_3;
2914 int font_text = FONT_TEXT_2;
2915 int xstep = getFontWidth(font_text);
2916 int ystep = getFontHeight(font_text);
2917 int ystart1 = mSY - SY + 100;
2918 int ystart2 = mSY - SY + 150;
2919 int ybottom = mSY - SY + SYSIZE - 20;
2920 int xstart1 = mSX + 2 * xstep;
2921 int xstart2 = mSX + 19 * xstep;
2922 #if defined(TARGET_SDL)
2923 int xstart3 = mSX + 29 * xstep;
2924 SDL_version sdl_version_compiled;
2925 const SDL_version *sdl_version_linked;
2926 int driver_name_len = 8;
2927 char driver_name[driver_name_len];
2930 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2933 FadeOut(REDRAW_FIELD);
2939 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2941 DrawTextF(xstart1, ystart2, font_header, "Name");
2942 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2945 DrawTextF(xstart1, ystart2, font_header, "Version");
2946 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2949 DrawTextF(xstart1, ystart2, font_header, "Platform");
2950 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2953 DrawTextF(xstart1, ystart2, font_header, "Target");
2954 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2957 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2958 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2960 #if defined(TARGET_SDL)
2961 ystart2 += 3 * ystep;
2962 DrawTextF(xstart1, ystart2, font_header, "Library");
2963 DrawTextF(xstart2, ystart2, font_header, "compiled");
2964 DrawTextF(xstart3, ystart2, font_header, "linked");
2966 SDL_VERSION(&sdl_version_compiled);
2967 sdl_version_linked = SDL_Linked_Version();
2969 ystart2 += 2 * ystep;
2970 DrawTextF(xstart1, ystart2, font_text, "SDL");
2971 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2972 sdl_version_compiled.major,
2973 sdl_version_compiled.minor,
2974 sdl_version_compiled.patch);
2975 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2976 sdl_version_linked->major,
2977 sdl_version_linked->minor,
2978 sdl_version_linked->patch);
2980 SDL_IMAGE_VERSION(&sdl_version_compiled);
2981 sdl_version_linked = IMG_Linked_Version();
2984 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2985 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2986 sdl_version_compiled.major,
2987 sdl_version_compiled.minor,
2988 sdl_version_compiled.patch);
2989 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2990 sdl_version_linked->major,
2991 sdl_version_linked->minor,
2992 sdl_version_linked->patch);
2994 SDL_MIXER_VERSION(&sdl_version_compiled);
2995 sdl_version_linked = Mix_Linked_Version();
2998 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2999 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3000 sdl_version_compiled.major,
3001 sdl_version_compiled.minor,
3002 sdl_version_compiled.patch);
3003 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3004 sdl_version_linked->major,
3005 sdl_version_linked->minor,
3006 sdl_version_linked->patch);
3008 SDL_NET_VERSION(&sdl_version_compiled);
3009 sdl_version_linked = SDLNet_Linked_Version();
3012 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3013 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3014 sdl_version_compiled.major,
3015 sdl_version_compiled.minor,
3016 sdl_version_compiled.patch);
3017 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3018 sdl_version_linked->major,
3019 sdl_version_linked->minor,
3020 sdl_version_linked->patch);
3022 ystart2 += 3 * ystep;
3023 DrawTextF(xstart1, ystart2, font_header, "Driver");
3024 DrawTextF(xstart2, ystart2, font_header, "Requested");
3025 DrawTextF(xstart3, ystart2, font_header, "Used");
3027 SDL_VideoDriverName(driver_name, driver_name_len);
3029 ystart2 += 2 * ystep;
3030 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3031 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3032 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3034 SDL_AudioDriverName(driver_name, driver_name_len);
3037 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3038 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3039 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3042 DrawTextSCentered(ybottom, FONT_TEXT_4,
3043 "Press any key or button for info menu");
3046 FadeIn(REDRAW_FIELD);
3050 void HandleInfoScreen_Version(int button)
3052 if (button == MB_MENU_LEAVE)
3054 PlaySound(SND_MENU_ITEM_SELECTING);
3056 info_mode = INFO_MODE_MAIN;
3061 else if (button == MB_MENU_CHOICE)
3063 PlaySound(SND_MENU_ITEM_SELECTING);
3065 FadeSoundsAndMusic();
3068 FadeOut(REDRAW_FIELD);
3071 info_mode = INFO_MODE_MAIN;
3072 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3076 PlayMenuSoundIfLoop();
3080 void DrawInfoScreen_LevelSet()
3082 struct TitleMessageInfo *tmi = &readme;
3083 char *filename = getLevelSetInfoFilename();
3085 /* if chars set to "-1", automatically determine by text and font width */
3086 if (tmi->chars == -1)
3087 tmi->chars = tmi->width / getFontWidth(tmi->font);
3089 tmi->width = tmi->chars * getFontWidth(tmi->font);
3091 /* if lines set to "-1", automatically determine by text and font height */
3092 if (tmi->lines == -1)
3093 tmi->lines = tmi->height / getFontHeight(tmi->font);
3095 tmi->height = tmi->lines * getFontHeight(tmi->font);
3097 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3100 FadeOut(REDRAW_FIELD);
3106 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3108 if (filename != NULL)
3109 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3110 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3111 tmi->autowrap, tmi->centered, tmi->parse_comments);
3113 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3114 "No information for this level set.");
3116 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3117 "Press any key or button for info menu");
3120 FadeIn(REDRAW_FIELD);
3124 void HandleInfoScreen_LevelSet(int button)
3126 if (button == MB_MENU_LEAVE)
3128 PlaySound(SND_MENU_ITEM_SELECTING);
3130 info_mode = INFO_MODE_MAIN;
3135 else if (button == MB_MENU_CHOICE)
3137 PlaySound(SND_MENU_ITEM_SELECTING);
3139 FadeSoundsAndMusic();
3142 FadeOut(REDRAW_FIELD);
3145 info_mode = INFO_MODE_MAIN;
3146 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3150 PlayMenuSoundIfLoop();
3154 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3156 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3158 if (info_mode == INFO_MODE_TITLE)
3159 DrawInfoScreen_TitleScreen();
3160 else if (info_mode == INFO_MODE_ELEMENTS)
3161 DrawInfoScreen_Elements();
3162 else if (info_mode == INFO_MODE_MUSIC)
3163 DrawInfoScreen_Music();
3164 else if (info_mode == INFO_MODE_CREDITS)
3165 DrawInfoScreen_Credits();
3166 else if (info_mode == INFO_MODE_PROGRAM)
3167 DrawInfoScreen_Program();
3168 else if (info_mode == INFO_MODE_VERSION)
3169 DrawInfoScreen_Version();
3170 else if (info_mode == INFO_MODE_LEVELSET)
3171 DrawInfoScreen_LevelSet();
3173 DrawInfoScreen_Main(fade_mask, do_fading);
3175 if (info_mode != INFO_MODE_MAIN &&
3176 info_mode != INFO_MODE_TITLE &&
3177 info_mode != INFO_MODE_MUSIC)
3184 void DrawAndFadeInInfoScreen(int fade_mask)
3186 DrawInfoScreenExt(fade_mask, TRUE);
3189 void DrawInfoScreen()
3191 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3194 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3196 if (info_mode == INFO_MODE_TITLE)
3197 HandleInfoScreen_TitleScreen(button);
3198 else if (info_mode == INFO_MODE_ELEMENTS)
3199 HandleInfoScreen_Elements(button);
3200 else if (info_mode == INFO_MODE_MUSIC)
3201 HandleInfoScreen_Music(button);
3202 else if (info_mode == INFO_MODE_CREDITS)
3203 HandleInfoScreen_Credits(button);
3204 else if (info_mode == INFO_MODE_PROGRAM)
3205 HandleInfoScreen_Program(button);
3206 else if (info_mode == INFO_MODE_VERSION)
3207 HandleInfoScreen_Version(button);
3208 else if (info_mode == INFO_MODE_LEVELSET)
3209 HandleInfoScreen_LevelSet(button);
3211 HandleInfoScreen_Main(mx, my, dx, dy, button);
3217 /* ========================================================================= */
3218 /* type name functions */
3219 /* ========================================================================= */
3221 void HandleTypeName(int newxpos, Key key)
3223 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3224 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3225 struct TextPosInfo *pos = mci->pos_input;
3226 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3227 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3228 static int xpos = 0;
3229 int font_nr = pos->font;
3230 int font_active_nr = FONT_ACTIVE(font_nr);
3231 int font_width = getFontWidth(font_active_nr);
3232 char key_char = getValidConfigValueChar(getCharFromKey(key));
3233 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3234 boolean is_active = TRUE;
3236 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3240 strcpy(last_player_name, setup.player_name);
3244 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3246 setup.player_name[xpos] = key_char;
3247 setup.player_name[xpos + 1] = 0;
3251 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3255 setup.player_name[xpos] = 0;
3257 else if (key == KSYM_Return && xpos > 0)
3263 game_status = GAME_MODE_MAIN;
3265 else if (key == KSYM_Escape)
3267 strcpy(setup.player_name, last_player_name);
3271 game_status = GAME_MODE_MAIN;
3276 pos->width = (strlen(setup.player_name) + 1) * font_width;
3277 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3279 DrawText(startx, starty, setup.player_name, font_active_nr);
3280 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3284 pos->width = strlen(setup.player_name) * font_width;
3285 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3287 DrawText(startx, starty, setup.player_name, font_nr);
3292 /* ========================================================================= */
3293 /* tree menu functions */
3294 /* ========================================================================= */
3296 static void DrawChooseTree(TreeInfo **ti_ptr)
3300 FreeScreenGadgets();
3301 CreateScreenGadgets();
3303 CloseDoor(DOOR_CLOSE_2);
3306 FadeOut(REDRAW_FIELD);
3311 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3312 MapScreenTreeGadgets(*ti_ptr);
3315 FadeIn(REDRAW_FIELD);
3321 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3323 struct GadgetInfo *gi = screen_gadget[id];
3324 int items_max, items_visible, item_position;
3326 items_max = numTreeInfoInGroup(ti);
3327 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3328 item_position = first_entry;
3330 if (item_position > items_max - items_visible)
3331 item_position = items_max - items_visible;
3333 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3334 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3335 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3338 static void drawChooseTreeList(int first_entry, int num_page_entries,
3342 char *title_string = NULL;
3343 int yoffset_sets = MENU_TITLE1_YPOS;
3344 int yoffset_setup = 16;
3345 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3346 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3347 int last_game_status = game_status; /* save current game status */
3349 title_string = ti->infotext;
3351 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3354 /* force LEVELS font on artwork setup screen */
3355 game_status = GAME_MODE_LEVELS;
3359 /* clear tree list area, but not title or scrollbar */
3360 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3361 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3362 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3364 /* clear tree list area, but not title or scrollbar */
3365 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3366 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3367 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3370 for (i = 0; i < num_page_entries; i++)
3372 TreeInfo *node, *node_first;
3373 int entry_pos = first_entry + i;
3374 int xpos = MENU_SCREEN_START_XPOS;
3375 int ypos = MENU_SCREEN_START_YPOS + i;
3376 int startx = mSX + xpos * 32;
3377 int starty = mSY + ypos * 32;
3378 int font_nr = FONT_TEXT_1;
3379 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3380 int startx_text = startx + font_xoffset;
3381 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3382 int text_size = startx_scrollbar - startx_text;
3383 int max_buffer_len = text_size / getFontWidth(font_nr);
3384 char buffer[max_buffer_len + 1];
3386 node_first = getTreeInfoFirstGroupEntry(ti);
3387 node = getTreeInfoFromPos(node_first, entry_pos);
3389 strncpy(buffer, node->name, max_buffer_len);
3390 buffer[max_buffer_len] = '\0';
3392 DrawText(startx, starty, buffer, font_nr + node->color);
3394 if (node->parent_link)
3395 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3396 else if (node->level_group)
3397 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3399 initCursor(i, IMG_MENU_BUTTON);
3402 game_status = last_game_status; /* restore current game status */
3404 redraw_mask |= REDRAW_FIELD;
3407 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3409 TreeInfo *node, *node_first;
3410 int x, last_redraw_mask = redraw_mask;
3411 int ypos = MENU_TITLE2_YPOS;
3412 int font_nr = FONT_TITLE_2;
3414 if (ti->type == TREE_TYPE_LEVEL_NR)
3415 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3417 if (ti->type != TREE_TYPE_LEVEL_DIR)
3420 node_first = getTreeInfoFirstGroupEntry(ti);
3421 node = getTreeInfoFromPos(node_first, entry_pos);
3423 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3426 if (node->parent_link)
3427 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3428 node->node_parent->name);
3429 else if (node->level_group)
3430 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3432 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3433 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3434 node->levels, (node->levels > 1 ? "levels" : "level"),
3437 if (node->parent_link)
3438 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3440 else if (node->level_group)
3441 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3443 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3444 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3445 node->levels, node->class_desc);
3448 /* let BackToFront() redraw only what is needed */
3449 redraw_mask = last_redraw_mask | REDRAW_TILES;
3450 for (x = 0; x < SCR_FIELDX; x++)
3451 MarkTileDirty(x, 1);
3454 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3457 TreeInfo *ti = *ti_ptr;
3459 int y = ti->cl_cursor;
3460 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3461 int num_entries = numTreeInfoInGroup(ti);
3462 int num_page_entries;
3463 int last_game_status = game_status; /* save current game status */
3464 boolean position_set_by_scrollbar = (dx == 999);
3467 /* force LEVELS draw offset on choose level and artwork setup screen */
3468 game_status = GAME_MODE_LEVELS;
3471 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3472 num_page_entries = num_entries;
3474 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3476 game_status = last_game_status; /* restore current game status */
3478 if (button == MB_MENU_INITIALIZE)
3480 int num_entries = numTreeInfoInGroup(ti);
3481 int entry_pos = posTreeInfo(ti);
3483 if (ti->cl_first == -1)
3485 /* only on initialization */
3486 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3487 ti->cl_cursor = entry_pos - ti->cl_first;
3489 else if (ti->cl_cursor >= num_page_entries ||
3490 (num_entries > num_page_entries &&
3491 num_entries - ti->cl_first < num_page_entries))
3493 /* only after change of list size (by custom graphic configuration) */
3494 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3495 ti->cl_cursor = entry_pos - ti->cl_first;
3498 if (position_set_by_scrollbar)
3501 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3504 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3505 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3506 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3510 else if (button == MB_MENU_LEAVE)
3514 PlaySound(SND_MENU_ITEM_SELECTING);
3516 if (ti->node_parent)
3518 *ti_ptr = ti->node_parent;
3519 DrawChooseTree(ti_ptr);
3521 else if (game_status == GAME_MODE_SETUP)
3523 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3525 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3526 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3527 execSetupGraphics();
3533 if (game_status == GAME_MODE_LEVELNR)
3534 level_nr = atoi(level_number_current->identifier);
3536 game_status = GAME_MODE_MAIN;
3538 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3544 if (mx || my) /* mouse input */
3546 int last_game_status = game_status; /* save current game status */
3549 /* force LEVELS draw offset on artwork setup screen */
3550 game_status = GAME_MODE_LEVELS;
3553 x = (mx - mSX) / 32;
3554 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3556 game_status = last_game_status; /* restore current game status */
3558 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3560 /* move cursor instead of scrolling when already at start/end of list */
3561 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3563 else if (dy == +1 * SCROLL_LINE &&
3564 ti->cl_first + num_page_entries == num_entries)
3567 /* handle scrolling screen one line or page */
3568 if (ti->cl_cursor + dy < 0 ||
3569 ti->cl_cursor + dy > num_page_entries - 1)
3571 if (ABS(dy) == SCROLL_PAGE)
3572 step = num_page_entries - 1;
3574 if (dy < 0 && ti->cl_first > 0)
3576 /* scroll page/line up */
3578 ti->cl_first -= step;
3579 if (ti->cl_first < 0)
3582 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3583 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3584 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3586 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3589 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3591 /* scroll page/line down */
3593 ti->cl_first += step;
3594 if (ti->cl_first + num_page_entries > num_entries)
3595 ti->cl_first = MAX(0, num_entries - num_page_entries);
3597 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3598 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3599 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3601 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3608 /* handle moving cursor one line */
3609 y = ti->cl_cursor + dy;
3614 TreeInfo *node_first, *node_cursor;
3615 int entry_pos = ti->cl_first + y;
3617 node_first = getTreeInfoFirstGroupEntry(ti);
3618 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3620 if (node_cursor->node_group)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 node_cursor->cl_first = ti->cl_first;
3627 node_cursor->cl_cursor = ti->cl_cursor;
3628 *ti_ptr = node_cursor->node_group;
3629 DrawChooseTree(ti_ptr);
3634 else if (dx == -1 && ti->node_parent)
3638 PlaySound(SND_MENU_ITEM_SELECTING);
3640 *ti_ptr = ti->node_parent;
3641 DrawChooseTree(ti_ptr);
3646 if (!anyScrollbarGadgetActive() &&
3647 IN_VIS_FIELD(x, y) &&
3648 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3649 y >= 0 && y < num_page_entries)
3653 if (y != ti->cl_cursor)
3655 PlaySound(SND_MENU_ITEM_ACTIVATING);
3657 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3658 drawChooseTreeCursor(y, TRUE);
3659 drawChooseTreeInfo(ti->cl_first + y, ti);
3666 TreeInfo *node_first, *node_cursor;
3667 int entry_pos = ti->cl_first + y;
3669 PlaySound(SND_MENU_ITEM_SELECTING);
3671 node_first = getTreeInfoFirstGroupEntry(ti);
3672 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3674 if (node_cursor->node_group)
3678 node_cursor->cl_first = ti->cl_first;
3679 node_cursor->cl_cursor = ti->cl_cursor;
3680 *ti_ptr = node_cursor->node_group;
3681 DrawChooseTree(ti_ptr);
3683 else if (node_cursor->parent_link)
3687 *ti_ptr = node_cursor->node_parent;
3688 DrawChooseTree(ti_ptr);
3692 FadeSetEnterScreen();
3694 node_cursor->cl_first = ti->cl_first;
3695 node_cursor->cl_cursor = ti->cl_cursor;
3696 *ti_ptr = node_cursor;
3698 if (ti->type == TREE_TYPE_LEVEL_DIR)
3700 LoadLevelSetup_SeriesInfo();
3702 SaveLevelSetup_LastSeries();
3703 SaveLevelSetup_SeriesInfo();
3707 if (game_status == GAME_MODE_SETUP)
3709 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3711 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3712 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3713 execSetupGraphics();
3719 if (game_status == GAME_MODE_LEVELNR)
3720 level_nr = atoi(level_number_current->identifier);
3722 game_status = GAME_MODE_MAIN;
3731 void DrawChooseLevelSet()
3733 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3735 DrawChooseTree(&leveldir_current);
3741 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3743 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3748 void DrawChooseLevelNr()
3752 if (level_number != NULL)
3754 freeTreeInfo(level_number);
3756 level_number = NULL;
3759 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3761 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3762 char identifier[32], name[32];
3765 /* temporarily load level info to get level name */
3766 LoadLevelInfoOnly(i);
3768 ti->node_top = &level_number;
3769 ti->sort_priority = 10000 + value;
3771 sprintf(identifier, "%d", value);
3772 sprintf(name, "%03d: %s", value, level.name);
3774 setString(&ti->identifier, identifier);
3775 setString(&ti->name, name);
3776 setString(&ti->name_sorting, name);
3778 pushTreeInfo(&level_number, ti);
3781 /* sort level number values to start with lowest level number */
3782 sortTreeInfo(&level_number);
3784 /* set current level number to current level number */
3785 level_number_current =
3786 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3788 /* if that also fails, set current level number to first available level */
3789 if (level_number_current == NULL)
3790 level_number_current = level_number;
3792 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3795 DrawChooseTree(&level_number_current);
3797 DrawChooseTree(&leveldir_current);
3804 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3807 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3809 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3815 void DrawHallOfFame(int highlight_position)
3818 FadeSoundsAndMusic();
3820 /* (this is needed when called from GameEnd() after winning a game) */
3821 KeyboardAutoRepeatOn();
3824 /* (this is needed when called from GameEnd() after winning a game) */
3825 SetDrawDeactivationMask(REDRAW_NONE);
3826 SetDrawBackgroundMask(REDRAW_FIELD);
3828 CloseDoor(DOOR_CLOSE_2);
3830 if (highlight_position < 0)
3831 LoadScore(level_nr);
3833 FadeSetEnterScreen();
3835 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3838 FadeOut(REDRAW_FIELD);
3846 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3849 FadeIn(REDRAW_FIELD);
3853 static void drawHallOfFameList(int first_entry, int highlight_position)
3857 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3860 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3861 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3862 "HighScores of Level %d", level_nr);
3864 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3866 int entry = first_entry + i;
3867 boolean active = (entry == highlight_position);
3868 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3869 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3870 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3871 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3872 int dx1 = 3 * getFontWidth(font_nr1);
3873 int dx2 = dx1 + getFontWidth(font_nr1);
3874 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3875 int sy = mSY + 64 + i * 32;
3877 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3878 DrawText(mSX + dx1, sy, ".", font_nr1);
3879 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3881 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3882 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3884 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3887 redraw_mask |= REDRAW_FIELD;
3890 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3892 static int first_entry = 0;
3893 static int highlight_position = 0;
3894 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3896 if (button == MB_MENU_INITIALIZE)
3899 highlight_position = mx;
3900 drawHallOfFameList(first_entry, highlight_position);
3905 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3906 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3910 if (first_entry > 0)
3912 first_entry -= step;
3913 if (first_entry < 0)
3916 drawHallOfFameList(first_entry, highlight_position);
3921 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3923 first_entry += step;
3924 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3925 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3927 drawHallOfFameList(first_entry, highlight_position);
3930 else if (button == MB_MENU_LEAVE)
3932 PlaySound(SND_MENU_ITEM_SELECTING);
3934 FadeSound(SND_BACKGROUND_SCORES);
3936 game_status = GAME_MODE_MAIN;
3940 else if (button == MB_MENU_CHOICE)
3942 PlaySound(SND_MENU_ITEM_SELECTING);
3944 FadeSound(SND_BACKGROUND_SCORES);
3947 FadeOut(REDRAW_FIELD);
3950 game_status = GAME_MODE_MAIN;
3952 DrawAndFadeInMainMenu(REDRAW_FIELD);
3955 if (game_status == GAME_MODE_SCORES)
3956 PlayMenuSoundIfLoop();
3962 /* ========================================================================= */
3963 /* setup screen functions */
3964 /* ========================================================================= */
3966 static struct TokenInfo *setup_info;
3967 static int num_setup_info;
3969 static char *screen_mode_text;
3970 static char *scroll_delay_text;
3971 static char *game_speed_text;
3972 static char *graphics_set_name;
3973 static char *sounds_set_name;
3974 static char *music_set_name;
3976 static void execSetupMain()
3978 setup_mode = SETUP_MODE_MAIN;
3983 static void execSetupGame()
3985 if (game_speeds == NULL)
3989 for (i = 0; game_speeds_list[i].value != -1; i++)
3991 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3992 char identifier[32], name[32];
3993 int value = game_speeds_list[i].value;
3994 char *text = game_speeds_list[i].text;
3996 ti->node_top = &game_speeds;
3997 ti->sort_priority = 10000 - value;
3999 sprintf(identifier, "%d", value);
4000 sprintf(name, "%s", text);
4002 setString(&ti->identifier, identifier);
4003 setString(&ti->name, name);
4004 setString(&ti->name_sorting, name);
4005 setString(&ti->infotext, "Game Speed");
4007 pushTreeInfo(&game_speeds, ti);
4010 /* sort game speed values to start with slowest game speed */
4011 sortTreeInfo(&game_speeds);
4013 /* set current game speed to configured game speed value */
4014 game_speed_current =
4015 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4017 /* if that fails, set current game speed to reliable default value */
4018 if (game_speed_current == NULL)
4019 game_speed_current =
4020 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4022 /* if that also fails, set current game speed to first available speed */
4023 if (game_speed_current == NULL)
4024 game_speed_current = game_speeds;
4027 setup.game_frame_delay = atoi(game_speed_current->identifier);
4029 /* needed for displaying game speed text instead of identifier */
4030 game_speed_text = game_speed_current->name;
4032 setup_mode = SETUP_MODE_GAME;
4037 static void execSetupChooseGameSpeed()
4039 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4044 static void execSetupEditor()
4046 setup_mode = SETUP_MODE_EDITOR;
4051 static void execSetupGraphics()
4053 if (video.fullscreen_available && screen_modes == NULL)
4057 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4059 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4060 char identifier[32], name[32];
4061 int x = video.fullscreen_modes[i].width;
4062 int y = video.fullscreen_modes[i].height;
4065 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4067 ti->node_top = &screen_modes;
4068 ti->sort_priority = x * 10000 + y;
4070 sprintf(identifier, "%dx%d", x, y);
4071 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4073 setString(&ti->identifier, identifier);
4074 setString(&ti->name, name);
4075 setString(&ti->name_sorting, name);
4076 setString(&ti->infotext, "Fullscreen Mode");
4078 pushTreeInfo(&screen_modes, ti);
4081 /* sort fullscreen modes to start with lowest available screen resolution */
4082 sortTreeInfo(&screen_modes);
4084 /* set current screen mode for fullscreen mode to configured setup value */
4085 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4086 setup.fullscreen_mode);
4088 /* if that fails, set current screen mode to reliable default value */
4089 if (screen_mode_current == NULL)
4090 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4091 DEFAULT_FULLSCREEN_MODE);
4093 /* if that also fails, set current screen mode to first available mode */
4094 if (screen_mode_current == NULL)
4095 screen_mode_current = screen_modes;
4097 if (screen_mode_current == NULL)
4098 video.fullscreen_available = FALSE;
4101 if (video.fullscreen_available)
4103 setup.fullscreen_mode = screen_mode_current->identifier;
4105 /* needed for displaying screen mode name instead of identifier */
4106 screen_mode_text = screen_mode_current->name;
4110 if (scroll_delays == NULL)
4114 for (i = 0; scroll_delays_list[i].value != -1; i++)
4116 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4117 char identifier[32], name[32];
4118 int value = scroll_delays_list[i].value;
4119 char *text = scroll_delays_list[i].text;
4121 ti->node_top = &scroll_delays;
4122 ti->sort_priority = value;
4124 sprintf(identifier, "%d", value);
4125 sprintf(name, "%s", text);
4127 setString(&ti->identifier, identifier);
4128 setString(&ti->name, name);
4129 setString(&ti->name_sorting, name);
4130 setString(&ti->infotext, "Scroll Delay");
4132 pushTreeInfo(&scroll_delays, ti);
4135 /* sort scroll delay values to start with lowest scroll delay value */
4136 sortTreeInfo(&scroll_delays);
4138 /* set current scroll delay value to configured scroll delay value */
4139 scroll_delay_current =
4140 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4142 /* if that fails, set current scroll delay to reliable default value */
4143 if (scroll_delay_current == NULL)
4144 scroll_delay_current =
4145 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4147 /* if that also fails, set current scroll delay to first available value */
4148 if (scroll_delay_current == NULL)
4149 scroll_delay_current = scroll_delays;
4152 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4154 /* needed for displaying scroll delay text instead of identifier */
4155 scroll_delay_text = scroll_delay_current->name;
4158 setup_mode = SETUP_MODE_GRAPHICS;
4162 static void execSetupChooseScreenMode()
4164 if (!video.fullscreen_available)
4167 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4172 static void execSetupChooseScrollDelay()
4174 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4179 static void execSetupSound()
4181 setup_mode = SETUP_MODE_SOUND;
4186 static void execSetupArtwork()
4189 printf("::: '%s', '%s', '%s'\n",
4190 artwork.gfx_current->subdir,
4191 artwork.gfx_current->fullpath,
4192 artwork.gfx_current->basepath);
4195 setup.graphics_set = artwork.gfx_current->identifier;
4196 setup.sounds_set = artwork.snd_current->identifier;
4197 setup.music_set = artwork.mus_current->identifier;
4199 /* needed if last screen (setup choice) changed graphics, sounds or music */
4200 ReloadCustomArtwork(0);
4202 /* needed for displaying artwork name instead of artwork identifier */
4203 graphics_set_name = artwork.gfx_current->name;
4204 sounds_set_name = artwork.snd_current->name;
4205 music_set_name = artwork.mus_current->name;
4207 setup_mode = SETUP_MODE_ARTWORK;
4212 static void execSetupChooseGraphics()
4214 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4219 static void execSetupChooseSounds()
4221 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4226 static void execSetupChooseMusic()
4228 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4233 static void execSetupInput()
4235 setup_mode = SETUP_MODE_INPUT;
4240 static void execSetupShortcuts()
4242 setup_mode = SETUP_MODE_SHORTCUTS;
4247 static void execSetupShortcuts1()
4249 setup_mode = SETUP_MODE_SHORTCUTS_1;
4254 static void execSetupShortcuts2()
4256 setup_mode = SETUP_MODE_SHORTCUTS_2;
4261 static void execSetupShortcuts3()
4263 setup_mode = SETUP_MODE_SHORTCUTS_3;
4268 static void execSetupShortcuts4()
4270 setup_mode = SETUP_MODE_SHORTCUTS_4;
4275 static void execSetupShortcuts5()
4277 setup_mode = SETUP_MODE_SHORTCUTS_5;
4282 static void execExitSetup()
4284 game_status = GAME_MODE_MAIN;
4286 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4289 static void execSaveAndExitSetup()
4295 static struct TokenInfo setup_info_main[] =
4297 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4298 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4299 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4300 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4301 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4302 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4303 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4304 { TYPE_EMPTY, NULL, "" },
4305 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4306 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4311 static struct TokenInfo setup_info_game[] =
4313 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4314 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4315 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4316 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4317 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4318 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4319 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4320 { TYPE_STRING, &game_speed_text, "" },
4321 { TYPE_EMPTY, NULL, "" },
4322 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4327 static struct TokenInfo setup_info_editor[] =
4330 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4331 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4332 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4333 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4334 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4335 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4336 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4337 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4339 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4340 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4341 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4343 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4345 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4346 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4347 { TYPE_EMPTY, NULL, "" },
4349 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4350 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4351 { TYPE_EMPTY, NULL, "" },
4353 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4354 { TYPE_EMPTY, NULL, "" },
4355 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4360 static struct TokenInfo setup_info_graphics[] =
4362 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4363 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4364 { TYPE_STRING, &screen_mode_text, "" },
4366 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4368 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4369 { TYPE_STRING, &scroll_delay_text, "" },
4371 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4373 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4374 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4375 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4376 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4377 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4378 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4379 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4380 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4381 { TYPE_EMPTY, NULL, "" },
4382 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4387 static struct TokenInfo setup_info_sound[] =
4389 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4390 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4391 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4392 { TYPE_EMPTY, NULL, "" },
4393 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4398 static struct TokenInfo setup_info_artwork[] =
4400 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4401 { TYPE_STRING, &graphics_set_name, "" },
4402 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4403 { TYPE_STRING, &sounds_set_name, "" },
4404 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4405 { TYPE_STRING, &music_set_name, "" },
4406 { TYPE_EMPTY, NULL, "" },
4409 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4410 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4411 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4413 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4414 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4415 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4416 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4419 { TYPE_STRING, NULL, "Override Level Artwork:"},
4420 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4421 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4422 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4424 { TYPE_EMPTY, NULL, "" },
4425 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4430 static struct TokenInfo setup_info_input[] =
4432 { TYPE_SWITCH, NULL, "Player:" },
4433 { TYPE_SWITCH, NULL, "Device:" },
4434 { TYPE_ENTER_MENU, NULL, "" },
4435 { TYPE_EMPTY, NULL, "" },
4436 { TYPE_EMPTY, NULL, "" },
4437 { TYPE_EMPTY, NULL, "" },
4438 { TYPE_EMPTY, NULL, "" },
4439 { TYPE_EMPTY, NULL, "" },
4440 { TYPE_EMPTY, NULL, "" },
4441 { TYPE_EMPTY, NULL, "" },
4442 { TYPE_EMPTY, NULL, "" },
4443 { TYPE_EMPTY, NULL, "" },
4444 { TYPE_EMPTY, NULL, "" },
4445 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4450 static struct TokenInfo setup_info_shortcuts[] =
4452 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4453 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4454 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4455 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4456 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4457 { TYPE_EMPTY, NULL, "" },
4458 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4463 static struct TokenInfo setup_info_shortcuts_1[] =
4465 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4466 { TYPE_KEY, &setup.shortcut.save_game, "" },
4467 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4468 { TYPE_KEY, &setup.shortcut.load_game, "" },
4469 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4470 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4471 { TYPE_EMPTY, NULL, "" },
4472 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4473 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4474 { TYPE_EMPTY, NULL, "" },
4475 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4480 static struct TokenInfo setup_info_shortcuts_2[] =
4482 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4483 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4484 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4485 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4486 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4487 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4488 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4489 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4490 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4491 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4492 { TYPE_EMPTY, NULL, "" },
4493 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4498 static struct TokenInfo setup_info_shortcuts_3[] =
4500 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
4501 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4502 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
4503 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
4504 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
4505 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4506 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
4507 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4508 { TYPE_KEYTEXT, NULL, "Record Tape:", },
4509 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4510 { TYPE_KEYTEXT, NULL, "Play Tape:", },
4511 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4512 { TYPE_EMPTY, NULL, "" },
4513 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4518 static struct TokenInfo setup_info_shortcuts_4[] =
4520 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
4521 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4522 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
4523 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4524 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
4525 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4526 { TYPE_EMPTY, NULL, "" },
4527 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4532 static struct TokenInfo setup_info_shortcuts_5[] =
4534 { TYPE_KEYTEXT, NULL, "Snap Left:", },
4535 { TYPE_KEY, &setup.shortcut.snap_left, "" },
4536 { TYPE_KEYTEXT, NULL, "Snap Right:", },
4537 { TYPE_KEY, &setup.shortcut.snap_right, "" },
4538 { TYPE_KEYTEXT, NULL, "Snap Up:", },
4539 { TYPE_KEY, &setup.shortcut.snap_up, "" },
4540 { TYPE_KEYTEXT, NULL, "Snap Down:", },
4541 { TYPE_KEY, &setup.shortcut.snap_down, "" },
4542 { TYPE_EMPTY, NULL, "" },
4543 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4548 static Key getSetupKey()
4550 Key key = KSYM_UNDEFINED;
4551 boolean got_key_event = FALSE;
4553 while (!got_key_event)
4555 if (PendingEvent()) /* got event */
4563 case EVENT_KEYPRESS:
4565 key = GetEventKey((KeyEvent *)&event, TRUE);
4567 /* press 'Escape' or 'Enter' to keep the existing key binding */
4568 if (key == KSYM_Escape || key == KSYM_Return)
4569 key = KSYM_UNDEFINED; /* keep old value */
4571 got_key_event = TRUE;
4575 case EVENT_KEYRELEASE:
4576 key_joystick_mapping = 0;
4580 HandleOtherEvents(&event);
4588 /* don't eat all CPU time */
4595 static int getSetupTextFont(int type)
4597 if (type & (TYPE_SWITCH |
4609 static int getSetupValueFont(int type, void *value)
4611 if (type & TYPE_KEY)
4612 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4613 else if (type & TYPE_STRING)
4614 return FONT_VALUE_2;
4615 else if (type & TYPE_ECS_AGA)
4616 return FONT_VALUE_1;
4617 else if (type & TYPE_BOOLEAN_STYLE)
4618 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4619 else if (type & TYPE_YES_NO_AUTO)
4620 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4621 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4623 return FONT_VALUE_1;
4626 static void drawSetupValue(int pos)
4628 boolean font_draw_xoffset_modified = FALSE;
4629 int font_draw_xoffset_old = -1;
4630 int xpos = MENU_SCREEN_VALUE_XPOS;
4631 int ypos = MENU_SCREEN_START_YPOS + pos;
4632 int startx = mSX + xpos * 32;
4633 int starty = mSY + ypos * 32;
4634 int font_nr, font_width, font_height;
4635 int type = setup_info[pos].type;
4636 void *value = setup_info[pos].value;
4637 char *value_string = getSetupValue(type, value);
4642 if (value_string == NULL)
4645 if (type & TYPE_KEY)
4647 xpos = MENU_SCREEN_START_XPOS;
4649 if (type & TYPE_QUERY)
4650 value_string = "<press key>";
4652 else if (type & TYPE_STRING)
4654 int max_value_len = (SCR_FIELDX - 2) * 2;
4656 xpos = MENU_SCREEN_START_XPOS;
4658 if (strlen(value_string) > max_value_len)
4659 value_string[max_value_len] = '\0';
4661 else if (type & TYPE_YES_NO_AUTO)
4663 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4666 startx = mSX + xpos * 32;
4667 starty = mSY + ypos * 32;
4668 font_nr = getSetupValueFont(type, value);
4669 font_width = getFontWidth(font_nr);
4670 font_height = getFontHeight(font_nr);
4672 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4673 if (setup_mode != SETUP_MODE_INPUT)
4675 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4676 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4677 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4678 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4679 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4680 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4681 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4682 boolean correct_font_draw_xoffset = FALSE;
4684 if (xpos == MENU_SCREEN_START_XPOS &&
4685 startx + font1_xoffset < text_startx + text_font_xoffset)
4686 correct_font_draw_xoffset = TRUE;
4688 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4689 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4690 correct_font_draw_xoffset = TRUE;
4692 /* check if setup value would overlap with setup text when printed */
4693 /* (this can happen for extreme/wrong values for font draw offset) */
4694 if (correct_font_draw_xoffset)
4696 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4697 font_draw_xoffset_modified = TRUE;
4699 if (type & TYPE_KEY)
4700 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4701 else if (!(type & TYPE_STRING))
4702 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4703 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4708 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4710 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4711 DrawText(startx + i * font_width, starty, " ", font_nr);
4714 DrawText(startx, starty, value_string, font_nr);
4716 if (font_draw_xoffset_modified)
4717 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4720 static void changeSetupValue(int pos, int dx)
4722 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4724 *(boolean *)setup_info[pos].value ^= TRUE;
4726 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4728 *(int *)setup_info[pos].value =
4730 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4731 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4732 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4733 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4735 else if (setup_info[pos].type & TYPE_KEY)
4739 setup_info[pos].type |= TYPE_QUERY;
4740 drawSetupValue(pos);
4741 setup_info[pos].type &= ~TYPE_QUERY;
4743 key = getSetupKey();
4744 if (key != KSYM_UNDEFINED)
4745 *(Key *)setup_info[pos].value = key;
4748 drawSetupValue(pos);
4751 static void DrawCursorAndText_Setup(int pos, boolean active)
4753 int xpos = MENU_SCREEN_START_XPOS;
4754 int ypos = MENU_SCREEN_START_YPOS + pos;
4755 int font_nr = getSetupTextFont(setup_info[pos].type);
4757 if (setup_info == setup_info_input)
4758 font_nr = FONT_MENU_1;
4761 font_nr = FONT_ACTIVE(font_nr);
4763 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4765 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4766 drawCursor(pos, active);
4769 static void DrawSetupScreen_Generic()
4771 boolean redraw_all = FALSE;
4772 char *title_string = NULL;
4776 CloseDoor(DOOR_CLOSE_2);
4778 if (redraw_mask & REDRAW_ALL)
4782 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4783 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4784 int2str(0, redraw_mask)));
4788 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4789 FadeOut(redraw_mask);
4791 FadeOut(REDRAW_FIELD);
4796 if (setup_mode == SETUP_MODE_MAIN)
4798 setup_info = setup_info_main;
4799 title_string = "Setup";
4801 else if (setup_mode == SETUP_MODE_GAME)
4803 setup_info = setup_info_game;
4804 title_string = "Setup Game";
4806 else if (setup_mode == SETUP_MODE_EDITOR)
4808 setup_info = setup_info_editor;
4809 title_string = "Setup Editor";
4811 else if (setup_mode == SETUP_MODE_GRAPHICS)
4813 setup_info = setup_info_graphics;
4814 title_string = "Setup Graphics";
4816 else if (setup_mode == SETUP_MODE_SOUND)
4818 setup_info = setup_info_sound;
4819 title_string = "Setup Sound";
4821 else if (setup_mode == SETUP_MODE_ARTWORK)
4823 setup_info = setup_info_artwork;
4824 title_string = "Custom Artwork";
4826 else if (setup_mode == SETUP_MODE_SHORTCUTS)
4828 setup_info = setup_info_shortcuts;
4829 title_string = "Setup Shortcuts";
4831 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4833 setup_info = setup_info_shortcuts_1;
4834 title_string = "Setup Shortcuts";
4836 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4838 setup_info = setup_info_shortcuts_2;
4839 title_string = "Setup Shortcuts";
4841 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
4843 setup_info = setup_info_shortcuts_3;
4844 title_string = "Setup Shortcuts";
4846 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
4848 setup_info = setup_info_shortcuts_4;
4849 title_string = "Setup Shortcuts";
4851 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
4853 setup_info = setup_info_shortcuts_5;
4854 title_string = "Setup Shortcuts";
4857 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4861 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4863 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4866 void *value_ptr = setup_info[i].value;
4868 /* set some entries to "unchangeable" according to other variables */
4869 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4870 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4871 (value_ptr == &setup.sound_music && !audio.music_available) ||
4872 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4873 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4874 setup_info[i].type |= TYPE_GHOSTED;
4876 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4877 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4878 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4879 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4880 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4881 initCursor(i, IMG_MENU_BUTTON);
4883 DrawCursorAndText_Setup(i, FALSE);
4885 if (setup_info[i].type & TYPE_VALUE)
4892 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4893 "Joysticks deactivated in setup menu");
4897 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4901 redraw_mask = REDRAW_ALL;
4904 FadeIn(redraw_mask);
4906 FadeIn(REDRAW_FIELD);
4911 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4915 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4917 static int choice_store[MAX_SETUP_MODES];
4918 int choice = choice_store[setup_mode]; /* always starts with 0 */
4922 if (button == MB_MENU_INITIALIZE)
4924 /* advance to first valid menu entry */
4925 while (choice < num_setup_info &&
4926 setup_info[choice].type & TYPE_SKIP_ENTRY)
4928 choice_store[setup_mode] = choice;
4930 DrawCursorAndText_Setup(choice, TRUE);
4934 else if (button == MB_MENU_LEAVE)
4936 PlaySound(SND_MENU_ITEM_SELECTING);
4938 for (y = 0; y < num_setup_info; y++)
4940 if (setup_info[y].type & TYPE_LEAVE_MENU)
4942 void (*menu_callback_function)(void) = setup_info[y].value;
4946 menu_callback_function();
4948 break; /* absolutely needed because function changes 'setup_info'! */
4955 if (mx || my) /* mouse input */
4957 x = (mx - mSX) / 32;
4958 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4960 else if (dx || dy) /* keyboard input */
4964 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4966 if (setup_info[choice].type & menu_navigation_type ||
4967 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4968 setup_info[choice].type & TYPE_YES_NO_AUTO)
4969 button = MB_MENU_CHOICE;
4974 /* jump to next non-empty menu entry (up or down) */
4975 while (y > 0 && y < num_setup_info - 1 &&
4976 setup_info[y].type & TYPE_SKIP_ENTRY)
4980 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4984 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4986 PlaySound(SND_MENU_ITEM_ACTIVATING);
4988 DrawCursorAndText_Setup(choice, FALSE);
4989 DrawCursorAndText_Setup(y, TRUE);
4991 choice = choice_store[setup_mode] = y;
4994 else if (!(setup_info[y].type & TYPE_GHOSTED))
4996 PlaySound(SND_MENU_ITEM_SELECTING);
4998 /* when selecting key headline, execute function for key value change */
4999 if (setup_info[y].type & TYPE_KEYTEXT &&
5000 setup_info[y + 1].type & TYPE_KEY)
5003 /* when selecting string value, execute function for list selection */
5004 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5005 setup_info[y - 1].type & TYPE_ENTER_LIST)
5008 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5010 void (*menu_callback_function)(void) = setup_info[y].value;
5012 FadeSetFromType(setup_info[y].type);
5014 menu_callback_function();
5018 if (setup_info[y].type & TYPE_VALUE)
5019 changeSetupValue(y, dx);
5025 void DrawSetupScreen_Input()
5030 FadeOut(REDRAW_FIELD);
5036 setup_info = setup_info_input;
5039 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5043 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5044 "Joysticks deactivated on this screen");
5046 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5047 "Joysticks deactivated on this screen");
5052 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5054 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5057 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5058 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5059 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5060 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5061 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5062 initCursor(i, IMG_MENU_BUTTON);
5064 DrawCursorAndText_Setup(i, FALSE);
5068 DeactivateJoystickForCalibration();
5073 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5074 "Joysticks deactivated on this screen");
5076 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5077 "Joysticks deactivated on this screen");
5081 /* create gadgets for setup input menu screen */
5082 FreeScreenGadgets();
5083 CreateScreenGadgets();
5085 /* map gadgets for setup input menu screen */
5086 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5088 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5091 FadeIn(REDRAW_FIELD);
5097 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5099 if (device_name == NULL)
5102 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5105 if (strlen(device_name) > 1)
5107 char c1 = device_name[strlen(device_name) - 1];
5108 char c2 = device_name[strlen(device_name) - 2];
5110 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5111 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5114 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5115 strlen(device_name));
5118 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5121 static struct SetupKeyboardInfo custom_key;
5128 { &custom_key.left, "Joystick Left" },
5129 { &custom_key.right, "Joystick Right" },
5130 { &custom_key.up, "Joystick Up" },
5131 { &custom_key.down, "Joystick Down" },
5132 { &custom_key.snap, "Button 1" },
5133 { &custom_key.drop, "Button 2" }
5135 static char *joystick_name[MAX_PLAYERS] =
5142 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5146 custom_key = setup.input[player_nr].key;
5148 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5149 FONT_INPUT_1_ACTIVE);
5151 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5153 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5154 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5156 if (setup.input[player_nr].use_joystick)
5158 char *device_name = setup.input[player_nr].joy.device_name;
5159 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5160 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5162 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5163 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5167 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5168 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5171 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5173 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5174 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5175 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5176 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5178 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5179 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5180 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5181 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5182 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5183 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5185 for (i = 0; i < 6; i++)
5187 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5189 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5191 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5192 (setup.input[player_nr].use_joystick ?
5194 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5198 static int input_player_nr = 0;
5200 void HandleSetupScreen_Input_Player(int step, int direction)
5202 int old_player_nr = input_player_nr;
5205 new_player_nr = old_player_nr + step * direction;
5206 if (new_player_nr < 0)
5208 if (new_player_nr > MAX_PLAYERS - 1)
5209 new_player_nr = MAX_PLAYERS - 1;
5211 if (new_player_nr != old_player_nr)
5213 input_player_nr = new_player_nr;
5215 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5219 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5221 static int choice = 0;
5224 int pos_start = SETUPINPUT_SCREEN_POS_START;
5225 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5226 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5227 int pos_end = SETUPINPUT_SCREEN_POS_END;
5229 if (button == MB_MENU_INITIALIZE)
5231 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5233 DrawCursorAndText_Setup(choice, TRUE);
5237 else if (button == MB_MENU_LEAVE)
5239 setup_mode = SETUP_MODE_MAIN;
5246 if (mx || my) /* mouse input */
5248 x = (mx - mSX) / 32;
5249 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5251 else if (dx || dy) /* keyboard input */
5253 if (dx && choice == 0)
5254 x = (dx < 0 ? 10 : 12);
5255 else if ((dx && choice == 1) ||
5256 (dx == +1 && choice == 2) ||
5257 (dx == -1 && choice == pos_end))
5258 button = MB_MENU_CHOICE;
5262 if (y >= pos_empty1 && y <= pos_empty2)
5263 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5266 if (y == 0 && dx != 0 && button)
5268 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5270 else if (IN_VIS_FIELD(x, y) &&
5271 y >= pos_start && y <= pos_end &&
5272 !(y >= pos_empty1 && y <= pos_empty2))
5278 DrawCursorAndText_Setup(choice, FALSE);
5279 DrawCursorAndText_Setup(y, TRUE);
5281 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5290 char *device_name = setup.input[input_player_nr].joy.device_name;
5292 if (!setup.input[input_player_nr].use_joystick)
5294 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5296 setJoystickDeviceToNr(device_name, new_device_nr);
5297 setup.input[input_player_nr].use_joystick = TRUE;
5301 int device_nr = getJoystickNrFromDeviceName(device_name);
5302 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5304 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5305 setup.input[input_player_nr].use_joystick = FALSE;
5307 setJoystickDeviceToNr(device_name, new_device_nr);
5310 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5314 if (setup.input[input_player_nr].use_joystick)
5317 CalibrateJoystick(input_player_nr);
5320 CustomizeKeyboard(input_player_nr);
5322 else if (y == pos_end)
5328 setup_mode = SETUP_MODE_MAIN;
5335 void CustomizeKeyboard(int player_nr)
5339 boolean finished = FALSE;
5340 static struct SetupKeyboardInfo custom_key;
5345 } customize_step[] =
5347 { &custom_key.left, "Move Left" },
5348 { &custom_key.right, "Move Right" },
5349 { &custom_key.up, "Move Up" },
5350 { &custom_key.down, "Move Down" },
5351 { &custom_key.snap, "Snap Field" },
5352 { &custom_key.drop, "Drop Element" }
5355 /* read existing key bindings from player setup */
5356 custom_key = setup.input[player_nr].key;
5359 FadeOut(REDRAW_FIELD);
5363 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5371 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5372 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5373 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5374 "Key:", FONT_INPUT_1_ACTIVE);
5375 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5376 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5379 FadeIn(REDRAW_FIELD);
5386 if (PendingEvent()) /* got event */
5394 case EVENT_KEYPRESS:
5396 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5398 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5400 if (key == KSYM_Escape)
5401 FadeSkipNextFadeIn();
5407 /* all keys configured -- wait for "Escape" or "Return" key */
5411 /* press 'Enter' to keep the existing key binding */
5412 if (key == KSYM_Return)
5413 key = *customize_step[step_nr].key;
5415 /* check if key already used */
5416 for (i = 0; i < step_nr; i++)
5417 if (*customize_step[i].key == key)
5422 /* got new key binding */
5423 *customize_step[step_nr].key = key;
5424 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5426 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5427 getKeyNameFromKey(key), FONT_VALUE_1);
5430 /* un-highlight last query */
5431 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5432 customize_step[step_nr - 1].text, FONT_MENU_1);
5433 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5434 "Key:", FONT_MENU_1);
5436 /* press 'Enter' to leave */
5439 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5440 "Press Enter", FONT_TITLE_1);
5444 /* query next key binding */
5445 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5446 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5447 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5448 "Key:", FONT_INPUT_1_ACTIVE);
5449 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5450 getKeyNameFromKey(*customize_step[step_nr].key),
5455 case EVENT_KEYRELEASE:
5456 key_joystick_mapping = 0;
5460 HandleOtherEvents(&event);
5468 /* don't eat all CPU time */
5472 /* write new key bindings back to player setup */
5473 setup.input[player_nr].key = custom_key;
5476 DrawSetupScreen_Input();
5479 static boolean CalibrateJoystickMain(int player_nr)
5481 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5482 int new_joystick_xright = JOYSTICK_XMIDDLE;
5483 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5484 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5485 int new_joystick_xmiddle, new_joystick_ymiddle;
5487 int joystick_fd = joystick.fd[player_nr];
5488 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5489 boolean check[3][3];
5490 int check_remaining = 3 * 3;
5495 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5498 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5502 FadeOut(REDRAW_FIELD);
5506 for (y = 0; y < 3; y++)
5508 for (x = 0; x < 3; x++)
5510 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5511 check[x][y] = FALSE;
5515 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5516 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5517 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5518 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5519 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5520 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5521 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5523 joy_value = Joystick(player_nr);
5524 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5525 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5527 /* eventually uncalibrated center position (joystick could be uncentered) */
5528 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5531 new_joystick_xmiddle = joy_x;
5532 new_joystick_ymiddle = joy_y;
5534 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5536 FadeIn(REDRAW_FIELD);
5538 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5543 if (PendingEvent()) /* got event */
5551 case EVENT_KEYPRESS:
5552 switch (GetEventKey((KeyEvent *)&event, TRUE))
5555 if (check_remaining == 0)
5560 FadeSkipNextFadeIn();
5569 case EVENT_KEYRELEASE:
5570 key_joystick_mapping = 0;
5574 HandleOtherEvents(&event);
5579 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5582 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5583 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5584 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5585 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5587 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5588 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5589 setup.input[player_nr].joy.xright = new_joystick_xright;
5590 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5591 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5592 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5594 CheckJoystickData();
5596 joy_value = Joystick(player_nr);
5598 if (joy_value & JOY_BUTTON && check_remaining == 0)
5601 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5602 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5604 if (x != last_x || y != last_y)
5606 DrawFixedGraphic(xpos + last_x, ypos + last_y,
5607 IMG_MENU_CALIBRATE_YELLOW, 0);
5608 DrawFixedGraphic(xpos + x, ypos + y,
5609 IMG_MENU_CALIBRATE_RED, 0);
5614 if (check_remaining > 0 && !check[x+1][y+1])
5616 check[x+1][y+1] = TRUE;
5622 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5623 setup.input[player_nr].joy.xleft,
5624 setup.input[player_nr].joy.xmiddle,
5625 setup.input[player_nr].joy.xright);
5626 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5627 setup.input[player_nr].joy.yupper,
5628 setup.input[player_nr].joy.ymiddle,
5629 setup.input[player_nr].joy.ylower);
5638 /* don't eat all CPU time */
5642 /* calibrated center position (joystick should now be centered) */
5643 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5646 new_joystick_xmiddle = joy_x;
5647 new_joystick_ymiddle = joy_y;
5652 DrawSetupScreen_Input();
5655 /* wait until the last pressed button was released */
5656 while (Joystick(player_nr) & JOY_BUTTON)
5658 if (PendingEvent()) /* got event */
5663 HandleOtherEvents(&event);
5672 void CalibrateJoystick(int player_nr)
5674 if (!CalibrateJoystickMain(player_nr))
5676 char *device_name = setup.input[player_nr].joy.device_name;
5677 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5678 int xpos = mSX - SX;
5679 int ypos = mSY - SY;
5683 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5684 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5687 Delay(2000); /* show error message for a short time */
5693 DrawSetupScreen_Input();
5697 void DrawSetupScreen()
5699 DeactivateJoystick();
5701 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5703 if (setup_mode == SETUP_MODE_INPUT)
5704 DrawSetupScreen_Input();
5705 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5706 DrawChooseTree(&game_speed_current);
5707 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5708 DrawChooseTree(&screen_mode_current);
5709 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5710 DrawChooseTree(&scroll_delay_current);
5711 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5712 DrawChooseTree(&artwork.gfx_current);
5713 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5714 DrawChooseTree(&artwork.snd_current);
5715 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5716 DrawChooseTree(&artwork.mus_current);
5718 DrawSetupScreen_Generic();
5724 void RedrawSetupScreenAfterFullscreenToggle()
5726 if (setup_mode == SETUP_MODE_GRAPHICS)
5730 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5732 if (setup_mode == SETUP_MODE_INPUT)
5733 HandleSetupScreen_Input(mx, my, dx, dy, button);
5734 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5735 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5736 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5737 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5738 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5739 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5740 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5741 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5742 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5743 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5744 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5745 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5747 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5752 void HandleGameActions()
5754 if (game_status != GAME_MODE_PLAYING)
5757 GameActions(); /* main game loop */
5759 if (tape.auto_play && !tape.playing)
5760 AutoPlayTape(); /* continue automatically playing next tape */
5764 /* ---------- new screen button stuff -------------------------------------- */
5766 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5771 case SCREEN_CTRL_ID_PREV_LEVEL:
5772 *x = mSX + menu.main.button.prev_level.x;
5773 *y = mSY + menu.main.button.prev_level.y;
5776 case SCREEN_CTRL_ID_NEXT_LEVEL:
5777 *x = mSX + menu.main.button.next_level.x;
5778 *y = mSY + menu.main.button.next_level.y;
5781 case SCREEN_CTRL_ID_PREV_LEVEL:
5782 *x = mSX + TILEX * getPrevlevelButtonPos();
5783 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5786 case SCREEN_CTRL_ID_NEXT_LEVEL:
5787 *x = mSX + TILEX * getNextLevelButtonPos();
5788 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5792 case SCREEN_CTRL_ID_PREV_PLAYER:
5793 *x = mSX + TILEX * 10;
5794 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5797 case SCREEN_CTRL_ID_NEXT_PLAYER:
5798 *x = mSX + TILEX * 12;
5799 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5803 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5809 int gfx_unpressed, gfx_pressed;
5810 void (*get_gadget_position)(int *, int *, int);
5814 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5817 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5818 getScreenMenuButtonPos,
5819 SCREEN_CTRL_ID_PREV_LEVEL,
5824 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5825 getScreenMenuButtonPos,
5826 SCREEN_CTRL_ID_NEXT_LEVEL,
5831 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5832 getScreenMenuButtonPos,
5833 SCREEN_CTRL_ID_PREV_PLAYER,
5838 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5839 getScreenMenuButtonPos,
5840 SCREEN_CTRL_ID_NEXT_PLAYER,
5848 int gfx_unpressed, gfx_pressed;
5852 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5855 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5857 -1, -1, /* these values are not constant, but can change at runtime */
5859 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5861 SCREEN_CTRL_ID_SCROLL_UP,
5865 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5867 -1, -1, /* these values are not constant, but can change at runtime */
5869 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5871 SCREEN_CTRL_ID_SCROLL_DOWN,
5878 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5879 Bitmap **gfx_unpressed, **gfx_pressed;
5881 int gfx_unpressed, gfx_pressed;
5888 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5891 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5892 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5894 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5897 -1, -1, /* these values are not constant, but can change at runtime */
5898 -1, -1, /* these values are not constant, but can change at runtime */
5900 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5901 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5903 GD_TYPE_SCROLLBAR_VERTICAL,
5904 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5905 "scroll level series vertically"
5909 static void CreateScreenMenubuttons()
5911 struct GadgetInfo *gi;
5912 unsigned long event_mask;
5915 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5917 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5918 int gfx_unpressed, gfx_pressed;
5919 int x, y, width, height;
5920 int gd_x1, gd_x2, gd_y1, gd_y2;
5921 int id = menubutton_info[i].gadget_id;
5923 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5925 menubutton_info[i].get_gadget_position(&x, &y, id);
5927 width = SC_MENUBUTTON_XSIZE;
5928 height = SC_MENUBUTTON_YSIZE;
5930 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5931 gfx_pressed = menubutton_info[i].gfx_pressed;
5932 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5933 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5934 gd_x1 = graphic_info[gfx_unpressed].src_x;
5935 gd_y1 = graphic_info[gfx_unpressed].src_y;
5936 gd_x2 = graphic_info[gfx_pressed].src_x;
5937 gd_y2 = graphic_info[gfx_pressed].src_y;
5939 gi = CreateGadget(GDI_CUSTOM_ID, id,
5940 GDI_CUSTOM_TYPE_ID, i,
5941 GDI_INFO_TEXT, menubutton_info[i].infotext,
5946 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5947 GDI_STATE, GD_BUTTON_UNPRESSED,
5948 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5949 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5950 GDI_DIRECT_DRAW, FALSE,
5951 GDI_EVENT_MASK, event_mask,
5952 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5956 Error(ERR_EXIT, "cannot create gadget");
5958 screen_gadget[id] = gi;
5962 static void CreateScreenScrollbuttons()
5964 struct GadgetInfo *gi;
5965 unsigned long event_mask;
5968 /* these values are not constant, but can change at runtime */
5969 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
5970 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
5971 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
5972 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
5974 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5976 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5977 int gfx_unpressed, gfx_pressed;
5978 int x, y, width, height;
5979 int gd_x1, gd_x2, gd_y1, gd_y2;
5980 int id = scrollbutton_info[i].gadget_id;
5982 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5984 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5985 y = mSY + scrollbutton_info[i].y;
5986 width = SC_SCROLLBUTTON_XSIZE;
5987 height = SC_SCROLLBUTTON_YSIZE;
5989 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5990 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5991 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5993 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5994 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5995 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5996 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5997 gd_x1 = graphic_info[gfx_unpressed].src_x;
5998 gd_y1 = graphic_info[gfx_unpressed].src_y;
5999 gd_x2 = graphic_info[gfx_pressed].src_x;
6000 gd_y2 = graphic_info[gfx_pressed].src_y;
6002 gi = CreateGadget(GDI_CUSTOM_ID, id,
6003 GDI_CUSTOM_TYPE_ID, i,
6004 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6009 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6010 GDI_STATE, GD_BUTTON_UNPRESSED,
6011 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6012 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6013 GDI_DIRECT_DRAW, FALSE,
6014 GDI_EVENT_MASK, event_mask,
6015 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6019 Error(ERR_EXIT, "cannot create gadget");
6021 screen_gadget[id] = gi;
6025 static void CreateScreenScrollbars()
6029 /* these values are not constant, but can change at runtime */
6030 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6031 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6032 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6033 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6035 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6037 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6038 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6039 int gfx_unpressed, gfx_pressed;
6041 int x, y, width, height;
6042 int gd_x1, gd_x2, gd_y1, gd_y2;
6043 struct GadgetInfo *gi;
6044 int items_max, items_visible, item_position;
6045 unsigned long event_mask;
6046 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6047 int id = scrollbar_info[i].gadget_id;
6049 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6051 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6052 y = mSY + scrollbar_info[i].y;
6053 width = scrollbar_info[i].width;
6054 height = scrollbar_info[i].height;
6056 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6057 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6059 items_max = num_page_entries;
6060 items_visible = num_page_entries;
6063 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6064 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6065 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6071 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6072 gfx_pressed = scrollbar_info[i].gfx_pressed;
6073 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6074 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6075 gd_x1 = graphic_info[gfx_unpressed].src_x;
6076 gd_y1 = graphic_info[gfx_unpressed].src_y;
6077 gd_x2 = graphic_info[gfx_pressed].src_x;
6078 gd_y2 = graphic_info[gfx_pressed].src_y;
6081 gi = CreateGadget(GDI_CUSTOM_ID, id,
6082 GDI_CUSTOM_TYPE_ID, i,
6083 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6088 GDI_TYPE, scrollbar_info[i].type,
6089 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6090 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6091 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6093 GDI_WHEEL_AREA_X, SX,
6094 GDI_WHEEL_AREA_Y, SY,
6095 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6096 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6098 GDI_WHEEL_AREA_X, 0,
6099 GDI_WHEEL_AREA_Y, 0,
6100 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6101 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6103 GDI_STATE, GD_BUTTON_UNPRESSED,
6104 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6105 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6106 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6107 GDI_DIRECT_DRAW, FALSE,
6108 GDI_EVENT_MASK, event_mask,
6109 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6113 Error(ERR_EXIT, "cannot create gadget");
6115 screen_gadget[id] = gi;
6119 void CreateScreenGadgets()
6121 int last_game_status = game_status; /* save current game status */
6123 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6126 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6128 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6130 /* copy pointers to clip mask and GC */
6131 scrollbar_bitmap[i]->clip_mask =
6132 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6133 scrollbar_bitmap[i]->stored_clip_gc =
6134 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6136 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6137 scrollbar_bitmap[i],
6138 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6139 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6140 TILEX, TILEY, 0, 0);
6144 CreateScreenMenubuttons();
6147 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6148 game_status = GAME_MODE_LEVELS;
6151 CreateScreenScrollbuttons();
6152 CreateScreenScrollbars();
6154 game_status = last_game_status; /* restore current game status */
6157 void FreeScreenGadgets()
6161 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6162 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6164 /* prevent freeing clip mask and GC twice */
6165 scrollbar_bitmap[i]->clip_mask = None;
6166 scrollbar_bitmap[i]->stored_clip_gc = None;
6168 FreeBitmap(scrollbar_bitmap[i]);
6172 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6173 FreeGadget(screen_gadget[i]);
6176 void MapScreenMenuGadgets(int screen_mask)
6180 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6181 if (screen_mask & menubutton_info[i].screen_mask)
6182 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6185 void MapScreenTreeGadgets(TreeInfo *ti)
6187 int num_entries = numTreeInfoInGroup(ti);
6190 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6193 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6194 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6196 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6197 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6200 static void HandleScreenGadgets(struct GadgetInfo *gi)
6202 int id = gi->custom_id;
6203 int button = gi->event.button;
6204 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6208 case SCREEN_CTRL_ID_PREV_LEVEL:
6209 HandleMainMenu_SelectLevel(step, -1);
6212 case SCREEN_CTRL_ID_NEXT_LEVEL:
6213 HandleMainMenu_SelectLevel(step, +1);
6216 case SCREEN_CTRL_ID_PREV_PLAYER:
6217 HandleSetupScreen_Input_Player(step, -1);
6220 case SCREEN_CTRL_ID_NEXT_PLAYER:
6221 HandleSetupScreen_Input_Player(step, +1);
6224 case SCREEN_CTRL_ID_SCROLL_UP:
6225 if (game_status == GAME_MODE_LEVELS)
6226 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6227 else if (game_status == GAME_MODE_LEVELNR)
6228 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6229 else if (game_status == GAME_MODE_SETUP)
6230 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6233 case SCREEN_CTRL_ID_SCROLL_DOWN:
6234 if (game_status == GAME_MODE_LEVELS)
6235 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6236 else if (game_status == GAME_MODE_LEVELNR)
6237 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6238 else if (game_status == GAME_MODE_SETUP)
6239 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6242 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6243 if (game_status == GAME_MODE_LEVELS)
6244 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6245 else if (game_status == GAME_MODE_LEVELNR)
6246 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6247 else if (game_status == GAME_MODE_SETUP)
6248 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);