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_1 4
33 #define SETUP_MODE_SHORTCUT_2 5
34 #define SETUP_MODE_GRAPHICS 6
35 #define SETUP_MODE_SOUND 7
36 #define SETUP_MODE_ARTWORK 8
37 #define SETUP_MODE_CHOOSE_GRAPHICS 9
38 #define SETUP_MODE_CHOOSE_SOUNDS 10
39 #define SETUP_MODE_CHOOSE_MUSIC 11
41 #define MAX_SETUP_MODES 12
43 /* for input setup functions */
44 #define SETUPINPUT_SCREEN_POS_START 0
45 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
46 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
47 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
49 /* screens on the info screen */
50 #define INFO_MODE_MAIN 0
51 #define INFO_MODE_TITLESCREEN 1
52 #define INFO_MODE_ELEMENTS 2
53 #define INFO_MODE_MUSIC 3
54 #define INFO_MODE_CREDITS 4
55 #define INFO_MODE_PROGRAM 5
56 #define INFO_MODE_LEVELSET 6
58 #define MAX_INFO_MODES 7
60 /* for various menu stuff */
61 #define MENU_SCREEN_START_XPOS 1
62 #define MENU_SCREEN_START_YPOS 2
63 #define MENU_SCREEN_VALUE_XPOS 14
64 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
65 #define MENU_TITLE1_YPOS 8
66 #define MENU_TITLE2_YPOS 46
67 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
68 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
69 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
70 MENU_SCREEN_START_XPOS)
71 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
73 /* buttons and scrollbars identifiers */
74 #define SCREEN_CTRL_ID_SCROLL_UP 0
75 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
76 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
78 #define NUM_SCREEN_SCROLLBUTTONS 2
79 #define NUM_SCREEN_SCROLLBARS 1
80 #define NUM_SCREEN_GADGETS 3
82 /* graphic position and size values for buttons and scrollbars */
83 #define SC_SCROLLBUTTON_XSIZE TILEX
84 #define SC_SCROLLBUTTON_YSIZE TILEY
86 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
88 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
89 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
90 SC_SCROLLBUTTON_YSIZE)
92 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
93 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
95 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
96 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
97 SC_SCROLLBUTTON_YSIZE)
99 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
100 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
101 SC_SCROLL_VERTICAL_YSIZE)
103 #define SC_BORDER_SIZE 14
106 /* forward declarations of internal functions */
107 static void HandleScreenGadgets(struct GadgetInfo *);
108 static void HandleSetupScreen_Generic(int, int, int, int, int);
109 static void HandleSetupScreen_Input(int, int, int, int, int);
110 static void CustomizeKeyboard(int);
111 static void CalibrateJoystick(int);
112 static void execSetupArtwork(void);
113 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
115 static void DrawChooseLevel(void);
116 static void DrawInfoScreen(void);
117 static void DrawSetupScreen(void);
119 static void DrawInfoScreenExt(int);
120 static void DrawInfoScreen_HelpAnim(int, int, boolean);
121 static void DrawInfoScreen_HelpText(int, int, int, int);
122 static void HandleInfoScreen_Main(int, int, int, int, int);
123 static void HandleInfoScreen_TitleScreen(int);
124 static void HandleInfoScreen_Elements(int);
125 static void HandleInfoScreen_Music(int);
126 static void HandleInfoScreen_Credits(int);
127 static void HandleInfoScreen_Program(int);
129 static void MapChooseTreeGadgets(TreeInfo *);
131 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
132 static int setup_mode = SETUP_MODE_MAIN;
133 static int info_mode = INFO_MODE_MAIN;
135 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
136 x <= GAME_MODE_SETUP ? x : \
137 x == GAME_MODE_PSEUDO_TYPENAME ? \
138 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
140 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
141 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
143 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
144 menu.list_size[game_status] : \
145 MAX_MENU_ENTRIES_ON_SCREEN)
147 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
148 #define NUM_SCROLLBAR_BITMAPS 2
149 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
153 static void drawCursorExt(int xpos, int ypos, int color, int g)
155 static int cursor_array[SCR_FIELDY];
160 cursor_array[ypos] = g;
162 g = cursor_array[ypos];
166 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
167 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
168 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
169 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
170 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
171 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
172 IMG_MENU_BUTTON_ACTIVE);
174 ypos += MENU_SCREEN_START_YPOS;
176 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
177 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
180 static void initCursor(int ypos, int graphic)
182 drawCursorExt(0, ypos, FC_BLUE, graphic);
185 static void drawCursor(int ypos, int color)
187 drawCursorExt(0, ypos, color, 0);
190 static void drawCursorXY(int xpos, int ypos, int graphic)
192 drawCursorExt(xpos, ypos, -1, graphic);
195 static void drawChooseTreeCursor(int ypos, int color)
197 int last_game_status = game_status; /* save current game status */
199 /* force LEVELS draw offset on artwork setup screen */
200 game_status = GAME_MODE_LEVELS;
202 drawCursorExt(0, ypos, color, 0);
204 game_status = last_game_status; /* restore current game status */
209 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
210 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
213 static void ToggleFullscreenIfNeeded()
215 if (setup.fullscreen != video.fullscreen_enabled)
217 /* save old door content */
218 BlitBitmap(backbuffer, bitmap_db_door,
219 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
221 /* toggle fullscreen */
222 ChangeVideoModeIfNeeded(setup.fullscreen);
223 setup.fullscreen = video.fullscreen_enabled;
225 /* redraw background to newly created backbuffer */
226 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
227 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
229 /* restore old door content */
230 BlitBitmap(bitmap_db_door, backbuffer,
231 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
233 redraw_mask = REDRAW_ALL;
237 static int getLastLevelButtonPos()
242 static int getCurrentLevelTextPos()
244 return (getLastLevelButtonPos() + 1);
247 static int getNextLevelButtonPos()
249 return getLastLevelButtonPos() + 3 + 1;
252 static int getLevelRangeTextPos()
254 return getNextLevelButtonPos() + 1;
257 void DrawTitleScreenImage(int nr)
259 int graphic = IMG_TITLESCREEN_1 + nr;
260 Bitmap *bitmap = graphic_info[graphic].bitmap;
261 int width = graphic_info[graphic].src_image_width;
262 int height = graphic_info[graphic].src_image_height;
263 int src_x = 0, src_y = 0;
269 if (width > WIN_XSIZE)
271 /* image width too large for window => center image horizontally */
272 src_x = (width - WIN_XSIZE) / 2;
276 if (height > WIN_YSIZE)
278 /* image height too large for window => center image vertically */
279 src_y = (height - WIN_YSIZE) / 2;
283 dst_x = (WIN_XSIZE - width) / 2;
284 dst_y = (WIN_YSIZE - height) / 2;
286 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
288 if (DrawingOnBackground(dst_x, dst_y))
289 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
291 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
293 redraw_mask = REDRAW_ALL;
296 void DrawTitleScreen()
298 KeyboardAutoRepeatOff();
300 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
305 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
310 static void DrawMainMenuExt(int fade_delay)
312 static LevelDirTree *leveldir_last_valid = NULL;
313 boolean levelset_has_changed = FALSE;
314 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
316 char *level_text = "Levelset";
318 char *level_text = "Level:";
320 int name_width, level_width;
324 FadeSoundsAndMusic();
326 KeyboardAutoRepeatOn();
329 SetDrawDeactivationMask(REDRAW_NONE);
330 SetDrawBackgroundMask(REDRAW_FIELD);
332 audio.sound_deactivated = FALSE;
338 /* needed if last screen was the playing screen, invoked from level editor */
339 if (level_editor_test_game)
341 game_status = GAME_MODE_EDITOR;
347 /* needed if last screen was the editor screen */
348 UndrawSpecialEditorDoor();
350 /* needed if last screen was the setup screen and fullscreen state changed */
351 ToggleFullscreenIfNeeded();
353 /* leveldir_current may be invalid (level group, parent link) */
354 if (!validLevelSeries(leveldir_current))
355 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
357 if (leveldir_current != leveldir_last_valid)
358 levelset_has_changed = TRUE;
360 /* store valid level series information */
361 leveldir_last_valid = leveldir_current;
363 /* needed if last screen (level choice) changed graphics, sounds or music */
364 ReloadCustomArtwork(0);
367 SetDrawtoField(DRAW_BACKBUFFER);
370 if (setup.show_titlescreen &&
371 levelset_has_changed &&
372 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
374 game_status = GAME_MODE_TITLE;
381 /* map gadgets for main menu screen */
385 /* level_nr may have been set to value over handicap with level editor */
386 if (setup.handicap && level_nr > leveldir_current->handicap_level)
387 level_nr = leveldir_current->handicap_level;
394 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
399 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
400 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
401 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
402 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
403 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
404 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
405 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
406 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
408 /* calculated after (possible) reload of custom artwork */
409 name_width = getTextWidth(name_text, FONT_MENU_1);
411 level_width = 9 * 32;
414 level_width = 9 * getFontWidth(FONT_MENU_1);
416 level_width = getTextWidth(level_text, FONT_MENU_1);
420 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
424 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
425 int2str(level_nr, 3), FONT_VALUE_1);
428 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
431 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
436 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
442 int text_height = getFontHeight(FONT_TEXT_3);
444 int xpos = getLevelRangeTextPos() * 32;
446 int xpos = level_width + 6 * 32;
448 int ypos2 = -SY + 3 * 32 + 16;
449 int ypos1 = ypos2 - text_height;
451 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
452 "%03d", leveldir_current->first_level);
453 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
454 "%03d", leveldir_current->last_level);
457 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
458 "%d", leveldir_current->levels);
462 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
463 leveldir_current->first_level, leveldir_current->last_level);
467 if (leveldir_current->readonly)
469 DrawTextS(mSX + level_width + 9 * 32 - 2,
470 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
471 DrawTextS(mSX + level_width + 9 * 32 - 2,
472 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
476 for (i = 0; i < 8; i++)
477 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
481 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
482 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
485 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
486 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
488 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
489 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
493 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
502 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
505 if (TAPE_IS_EMPTY(tape))
507 DrawCompleteVideoDisplay();
514 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
517 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
519 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
528 /* map gadgets for main menu screen */
545 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
555 static void gotoTopLevelDir()
557 /* move upwards to top level directory */
558 while (leveldir_current->node_parent)
560 /* write a "path" into level tree for easy navigation to last level */
561 if (leveldir_current->node_parent->node_group->cl_first == -1)
563 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
564 int leveldir_pos = posTreeInfo(leveldir_current);
565 int num_page_entries;
566 int cl_first, cl_cursor;
568 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
569 num_page_entries = num_leveldirs;
571 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
573 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
574 cl_cursor = leveldir_pos - cl_first;
576 leveldir_current->node_parent->node_group->cl_first = cl_first;
577 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
580 leveldir_current = leveldir_current->node_parent;
585 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
587 static int title_nr = 0;
588 boolean return_to_main_menu = FALSE;
589 boolean use_fading_main_menu = TRUE;
590 boolean use_cross_fading = TRUE;
591 int fade_delay = 500;
592 int post_delay = fade_delay / 2;
594 if (button == MB_MENU_INITIALIZE)
598 if (game_status == GAME_MODE_INFO)
600 FadeSoundsAndMusic();
602 FadeOut(fade_delay, post_delay);
605 DrawTitleScreenImage(title_nr);
611 else if (button == MB_MENU_LEAVE)
613 return_to_main_menu = TRUE;
614 use_fading_main_menu = FALSE;
616 else if (button == MB_MENU_CHOICE)
620 if (!use_cross_fading)
621 FadeOut(fade_delay, post_delay);
623 if (title_nr < MAX_NUM_TITLE_SCREENS &&
624 graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
626 Bitmap *drawto_last = drawto;
628 if (use_cross_fading)
629 drawto = bitmap_db_title;
631 DrawTitleScreenImage(title_nr);
633 drawto = drawto_last;
635 if (use_cross_fading)
636 FadeCross(fade_delay);
642 FadeSoundsAndMusic();
644 FadeOut(fade_delay, post_delay);
646 return_to_main_menu = TRUE;
650 if (return_to_main_menu)
652 int menu_fade_delay = (use_fading_main_menu ? fade_delay : 0);
656 if (game_status == GAME_MODE_INFO)
658 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
660 info_mode = INFO_MODE_MAIN;
661 DrawInfoScreenExt(menu_fade_delay);
663 else /* default: return to main menu */
665 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
667 game_status = GAME_MODE_MAIN;
668 DrawMainMenuExt(menu_fade_delay);
673 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
675 static unsigned long level_delay = 0;
676 static int choice = 5;
680 if (button == MB_MENU_INITIALIZE)
682 drawCursor(choice, FC_RED);
686 if (mx || my) /* mouse input */
689 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
691 else if (dx || dy) /* keyboard input */
693 if (dx && choice == 1)
694 x = (dx < 0 ? 10 : 14);
697 if (choice == 4 || choice == 6)
698 button = MB_MENU_CHOICE;
704 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
705 (x == 14 && level_nr < leveldir_current->last_level)) &&
706 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
708 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
709 int old_level_nr = level_nr;
712 new_level_nr = level_nr + (x == 10 ? -step : +step);
713 if (new_level_nr < leveldir_current->first_level)
714 new_level_nr = leveldir_current->first_level;
715 if (new_level_nr > leveldir_current->last_level)
716 new_level_nr = leveldir_current->last_level;
718 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
720 /* skipping levels is only allowed when trying to skip single level */
721 if (setup.skip_levels && step == 1 &&
722 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
724 leveldir_current->handicap_level++;
725 SaveLevelSetup_SeriesInfo();
728 new_level_nr = leveldir_current->handicap_level;
731 if (new_level_nr != old_level_nr)
733 level_nr = new_level_nr;
735 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
739 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
743 DrawCompleteVideoDisplay();
745 /* needed because DrawMicroLevel() takes some time */
748 DelayReached(&level_delay, 0); /* reset delay counter */
751 else if (IN_VIS_FIELD(x, y) &&
752 y >= 0 && y <= 7 && (y != 1 || x < 10))
758 drawCursor(y, FC_RED);
759 drawCursor(choice, FC_BLUE);
767 game_status = GAME_MODE_PSEUDO_TYPENAME;
768 HandleTypeName(strlen(setup.player_name), 0);
774 game_status = GAME_MODE_LEVELS;
775 SaveLevelSetup_LastSeries();
776 SaveLevelSetup_SeriesInfo();
787 game_status = GAME_MODE_SCORES;
792 if (leveldir_current->readonly &&
793 !strEqual(setup.player_name, "Artsoft"))
794 Request("This level is read only !", REQ_CONFIRM);
795 game_status = GAME_MODE_EDITOR;
800 game_status = GAME_MODE_INFO;
801 info_mode = INFO_MODE_MAIN;
806 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
810 game_status = GAME_MODE_SETUP;
811 setup_mode = SETUP_MODE_MAIN;
817 SaveLevelSetup_LastSeries();
818 SaveLevelSetup_SeriesInfo();
820 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
821 game_status = GAME_MODE_QUIT;
826 if (game_status == GAME_MODE_MAIN)
828 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
834 /* ========================================================================= */
835 /* info screen functions */
836 /* ========================================================================= */
838 static struct TokenInfo *info_info;
839 static int num_info_info;
841 static void execInfoTitleScreen()
843 info_mode = INFO_MODE_TITLESCREEN;
847 static void execInfoElements()
849 info_mode = INFO_MODE_ELEMENTS;
853 static void execInfoMusic()
855 info_mode = INFO_MODE_MUSIC;
859 static void execInfoCredits()
861 info_mode = INFO_MODE_CREDITS;
865 static void execInfoProgram()
867 info_mode = INFO_MODE_PROGRAM;
871 static void execInfoLevelSet()
873 info_mode = INFO_MODE_LEVELSET;
877 static void execExitInfo()
879 game_status = GAME_MODE_MAIN;
883 static struct TokenInfo info_info_main[] =
885 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
886 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
887 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
888 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
889 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
890 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
891 { TYPE_EMPTY, NULL, "" },
892 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
897 static void DrawInfoScreen_Main(int fade_delay)
902 CloseDoor(DOOR_CLOSE_2);
907 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
909 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
912 info_info = info_info_main;
915 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
917 int xpos = MENU_SCREEN_START_XPOS;
918 int ypos = MENU_SCREEN_START_YPOS + i;
919 int font_nr = FONT_MENU_1;
921 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
923 if (info_info[i].type & TYPE_ENTER_MENU)
924 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
925 else if (info_info[i].type & TYPE_LEAVE_MENU)
926 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
927 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
928 initCursor(i, IMG_MENU_BUTTON);
935 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
951 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
955 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
957 static int choice_store[MAX_INFO_MODES];
958 int choice = choice_store[info_mode]; /* always starts with 0 */
962 if (button == MB_MENU_INITIALIZE)
964 /* advance to first valid menu entry */
965 while (choice < num_info_info &&
966 info_info[choice].type & TYPE_SKIP_ENTRY)
968 choice_store[info_mode] = choice;
970 drawCursor(choice, FC_RED);
973 else if (button == MB_MENU_LEAVE)
975 for (y = 0; y < num_info_info; y++)
977 if (info_info[y].type & TYPE_LEAVE_MENU)
979 void (*menu_callback_function)(void) = info_info[y].value;
981 menu_callback_function();
982 break; /* absolutely needed because function changes 'info_info'! */
989 if (mx || my) /* mouse input */
992 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
994 else if (dx || dy) /* keyboard input */
998 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1000 if (info_info[choice].type & menu_navigation_type ||
1001 info_info[choice].type & TYPE_ENTER_SCREEN ||
1002 info_info[choice].type & TYPE_BOOLEAN_STYLE)
1003 button = MB_MENU_CHOICE;
1008 /* jump to next non-empty menu entry (up or down) */
1009 while (y > 0 && y < num_info_info - 1 &&
1010 info_info[y].type & TYPE_SKIP_ENTRY)
1014 if (IN_VIS_FIELD(x, y) &&
1015 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
1021 drawCursor(y, FC_RED);
1022 drawCursor(choice, FC_BLUE);
1023 choice = choice_store[info_mode] = y;
1026 else if (!(info_info[y].type & TYPE_GHOSTED))
1028 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1030 void (*menu_callback_function)(void) = info_info[choice].value;
1032 menu_callback_function();
1038 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
1040 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
1041 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
1042 int xstart = mSX + 16;
1043 int ystart = mSY + 64 + 2 * 32;
1044 int ystep = TILEY + 4;
1045 int element, action, direction;
1053 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
1054 infoscreen_step[i] = infoscreen_frame[i] = 0;
1059 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
1061 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1062 "Press any key or button for next page");
1068 while (helpanim_info[j].element != HELPANIM_LIST_END)
1070 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1075 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1084 j += infoscreen_step[i - start];
1086 element = helpanim_info[j].element;
1087 action = helpanim_info[j].action;
1088 direction = helpanim_info[j].direction;
1091 element = EL_UNKNOWN;
1093 if (action != -1 && direction != -1)
1094 graphic = el_act_dir2img(element, action, direction);
1095 else if (action != -1)
1096 graphic = el_act2img(element, action);
1097 else if (direction != -1)
1098 graphic = el_dir2img(element, direction);
1100 graphic = el2img(element);
1102 delay = helpanim_info[j++].delay;
1107 if (infoscreen_frame[i - start] == 0)
1110 infoscreen_frame[i - start] = delay - 1;
1114 sync_frame = delay - infoscreen_frame[i - start];
1115 infoscreen_frame[i - start]--;
1118 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1120 if (!infoscreen_frame[i - start])
1121 infoscreen_step[i - start] = 0;
1125 if (!infoscreen_frame[i - start])
1126 infoscreen_step[i - start]++;
1127 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1133 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1135 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1136 graphic, sync_frame, USE_MASKING);
1139 DrawInfoScreen_HelpText(element, action, direction, i - start);
1144 redraw_mask |= REDRAW_FIELD;
1149 static char *getHelpText(int element, int action, int direction)
1151 char token[MAX_LINE_LEN];
1153 strcpy(token, element_info[element].token_name);
1156 strcat(token, element_action_info[action].suffix);
1158 if (direction != -1)
1159 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1161 return getHashEntry(helptext_info, token);
1164 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1166 int font_nr = FONT_LEVEL_NUMBER;
1167 int font_width = getFontWidth(font_nr);
1168 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1169 int sy = mSY + 65 + 2 * 32 + 1;
1170 int ystep = TILEY + 4;
1171 int pad_x = sx - SX;
1172 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1173 int max_lines_per_text = 2;
1176 if (action != -1 && direction != -1) /* element.action.direction */
1177 text = getHelpText(element, action, direction);
1179 if (text == NULL && action != -1) /* element.action */
1180 text = getHelpText(element, action, -1);
1182 if (text == NULL && direction != -1) /* element.direction */
1183 text = getHelpText(element, -1, direction);
1185 if (text == NULL) /* base element */
1186 text = getHelpText(element, -1, -1);
1188 if (text == NULL) /* not found */
1189 text = "No description available";
1191 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1192 sy += getFontHeight(font_nr) / 2;
1194 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1195 max_chars_per_line, max_lines_per_text);
1198 void DrawInfoScreen_TitleScreen()
1203 void HandleInfoScreen_TitleScreen(int button)
1205 HandleTitleScreen(0, 0, 0, 0, button);
1208 void DrawInfoScreen_Elements()
1210 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1215 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1221 void HandleInfoScreen_Elements(int button)
1223 static unsigned long info_delay = 0;
1224 static int num_anims;
1225 static int num_pages;
1227 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1228 int button_released = !button;
1231 if (button == MB_MENU_INITIALIZE)
1233 boolean new_element = TRUE;
1236 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1238 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1240 else if (new_element)
1243 new_element = FALSE;
1247 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1250 else if (button == MB_MENU_LEAVE)
1252 info_mode = INFO_MODE_MAIN;
1258 if (button_released || button == MB_MENU_INITIALIZE)
1260 if (button != MB_MENU_INITIALIZE)
1263 if (page >= num_pages)
1265 FadeSoundsAndMusic();
1267 info_mode = INFO_MODE_MAIN;
1273 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1277 if (DelayReached(&info_delay, GameFrameDelay))
1278 if (page < num_pages)
1279 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1281 PlayMenuSoundIfLoop();
1285 void DrawInfoScreen_Music()
1287 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1294 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1297 void HandleInfoScreen_Music(int button)
1299 static struct MusicFileInfo *list = NULL;
1300 int ystart = 150, dy = 30;
1301 int ybottom = SYSIZE - 20;
1302 int button_released = !button;
1304 if (button == MB_MENU_INITIALIZE)
1306 list = music_file_info;
1310 FadeSoundsAndMusic();
1315 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1317 DrawTextSCentered(ybottom, FONT_TEXT_4,
1318 "Press any key or button for info menu");
1323 else if (button == MB_MENU_LEAVE)
1325 info_mode = INFO_MODE_MAIN;
1331 if (button_released || button == MB_MENU_INITIALIZE)
1335 if (button != MB_MENU_INITIALIZE)
1341 info_mode = INFO_MODE_MAIN;
1347 FadeSoundsAndMusic();
1354 int sound = list->music;
1356 if (sound_info[sound].loop)
1357 PlaySoundLoop(sound);
1361 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1365 PlayMusic(list->music);
1367 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1370 if (!strEqual(list->title, UNKNOWN_NAME))
1372 if (!strEqual(list->title_header, UNKNOWN_NAME))
1373 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1375 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1378 if (!strEqual(list->artist, UNKNOWN_NAME))
1380 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1381 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1383 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1385 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1388 if (!strEqual(list->album, UNKNOWN_NAME))
1390 if (!strEqual(list->album_header, UNKNOWN_NAME))
1391 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1393 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1395 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1398 if (!strEqual(list->year, UNKNOWN_NAME))
1400 if (!strEqual(list->year_header, UNKNOWN_NAME))
1401 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1403 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1405 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1408 DrawTextSCentered(ybottom, FONT_TEXT_4,
1409 "Press any key or button for next page");
1412 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1413 PlaySoundLoop(list->music);
1416 void DrawInfoScreen_Credits()
1418 int ystart = 150, ystep = 30;
1419 int ybottom = SYSIZE - 20;
1421 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1423 FadeSoundsAndMusic();
1428 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1429 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1430 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1431 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1432 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1433 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1434 "...and many thanks to all contributors");
1435 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1437 DrawTextSCentered(ybottom, FONT_TEXT_4,
1438 "Press any key or button for info menu");
1441 void HandleInfoScreen_Credits(int button)
1443 int button_released = !button;
1445 if (button == MB_MENU_LEAVE)
1447 info_mode = INFO_MODE_MAIN;
1453 if (button_released)
1455 FadeSoundsAndMusic();
1457 info_mode = INFO_MODE_MAIN;
1462 PlayMenuSoundIfLoop();
1466 void DrawInfoScreen_Program()
1468 int ystart = 150, ystep = 30;
1469 int ybottom = SYSIZE - 20;
1471 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1476 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1478 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1479 "This game is Freeware!");
1480 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1481 "If you like it, send e-mail to:");
1482 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1483 "info@artsoft.org");
1484 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1485 "or SnailMail to:");
1486 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1488 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1489 "Detmolder Strasse 189");
1490 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1492 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1495 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1496 "If you have created new levels,");
1497 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1498 "send them to me to include them!");
1499 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1502 DrawTextSCentered(ybottom, FONT_TEXT_4,
1503 "Press any key or button for info menu");
1506 void HandleInfoScreen_Program(int button)
1508 int button_released = !button;
1510 if (button == MB_MENU_LEAVE)
1512 info_mode = INFO_MODE_MAIN;
1518 if (button_released)
1520 FadeSoundsAndMusic();
1522 info_mode = INFO_MODE_MAIN;
1527 PlayMenuSoundIfLoop();
1531 void DrawInfoScreen_LevelSet()
1534 int ybottom = SYSIZE - 20;
1535 char *filename = getLevelSetInfoFilename();
1536 int font_nr = FONT_LEVEL_NUMBER;
1537 int font_width = getFontWidth(font_nr);
1538 int font_height = getFontHeight(font_nr);
1541 int sx = SX + pad_x;
1542 int sy = SY + pad_y;
1543 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1544 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1546 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1551 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1553 DrawTextSCentered(ybottom, FONT_TEXT_4,
1554 "Press any key or button for info menu");
1556 if (filename != NULL)
1557 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1558 max_lines_per_screen);
1560 DrawTextSCentered(ystart, FONT_TEXT_2,
1561 "No information for this level set.");
1564 void HandleInfoScreen_LevelSet(int button)
1566 int button_released = !button;
1568 if (button == MB_MENU_LEAVE)
1570 info_mode = INFO_MODE_MAIN;
1576 if (button_released)
1578 FadeSoundsAndMusic();
1580 info_mode = INFO_MODE_MAIN;
1585 PlayMenuSoundIfLoop();
1589 static void DrawInfoScreenExt(int fade_delay)
1591 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1593 if (info_mode == INFO_MODE_TITLESCREEN)
1594 DrawInfoScreen_TitleScreen();
1595 else if (info_mode == INFO_MODE_ELEMENTS)
1596 DrawInfoScreen_Elements();
1597 else if (info_mode == INFO_MODE_MUSIC)
1598 DrawInfoScreen_Music();
1599 else if (info_mode == INFO_MODE_CREDITS)
1600 DrawInfoScreen_Credits();
1601 else if (info_mode == INFO_MODE_PROGRAM)
1602 DrawInfoScreen_Program();
1603 else if (info_mode == INFO_MODE_LEVELSET)
1604 DrawInfoScreen_LevelSet();
1606 DrawInfoScreen_Main(fade_delay);
1608 if (info_mode != INFO_MODE_MUSIC)
1615 void DrawInfoScreen()
1617 DrawInfoScreenExt(0);
1620 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1622 if (info_mode == INFO_MODE_TITLESCREEN)
1623 HandleInfoScreen_TitleScreen(button);
1624 else if (info_mode == INFO_MODE_ELEMENTS)
1625 HandleInfoScreen_Elements(button);
1626 else if (info_mode == INFO_MODE_MUSIC)
1627 HandleInfoScreen_Music(button);
1628 else if (info_mode == INFO_MODE_CREDITS)
1629 HandleInfoScreen_Credits(button);
1630 else if (info_mode == INFO_MODE_PROGRAM)
1631 HandleInfoScreen_Program(button);
1632 else if (info_mode == INFO_MODE_LEVELSET)
1633 HandleInfoScreen_LevelSet(button);
1635 HandleInfoScreen_Main(mx, my, dx, dy, button);
1641 /* ========================================================================= */
1642 /* type name functions */
1643 /* ========================================================================= */
1645 void HandleTypeName(int newxpos, Key key)
1647 static int xpos = 0, ypos = 2;
1648 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1649 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1650 int startx = mSX + 32 + name_width;
1651 int starty = mSY + ypos * 32;
1657 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1658 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1663 if (((key >= KSYM_A && key <= KSYM_Z) ||
1664 (key >= KSYM_a && key <= KSYM_z)) &&
1665 xpos < MAX_PLAYER_NAME_LEN)
1669 if (key >= KSYM_A && key <= KSYM_Z)
1670 ascii = 'A' + (char)(key - KSYM_A);
1672 ascii = 'a' + (char)(key - KSYM_a);
1674 setup.player_name[xpos] = ascii;
1675 setup.player_name[xpos + 1] = 0;
1678 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1679 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1681 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1684 setup.player_name[xpos] = 0;
1686 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1688 else if (key == KSYM_Return && xpos > 0)
1690 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1691 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1694 game_status = GAME_MODE_MAIN;
1699 /* ========================================================================= */
1700 /* tree menu functions */
1701 /* ========================================================================= */
1703 static void DrawChooseTree(TreeInfo **ti_ptr)
1707 FreeScreenGadgets();
1708 CreateScreenGadgets();
1710 CloseDoor(DOOR_CLOSE_2);
1714 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1715 MapChooseTreeGadgets(*ti_ptr);
1721 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1723 struct GadgetInfo *gi = screen_gadget[id];
1724 int items_max, items_visible, item_position;
1726 items_max = numTreeInfoInGroup(ti);
1727 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1728 item_position = first_entry;
1730 if (item_position > items_max - items_visible)
1731 item_position = items_max - items_visible;
1733 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1734 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1735 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1738 static void drawChooseTreeList(int first_entry, int num_page_entries,
1742 char *title_string = NULL;
1744 int xoffset_sets = 16;
1746 int yoffset_sets = MENU_TITLE1_YPOS;
1748 int xoffset_setup = 16;
1750 int yoffset_setup = 16;
1753 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1756 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1759 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1760 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1762 int last_game_status = game_status; /* save current game status */
1765 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1766 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1767 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1768 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1771 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1773 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1776 /* force LEVELS font on artwork setup screen */
1777 game_status = GAME_MODE_LEVELS;
1779 /* clear tree list area, but not title or scrollbar */
1780 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1781 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
1782 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1784 for (i = 0; i < num_page_entries; i++)
1786 TreeInfo *node, *node_first;
1787 int entry_pos = first_entry + i;
1788 int xpos = MENU_SCREEN_START_XPOS;
1789 int ypos = MENU_SCREEN_START_YPOS + i;
1790 int startx = mSX + xpos * 32;
1791 int starty = mSY + ypos * 32;
1792 int font_nr = FONT_TEXT_1;
1793 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
1794 int startx_text = startx + font_xoffset;
1795 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1796 int text_size = startx_scrollbar - startx_text;
1797 int max_buffer_len = text_size / getFontWidth(font_nr);
1798 char buffer[max_buffer_len + 1];
1800 node_first = getTreeInfoFirstGroupEntry(ti);
1801 node = getTreeInfoFromPos(node_first, entry_pos);
1803 strncpy(buffer, node->name, max_buffer_len);
1804 buffer[max_buffer_len] = '\0';
1806 DrawText(startx, starty, buffer, font_nr + node->color);
1808 if (node->parent_link)
1809 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1810 else if (node->level_group)
1811 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1813 initCursor(i, IMG_MENU_BUTTON);
1816 game_status = last_game_status; /* restore current game status */
1818 redraw_mask |= REDRAW_FIELD;
1821 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1823 TreeInfo *node, *node_first;
1824 int x, last_redraw_mask = redraw_mask;
1826 int ypos = MENU_TITLE2_YPOS;
1831 if (ti->type != TREE_TYPE_LEVEL_DIR)
1834 node_first = getTreeInfoFirstGroupEntry(ti);
1835 node = getTreeInfoFromPos(node_first, entry_pos);
1837 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1839 if (node->parent_link)
1840 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1842 else if (node->level_group)
1843 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1845 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1846 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1847 node->levels, node->class_desc);
1849 /* let BackToFront() redraw only what is needed */
1850 redraw_mask = last_redraw_mask | REDRAW_TILES;
1851 for (x = 0; x < SCR_FIELDX; x++)
1852 MarkTileDirty(x, 1);
1855 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1858 TreeInfo *ti = *ti_ptr;
1860 int y = ti->cl_cursor;
1861 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1862 int num_entries = numTreeInfoInGroup(ti);
1863 int num_page_entries;
1864 int last_game_status = game_status; /* save current game status */
1865 boolean position_set_by_scrollbar = (dx == 999);
1867 /* force LEVELS draw offset on choose level and artwork setup screen */
1868 game_status = GAME_MODE_LEVELS;
1870 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1871 num_page_entries = num_entries;
1873 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1875 game_status = last_game_status; /* restore current game status */
1877 if (button == MB_MENU_INITIALIZE)
1879 int num_entries = numTreeInfoInGroup(ti);
1880 int entry_pos = posTreeInfo(ti);
1882 if (ti->cl_first == -1)
1884 /* only on initialization */
1885 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1886 ti->cl_cursor = entry_pos - ti->cl_first;
1888 else if (ti->cl_cursor >= num_page_entries ||
1889 (num_entries > num_page_entries &&
1890 num_entries - ti->cl_first < num_page_entries))
1892 /* only after change of list size (by custom graphic configuration) */
1893 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1894 ti->cl_cursor = entry_pos - ti->cl_first;
1897 if (position_set_by_scrollbar)
1900 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1903 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1904 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1905 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1909 else if (button == MB_MENU_LEAVE)
1911 if (ti->node_parent)
1913 *ti_ptr = ti->node_parent;
1914 DrawChooseTree(ti_ptr);
1916 else if (game_status == GAME_MODE_SETUP)
1922 game_status = GAME_MODE_MAIN;
1929 if (mx || my) /* mouse input */
1931 int last_game_status = game_status; /* save current game status */
1933 /* force LEVELS draw offset on artwork setup screen */
1934 game_status = GAME_MODE_LEVELS;
1936 x = (mx - mSX) / 32;
1937 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1939 game_status = last_game_status; /* restore current game status */
1941 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1943 /* move cursor instead of scrolling when already at start/end of list */
1944 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1946 else if (dy == +1 * SCROLL_LINE &&
1947 ti->cl_first + num_page_entries == num_entries)
1950 /* handle scrolling screen one line or page */
1951 if (ti->cl_cursor + dy < 0 ||
1952 ti->cl_cursor + dy > num_page_entries - 1)
1954 if (ABS(dy) == SCROLL_PAGE)
1955 step = num_page_entries - 1;
1957 if (dy < 0 && ti->cl_first > 0)
1959 /* scroll page/line up */
1961 ti->cl_first -= step;
1962 if (ti->cl_first < 0)
1965 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1966 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1967 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1968 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1971 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1973 /* scroll page/line down */
1975 ti->cl_first += step;
1976 if (ti->cl_first + num_page_entries > num_entries)
1977 ti->cl_first = MAX(0, num_entries - num_page_entries);
1979 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1980 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1981 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1982 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1989 /* handle moving cursor one line */
1990 y = ti->cl_cursor + dy;
1995 TreeInfo *node_first, *node_cursor;
1996 int entry_pos = ti->cl_first + y;
1998 node_first = getTreeInfoFirstGroupEntry(ti);
1999 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2001 if (node_cursor->node_group)
2003 node_cursor->cl_first = ti->cl_first;
2004 node_cursor->cl_cursor = ti->cl_cursor;
2005 *ti_ptr = node_cursor->node_group;
2006 DrawChooseTree(ti_ptr);
2011 else if (dx == -1 && ti->node_parent)
2013 *ti_ptr = ti->node_parent;
2014 DrawChooseTree(ti_ptr);
2019 if (!anyScrollbarGadgetActive() &&
2020 IN_VIS_FIELD(x, y) &&
2021 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2022 y >= 0 && y < num_page_entries)
2026 if (y != ti->cl_cursor)
2028 drawChooseTreeCursor(y, FC_RED);
2029 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
2030 drawChooseTreeInfo(ti->cl_first + y, ti);
2036 TreeInfo *node_first, *node_cursor;
2037 int entry_pos = ti->cl_first + y;
2039 node_first = getTreeInfoFirstGroupEntry(ti);
2040 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2042 if (node_cursor->node_group)
2044 node_cursor->cl_first = ti->cl_first;
2045 node_cursor->cl_cursor = ti->cl_cursor;
2046 *ti_ptr = node_cursor->node_group;
2047 DrawChooseTree(ti_ptr);
2049 else if (node_cursor->parent_link)
2051 *ti_ptr = node_cursor->node_parent;
2052 DrawChooseTree(ti_ptr);
2056 node_cursor->cl_first = ti->cl_first;
2057 node_cursor->cl_cursor = ti->cl_cursor;
2058 *ti_ptr = node_cursor;
2060 if (ti->type == TREE_TYPE_LEVEL_DIR)
2062 LoadLevelSetup_SeriesInfo();
2064 SaveLevelSetup_LastSeries();
2065 SaveLevelSetup_SeriesInfo();
2069 if (game_status == GAME_MODE_SETUP)
2075 game_status = GAME_MODE_MAIN;
2083 void DrawChooseLevel()
2085 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2087 DrawChooseTree(&leveldir_current);
2093 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2095 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2100 void DrawHallOfFame(int highlight_position)
2103 FadeSoundsAndMusic();
2104 CloseDoor(DOOR_CLOSE_2);
2106 if (highlight_position < 0)
2107 LoadScore(level_nr);
2115 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2118 static void drawHallOfFameList(int first_entry, int highlight_position)
2122 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2126 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2127 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2128 "HighScores of Level %d", level_nr);
2130 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2131 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2132 "HighScores of Level %d", level_nr);
2135 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2137 int entry = first_entry + i;
2138 boolean active = (entry == highlight_position);
2139 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2140 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2141 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2142 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2143 int dx1 = 3 * getFontWidth(font_nr1);
2144 int dx2 = dx1 + getFontWidth(font_nr1);
2145 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2146 int sy = mSY + 64 + i * 32;
2148 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2149 DrawText(mSX + dx1, sy, ".", font_nr1);
2150 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2152 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2153 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2155 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2158 redraw_mask |= REDRAW_FIELD;
2161 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2163 static int first_entry = 0;
2164 static int highlight_position = 0;
2165 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2166 int button_released = !button;
2168 if (button == MB_MENU_INITIALIZE)
2171 highlight_position = mx;
2172 drawHallOfFameList(first_entry, highlight_position);
2177 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2178 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2182 if (first_entry > 0)
2184 first_entry -= step;
2185 if (first_entry < 0)
2188 drawHallOfFameList(first_entry, highlight_position);
2193 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2195 first_entry += step;
2196 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2197 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2199 drawHallOfFameList(first_entry, highlight_position);
2202 else if (button_released)
2204 FadeSound(SND_BACKGROUND_SCORES);
2205 game_status = GAME_MODE_MAIN;
2209 if (game_status == GAME_MODE_SCORES)
2210 PlayMenuSoundIfLoop();
2216 /* ========================================================================= */
2217 /* setup screen functions */
2218 /* ========================================================================= */
2220 static struct TokenInfo *setup_info;
2221 static int num_setup_info;
2223 static char *graphics_set_name;
2224 static char *sounds_set_name;
2225 static char *music_set_name;
2227 static void execSetupMain()
2229 setup_mode = SETUP_MODE_MAIN;
2233 static void execSetupGame()
2235 setup_mode = SETUP_MODE_GAME;
2239 static void execSetupEditor()
2241 setup_mode = SETUP_MODE_EDITOR;
2245 static void execSetupGraphics()
2247 setup_mode = SETUP_MODE_GRAPHICS;
2251 static void execSetupSound()
2253 setup_mode = SETUP_MODE_SOUND;
2257 static void execSetupArtwork()
2259 setup.graphics_set = artwork.gfx_current->identifier;
2260 setup.sounds_set = artwork.snd_current->identifier;
2261 setup.music_set = artwork.mus_current->identifier;
2263 /* needed if last screen (setup choice) changed graphics, sounds or music */
2264 ReloadCustomArtwork(0);
2266 /* needed for displaying artwork name instead of artwork identifier */
2267 graphics_set_name = artwork.gfx_current->name;
2268 sounds_set_name = artwork.snd_current->name;
2269 music_set_name = artwork.mus_current->name;
2271 setup_mode = SETUP_MODE_ARTWORK;
2275 static void execSetupChooseGraphics()
2277 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2281 static void execSetupChooseSounds()
2283 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2287 static void execSetupChooseMusic()
2289 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2293 static void execSetupInput()
2295 setup_mode = SETUP_MODE_INPUT;
2299 static void execSetupShortcut1()
2301 setup_mode = SETUP_MODE_SHORTCUT_1;
2305 static void execSetupShortcut2()
2307 setup_mode = SETUP_MODE_SHORTCUT_2;
2311 static void execExitSetup()
2313 game_status = GAME_MODE_MAIN;
2317 static void execSaveAndExitSetup()
2323 static struct TokenInfo setup_info_main[] =
2325 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2326 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2327 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2328 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2329 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2330 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2331 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2332 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2333 { TYPE_EMPTY, NULL, "" },
2334 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2335 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2340 static struct TokenInfo setup_info_game[] =
2342 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2343 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2344 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2345 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2346 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2347 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2348 { TYPE_EMPTY, NULL, "" },
2349 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2354 static struct TokenInfo setup_info_editor[] =
2357 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2358 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2359 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2360 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2361 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2362 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2363 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2364 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2366 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2367 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2368 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2369 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2370 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2371 { TYPE_EMPTY, NULL, "" },
2372 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2373 { TYPE_EMPTY, NULL, "" },
2374 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2379 static struct TokenInfo setup_info_graphics[] =
2381 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen Mode:" },
2382 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2384 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2385 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2386 { TYPE_SWITCH, &setup.fading, "Fading:" },
2388 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2389 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2390 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2391 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2392 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2393 { TYPE_EMPTY, NULL, "" },
2394 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2399 static struct TokenInfo setup_info_sound[] =
2401 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2402 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2403 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2404 { TYPE_EMPTY, NULL, "" },
2405 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2410 static struct TokenInfo setup_info_artwork[] =
2412 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2413 { TYPE_STRING, &graphics_set_name, "" },
2414 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2415 { TYPE_STRING, &sounds_set_name, "" },
2416 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2417 { TYPE_STRING, &music_set_name, "" },
2418 { TYPE_EMPTY, NULL, "" },
2420 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2421 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2422 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2424 { TYPE_STRING, NULL, "Override Level Artwork:"},
2425 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2426 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2427 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2429 { TYPE_EMPTY, NULL, "" },
2430 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2435 static struct TokenInfo setup_info_shortcut_1[] =
2437 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2438 { TYPE_KEY, &setup.shortcut.save_game, "" },
2439 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2440 { TYPE_KEY, &setup.shortcut.load_game, "" },
2441 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2442 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2443 { TYPE_EMPTY, NULL, "" },
2444 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2445 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2446 { TYPE_EMPTY, NULL, "" },
2447 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2452 static struct TokenInfo setup_info_shortcut_2[] =
2454 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2455 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2456 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2457 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2458 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2459 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2460 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2461 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2462 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2463 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2464 { TYPE_EMPTY, NULL, "" },
2465 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2470 static Key getSetupKey()
2472 Key key = KSYM_UNDEFINED;
2473 boolean got_key_event = FALSE;
2475 while (!got_key_event)
2477 if (PendingEvent()) /* got event */
2485 case EVENT_KEYPRESS:
2487 key = GetEventKey((KeyEvent *)&event, TRUE);
2489 /* press 'Escape' or 'Enter' to keep the existing key binding */
2490 if (key == KSYM_Escape || key == KSYM_Return)
2491 key = KSYM_UNDEFINED; /* keep old value */
2493 got_key_event = TRUE;
2497 case EVENT_KEYRELEASE:
2498 key_joystick_mapping = 0;
2502 HandleOtherEvents(&event);
2510 /* don't eat all CPU time */
2517 static int getSetupTextFont(int type)
2519 if (type & (TYPE_SWITCH |
2529 static int getSetupValueFont(int type, void *value)
2531 if (type & TYPE_KEY)
2532 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2533 else if (type & TYPE_STRING)
2534 return FONT_VALUE_2;
2535 else if (type & TYPE_ECS_AGA)
2536 return FONT_VALUE_1;
2537 else if (type & TYPE_BOOLEAN_STYLE)
2538 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2540 return FONT_VALUE_1;
2543 static void drawSetupValue(int pos)
2545 boolean font_draw_xoffset_modified = FALSE;
2546 int font_draw_xoffset_old = -1;
2547 int xpos = MENU_SCREEN_VALUE_XPOS;
2548 int ypos = MENU_SCREEN_START_YPOS + pos;
2549 int startx = mSX + xpos * 32;
2550 int starty = mSY + ypos * 32;
2551 int font_nr, font_width;
2552 int type = setup_info[pos].type;
2553 void *value = setup_info[pos].value;
2554 char *value_string = getSetupValue(type, value);
2557 if (value_string == NULL)
2560 if (type & TYPE_KEY)
2563 xpos = MENU_SCREEN_START_XPOS;
2568 if (type & TYPE_QUERY)
2570 value_string = "<press key>";
2572 font_nr = FONT_INPUT_1_ACTIVE;
2576 else if (type & TYPE_STRING)
2578 int max_value_len = (SCR_FIELDX - 2) * 2;
2580 xpos = MENU_SCREEN_START_XPOS;
2582 font_nr = FONT_VALUE_2;
2585 if (strlen(value_string) > max_value_len)
2586 value_string[max_value_len] = '\0';
2588 else if (type & TYPE_ECS_AGA)
2591 font_nr = FONT_VALUE_1;
2594 else if (type & TYPE_BOOLEAN_STYLE)
2597 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2601 startx = mSX + xpos * 32;
2602 starty = mSY + ypos * 32;
2603 font_nr = getSetupValueFont(type, value);
2604 font_width = getFontWidth(font_nr);
2606 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2607 if (setup_mode != SETUP_MODE_INPUT)
2609 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
2610 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2611 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
2612 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
2613 int text_font_nr = getSetupTextFont(FONT_MENU_2);
2614 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
2615 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
2616 boolean correct_font_draw_xoffset = FALSE;
2618 if (xpos == MENU_SCREEN_START_XPOS &&
2619 startx + font1_xoffset < text_startx + text_font_xoffset)
2620 correct_font_draw_xoffset = TRUE;
2622 if (xpos == MENU_SCREEN_VALUE_XPOS &&
2623 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
2624 correct_font_draw_xoffset = TRUE;
2627 printf("::: %d + %d < %d + %d + %d\n",
2628 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
2629 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
2632 /* check if setup value would overlap with setup text when printed */
2633 /* (this can happen for extreme/wrong values for font draw offset) */
2634 if (correct_font_draw_xoffset)
2636 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
2637 font_draw_xoffset_modified = TRUE;
2639 if (type & TYPE_KEY)
2640 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
2641 else if (!(type & TYPE_STRING))
2642 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
2643 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
2648 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
2649 DrawText(startx + i * font_width, starty, " ", font_nr);
2652 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
2653 DrawText(mSX + i * 32, starty, " ", font_nr);
2655 DrawText(startx, starty,
2656 (xpos == 3 ? " " : " "), font_nr);
2660 DrawText(startx, starty, value_string, font_nr);
2662 if (font_draw_xoffset_modified)
2663 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
2666 static void changeSetupValue(int pos)
2668 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2670 *(boolean *)setup_info[pos].value ^= TRUE;
2672 else if (setup_info[pos].type & TYPE_KEY)
2676 setup_info[pos].type |= TYPE_QUERY;
2677 drawSetupValue(pos);
2678 setup_info[pos].type &= ~TYPE_QUERY;
2680 key = getSetupKey();
2681 if (key != KSYM_UNDEFINED)
2682 *(Key *)setup_info[pos].value = key;
2685 drawSetupValue(pos);
2688 static void DrawSetupScreen_Generic()
2690 char *title_string = NULL;
2694 CloseDoor(DOOR_CLOSE_2);
2698 if (setup_mode == SETUP_MODE_MAIN)
2700 setup_info = setup_info_main;
2701 title_string = "Setup";
2703 else if (setup_mode == SETUP_MODE_GAME)
2705 setup_info = setup_info_game;
2706 title_string = "Setup Game";
2708 else if (setup_mode == SETUP_MODE_EDITOR)
2710 setup_info = setup_info_editor;
2711 title_string = "Setup Editor";
2713 else if (setup_mode == SETUP_MODE_GRAPHICS)
2715 setup_info = setup_info_graphics;
2716 title_string = "Setup Graphics";
2718 else if (setup_mode == SETUP_MODE_SOUND)
2720 setup_info = setup_info_sound;
2721 title_string = "Setup Sound";
2723 else if (setup_mode == SETUP_MODE_ARTWORK)
2725 setup_info = setup_info_artwork;
2726 title_string = "Custom Artwork";
2728 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
2730 setup_info = setup_info_shortcut_1;
2731 title_string = "Setup Shortcuts";
2733 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
2735 setup_info = setup_info_shortcut_2;
2736 title_string = "Setup Shortcuts";
2740 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2742 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2746 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2748 void *value_ptr = setup_info[i].value;
2749 int xpos = MENU_SCREEN_START_XPOS;
2750 int ypos = MENU_SCREEN_START_YPOS + i;
2754 int font_nr = FONT_MENU_1;
2757 /* set some entries to "unchangeable" according to other variables */
2758 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2759 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2760 (value_ptr == &setup.sound_music && !audio.music_available) ||
2761 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2762 setup_info[i].type |= TYPE_GHOSTED;
2765 font_nr = getSetupTextFont(setup_info[i].type);
2768 if (setup_info[i].type & (TYPE_SWITCH |
2773 font_nr = FONT_MENU_2;
2775 if (setup_info[i].type & TYPE_STRING)
2776 font_nr = FONT_MENU_2;
2780 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2782 if (setup_info[i].type & TYPE_ENTER_MENU)
2783 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2784 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2785 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2786 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2787 initCursor(i, IMG_MENU_BUTTON);
2789 if (setup_info[i].type & TYPE_VALUE)
2796 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2797 "Joysticks deactivated in setup menu");
2802 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2805 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2807 static int choice_store[MAX_SETUP_MODES];
2808 int choice = choice_store[setup_mode]; /* always starts with 0 */
2812 if (button == MB_MENU_INITIALIZE)
2814 /* advance to first valid menu entry */
2815 while (choice < num_setup_info &&
2816 setup_info[choice].type & TYPE_SKIP_ENTRY)
2818 choice_store[setup_mode] = choice;
2820 drawCursor(choice, FC_RED);
2823 else if (button == MB_MENU_LEAVE)
2825 for (y = 0; y < num_setup_info; y++)
2827 if (setup_info[y].type & TYPE_LEAVE_MENU)
2829 void (*menu_callback_function)(void) = setup_info[y].value;
2831 menu_callback_function();
2832 break; /* absolutely needed because function changes 'setup_info'! */
2839 if (mx || my) /* mouse input */
2841 x = (mx - mSX) / 32;
2842 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2844 else if (dx || dy) /* keyboard input */
2848 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2850 if (setup_info[choice].type & menu_navigation_type ||
2851 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2852 button = MB_MENU_CHOICE;
2857 /* jump to next non-empty menu entry (up or down) */
2858 while (y > 0 && y < num_setup_info - 1 &&
2859 setup_info[y].type & TYPE_SKIP_ENTRY)
2863 if (IN_VIS_FIELD(x, y) &&
2864 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2870 drawCursor(y, FC_RED);
2871 drawCursor(choice, FC_BLUE);
2872 choice = choice_store[setup_mode] = y;
2875 else if (!(setup_info[y].type & TYPE_GHOSTED))
2877 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2879 void (*menu_callback_function)(void) = setup_info[choice].value;
2881 menu_callback_function();
2885 if (setup_info[y].type & TYPE_KEYTEXT &&
2886 setup_info[y + 1].type & TYPE_KEY)
2889 if (setup_info[y].type & TYPE_VALUE)
2890 changeSetupValue(y);
2896 void DrawSetupScreen_Input()
2901 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2903 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2906 initCursor(0, IMG_MENU_BUTTON);
2907 initCursor(1, IMG_MENU_BUTTON);
2908 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2909 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2911 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2912 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2914 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2915 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2916 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2919 DeactivateJoystickForCalibration();
2922 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2923 "Joysticks deactivated on this screen");
2926 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2931 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2933 if (device_name == NULL)
2936 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2939 if (strlen(device_name) > 1)
2941 char c1 = device_name[strlen(device_name) - 1];
2942 char c2 = device_name[strlen(device_name) - 2];
2944 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2945 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2948 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2949 strlen(device_name));
2952 static void drawPlayerSetupInputInfo(int player_nr)
2955 static struct SetupKeyboardInfo custom_key;
2962 { &custom_key.left, "Joystick Left" },
2963 { &custom_key.right, "Joystick Right" },
2964 { &custom_key.up, "Joystick Up" },
2965 { &custom_key.down, "Joystick Down" },
2966 { &custom_key.snap, "Button 1" },
2967 { &custom_key.drop, "Button 2" }
2969 static char *joystick_name[MAX_PLAYERS] =
2979 custom_key = setup.input[player_nr].key;
2981 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2982 FONT_INPUT_1_ACTIVE);
2984 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2986 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2987 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2989 if (setup.input[player_nr].use_joystick)
2991 char *device_name = setup.input[player_nr].joy.device_name;
2992 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
2993 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
2995 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
2996 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
3000 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
3001 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
3004 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
3005 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
3006 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
3007 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
3008 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
3009 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
3010 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
3011 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
3012 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
3013 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
3014 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
3016 for (i = 0; i < 6; i++)
3018 int ypos = 6 + i + (i > 3 ? i-3 : 0);
3020 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3022 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3023 (setup.input[player_nr].use_joystick ?
3025 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
3029 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
3031 static int choice = 0;
3032 static int player_nr = 0;
3035 int pos_start = SETUPINPUT_SCREEN_POS_START;
3036 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
3037 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
3038 int pos_end = SETUPINPUT_SCREEN_POS_END;
3040 if (button == MB_MENU_INITIALIZE)
3042 drawPlayerSetupInputInfo(player_nr);
3043 drawCursor(choice, FC_RED);
3047 else if (button == MB_MENU_LEAVE)
3049 setup_mode = SETUP_MODE_MAIN;
3056 if (mx || my) /* mouse input */
3058 x = (mx - mSX) / 32;
3059 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3061 else if (dx || dy) /* keyboard input */
3063 if (dx && choice == 0)
3064 x = (dx < 0 ? 10 : 12);
3065 else if ((dx && choice == 1) ||
3066 (dx == +1 && choice == 2) ||
3067 (dx == -1 && choice == pos_end))
3068 button = MB_MENU_CHOICE;
3072 if (y >= pos_empty1 && y <= pos_empty2)
3073 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
3076 if (IN_VIS_FIELD(x, y) &&
3077 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
3079 static unsigned long delay = 0;
3081 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3084 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3086 drawPlayerSetupInputInfo(player_nr);
3088 else if (IN_VIS_FIELD(x, y) &&
3089 y >= pos_start && y <= pos_end &&
3090 !(y >= pos_empty1 && y <= pos_empty2))
3096 drawCursor(y, FC_RED);
3097 drawCursor(choice, FC_BLUE);
3105 char *device_name = setup.input[player_nr].joy.device_name;
3107 if (!setup.input[player_nr].use_joystick)
3109 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3111 setJoystickDeviceToNr(device_name, new_device_nr);
3112 setup.input[player_nr].use_joystick = TRUE;
3116 int device_nr = getJoystickNrFromDeviceName(device_name);
3117 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3119 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3120 setup.input[player_nr].use_joystick = FALSE;
3122 setJoystickDeviceToNr(device_name, new_device_nr);
3125 drawPlayerSetupInputInfo(player_nr);
3129 if (setup.input[player_nr].use_joystick)
3132 CalibrateJoystick(player_nr);
3135 CustomizeKeyboard(player_nr);
3137 else if (y == pos_end)
3141 setup_mode = SETUP_MODE_MAIN;
3148 void CustomizeKeyboard(int player_nr)
3152 boolean finished = FALSE;
3153 static struct SetupKeyboardInfo custom_key;
3158 } customize_step[] =
3160 { &custom_key.left, "Move Left" },
3161 { &custom_key.right, "Move Right" },
3162 { &custom_key.up, "Move Up" },
3163 { &custom_key.down, "Move Down" },
3164 { &custom_key.snap, "Snap Field" },
3165 { &custom_key.drop, "Drop Element" }
3168 /* read existing key bindings from player setup */
3169 custom_key = setup.input[player_nr].key;
3174 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3176 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3183 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3184 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3185 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3186 "Key:", FONT_INPUT_1_ACTIVE);
3187 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3188 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3192 if (PendingEvent()) /* got event */
3200 case EVENT_KEYPRESS:
3202 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3204 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3210 /* all keys configured -- wait for "Escape" or "Return" key */
3214 /* press 'Enter' to keep the existing key binding */
3215 if (key == KSYM_Return)
3216 key = *customize_step[step_nr].key;
3218 /* check if key already used */
3219 for (i = 0; i < step_nr; i++)
3220 if (*customize_step[i].key == key)
3225 /* got new key binding */
3226 *customize_step[step_nr].key = key;
3227 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3229 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3230 getKeyNameFromKey(key), FONT_VALUE_1);
3233 /* un-highlight last query */
3234 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3235 customize_step[step_nr - 1].text, FONT_MENU_1);
3236 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3237 "Key:", FONT_MENU_1);
3239 /* press 'Enter' to leave */
3242 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3243 "Press Enter", FONT_TITLE_1);
3247 /* query next key binding */
3248 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3249 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3250 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3251 "Key:", FONT_INPUT_1_ACTIVE);
3252 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3253 getKeyNameFromKey(*customize_step[step_nr].key),
3258 case EVENT_KEYRELEASE:
3259 key_joystick_mapping = 0;
3263 HandleOtherEvents(&event);
3271 /* don't eat all CPU time */
3275 /* write new key bindings back to player setup */
3276 setup.input[player_nr].key = custom_key;
3279 DrawSetupScreen_Input();
3282 static boolean CalibrateJoystickMain(int player_nr)
3284 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3285 int new_joystick_xright = JOYSTICK_XMIDDLE;
3286 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3287 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3288 int new_joystick_xmiddle, new_joystick_ymiddle;
3290 int joystick_fd = joystick.fd[player_nr];
3291 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3292 boolean check[3][3];
3293 int check_remaining = 3 * 3;
3298 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3301 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3306 for (y = 0; y < 3; y++)
3308 for (x = 0; x < 3; x++)
3310 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3311 check[x][y] = FALSE;
3315 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3316 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3317 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3318 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3319 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3320 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3321 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3323 joy_value = Joystick(player_nr);
3324 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3325 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3327 /* eventually uncalibrated center position (joystick could be uncentered) */
3328 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3331 new_joystick_xmiddle = joy_x;
3332 new_joystick_ymiddle = joy_y;
3334 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3337 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3342 if (PendingEvent()) /* got event */
3350 case EVENT_KEYPRESS:
3351 switch(GetEventKey((KeyEvent *)&event, TRUE))
3354 if (check_remaining == 0)
3367 case EVENT_KEYRELEASE:
3368 key_joystick_mapping = 0;
3372 HandleOtherEvents(&event);
3377 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3380 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3381 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3382 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3383 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3385 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3386 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3387 setup.input[player_nr].joy.xright = new_joystick_xright;
3388 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3389 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3390 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3392 CheckJoystickData();
3394 joy_value = Joystick(player_nr);
3396 if (joy_value & JOY_BUTTON && check_remaining == 0)
3399 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3400 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3402 if (x != last_x || y != last_y)
3404 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3405 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3410 if (check_remaining > 0 && !check[x+1][y+1])
3412 check[x+1][y+1] = TRUE;
3418 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3419 setup.input[player_nr].joy.xleft,
3420 setup.input[player_nr].joy.xmiddle,
3421 setup.input[player_nr].joy.xright);
3422 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3423 setup.input[player_nr].joy.yupper,
3424 setup.input[player_nr].joy.ymiddle,
3425 setup.input[player_nr].joy.ylower);
3434 /* don't eat all CPU time */
3438 /* calibrated center position (joystick should now be centered) */
3439 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3442 new_joystick_xmiddle = joy_x;
3443 new_joystick_ymiddle = joy_y;
3448 DrawSetupScreen_Input();
3451 /* wait until the last pressed button was released */
3452 while (Joystick(player_nr) & JOY_BUTTON)
3454 if (PendingEvent()) /* got event */
3459 HandleOtherEvents(&event);
3468 void CalibrateJoystick(int player_nr)
3470 if (!CalibrateJoystickMain(player_nr))
3472 char *device_name = setup.input[player_nr].joy.device_name;
3473 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3474 int xpos = mSX - SX;
3475 int ypos = mSY - SY;
3479 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3480 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3483 Delay(2000); /* show error message for a short time */
3489 DrawSetupScreen_Input();
3493 void DrawSetupScreen()
3495 DeactivateJoystick();
3497 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3499 if (setup_mode == SETUP_MODE_INPUT)
3500 DrawSetupScreen_Input();
3501 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3502 DrawChooseTree(&artwork.gfx_current);
3503 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3504 DrawChooseTree(&artwork.snd_current);
3505 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3506 DrawChooseTree(&artwork.mus_current);
3508 DrawSetupScreen_Generic();
3514 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3516 if (setup_mode == SETUP_MODE_INPUT)
3517 HandleSetupScreen_Input(mx, my, dx, dy, button);
3518 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3519 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3520 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3521 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3522 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3523 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3525 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3530 void HandleGameActions()
3532 if (game_status != GAME_MODE_PLAYING)
3535 GameActions(); /* main game loop */
3537 if (tape.auto_play && !tape.playing)
3538 AutoPlayTape(); /* continue automatically playing next tape */
3542 /* ---------- new screen button stuff -------------------------------------- */
3546 int gfx_unpressed, gfx_pressed;
3550 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3553 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3554 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3555 SCREEN_CTRL_ID_SCROLL_UP,
3559 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3560 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3561 SCREEN_CTRL_ID_SCROLL_DOWN,
3568 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3569 Bitmap **gfx_unpressed, **gfx_pressed;
3571 int gfx_unpressed, gfx_pressed;
3578 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3581 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3582 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3584 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3586 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3587 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3588 GD_TYPE_SCROLLBAR_VERTICAL,
3589 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3590 "scroll level series vertically"
3594 static void CreateScreenScrollbuttons()
3596 struct GadgetInfo *gi;
3597 unsigned long event_mask;
3600 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3602 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3603 int gfx_unpressed, gfx_pressed;
3604 int x, y, width, height;
3605 int gd_x1, gd_x2, gd_y1, gd_y2;
3606 int id = scrollbutton_info[i].gadget_id;
3608 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3610 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3611 y = mSY + scrollbutton_info[i].y;
3612 width = SC_SCROLLBUTTON_XSIZE;
3613 height = SC_SCROLLBUTTON_YSIZE;
3615 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3616 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3617 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3619 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3620 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3621 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3622 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3623 gd_x1 = graphic_info[gfx_unpressed].src_x;
3624 gd_y1 = graphic_info[gfx_unpressed].src_y;
3625 gd_x2 = graphic_info[gfx_pressed].src_x;
3626 gd_y2 = graphic_info[gfx_pressed].src_y;
3628 gi = CreateGadget(GDI_CUSTOM_ID, id,
3629 GDI_CUSTOM_TYPE_ID, i,
3630 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3635 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3636 GDI_STATE, GD_BUTTON_UNPRESSED,
3637 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3638 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3639 GDI_DIRECT_DRAW, FALSE,
3640 GDI_EVENT_MASK, event_mask,
3641 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3645 Error(ERR_EXIT, "cannot create gadget");
3647 screen_gadget[id] = gi;
3651 static void CreateScreenScrollbars()
3655 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3657 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3658 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3659 int gfx_unpressed, gfx_pressed;
3661 int x, y, width, height;
3662 int gd_x1, gd_x2, gd_y1, gd_y2;
3663 struct GadgetInfo *gi;
3664 int items_max, items_visible, item_position;
3665 unsigned long event_mask;
3666 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3667 int id = scrollbar_info[i].gadget_id;
3669 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3671 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3672 y = mSY + scrollbar_info[i].y;
3673 width = scrollbar_info[i].width;
3674 height = scrollbar_info[i].height;
3676 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3677 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3679 items_max = num_page_entries;
3680 items_visible = num_page_entries;
3683 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3684 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3685 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3691 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3692 gfx_pressed = scrollbar_info[i].gfx_pressed;
3693 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3694 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3695 gd_x1 = graphic_info[gfx_unpressed].src_x;
3696 gd_y1 = graphic_info[gfx_unpressed].src_y;
3697 gd_x2 = graphic_info[gfx_pressed].src_x;
3698 gd_y2 = graphic_info[gfx_pressed].src_y;
3701 gi = CreateGadget(GDI_CUSTOM_ID, id,
3702 GDI_CUSTOM_TYPE_ID, i,
3703 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3708 GDI_TYPE, scrollbar_info[i].type,
3709 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3710 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3711 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3712 GDI_STATE, GD_BUTTON_UNPRESSED,
3713 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3714 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3715 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3716 GDI_DIRECT_DRAW, FALSE,
3717 GDI_EVENT_MASK, event_mask,
3718 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3722 Error(ERR_EXIT, "cannot create gadget");
3724 screen_gadget[id] = gi;
3728 void CreateScreenGadgets()
3730 int last_game_status = game_status; /* save current game status */
3732 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3735 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3737 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3739 /* copy pointers to clip mask and GC */
3740 scrollbar_bitmap[i]->clip_mask =
3741 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3742 scrollbar_bitmap[i]->stored_clip_gc =
3743 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3745 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3746 scrollbar_bitmap[i],
3747 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3748 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3749 TILEX, TILEY, 0, 0);
3753 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3754 game_status = GAME_MODE_LEVELS;
3756 CreateScreenScrollbuttons();
3757 CreateScreenScrollbars();
3759 game_status = last_game_status; /* restore current game status */
3762 void FreeScreenGadgets()
3766 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3767 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3769 /* prevent freeing clip mask and GC twice */
3770 scrollbar_bitmap[i]->clip_mask = None;
3771 scrollbar_bitmap[i]->stored_clip_gc = None;
3773 FreeBitmap(scrollbar_bitmap[i]);
3777 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3778 FreeGadget(screen_gadget[i]);
3781 void MapChooseTreeGadgets(TreeInfo *ti)
3783 int num_entries = numTreeInfoInGroup(ti);
3786 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3789 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3790 MapGadget(screen_gadget[i]);
3794 void UnmapChooseTreeGadgets()
3798 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3799 UnmapGadget(screen_gadget[i]);
3803 static void HandleScreenGadgets(struct GadgetInfo *gi)
3805 int id = gi->custom_id;
3807 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3812 case SCREEN_CTRL_ID_SCROLL_UP:
3813 if (game_status == GAME_MODE_LEVELS)
3814 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3815 else if (game_status == GAME_MODE_SETUP)
3816 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3819 case SCREEN_CTRL_ID_SCROLL_DOWN:
3820 if (game_status == GAME_MODE_LEVELS)
3821 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3822 else if (game_status == GAME_MODE_SETUP)
3823 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3826 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3827 if (game_status == GAME_MODE_LEVELS)
3828 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3829 else if (game_status == GAME_MODE_SETUP)
3830 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);