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;
816 static char *getHelpText(int element, int action, int direction)
818 char token[MAX_LINE_LEN];
820 strcpy(token, element_info[element].token_name);
823 strcat(token, element_action_info[action].suffix);
826 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
828 return getHashEntry(helptext_info, token);
831 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
833 int font_nr = FONT_TEXT_2;
834 int max_chars_per_line = 34;
835 int max_lines_per_text = 2;
837 int sy = mSY + 65 + 2 * 32 + 1;
838 int ystep = TILEY + 4;
841 if (action != -1 && direction != -1) /* element.action.direction */
842 text = getHelpText(element, action, direction);
844 if (text == NULL && action != -1) /* element.action */
845 text = getHelpText(element, action, -1);
847 if (text == NULL && direction != -1) /* element.direction */
848 text = getHelpText(element, -1, direction);
850 if (text == NULL) /* base element */
851 text = getHelpText(element, -1, -1);
853 if (text == NULL) /* not found */
854 text = "No description available";
856 if (strlen(text) <= max_chars_per_line) /* only one line of text */
857 sy += getFontHeight(font_nr) / 2;
859 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
860 max_chars_per_line, max_lines_per_text);
865 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
867 int font_nr = FONT_TEXT_2;
868 int max_chars_per_line = 34;
869 int max_lines_per_text = 2;
871 int sy = mSY + 65 + 2 * 32 + 1;
872 int ystep = TILEY + 4;
875 /* 1st try: get text for base element */
876 text = getHashEntry(helptext_info, element_info[element].token_name);
880 /* 2nd try: get text for element/action/direction */
881 char token[MAX_LINE_LEN];
883 strcpy(token, element_info[element].token_name);
886 strcat(token, element_action_info[action].suffix);
889 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
891 text = getHashEntry(helptext_info, token);
894 text = "No description available";
897 if (strlen(text) <= max_chars_per_line) /* only one line of text */
898 sy += getFontHeight(font_nr) / 2;
900 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
901 max_chars_per_line, max_lines_per_text);
905 void DrawInfoScreen_Elements()
910 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
916 void HandleInfoScreen_Elements(int button)
918 static unsigned long info_delay = 0;
919 static int num_anims;
920 static int num_pages;
922 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
923 int button_released = !button;
926 if (button == MB_MENU_INITIALIZE)
928 boolean new_element = TRUE;
931 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
933 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
935 else if (new_element)
942 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
945 else if (button == MB_MENU_LEAVE)
947 info_mode = INFO_MODE_MAIN;
953 if (button_released || button == MB_MENU_INITIALIZE)
955 if (button != MB_MENU_INITIALIZE)
958 if (page >= num_pages)
960 FadeSoundsAndMusic();
962 info_mode = INFO_MODE_MAIN;
968 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
972 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
973 if (page < num_pages)
974 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
976 PlayMenuSoundIfLoop();
980 void DrawInfoScreen_Music()
987 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
990 void HandleInfoScreen_Music(int button)
992 static struct MusicFileInfo *list = NULL;
993 int ystart = 150, ystep = 30;
994 int ybottom = SYSIZE - 20;
995 int button_released = !button;
997 if (button == MB_MENU_INITIALIZE)
999 list = music_file_info;
1003 FadeSoundsAndMusic();
1008 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1010 DrawTextSCentered(ybottom, FONT_TEXT_4,
1011 "Press any key or button for info menu");
1016 else if (button == MB_MENU_LEAVE)
1018 info_mode = INFO_MODE_MAIN;
1024 if (button_released || button == MB_MENU_INITIALIZE)
1028 info_mode = INFO_MODE_MAIN;
1034 FadeSoundsAndMusic();
1039 DrawTextSCentered(100, FONT_TEXT_1, "The game background music:");
1041 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
1042 DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "\"%s\"", list->title);
1043 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
1044 DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "%s", list->artist);
1045 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
1046 DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3, "\"%s\"", list->album);
1048 DrawTextSCentered(ybottom, FONT_TEXT_4,
1049 "Press any key or button for next page");
1051 PlayMusic(list->music);
1057 void DrawInfoScreen_Credits()
1059 int ystart = 150, ystep = 30;
1060 int ybottom = SYSIZE - 20;
1062 FadeSoundsAndMusic();
1067 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1068 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1069 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1070 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1071 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1072 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1073 "...and many thanks to all contributors");
1074 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1076 DrawTextSCentered(ybottom, FONT_TEXT_4,
1077 "Press any key or button for info menu");
1080 void HandleInfoScreen_Credits(int button)
1082 int button_released = !button;
1084 if (button == MB_MENU_LEAVE)
1086 info_mode = INFO_MODE_MAIN;
1092 if (button_released)
1094 FadeSoundsAndMusic();
1096 info_mode = INFO_MODE_MAIN;
1101 PlayMenuSoundIfLoop();
1105 void DrawInfoScreen_Program()
1107 int ystart = 150, ystep = 30;
1108 int ybottom = SYSIZE - 20;
1113 DrawTextSCentered(100, FONT_TEXT_1, "Program information:");
1115 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1116 "This game is Freeware!");
1117 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1118 "If you like it, send e-mail to:");
1119 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1120 "info@artsoft.org");
1121 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1122 "or SnailMail to:");
1123 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1125 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1126 "Detmolder Strasse 189");
1127 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1129 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1132 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1133 "If you have created new levels,");
1134 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1135 "send them to me to include them!");
1136 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1139 DrawTextSCentered(ybottom, FONT_TEXT_4,
1140 "Press any key or button for info menu");
1143 void HandleInfoScreen_Program(int button)
1145 int button_released = !button;
1147 if (button == MB_MENU_LEAVE)
1149 info_mode = INFO_MODE_MAIN;
1155 if (button_released)
1157 FadeSoundsAndMusic();
1159 info_mode = INFO_MODE_MAIN;
1164 PlayMenuSoundIfLoop();
1168 void DrawInfoScreen()
1170 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1172 if (info_mode == INFO_MODE_ELEMENTS)
1173 DrawInfoScreen_Elements();
1174 else if (info_mode == INFO_MODE_MUSIC)
1175 DrawInfoScreen_Music();
1176 else if (info_mode == INFO_MODE_CREDITS)
1177 DrawInfoScreen_Credits();
1178 else if (info_mode == INFO_MODE_PROGRAM)
1179 DrawInfoScreen_Program();
1181 DrawInfoScreen_Main();
1183 if (info_mode != INFO_MODE_MUSIC)
1190 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1192 if (info_mode == INFO_MODE_ELEMENTS)
1193 HandleInfoScreen_Elements(button);
1194 else if (info_mode == INFO_MODE_MUSIC)
1195 HandleInfoScreen_Music(button);
1196 else if (info_mode == INFO_MODE_CREDITS)
1197 HandleInfoScreen_Credits(button);
1198 else if (info_mode == INFO_MODE_PROGRAM)
1199 HandleInfoScreen_Program(button);
1201 HandleInfoScreen_Main(mx, my, dx, dy, button);
1207 /* ========================================================================= */
1208 /* type name functions */
1209 /* ========================================================================= */
1211 void HandleTypeName(int newxpos, Key key)
1213 static int xpos = 0, ypos = 2;
1214 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1215 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1216 int startx = mSX + 32 + name_width;
1217 int starty = mSY + ypos * 32;
1223 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1224 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1229 if (((key >= KSYM_A && key <= KSYM_Z) ||
1230 (key >= KSYM_a && key <= KSYM_z)) &&
1231 xpos < MAX_PLAYER_NAME_LEN)
1235 if (key >= KSYM_A && key <= KSYM_Z)
1236 ascii = 'A' + (char)(key - KSYM_A);
1238 ascii = 'a' + (char)(key - KSYM_a);
1240 setup.player_name[xpos] = ascii;
1241 setup.player_name[xpos + 1] = 0;
1244 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1245 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1247 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1250 setup.player_name[xpos] = 0;
1252 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1254 else if (key == KSYM_Return && xpos > 0)
1256 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1257 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1260 game_status = GAME_MODE_MAIN;
1265 /* ========================================================================= */
1266 /* tree menu functions */
1267 /* ========================================================================= */
1269 static void DrawChooseTree(TreeInfo **ti_ptr)
1273 FreeScreenGadgets();
1274 CreateScreenGadgets();
1276 CloseDoor(DOOR_CLOSE_2);
1280 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1281 MapChooseTreeGadgets(*ti_ptr);
1287 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1289 struct GadgetInfo *gi = screen_gadget[id];
1290 int items_max, items_visible, item_position;
1292 items_max = numTreeInfoInGroup(ti);
1293 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1294 item_position = first_entry;
1296 if (item_position > items_max - items_visible)
1297 item_position = items_max - items_visible;
1299 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1300 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1301 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1304 static void drawChooseTreeList(int first_entry, int num_page_entries,
1308 char buffer[SCR_FIELDX * 2];
1309 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1310 char *title_string = NULL;
1311 int xoffset_setup = 16;
1312 int yoffset_setup = 16;
1313 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1314 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1315 int last_game_status = game_status; /* save current game status */
1318 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1319 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1320 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1321 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1323 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1325 /* force LEVELS font on artwork setup screen */
1326 game_status = GAME_MODE_LEVELS;
1328 /* clear tree list area, but not title or scrollbar */
1329 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1330 SXSIZE - 32 + menu.scrollbar_xoffset,
1331 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1333 for (i = 0; i < num_page_entries; i++)
1335 TreeInfo *node, *node_first;
1336 int entry_pos = first_entry + i;
1337 int ypos = MENU_SCREEN_START_YPOS + i;
1339 node_first = getTreeInfoFirstGroupEntry(ti);
1340 node = getTreeInfoFromPos(node_first, entry_pos);
1342 strncpy(buffer, node->name , max_buffer_len);
1343 buffer[max_buffer_len] = '\0';
1345 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1347 if (node->parent_link)
1348 initCursor(i, IMG_MENU_BUTTON_LEFT);
1349 else if (node->level_group)
1350 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1352 initCursor(i, IMG_MENU_BUTTON);
1355 game_status = last_game_status; /* restore current game status */
1357 redraw_mask |= REDRAW_FIELD;
1360 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1362 TreeInfo *node, *node_first;
1363 int x, last_redraw_mask = redraw_mask;
1365 if (ti->type != TREE_TYPE_LEVEL_DIR)
1368 node_first = getTreeInfoFirstGroupEntry(ti);
1369 node = getTreeInfoFromPos(node_first, entry_pos);
1371 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1373 if (node->parent_link)
1374 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1376 else if (node->level_group)
1377 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1379 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1380 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1381 node->levels, node->class_desc);
1383 /* let BackToFront() redraw only what is needed */
1384 redraw_mask = last_redraw_mask | REDRAW_TILES;
1385 for (x = 0; x < SCR_FIELDX; x++)
1386 MarkTileDirty(x, 1);
1389 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1392 TreeInfo *ti = *ti_ptr;
1394 int y = ti->cl_cursor;
1395 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1396 int num_entries = numTreeInfoInGroup(ti);
1397 int num_page_entries;
1398 int last_game_status = game_status; /* save current game status */
1400 /* force LEVELS draw offset on choose level and artwork setup screen */
1401 game_status = GAME_MODE_LEVELS;
1403 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1404 num_page_entries = num_entries;
1406 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1408 game_status = last_game_status; /* restore current game status */
1410 if (button == MB_MENU_INITIALIZE)
1412 int num_entries = numTreeInfoInGroup(ti);
1413 int entry_pos = posTreeInfo(ti);
1415 if (ti->cl_first == -1)
1417 /* only on initialization */
1418 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1419 ti->cl_cursor = entry_pos - ti->cl_first;
1421 else if (ti->cl_cursor >= num_page_entries ||
1422 (num_entries > num_page_entries &&
1423 num_entries - ti->cl_first < num_page_entries))
1425 /* only after change of list size (by custom graphic configuration) */
1426 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1427 ti->cl_cursor = entry_pos - ti->cl_first;
1430 if (dx == 999) /* first entry is set by scrollbar position */
1433 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1436 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1437 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1438 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1442 else if (button == MB_MENU_LEAVE)
1444 if (ti->node_parent)
1446 *ti_ptr = ti->node_parent;
1447 DrawChooseTree(ti_ptr);
1449 else if (game_status == GAME_MODE_SETUP)
1455 game_status = GAME_MODE_MAIN;
1462 if (mx || my) /* mouse input */
1464 int last_game_status = game_status; /* save current game status */
1466 /* force LEVELS draw offset on artwork setup screen */
1467 game_status = GAME_MODE_LEVELS;
1469 x = (mx - mSX) / 32;
1470 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1472 game_status = last_game_status; /* restore current game status */
1474 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1476 /* move cursor instead of scrolling when already at start/end of list */
1477 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1479 else if (dy == +1 * SCROLL_LINE &&
1480 ti->cl_first + num_page_entries == num_entries)
1483 /* handle scrolling screen one line or page */
1484 if (ti->cl_cursor + dy < 0 ||
1485 ti->cl_cursor + dy > num_page_entries - 1)
1487 if (ABS(dy) == SCROLL_PAGE)
1488 step = num_page_entries - 1;
1490 if (dy < 0 && ti->cl_first > 0)
1492 /* scroll page/line up */
1494 ti->cl_first -= step;
1495 if (ti->cl_first < 0)
1498 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1499 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1500 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1501 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1504 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1506 /* scroll page/line down */
1508 ti->cl_first += step;
1509 if (ti->cl_first + num_page_entries > num_entries)
1510 ti->cl_first = MAX(0, num_entries - num_page_entries);
1512 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1513 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1514 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1515 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1522 /* handle moving cursor one line */
1523 y = ti->cl_cursor + dy;
1528 TreeInfo *node_first, *node_cursor;
1529 int entry_pos = ti->cl_first + y;
1531 node_first = getTreeInfoFirstGroupEntry(ti);
1532 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1534 if (node_cursor->node_group)
1536 node_cursor->cl_first = ti->cl_first;
1537 node_cursor->cl_cursor = ti->cl_cursor;
1538 *ti_ptr = node_cursor->node_group;
1539 DrawChooseTree(ti_ptr);
1544 else if (dx == -1 && ti->node_parent)
1546 *ti_ptr = ti->node_parent;
1547 DrawChooseTree(ti_ptr);
1552 if (IN_GFX_SCREEN(mx, my) &&
1553 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1554 y >= 0 && y < num_page_entries)
1558 if (y != ti->cl_cursor)
1560 drawChooseTreeCursor(y, FC_RED);
1561 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1562 drawChooseTreeInfo(ti->cl_first + y, ti);
1568 TreeInfo *node_first, *node_cursor;
1569 int entry_pos = ti->cl_first + y;
1571 node_first = getTreeInfoFirstGroupEntry(ti);
1572 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1574 if (node_cursor->node_group)
1576 node_cursor->cl_first = ti->cl_first;
1577 node_cursor->cl_cursor = ti->cl_cursor;
1578 *ti_ptr = node_cursor->node_group;
1579 DrawChooseTree(ti_ptr);
1581 else if (node_cursor->parent_link)
1583 *ti_ptr = node_cursor->node_parent;
1584 DrawChooseTree(ti_ptr);
1588 node_cursor->cl_first = ti->cl_first;
1589 node_cursor->cl_cursor = ti->cl_cursor;
1590 *ti_ptr = node_cursor;
1592 if (ti->type == TREE_TYPE_LEVEL_DIR)
1594 LoadLevelSetup_SeriesInfo();
1596 SaveLevelSetup_LastSeries();
1597 SaveLevelSetup_SeriesInfo();
1601 if (game_status == GAME_MODE_SETUP)
1607 game_status = GAME_MODE_MAIN;
1615 void DrawChooseLevel()
1617 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1619 DrawChooseTree(&leveldir_current);
1625 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1627 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1632 void DrawHallOfFame(int highlight_position)
1635 FadeSoundsAndMusic();
1636 CloseDoor(DOOR_CLOSE_2);
1638 if (highlight_position < 0)
1639 LoadScore(level_nr);
1647 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1650 static void drawHallOfFameList(int first_entry, int highlight_position)
1654 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1657 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1658 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1660 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1662 int entry = first_entry + i;
1663 boolean active = (entry == highlight_position);
1664 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1665 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1666 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1667 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1668 int dx1 = 3 * getFontWidth(font_nr1);
1669 int dx2 = dx1 + getFontWidth(font_nr1);
1670 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1671 int sy = mSY + 64 + i * 32;
1673 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1674 DrawText(mSX + dx1, sy, ".", font_nr1);
1675 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1676 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1677 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1678 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1681 redraw_mask |= REDRAW_FIELD;
1684 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1686 static int first_entry = 0;
1687 static int highlight_position = 0;
1688 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1689 int button_released = !button;
1691 if (button == MB_MENU_INITIALIZE)
1694 highlight_position = mx;
1695 drawHallOfFameList(first_entry, highlight_position);
1700 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1701 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1705 if (first_entry > 0)
1707 first_entry -= step;
1708 if (first_entry < 0)
1711 drawHallOfFameList(first_entry, highlight_position);
1716 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1718 first_entry += step;
1719 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1720 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1722 drawHallOfFameList(first_entry, highlight_position);
1725 else if (button_released)
1727 FadeSound(SND_BACKGROUND_SCORES);
1728 game_status = GAME_MODE_MAIN;
1732 if (game_status == GAME_MODE_SCORES)
1733 PlayMenuSoundIfLoop();
1739 /* ========================================================================= */
1740 /* setup screen functions */
1741 /* ========================================================================= */
1743 static struct TokenInfo *setup_info;
1744 static int num_setup_info;
1746 static char *graphics_set_name;
1747 static char *sounds_set_name;
1748 static char *music_set_name;
1750 static void execSetupMain()
1752 setup_mode = SETUP_MODE_MAIN;
1756 static void execSetupGame()
1758 setup_mode = SETUP_MODE_GAME;
1762 static void execSetupEditor()
1764 setup_mode = SETUP_MODE_EDITOR;
1768 static void execSetupGraphics()
1770 setup_mode = SETUP_MODE_GRAPHICS;
1774 static void execSetupSound()
1776 setup_mode = SETUP_MODE_SOUND;
1780 static void execSetupArtwork()
1782 setup.graphics_set = artwork.gfx_current->identifier;
1783 setup.sounds_set = artwork.snd_current->identifier;
1784 setup.music_set = artwork.mus_current->identifier;
1786 /* needed if last screen (setup choice) changed graphics, sounds or music */
1787 ReloadCustomArtwork();
1789 /* needed for displaying artwork name instead of artwork identifier */
1790 graphics_set_name = artwork.gfx_current->name;
1791 sounds_set_name = artwork.snd_current->name;
1792 music_set_name = artwork.mus_current->name;
1794 setup_mode = SETUP_MODE_ARTWORK;
1798 static void execSetupChooseGraphics()
1800 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1804 static void execSetupChooseSounds()
1806 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1810 static void execSetupChooseMusic()
1812 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1816 static void execSetupInput()
1818 setup_mode = SETUP_MODE_INPUT;
1822 static void execSetupShortcut()
1824 setup_mode = SETUP_MODE_SHORTCUT;
1828 static void execExitSetup()
1830 game_status = GAME_MODE_MAIN;
1834 static void execSaveAndExitSetup()
1840 static struct TokenInfo setup_info_main[] =
1842 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1843 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1844 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1845 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1846 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1847 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1848 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1849 { TYPE_EMPTY, NULL, "" },
1850 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1851 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1856 static struct TokenInfo setup_info_game[] =
1858 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1859 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1860 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1861 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1862 { TYPE_EMPTY, NULL, "" },
1863 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1868 static struct TokenInfo setup_info_editor[] =
1870 { TYPE_STRING, NULL, "Offer Special Elements:"},
1871 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1872 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1873 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1874 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1875 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1876 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1877 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1878 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1879 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1880 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1881 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1882 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1883 { TYPE_EMPTY, NULL, "" },
1884 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1889 static struct TokenInfo setup_info_graphics[] =
1891 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1892 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1893 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1895 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1896 { TYPE_SWITCH, &setup.fading, "Fading:" },
1898 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1899 { TYPE_SWITCH, &setup.toons, "Toons:" },
1900 { TYPE_EMPTY, NULL, "" },
1901 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1906 static struct TokenInfo setup_info_sound[] =
1908 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1909 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1910 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1911 { TYPE_EMPTY, NULL, "" },
1912 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1917 static struct TokenInfo setup_info_artwork[] =
1919 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1920 { TYPE_STRING, &graphics_set_name, "" },
1921 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1922 { TYPE_STRING, &sounds_set_name, "" },
1923 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
1924 { TYPE_STRING, &music_set_name, "" },
1925 { TYPE_EMPTY, NULL, "" },
1926 { TYPE_STRING, NULL, "Override Level Artwork:"},
1927 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
1928 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
1929 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
1930 { TYPE_EMPTY, NULL, "" },
1931 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1936 static struct TokenInfo setup_info_shortcut[] =
1938 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
1939 { TYPE_KEY, &setup.shortcut.save_game, "" },
1940 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
1941 { TYPE_KEY, &setup.shortcut.load_game, "" },
1942 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
1943 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
1944 { TYPE_EMPTY, NULL, "" },
1945 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
1946 { TYPE_EMPTY, NULL, "" },
1947 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1952 static Key getSetupKey()
1954 Key key = KSYM_UNDEFINED;
1955 boolean got_key_event = FALSE;
1957 while (!got_key_event)
1959 if (PendingEvent()) /* got event */
1967 case EVENT_KEYPRESS:
1969 key = GetEventKey((KeyEvent *)&event, TRUE);
1971 /* press 'Escape' or 'Enter' to keep the existing key binding */
1972 if (key == KSYM_Escape || key == KSYM_Return)
1973 key = KSYM_UNDEFINED; /* keep old value */
1975 got_key_event = TRUE;
1979 case EVENT_KEYRELEASE:
1980 key_joystick_mapping = 0;
1984 HandleOtherEvents(&event);
1992 /* don't eat all CPU time */
1999 static void drawSetupValue(int pos)
2001 int xpos = MENU_SCREEN_VALUE_XPOS;
2002 int ypos = MENU_SCREEN_START_YPOS + pos;
2003 int font_nr = FONT_VALUE_1;
2004 int type = setup_info[pos].type;
2005 void *value = setup_info[pos].value;
2006 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2009 if (value_string == NULL)
2012 if (type & TYPE_KEY)
2016 if (type & TYPE_QUERY)
2018 value_string = "<press key>";
2019 font_nr = FONT_INPUT_1_ACTIVE;
2022 else if (type & TYPE_STRING)
2024 int max_value_len = (SCR_FIELDX - 2) * 2;
2027 font_nr = FONT_VALUE_2;
2029 if (strlen(value_string) > max_value_len)
2030 value_string[max_value_len] = '\0';
2032 else if (type & TYPE_BOOLEAN_STYLE)
2034 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2037 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2038 (xpos == 3 ? " " : " "), font_nr);
2039 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2042 static void changeSetupValue(int pos)
2044 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2046 *(boolean *)setup_info[pos].value ^= TRUE;
2048 else if (setup_info[pos].type & TYPE_KEY)
2052 setup_info[pos].type |= TYPE_QUERY;
2053 drawSetupValue(pos);
2054 setup_info[pos].type &= ~TYPE_QUERY;
2056 key = getSetupKey();
2057 if (key != KSYM_UNDEFINED)
2058 *(Key *)setup_info[pos].value = key;
2061 drawSetupValue(pos);
2064 static void DrawSetupScreen_Generic()
2066 char *title_string = NULL;
2070 CloseDoor(DOOR_CLOSE_2);
2074 if (setup_mode == SETUP_MODE_MAIN)
2076 setup_info = setup_info_main;
2077 title_string = "Setup";
2079 else if (setup_mode == SETUP_MODE_GAME)
2081 setup_info = setup_info_game;
2082 title_string = "Setup Game";
2084 else if (setup_mode == SETUP_MODE_EDITOR)
2086 setup_info = setup_info_editor;
2087 title_string = "Setup Editor";
2089 else if (setup_mode == SETUP_MODE_GRAPHICS)
2091 setup_info = setup_info_graphics;
2092 title_string = "Setup Graphics";
2094 else if (setup_mode == SETUP_MODE_SOUND)
2096 setup_info = setup_info_sound;
2097 title_string = "Setup Sound";
2099 else if (setup_mode == SETUP_MODE_ARTWORK)
2101 setup_info = setup_info_artwork;
2102 title_string = "Custom Artwork";
2104 else if (setup_mode == SETUP_MODE_SHORTCUT)
2106 setup_info = setup_info_shortcut;
2107 title_string = "Setup Shortcuts";
2110 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2113 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2115 void *value_ptr = setup_info[i].value;
2116 int ypos = MENU_SCREEN_START_YPOS + i;
2117 int font_nr = FONT_MENU_1;
2119 /* set some entries to "unchangeable" according to other variables */
2120 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2121 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2122 (value_ptr == &setup.sound_music && !audio.music_available) ||
2123 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2124 setup_info[i].type |= TYPE_GHOSTED;
2126 if (setup_info[i].type & TYPE_STRING)
2127 font_nr = FONT_MENU_2;
2129 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2131 if (setup_info[i].type & TYPE_ENTER_MENU)
2132 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2133 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2134 initCursor(i, IMG_MENU_BUTTON_LEFT);
2135 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2136 initCursor(i, IMG_MENU_BUTTON);
2138 if (setup_info[i].type & TYPE_VALUE)
2146 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2149 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2151 static int choice_store[MAX_SETUP_MODES];
2152 int choice = choice_store[setup_mode]; /* always starts with 0 */
2156 if (button == MB_MENU_INITIALIZE)
2158 /* advance to first valid menu entry */
2159 while (choice < num_setup_info &&
2160 setup_info[choice].type & TYPE_SKIP_ENTRY)
2162 choice_store[setup_mode] = choice;
2164 drawCursor(choice, FC_RED);
2167 else if (button == MB_MENU_LEAVE)
2169 for (y = 0; y < num_setup_info; y++)
2171 if (setup_info[y].type & TYPE_LEAVE_MENU)
2173 void (*menu_callback_function)(void) = setup_info[y].value;
2175 menu_callback_function();
2176 break; /* absolutely needed because function changes 'setup_info'! */
2183 if (mx || my) /* mouse input */
2185 x = (mx - mSX) / 32;
2186 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2188 else if (dx || dy) /* keyboard input */
2192 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2194 if (setup_info[choice].type & menu_navigation_type ||
2195 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2196 button = MB_MENU_CHOICE;
2201 /* jump to next non-empty menu entry (up or down) */
2202 while (y > 0 && y < num_setup_info - 1 &&
2203 setup_info[y].type & TYPE_SKIP_ENTRY)
2207 if (IN_GFX_SCREEN(mx, my) &&
2208 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2214 drawCursor(y, FC_RED);
2215 drawCursor(choice, FC_BLUE);
2216 choice = choice_store[setup_mode] = y;
2219 else if (!(setup_info[y].type & TYPE_GHOSTED))
2221 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2223 void (*menu_callback_function)(void) = setup_info[choice].value;
2225 menu_callback_function();
2229 if (setup_info[y].type & TYPE_KEYTEXT &&
2230 setup_info[y + 1].type & TYPE_KEY)
2233 if (setup_info[y].type & TYPE_VALUE)
2234 changeSetupValue(y);
2240 void DrawSetupScreen_Input()
2244 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2246 initCursor(0, IMG_MENU_BUTTON);
2247 initCursor(1, IMG_MENU_BUTTON);
2248 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2249 initCursor(13, IMG_MENU_BUTTON_LEFT);
2251 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2252 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2254 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2255 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2256 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2259 DeactivateJoystickForCalibration();
2260 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2261 "Joysticks deactivated on this screen");
2264 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2269 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2271 if (device_name == NULL)
2274 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2277 if (strlen(device_name) > 1)
2279 char c1 = device_name[strlen(device_name) - 1];
2280 char c2 = device_name[strlen(device_name) - 2];
2282 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2283 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2286 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2287 strlen(device_name));
2290 static void drawPlayerSetupInputInfo(int player_nr)
2293 static struct SetupKeyboardInfo custom_key;
2300 { &custom_key.left, "Joystick Left" },
2301 { &custom_key.right, "Joystick Right" },
2302 { &custom_key.up, "Joystick Up" },
2303 { &custom_key.down, "Joystick Down" },
2304 { &custom_key.snap, "Button 1" },
2305 { &custom_key.bomb, "Button 2" }
2307 static char *joystick_name[MAX_PLAYERS] =
2315 custom_key = setup.input[player_nr].key;
2317 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2319 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2320 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2322 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2325 if (setup.input[player_nr].use_joystick)
2327 char *device_name = setup.input[player_nr].joy.device_name;
2329 DrawText(mSX+8*32, mSY+3*32,
2330 joystick_name[getJoystickNrFromDeviceName(device_name)],
2332 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2336 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2337 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2340 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2341 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2342 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2343 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2344 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2345 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2346 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2347 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2348 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2349 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2350 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2352 for (i = 0; i < 6; i++)
2354 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2356 DrawText(mSX + 3*32, mSY + ypos*32,
2358 DrawText(mSX + 3*32, mSY + ypos*32,
2359 (setup.input[player_nr].use_joystick ?
2361 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2365 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2367 static int choice = 0;
2368 static int player_nr = 0;
2371 int pos_start = SETUPINPUT_SCREEN_POS_START;
2372 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2373 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2374 int pos_end = SETUPINPUT_SCREEN_POS_END;
2376 if (button == MB_MENU_INITIALIZE)
2378 drawPlayerSetupInputInfo(player_nr);
2379 drawCursor(choice, FC_RED);
2383 else if (button == MB_MENU_LEAVE)
2385 setup_mode = SETUP_MODE_MAIN;
2392 if (mx || my) /* mouse input */
2394 x = (mx - mSX) / 32;
2395 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2397 else if (dx || dy) /* keyboard input */
2399 if (dx && choice == 0)
2400 x = (dx < 0 ? 10 : 12);
2401 else if ((dx && choice == 1) ||
2402 (dx == +1 && choice == 2) ||
2403 (dx == -1 && choice == pos_end))
2404 button = MB_MENU_CHOICE;
2408 if (y >= pos_empty1 && y <= pos_empty2)
2409 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2412 if (IN_GFX_SCREEN(mx, my) &&
2413 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2415 static unsigned long delay = 0;
2417 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2420 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2422 drawPlayerSetupInputInfo(player_nr);
2424 else if (IN_GFX_SCREEN(mx, my) &&
2425 y >= pos_start && y <= pos_end &&
2426 !(y >= pos_empty1 && y <= pos_empty2))
2432 drawCursor(y, FC_RED);
2433 drawCursor(choice, FC_BLUE);
2441 char *device_name = setup.input[player_nr].joy.device_name;
2443 if (!setup.input[player_nr].use_joystick)
2445 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2447 setJoystickDeviceToNr(device_name, new_device_nr);
2448 setup.input[player_nr].use_joystick = TRUE;
2452 int device_nr = getJoystickNrFromDeviceName(device_name);
2453 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2455 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2456 setup.input[player_nr].use_joystick = FALSE;
2458 setJoystickDeviceToNr(device_name, new_device_nr);
2461 drawPlayerSetupInputInfo(player_nr);
2465 if (setup.input[player_nr].use_joystick)
2468 CalibrateJoystick(player_nr);
2471 CustomizeKeyboard(player_nr);
2473 else if (y == pos_end)
2477 setup_mode = SETUP_MODE_MAIN;
2484 void CustomizeKeyboard(int player_nr)
2488 boolean finished = FALSE;
2489 static struct SetupKeyboardInfo custom_key;
2494 } customize_step[] =
2496 { &custom_key.left, "Move Left" },
2497 { &custom_key.right, "Move Right" },
2498 { &custom_key.up, "Move Up" },
2499 { &custom_key.down, "Move Down" },
2500 { &custom_key.snap, "Snap Field" },
2501 { &custom_key.bomb, "Place Bomb" }
2504 /* read existing key bindings from player setup */
2505 custom_key = setup.input[player_nr].key;
2508 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2514 DrawText(mSX, mSY + (2+2*step_nr)*32,
2515 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2516 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2517 "Key:", FONT_INPUT_1_ACTIVE);
2518 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2519 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2523 if (PendingEvent()) /* got event */
2531 case EVENT_KEYPRESS:
2533 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2535 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2541 /* all keys configured -- wait for "Escape" or "Return" key */
2545 /* press 'Enter' to keep the existing key binding */
2546 if (key == KSYM_Return)
2547 key = *customize_step[step_nr].key;
2549 /* check if key already used */
2550 for (i = 0; i < step_nr; i++)
2551 if (*customize_step[i].key == key)
2556 /* got new key binding */
2557 *customize_step[step_nr].key = key;
2558 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2560 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2561 getKeyNameFromKey(key), FONT_VALUE_1);
2564 /* un-highlight last query */
2565 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2566 customize_step[step_nr-1].text, FONT_MENU_1);
2567 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2568 "Key:", FONT_MENU_1);
2570 /* press 'Enter' to leave */
2573 DrawText(mSX + 16, mSY + 15*32+16,
2574 "Press Enter", FONT_TITLE_1);
2578 /* query next key binding */
2579 DrawText(mSX, mSY+(2+2*step_nr)*32,
2580 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2581 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2582 "Key:", FONT_INPUT_1_ACTIVE);
2583 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2584 getKeyNameFromKey(*customize_step[step_nr].key),
2589 case EVENT_KEYRELEASE:
2590 key_joystick_mapping = 0;
2594 HandleOtherEvents(&event);
2602 /* don't eat all CPU time */
2606 /* write new key bindings back to player setup */
2607 setup.input[player_nr].key = custom_key;
2610 DrawSetupScreen_Input();
2613 static boolean CalibrateJoystickMain(int player_nr)
2615 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2616 int new_joystick_xright = JOYSTICK_XMIDDLE;
2617 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2618 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2619 int new_joystick_xmiddle, new_joystick_ymiddle;
2621 int joystick_fd = joystick.fd[player_nr];
2622 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2623 boolean check[3][3];
2624 int check_remaining = 3 * 3;
2629 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2632 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2637 for (y = 0; y < 3; y++)
2639 for (x = 0; x < 3; x++)
2641 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2642 check[x][y] = FALSE;
2646 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2647 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2648 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2649 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2650 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2651 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2652 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2654 joy_value = Joystick(player_nr);
2655 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2656 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2658 /* eventually uncalibrated center position (joystick could be uncentered) */
2659 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2662 new_joystick_xmiddle = joy_x;
2663 new_joystick_ymiddle = joy_y;
2665 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2668 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2673 if (PendingEvent()) /* got event */
2681 case EVENT_KEYPRESS:
2682 switch(GetEventKey((KeyEvent *)&event, TRUE))
2685 if (check_remaining == 0)
2698 case EVENT_KEYRELEASE:
2699 key_joystick_mapping = 0;
2703 HandleOtherEvents(&event);
2708 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2711 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2712 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2713 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2714 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2716 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2717 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2718 setup.input[player_nr].joy.xright = new_joystick_xright;
2719 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2720 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2721 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2723 CheckJoystickData();
2725 joy_value = Joystick(player_nr);
2727 if (joy_value & JOY_BUTTON && check_remaining == 0)
2730 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2731 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2733 if (x != last_x || y != last_y)
2735 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2736 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2741 if (check_remaining > 0 && !check[x+1][y+1])
2743 check[x+1][y+1] = TRUE;
2749 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2750 setup.input[player_nr].joy.xleft,
2751 setup.input[player_nr].joy.xmiddle,
2752 setup.input[player_nr].joy.xright);
2753 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2754 setup.input[player_nr].joy.yupper,
2755 setup.input[player_nr].joy.ymiddle,
2756 setup.input[player_nr].joy.ylower);
2765 /* don't eat all CPU time */
2769 /* calibrated center position (joystick should now be centered) */
2770 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2773 new_joystick_xmiddle = joy_x;
2774 new_joystick_ymiddle = joy_y;
2778 DrawSetupScreen_Input();
2780 /* wait until the last pressed button was released */
2781 while (Joystick(player_nr) & JOY_BUTTON)
2783 if (PendingEvent()) /* got event */
2788 HandleOtherEvents(&event);
2797 void CalibrateJoystick(int player_nr)
2799 if (!CalibrateJoystickMain(player_nr))
2803 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
2804 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
2806 Delay(2000); /* show error message for two seconds */
2810 void DrawSetupScreen()
2812 DeactivateJoystick();
2814 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2816 if (setup_mode == SETUP_MODE_INPUT)
2817 DrawSetupScreen_Input();
2818 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2819 DrawChooseTree(&artwork.gfx_current);
2820 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2821 DrawChooseTree(&artwork.snd_current);
2822 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2823 DrawChooseTree(&artwork.mus_current);
2825 DrawSetupScreen_Generic();
2831 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2833 if (setup_mode == SETUP_MODE_INPUT)
2834 HandleSetupScreen_Input(mx, my, dx, dy, button);
2835 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2836 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2837 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2838 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2839 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2840 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2842 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2847 void HandleGameActions()
2849 if (game_status != GAME_MODE_PLAYING)
2852 if (local_player->LevelSolved)
2855 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2861 if (tape.auto_play && !tape.playing)
2862 AutoPlayTape(); /* continue automatically playing next tape */
2865 /* ---------- new screen button stuff -------------------------------------- */
2867 /* graphic position and size values for buttons and scrollbars */
2868 #define SC_SCROLLBUTTON_XSIZE TILEX
2869 #define SC_SCROLLBUTTON_YSIZE TILEY
2871 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2872 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
2873 SC_SCROLLBUTTON_YSIZE)
2874 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2875 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
2876 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2877 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
2878 SC_SCROLLBUTTON_YSIZE)
2879 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2880 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
2881 SC_SCROLL_VERTICAL_YSIZE)
2883 #define SC_BORDER_SIZE 14
2887 int gfx_unpressed, gfx_pressed;
2891 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2894 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2895 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2896 SCREEN_CTRL_ID_SCROLL_UP,
2900 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2901 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2902 SCREEN_CTRL_ID_SCROLL_DOWN,
2909 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2910 Bitmap **gfx_unpressed, **gfx_pressed;
2912 int gfx_unpressed, gfx_pressed;
2919 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2922 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2923 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
2925 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
2927 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
2928 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
2929 GD_TYPE_SCROLLBAR_VERTICAL,
2930 SCREEN_CTRL_ID_SCROLL_VERTICAL,
2931 "scroll level series vertically"
2935 static void CreateScreenScrollbuttons()
2937 struct GadgetInfo *gi;
2938 unsigned long event_mask;
2941 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
2943 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2944 int gfx_unpressed, gfx_pressed;
2945 int x, y, width, height;
2946 int gd_x1, gd_x2, gd_y1, gd_y2;
2947 int id = scrollbutton_info[i].gadget_id;
2949 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2951 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
2952 y = mSY + scrollbutton_info[i].y;
2953 width = SC_SCROLLBUTTON_XSIZE;
2954 height = SC_SCROLLBUTTON_YSIZE;
2956 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
2957 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
2958 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
2960 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
2961 gfx_pressed = scrollbutton_info[i].gfx_pressed;
2962 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
2963 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
2964 gd_x1 = graphic_info[gfx_unpressed].src_x;
2965 gd_y1 = graphic_info[gfx_unpressed].src_y;
2966 gd_x2 = graphic_info[gfx_pressed].src_x;
2967 gd_y2 = graphic_info[gfx_pressed].src_y;
2969 gi = CreateGadget(GDI_CUSTOM_ID, id,
2970 GDI_CUSTOM_TYPE_ID, i,
2971 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
2976 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
2977 GDI_STATE, GD_BUTTON_UNPRESSED,
2978 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
2979 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
2980 GDI_DIRECT_DRAW, FALSE,
2981 GDI_EVENT_MASK, event_mask,
2982 GDI_CALLBACK_ACTION, HandleScreenGadgets,
2986 Error(ERR_EXIT, "cannot create gadget");
2988 screen_gadget[id] = gi;
2992 static void CreateScreenScrollbars()
2996 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
2998 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
2999 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3000 int gfx_unpressed, gfx_pressed;
3002 int x, y, width, height;
3003 int gd_x1, gd_x2, gd_y1, gd_y2;
3004 struct GadgetInfo *gi;
3005 int items_max, items_visible, item_position;
3006 unsigned long event_mask;
3007 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3008 int id = scrollbar_info[i].gadget_id;
3010 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3012 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3013 y = mSY + scrollbar_info[i].y;
3014 width = scrollbar_info[i].width;
3015 height = scrollbar_info[i].height;
3017 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3018 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3020 items_max = num_page_entries;
3021 items_visible = num_page_entries;
3024 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3025 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3026 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3032 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3033 gfx_pressed = scrollbar_info[i].gfx_pressed;
3034 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3035 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3036 gd_x1 = graphic_info[gfx_unpressed].src_x;
3037 gd_y1 = graphic_info[gfx_unpressed].src_y;
3038 gd_x2 = graphic_info[gfx_pressed].src_x;
3039 gd_y2 = graphic_info[gfx_pressed].src_y;
3042 gi = CreateGadget(GDI_CUSTOM_ID, id,
3043 GDI_CUSTOM_TYPE_ID, i,
3044 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3049 GDI_TYPE, scrollbar_info[i].type,
3050 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3051 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3052 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3053 GDI_STATE, GD_BUTTON_UNPRESSED,
3054 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3055 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3056 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3057 GDI_DIRECT_DRAW, FALSE,
3058 GDI_EVENT_MASK, event_mask,
3059 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3063 Error(ERR_EXIT, "cannot create gadget");
3065 screen_gadget[id] = gi;
3069 void CreateScreenGadgets()
3071 int last_game_status = game_status; /* save current game status */
3073 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3076 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3078 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3080 /* copy pointers to clip mask and GC */
3081 scrollbar_bitmap[i]->clip_mask =
3082 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3083 scrollbar_bitmap[i]->stored_clip_gc =
3084 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3086 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3087 scrollbar_bitmap[i],
3088 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3089 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3090 TILEX, TILEY, 0, 0);
3094 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3095 game_status = GAME_MODE_LEVELS;
3097 CreateScreenScrollbuttons();
3098 CreateScreenScrollbars();
3100 game_status = last_game_status; /* restore current game status */
3103 void FreeScreenGadgets()
3107 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3108 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3110 /* prevent freeing clip mask and GC twice */
3111 scrollbar_bitmap[i]->clip_mask = None;
3112 scrollbar_bitmap[i]->stored_clip_gc = None;
3114 FreeBitmap(scrollbar_bitmap[i]);
3118 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3119 FreeGadget(screen_gadget[i]);
3122 void MapChooseTreeGadgets(TreeInfo *ti)
3124 int num_entries = numTreeInfoInGroup(ti);
3127 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3130 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3131 MapGadget(screen_gadget[i]);
3135 void UnmapChooseTreeGadgets()
3139 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3140 UnmapGadget(screen_gadget[i]);
3144 static void HandleScreenGadgets(struct GadgetInfo *gi)
3146 int id = gi->custom_id;
3148 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3153 case SCREEN_CTRL_ID_SCROLL_UP:
3154 if (game_status == GAME_MODE_LEVELS)
3155 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3156 else if (game_status == GAME_MODE_SETUP)
3157 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3160 case SCREEN_CTRL_ID_SCROLL_DOWN:
3161 if (game_status == GAME_MODE_LEVELS)
3162 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3163 else if (game_status == GAME_MODE_SETUP)
3164 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3167 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3168 if (game_status == GAME_MODE_LEVELS)
3169 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3170 else if (game_status == GAME_MODE_SETUP)
3171 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);