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 int 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 int 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;
3770 ti->color = (level.no_valid_file ? FC_BLUE :
3771 LevelStats_getSolved(i) ? FC_GREEN :
3772 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3774 sprintf(identifier, "%d", value);
3775 sprintf(name, "%03d: %s", value,
3776 (level.no_valid_file ? "(no file)" : level.name));
3778 setString(&ti->identifier, identifier);
3779 setString(&ti->name, name);
3780 setString(&ti->name_sorting, name);
3782 pushTreeInfo(&level_number, ti);
3785 /* sort level number values to start with lowest level number */
3786 sortTreeInfo(&level_number);
3788 /* set current level number to current level number */
3789 level_number_current =
3790 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3792 /* if that also fails, set current level number to first available level */
3793 if (level_number_current == NULL)
3794 level_number_current = level_number;
3796 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3799 DrawChooseTree(&level_number_current);
3801 DrawChooseTree(&leveldir_current);
3808 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3811 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3813 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3819 void DrawHallOfFame(int highlight_position)
3822 FadeSoundsAndMusic();
3824 /* (this is needed when called from GameEnd() after winning a game) */
3825 KeyboardAutoRepeatOn();
3828 /* (this is needed when called from GameEnd() after winning a game) */
3829 SetDrawDeactivationMask(REDRAW_NONE);
3830 SetDrawBackgroundMask(REDRAW_FIELD);
3832 CloseDoor(DOOR_CLOSE_2);
3834 if (highlight_position < 0)
3835 LoadScore(level_nr);
3837 FadeSetEnterScreen();
3839 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3842 FadeOut(REDRAW_FIELD);
3850 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3853 FadeIn(REDRAW_FIELD);
3857 static void drawHallOfFameList(int first_entry, int highlight_position)
3861 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3864 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3865 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3866 "HighScores of Level %d", level_nr);
3868 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3870 int entry = first_entry + i;
3871 boolean active = (entry == highlight_position);
3872 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3873 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3874 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3875 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3876 int dx1 = 3 * getFontWidth(font_nr1);
3877 int dx2 = dx1 + getFontWidth(font_nr1);
3878 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3879 int sy = mSY + 64 + i * 32;
3881 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3882 DrawText(mSX + dx1, sy, ".", font_nr1);
3883 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3885 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3886 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3888 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3891 redraw_mask |= REDRAW_FIELD;
3894 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3896 static int first_entry = 0;
3897 static int highlight_position = 0;
3898 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3900 if (button == MB_MENU_INITIALIZE)
3903 highlight_position = mx;
3904 drawHallOfFameList(first_entry, highlight_position);
3909 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3910 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3914 if (first_entry > 0)
3916 first_entry -= step;
3917 if (first_entry < 0)
3920 drawHallOfFameList(first_entry, highlight_position);
3925 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3927 first_entry += step;
3928 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3929 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3931 drawHallOfFameList(first_entry, highlight_position);
3934 else if (button == MB_MENU_LEAVE)
3936 PlaySound(SND_MENU_ITEM_SELECTING);
3938 FadeSound(SND_BACKGROUND_SCORES);
3940 game_status = GAME_MODE_MAIN;
3944 else if (button == MB_MENU_CHOICE)
3946 PlaySound(SND_MENU_ITEM_SELECTING);
3948 FadeSound(SND_BACKGROUND_SCORES);
3951 FadeOut(REDRAW_FIELD);
3954 game_status = GAME_MODE_MAIN;
3956 DrawAndFadeInMainMenu(REDRAW_FIELD);
3959 if (game_status == GAME_MODE_SCORES)
3960 PlayMenuSoundIfLoop();
3966 /* ========================================================================= */
3967 /* setup screen functions */
3968 /* ========================================================================= */
3970 static struct TokenInfo *setup_info;
3971 static int num_setup_info;
3973 static char *screen_mode_text;
3974 static char *scroll_delay_text;
3975 static char *game_speed_text;
3976 static char *graphics_set_name;
3977 static char *sounds_set_name;
3978 static char *music_set_name;
3980 static void execSetupMain()
3982 setup_mode = SETUP_MODE_MAIN;
3987 static void execSetupGame()
3989 if (game_speeds == NULL)
3993 for (i = 0; game_speeds_list[i].value != -1; i++)
3995 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3996 char identifier[32], name[32];
3997 int value = game_speeds_list[i].value;
3998 char *text = game_speeds_list[i].text;
4000 ti->node_top = &game_speeds;
4001 ti->sort_priority = 10000 - value;
4003 sprintf(identifier, "%d", value);
4004 sprintf(name, "%s", text);
4006 setString(&ti->identifier, identifier);
4007 setString(&ti->name, name);
4008 setString(&ti->name_sorting, name);
4009 setString(&ti->infotext, "Game Speed");
4011 pushTreeInfo(&game_speeds, ti);
4014 /* sort game speed values to start with slowest game speed */
4015 sortTreeInfo(&game_speeds);
4017 /* set current game speed to configured game speed value */
4018 game_speed_current =
4019 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4021 /* if that fails, set current game speed to reliable default value */
4022 if (game_speed_current == NULL)
4023 game_speed_current =
4024 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4026 /* if that also fails, set current game speed to first available speed */
4027 if (game_speed_current == NULL)
4028 game_speed_current = game_speeds;
4031 setup.game_frame_delay = atoi(game_speed_current->identifier);
4033 /* needed for displaying game speed text instead of identifier */
4034 game_speed_text = game_speed_current->name;
4036 setup_mode = SETUP_MODE_GAME;
4041 static void execSetupChooseGameSpeed()
4043 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4048 static void execSetupEditor()
4050 setup_mode = SETUP_MODE_EDITOR;
4055 static void execSetupGraphics()
4057 if (video.fullscreen_available && screen_modes == NULL)
4061 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4063 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4064 char identifier[32], name[32];
4065 int x = video.fullscreen_modes[i].width;
4066 int y = video.fullscreen_modes[i].height;
4069 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4071 ti->node_top = &screen_modes;
4072 ti->sort_priority = x * 10000 + y;
4074 sprintf(identifier, "%dx%d", x, y);
4075 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4077 setString(&ti->identifier, identifier);
4078 setString(&ti->name, name);
4079 setString(&ti->name_sorting, name);
4080 setString(&ti->infotext, "Fullscreen Mode");
4082 pushTreeInfo(&screen_modes, ti);
4085 /* sort fullscreen modes to start with lowest available screen resolution */
4086 sortTreeInfo(&screen_modes);
4088 /* set current screen mode for fullscreen mode to configured setup value */
4089 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4090 setup.fullscreen_mode);
4092 /* if that fails, set current screen mode to reliable default value */
4093 if (screen_mode_current == NULL)
4094 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4095 DEFAULT_FULLSCREEN_MODE);
4097 /* if that also fails, set current screen mode to first available mode */
4098 if (screen_mode_current == NULL)
4099 screen_mode_current = screen_modes;
4101 if (screen_mode_current == NULL)
4102 video.fullscreen_available = FALSE;
4105 if (video.fullscreen_available)
4107 setup.fullscreen_mode = screen_mode_current->identifier;
4109 /* needed for displaying screen mode name instead of identifier */
4110 screen_mode_text = screen_mode_current->name;
4114 if (scroll_delays == NULL)
4118 for (i = 0; scroll_delays_list[i].value != -1; i++)
4120 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4121 char identifier[32], name[32];
4122 int value = scroll_delays_list[i].value;
4123 char *text = scroll_delays_list[i].text;
4125 ti->node_top = &scroll_delays;
4126 ti->sort_priority = value;
4128 sprintf(identifier, "%d", value);
4129 sprintf(name, "%s", text);
4131 setString(&ti->identifier, identifier);
4132 setString(&ti->name, name);
4133 setString(&ti->name_sorting, name);
4134 setString(&ti->infotext, "Scroll Delay");
4136 pushTreeInfo(&scroll_delays, ti);
4139 /* sort scroll delay values to start with lowest scroll delay value */
4140 sortTreeInfo(&scroll_delays);
4142 /* set current scroll delay value to configured scroll delay value */
4143 scroll_delay_current =
4144 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4146 /* if that fails, set current scroll delay to reliable default value */
4147 if (scroll_delay_current == NULL)
4148 scroll_delay_current =
4149 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4151 /* if that also fails, set current scroll delay to first available value */
4152 if (scroll_delay_current == NULL)
4153 scroll_delay_current = scroll_delays;
4156 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4158 /* needed for displaying scroll delay text instead of identifier */
4159 scroll_delay_text = scroll_delay_current->name;
4162 setup_mode = SETUP_MODE_GRAPHICS;
4166 static void execSetupChooseScreenMode()
4168 if (!video.fullscreen_available)
4171 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4176 static void execSetupChooseScrollDelay()
4178 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4183 static void execSetupSound()
4185 setup_mode = SETUP_MODE_SOUND;
4190 static void execSetupArtwork()
4193 printf("::: '%s', '%s', '%s'\n",
4194 artwork.gfx_current->subdir,
4195 artwork.gfx_current->fullpath,
4196 artwork.gfx_current->basepath);
4199 setup.graphics_set = artwork.gfx_current->identifier;
4200 setup.sounds_set = artwork.snd_current->identifier;
4201 setup.music_set = artwork.mus_current->identifier;
4203 /* needed if last screen (setup choice) changed graphics, sounds or music */
4204 ReloadCustomArtwork(0);
4206 /* needed for displaying artwork name instead of artwork identifier */
4207 graphics_set_name = artwork.gfx_current->name;
4208 sounds_set_name = artwork.snd_current->name;
4209 music_set_name = artwork.mus_current->name;
4211 setup_mode = SETUP_MODE_ARTWORK;
4216 static void execSetupChooseGraphics()
4218 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4223 static void execSetupChooseSounds()
4225 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4230 static void execSetupChooseMusic()
4232 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4237 static void execSetupInput()
4239 setup_mode = SETUP_MODE_INPUT;
4244 static void execSetupShortcuts()
4246 setup_mode = SETUP_MODE_SHORTCUTS;
4251 static void execSetupShortcuts1()
4253 setup_mode = SETUP_MODE_SHORTCUTS_1;
4258 static void execSetupShortcuts2()
4260 setup_mode = SETUP_MODE_SHORTCUTS_2;
4265 static void execSetupShortcuts3()
4267 setup_mode = SETUP_MODE_SHORTCUTS_3;
4272 static void execSetupShortcuts4()
4274 setup_mode = SETUP_MODE_SHORTCUTS_4;
4279 static void execSetupShortcuts5()
4281 setup_mode = SETUP_MODE_SHORTCUTS_5;
4286 static void execExitSetup()
4288 game_status = GAME_MODE_MAIN;
4290 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4293 static void execSaveAndExitSetup()
4299 static struct TokenInfo setup_info_main[] =
4301 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4302 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4303 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4304 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4305 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4306 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4307 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4308 { TYPE_EMPTY, NULL, "" },
4309 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4310 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4315 static struct TokenInfo setup_info_game[] =
4317 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4318 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4319 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4320 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4321 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4322 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4323 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4324 { TYPE_STRING, &game_speed_text, "" },
4325 { TYPE_EMPTY, NULL, "" },
4326 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4331 static struct TokenInfo setup_info_editor[] =
4334 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4335 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4336 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4337 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4338 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4339 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4340 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4341 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4343 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4344 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4345 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4347 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4349 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4350 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4351 { TYPE_EMPTY, NULL, "" },
4353 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4354 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4355 { TYPE_EMPTY, NULL, "" },
4357 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4358 { TYPE_EMPTY, NULL, "" },
4359 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4364 static struct TokenInfo setup_info_graphics[] =
4366 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4367 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4368 { TYPE_STRING, &screen_mode_text, "" },
4370 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4372 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4373 { TYPE_STRING, &scroll_delay_text, "" },
4375 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4377 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4378 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4379 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4380 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4381 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4382 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4383 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4384 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4385 { TYPE_EMPTY, NULL, "" },
4386 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4391 static struct TokenInfo setup_info_sound[] =
4393 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4394 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4395 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4396 { TYPE_EMPTY, NULL, "" },
4397 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4402 static struct TokenInfo setup_info_artwork[] =
4404 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4405 { TYPE_STRING, &graphics_set_name, "" },
4406 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4407 { TYPE_STRING, &sounds_set_name, "" },
4408 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4409 { TYPE_STRING, &music_set_name, "" },
4410 { TYPE_EMPTY, NULL, "" },
4413 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4414 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4415 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4417 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4418 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4419 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4420 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4423 { TYPE_STRING, NULL, "Override Level Artwork:"},
4424 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4425 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4426 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4428 { TYPE_EMPTY, NULL, "" },
4429 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4434 static struct TokenInfo setup_info_input[] =
4436 { TYPE_SWITCH, NULL, "Player:" },
4437 { TYPE_SWITCH, NULL, "Device:" },
4438 { TYPE_ENTER_MENU, 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_EMPTY, NULL, "" },
4446 { TYPE_EMPTY, NULL, "" },
4447 { TYPE_EMPTY, NULL, "" },
4448 { TYPE_EMPTY, NULL, "" },
4449 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4454 static struct TokenInfo setup_info_shortcuts[] =
4456 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4457 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4458 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4459 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4460 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4461 { TYPE_EMPTY, NULL, "" },
4462 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4467 static struct TokenInfo setup_info_shortcuts_1[] =
4469 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4470 { TYPE_KEY, &setup.shortcut.save_game, "" },
4471 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4472 { TYPE_KEY, &setup.shortcut.load_game, "" },
4473 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4474 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4475 { TYPE_EMPTY, NULL, "" },
4476 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4477 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4478 { TYPE_EMPTY, NULL, "" },
4479 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4484 static struct TokenInfo setup_info_shortcuts_2[] =
4486 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4487 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4488 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4489 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4490 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4491 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4492 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4493 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4494 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4495 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4496 { TYPE_EMPTY, NULL, "" },
4497 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4502 static struct TokenInfo setup_info_shortcuts_3[] =
4504 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
4505 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4506 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
4507 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
4508 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
4509 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4510 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
4511 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4512 { TYPE_KEYTEXT, NULL, "Record Tape:", },
4513 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4514 { TYPE_KEYTEXT, NULL, "Play Tape:", },
4515 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4516 { TYPE_EMPTY, NULL, "" },
4517 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4522 static struct TokenInfo setup_info_shortcuts_4[] =
4524 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
4525 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4526 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
4527 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4528 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
4529 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4530 { TYPE_EMPTY, NULL, "" },
4531 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4536 static struct TokenInfo setup_info_shortcuts_5[] =
4538 { TYPE_KEYTEXT, NULL, "Snap Left:", },
4539 { TYPE_KEY, &setup.shortcut.snap_left, "" },
4540 { TYPE_KEYTEXT, NULL, "Snap Right:", },
4541 { TYPE_KEY, &setup.shortcut.snap_right, "" },
4542 { TYPE_KEYTEXT, NULL, "Snap Up:", },
4543 { TYPE_KEY, &setup.shortcut.snap_up, "" },
4544 { TYPE_KEYTEXT, NULL, "Snap Down:", },
4545 { TYPE_KEY, &setup.shortcut.snap_down, "" },
4546 { TYPE_EMPTY, NULL, "" },
4547 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4552 static Key getSetupKey()
4554 Key key = KSYM_UNDEFINED;
4555 boolean got_key_event = FALSE;
4557 while (!got_key_event)
4559 if (PendingEvent()) /* got event */
4567 case EVENT_KEYPRESS:
4569 key = GetEventKey((KeyEvent *)&event, TRUE);
4571 /* press 'Escape' or 'Enter' to keep the existing key binding */
4572 if (key == KSYM_Escape || key == KSYM_Return)
4573 key = KSYM_UNDEFINED; /* keep old value */
4575 got_key_event = TRUE;
4579 case EVENT_KEYRELEASE:
4580 key_joystick_mapping = 0;
4584 HandleOtherEvents(&event);
4592 /* don't eat all CPU time */
4599 static int getSetupTextFont(int type)
4601 if (type & (TYPE_SWITCH |
4613 static int getSetupValueFont(int type, void *value)
4615 if (type & TYPE_KEY)
4616 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4617 else if (type & TYPE_STRING)
4618 return FONT_VALUE_2;
4619 else if (type & TYPE_ECS_AGA)
4620 return FONT_VALUE_1;
4621 else if (type & TYPE_BOOLEAN_STYLE)
4622 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4623 else if (type & TYPE_YES_NO_AUTO)
4624 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4625 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4627 return FONT_VALUE_1;
4630 static void drawSetupValue(int pos)
4632 boolean font_draw_xoffset_modified = FALSE;
4633 int font_draw_xoffset_old = -1;
4634 int xpos = MENU_SCREEN_VALUE_XPOS;
4635 int ypos = MENU_SCREEN_START_YPOS + pos;
4636 int startx = mSX + xpos * 32;
4637 int starty = mSY + ypos * 32;
4638 int font_nr, font_width, font_height;
4639 int type = setup_info[pos].type;
4640 void *value = setup_info[pos].value;
4641 char *value_string = getSetupValue(type, value);
4646 if (value_string == NULL)
4649 if (type & TYPE_KEY)
4651 xpos = MENU_SCREEN_START_XPOS;
4653 if (type & TYPE_QUERY)
4654 value_string = "<press key>";
4656 else if (type & TYPE_STRING)
4658 int max_value_len = (SCR_FIELDX - 2) * 2;
4660 xpos = MENU_SCREEN_START_XPOS;
4662 if (strlen(value_string) > max_value_len)
4663 value_string[max_value_len] = '\0';
4665 else if (type & TYPE_YES_NO_AUTO)
4667 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4670 startx = mSX + xpos * 32;
4671 starty = mSY + ypos * 32;
4672 font_nr = getSetupValueFont(type, value);
4673 font_width = getFontWidth(font_nr);
4674 font_height = getFontHeight(font_nr);
4676 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4677 if (setup_mode != SETUP_MODE_INPUT)
4679 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4680 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4681 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4682 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4683 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4684 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4685 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4686 boolean correct_font_draw_xoffset = FALSE;
4688 if (xpos == MENU_SCREEN_START_XPOS &&
4689 startx + font1_xoffset < text_startx + text_font_xoffset)
4690 correct_font_draw_xoffset = TRUE;
4692 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4693 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4694 correct_font_draw_xoffset = TRUE;
4696 /* check if setup value would overlap with setup text when printed */
4697 /* (this can happen for extreme/wrong values for font draw offset) */
4698 if (correct_font_draw_xoffset)
4700 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4701 font_draw_xoffset_modified = TRUE;
4703 if (type & TYPE_KEY)
4704 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4705 else if (!(type & TYPE_STRING))
4706 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4707 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4712 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4714 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4715 DrawText(startx + i * font_width, starty, " ", font_nr);
4718 DrawText(startx, starty, value_string, font_nr);
4720 if (font_draw_xoffset_modified)
4721 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4724 static void changeSetupValue(int pos, int dx)
4726 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4728 *(boolean *)setup_info[pos].value ^= TRUE;
4730 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4732 *(int *)setup_info[pos].value =
4734 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4735 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4736 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4737 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4739 else if (setup_info[pos].type & TYPE_KEY)
4743 setup_info[pos].type |= TYPE_QUERY;
4744 drawSetupValue(pos);
4745 setup_info[pos].type &= ~TYPE_QUERY;
4747 key = getSetupKey();
4748 if (key != KSYM_UNDEFINED)
4749 *(Key *)setup_info[pos].value = key;
4752 drawSetupValue(pos);
4755 static void DrawCursorAndText_Setup(int pos, boolean active)
4757 int xpos = MENU_SCREEN_START_XPOS;
4758 int ypos = MENU_SCREEN_START_YPOS + pos;
4759 int font_nr = getSetupTextFont(setup_info[pos].type);
4761 if (setup_info == setup_info_input)
4762 font_nr = FONT_MENU_1;
4765 font_nr = FONT_ACTIVE(font_nr);
4767 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4769 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4770 drawCursor(pos, active);
4773 static void DrawSetupScreen_Generic()
4775 boolean redraw_all = FALSE;
4776 char *title_string = NULL;
4780 CloseDoor(DOOR_CLOSE_2);
4782 if (redraw_mask & REDRAW_ALL)
4786 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4787 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4788 int2str(0, redraw_mask)));
4792 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4793 FadeOut(redraw_mask);
4795 FadeOut(REDRAW_FIELD);
4800 if (setup_mode == SETUP_MODE_MAIN)
4802 setup_info = setup_info_main;
4803 title_string = "Setup";
4805 else if (setup_mode == SETUP_MODE_GAME)
4807 setup_info = setup_info_game;
4808 title_string = "Setup Game";
4810 else if (setup_mode == SETUP_MODE_EDITOR)
4812 setup_info = setup_info_editor;
4813 title_string = "Setup Editor";
4815 else if (setup_mode == SETUP_MODE_GRAPHICS)
4817 setup_info = setup_info_graphics;
4818 title_string = "Setup Graphics";
4820 else if (setup_mode == SETUP_MODE_SOUND)
4822 setup_info = setup_info_sound;
4823 title_string = "Setup Sound";
4825 else if (setup_mode == SETUP_MODE_ARTWORK)
4827 setup_info = setup_info_artwork;
4828 title_string = "Custom Artwork";
4830 else if (setup_mode == SETUP_MODE_SHORTCUTS)
4832 setup_info = setup_info_shortcuts;
4833 title_string = "Setup Shortcuts";
4835 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4837 setup_info = setup_info_shortcuts_1;
4838 title_string = "Setup Shortcuts";
4840 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4842 setup_info = setup_info_shortcuts_2;
4843 title_string = "Setup Shortcuts";
4845 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
4847 setup_info = setup_info_shortcuts_3;
4848 title_string = "Setup Shortcuts";
4850 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
4852 setup_info = setup_info_shortcuts_4;
4853 title_string = "Setup Shortcuts";
4855 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
4857 setup_info = setup_info_shortcuts_5;
4858 title_string = "Setup Shortcuts";
4861 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4865 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4867 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4870 void *value_ptr = setup_info[i].value;
4872 /* set some entries to "unchangeable" according to other variables */
4873 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4874 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4875 (value_ptr == &setup.sound_music && !audio.music_available) ||
4876 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4877 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4878 setup_info[i].type |= TYPE_GHOSTED;
4880 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4881 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4882 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4883 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4884 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4885 initCursor(i, IMG_MENU_BUTTON);
4887 DrawCursorAndText_Setup(i, FALSE);
4889 if (setup_info[i].type & TYPE_VALUE)
4896 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4897 "Joysticks deactivated in setup menu");
4901 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4905 redraw_mask = REDRAW_ALL;
4908 FadeIn(redraw_mask);
4910 FadeIn(REDRAW_FIELD);
4915 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4919 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4921 static int choice_store[MAX_SETUP_MODES];
4922 int choice = choice_store[setup_mode]; /* always starts with 0 */
4926 if (button == MB_MENU_INITIALIZE)
4928 /* advance to first valid menu entry */
4929 while (choice < num_setup_info &&
4930 setup_info[choice].type & TYPE_SKIP_ENTRY)
4932 choice_store[setup_mode] = choice;
4934 DrawCursorAndText_Setup(choice, TRUE);
4938 else if (button == MB_MENU_LEAVE)
4940 PlaySound(SND_MENU_ITEM_SELECTING);
4942 for (y = 0; y < num_setup_info; y++)
4944 if (setup_info[y].type & TYPE_LEAVE_MENU)
4946 void (*menu_callback_function)(void) = setup_info[y].value;
4950 menu_callback_function();
4952 break; /* absolutely needed because function changes 'setup_info'! */
4959 if (mx || my) /* mouse input */
4961 x = (mx - mSX) / 32;
4962 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4964 else if (dx || dy) /* keyboard input */
4968 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4970 if (setup_info[choice].type & menu_navigation_type ||
4971 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4972 setup_info[choice].type & TYPE_YES_NO_AUTO)
4973 button = MB_MENU_CHOICE;
4978 /* jump to next non-empty menu entry (up or down) */
4979 while (y > 0 && y < num_setup_info - 1 &&
4980 setup_info[y].type & TYPE_SKIP_ENTRY)
4984 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4988 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4990 PlaySound(SND_MENU_ITEM_ACTIVATING);
4992 DrawCursorAndText_Setup(choice, FALSE);
4993 DrawCursorAndText_Setup(y, TRUE);
4995 choice = choice_store[setup_mode] = y;
4998 else if (!(setup_info[y].type & TYPE_GHOSTED))
5000 PlaySound(SND_MENU_ITEM_SELECTING);
5002 /* when selecting key headline, execute function for key value change */
5003 if (setup_info[y].type & TYPE_KEYTEXT &&
5004 setup_info[y + 1].type & TYPE_KEY)
5007 /* when selecting string value, execute function for list selection */
5008 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5009 setup_info[y - 1].type & TYPE_ENTER_LIST)
5012 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5014 void (*menu_callback_function)(void) = setup_info[y].value;
5016 FadeSetFromType(setup_info[y].type);
5018 menu_callback_function();
5022 if (setup_info[y].type & TYPE_VALUE)
5023 changeSetupValue(y, dx);
5029 void DrawSetupScreen_Input()
5034 FadeOut(REDRAW_FIELD);
5040 setup_info = setup_info_input;
5043 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5047 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5048 "Joysticks deactivated on this screen");
5050 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5051 "Joysticks deactivated on this screen");
5056 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5058 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5061 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5062 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5063 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5064 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5065 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5066 initCursor(i, IMG_MENU_BUTTON);
5068 DrawCursorAndText_Setup(i, FALSE);
5072 DeactivateJoystickForCalibration();
5077 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5078 "Joysticks deactivated on this screen");
5080 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5081 "Joysticks deactivated on this screen");
5085 /* create gadgets for setup input menu screen */
5086 FreeScreenGadgets();
5087 CreateScreenGadgets();
5089 /* map gadgets for setup input menu screen */
5090 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5092 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5095 FadeIn(REDRAW_FIELD);
5101 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5103 if (device_name == NULL)
5106 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5109 if (strlen(device_name) > 1)
5111 char c1 = device_name[strlen(device_name) - 1];
5112 char c2 = device_name[strlen(device_name) - 2];
5114 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5115 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5118 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5119 strlen(device_name));
5122 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5125 static struct SetupKeyboardInfo custom_key;
5132 { &custom_key.left, "Joystick Left" },
5133 { &custom_key.right, "Joystick Right" },
5134 { &custom_key.up, "Joystick Up" },
5135 { &custom_key.down, "Joystick Down" },
5136 { &custom_key.snap, "Button 1" },
5137 { &custom_key.drop, "Button 2" }
5139 static char *joystick_name[MAX_PLAYERS] =
5146 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5150 custom_key = setup.input[player_nr].key;
5152 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5153 FONT_INPUT_1_ACTIVE);
5155 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5157 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5158 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5160 if (setup.input[player_nr].use_joystick)
5162 char *device_name = setup.input[player_nr].joy.device_name;
5163 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5164 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5166 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5167 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5171 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5172 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5175 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5177 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5178 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5179 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5180 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5182 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5183 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5184 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5185 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5186 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5187 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5189 for (i = 0; i < 6; i++)
5191 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5193 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5195 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5196 (setup.input[player_nr].use_joystick ?
5198 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5202 static int input_player_nr = 0;
5204 void HandleSetupScreen_Input_Player(int step, int direction)
5206 int old_player_nr = input_player_nr;
5209 new_player_nr = old_player_nr + step * direction;
5210 if (new_player_nr < 0)
5212 if (new_player_nr > MAX_PLAYERS - 1)
5213 new_player_nr = MAX_PLAYERS - 1;
5215 if (new_player_nr != old_player_nr)
5217 input_player_nr = new_player_nr;
5219 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5223 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5225 static int choice = 0;
5228 int pos_start = SETUPINPUT_SCREEN_POS_START;
5229 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5230 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5231 int pos_end = SETUPINPUT_SCREEN_POS_END;
5233 if (button == MB_MENU_INITIALIZE)
5235 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5237 DrawCursorAndText_Setup(choice, TRUE);
5241 else if (button == MB_MENU_LEAVE)
5243 setup_mode = SETUP_MODE_MAIN;
5250 if (mx || my) /* mouse input */
5252 x = (mx - mSX) / 32;
5253 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5255 else if (dx || dy) /* keyboard input */
5257 if (dx && choice == 0)
5258 x = (dx < 0 ? 10 : 12);
5259 else if ((dx && choice == 1) ||
5260 (dx == +1 && choice == 2) ||
5261 (dx == -1 && choice == pos_end))
5262 button = MB_MENU_CHOICE;
5266 if (y >= pos_empty1 && y <= pos_empty2)
5267 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5270 if (y == 0 && dx != 0 && button)
5272 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5274 else if (IN_VIS_FIELD(x, y) &&
5275 y >= pos_start && y <= pos_end &&
5276 !(y >= pos_empty1 && y <= pos_empty2))
5282 DrawCursorAndText_Setup(choice, FALSE);
5283 DrawCursorAndText_Setup(y, TRUE);
5285 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5294 char *device_name = setup.input[input_player_nr].joy.device_name;
5296 if (!setup.input[input_player_nr].use_joystick)
5298 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5300 setJoystickDeviceToNr(device_name, new_device_nr);
5301 setup.input[input_player_nr].use_joystick = TRUE;
5305 int device_nr = getJoystickNrFromDeviceName(device_name);
5306 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5308 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5309 setup.input[input_player_nr].use_joystick = FALSE;
5311 setJoystickDeviceToNr(device_name, new_device_nr);
5314 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5318 if (setup.input[input_player_nr].use_joystick)
5321 CalibrateJoystick(input_player_nr);
5324 CustomizeKeyboard(input_player_nr);
5326 else if (y == pos_end)
5332 setup_mode = SETUP_MODE_MAIN;
5339 void CustomizeKeyboard(int player_nr)
5343 boolean finished = FALSE;
5344 static struct SetupKeyboardInfo custom_key;
5349 } customize_step[] =
5351 { &custom_key.left, "Move Left" },
5352 { &custom_key.right, "Move Right" },
5353 { &custom_key.up, "Move Up" },
5354 { &custom_key.down, "Move Down" },
5355 { &custom_key.snap, "Snap Field" },
5356 { &custom_key.drop, "Drop Element" }
5359 /* read existing key bindings from player setup */
5360 custom_key = setup.input[player_nr].key;
5363 FadeOut(REDRAW_FIELD);
5367 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5375 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5376 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5377 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5378 "Key:", FONT_INPUT_1_ACTIVE);
5379 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5380 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5383 FadeIn(REDRAW_FIELD);
5390 if (PendingEvent()) /* got event */
5398 case EVENT_KEYPRESS:
5400 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5402 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5404 if (key == KSYM_Escape)
5405 FadeSkipNextFadeIn();
5411 /* all keys configured -- wait for "Escape" or "Return" key */
5415 /* press 'Enter' to keep the existing key binding */
5416 if (key == KSYM_Return)
5417 key = *customize_step[step_nr].key;
5419 /* check if key already used */
5420 for (i = 0; i < step_nr; i++)
5421 if (*customize_step[i].key == key)
5426 /* got new key binding */
5427 *customize_step[step_nr].key = key;
5428 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5430 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5431 getKeyNameFromKey(key), FONT_VALUE_1);
5434 /* un-highlight last query */
5435 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5436 customize_step[step_nr - 1].text, FONT_MENU_1);
5437 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5438 "Key:", FONT_MENU_1);
5440 /* press 'Enter' to leave */
5443 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5444 "Press Enter", FONT_TITLE_1);
5448 /* query next key binding */
5449 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5450 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5451 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5452 "Key:", FONT_INPUT_1_ACTIVE);
5453 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5454 getKeyNameFromKey(*customize_step[step_nr].key),
5459 case EVENT_KEYRELEASE:
5460 key_joystick_mapping = 0;
5464 HandleOtherEvents(&event);
5472 /* don't eat all CPU time */
5476 /* write new key bindings back to player setup */
5477 setup.input[player_nr].key = custom_key;
5480 DrawSetupScreen_Input();
5483 static boolean CalibrateJoystickMain(int player_nr)
5485 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5486 int new_joystick_xright = JOYSTICK_XMIDDLE;
5487 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5488 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5489 int new_joystick_xmiddle, new_joystick_ymiddle;
5491 int joystick_fd = joystick.fd[player_nr];
5492 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5493 boolean check[3][3];
5494 int check_remaining = 3 * 3;
5499 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5502 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5506 FadeOut(REDRAW_FIELD);
5510 for (y = 0; y < 3; y++)
5512 for (x = 0; x < 3; x++)
5514 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5515 check[x][y] = FALSE;
5519 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5520 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5521 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5522 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5523 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5524 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5525 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5527 joy_value = Joystick(player_nr);
5528 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5529 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5531 /* eventually uncalibrated center position (joystick could be uncentered) */
5532 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5535 new_joystick_xmiddle = joy_x;
5536 new_joystick_ymiddle = joy_y;
5538 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5540 FadeIn(REDRAW_FIELD);
5542 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5547 if (PendingEvent()) /* got event */
5555 case EVENT_KEYPRESS:
5556 switch (GetEventKey((KeyEvent *)&event, TRUE))
5559 if (check_remaining == 0)
5564 FadeSkipNextFadeIn();
5573 case EVENT_KEYRELEASE:
5574 key_joystick_mapping = 0;
5578 HandleOtherEvents(&event);
5583 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5586 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5587 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5588 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5589 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5591 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5592 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5593 setup.input[player_nr].joy.xright = new_joystick_xright;
5594 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5595 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5596 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5598 CheckJoystickData();
5600 joy_value = Joystick(player_nr);
5602 if (joy_value & JOY_BUTTON && check_remaining == 0)
5605 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5606 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5608 if (x != last_x || y != last_y)
5610 DrawFixedGraphic(xpos + last_x, ypos + last_y,
5611 IMG_MENU_CALIBRATE_YELLOW, 0);
5612 DrawFixedGraphic(xpos + x, ypos + y,
5613 IMG_MENU_CALIBRATE_RED, 0);
5618 if (check_remaining > 0 && !check[x+1][y+1])
5620 check[x+1][y+1] = TRUE;
5626 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5627 setup.input[player_nr].joy.xleft,
5628 setup.input[player_nr].joy.xmiddle,
5629 setup.input[player_nr].joy.xright);
5630 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5631 setup.input[player_nr].joy.yupper,
5632 setup.input[player_nr].joy.ymiddle,
5633 setup.input[player_nr].joy.ylower);
5642 /* don't eat all CPU time */
5646 /* calibrated center position (joystick should now be centered) */
5647 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5650 new_joystick_xmiddle = joy_x;
5651 new_joystick_ymiddle = joy_y;
5656 DrawSetupScreen_Input();
5659 /* wait until the last pressed button was released */
5660 while (Joystick(player_nr) & JOY_BUTTON)
5662 if (PendingEvent()) /* got event */
5667 HandleOtherEvents(&event);
5676 void CalibrateJoystick(int player_nr)
5678 if (!CalibrateJoystickMain(player_nr))
5680 char *device_name = setup.input[player_nr].joy.device_name;
5681 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5682 int xpos = mSX - SX;
5683 int ypos = mSY - SY;
5687 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5688 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5691 Delay(2000); /* show error message for a short time */
5697 DrawSetupScreen_Input();
5701 void DrawSetupScreen()
5703 DeactivateJoystick();
5705 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5707 if (setup_mode == SETUP_MODE_INPUT)
5708 DrawSetupScreen_Input();
5709 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5710 DrawChooseTree(&game_speed_current);
5711 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5712 DrawChooseTree(&screen_mode_current);
5713 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5714 DrawChooseTree(&scroll_delay_current);
5715 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5716 DrawChooseTree(&artwork.gfx_current);
5717 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5718 DrawChooseTree(&artwork.snd_current);
5719 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5720 DrawChooseTree(&artwork.mus_current);
5722 DrawSetupScreen_Generic();
5728 void RedrawSetupScreenAfterFullscreenToggle()
5730 if (setup_mode == SETUP_MODE_GRAPHICS)
5734 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5736 if (setup_mode == SETUP_MODE_INPUT)
5737 HandleSetupScreen_Input(mx, my, dx, dy, button);
5738 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5739 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5740 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5741 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5742 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5743 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5744 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5745 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5746 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5747 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5748 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5749 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5751 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5756 void HandleGameActions()
5758 if (game_status != GAME_MODE_PLAYING)
5761 GameActions(); /* main game loop */
5763 if (tape.auto_play && !tape.playing)
5764 AutoPlayTape(); /* continue automatically playing next tape */
5768 /* ---------- new screen button stuff -------------------------------------- */
5770 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5775 case SCREEN_CTRL_ID_PREV_LEVEL:
5776 *x = mSX + menu.main.button.prev_level.x;
5777 *y = mSY + menu.main.button.prev_level.y;
5780 case SCREEN_CTRL_ID_NEXT_LEVEL:
5781 *x = mSX + menu.main.button.next_level.x;
5782 *y = mSY + menu.main.button.next_level.y;
5785 case SCREEN_CTRL_ID_PREV_LEVEL:
5786 *x = mSX + TILEX * getPrevlevelButtonPos();
5787 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5790 case SCREEN_CTRL_ID_NEXT_LEVEL:
5791 *x = mSX + TILEX * getNextLevelButtonPos();
5792 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5796 case SCREEN_CTRL_ID_PREV_PLAYER:
5797 *x = mSX + TILEX * 10;
5798 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5801 case SCREEN_CTRL_ID_NEXT_PLAYER:
5802 *x = mSX + TILEX * 12;
5803 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5807 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5813 int gfx_unpressed, gfx_pressed;
5814 void (*get_gadget_position)(int *, int *, int);
5818 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5821 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5822 getScreenMenuButtonPos,
5823 SCREEN_CTRL_ID_PREV_LEVEL,
5828 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5829 getScreenMenuButtonPos,
5830 SCREEN_CTRL_ID_NEXT_LEVEL,
5835 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5836 getScreenMenuButtonPos,
5837 SCREEN_CTRL_ID_PREV_PLAYER,
5842 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5843 getScreenMenuButtonPos,
5844 SCREEN_CTRL_ID_NEXT_PLAYER,
5852 int gfx_unpressed, gfx_pressed;
5856 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5859 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5861 -1, -1, /* these values are not constant, but can change at runtime */
5863 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5865 SCREEN_CTRL_ID_SCROLL_UP,
5869 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5871 -1, -1, /* these values are not constant, but can change at runtime */
5873 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5875 SCREEN_CTRL_ID_SCROLL_DOWN,
5882 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5883 Bitmap **gfx_unpressed, **gfx_pressed;
5885 int gfx_unpressed, gfx_pressed;
5892 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5895 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5896 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5898 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5901 -1, -1, /* these values are not constant, but can change at runtime */
5902 -1, -1, /* these values are not constant, but can change at runtime */
5904 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5905 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5907 GD_TYPE_SCROLLBAR_VERTICAL,
5908 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5909 "scroll level series vertically"
5913 static void CreateScreenMenubuttons()
5915 struct GadgetInfo *gi;
5916 unsigned int event_mask;
5919 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5921 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5922 int gfx_unpressed, gfx_pressed;
5923 int x, y, width, height;
5924 int gd_x1, gd_x2, gd_y1, gd_y2;
5925 int id = menubutton_info[i].gadget_id;
5927 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5929 menubutton_info[i].get_gadget_position(&x, &y, id);
5931 width = SC_MENUBUTTON_XSIZE;
5932 height = SC_MENUBUTTON_YSIZE;
5934 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5935 gfx_pressed = menubutton_info[i].gfx_pressed;
5936 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5937 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5938 gd_x1 = graphic_info[gfx_unpressed].src_x;
5939 gd_y1 = graphic_info[gfx_unpressed].src_y;
5940 gd_x2 = graphic_info[gfx_pressed].src_x;
5941 gd_y2 = graphic_info[gfx_pressed].src_y;
5943 gi = CreateGadget(GDI_CUSTOM_ID, id,
5944 GDI_CUSTOM_TYPE_ID, i,
5945 GDI_INFO_TEXT, menubutton_info[i].infotext,
5950 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5951 GDI_STATE, GD_BUTTON_UNPRESSED,
5952 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5953 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5954 GDI_DIRECT_DRAW, FALSE,
5955 GDI_EVENT_MASK, event_mask,
5956 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5960 Error(ERR_EXIT, "cannot create gadget");
5962 screen_gadget[id] = gi;
5966 static void CreateScreenScrollbuttons()
5968 struct GadgetInfo *gi;
5969 unsigned int event_mask;
5972 /* these values are not constant, but can change at runtime */
5973 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
5974 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
5975 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
5976 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
5978 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5980 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5981 int gfx_unpressed, gfx_pressed;
5982 int x, y, width, height;
5983 int gd_x1, gd_x2, gd_y1, gd_y2;
5984 int id = scrollbutton_info[i].gadget_id;
5986 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5988 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5989 y = mSY + scrollbutton_info[i].y;
5990 width = SC_SCROLLBUTTON_XSIZE;
5991 height = SC_SCROLLBUTTON_YSIZE;
5993 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5994 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5995 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5997 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5998 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5999 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6000 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6001 gd_x1 = graphic_info[gfx_unpressed].src_x;
6002 gd_y1 = graphic_info[gfx_unpressed].src_y;
6003 gd_x2 = graphic_info[gfx_pressed].src_x;
6004 gd_y2 = graphic_info[gfx_pressed].src_y;
6006 gi = CreateGadget(GDI_CUSTOM_ID, id,
6007 GDI_CUSTOM_TYPE_ID, i,
6008 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6013 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6014 GDI_STATE, GD_BUTTON_UNPRESSED,
6015 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6016 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6017 GDI_DIRECT_DRAW, FALSE,
6018 GDI_EVENT_MASK, event_mask,
6019 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6023 Error(ERR_EXIT, "cannot create gadget");
6025 screen_gadget[id] = gi;
6029 static void CreateScreenScrollbars()
6033 /* these values are not constant, but can change at runtime */
6034 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6035 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6036 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6037 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6039 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6041 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6042 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6043 int gfx_unpressed, gfx_pressed;
6045 int x, y, width, height;
6046 int gd_x1, gd_x2, gd_y1, gd_y2;
6047 struct GadgetInfo *gi;
6048 int items_max, items_visible, item_position;
6049 unsigned int event_mask;
6050 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6051 int id = scrollbar_info[i].gadget_id;
6053 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6055 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6056 y = mSY + scrollbar_info[i].y;
6057 width = scrollbar_info[i].width;
6058 height = scrollbar_info[i].height;
6060 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6061 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6063 items_max = num_page_entries;
6064 items_visible = num_page_entries;
6067 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6068 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6069 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6075 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6076 gfx_pressed = scrollbar_info[i].gfx_pressed;
6077 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6078 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6079 gd_x1 = graphic_info[gfx_unpressed].src_x;
6080 gd_y1 = graphic_info[gfx_unpressed].src_y;
6081 gd_x2 = graphic_info[gfx_pressed].src_x;
6082 gd_y2 = graphic_info[gfx_pressed].src_y;
6085 gi = CreateGadget(GDI_CUSTOM_ID, id,
6086 GDI_CUSTOM_TYPE_ID, i,
6087 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6092 GDI_TYPE, scrollbar_info[i].type,
6093 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6094 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6095 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6097 GDI_WHEEL_AREA_X, SX,
6098 GDI_WHEEL_AREA_Y, SY,
6099 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6100 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6102 GDI_WHEEL_AREA_X, 0,
6103 GDI_WHEEL_AREA_Y, 0,
6104 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6105 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6107 GDI_STATE, GD_BUTTON_UNPRESSED,
6108 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6109 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6110 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6111 GDI_DIRECT_DRAW, FALSE,
6112 GDI_EVENT_MASK, event_mask,
6113 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6117 Error(ERR_EXIT, "cannot create gadget");
6119 screen_gadget[id] = gi;
6123 void CreateScreenGadgets()
6125 int last_game_status = game_status; /* save current game status */
6127 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6130 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6132 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6134 /* copy pointers to clip mask and GC */
6135 scrollbar_bitmap[i]->clip_mask =
6136 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6137 scrollbar_bitmap[i]->stored_clip_gc =
6138 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6140 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6141 scrollbar_bitmap[i],
6142 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6143 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6144 TILEX, TILEY, 0, 0);
6148 CreateScreenMenubuttons();
6151 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6152 game_status = GAME_MODE_LEVELS;
6155 CreateScreenScrollbuttons();
6156 CreateScreenScrollbars();
6158 game_status = last_game_status; /* restore current game status */
6161 void FreeScreenGadgets()
6165 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6166 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6168 /* prevent freeing clip mask and GC twice */
6169 scrollbar_bitmap[i]->clip_mask = None;
6170 scrollbar_bitmap[i]->stored_clip_gc = None;
6172 FreeBitmap(scrollbar_bitmap[i]);
6176 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6177 FreeGadget(screen_gadget[i]);
6180 void MapScreenMenuGadgets(int screen_mask)
6184 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6185 if (screen_mask & menubutton_info[i].screen_mask)
6186 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6189 void MapScreenTreeGadgets(TreeInfo *ti)
6191 int num_entries = numTreeInfoInGroup(ti);
6194 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6197 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6198 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6200 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6201 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6204 static void HandleScreenGadgets(struct GadgetInfo *gi)
6206 int id = gi->custom_id;
6207 int button = gi->event.button;
6208 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6212 case SCREEN_CTRL_ID_PREV_LEVEL:
6213 HandleMainMenu_SelectLevel(step, -1);
6216 case SCREEN_CTRL_ID_NEXT_LEVEL:
6217 HandleMainMenu_SelectLevel(step, +1);
6220 case SCREEN_CTRL_ID_PREV_PLAYER:
6221 HandleSetupScreen_Input_Player(step, -1);
6224 case SCREEN_CTRL_ID_NEXT_PLAYER:
6225 HandleSetupScreen_Input_Player(step, +1);
6228 case SCREEN_CTRL_ID_SCROLL_UP:
6229 if (game_status == GAME_MODE_LEVELS)
6230 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6231 else if (game_status == GAME_MODE_LEVELNR)
6232 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6233 else if (game_status == GAME_MODE_SETUP)
6234 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6237 case SCREEN_CTRL_ID_SCROLL_DOWN:
6238 if (game_status == GAME_MODE_LEVELS)
6239 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6240 else if (game_status == GAME_MODE_LEVELNR)
6241 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6242 else if (game_status == GAME_MODE_SETUP)
6243 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6246 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6247 if (game_status == GAME_MODE_LEVELS)
6248 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6249 else if (game_status == GAME_MODE_LEVELNR)
6250 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6251 else if (game_status == GAME_MODE_SETUP)
6252 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);