1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT 4
33 #define SETUP_MODE_GRAPHICS 5
34 #define SETUP_MODE_SOUND 6
35 #define SETUP_MODE_ARTWORK 7
36 #define SETUP_MODE_CHOOSE_GRAPHICS 8
37 #define SETUP_MODE_CHOOSE_SOUNDS 9
38 #define SETUP_MODE_CHOOSE_MUSIC 10
40 #define MAX_SETUP_MODES 11
42 /* for input setup functions */
43 #define SETUPINPUT_SCREEN_POS_START 0
44 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
45 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
46 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
48 /* screens on the info screen */
49 #define INFO_MODE_MAIN 0
50 #define INFO_MODE_ELEMENTS 1
51 #define INFO_MODE_MUSIC 2
52 #define INFO_MODE_CREDITS 3
53 #define INFO_MODE_PROGRAM 4
55 #define MAX_INFO_MODES 5
57 /* for various menu stuff */
58 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
59 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
60 #define MENU_SCREEN_START_YPOS 2
61 #define MENU_SCREEN_VALUE_XPOS 14
63 /* buttons and scrollbars identifiers */
64 #define SCREEN_CTRL_ID_SCROLL_UP 0
65 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
66 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
68 #define NUM_SCREEN_SCROLLBUTTONS 2
69 #define NUM_SCREEN_SCROLLBARS 1
70 #define NUM_SCREEN_GADGETS 3
72 /* forward declarations of internal functions */
73 static void HandleScreenGadgets(struct GadgetInfo *);
74 static void HandleSetupScreen_Generic(int, int, int, int, int);
75 static void HandleSetupScreen_Input(int, int, int, int, int);
76 static void CustomizeKeyboard(int);
77 static void CalibrateJoystick(int);
78 static void execSetupArtwork(void);
79 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
81 static void DrawChooseLevel(void);
82 static void DrawInfoScreen(void);
83 static void DrawSetupScreen(void);
85 static void DrawInfoScreen_HelpAnim(int, int, boolean);
86 static void DrawInfoScreen_HelpText(int, int, int, int);
87 static void HandleInfoScreen_Main(int, int, int, int, int);
88 static void HandleInfoScreen_Elements(int);
89 static void HandleInfoScreen_Music(int);
90 static void HandleInfoScreen_Credits(int);
91 static void HandleInfoScreen_Program(int);
93 static void MapChooseTreeGadgets(TreeInfo *);
95 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
96 static int setup_mode = SETUP_MODE_MAIN;
97 static int info_mode = INFO_MODE_MAIN;
99 #define mSX (SX + (game_status >= GAME_MODE_MAIN && \
100 game_status <= GAME_MODE_SETUP ? \
101 menu.draw_xoffset[game_status] : menu.draw_xoffset_default))
102 #define mSY (SY + (game_status >= GAME_MODE_MAIN && \
103 game_status <= GAME_MODE_SETUP ? \
104 menu.draw_yoffset[game_status] : menu.draw_yoffset_default))
106 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
107 menu.list_size[game_status] : \
108 MAX_MENU_ENTRIES_ON_SCREEN)
110 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
111 #define NUM_SCROLLBAR_BITMAPS 2
112 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
116 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
118 static int cursor_array[SCR_FIELDY];
123 cursor_array[ypos] = graphic;
125 graphic = cursor_array[ypos];
129 graphic = (graphic == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
130 graphic == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE:
131 IMG_MENU_BUTTON_ACTIVE);
133 ypos += MENU_SCREEN_START_YPOS;
135 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
136 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY,
140 static void initCursor(int ypos, int graphic)
142 drawCursorExt(0, ypos, FC_BLUE, graphic);
145 static void drawCursor(int ypos, int color)
147 drawCursorExt(0, ypos, color, 0);
150 static void drawCursorXY(int xpos, int ypos, int graphic)
152 drawCursorExt(xpos, ypos, -1, graphic);
155 static void drawChooseTreeCursor(int ypos, int color)
157 int last_game_status = game_status; /* save current game status */
159 /* force LEVELS draw offset on artwork setup screen */
160 game_status = GAME_MODE_LEVELS;
162 drawCursorExt(0, ypos, color, 0);
164 game_status = last_game_status; /* restore current game status */
167 static void PlayMenuSound()
169 int sound = menu.sound[game_status];
171 if (sound == SND_UNDEFINED)
174 if (sound_info[sound].loop)
175 PlaySoundLoop(sound);
180 static void PlayMenuSoundIfLoop()
182 int sound = menu.sound[game_status];
184 if (sound == SND_UNDEFINED)
187 if (sound_info[sound].loop)
188 PlaySoundLoop(sound);
191 static void PlayMenuMusic()
193 int music = menu.music[game_status];
195 if (music == MUS_UNDEFINED)
203 int text1_width = getTextWidth(PROGRAM_TITLE_STRING, FONT_TITLE_1);
204 int text2_width = getTextWidth(PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2);
205 int x1 = SX + (SXSIZE - text1_width) / 2;
206 int x2 = SX + (SXSIZE - text2_width) / 2;
208 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
209 DrawText(x2, SY + 46, PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2);
212 static void ToggleFullscreenIfNeeded()
214 if (setup.fullscreen != video.fullscreen_enabled)
216 /* save old door content */
217 BlitBitmap(backbuffer, bitmap_db_door,
218 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
220 /* toggle fullscreen */
221 ChangeVideoModeIfNeeded(setup.fullscreen);
222 setup.fullscreen = video.fullscreen_enabled;
224 /* redraw background to newly created backbuffer */
225 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
226 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
228 /* restore old door content */
229 BlitBitmap(bitmap_db_door, backbuffer,
230 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
232 redraw_mask = REDRAW_ALL;
238 static LevelDirTree *leveldir_last_valid = NULL;
239 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
240 int name_width = getTextWidth("Name:", FONT_MENU_1);
241 int level_width = getTextWidth("Level:", FONT_MENU_1);
245 FadeSoundsAndMusic();
247 KeyboardAutoRepeatOn();
250 SetDrawDeactivationMask(REDRAW_NONE);
251 SetDrawBackgroundMask(REDRAW_FIELD);
253 audio.sound_deactivated = FALSE;
255 /* needed if last screen was the playing screen, invoked from level editor */
256 if (level_editor_test_game)
258 game_status = GAME_MODE_EDITOR;
264 /* needed if last screen was the editor screen */
265 UndrawSpecialEditorDoor();
267 /* needed if last screen was the setup screen and fullscreen state changed */
268 ToggleFullscreenIfNeeded();
270 /* leveldir_current may be invalid (level group, parent link) */
271 if (!validLevelSeries(leveldir_current))
272 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
274 /* store valid level series information */
275 leveldir_last_valid = leveldir_current;
277 /* needed if last screen (level choice) changed graphics, sounds or music */
278 ReloadCustomArtwork();
281 SetDrawtoField(DRAW_BACKBUFFER);
284 /* map gadgets for main menu screen */
287 /* level_nr may have been set to value over handicap with level editor */
288 if (setup.handicap && level_nr > leveldir_current->handicap_level)
289 level_nr = leveldir_current->handicap_level;
294 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
299 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
300 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
301 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
302 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
303 DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
304 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
305 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
306 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
308 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
309 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
312 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
314 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
315 leveldir_current->first_level, leveldir_current->last_level);
317 if (leveldir_current->readonly)
319 DrawTextS(mSX + level_width + 9 * 32 - 2,
320 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
321 DrawTextS(mSX + level_width + 9 * 32 - 2,
322 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
325 for (i = 0; i < 8; i++)
326 initCursor(i, (i == 1 || i == 6 ? IMG_MENU_BUTTON_RIGHT :IMG_MENU_BUTTON));
328 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
329 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
331 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
336 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
339 if (TAPE_IS_EMPTY(tape))
341 DrawCompleteVideoDisplay();
346 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
349 static void gotoTopLevelDir()
351 /* move upwards to top level directory */
352 while (leveldir_current->node_parent)
354 /* write a "path" into level tree for easy navigation to last level */
355 if (leveldir_current->node_parent->node_group->cl_first == -1)
357 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
358 int leveldir_pos = posTreeInfo(leveldir_current);
359 int num_page_entries;
360 int cl_first, cl_cursor;
362 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
363 num_page_entries = num_leveldirs;
365 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
367 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
368 cl_cursor = leveldir_pos - cl_first;
370 leveldir_current->node_parent->node_group->cl_first = cl_first;
371 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
374 leveldir_current = leveldir_current->node_parent;
378 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
380 static int choice = 5;
384 if (button == MB_MENU_INITIALIZE)
386 drawCursor(choice, FC_RED);
390 if (mx || my) /* mouse input */
393 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
395 else if (dx || dy) /* keyboard input */
397 if (dx && choice == 1)
398 x = (dx < 0 ? 10 : 14);
403 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
404 (x == 14 && level_nr < leveldir_current->last_level)) &&
407 static unsigned long level_delay = 0;
408 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
409 int old_level_nr = level_nr;
412 new_level_nr = level_nr + (x == 10 ? -step : +step);
413 if (new_level_nr < leveldir_current->first_level)
414 new_level_nr = leveldir_current->first_level;
415 if (new_level_nr > leveldir_current->last_level)
416 new_level_nr = leveldir_current->last_level;
418 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
419 new_level_nr = leveldir_current->handicap_level;
421 if (new_level_nr != old_level_nr &&
422 DelayReached(&level_delay, GADGET_FRAME_DELAY))
424 level_nr = new_level_nr;
426 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
430 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
434 DrawCompleteVideoDisplay();
436 /* needed because DrawMicroLevel() takes some time */
439 DelayReached(&level_delay, 0); /* reset delay counter */
442 else if (IN_GFX_SCREEN(mx, my) &&
443 y >= 0 && y <= 7 && (y != 1 || x < 10))
449 drawCursor(y, FC_RED);
450 drawCursor(choice, FC_BLUE);
458 game_status = GAME_MODE_PSEUDO_TYPENAME;
459 HandleTypeName(strlen(setup.player_name), 0);
465 game_status = GAME_MODE_LEVELS;
466 SaveLevelSetup_LastSeries();
467 SaveLevelSetup_SeriesInfo();
476 game_status = GAME_MODE_SCORES;
481 if (leveldir_current->readonly &&
482 strcmp(setup.player_name, "Artsoft") != 0)
483 Request("This level is read only !", REQ_CONFIRM);
484 game_status = GAME_MODE_EDITOR;
489 game_status = GAME_MODE_INFO;
490 info_mode = INFO_MODE_MAIN;
495 if (setup.autorecord)
496 TapeStartRecording();
498 #if defined(PLATFORM_UNIX)
500 SendToServer_StartPlaying();
504 game_status = GAME_MODE_PLAYING;
511 game_status = GAME_MODE_SETUP;
512 setup_mode = SETUP_MODE_MAIN;
517 SaveLevelSetup_LastSeries();
518 SaveLevelSetup_SeriesInfo();
519 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
520 game_status = GAME_MODE_QUIT;
525 if (game_status == GAME_MODE_MAIN)
527 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
533 /* ========================================================================= */
534 /* info screen functions */
535 /* ========================================================================= */
537 static struct TokenInfo *info_info;
538 static int num_info_info;
540 static void execInfoElements()
542 info_mode = INFO_MODE_ELEMENTS;
546 static void execInfoMusic()
548 info_mode = INFO_MODE_MUSIC;
552 static void execInfoCredits()
554 info_mode = INFO_MODE_CREDITS;
558 static void execInfoProgram()
560 info_mode = INFO_MODE_PROGRAM;
564 static void execExitInfo()
566 game_status = GAME_MODE_MAIN;
570 static struct TokenInfo info_info_main[] =
572 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
573 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
574 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
575 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
576 { TYPE_EMPTY, NULL, "" },
577 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
582 static void DrawInfoScreen_Main()
587 CloseDoor(DOOR_CLOSE_2);
591 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
593 info_info = info_info_main;
596 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
598 int ypos = MENU_SCREEN_START_YPOS + i;
599 int font_nr = FONT_MENU_1;
601 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
603 if (info_info[i].type & TYPE_ENTER_MENU)
604 initCursor(i, IMG_MENU_BUTTON_RIGHT);
605 else if (info_info[i].type & TYPE_LEAVE_MENU)
606 initCursor(i, IMG_MENU_BUTTON_LEFT);
607 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
608 initCursor(i, IMG_MENU_BUTTON);
619 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
622 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
624 static int choice_store[MAX_INFO_MODES];
625 int choice = choice_store[info_mode]; /* always starts with 0 */
629 if (button == MB_MENU_INITIALIZE)
631 /* advance to first valid menu entry */
632 while (choice < num_info_info &&
633 info_info[choice].type & TYPE_SKIP_ENTRY)
635 choice_store[info_mode] = choice;
637 drawCursor(choice, FC_RED);
640 else if (button == MB_MENU_LEAVE)
642 for (y = 0; y < num_info_info; y++)
644 if (info_info[y].type & TYPE_LEAVE_MENU)
646 void (*menu_callback_function)(void) = info_info[y].value;
648 menu_callback_function();
649 break; /* absolutely needed because function changes 'info_info'! */
656 if (mx || my) /* mouse input */
659 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
661 else if (dx || dy) /* keyboard input */
665 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
667 if (info_info[choice].type & menu_navigation_type ||
668 info_info[choice].type & TYPE_ENTER_SCREEN ||
669 info_info[choice].type & TYPE_BOOLEAN_STYLE)
670 button = MB_MENU_CHOICE;
675 /* jump to next non-empty menu entry (up or down) */
676 while (y > 0 && y < num_info_info - 1 &&
677 info_info[y].type & TYPE_SKIP_ENTRY)
681 if (IN_GFX_SCREEN(mx, my) &&
682 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
688 drawCursor(y, FC_RED);
689 drawCursor(choice, FC_BLUE);
690 choice = choice_store[info_mode] = y;
693 else if (!(info_info[y].type & TYPE_GHOSTED))
695 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
697 void (*menu_callback_function)(void) = info_info[choice].value;
699 menu_callback_function();
705 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
707 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
708 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
709 int xstart = mSX + 16;
710 int ystart = mSY + 64 + 2 * 32;
711 int ystep = TILEY + 4;
712 int element, action, direction;
720 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
721 infoscreen_step[i] = infoscreen_frame[i] = 0;
723 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
727 DrawTextSCentered(100, FONT_TEXT_1, "The game elements:");
729 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
730 "Press any key or button for next page");
736 while (helpanim_info[j].element != HELPANIM_LIST_END)
738 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
743 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
752 j += infoscreen_step[i - start];
754 element = helpanim_info[j].element;
755 action = helpanim_info[j].action;
756 direction = helpanim_info[j].direction;
758 if (action != -1 && direction != -1)
759 graphic = el_act_dir2img(element, action, direction);
760 else if (action != -1)
761 graphic = el_act2img(element, action);
762 else if (direction != -1)
763 graphic = el_act2img(element, direction);
765 graphic = el2img(element);
767 delay = helpanim_info[j++].delay;
772 if (infoscreen_frame[i - start] == 0)
775 infoscreen_frame[i - start] = delay - 1;
779 sync_frame = delay - infoscreen_frame[i - start];
780 infoscreen_frame[i - start]--;
783 if (helpanim_info[j].element == -1)
785 if (!infoscreen_frame[i - start])
786 infoscreen_step[i - start] = 0;
790 if (!infoscreen_frame[i - start])
791 infoscreen_step[i - start]++;
792 while (helpanim_info[j].element != -1)
798 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
800 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
801 graphic, sync_frame, USE_MASKING);
804 DrawInfoScreen_HelpText(element, action, direction, i - start);
809 redraw_mask |= REDRAW_FIELD;
814 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
816 int font_nr = FONT_TEXT_2;
817 int max_chars_per_line = 34;
818 int max_lines_per_text = 2;
820 int sy = mSY + 65 + 2 * 32 + 1;
821 int ystep = TILEY + 4;
824 /* 1st try: get text for base element */
825 text = getHashEntry(helptext_info, element_info[element].token_name);
829 /* 2nd try: get text for element/action/direction */
830 char token[MAX_LINE_LEN];
832 strcpy(token, element_info[element].token_name);
835 strcat(token, element_action_info[action].suffix);
838 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
840 text = getHashEntry(helptext_info, token);
843 text = "No description available";
846 if (strlen(text) <= max_chars_per_line) /* only one line of text */
847 sy += getFontHeight(font_nr) / 2;
849 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
850 max_chars_per_line, max_lines_per_text);
853 void DrawInfoScreen_Elements()
858 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
864 void HandleInfoScreen_Elements(int button)
866 static unsigned long info_delay = 0;
867 static int num_anims;
868 static int num_pages;
870 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
871 int button_released = !button;
874 if (button == MB_MENU_INITIALIZE)
876 boolean new_element = TRUE;
879 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
881 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
883 else if (new_element)
890 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
893 else if (button == MB_MENU_LEAVE)
895 info_mode = INFO_MODE_MAIN;
901 if (button_released || button == MB_MENU_INITIALIZE)
903 if (button != MB_MENU_INITIALIZE)
906 if (page >= num_pages)
908 FadeSoundsAndMusic();
910 info_mode = INFO_MODE_MAIN;
916 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
920 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
921 if (page < num_pages)
922 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
924 PlayMenuSoundIfLoop();
928 void DrawInfoScreen_Music()
935 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
938 void HandleInfoScreen_Music(int button)
940 static struct MusicFileInfo *list = NULL;
941 int ystart = 150, ystep = 30;
942 int ybottom = SYSIZE - 20;
943 int button_released = !button;
945 if (button == MB_MENU_INITIALIZE)
947 list = music_file_info;
951 FadeSoundsAndMusic();
956 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
958 DrawTextSCentered(ybottom, FONT_TEXT_4,
959 "Press any key or button for info menu");
964 else if (button == MB_MENU_LEAVE)
966 info_mode = INFO_MODE_MAIN;
972 if (button_released || button == MB_MENU_INITIALIZE)
976 info_mode = INFO_MODE_MAIN;
982 FadeSoundsAndMusic();
987 DrawTextSCentered(100, FONT_TEXT_1, "The game background music:");
989 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
990 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "\"%s\"", list->title);
991 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
992 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "%s", list->artist);
993 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
994 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3, "\"%s\"", list->album);
996 DrawTextSCentered(ybottom, FONT_TEXT_4,
997 "Press any key or button for next page");
999 PlayMusic(list->music);
1005 void DrawInfoScreen_Credits()
1007 int ystart = 150, ystep = 30;
1008 int ybottom = SYSIZE - 20;
1010 FadeSoundsAndMusic();
1015 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1016 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1017 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1018 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1019 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1020 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1021 "...and many thanks to all contributors");
1022 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1024 DrawTextSCentered(ybottom, FONT_TEXT_4,
1025 "Press any key or button for info menu");
1028 void HandleInfoScreen_Credits(int button)
1030 int button_released = !button;
1032 if (button == MB_MENU_LEAVE)
1034 info_mode = INFO_MODE_MAIN;
1040 if (button_released)
1042 FadeSoundsAndMusic();
1044 info_mode = INFO_MODE_MAIN;
1049 PlayMenuSoundIfLoop();
1053 void DrawInfoScreen_Program()
1055 int ystart = 150, ystep = 30;
1056 int ybottom = SYSIZE - 20;
1061 DrawTextSCentered(100, FONT_TEXT_1, "Program information:");
1063 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1064 "This game is Freeware!");
1065 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1066 "If you like it, send e-mail to:");
1067 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1068 "info@artsoft.org");
1069 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1070 "or SnailMail to:");
1071 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1073 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1074 "Detmolder Strasse 189");
1075 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1077 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1080 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1081 "If you have created new levels,");
1082 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1083 "send them to me to include them!");
1084 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1087 DrawTextSCentered(ybottom, FONT_TEXT_4,
1088 "Press any key or button for info menu");
1091 void HandleInfoScreen_Program(int button)
1093 int button_released = !button;
1095 if (button == MB_MENU_LEAVE)
1097 info_mode = INFO_MODE_MAIN;
1103 if (button_released)
1105 FadeSoundsAndMusic();
1107 info_mode = INFO_MODE_MAIN;
1112 PlayMenuSoundIfLoop();
1116 void DrawInfoScreen()
1118 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1120 if (info_mode == INFO_MODE_ELEMENTS)
1121 DrawInfoScreen_Elements();
1122 else if (info_mode == INFO_MODE_MUSIC)
1123 DrawInfoScreen_Music();
1124 else if (info_mode == INFO_MODE_CREDITS)
1125 DrawInfoScreen_Credits();
1126 else if (info_mode == INFO_MODE_PROGRAM)
1127 DrawInfoScreen_Program();
1129 DrawInfoScreen_Main();
1131 if (info_mode != INFO_MODE_MUSIC)
1138 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1140 if (info_mode == INFO_MODE_ELEMENTS)
1141 HandleInfoScreen_Elements(button);
1142 else if (info_mode == INFO_MODE_MUSIC)
1143 HandleInfoScreen_Music(button);
1144 else if (info_mode == INFO_MODE_CREDITS)
1145 HandleInfoScreen_Credits(button);
1146 else if (info_mode == INFO_MODE_PROGRAM)
1147 HandleInfoScreen_Program(button);
1149 HandleInfoScreen_Main(mx, my, dx, dy, button);
1155 /* ========================================================================= */
1156 /* type name functions */
1157 /* ========================================================================= */
1159 void HandleTypeName(int newxpos, Key key)
1161 static int xpos = 0, ypos = 2;
1162 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1163 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1164 int startx = mSX + 32 + name_width;
1165 int starty = mSY + ypos * 32;
1171 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1172 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1177 if (((key >= KSYM_A && key <= KSYM_Z) ||
1178 (key >= KSYM_a && key <= KSYM_z)) &&
1179 xpos < MAX_PLAYER_NAME_LEN)
1183 if (key >= KSYM_A && key <= KSYM_Z)
1184 ascii = 'A' + (char)(key - KSYM_A);
1186 ascii = 'a' + (char)(key - KSYM_a);
1188 setup.player_name[xpos] = ascii;
1189 setup.player_name[xpos + 1] = 0;
1192 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1193 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1195 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1198 setup.player_name[xpos] = 0;
1200 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1202 else if (key == KSYM_Return && xpos > 0)
1204 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1205 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1208 game_status = GAME_MODE_MAIN;
1213 /* ========================================================================= */
1214 /* tree menu functions */
1215 /* ========================================================================= */
1217 static void DrawChooseTree(TreeInfo **ti_ptr)
1221 FreeScreenGadgets();
1222 CreateScreenGadgets();
1224 CloseDoor(DOOR_CLOSE_2);
1228 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1229 MapChooseTreeGadgets(*ti_ptr);
1235 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1237 struct GadgetInfo *gi = screen_gadget[id];
1238 int items_max, items_visible, item_position;
1240 items_max = numTreeInfoInGroup(ti);
1241 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1242 item_position = first_entry;
1244 if (item_position > items_max - items_visible)
1245 item_position = items_max - items_visible;
1247 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1248 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1249 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1252 static void drawChooseTreeList(int first_entry, int num_page_entries,
1256 char buffer[SCR_FIELDX * 2];
1257 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1258 char *title_string = NULL;
1259 int xoffset_setup = 16;
1260 int yoffset_setup = 16;
1261 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1262 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1263 int last_game_status = game_status; /* save current game status */
1266 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1267 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1268 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1269 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1271 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1273 /* force LEVELS font on artwork setup screen */
1274 game_status = GAME_MODE_LEVELS;
1276 /* clear tree list area, but not title or scrollbar */
1277 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1278 SXSIZE - 32 + menu.scrollbar_xoffset,
1279 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1281 for (i = 0; i < num_page_entries; i++)
1283 TreeInfo *node, *node_first;
1284 int entry_pos = first_entry + i;
1285 int ypos = MENU_SCREEN_START_YPOS + i;
1287 node_first = getTreeInfoFirstGroupEntry(ti);
1288 node = getTreeInfoFromPos(node_first, entry_pos);
1290 strncpy(buffer, node->name , max_buffer_len);
1291 buffer[max_buffer_len] = '\0';
1293 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1295 if (node->parent_link)
1296 initCursor(i, IMG_MENU_BUTTON_LEFT);
1297 else if (node->level_group)
1298 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1300 initCursor(i, IMG_MENU_BUTTON);
1303 game_status = last_game_status; /* restore current game status */
1305 redraw_mask |= REDRAW_FIELD;
1308 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1310 TreeInfo *node, *node_first;
1311 int x, last_redraw_mask = redraw_mask;
1313 if (ti->type != TREE_TYPE_LEVEL_DIR)
1316 node_first = getTreeInfoFirstGroupEntry(ti);
1317 node = getTreeInfoFromPos(node_first, entry_pos);
1319 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1321 if (node->parent_link)
1322 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1324 else if (node->level_group)
1325 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1327 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1328 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1329 node->levels, node->class_desc);
1331 /* let BackToFront() redraw only what is needed */
1332 redraw_mask = last_redraw_mask | REDRAW_TILES;
1333 for (x = 0; x < SCR_FIELDX; x++)
1334 MarkTileDirty(x, 1);
1337 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1340 TreeInfo *ti = *ti_ptr;
1342 int y = ti->cl_cursor;
1343 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1344 int num_entries = numTreeInfoInGroup(ti);
1345 int num_page_entries;
1346 int last_game_status = game_status; /* save current game status */
1348 /* force LEVELS draw offset on choose level and artwork setup screen */
1349 game_status = GAME_MODE_LEVELS;
1351 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1352 num_page_entries = num_entries;
1354 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1356 game_status = last_game_status; /* restore current game status */
1358 if (button == MB_MENU_INITIALIZE)
1360 int num_entries = numTreeInfoInGroup(ti);
1361 int entry_pos = posTreeInfo(ti);
1363 if (ti->cl_first == -1)
1365 /* only on initialization */
1366 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1367 ti->cl_cursor = entry_pos - ti->cl_first;
1369 else if (ti->cl_cursor >= num_page_entries ||
1370 (num_entries > num_page_entries &&
1371 num_entries - ti->cl_first < num_page_entries))
1373 /* only after change of list size (by custom graphic configuration) */
1374 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1375 ti->cl_cursor = entry_pos - ti->cl_first;
1378 if (dx == 999) /* first entry is set by scrollbar position */
1381 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1384 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1385 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1386 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1390 else if (button == MB_MENU_LEAVE)
1392 if (ti->node_parent)
1394 *ti_ptr = ti->node_parent;
1395 DrawChooseTree(ti_ptr);
1397 else if (game_status == GAME_MODE_SETUP)
1403 game_status = GAME_MODE_MAIN;
1410 if (mx || my) /* mouse input */
1412 int last_game_status = game_status; /* save current game status */
1414 /* force LEVELS draw offset on artwork setup screen */
1415 game_status = GAME_MODE_LEVELS;
1417 x = (mx - mSX) / 32;
1418 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1420 game_status = last_game_status; /* restore current game status */
1422 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1424 /* move cursor instead of scrolling when already at start/end of list */
1425 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1427 else if (dy == +1 * SCROLL_LINE &&
1428 ti->cl_first + num_page_entries == num_entries)
1431 /* handle scrolling screen one line or page */
1432 if (ti->cl_cursor + dy < 0 ||
1433 ti->cl_cursor + dy > num_page_entries - 1)
1435 if (ABS(dy) == SCROLL_PAGE)
1436 step = num_page_entries - 1;
1438 if (dy < 0 && ti->cl_first > 0)
1440 /* scroll page/line up */
1442 ti->cl_first -= step;
1443 if (ti->cl_first < 0)
1446 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1447 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1448 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1449 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1452 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1454 /* scroll page/line down */
1456 ti->cl_first += step;
1457 if (ti->cl_first + num_page_entries > num_entries)
1458 ti->cl_first = MAX(0, num_entries - num_page_entries);
1460 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1461 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1462 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1463 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1470 /* handle moving cursor one line */
1471 y = ti->cl_cursor + dy;
1476 TreeInfo *node_first, *node_cursor;
1477 int entry_pos = ti->cl_first + y;
1479 node_first = getTreeInfoFirstGroupEntry(ti);
1480 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1482 if (node_cursor->node_group)
1484 node_cursor->cl_first = ti->cl_first;
1485 node_cursor->cl_cursor = ti->cl_cursor;
1486 *ti_ptr = node_cursor->node_group;
1487 DrawChooseTree(ti_ptr);
1492 else if (dx == -1 && ti->node_parent)
1494 *ti_ptr = ti->node_parent;
1495 DrawChooseTree(ti_ptr);
1500 if (IN_GFX_SCREEN(mx, my) &&
1501 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1502 y >= 0 && y < num_page_entries)
1506 if (y != ti->cl_cursor)
1508 drawChooseTreeCursor(y, FC_RED);
1509 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1510 drawChooseTreeInfo(ti->cl_first + y, ti);
1516 TreeInfo *node_first, *node_cursor;
1517 int entry_pos = ti->cl_first + y;
1519 node_first = getTreeInfoFirstGroupEntry(ti);
1520 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1522 if (node_cursor->node_group)
1524 node_cursor->cl_first = ti->cl_first;
1525 node_cursor->cl_cursor = ti->cl_cursor;
1526 *ti_ptr = node_cursor->node_group;
1527 DrawChooseTree(ti_ptr);
1529 else if (node_cursor->parent_link)
1531 *ti_ptr = node_cursor->node_parent;
1532 DrawChooseTree(ti_ptr);
1536 node_cursor->cl_first = ti->cl_first;
1537 node_cursor->cl_cursor = ti->cl_cursor;
1538 *ti_ptr = node_cursor;
1540 if (ti->type == TREE_TYPE_LEVEL_DIR)
1542 LoadLevelSetup_SeriesInfo();
1544 SaveLevelSetup_LastSeries();
1545 SaveLevelSetup_SeriesInfo();
1549 if (game_status == GAME_MODE_SETUP)
1555 game_status = GAME_MODE_MAIN;
1563 void DrawChooseLevel()
1565 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1567 DrawChooseTree(&leveldir_current);
1573 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1575 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1580 void DrawHallOfFame(int highlight_position)
1583 FadeSoundsAndMusic();
1584 CloseDoor(DOOR_CLOSE_2);
1586 if (highlight_position < 0)
1587 LoadScore(level_nr);
1595 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1598 static void drawHallOfFameList(int first_entry, int highlight_position)
1602 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1605 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1606 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1608 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1610 int entry = first_entry + i;
1611 boolean active = (entry == highlight_position);
1612 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1613 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1614 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1615 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1616 int dx1 = 3 * getFontWidth(font_nr1);
1617 int dx2 = dx1 + getFontWidth(font_nr1);
1618 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1619 int sy = mSY + 64 + i * 32;
1621 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1622 DrawText(mSX + dx1, sy, ".", font_nr1);
1623 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1624 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1625 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1626 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1629 redraw_mask |= REDRAW_FIELD;
1632 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1634 static int first_entry = 0;
1635 static int highlight_position = 0;
1636 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1637 int button_released = !button;
1639 if (button == MB_MENU_INITIALIZE)
1642 highlight_position = mx;
1643 drawHallOfFameList(first_entry, highlight_position);
1648 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1649 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1653 if (first_entry > 0)
1655 first_entry -= step;
1656 if (first_entry < 0)
1659 drawHallOfFameList(first_entry, highlight_position);
1664 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1666 first_entry += step;
1667 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1668 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1670 drawHallOfFameList(first_entry, highlight_position);
1673 else if (button_released)
1675 FadeSound(SND_BACKGROUND_SCORES);
1676 game_status = GAME_MODE_MAIN;
1680 if (game_status == GAME_MODE_SCORES)
1681 PlayMenuSoundIfLoop();
1687 /* ========================================================================= */
1688 /* setup screen functions */
1689 /* ========================================================================= */
1691 static struct TokenInfo *setup_info;
1692 static int num_setup_info;
1694 static char *graphics_set_name;
1695 static char *sounds_set_name;
1696 static char *music_set_name;
1698 static void execSetupMain()
1700 setup_mode = SETUP_MODE_MAIN;
1704 static void execSetupGame()
1706 setup_mode = SETUP_MODE_GAME;
1710 static void execSetupEditor()
1712 setup_mode = SETUP_MODE_EDITOR;
1716 static void execSetupGraphics()
1718 setup_mode = SETUP_MODE_GRAPHICS;
1722 static void execSetupSound()
1724 setup_mode = SETUP_MODE_SOUND;
1728 static void execSetupArtwork()
1730 setup.graphics_set = artwork.gfx_current->identifier;
1731 setup.sounds_set = artwork.snd_current->identifier;
1732 setup.music_set = artwork.mus_current->identifier;
1734 /* needed if last screen (setup choice) changed graphics, sounds or music */
1735 ReloadCustomArtwork();
1737 /* needed for displaying artwork name instead of artwork identifier */
1738 graphics_set_name = artwork.gfx_current->name;
1739 sounds_set_name = artwork.snd_current->name;
1740 music_set_name = artwork.mus_current->name;
1742 setup_mode = SETUP_MODE_ARTWORK;
1746 static void execSetupChooseGraphics()
1748 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1752 static void execSetupChooseSounds()
1754 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1758 static void execSetupChooseMusic()
1760 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1764 static void execSetupInput()
1766 setup_mode = SETUP_MODE_INPUT;
1770 static void execSetupShortcut()
1772 setup_mode = SETUP_MODE_SHORTCUT;
1776 static void execExitSetup()
1778 game_status = GAME_MODE_MAIN;
1782 static void execSaveAndExitSetup()
1788 static struct TokenInfo setup_info_main[] =
1790 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1791 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1792 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1793 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1794 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1795 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1796 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1797 { TYPE_EMPTY, NULL, "" },
1798 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1799 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1804 static struct TokenInfo setup_info_game[] =
1806 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1807 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1808 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1809 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1810 { TYPE_EMPTY, NULL, "" },
1811 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1816 static struct TokenInfo setup_info_editor[] =
1818 { TYPE_STRING, NULL, "Offer Special Elements:"},
1819 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1820 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1821 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1822 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1823 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1824 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1825 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1826 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1827 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1828 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1829 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1830 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1831 { TYPE_EMPTY, NULL, "" },
1832 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1837 static struct TokenInfo setup_info_graphics[] =
1839 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1840 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1841 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1843 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1844 { TYPE_SWITCH, &setup.fading, "Fading:" },
1846 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1847 { TYPE_SWITCH, &setup.toons, "Toons:" },
1848 { TYPE_EMPTY, NULL, "" },
1849 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1854 static struct TokenInfo setup_info_sound[] =
1856 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1857 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1858 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1859 { TYPE_EMPTY, NULL, "" },
1860 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1865 static struct TokenInfo setup_info_artwork[] =
1867 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1868 { TYPE_STRING, &graphics_set_name, "" },
1869 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1870 { TYPE_STRING, &sounds_set_name, "" },
1871 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1872 { TYPE_STRING, &music_set_name, "" },
1873 { TYPE_EMPTY, NULL, "" },
1874 { TYPE_STRING, NULL, "Override Level Artwork:"},
1875 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1876 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1877 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1878 { TYPE_EMPTY, NULL, "" },
1879 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1884 static struct TokenInfo setup_info_shortcut[] =
1886 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1887 { TYPE_KEY, &setup.shortcut.save_game, "" },
1888 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1889 { TYPE_KEY, &setup.shortcut.load_game, "" },
1890 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1891 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1892 { TYPE_EMPTY, NULL, "" },
1893 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1894 { TYPE_EMPTY, NULL, "" },
1895 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1900 static Key getSetupKey()
1902 Key key = KSYM_UNDEFINED;
1903 boolean got_key_event = FALSE;
1905 while (!got_key_event)
1907 if (PendingEvent()) /* got event */
1915 case EVENT_KEYPRESS:
1917 key = GetEventKey((KeyEvent *)&event, TRUE);
1919 /* press 'Escape' or 'Enter' to keep the existing key binding */
1920 if (key == KSYM_Escape || key == KSYM_Return)
1921 key = KSYM_UNDEFINED; /* keep old value */
1923 got_key_event = TRUE;
1927 case EVENT_KEYRELEASE:
1928 key_joystick_mapping = 0;
1932 HandleOtherEvents(&event);
1940 /* don't eat all CPU time */
1947 static void drawSetupValue(int pos)
1949 int xpos = MENU_SCREEN_VALUE_XPOS;
1950 int ypos = MENU_SCREEN_START_YPOS + pos;
1951 int font_nr = FONT_VALUE_1;
1952 int type = setup_info[pos].type;
1953 void *value = setup_info[pos].value;
1954 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
1957 if (value_string == NULL)
1960 if (type & TYPE_KEY)
1964 if (type & TYPE_QUERY)
1966 value_string = "<press key>";
1967 font_nr = FONT_INPUT_1_ACTIVE;
1970 else if (type & TYPE_STRING)
1972 int max_value_len = (SCR_FIELDX - 2) * 2;
1975 font_nr = FONT_VALUE_2;
1977 if (strlen(value_string) > max_value_len)
1978 value_string[max_value_len] = '\0';
1980 else if (type & TYPE_BOOLEAN_STYLE)
1982 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
1985 DrawText(mSX + xpos * 32, mSY + ypos * 32,
1986 (xpos == 3 ? " " : " "), font_nr);
1987 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
1990 static void changeSetupValue(int pos)
1992 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
1994 *(boolean *)setup_info[pos].value ^= TRUE;
1996 else if (setup_info[pos].type & TYPE_KEY)
2000 setup_info[pos].type |= TYPE_QUERY;
2001 drawSetupValue(pos);
2002 setup_info[pos].type &= ~TYPE_QUERY;
2004 key = getSetupKey();
2005 if (key != KSYM_UNDEFINED)
2006 *(Key *)setup_info[pos].value = key;
2009 drawSetupValue(pos);
2012 static void DrawSetupScreen_Generic()
2014 char *title_string = NULL;
2018 CloseDoor(DOOR_CLOSE_2);
2022 if (setup_mode == SETUP_MODE_MAIN)
2024 setup_info = setup_info_main;
2025 title_string = "Setup";
2027 else if (setup_mode == SETUP_MODE_GAME)
2029 setup_info = setup_info_game;
2030 title_string = "Setup Game";
2032 else if (setup_mode == SETUP_MODE_EDITOR)
2034 setup_info = setup_info_editor;
2035 title_string = "Setup Editor";
2037 else if (setup_mode == SETUP_MODE_GRAPHICS)
2039 setup_info = setup_info_graphics;
2040 title_string = "Setup Graphics";
2042 else if (setup_mode == SETUP_MODE_SOUND)
2044 setup_info = setup_info_sound;
2045 title_string = "Setup Sound";
2047 else if (setup_mode == SETUP_MODE_ARTWORK)
2049 setup_info = setup_info_artwork;
2050 title_string = "Custom Artwork";
2052 else if (setup_mode == SETUP_MODE_SHORTCUT)
2054 setup_info = setup_info_shortcut;
2055 title_string = "Setup Shortcuts";
2058 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2061 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2063 void *value_ptr = setup_info[i].value;
2064 int ypos = MENU_SCREEN_START_YPOS + i;
2065 int font_nr = FONT_MENU_1;
2067 /* set some entries to "unchangeable" according to other variables */
2068 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2069 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2070 (value_ptr == &setup.sound_music && !audio.music_available) ||
2071 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2072 setup_info[i].type |= TYPE_GHOSTED;
2074 if (setup_info[i].type & TYPE_STRING)
2075 font_nr = FONT_MENU_2;
2077 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2079 if (setup_info[i].type & TYPE_ENTER_MENU)
2080 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2081 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2082 initCursor(i, IMG_MENU_BUTTON_LEFT);
2083 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2084 initCursor(i, IMG_MENU_BUTTON);
2086 if (setup_info[i].type & TYPE_VALUE)
2094 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2097 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2099 static int choice_store[MAX_SETUP_MODES];
2100 int choice = choice_store[setup_mode]; /* always starts with 0 */
2104 if (button == MB_MENU_INITIALIZE)
2106 /* advance to first valid menu entry */
2107 while (choice < num_setup_info &&
2108 setup_info[choice].type & TYPE_SKIP_ENTRY)
2110 choice_store[setup_mode] = choice;
2112 drawCursor(choice, FC_RED);
2115 else if (button == MB_MENU_LEAVE)
2117 for (y = 0; y < num_setup_info; y++)
2119 if (setup_info[y].type & TYPE_LEAVE_MENU)
2121 void (*menu_callback_function)(void) = setup_info[y].value;
2123 menu_callback_function();
2124 break; /* absolutely needed because function changes 'setup_info'! */
2131 if (mx || my) /* mouse input */
2133 x = (mx - mSX) / 32;
2134 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2136 else if (dx || dy) /* keyboard input */
2140 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2142 if (setup_info[choice].type & menu_navigation_type ||
2143 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2144 button = MB_MENU_CHOICE;
2149 /* jump to next non-empty menu entry (up or down) */
2150 while (y > 0 && y < num_setup_info - 1 &&
2151 setup_info[y].type & TYPE_SKIP_ENTRY)
2155 if (IN_GFX_SCREEN(mx, my) &&
2156 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2162 drawCursor(y, FC_RED);
2163 drawCursor(choice, FC_BLUE);
2164 choice = choice_store[setup_mode] = y;
2167 else if (!(setup_info[y].type & TYPE_GHOSTED))
2169 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2171 void (*menu_callback_function)(void) = setup_info[choice].value;
2173 menu_callback_function();
2177 if (setup_info[y].type & TYPE_KEYTEXT &&
2178 setup_info[y + 1].type & TYPE_KEY)
2181 if (setup_info[y].type & TYPE_VALUE)
2182 changeSetupValue(y);
2188 void DrawSetupScreen_Input()
2192 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2194 initCursor(0, IMG_MENU_BUTTON);
2195 initCursor(1, IMG_MENU_BUTTON);
2196 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2197 initCursor(13, IMG_MENU_BUTTON_LEFT);
2199 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2200 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2202 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2203 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2204 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2207 DeactivateJoystickForCalibration();
2208 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2209 "Joysticks deactivated on this screen");
2212 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2217 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2219 if (device_name == NULL)
2222 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2225 if (strlen(device_name) > 1)
2227 char c1 = device_name[strlen(device_name) - 1];
2228 char c2 = device_name[strlen(device_name) - 2];
2230 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2231 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2234 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2235 strlen(device_name));
2238 static void drawPlayerSetupInputInfo(int player_nr)
2241 static struct SetupKeyboardInfo custom_key;
2248 { &custom_key.left, "Joystick Left" },
2249 { &custom_key.right, "Joystick Right" },
2250 { &custom_key.up, "Joystick Up" },
2251 { &custom_key.down, "Joystick Down" },
2252 { &custom_key.snap, "Button 1" },
2253 { &custom_key.bomb, "Button 2" }
2255 static char *joystick_name[MAX_PLAYERS] =
2263 custom_key = setup.input[player_nr].key;
2265 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2267 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2268 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2270 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2273 if (setup.input[player_nr].use_joystick)
2275 char *device_name = setup.input[player_nr].joy.device_name;
2277 DrawText(mSX+8*32, mSY+3*32,
2278 joystick_name[getJoystickNrFromDeviceName(device_name)],
2280 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2284 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2285 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2288 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2289 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2290 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2291 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2292 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2293 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2294 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2295 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2296 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2297 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2298 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2300 for (i = 0; i < 6; i++)
2302 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2304 DrawText(mSX + 3*32, mSY + ypos*32,
2306 DrawText(mSX + 3*32, mSY + ypos*32,
2307 (setup.input[player_nr].use_joystick ?
2309 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2313 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2315 static int choice = 0;
2316 static int player_nr = 0;
2319 int pos_start = SETUPINPUT_SCREEN_POS_START;
2320 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2321 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2322 int pos_end = SETUPINPUT_SCREEN_POS_END;
2324 if (button == MB_MENU_INITIALIZE)
2326 drawPlayerSetupInputInfo(player_nr);
2327 drawCursor(choice, FC_RED);
2331 else if (button == MB_MENU_LEAVE)
2333 setup_mode = SETUP_MODE_MAIN;
2340 if (mx || my) /* mouse input */
2342 x = (mx - mSX) / 32;
2343 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2345 else if (dx || dy) /* keyboard input */
2347 if (dx && choice == 0)
2348 x = (dx < 0 ? 10 : 12);
2349 else if ((dx && choice == 1) ||
2350 (dx == +1 && choice == 2) ||
2351 (dx == -1 && choice == pos_end))
2352 button = MB_MENU_CHOICE;
2356 if (y >= pos_empty1 && y <= pos_empty2)
2357 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2360 if (IN_GFX_SCREEN(mx, my) &&
2361 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2363 static unsigned long delay = 0;
2365 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2368 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2370 drawPlayerSetupInputInfo(player_nr);
2372 else if (IN_GFX_SCREEN(mx, my) &&
2373 y >= pos_start && y <= pos_end &&
2374 !(y >= pos_empty1 && y <= pos_empty2))
2380 drawCursor(y, FC_RED);
2381 drawCursor(choice, FC_BLUE);
2389 char *device_name = setup.input[player_nr].joy.device_name;
2391 if (!setup.input[player_nr].use_joystick)
2393 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2395 setJoystickDeviceToNr(device_name, new_device_nr);
2396 setup.input[player_nr].use_joystick = TRUE;
2400 int device_nr = getJoystickNrFromDeviceName(device_name);
2401 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2403 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2404 setup.input[player_nr].use_joystick = FALSE;
2406 setJoystickDeviceToNr(device_name, new_device_nr);
2409 drawPlayerSetupInputInfo(player_nr);
2413 if (setup.input[player_nr].use_joystick)
2416 CalibrateJoystick(player_nr);
2419 CustomizeKeyboard(player_nr);
2421 else if (y == pos_end)
2425 setup_mode = SETUP_MODE_MAIN;
2432 void CustomizeKeyboard(int player_nr)
2436 boolean finished = FALSE;
2437 static struct SetupKeyboardInfo custom_key;
2442 } customize_step[] =
2444 { &custom_key.left, "Move Left" },
2445 { &custom_key.right, "Move Right" },
2446 { &custom_key.up, "Move Up" },
2447 { &custom_key.down, "Move Down" },
2448 { &custom_key.snap, "Snap Field" },
2449 { &custom_key.bomb, "Place Bomb" }
2452 /* read existing key bindings from player setup */
2453 custom_key = setup.input[player_nr].key;
2456 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2462 DrawText(mSX, mSY + (2+2*step_nr)*32,
2463 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2464 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2465 "Key:", FONT_INPUT_1_ACTIVE);
2466 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2467 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2471 if (PendingEvent()) /* got event */
2479 case EVENT_KEYPRESS:
2481 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2483 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2489 /* all keys configured -- wait for "Escape" or "Return" key */
2493 /* press 'Enter' to keep the existing key binding */
2494 if (key == KSYM_Return)
2495 key = *customize_step[step_nr].key;
2497 /* check if key already used */
2498 for (i = 0; i < step_nr; i++)
2499 if (*customize_step[i].key == key)
2504 /* got new key binding */
2505 *customize_step[step_nr].key = key;
2506 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2508 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2509 getKeyNameFromKey(key), FONT_VALUE_1);
2512 /* un-highlight last query */
2513 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2514 customize_step[step_nr-1].text, FONT_MENU_1);
2515 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2516 "Key:", FONT_MENU_1);
2518 /* press 'Enter' to leave */
2521 DrawText(mSX + 16, mSY + 15*32+16,
2522 "Press Enter", FONT_TITLE_1);
2526 /* query next key binding */
2527 DrawText(mSX, mSY+(2+2*step_nr)*32,
2528 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2529 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2530 "Key:", FONT_INPUT_1_ACTIVE);
2531 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2532 getKeyNameFromKey(*customize_step[step_nr].key),
2537 case EVENT_KEYRELEASE:
2538 key_joystick_mapping = 0;
2542 HandleOtherEvents(&event);
2550 /* don't eat all CPU time */
2554 /* write new key bindings back to player setup */
2555 setup.input[player_nr].key = custom_key;
2558 DrawSetupScreen_Input();
2561 static boolean CalibrateJoystickMain(int player_nr)
2563 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2564 int new_joystick_xright = JOYSTICK_XMIDDLE;
2565 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2566 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2567 int new_joystick_xmiddle, new_joystick_ymiddle;
2569 int joystick_fd = joystick.fd[player_nr];
2570 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2571 boolean check[3][3];
2572 int check_remaining = 3 * 3;
2577 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2580 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2585 for (y = 0; y < 3; y++)
2587 for (x = 0; x < 3; x++)
2589 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2590 check[x][y] = FALSE;
2594 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2595 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2596 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2597 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2598 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2599 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2600 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2602 joy_value = Joystick(player_nr);
2603 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2604 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2606 /* eventually uncalibrated center position (joystick could be uncentered) */
2607 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2610 new_joystick_xmiddle = joy_x;
2611 new_joystick_ymiddle = joy_y;
2613 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2616 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2621 if (PendingEvent()) /* got event */
2629 case EVENT_KEYPRESS:
2630 switch(GetEventKey((KeyEvent *)&event, TRUE))
2633 if (check_remaining == 0)
2646 case EVENT_KEYRELEASE:
2647 key_joystick_mapping = 0;
2651 HandleOtherEvents(&event);
2656 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2659 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2660 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2661 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2662 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2664 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2665 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2666 setup.input[player_nr].joy.xright = new_joystick_xright;
2667 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2668 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2669 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2671 CheckJoystickData();
2673 joy_value = Joystick(player_nr);
2675 if (joy_value & JOY_BUTTON && check_remaining == 0)
2678 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2679 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2681 if (x != last_x || y != last_y)
2683 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2684 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2689 if (check_remaining > 0 && !check[x+1][y+1])
2691 check[x+1][y+1] = TRUE;
2697 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2698 setup.input[player_nr].joy.xleft,
2699 setup.input[player_nr].joy.xmiddle,
2700 setup.input[player_nr].joy.xright);
2701 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2702 setup.input[player_nr].joy.yupper,
2703 setup.input[player_nr].joy.ymiddle,
2704 setup.input[player_nr].joy.ylower);
2713 /* don't eat all CPU time */
2717 /* calibrated center position (joystick should now be centered) */
2718 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2721 new_joystick_xmiddle = joy_x;
2722 new_joystick_ymiddle = joy_y;
2726 DrawSetupScreen_Input();
2728 /* wait until the last pressed button was released */
2729 while (Joystick(player_nr) & JOY_BUTTON)
2731 if (PendingEvent()) /* got event */
2736 HandleOtherEvents(&event);
2745 void CalibrateJoystick(int player_nr)
2747 if (!CalibrateJoystickMain(player_nr))
2751 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
2752 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
2754 Delay(2000); /* show error message for two seconds */
2758 void DrawSetupScreen()
2760 DeactivateJoystick();
2762 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2764 if (setup_mode == SETUP_MODE_INPUT)
2765 DrawSetupScreen_Input();
2766 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2767 DrawChooseTree(&artwork.gfx_current);
2768 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2769 DrawChooseTree(&artwork.snd_current);
2770 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2771 DrawChooseTree(&artwork.mus_current);
2773 DrawSetupScreen_Generic();
2779 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2781 if (setup_mode == SETUP_MODE_INPUT)
2782 HandleSetupScreen_Input(mx, my, dx, dy, button);
2783 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2784 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2785 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2786 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2787 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2788 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2790 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2795 void HandleGameActions()
2797 if (game_status != GAME_MODE_PLAYING)
2800 if (local_player->LevelSolved)
2803 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2809 if (tape.auto_play && !tape.playing)
2810 AutoPlayTape(); /* continue automatically playing next tape */
2813 /* ---------- new screen button stuff -------------------------------------- */
2815 /* graphic position and size values for buttons and scrollbars */
2816 #define SC_SCROLLBUTTON_XSIZE TILEX
2817 #define SC_SCROLLBUTTON_YSIZE TILEY
2819 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2820 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
2821 SC_SCROLLBUTTON_YSIZE)
2822 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2823 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
2824 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2825 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
2826 SC_SCROLLBUTTON_YSIZE)
2827 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2828 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
2829 SC_SCROLL_VERTICAL_YSIZE)
2831 #define SC_BORDER_SIZE 14
2835 int gfx_unpressed, gfx_pressed;
2839 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2842 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2843 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2844 SCREEN_CTRL_ID_SCROLL_UP,
2848 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2849 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2850 SCREEN_CTRL_ID_SCROLL_DOWN,
2857 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2858 Bitmap **gfx_unpressed, **gfx_pressed;
2860 int gfx_unpressed, gfx_pressed;
2867 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2870 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2871 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2873 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2875 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
2876 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2877 GD_TYPE_SCROLLBAR_VERTICAL,
2878 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2879 "scroll level series vertically"
2883 static void CreateScreenScrollbuttons()
2885 struct GadgetInfo *gi;
2886 unsigned long event_mask;
2889 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
2891 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2892 int gfx_unpressed, gfx_pressed;
2893 int x, y, width, height;
2894 int gd_x1, gd_x2, gd_y1, gd_y2;
2895 int id = scrollbutton_info[i].gadget_id;
2897 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2899 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
2900 y = mSY + scrollbutton_info[i].y;
2901 width = SC_SCROLLBUTTON_XSIZE;
2902 height = SC_SCROLLBUTTON_YSIZE;
2904 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
2905 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
2906 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
2908 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2909 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2910 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2911 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2912 gd_x1 = graphic_info[gfx_unpressed].src_x;
2913 gd_y1 = graphic_info[gfx_unpressed].src_y;
2914 gd_x2 = graphic_info[gfx_pressed].src_x;
2915 gd_y2 = graphic_info[gfx_pressed].src_y;
2917 gi = CreateGadget(GDI_CUSTOM_ID, id,
2918 GDI_CUSTOM_TYPE_ID, i,
2919 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2924 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2925 GDI_STATE, GD_BUTTON_UNPRESSED,
2926 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2927 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2928 GDI_DIRECT_DRAW, FALSE,
2929 GDI_EVENT_MASK, event_mask,
2930 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2934 Error(ERR_EXIT, "cannot create gadget");
2936 screen_gadget[id] = gi;
2940 static void CreateScreenScrollbars()
2944 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
2946 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2947 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2948 int gfx_unpressed, gfx_pressed;
2950 int x, y, width, height;
2951 int gd_x1, gd_x2, gd_y1, gd_y2;
2952 struct GadgetInfo *gi;
2953 int items_max, items_visible, item_position;
2954 unsigned long event_mask;
2955 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2956 int id = scrollbar_info[i].gadget_id;
2958 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
2960 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
2961 y = mSY + scrollbar_info[i].y;
2962 width = scrollbar_info[i].width;
2963 height = scrollbar_info[i].height;
2965 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
2966 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
2968 items_max = num_page_entries;
2969 items_visible = num_page_entries;
2972 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2973 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
2974 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
2980 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
2981 gfx_pressed = scrollbar_info[i].gfx_pressed;
2982 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2983 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2984 gd_x1 = graphic_info[gfx_unpressed].src_x;
2985 gd_y1 = graphic_info[gfx_unpressed].src_y;
2986 gd_x2 = graphic_info[gfx_pressed].src_x;
2987 gd_y2 = graphic_info[gfx_pressed].src_y;
2990 gi = CreateGadget(GDI_CUSTOM_ID, id,
2991 GDI_CUSTOM_TYPE_ID, i,
2992 GDI_INFO_TEXT, scrollbar_info[i].infotext,
2997 GDI_TYPE, scrollbar_info[i].type,
2998 GDI_SCROLLBAR_ITEMS_MAX, items_max,
2999 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3000 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3001 GDI_STATE, GD_BUTTON_UNPRESSED,
3002 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3003 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3004 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3005 GDI_DIRECT_DRAW, FALSE,
3006 GDI_EVENT_MASK, event_mask,
3007 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3011 Error(ERR_EXIT, "cannot create gadget");
3013 screen_gadget[id] = gi;
3017 void CreateScreenGadgets()
3019 int last_game_status = game_status; /* save current game status */
3021 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3024 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3026 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3028 /* copy pointers to clip mask and GC */
3029 scrollbar_bitmap[i]->clip_mask =
3030 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3031 scrollbar_bitmap[i]->stored_clip_gc =
3032 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3034 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3035 scrollbar_bitmap[i],
3036 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3037 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3038 TILEX, TILEY, 0, 0);
3042 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3043 game_status = GAME_MODE_LEVELS;
3045 CreateScreenScrollbuttons();
3046 CreateScreenScrollbars();
3048 game_status = last_game_status; /* restore current game status */
3051 void FreeScreenGadgets()
3055 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3056 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3058 /* prevent freeing clip mask and GC twice */
3059 scrollbar_bitmap[i]->clip_mask = None;
3060 scrollbar_bitmap[i]->stored_clip_gc = None;
3062 FreeBitmap(scrollbar_bitmap[i]);
3066 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3067 FreeGadget(screen_gadget[i]);
3070 void MapChooseTreeGadgets(TreeInfo *ti)
3072 int num_entries = numTreeInfoInGroup(ti);
3075 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3078 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3079 MapGadget(screen_gadget[i]);
3083 void UnmapChooseTreeGadgets()
3087 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3088 UnmapGadget(screen_gadget[i]);
3092 static void HandleScreenGadgets(struct GadgetInfo *gi)
3094 int id = gi->custom_id;
3096 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3101 case SCREEN_CTRL_ID_SCROLL_UP:
3102 if (game_status == GAME_MODE_LEVELS)
3103 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3104 else if (game_status == GAME_MODE_SETUP)
3105 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3108 case SCREEN_CTRL_ID_SCROLL_DOWN:
3109 if (game_status == GAME_MODE_LEVELS)
3110 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3111 else if (game_status == GAME_MODE_SETUP)
3112 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3115 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3116 if (game_status == GAME_MODE_LEVELS)
3117 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3118 else if (game_status == GAME_MODE_SETUP)
3119 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);