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_ELEMENTS 1
52 #define INFO_MODE_MUSIC 2
53 #define INFO_MODE_CREDITS 3
54 #define INFO_MODE_PROGRAM 4
55 #define INFO_MODE_LEVELSET 5
57 #define MAX_INFO_MODES 6
59 /* for various menu stuff */
60 #define MENU_SCREEN_START_XPOS 1
61 #define MENU_SCREEN_START_YPOS 2
62 #define MENU_SCREEN_VALUE_XPOS 14
63 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
64 #define MENU_TITLE1_YPOS 8
65 #define MENU_TITLE2_YPOS 46
66 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
67 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
68 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
69 MENU_SCREEN_START_XPOS)
70 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
72 /* buttons and scrollbars identifiers */
73 #define SCREEN_CTRL_ID_SCROLL_UP 0
74 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
75 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
77 #define NUM_SCREEN_SCROLLBUTTONS 2
78 #define NUM_SCREEN_SCROLLBARS 1
79 #define NUM_SCREEN_GADGETS 3
81 /* graphic position and size values for buttons and scrollbars */
82 #define SC_SCROLLBUTTON_XSIZE TILEX
83 #define SC_SCROLLBUTTON_YSIZE TILEY
85 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
87 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
88 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
89 SC_SCROLLBUTTON_YSIZE)
91 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
92 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
94 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
95 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
96 SC_SCROLLBUTTON_YSIZE)
98 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
99 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
100 SC_SCROLL_VERTICAL_YSIZE)
102 #define SC_BORDER_SIZE 14
105 /* forward declarations of internal functions */
106 static void HandleScreenGadgets(struct GadgetInfo *);
107 static void HandleSetupScreen_Generic(int, int, int, int, int);
108 static void HandleSetupScreen_Input(int, int, int, int, int);
109 static void CustomizeKeyboard(int);
110 static void CalibrateJoystick(int);
111 static void execSetupArtwork(void);
112 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
114 static void DrawChooseLevel(void);
115 static void DrawInfoScreen(void);
116 static void DrawSetupScreen(void);
118 static void DrawInfoScreen_HelpAnim(int, int, boolean);
119 static void DrawInfoScreen_HelpText(int, int, int, int);
120 static void HandleInfoScreen_Main(int, int, int, int, int);
121 static void HandleInfoScreen_Elements(int);
122 static void HandleInfoScreen_Music(int);
123 static void HandleInfoScreen_Credits(int);
124 static void HandleInfoScreen_Program(int);
126 static void MapChooseTreeGadgets(TreeInfo *);
128 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
129 static int setup_mode = SETUP_MODE_MAIN;
130 static int info_mode = INFO_MODE_MAIN;
132 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
133 x <= GAME_MODE_SETUP ? x : \
134 x == GAME_MODE_PSEUDO_TYPENAME ? \
135 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
137 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
138 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
140 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
141 menu.list_size[game_status] : \
142 MAX_MENU_ENTRIES_ON_SCREEN)
144 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
145 #define NUM_SCROLLBAR_BITMAPS 2
146 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
150 static void drawCursorExt(int xpos, int ypos, int color, int g)
152 static int cursor_array[SCR_FIELDY];
157 cursor_array[ypos] = g;
159 g = cursor_array[ypos];
163 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
164 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
165 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
166 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
167 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
168 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
169 IMG_MENU_BUTTON_ACTIVE);
171 ypos += MENU_SCREEN_START_YPOS;
173 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
174 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
177 static void initCursor(int ypos, int graphic)
179 drawCursorExt(0, ypos, FC_BLUE, graphic);
182 static void drawCursor(int ypos, int color)
184 drawCursorExt(0, ypos, color, 0);
187 static void drawCursorXY(int xpos, int ypos, int graphic)
189 drawCursorExt(xpos, ypos, -1, graphic);
192 static void drawChooseTreeCursor(int ypos, int color)
194 int last_game_status = game_status; /* save current game status */
196 /* force LEVELS draw offset on artwork setup screen */
197 game_status = GAME_MODE_LEVELS;
199 drawCursorExt(0, ypos, color, 0);
201 game_status = last_game_status; /* restore current game status */
206 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
207 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
210 static void ToggleFullscreenIfNeeded()
212 if (setup.fullscreen != video.fullscreen_enabled)
214 /* save old door content */
215 BlitBitmap(backbuffer, bitmap_db_door,
216 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
218 /* toggle fullscreen */
219 ChangeVideoModeIfNeeded(setup.fullscreen);
220 setup.fullscreen = video.fullscreen_enabled;
222 /* redraw background to newly created backbuffer */
223 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
224 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
226 /* restore old door content */
227 BlitBitmap(bitmap_db_door, backbuffer,
228 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
230 redraw_mask = REDRAW_ALL;
234 static int getLastLevelButtonPos()
239 static int getCurrentLevelTextPos()
241 return (getLastLevelButtonPos() + 1);
244 static int getNextLevelButtonPos()
246 return getLastLevelButtonPos() + 3 + 1;
249 static int getLevelRangeTextPos()
251 return getNextLevelButtonPos() + 1;
254 void DrawTitleScreenImage(int nr)
256 int graphic = IMG_TITLESCREEN_1 + nr;
257 Bitmap *bitmap = graphic_info[graphic].bitmap;
258 int width = graphic_info[graphic].src_image_width;
259 int height = graphic_info[graphic].src_image_height;
260 int src_x = 0, src_y = 0;
266 if (width > WIN_XSIZE)
268 src_x = (width - WIN_XSIZE) / 2;
272 if (height > WIN_YSIZE)
274 src_y = (height - WIN_YSIZE) / 2;
278 dst_x = (WIN_XSIZE - width) / 2;
279 dst_y = (WIN_YSIZE - height) / 2;
281 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
283 if (DrawingOnBackground(dst_x, dst_y))
284 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
286 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
288 redraw_mask = REDRAW_ALL;
291 void DrawTitleScreen()
293 KeyboardAutoRepeatOff();
295 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
300 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
305 static void DrawMainMenuExt(int fade_delay)
307 static LevelDirTree *leveldir_last_valid = NULL;
308 boolean levelset_has_changed = FALSE;
309 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
311 char *level_text = "Levelset";
313 char *level_text = "Level:";
315 int name_width, level_width;
319 FadeSoundsAndMusic();
321 KeyboardAutoRepeatOn();
324 SetDrawDeactivationMask(REDRAW_NONE);
325 SetDrawBackgroundMask(REDRAW_FIELD);
327 audio.sound_deactivated = FALSE;
333 /* needed if last screen was the playing screen, invoked from level editor */
334 if (level_editor_test_game)
336 game_status = GAME_MODE_EDITOR;
342 /* needed if last screen was the editor screen */
343 UndrawSpecialEditorDoor();
345 /* needed if last screen was the setup screen and fullscreen state changed */
346 ToggleFullscreenIfNeeded();
348 /* leveldir_current may be invalid (level group, parent link) */
349 if (!validLevelSeries(leveldir_current))
350 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
352 if (leveldir_current != leveldir_last_valid)
353 levelset_has_changed = TRUE;
355 /* store valid level series information */
356 leveldir_last_valid = leveldir_current;
358 /* needed if last screen (level choice) changed graphics, sounds or music */
359 ReloadCustomArtwork(0);
362 SetDrawtoField(DRAW_BACKBUFFER);
365 if (setup.show_titlescreen &&
366 levelset_has_changed &&
367 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
369 game_status = GAME_MODE_TITLE;
376 /* map gadgets for main menu screen */
380 /* level_nr may have been set to value over handicap with level editor */
381 if (setup.handicap && level_nr > leveldir_current->handicap_level)
382 level_nr = leveldir_current->handicap_level;
389 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
394 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
395 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
396 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
397 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
398 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
399 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
400 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
401 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
403 /* calculated after (possible) reload of custom artwork */
404 name_width = getTextWidth(name_text, FONT_MENU_1);
406 level_width = 9 * 32;
409 level_width = 9 * getFontWidth(FONT_MENU_1);
411 level_width = getTextWidth(level_text, FONT_MENU_1);
415 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
419 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
420 int2str(level_nr, 3), FONT_VALUE_1);
423 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
426 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
431 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
437 int text_height = getFontHeight(FONT_TEXT_3);
439 int xpos = getLevelRangeTextPos() * 32;
441 int xpos = level_width + 6 * 32;
443 int ypos2 = -SY + 3 * 32 + 16;
444 int ypos1 = ypos2 - text_height;
446 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
447 "%03d", leveldir_current->first_level);
448 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
449 "%03d", leveldir_current->last_level);
452 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
453 "%d", leveldir_current->levels);
457 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
458 leveldir_current->first_level, leveldir_current->last_level);
462 if (leveldir_current->readonly)
464 DrawTextS(mSX + level_width + 9 * 32 - 2,
465 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
466 DrawTextS(mSX + level_width + 9 * 32 - 2,
467 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
471 for (i = 0; i < 8; i++)
472 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
476 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
477 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
480 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
481 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
483 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
484 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
488 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
495 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
498 if (TAPE_IS_EMPTY(tape))
500 DrawCompleteVideoDisplay();
506 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
509 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
511 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
515 /* map gadgets for main menu screen */
528 DrawMainMenuExt(FALSE);
532 static void gotoTopLevelDir()
534 /* move upwards to top level directory */
535 while (leveldir_current->node_parent)
537 /* write a "path" into level tree for easy navigation to last level */
538 if (leveldir_current->node_parent->node_group->cl_first == -1)
540 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
541 int leveldir_pos = posTreeInfo(leveldir_current);
542 int num_page_entries;
543 int cl_first, cl_cursor;
545 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
546 num_page_entries = num_leveldirs;
548 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
550 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
551 cl_cursor = leveldir_pos - cl_first;
553 leveldir_current->node_parent->node_group->cl_first = cl_first;
554 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
557 leveldir_current = leveldir_current->node_parent;
562 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
564 static int title_nr = 0;
565 boolean return_to_main_menu = FALSE;
566 boolean use_fading_main_menu = TRUE;
567 boolean use_cross_fading = TRUE;
568 int fade_delay = 1000;
569 int post_delay = 500;
571 if (button == MB_MENU_INITIALIZE)
575 DrawTitleScreenImage(title_nr);
581 else if (button == MB_MENU_LEAVE)
583 return_to_main_menu = TRUE;
584 use_fading_main_menu = FALSE;
586 else if (button == MB_MENU_CHOICE)
590 if (!use_cross_fading)
591 FadeOut(fade_delay, post_delay);
593 if (title_nr < MAX_NUM_TITLE_SCREENS &&
594 graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
596 Bitmap *drawto_last = drawto;
598 if (use_cross_fading)
599 drawto = bitmap_db_title;
601 DrawTitleScreenImage(title_nr);
603 drawto = drawto_last;
605 if (use_cross_fading)
606 FadeCross(fade_delay);
612 FadeOut(fade_delay, post_delay);
614 return_to_main_menu = TRUE;
618 if (return_to_main_menu)
623 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
626 game_status = GAME_MODE_MAIN;
627 DrawMainMenuExt(use_fading_main_menu ? fade_delay : 0);
631 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
633 static unsigned long level_delay = 0;
634 static int choice = 5;
638 if (button == MB_MENU_INITIALIZE)
640 drawCursor(choice, FC_RED);
644 if (mx || my) /* mouse input */
647 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
649 else if (dx || dy) /* keyboard input */
651 if (dx && choice == 1)
652 x = (dx < 0 ? 10 : 14);
655 if (choice == 4 || choice == 6)
656 button = MB_MENU_CHOICE;
662 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
663 (x == 14 && level_nr < leveldir_current->last_level)) &&
664 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
666 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
667 int old_level_nr = level_nr;
670 new_level_nr = level_nr + (x == 10 ? -step : +step);
671 if (new_level_nr < leveldir_current->first_level)
672 new_level_nr = leveldir_current->first_level;
673 if (new_level_nr > leveldir_current->last_level)
674 new_level_nr = leveldir_current->last_level;
676 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
678 /* skipping levels is only allowed when trying to skip single level */
679 if (setup.skip_levels && step == 1 &&
680 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
682 leveldir_current->handicap_level++;
683 SaveLevelSetup_SeriesInfo();
686 new_level_nr = leveldir_current->handicap_level;
689 if (new_level_nr != old_level_nr)
691 level_nr = new_level_nr;
693 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
697 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
701 DrawCompleteVideoDisplay();
703 /* needed because DrawMicroLevel() takes some time */
706 DelayReached(&level_delay, 0); /* reset delay counter */
709 else if (IN_VIS_FIELD(x, y) &&
710 y >= 0 && y <= 7 && (y != 1 || x < 10))
716 drawCursor(y, FC_RED);
717 drawCursor(choice, FC_BLUE);
725 game_status = GAME_MODE_PSEUDO_TYPENAME;
726 HandleTypeName(strlen(setup.player_name), 0);
732 game_status = GAME_MODE_LEVELS;
733 SaveLevelSetup_LastSeries();
734 SaveLevelSetup_SeriesInfo();
745 game_status = GAME_MODE_SCORES;
750 if (leveldir_current->readonly &&
751 !strEqual(setup.player_name, "Artsoft"))
752 Request("This level is read only !", REQ_CONFIRM);
753 game_status = GAME_MODE_EDITOR;
758 game_status = GAME_MODE_INFO;
759 info_mode = INFO_MODE_MAIN;
764 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
768 game_status = GAME_MODE_SETUP;
769 setup_mode = SETUP_MODE_MAIN;
775 SaveLevelSetup_LastSeries();
776 SaveLevelSetup_SeriesInfo();
778 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
779 game_status = GAME_MODE_QUIT;
784 if (game_status == GAME_MODE_MAIN)
786 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
792 /* ========================================================================= */
793 /* info screen functions */
794 /* ========================================================================= */
796 static struct TokenInfo *info_info;
797 static int num_info_info;
799 static void execInfoElements()
801 info_mode = INFO_MODE_ELEMENTS;
805 static void execInfoMusic()
807 info_mode = INFO_MODE_MUSIC;
811 static void execInfoCredits()
813 info_mode = INFO_MODE_CREDITS;
817 static void execInfoProgram()
819 info_mode = INFO_MODE_PROGRAM;
823 static void execInfoLevelSet()
825 info_mode = INFO_MODE_LEVELSET;
829 static void execExitInfo()
831 game_status = GAME_MODE_MAIN;
835 static struct TokenInfo info_info_main[] =
837 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
838 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
839 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
840 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
841 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
842 { TYPE_EMPTY, NULL, "" },
843 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
848 static void DrawInfoScreen_Main()
853 CloseDoor(DOOR_CLOSE_2);
858 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
860 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
863 info_info = info_info_main;
866 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
868 int xpos = MENU_SCREEN_START_XPOS;
869 int ypos = MENU_SCREEN_START_YPOS + i;
870 int font_nr = FONT_MENU_1;
872 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
874 if (info_info[i].type & TYPE_ENTER_MENU)
875 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
876 else if (info_info[i].type & TYPE_LEAVE_MENU)
877 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
878 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
879 initCursor(i, IMG_MENU_BUTTON);
890 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
893 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
895 static int choice_store[MAX_INFO_MODES];
896 int choice = choice_store[info_mode]; /* always starts with 0 */
900 if (button == MB_MENU_INITIALIZE)
902 /* advance to first valid menu entry */
903 while (choice < num_info_info &&
904 info_info[choice].type & TYPE_SKIP_ENTRY)
906 choice_store[info_mode] = choice;
908 drawCursor(choice, FC_RED);
911 else if (button == MB_MENU_LEAVE)
913 for (y = 0; y < num_info_info; y++)
915 if (info_info[y].type & TYPE_LEAVE_MENU)
917 void (*menu_callback_function)(void) = info_info[y].value;
919 menu_callback_function();
920 break; /* absolutely needed because function changes 'info_info'! */
927 if (mx || my) /* mouse input */
930 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
932 else if (dx || dy) /* keyboard input */
936 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
938 if (info_info[choice].type & menu_navigation_type ||
939 info_info[choice].type & TYPE_ENTER_SCREEN ||
940 info_info[choice].type & TYPE_BOOLEAN_STYLE)
941 button = MB_MENU_CHOICE;
946 /* jump to next non-empty menu entry (up or down) */
947 while (y > 0 && y < num_info_info - 1 &&
948 info_info[y].type & TYPE_SKIP_ENTRY)
952 if (IN_VIS_FIELD(x, y) &&
953 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
959 drawCursor(y, FC_RED);
960 drawCursor(choice, FC_BLUE);
961 choice = choice_store[info_mode] = y;
964 else if (!(info_info[y].type & TYPE_GHOSTED))
966 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
968 void (*menu_callback_function)(void) = info_info[choice].value;
970 menu_callback_function();
976 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
978 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
979 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
980 int xstart = mSX + 16;
981 int ystart = mSY + 64 + 2 * 32;
982 int ystep = TILEY + 4;
983 int element, action, direction;
991 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
992 infoscreen_step[i] = infoscreen_frame[i] = 0;
997 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
999 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1000 "Press any key or button for next page");
1006 while (helpanim_info[j].element != HELPANIM_LIST_END)
1008 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1013 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1022 j += infoscreen_step[i - start];
1024 element = helpanim_info[j].element;
1025 action = helpanim_info[j].action;
1026 direction = helpanim_info[j].direction;
1029 element = EL_UNKNOWN;
1031 if (action != -1 && direction != -1)
1032 graphic = el_act_dir2img(element, action, direction);
1033 else if (action != -1)
1034 graphic = el_act2img(element, action);
1035 else if (direction != -1)
1036 graphic = el_dir2img(element, direction);
1038 graphic = el2img(element);
1040 delay = helpanim_info[j++].delay;
1045 if (infoscreen_frame[i - start] == 0)
1048 infoscreen_frame[i - start] = delay - 1;
1052 sync_frame = delay - infoscreen_frame[i - start];
1053 infoscreen_frame[i - start]--;
1056 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1058 if (!infoscreen_frame[i - start])
1059 infoscreen_step[i - start] = 0;
1063 if (!infoscreen_frame[i - start])
1064 infoscreen_step[i - start]++;
1065 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1071 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1073 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1074 graphic, sync_frame, USE_MASKING);
1077 DrawInfoScreen_HelpText(element, action, direction, i - start);
1082 redraw_mask |= REDRAW_FIELD;
1087 static char *getHelpText(int element, int action, int direction)
1089 char token[MAX_LINE_LEN];
1091 strcpy(token, element_info[element].token_name);
1094 strcat(token, element_action_info[action].suffix);
1096 if (direction != -1)
1097 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1099 return getHashEntry(helptext_info, token);
1102 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1104 int font_nr = FONT_LEVEL_NUMBER;
1105 int font_width = getFontWidth(font_nr);
1106 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1107 int sy = mSY + 65 + 2 * 32 + 1;
1108 int ystep = TILEY + 4;
1109 int pad_x = sx - SX;
1110 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1111 int max_lines_per_text = 2;
1114 if (action != -1 && direction != -1) /* element.action.direction */
1115 text = getHelpText(element, action, direction);
1117 if (text == NULL && action != -1) /* element.action */
1118 text = getHelpText(element, action, -1);
1120 if (text == NULL && direction != -1) /* element.direction */
1121 text = getHelpText(element, -1, direction);
1123 if (text == NULL) /* base element */
1124 text = getHelpText(element, -1, -1);
1126 if (text == NULL) /* not found */
1127 text = "No description available";
1129 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1130 sy += getFontHeight(font_nr) / 2;
1132 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1133 max_chars_per_line, max_lines_per_text);
1136 void DrawInfoScreen_Elements()
1138 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1143 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1149 void HandleInfoScreen_Elements(int button)
1151 static unsigned long info_delay = 0;
1152 static int num_anims;
1153 static int num_pages;
1155 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1156 int button_released = !button;
1159 if (button == MB_MENU_INITIALIZE)
1161 boolean new_element = TRUE;
1164 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1166 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1168 else if (new_element)
1171 new_element = FALSE;
1175 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1178 else if (button == MB_MENU_LEAVE)
1180 info_mode = INFO_MODE_MAIN;
1186 if (button_released || button == MB_MENU_INITIALIZE)
1188 if (button != MB_MENU_INITIALIZE)
1191 if (page >= num_pages)
1193 FadeSoundsAndMusic();
1195 info_mode = INFO_MODE_MAIN;
1201 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1205 if (DelayReached(&info_delay, GameFrameDelay))
1206 if (page < num_pages)
1207 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1209 PlayMenuSoundIfLoop();
1213 void DrawInfoScreen_Music()
1215 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1222 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1225 void HandleInfoScreen_Music(int button)
1227 static struct MusicFileInfo *list = NULL;
1228 int ystart = 150, dy = 30;
1229 int ybottom = SYSIZE - 20;
1230 int button_released = !button;
1232 if (button == MB_MENU_INITIALIZE)
1234 list = music_file_info;
1238 FadeSoundsAndMusic();
1243 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1245 DrawTextSCentered(ybottom, FONT_TEXT_4,
1246 "Press any key or button for info menu");
1251 else if (button == MB_MENU_LEAVE)
1253 info_mode = INFO_MODE_MAIN;
1259 if (button_released || button == MB_MENU_INITIALIZE)
1263 if (button != MB_MENU_INITIALIZE)
1269 info_mode = INFO_MODE_MAIN;
1275 FadeSoundsAndMusic();
1282 int sound = list->music;
1284 if (sound_info[sound].loop)
1285 PlaySoundLoop(sound);
1289 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1293 PlayMusic(list->music);
1295 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1298 if (!strEqual(list->title, UNKNOWN_NAME))
1300 if (!strEqual(list->title_header, UNKNOWN_NAME))
1301 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1303 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1306 if (!strEqual(list->artist, UNKNOWN_NAME))
1308 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1309 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1311 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1313 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1316 if (!strEqual(list->album, UNKNOWN_NAME))
1318 if (!strEqual(list->album_header, UNKNOWN_NAME))
1319 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1321 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1323 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1326 if (!strEqual(list->year, UNKNOWN_NAME))
1328 if (!strEqual(list->year_header, UNKNOWN_NAME))
1329 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1331 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1333 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1336 DrawTextSCentered(ybottom, FONT_TEXT_4,
1337 "Press any key or button for next page");
1340 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1341 PlaySoundLoop(list->music);
1344 void DrawInfoScreen_Credits()
1346 int ystart = 150, ystep = 30;
1347 int ybottom = SYSIZE - 20;
1349 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1351 FadeSoundsAndMusic();
1356 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1357 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1358 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1359 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1360 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1361 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1362 "...and many thanks to all contributors");
1363 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1365 DrawTextSCentered(ybottom, FONT_TEXT_4,
1366 "Press any key or button for info menu");
1369 void HandleInfoScreen_Credits(int button)
1371 int button_released = !button;
1373 if (button == MB_MENU_LEAVE)
1375 info_mode = INFO_MODE_MAIN;
1381 if (button_released)
1383 FadeSoundsAndMusic();
1385 info_mode = INFO_MODE_MAIN;
1390 PlayMenuSoundIfLoop();
1394 void DrawInfoScreen_Program()
1396 int ystart = 150, ystep = 30;
1397 int ybottom = SYSIZE - 20;
1399 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1404 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1406 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1407 "This game is Freeware!");
1408 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1409 "If you like it, send e-mail to:");
1410 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1411 "info@artsoft.org");
1412 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1413 "or SnailMail to:");
1414 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1416 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1417 "Detmolder Strasse 189");
1418 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1420 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1423 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1424 "If you have created new levels,");
1425 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1426 "send them to me to include them!");
1427 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1430 DrawTextSCentered(ybottom, FONT_TEXT_4,
1431 "Press any key or button for info menu");
1434 void HandleInfoScreen_Program(int button)
1436 int button_released = !button;
1438 if (button == MB_MENU_LEAVE)
1440 info_mode = INFO_MODE_MAIN;
1446 if (button_released)
1448 FadeSoundsAndMusic();
1450 info_mode = INFO_MODE_MAIN;
1455 PlayMenuSoundIfLoop();
1459 void DrawInfoScreen_LevelSet()
1462 int ybottom = SYSIZE - 20;
1463 char *filename = getLevelSetInfoFilename();
1464 int font_nr = FONT_LEVEL_NUMBER;
1465 int font_width = getFontWidth(font_nr);
1466 int font_height = getFontHeight(font_nr);
1469 int sx = SX + pad_x;
1470 int sy = SY + pad_y;
1471 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1472 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1474 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1479 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1481 DrawTextSCentered(ybottom, FONT_TEXT_4,
1482 "Press any key or button for info menu");
1484 if (filename != NULL)
1485 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1486 max_lines_per_screen);
1488 DrawTextSCentered(ystart, FONT_TEXT_2,
1489 "No information for this level set.");
1492 void HandleInfoScreen_LevelSet(int button)
1494 int button_released = !button;
1496 if (button == MB_MENU_LEAVE)
1498 info_mode = INFO_MODE_MAIN;
1504 if (button_released)
1506 FadeSoundsAndMusic();
1508 info_mode = INFO_MODE_MAIN;
1513 PlayMenuSoundIfLoop();
1517 void DrawInfoScreen()
1519 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1521 if (info_mode == INFO_MODE_ELEMENTS)
1522 DrawInfoScreen_Elements();
1523 else if (info_mode == INFO_MODE_MUSIC)
1524 DrawInfoScreen_Music();
1525 else if (info_mode == INFO_MODE_CREDITS)
1526 DrawInfoScreen_Credits();
1527 else if (info_mode == INFO_MODE_PROGRAM)
1528 DrawInfoScreen_Program();
1529 else if (info_mode == INFO_MODE_LEVELSET)
1530 DrawInfoScreen_LevelSet();
1532 DrawInfoScreen_Main();
1534 if (info_mode != INFO_MODE_MUSIC)
1541 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1543 if (info_mode == INFO_MODE_ELEMENTS)
1544 HandleInfoScreen_Elements(button);
1545 else if (info_mode == INFO_MODE_MUSIC)
1546 HandleInfoScreen_Music(button);
1547 else if (info_mode == INFO_MODE_CREDITS)
1548 HandleInfoScreen_Credits(button);
1549 else if (info_mode == INFO_MODE_PROGRAM)
1550 HandleInfoScreen_Program(button);
1551 else if (info_mode == INFO_MODE_LEVELSET)
1552 HandleInfoScreen_LevelSet(button);
1554 HandleInfoScreen_Main(mx, my, dx, dy, button);
1560 /* ========================================================================= */
1561 /* type name functions */
1562 /* ========================================================================= */
1564 void HandleTypeName(int newxpos, Key key)
1566 static int xpos = 0, ypos = 2;
1567 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1568 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1569 int startx = mSX + 32 + name_width;
1570 int starty = mSY + ypos * 32;
1576 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1577 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1582 if (((key >= KSYM_A && key <= KSYM_Z) ||
1583 (key >= KSYM_a && key <= KSYM_z)) &&
1584 xpos < MAX_PLAYER_NAME_LEN)
1588 if (key >= KSYM_A && key <= KSYM_Z)
1589 ascii = 'A' + (char)(key - KSYM_A);
1591 ascii = 'a' + (char)(key - KSYM_a);
1593 setup.player_name[xpos] = ascii;
1594 setup.player_name[xpos + 1] = 0;
1597 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1598 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1600 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1603 setup.player_name[xpos] = 0;
1605 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1607 else if (key == KSYM_Return && xpos > 0)
1609 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1610 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1613 game_status = GAME_MODE_MAIN;
1618 /* ========================================================================= */
1619 /* tree menu functions */
1620 /* ========================================================================= */
1622 static void DrawChooseTree(TreeInfo **ti_ptr)
1626 FreeScreenGadgets();
1627 CreateScreenGadgets();
1629 CloseDoor(DOOR_CLOSE_2);
1633 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1634 MapChooseTreeGadgets(*ti_ptr);
1640 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1642 struct GadgetInfo *gi = screen_gadget[id];
1643 int items_max, items_visible, item_position;
1645 items_max = numTreeInfoInGroup(ti);
1646 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1647 item_position = first_entry;
1649 if (item_position > items_max - items_visible)
1650 item_position = items_max - items_visible;
1652 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1653 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1654 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1657 static void drawChooseTreeList(int first_entry, int num_page_entries,
1661 char *title_string = NULL;
1663 int xoffset_sets = 16;
1665 int yoffset_sets = MENU_TITLE1_YPOS;
1667 int xoffset_setup = 16;
1669 int yoffset_setup = 16;
1672 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1675 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1678 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1679 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1681 int last_game_status = game_status; /* save current game status */
1684 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1685 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1686 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1687 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1690 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1692 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1695 /* force LEVELS font on artwork setup screen */
1696 game_status = GAME_MODE_LEVELS;
1698 /* clear tree list area, but not title or scrollbar */
1699 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1700 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
1701 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1703 for (i = 0; i < num_page_entries; i++)
1705 TreeInfo *node, *node_first;
1706 int entry_pos = first_entry + i;
1707 int xpos = MENU_SCREEN_START_XPOS;
1708 int ypos = MENU_SCREEN_START_YPOS + i;
1709 int startx = mSX + xpos * 32;
1710 int starty = mSY + ypos * 32;
1711 int font_nr = FONT_TEXT_1;
1712 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
1713 int startx_text = startx + font_xoffset;
1714 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1715 int text_size = startx_scrollbar - startx_text;
1716 int max_buffer_len = text_size / getFontWidth(font_nr);
1717 char buffer[max_buffer_len + 1];
1719 node_first = getTreeInfoFirstGroupEntry(ti);
1720 node = getTreeInfoFromPos(node_first, entry_pos);
1722 strncpy(buffer, node->name, max_buffer_len);
1723 buffer[max_buffer_len] = '\0';
1725 DrawText(startx, starty, buffer, font_nr + node->color);
1727 if (node->parent_link)
1728 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1729 else if (node->level_group)
1730 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1732 initCursor(i, IMG_MENU_BUTTON);
1735 game_status = last_game_status; /* restore current game status */
1737 redraw_mask |= REDRAW_FIELD;
1740 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1742 TreeInfo *node, *node_first;
1743 int x, last_redraw_mask = redraw_mask;
1745 int ypos = MENU_TITLE2_YPOS;
1750 if (ti->type != TREE_TYPE_LEVEL_DIR)
1753 node_first = getTreeInfoFirstGroupEntry(ti);
1754 node = getTreeInfoFromPos(node_first, entry_pos);
1756 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1758 if (node->parent_link)
1759 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1761 else if (node->level_group)
1762 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1764 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1765 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1766 node->levels, node->class_desc);
1768 /* let BackToFront() redraw only what is needed */
1769 redraw_mask = last_redraw_mask | REDRAW_TILES;
1770 for (x = 0; x < SCR_FIELDX; x++)
1771 MarkTileDirty(x, 1);
1774 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1777 TreeInfo *ti = *ti_ptr;
1779 int y = ti->cl_cursor;
1780 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1781 int num_entries = numTreeInfoInGroup(ti);
1782 int num_page_entries;
1783 int last_game_status = game_status; /* save current game status */
1784 boolean position_set_by_scrollbar = (dx == 999);
1786 /* force LEVELS draw offset on choose level and artwork setup screen */
1787 game_status = GAME_MODE_LEVELS;
1789 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1790 num_page_entries = num_entries;
1792 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1794 game_status = last_game_status; /* restore current game status */
1796 if (button == MB_MENU_INITIALIZE)
1798 int num_entries = numTreeInfoInGroup(ti);
1799 int entry_pos = posTreeInfo(ti);
1801 if (ti->cl_first == -1)
1803 /* only on initialization */
1804 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1805 ti->cl_cursor = entry_pos - ti->cl_first;
1807 else if (ti->cl_cursor >= num_page_entries ||
1808 (num_entries > num_page_entries &&
1809 num_entries - ti->cl_first < num_page_entries))
1811 /* only after change of list size (by custom graphic configuration) */
1812 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1813 ti->cl_cursor = entry_pos - ti->cl_first;
1816 if (position_set_by_scrollbar)
1819 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1822 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1823 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1824 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1828 else if (button == MB_MENU_LEAVE)
1830 if (ti->node_parent)
1832 *ti_ptr = ti->node_parent;
1833 DrawChooseTree(ti_ptr);
1835 else if (game_status == GAME_MODE_SETUP)
1841 game_status = GAME_MODE_MAIN;
1848 if (mx || my) /* mouse input */
1850 int last_game_status = game_status; /* save current game status */
1852 /* force LEVELS draw offset on artwork setup screen */
1853 game_status = GAME_MODE_LEVELS;
1855 x = (mx - mSX) / 32;
1856 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1858 game_status = last_game_status; /* restore current game status */
1860 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1862 /* move cursor instead of scrolling when already at start/end of list */
1863 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1865 else if (dy == +1 * SCROLL_LINE &&
1866 ti->cl_first + num_page_entries == num_entries)
1869 /* handle scrolling screen one line or page */
1870 if (ti->cl_cursor + dy < 0 ||
1871 ti->cl_cursor + dy > num_page_entries - 1)
1873 if (ABS(dy) == SCROLL_PAGE)
1874 step = num_page_entries - 1;
1876 if (dy < 0 && ti->cl_first > 0)
1878 /* scroll page/line up */
1880 ti->cl_first -= step;
1881 if (ti->cl_first < 0)
1884 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1885 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1886 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1887 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1890 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1892 /* scroll page/line down */
1894 ti->cl_first += step;
1895 if (ti->cl_first + num_page_entries > num_entries)
1896 ti->cl_first = MAX(0, num_entries - num_page_entries);
1898 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1899 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1900 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1901 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1908 /* handle moving cursor one line */
1909 y = ti->cl_cursor + dy;
1914 TreeInfo *node_first, *node_cursor;
1915 int entry_pos = ti->cl_first + y;
1917 node_first = getTreeInfoFirstGroupEntry(ti);
1918 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1920 if (node_cursor->node_group)
1922 node_cursor->cl_first = ti->cl_first;
1923 node_cursor->cl_cursor = ti->cl_cursor;
1924 *ti_ptr = node_cursor->node_group;
1925 DrawChooseTree(ti_ptr);
1930 else if (dx == -1 && ti->node_parent)
1932 *ti_ptr = ti->node_parent;
1933 DrawChooseTree(ti_ptr);
1938 if (!anyScrollbarGadgetActive() &&
1939 IN_VIS_FIELD(x, y) &&
1940 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1941 y >= 0 && y < num_page_entries)
1945 if (y != ti->cl_cursor)
1947 drawChooseTreeCursor(y, FC_RED);
1948 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1949 drawChooseTreeInfo(ti->cl_first + y, ti);
1955 TreeInfo *node_first, *node_cursor;
1956 int entry_pos = ti->cl_first + y;
1958 node_first = getTreeInfoFirstGroupEntry(ti);
1959 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1961 if (node_cursor->node_group)
1963 node_cursor->cl_first = ti->cl_first;
1964 node_cursor->cl_cursor = ti->cl_cursor;
1965 *ti_ptr = node_cursor->node_group;
1966 DrawChooseTree(ti_ptr);
1968 else if (node_cursor->parent_link)
1970 *ti_ptr = node_cursor->node_parent;
1971 DrawChooseTree(ti_ptr);
1975 node_cursor->cl_first = ti->cl_first;
1976 node_cursor->cl_cursor = ti->cl_cursor;
1977 *ti_ptr = node_cursor;
1979 if (ti->type == TREE_TYPE_LEVEL_DIR)
1981 LoadLevelSetup_SeriesInfo();
1983 SaveLevelSetup_LastSeries();
1984 SaveLevelSetup_SeriesInfo();
1988 if (game_status == GAME_MODE_SETUP)
1994 game_status = GAME_MODE_MAIN;
2002 void DrawChooseLevel()
2004 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2006 DrawChooseTree(&leveldir_current);
2012 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2014 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2019 void DrawHallOfFame(int highlight_position)
2022 FadeSoundsAndMusic();
2023 CloseDoor(DOOR_CLOSE_2);
2025 if (highlight_position < 0)
2026 LoadScore(level_nr);
2034 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2037 static void drawHallOfFameList(int first_entry, int highlight_position)
2041 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2045 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2046 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2047 "HighScores of Level %d", level_nr);
2049 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2050 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2051 "HighScores of Level %d", level_nr);
2054 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2056 int entry = first_entry + i;
2057 boolean active = (entry == highlight_position);
2058 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2059 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2060 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2061 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2062 int dx1 = 3 * getFontWidth(font_nr1);
2063 int dx2 = dx1 + getFontWidth(font_nr1);
2064 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2065 int sy = mSY + 64 + i * 32;
2067 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2068 DrawText(mSX + dx1, sy, ".", font_nr1);
2069 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2071 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2072 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2074 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2077 redraw_mask |= REDRAW_FIELD;
2080 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2082 static int first_entry = 0;
2083 static int highlight_position = 0;
2084 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2085 int button_released = !button;
2087 if (button == MB_MENU_INITIALIZE)
2090 highlight_position = mx;
2091 drawHallOfFameList(first_entry, highlight_position);
2096 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2097 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2101 if (first_entry > 0)
2103 first_entry -= step;
2104 if (first_entry < 0)
2107 drawHallOfFameList(first_entry, highlight_position);
2112 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2114 first_entry += step;
2115 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2116 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2118 drawHallOfFameList(first_entry, highlight_position);
2121 else if (button_released)
2123 FadeSound(SND_BACKGROUND_SCORES);
2124 game_status = GAME_MODE_MAIN;
2128 if (game_status == GAME_MODE_SCORES)
2129 PlayMenuSoundIfLoop();
2135 /* ========================================================================= */
2136 /* setup screen functions */
2137 /* ========================================================================= */
2139 static struct TokenInfo *setup_info;
2140 static int num_setup_info;
2142 static char *graphics_set_name;
2143 static char *sounds_set_name;
2144 static char *music_set_name;
2146 static void execSetupMain()
2148 setup_mode = SETUP_MODE_MAIN;
2152 static void execSetupGame()
2154 setup_mode = SETUP_MODE_GAME;
2158 static void execSetupEditor()
2160 setup_mode = SETUP_MODE_EDITOR;
2164 static void execSetupGraphics()
2166 setup_mode = SETUP_MODE_GRAPHICS;
2170 static void execSetupSound()
2172 setup_mode = SETUP_MODE_SOUND;
2176 static void execSetupArtwork()
2178 setup.graphics_set = artwork.gfx_current->identifier;
2179 setup.sounds_set = artwork.snd_current->identifier;
2180 setup.music_set = artwork.mus_current->identifier;
2182 /* needed if last screen (setup choice) changed graphics, sounds or music */
2183 ReloadCustomArtwork(0);
2185 /* needed for displaying artwork name instead of artwork identifier */
2186 graphics_set_name = artwork.gfx_current->name;
2187 sounds_set_name = artwork.snd_current->name;
2188 music_set_name = artwork.mus_current->name;
2190 setup_mode = SETUP_MODE_ARTWORK;
2194 static void execSetupChooseGraphics()
2196 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2200 static void execSetupChooseSounds()
2202 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2206 static void execSetupChooseMusic()
2208 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2212 static void execSetupInput()
2214 setup_mode = SETUP_MODE_INPUT;
2218 static void execSetupShortcut1()
2220 setup_mode = SETUP_MODE_SHORTCUT_1;
2224 static void execSetupShortcut2()
2226 setup_mode = SETUP_MODE_SHORTCUT_2;
2230 static void execExitSetup()
2232 game_status = GAME_MODE_MAIN;
2236 static void execSaveAndExitSetup()
2242 static struct TokenInfo setup_info_main[] =
2244 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2245 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2246 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2247 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2248 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2249 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2250 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2251 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2252 { TYPE_EMPTY, NULL, "" },
2253 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2254 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2259 static struct TokenInfo setup_info_game[] =
2261 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2262 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2263 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2264 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2265 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2266 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2267 { TYPE_EMPTY, NULL, "" },
2268 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2273 static struct TokenInfo setup_info_editor[] =
2276 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2277 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2278 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2279 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2280 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2281 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2282 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2283 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2285 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2286 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2287 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2288 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2289 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2290 { TYPE_EMPTY, NULL, "" },
2291 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2292 { TYPE_EMPTY, NULL, "" },
2293 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2298 static struct TokenInfo setup_info_graphics[] =
2300 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen Mode:" },
2301 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2303 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2304 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2305 { TYPE_SWITCH, &setup.fading, "Fading:" },
2307 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2308 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2309 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2310 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2311 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2312 { TYPE_EMPTY, NULL, "" },
2313 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2318 static struct TokenInfo setup_info_sound[] =
2320 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2321 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2322 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2323 { TYPE_EMPTY, NULL, "" },
2324 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2329 static struct TokenInfo setup_info_artwork[] =
2331 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2332 { TYPE_STRING, &graphics_set_name, "" },
2333 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2334 { TYPE_STRING, &sounds_set_name, "" },
2335 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2336 { TYPE_STRING, &music_set_name, "" },
2337 { TYPE_EMPTY, NULL, "" },
2339 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2340 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2341 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2343 { TYPE_STRING, NULL, "Override Level Artwork:"},
2344 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2345 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2346 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2348 { TYPE_EMPTY, NULL, "" },
2349 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2354 static struct TokenInfo setup_info_shortcut_1[] =
2356 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2357 { TYPE_KEY, &setup.shortcut.save_game, "" },
2358 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2359 { TYPE_KEY, &setup.shortcut.load_game, "" },
2360 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2361 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2362 { TYPE_EMPTY, NULL, "" },
2363 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2364 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2365 { TYPE_EMPTY, NULL, "" },
2366 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2371 static struct TokenInfo setup_info_shortcut_2[] =
2373 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2374 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2375 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2376 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2377 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2378 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2379 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2380 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2381 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2382 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2383 { TYPE_EMPTY, NULL, "" },
2384 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2389 static Key getSetupKey()
2391 Key key = KSYM_UNDEFINED;
2392 boolean got_key_event = FALSE;
2394 while (!got_key_event)
2396 if (PendingEvent()) /* got event */
2404 case EVENT_KEYPRESS:
2406 key = GetEventKey((KeyEvent *)&event, TRUE);
2408 /* press 'Escape' or 'Enter' to keep the existing key binding */
2409 if (key == KSYM_Escape || key == KSYM_Return)
2410 key = KSYM_UNDEFINED; /* keep old value */
2412 got_key_event = TRUE;
2416 case EVENT_KEYRELEASE:
2417 key_joystick_mapping = 0;
2421 HandleOtherEvents(&event);
2429 /* don't eat all CPU time */
2436 static int getSetupTextFont(int type)
2438 if (type & (TYPE_SWITCH |
2448 static int getSetupValueFont(int type, void *value)
2450 if (type & TYPE_KEY)
2451 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2452 else if (type & TYPE_STRING)
2453 return FONT_VALUE_2;
2454 else if (type & TYPE_ECS_AGA)
2455 return FONT_VALUE_1;
2456 else if (type & TYPE_BOOLEAN_STYLE)
2457 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2459 return FONT_VALUE_1;
2462 static void drawSetupValue(int pos)
2464 boolean font_draw_xoffset_modified = FALSE;
2465 int font_draw_xoffset_old = -1;
2466 int xpos = MENU_SCREEN_VALUE_XPOS;
2467 int ypos = MENU_SCREEN_START_YPOS + pos;
2468 int startx = mSX + xpos * 32;
2469 int starty = mSY + ypos * 32;
2470 int font_nr, font_width;
2471 int type = setup_info[pos].type;
2472 void *value = setup_info[pos].value;
2473 char *value_string = getSetupValue(type, value);
2476 if (value_string == NULL)
2479 if (type & TYPE_KEY)
2482 xpos = MENU_SCREEN_START_XPOS;
2487 if (type & TYPE_QUERY)
2489 value_string = "<press key>";
2491 font_nr = FONT_INPUT_1_ACTIVE;
2495 else if (type & TYPE_STRING)
2497 int max_value_len = (SCR_FIELDX - 2) * 2;
2499 xpos = MENU_SCREEN_START_XPOS;
2501 font_nr = FONT_VALUE_2;
2504 if (strlen(value_string) > max_value_len)
2505 value_string[max_value_len] = '\0';
2507 else if (type & TYPE_ECS_AGA)
2510 font_nr = FONT_VALUE_1;
2513 else if (type & TYPE_BOOLEAN_STYLE)
2516 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2520 startx = mSX + xpos * 32;
2521 starty = mSY + ypos * 32;
2522 font_nr = getSetupValueFont(type, value);
2523 font_width = getFontWidth(font_nr);
2525 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2526 if (setup_mode != SETUP_MODE_INPUT)
2528 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
2529 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2530 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
2531 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
2532 int text_font_nr = getSetupTextFont(FONT_MENU_2);
2533 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
2534 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
2535 boolean correct_font_draw_xoffset = FALSE;
2537 if (xpos == MENU_SCREEN_START_XPOS &&
2538 startx + font1_xoffset < text_startx + text_font_xoffset)
2539 correct_font_draw_xoffset = TRUE;
2541 if (xpos == MENU_SCREEN_VALUE_XPOS &&
2542 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
2543 correct_font_draw_xoffset = TRUE;
2546 printf("::: %d + %d < %d + %d + %d\n",
2547 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
2548 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
2551 /* check if setup value would overlap with setup text when printed */
2552 /* (this can happen for extreme/wrong values for font draw offset) */
2553 if (correct_font_draw_xoffset)
2555 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
2556 font_draw_xoffset_modified = TRUE;
2558 if (type & TYPE_KEY)
2559 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
2560 else if (!(type & TYPE_STRING))
2561 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
2562 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
2567 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
2568 DrawText(startx + i * font_width, starty, " ", font_nr);
2571 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
2572 DrawText(mSX + i * 32, starty, " ", font_nr);
2574 DrawText(startx, starty,
2575 (xpos == 3 ? " " : " "), font_nr);
2579 DrawText(startx, starty, value_string, font_nr);
2581 if (font_draw_xoffset_modified)
2582 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
2585 static void changeSetupValue(int pos)
2587 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2589 *(boolean *)setup_info[pos].value ^= TRUE;
2591 else if (setup_info[pos].type & TYPE_KEY)
2595 setup_info[pos].type |= TYPE_QUERY;
2596 drawSetupValue(pos);
2597 setup_info[pos].type &= ~TYPE_QUERY;
2599 key = getSetupKey();
2600 if (key != KSYM_UNDEFINED)
2601 *(Key *)setup_info[pos].value = key;
2604 drawSetupValue(pos);
2607 static void DrawSetupScreen_Generic()
2609 char *title_string = NULL;
2613 CloseDoor(DOOR_CLOSE_2);
2617 if (setup_mode == SETUP_MODE_MAIN)
2619 setup_info = setup_info_main;
2620 title_string = "Setup";
2622 else if (setup_mode == SETUP_MODE_GAME)
2624 setup_info = setup_info_game;
2625 title_string = "Setup Game";
2627 else if (setup_mode == SETUP_MODE_EDITOR)
2629 setup_info = setup_info_editor;
2630 title_string = "Setup Editor";
2632 else if (setup_mode == SETUP_MODE_GRAPHICS)
2634 setup_info = setup_info_graphics;
2635 title_string = "Setup Graphics";
2637 else if (setup_mode == SETUP_MODE_SOUND)
2639 setup_info = setup_info_sound;
2640 title_string = "Setup Sound";
2642 else if (setup_mode == SETUP_MODE_ARTWORK)
2644 setup_info = setup_info_artwork;
2645 title_string = "Custom Artwork";
2647 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
2649 setup_info = setup_info_shortcut_1;
2650 title_string = "Setup Shortcuts";
2652 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
2654 setup_info = setup_info_shortcut_2;
2655 title_string = "Setup Shortcuts";
2659 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2661 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2665 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2667 void *value_ptr = setup_info[i].value;
2668 int xpos = MENU_SCREEN_START_XPOS;
2669 int ypos = MENU_SCREEN_START_YPOS + i;
2673 int font_nr = FONT_MENU_1;
2676 /* set some entries to "unchangeable" according to other variables */
2677 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2678 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2679 (value_ptr == &setup.sound_music && !audio.music_available) ||
2680 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2681 setup_info[i].type |= TYPE_GHOSTED;
2684 font_nr = getSetupTextFont(setup_info[i].type);
2687 if (setup_info[i].type & (TYPE_SWITCH |
2692 font_nr = FONT_MENU_2;
2694 if (setup_info[i].type & TYPE_STRING)
2695 font_nr = FONT_MENU_2;
2699 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2701 if (setup_info[i].type & TYPE_ENTER_MENU)
2702 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2703 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2704 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2705 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2706 initCursor(i, IMG_MENU_BUTTON);
2708 if (setup_info[i].type & TYPE_VALUE)
2715 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2716 "Joysticks deactivated in setup menu");
2721 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2724 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2726 static int choice_store[MAX_SETUP_MODES];
2727 int choice = choice_store[setup_mode]; /* always starts with 0 */
2731 if (button == MB_MENU_INITIALIZE)
2733 /* advance to first valid menu entry */
2734 while (choice < num_setup_info &&
2735 setup_info[choice].type & TYPE_SKIP_ENTRY)
2737 choice_store[setup_mode] = choice;
2739 drawCursor(choice, FC_RED);
2742 else if (button == MB_MENU_LEAVE)
2744 for (y = 0; y < num_setup_info; y++)
2746 if (setup_info[y].type & TYPE_LEAVE_MENU)
2748 void (*menu_callback_function)(void) = setup_info[y].value;
2750 menu_callback_function();
2751 break; /* absolutely needed because function changes 'setup_info'! */
2758 if (mx || my) /* mouse input */
2760 x = (mx - mSX) / 32;
2761 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2763 else if (dx || dy) /* keyboard input */
2767 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2769 if (setup_info[choice].type & menu_navigation_type ||
2770 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2771 button = MB_MENU_CHOICE;
2776 /* jump to next non-empty menu entry (up or down) */
2777 while (y > 0 && y < num_setup_info - 1 &&
2778 setup_info[y].type & TYPE_SKIP_ENTRY)
2782 if (IN_VIS_FIELD(x, y) &&
2783 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2789 drawCursor(y, FC_RED);
2790 drawCursor(choice, FC_BLUE);
2791 choice = choice_store[setup_mode] = y;
2794 else if (!(setup_info[y].type & TYPE_GHOSTED))
2796 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2798 void (*menu_callback_function)(void) = setup_info[choice].value;
2800 menu_callback_function();
2804 if (setup_info[y].type & TYPE_KEYTEXT &&
2805 setup_info[y + 1].type & TYPE_KEY)
2808 if (setup_info[y].type & TYPE_VALUE)
2809 changeSetupValue(y);
2815 void DrawSetupScreen_Input()
2820 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2822 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2825 initCursor(0, IMG_MENU_BUTTON);
2826 initCursor(1, IMG_MENU_BUTTON);
2827 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2828 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2830 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2831 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2833 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2834 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2835 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2838 DeactivateJoystickForCalibration();
2841 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2842 "Joysticks deactivated on this screen");
2845 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2850 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2852 if (device_name == NULL)
2855 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2858 if (strlen(device_name) > 1)
2860 char c1 = device_name[strlen(device_name) - 1];
2861 char c2 = device_name[strlen(device_name) - 2];
2863 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2864 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2867 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2868 strlen(device_name));
2871 static void drawPlayerSetupInputInfo(int player_nr)
2874 static struct SetupKeyboardInfo custom_key;
2881 { &custom_key.left, "Joystick Left" },
2882 { &custom_key.right, "Joystick Right" },
2883 { &custom_key.up, "Joystick Up" },
2884 { &custom_key.down, "Joystick Down" },
2885 { &custom_key.snap, "Button 1" },
2886 { &custom_key.drop, "Button 2" }
2888 static char *joystick_name[MAX_PLAYERS] =
2898 custom_key = setup.input[player_nr].key;
2900 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2901 FONT_INPUT_1_ACTIVE);
2903 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2905 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2906 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2908 if (setup.input[player_nr].use_joystick)
2910 char *device_name = setup.input[player_nr].joy.device_name;
2911 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
2912 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
2914 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
2915 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
2919 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
2920 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
2923 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
2924 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2925 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2926 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2927 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2928 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
2929 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
2930 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
2931 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
2932 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
2933 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
2935 for (i = 0; i < 6; i++)
2937 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2939 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2941 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2942 (setup.input[player_nr].use_joystick ?
2944 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2948 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2950 static int choice = 0;
2951 static int player_nr = 0;
2954 int pos_start = SETUPINPUT_SCREEN_POS_START;
2955 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2956 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2957 int pos_end = SETUPINPUT_SCREEN_POS_END;
2959 if (button == MB_MENU_INITIALIZE)
2961 drawPlayerSetupInputInfo(player_nr);
2962 drawCursor(choice, FC_RED);
2966 else if (button == MB_MENU_LEAVE)
2968 setup_mode = SETUP_MODE_MAIN;
2975 if (mx || my) /* mouse input */
2977 x = (mx - mSX) / 32;
2978 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2980 else if (dx || dy) /* keyboard input */
2982 if (dx && choice == 0)
2983 x = (dx < 0 ? 10 : 12);
2984 else if ((dx && choice == 1) ||
2985 (dx == +1 && choice == 2) ||
2986 (dx == -1 && choice == pos_end))
2987 button = MB_MENU_CHOICE;
2991 if (y >= pos_empty1 && y <= pos_empty2)
2992 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2995 if (IN_VIS_FIELD(x, y) &&
2996 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2998 static unsigned long delay = 0;
3000 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3003 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3005 drawPlayerSetupInputInfo(player_nr);
3007 else if (IN_VIS_FIELD(x, y) &&
3008 y >= pos_start && y <= pos_end &&
3009 !(y >= pos_empty1 && y <= pos_empty2))
3015 drawCursor(y, FC_RED);
3016 drawCursor(choice, FC_BLUE);
3024 char *device_name = setup.input[player_nr].joy.device_name;
3026 if (!setup.input[player_nr].use_joystick)
3028 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3030 setJoystickDeviceToNr(device_name, new_device_nr);
3031 setup.input[player_nr].use_joystick = TRUE;
3035 int device_nr = getJoystickNrFromDeviceName(device_name);
3036 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3038 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3039 setup.input[player_nr].use_joystick = FALSE;
3041 setJoystickDeviceToNr(device_name, new_device_nr);
3044 drawPlayerSetupInputInfo(player_nr);
3048 if (setup.input[player_nr].use_joystick)
3051 CalibrateJoystick(player_nr);
3054 CustomizeKeyboard(player_nr);
3056 else if (y == pos_end)
3060 setup_mode = SETUP_MODE_MAIN;
3067 void CustomizeKeyboard(int player_nr)
3071 boolean finished = FALSE;
3072 static struct SetupKeyboardInfo custom_key;
3077 } customize_step[] =
3079 { &custom_key.left, "Move Left" },
3080 { &custom_key.right, "Move Right" },
3081 { &custom_key.up, "Move Up" },
3082 { &custom_key.down, "Move Down" },
3083 { &custom_key.snap, "Snap Field" },
3084 { &custom_key.drop, "Drop Element" }
3087 /* read existing key bindings from player setup */
3088 custom_key = setup.input[player_nr].key;
3093 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3095 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3102 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3103 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3104 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3105 "Key:", FONT_INPUT_1_ACTIVE);
3106 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3107 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3111 if (PendingEvent()) /* got event */
3119 case EVENT_KEYPRESS:
3121 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3123 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3129 /* all keys configured -- wait for "Escape" or "Return" key */
3133 /* press 'Enter' to keep the existing key binding */
3134 if (key == KSYM_Return)
3135 key = *customize_step[step_nr].key;
3137 /* check if key already used */
3138 for (i = 0; i < step_nr; i++)
3139 if (*customize_step[i].key == key)
3144 /* got new key binding */
3145 *customize_step[step_nr].key = key;
3146 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3148 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3149 getKeyNameFromKey(key), FONT_VALUE_1);
3152 /* un-highlight last query */
3153 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3154 customize_step[step_nr - 1].text, FONT_MENU_1);
3155 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3156 "Key:", FONT_MENU_1);
3158 /* press 'Enter' to leave */
3161 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3162 "Press Enter", FONT_TITLE_1);
3166 /* query next key binding */
3167 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3168 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3169 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3170 "Key:", FONT_INPUT_1_ACTIVE);
3171 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3172 getKeyNameFromKey(*customize_step[step_nr].key),
3177 case EVENT_KEYRELEASE:
3178 key_joystick_mapping = 0;
3182 HandleOtherEvents(&event);
3190 /* don't eat all CPU time */
3194 /* write new key bindings back to player setup */
3195 setup.input[player_nr].key = custom_key;
3198 DrawSetupScreen_Input();
3201 static boolean CalibrateJoystickMain(int player_nr)
3203 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3204 int new_joystick_xright = JOYSTICK_XMIDDLE;
3205 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3206 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3207 int new_joystick_xmiddle, new_joystick_ymiddle;
3209 int joystick_fd = joystick.fd[player_nr];
3210 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3211 boolean check[3][3];
3212 int check_remaining = 3 * 3;
3217 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3220 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3225 for (y = 0; y < 3; y++)
3227 for (x = 0; x < 3; x++)
3229 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3230 check[x][y] = FALSE;
3234 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3235 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3236 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3237 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3238 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3239 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3240 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3242 joy_value = Joystick(player_nr);
3243 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3244 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3246 /* eventually uncalibrated center position (joystick could be uncentered) */
3247 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3250 new_joystick_xmiddle = joy_x;
3251 new_joystick_ymiddle = joy_y;
3253 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3256 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3261 if (PendingEvent()) /* got event */
3269 case EVENT_KEYPRESS:
3270 switch(GetEventKey((KeyEvent *)&event, TRUE))
3273 if (check_remaining == 0)
3286 case EVENT_KEYRELEASE:
3287 key_joystick_mapping = 0;
3291 HandleOtherEvents(&event);
3296 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3299 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3300 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3301 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3302 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3304 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3305 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3306 setup.input[player_nr].joy.xright = new_joystick_xright;
3307 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3308 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3309 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3311 CheckJoystickData();
3313 joy_value = Joystick(player_nr);
3315 if (joy_value & JOY_BUTTON && check_remaining == 0)
3318 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3319 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3321 if (x != last_x || y != last_y)
3323 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3324 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3329 if (check_remaining > 0 && !check[x+1][y+1])
3331 check[x+1][y+1] = TRUE;
3337 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3338 setup.input[player_nr].joy.xleft,
3339 setup.input[player_nr].joy.xmiddle,
3340 setup.input[player_nr].joy.xright);
3341 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3342 setup.input[player_nr].joy.yupper,
3343 setup.input[player_nr].joy.ymiddle,
3344 setup.input[player_nr].joy.ylower);
3353 /* don't eat all CPU time */
3357 /* calibrated center position (joystick should now be centered) */
3358 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3361 new_joystick_xmiddle = joy_x;
3362 new_joystick_ymiddle = joy_y;
3367 DrawSetupScreen_Input();
3370 /* wait until the last pressed button was released */
3371 while (Joystick(player_nr) & JOY_BUTTON)
3373 if (PendingEvent()) /* got event */
3378 HandleOtherEvents(&event);
3387 void CalibrateJoystick(int player_nr)
3389 if (!CalibrateJoystickMain(player_nr))
3391 char *device_name = setup.input[player_nr].joy.device_name;
3392 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3393 int xpos = mSX - SX;
3394 int ypos = mSY - SY;
3398 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3399 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3402 Delay(2000); /* show error message for a short time */
3408 DrawSetupScreen_Input();
3412 void DrawSetupScreen()
3414 DeactivateJoystick();
3416 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3418 if (setup_mode == SETUP_MODE_INPUT)
3419 DrawSetupScreen_Input();
3420 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3421 DrawChooseTree(&artwork.gfx_current);
3422 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3423 DrawChooseTree(&artwork.snd_current);
3424 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3425 DrawChooseTree(&artwork.mus_current);
3427 DrawSetupScreen_Generic();
3433 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3435 if (setup_mode == SETUP_MODE_INPUT)
3436 HandleSetupScreen_Input(mx, my, dx, dy, button);
3437 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3438 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3439 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3440 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3441 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3442 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3444 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3449 void HandleGameActions()
3451 if (game_status != GAME_MODE_PLAYING)
3454 GameActions(); /* main game loop */
3456 if (tape.auto_play && !tape.playing)
3457 AutoPlayTape(); /* continue automatically playing next tape */
3461 /* ---------- new screen button stuff -------------------------------------- */
3465 int gfx_unpressed, gfx_pressed;
3469 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3472 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3473 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3474 SCREEN_CTRL_ID_SCROLL_UP,
3478 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3479 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3480 SCREEN_CTRL_ID_SCROLL_DOWN,
3487 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3488 Bitmap **gfx_unpressed, **gfx_pressed;
3490 int gfx_unpressed, gfx_pressed;
3497 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3500 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3501 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3503 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3505 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3506 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3507 GD_TYPE_SCROLLBAR_VERTICAL,
3508 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3509 "scroll level series vertically"
3513 static void CreateScreenScrollbuttons()
3515 struct GadgetInfo *gi;
3516 unsigned long event_mask;
3519 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3521 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3522 int gfx_unpressed, gfx_pressed;
3523 int x, y, width, height;
3524 int gd_x1, gd_x2, gd_y1, gd_y2;
3525 int id = scrollbutton_info[i].gadget_id;
3527 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3529 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3530 y = mSY + scrollbutton_info[i].y;
3531 width = SC_SCROLLBUTTON_XSIZE;
3532 height = SC_SCROLLBUTTON_YSIZE;
3534 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3535 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3536 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3538 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3539 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3540 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3541 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3542 gd_x1 = graphic_info[gfx_unpressed].src_x;
3543 gd_y1 = graphic_info[gfx_unpressed].src_y;
3544 gd_x2 = graphic_info[gfx_pressed].src_x;
3545 gd_y2 = graphic_info[gfx_pressed].src_y;
3547 gi = CreateGadget(GDI_CUSTOM_ID, id,
3548 GDI_CUSTOM_TYPE_ID, i,
3549 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3554 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3555 GDI_STATE, GD_BUTTON_UNPRESSED,
3556 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3557 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3558 GDI_DIRECT_DRAW, FALSE,
3559 GDI_EVENT_MASK, event_mask,
3560 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3564 Error(ERR_EXIT, "cannot create gadget");
3566 screen_gadget[id] = gi;
3570 static void CreateScreenScrollbars()
3574 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3576 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3577 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3578 int gfx_unpressed, gfx_pressed;
3580 int x, y, width, height;
3581 int gd_x1, gd_x2, gd_y1, gd_y2;
3582 struct GadgetInfo *gi;
3583 int items_max, items_visible, item_position;
3584 unsigned long event_mask;
3585 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3586 int id = scrollbar_info[i].gadget_id;
3588 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3590 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3591 y = mSY + scrollbar_info[i].y;
3592 width = scrollbar_info[i].width;
3593 height = scrollbar_info[i].height;
3595 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3596 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3598 items_max = num_page_entries;
3599 items_visible = num_page_entries;
3602 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3603 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3604 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3610 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3611 gfx_pressed = scrollbar_info[i].gfx_pressed;
3612 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3613 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3614 gd_x1 = graphic_info[gfx_unpressed].src_x;
3615 gd_y1 = graphic_info[gfx_unpressed].src_y;
3616 gd_x2 = graphic_info[gfx_pressed].src_x;
3617 gd_y2 = graphic_info[gfx_pressed].src_y;
3620 gi = CreateGadget(GDI_CUSTOM_ID, id,
3621 GDI_CUSTOM_TYPE_ID, i,
3622 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3627 GDI_TYPE, scrollbar_info[i].type,
3628 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3629 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3630 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3631 GDI_STATE, GD_BUTTON_UNPRESSED,
3632 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3633 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3634 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3635 GDI_DIRECT_DRAW, FALSE,
3636 GDI_EVENT_MASK, event_mask,
3637 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3641 Error(ERR_EXIT, "cannot create gadget");
3643 screen_gadget[id] = gi;
3647 void CreateScreenGadgets()
3649 int last_game_status = game_status; /* save current game status */
3651 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3654 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3656 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3658 /* copy pointers to clip mask and GC */
3659 scrollbar_bitmap[i]->clip_mask =
3660 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3661 scrollbar_bitmap[i]->stored_clip_gc =
3662 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3664 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3665 scrollbar_bitmap[i],
3666 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3667 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3668 TILEX, TILEY, 0, 0);
3672 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3673 game_status = GAME_MODE_LEVELS;
3675 CreateScreenScrollbuttons();
3676 CreateScreenScrollbars();
3678 game_status = last_game_status; /* restore current game status */
3681 void FreeScreenGadgets()
3685 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3686 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3688 /* prevent freeing clip mask and GC twice */
3689 scrollbar_bitmap[i]->clip_mask = None;
3690 scrollbar_bitmap[i]->stored_clip_gc = None;
3692 FreeBitmap(scrollbar_bitmap[i]);
3696 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3697 FreeGadget(screen_gadget[i]);
3700 void MapChooseTreeGadgets(TreeInfo *ti)
3702 int num_entries = numTreeInfoInGroup(ti);
3705 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3708 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3709 MapGadget(screen_gadget[i]);
3713 void UnmapChooseTreeGadgets()
3717 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3718 UnmapGadget(screen_gadget[i]);
3722 static void HandleScreenGadgets(struct GadgetInfo *gi)
3724 int id = gi->custom_id;
3726 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3731 case SCREEN_CTRL_ID_SCROLL_UP:
3732 if (game_status == GAME_MODE_LEVELS)
3733 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3734 else if (game_status == GAME_MODE_SETUP)
3735 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3738 case SCREEN_CTRL_ID_SCROLL_DOWN:
3739 if (game_status == GAME_MODE_LEVELS)
3740 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3741 else if (game_status == GAME_MODE_SETUP)
3742 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3745 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3746 if (game_status == GAME_MODE_LEVELS)
3747 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3748 else if (game_status == GAME_MODE_SETUP)
3749 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);