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 */
204 static void PlayMenuSound()
206 int sound = menu.sound[game_status];
208 if (sound == SND_UNDEFINED)
211 if (sound_info[sound].loop)
212 PlaySoundLoop(sound);
217 static void PlayMenuSoundIfLoop()
219 int sound = menu.sound[game_status];
221 if (sound == SND_UNDEFINED)
224 if (sound_info[sound].loop)
225 PlaySoundLoop(sound);
228 static void PlayMenuMusic()
230 int music = menu.music[game_status];
232 if (music == MUS_UNDEFINED)
240 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
241 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
244 static void ToggleFullscreenIfNeeded()
246 if (setup.fullscreen != video.fullscreen_enabled)
248 /* save old door content */
249 BlitBitmap(backbuffer, bitmap_db_door,
250 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
252 /* toggle fullscreen */
253 ChangeVideoModeIfNeeded(setup.fullscreen);
254 setup.fullscreen = video.fullscreen_enabled;
256 /* redraw background to newly created backbuffer */
257 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
258 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
260 /* restore old door content */
261 BlitBitmap(bitmap_db_door, backbuffer,
262 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
264 redraw_mask = REDRAW_ALL;
268 static int getLastLevelButtonPos()
273 static int getCurrentLevelTextPos()
275 return (getLastLevelButtonPos() + 1);
278 static int getNextLevelButtonPos()
280 return getLastLevelButtonPos() + 3 + 1;
283 static int getLevelRangeTextPos()
285 return getNextLevelButtonPos() + 1;
288 void DrawTitleScreenImage(int nr)
290 int graphic = IMG_TITLESCREEN_1 + nr;
291 Bitmap *bitmap = graphic_info[graphic].bitmap;
292 int width = graphic_info[graphic].src_image_width;
293 int height = graphic_info[graphic].src_image_height;
294 int src_x = 0, src_y = 0;
300 if (width > WIN_XSIZE)
302 src_x = (width - WIN_XSIZE) / 2;
306 if (height > WIN_YSIZE)
308 src_y = (height - WIN_YSIZE) / 2;
312 dst_x = (WIN_XSIZE - width) / 2;
313 dst_y = (WIN_YSIZE - height) / 2;
316 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
318 DrawBackground(0, 0, WIN_XSIZE, WIN_YSIZE);
321 if (DrawingOnBackground(dst_x, dst_y))
322 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
324 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
326 redraw_mask = REDRAW_ALL;
329 void DrawTitleScreen()
331 KeyboardAutoRepeatOff();
333 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
336 CloseDoor(DOOR_CLOSE_1);
342 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
355 static void DrawMainMenuExt(int fade_delay)
357 static LevelDirTree *leveldir_last_valid = NULL;
358 boolean levelset_has_changed = FALSE;
359 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
361 char *level_text = "Levelset";
363 char *level_text = "Level:";
365 int name_width, level_width;
369 FadeSoundsAndMusic();
371 KeyboardAutoRepeatOn();
374 SetDrawDeactivationMask(REDRAW_NONE);
375 SetDrawBackgroundMask(REDRAW_FIELD);
377 audio.sound_deactivated = FALSE;
379 /* needed if last screen was the playing screen, invoked from level editor */
380 if (level_editor_test_game)
382 game_status = GAME_MODE_EDITOR;
388 /* needed if last screen was the editor screen */
389 UndrawSpecialEditorDoor();
391 /* needed if last screen was the setup screen and fullscreen state changed */
392 ToggleFullscreenIfNeeded();
394 /* leveldir_current may be invalid (level group, parent link) */
395 if (!validLevelSeries(leveldir_current))
396 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
398 if (leveldir_current != leveldir_last_valid)
399 levelset_has_changed = TRUE;
401 /* store valid level series information */
402 leveldir_last_valid = leveldir_current;
404 /* needed if last screen (level choice) changed graphics, sounds or music */
405 ReloadCustomArtwork(0);
408 SetDrawtoField(DRAW_BACKBUFFER);
411 if (setup.show_titlescreen &&
412 levelset_has_changed &&
413 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
415 game_status = GAME_MODE_TITLE;
422 /* map gadgets for main menu screen */
426 /* level_nr may have been set to value over handicap with level editor */
427 if (setup.handicap && level_nr > leveldir_current->handicap_level)
428 level_nr = leveldir_current->handicap_level;
433 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
438 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
439 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
440 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
441 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
442 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
443 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
444 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
445 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
447 /* calculated after (possible) reload of custom artwork */
448 name_width = getTextWidth(name_text, FONT_MENU_1);
450 level_width = 9 * 32;
453 level_width = 9 * getFontWidth(FONT_MENU_1);
455 level_width = getTextWidth(level_text, FONT_MENU_1);
459 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
463 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
464 int2str(level_nr, 3), FONT_VALUE_1);
467 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
470 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
475 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
481 int text_height = getFontHeight(FONT_TEXT_3);
483 int xpos = getLevelRangeTextPos() * 32;
485 int xpos = level_width + 6 * 32;
487 int ypos2 = -SY + 3 * 32 + 16;
488 int ypos1 = ypos2 - text_height;
490 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
491 "%03d", leveldir_current->first_level);
492 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
493 "%03d", leveldir_current->last_level);
496 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
497 "%d", leveldir_current->levels);
501 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
502 leveldir_current->first_level, leveldir_current->last_level);
506 if (leveldir_current->readonly)
508 DrawTextS(mSX + level_width + 9 * 32 - 2,
509 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
510 DrawTextS(mSX + level_width + 9 * 32 - 2,
511 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
515 for (i = 0; i < 8; i++)
516 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
520 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
521 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
524 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
525 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
527 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
528 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
532 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
539 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
542 if (TAPE_IS_EMPTY(tape))
544 DrawCompleteVideoDisplay();
550 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
553 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
555 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
559 /* map gadgets for main menu screen */
575 DrawMainMenuExt(FALSE);
579 static void gotoTopLevelDir()
581 /* move upwards to top level directory */
582 while (leveldir_current->node_parent)
584 /* write a "path" into level tree for easy navigation to last level */
585 if (leveldir_current->node_parent->node_group->cl_first == -1)
587 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
588 int leveldir_pos = posTreeInfo(leveldir_current);
589 int num_page_entries;
590 int cl_first, cl_cursor;
592 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
593 num_page_entries = num_leveldirs;
595 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
597 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
598 cl_cursor = leveldir_pos - cl_first;
600 leveldir_current->node_parent->node_group->cl_first = cl_first;
601 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
604 leveldir_current = leveldir_current->node_parent;
609 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
611 static int title_nr = 0;
612 boolean return_to_main_menu = FALSE;
613 boolean use_fading_main_menu = TRUE;
614 boolean use_cross_fading = TRUE;
615 int fade_delay = 1000;
616 int post_delay = 500;
618 if (button == MB_MENU_INITIALIZE)
622 DrawTitleScreenImage(title_nr);
628 else if (button == MB_MENU_LEAVE)
630 return_to_main_menu = TRUE;
631 use_fading_main_menu = FALSE;
633 else if (button == MB_MENU_CHOICE)
637 if (!use_cross_fading)
638 FadeOut(fade_delay, post_delay);
640 if (title_nr < MAX_NUM_TITLE_SCREENS &&
641 graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
643 Bitmap *drawto_last = drawto;
645 if (use_cross_fading)
646 drawto = bitmap_db_title;
648 DrawTitleScreenImage(title_nr);
650 drawto = drawto_last;
652 if (use_cross_fading)
653 FadeCross(bitmap_db_title, fade_delay);
659 FadeOut(fade_delay, post_delay);
661 return_to_main_menu = TRUE;
665 if (return_to_main_menu)
670 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
673 game_status = GAME_MODE_MAIN;
674 DrawMainMenuExt(use_fading_main_menu ? fade_delay : 0);
678 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
680 static unsigned long level_delay = 0;
681 static int choice = 5;
685 if (button == MB_MENU_INITIALIZE)
687 drawCursor(choice, FC_RED);
691 if (mx || my) /* mouse input */
694 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
696 else if (dx || dy) /* keyboard input */
698 if (dx && choice == 1)
699 x = (dx < 0 ? 10 : 14);
702 if (choice == 4 || choice == 6)
703 button = MB_MENU_CHOICE;
709 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
710 (x == 14 && level_nr < leveldir_current->last_level)) &&
711 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
713 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
714 int old_level_nr = level_nr;
717 new_level_nr = level_nr + (x == 10 ? -step : +step);
718 if (new_level_nr < leveldir_current->first_level)
719 new_level_nr = leveldir_current->first_level;
720 if (new_level_nr > leveldir_current->last_level)
721 new_level_nr = leveldir_current->last_level;
723 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
725 /* skipping levels is only allowed when trying to skip single level */
726 if (setup.skip_levels && step == 1 &&
727 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
729 leveldir_current->handicap_level++;
730 SaveLevelSetup_SeriesInfo();
733 new_level_nr = leveldir_current->handicap_level;
736 if (new_level_nr != old_level_nr)
738 level_nr = new_level_nr;
740 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
744 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
748 DrawCompleteVideoDisplay();
750 /* needed because DrawMicroLevel() takes some time */
753 DelayReached(&level_delay, 0); /* reset delay counter */
756 else if (IN_VIS_FIELD(x, y) &&
757 y >= 0 && y <= 7 && (y != 1 || x < 10))
763 drawCursor(y, FC_RED);
764 drawCursor(choice, FC_BLUE);
772 game_status = GAME_MODE_PSEUDO_TYPENAME;
773 HandleTypeName(strlen(setup.player_name), 0);
779 game_status = GAME_MODE_LEVELS;
780 SaveLevelSetup_LastSeries();
781 SaveLevelSetup_SeriesInfo();
792 game_status = GAME_MODE_SCORES;
797 if (leveldir_current->readonly &&
798 !strEqual(setup.player_name, "Artsoft"))
799 Request("This level is read only !", REQ_CONFIRM);
800 game_status = GAME_MODE_EDITOR;
805 game_status = GAME_MODE_INFO;
806 info_mode = INFO_MODE_MAIN;
811 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
815 game_status = GAME_MODE_SETUP;
816 setup_mode = SETUP_MODE_MAIN;
822 SaveLevelSetup_LastSeries();
823 SaveLevelSetup_SeriesInfo();
825 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
826 game_status = GAME_MODE_QUIT;
831 if (game_status == GAME_MODE_MAIN)
833 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
839 /* ========================================================================= */
840 /* info screen functions */
841 /* ========================================================================= */
843 static struct TokenInfo *info_info;
844 static int num_info_info;
846 static void execInfoElements()
848 info_mode = INFO_MODE_ELEMENTS;
852 static void execInfoMusic()
854 info_mode = INFO_MODE_MUSIC;
858 static void execInfoCredits()
860 info_mode = INFO_MODE_CREDITS;
864 static void execInfoProgram()
866 info_mode = INFO_MODE_PROGRAM;
870 static void execInfoLevelSet()
872 info_mode = INFO_MODE_LEVELSET;
876 static void execExitInfo()
878 game_status = GAME_MODE_MAIN;
882 static struct TokenInfo info_info_main[] =
884 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
885 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
886 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
887 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
888 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
889 { TYPE_EMPTY, NULL, "" },
890 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
895 static void DrawInfoScreen_Main()
900 CloseDoor(DOOR_CLOSE_2);
905 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
907 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
910 info_info = info_info_main;
913 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
915 int xpos = MENU_SCREEN_START_XPOS;
916 int ypos = MENU_SCREEN_START_YPOS + i;
917 int font_nr = FONT_MENU_1;
919 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
921 if (info_info[i].type & TYPE_ENTER_MENU)
922 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
923 else if (info_info[i].type & TYPE_LEAVE_MENU)
924 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
925 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
926 initCursor(i, IMG_MENU_BUTTON);
937 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
940 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
942 static int choice_store[MAX_INFO_MODES];
943 int choice = choice_store[info_mode]; /* always starts with 0 */
947 if (button == MB_MENU_INITIALIZE)
949 /* advance to first valid menu entry */
950 while (choice < num_info_info &&
951 info_info[choice].type & TYPE_SKIP_ENTRY)
953 choice_store[info_mode] = choice;
955 drawCursor(choice, FC_RED);
958 else if (button == MB_MENU_LEAVE)
960 for (y = 0; y < num_info_info; y++)
962 if (info_info[y].type & TYPE_LEAVE_MENU)
964 void (*menu_callback_function)(void) = info_info[y].value;
966 menu_callback_function();
967 break; /* absolutely needed because function changes 'info_info'! */
974 if (mx || my) /* mouse input */
977 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
979 else if (dx || dy) /* keyboard input */
983 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
985 if (info_info[choice].type & menu_navigation_type ||
986 info_info[choice].type & TYPE_ENTER_SCREEN ||
987 info_info[choice].type & TYPE_BOOLEAN_STYLE)
988 button = MB_MENU_CHOICE;
993 /* jump to next non-empty menu entry (up or down) */
994 while (y > 0 && y < num_info_info - 1 &&
995 info_info[y].type & TYPE_SKIP_ENTRY)
999 if (IN_VIS_FIELD(x, y) &&
1000 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
1006 drawCursor(y, FC_RED);
1007 drawCursor(choice, FC_BLUE);
1008 choice = choice_store[info_mode] = y;
1011 else if (!(info_info[y].type & TYPE_GHOSTED))
1013 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
1015 void (*menu_callback_function)(void) = info_info[choice].value;
1017 menu_callback_function();
1023 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
1025 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
1026 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
1027 int xstart = mSX + 16;
1028 int ystart = mSY + 64 + 2 * 32;
1029 int ystep = TILEY + 4;
1030 int element, action, direction;
1038 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
1039 infoscreen_step[i] = infoscreen_frame[i] = 0;
1044 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
1046 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1047 "Press any key or button for next page");
1053 while (helpanim_info[j].element != HELPANIM_LIST_END)
1055 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1060 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1069 j += infoscreen_step[i - start];
1071 element = helpanim_info[j].element;
1072 action = helpanim_info[j].action;
1073 direction = helpanim_info[j].direction;
1076 element = EL_UNKNOWN;
1078 if (action != -1 && direction != -1)
1079 graphic = el_act_dir2img(element, action, direction);
1080 else if (action != -1)
1081 graphic = el_act2img(element, action);
1082 else if (direction != -1)
1083 graphic = el_dir2img(element, direction);
1085 graphic = el2img(element);
1087 delay = helpanim_info[j++].delay;
1092 if (infoscreen_frame[i - start] == 0)
1095 infoscreen_frame[i - start] = delay - 1;
1099 sync_frame = delay - infoscreen_frame[i - start];
1100 infoscreen_frame[i - start]--;
1103 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1105 if (!infoscreen_frame[i - start])
1106 infoscreen_step[i - start] = 0;
1110 if (!infoscreen_frame[i - start])
1111 infoscreen_step[i - start]++;
1112 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1118 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1120 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1121 graphic, sync_frame, USE_MASKING);
1124 DrawInfoScreen_HelpText(element, action, direction, i - start);
1129 redraw_mask |= REDRAW_FIELD;
1134 static char *getHelpText(int element, int action, int direction)
1136 char token[MAX_LINE_LEN];
1138 strcpy(token, element_info[element].token_name);
1141 strcat(token, element_action_info[action].suffix);
1143 if (direction != -1)
1144 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1146 return getHashEntry(helptext_info, token);
1149 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1151 int font_nr = FONT_LEVEL_NUMBER;
1152 int font_width = getFontWidth(font_nr);
1153 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1154 int sy = mSY + 65 + 2 * 32 + 1;
1155 int ystep = TILEY + 4;
1156 int pad_x = sx - SX;
1157 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1158 int max_lines_per_text = 2;
1161 if (action != -1 && direction != -1) /* element.action.direction */
1162 text = getHelpText(element, action, direction);
1164 if (text == NULL && action != -1) /* element.action */
1165 text = getHelpText(element, action, -1);
1167 if (text == NULL && direction != -1) /* element.direction */
1168 text = getHelpText(element, -1, direction);
1170 if (text == NULL) /* base element */
1171 text = getHelpText(element, -1, -1);
1173 if (text == NULL) /* not found */
1174 text = "No description available";
1176 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1177 sy += getFontHeight(font_nr) / 2;
1179 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1180 max_chars_per_line, max_lines_per_text);
1183 void DrawInfoScreen_Elements()
1185 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1190 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1196 void HandleInfoScreen_Elements(int button)
1198 static unsigned long info_delay = 0;
1199 static int num_anims;
1200 static int num_pages;
1202 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1203 int button_released = !button;
1206 if (button == MB_MENU_INITIALIZE)
1208 boolean new_element = TRUE;
1211 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1213 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1215 else if (new_element)
1218 new_element = FALSE;
1222 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1225 else if (button == MB_MENU_LEAVE)
1227 info_mode = INFO_MODE_MAIN;
1233 if (button_released || button == MB_MENU_INITIALIZE)
1235 if (button != MB_MENU_INITIALIZE)
1238 if (page >= num_pages)
1240 FadeSoundsAndMusic();
1242 info_mode = INFO_MODE_MAIN;
1248 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1252 if (DelayReached(&info_delay, GameFrameDelay))
1253 if (page < num_pages)
1254 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1256 PlayMenuSoundIfLoop();
1260 void DrawInfoScreen_Music()
1262 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1269 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1272 void HandleInfoScreen_Music(int button)
1274 static struct MusicFileInfo *list = NULL;
1275 int ystart = 150, dy = 30;
1276 int ybottom = SYSIZE - 20;
1277 int button_released = !button;
1279 if (button == MB_MENU_INITIALIZE)
1281 list = music_file_info;
1285 FadeSoundsAndMusic();
1290 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1292 DrawTextSCentered(ybottom, FONT_TEXT_4,
1293 "Press any key or button for info menu");
1298 else if (button == MB_MENU_LEAVE)
1300 info_mode = INFO_MODE_MAIN;
1306 if (button_released || button == MB_MENU_INITIALIZE)
1310 if (button != MB_MENU_INITIALIZE)
1316 info_mode = INFO_MODE_MAIN;
1322 FadeSoundsAndMusic();
1329 int sound = list->music;
1331 if (sound_info[sound].loop)
1332 PlaySoundLoop(sound);
1336 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1340 PlayMusic(list->music);
1342 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1345 if (!strEqual(list->title, UNKNOWN_NAME))
1347 if (!strEqual(list->title_header, UNKNOWN_NAME))
1348 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1350 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1353 if (!strEqual(list->artist, UNKNOWN_NAME))
1355 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1356 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1358 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1360 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1363 if (!strEqual(list->album, UNKNOWN_NAME))
1365 if (!strEqual(list->album_header, UNKNOWN_NAME))
1366 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1368 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1370 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1373 if (!strEqual(list->year, UNKNOWN_NAME))
1375 if (!strEqual(list->year_header, UNKNOWN_NAME))
1376 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1378 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1380 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1383 DrawTextSCentered(ybottom, FONT_TEXT_4,
1384 "Press any key or button for next page");
1387 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1388 PlaySoundLoop(list->music);
1391 void DrawInfoScreen_Credits()
1393 int ystart = 150, ystep = 30;
1394 int ybottom = SYSIZE - 20;
1396 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1398 FadeSoundsAndMusic();
1403 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1404 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1405 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1406 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1407 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1408 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1409 "...and many thanks to all contributors");
1410 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1412 DrawTextSCentered(ybottom, FONT_TEXT_4,
1413 "Press any key or button for info menu");
1416 void HandleInfoScreen_Credits(int button)
1418 int button_released = !button;
1420 if (button == MB_MENU_LEAVE)
1422 info_mode = INFO_MODE_MAIN;
1428 if (button_released)
1430 FadeSoundsAndMusic();
1432 info_mode = INFO_MODE_MAIN;
1437 PlayMenuSoundIfLoop();
1441 void DrawInfoScreen_Program()
1443 int ystart = 150, ystep = 30;
1444 int ybottom = SYSIZE - 20;
1446 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1451 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1453 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1454 "This game is Freeware!");
1455 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1456 "If you like it, send e-mail to:");
1457 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1458 "info@artsoft.org");
1459 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1460 "or SnailMail to:");
1461 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1463 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1464 "Detmolder Strasse 189");
1465 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1467 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1470 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1471 "If you have created new levels,");
1472 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1473 "send them to me to include them!");
1474 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1477 DrawTextSCentered(ybottom, FONT_TEXT_4,
1478 "Press any key or button for info menu");
1481 void HandleInfoScreen_Program(int button)
1483 int button_released = !button;
1485 if (button == MB_MENU_LEAVE)
1487 info_mode = INFO_MODE_MAIN;
1493 if (button_released)
1495 FadeSoundsAndMusic();
1497 info_mode = INFO_MODE_MAIN;
1502 PlayMenuSoundIfLoop();
1506 void DrawInfoScreen_LevelSet()
1509 int ybottom = SYSIZE - 20;
1510 char *filename = getLevelSetInfoFilename();
1511 int font_nr = FONT_LEVEL_NUMBER;
1512 int font_width = getFontWidth(font_nr);
1513 int font_height = getFontHeight(font_nr);
1516 int sx = SX + pad_x;
1517 int sy = SY + pad_y;
1518 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1519 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1521 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1526 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1528 DrawTextSCentered(ybottom, FONT_TEXT_4,
1529 "Press any key or button for info menu");
1531 if (filename != NULL)
1532 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1533 max_lines_per_screen);
1535 DrawTextSCentered(ystart, FONT_TEXT_2,
1536 "No information for this level set.");
1539 void HandleInfoScreen_LevelSet(int button)
1541 int button_released = !button;
1543 if (button == MB_MENU_LEAVE)
1545 info_mode = INFO_MODE_MAIN;
1551 if (button_released)
1553 FadeSoundsAndMusic();
1555 info_mode = INFO_MODE_MAIN;
1560 PlayMenuSoundIfLoop();
1564 void DrawInfoScreen()
1566 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1568 if (info_mode == INFO_MODE_ELEMENTS)
1569 DrawInfoScreen_Elements();
1570 else if (info_mode == INFO_MODE_MUSIC)
1571 DrawInfoScreen_Music();
1572 else if (info_mode == INFO_MODE_CREDITS)
1573 DrawInfoScreen_Credits();
1574 else if (info_mode == INFO_MODE_PROGRAM)
1575 DrawInfoScreen_Program();
1576 else if (info_mode == INFO_MODE_LEVELSET)
1577 DrawInfoScreen_LevelSet();
1579 DrawInfoScreen_Main();
1581 if (info_mode != INFO_MODE_MUSIC)
1588 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1590 if (info_mode == INFO_MODE_ELEMENTS)
1591 HandleInfoScreen_Elements(button);
1592 else if (info_mode == INFO_MODE_MUSIC)
1593 HandleInfoScreen_Music(button);
1594 else if (info_mode == INFO_MODE_CREDITS)
1595 HandleInfoScreen_Credits(button);
1596 else if (info_mode == INFO_MODE_PROGRAM)
1597 HandleInfoScreen_Program(button);
1598 else if (info_mode == INFO_MODE_LEVELSET)
1599 HandleInfoScreen_LevelSet(button);
1601 HandleInfoScreen_Main(mx, my, dx, dy, button);
1607 /* ========================================================================= */
1608 /* type name functions */
1609 /* ========================================================================= */
1611 void HandleTypeName(int newxpos, Key key)
1613 static int xpos = 0, ypos = 2;
1614 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1615 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1616 int startx = mSX + 32 + name_width;
1617 int starty = mSY + ypos * 32;
1623 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1624 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1629 if (((key >= KSYM_A && key <= KSYM_Z) ||
1630 (key >= KSYM_a && key <= KSYM_z)) &&
1631 xpos < MAX_PLAYER_NAME_LEN)
1635 if (key >= KSYM_A && key <= KSYM_Z)
1636 ascii = 'A' + (char)(key - KSYM_A);
1638 ascii = 'a' + (char)(key - KSYM_a);
1640 setup.player_name[xpos] = ascii;
1641 setup.player_name[xpos + 1] = 0;
1644 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1645 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1647 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1650 setup.player_name[xpos] = 0;
1652 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1654 else if (key == KSYM_Return && xpos > 0)
1656 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1657 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1660 game_status = GAME_MODE_MAIN;
1665 /* ========================================================================= */
1666 /* tree menu functions */
1667 /* ========================================================================= */
1669 static void DrawChooseTree(TreeInfo **ti_ptr)
1673 FreeScreenGadgets();
1674 CreateScreenGadgets();
1676 CloseDoor(DOOR_CLOSE_2);
1680 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1681 MapChooseTreeGadgets(*ti_ptr);
1687 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1689 struct GadgetInfo *gi = screen_gadget[id];
1690 int items_max, items_visible, item_position;
1692 items_max = numTreeInfoInGroup(ti);
1693 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1694 item_position = first_entry;
1696 if (item_position > items_max - items_visible)
1697 item_position = items_max - items_visible;
1699 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1700 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1701 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1704 static void drawChooseTreeList(int first_entry, int num_page_entries,
1708 char *title_string = NULL;
1710 int xoffset_sets = 16;
1712 int yoffset_sets = MENU_TITLE1_YPOS;
1714 int xoffset_setup = 16;
1716 int yoffset_setup = 16;
1719 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1722 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1725 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1726 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1728 int last_game_status = game_status; /* save current game status */
1731 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1732 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1733 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1734 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1737 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1739 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1742 /* force LEVELS font on artwork setup screen */
1743 game_status = GAME_MODE_LEVELS;
1745 /* clear tree list area, but not title or scrollbar */
1746 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1747 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
1748 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1750 for (i = 0; i < num_page_entries; i++)
1752 TreeInfo *node, *node_first;
1753 int entry_pos = first_entry + i;
1754 int xpos = MENU_SCREEN_START_XPOS;
1755 int ypos = MENU_SCREEN_START_YPOS + i;
1756 int startx = mSX + xpos * 32;
1757 int starty = mSY + ypos * 32;
1758 int font_nr = FONT_TEXT_1;
1759 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
1760 int startx_text = startx + font_xoffset;
1761 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1762 int text_size = startx_scrollbar - startx_text;
1763 int max_buffer_len = text_size / getFontWidth(font_nr);
1764 char buffer[max_buffer_len + 1];
1766 node_first = getTreeInfoFirstGroupEntry(ti);
1767 node = getTreeInfoFromPos(node_first, entry_pos);
1769 strncpy(buffer, node->name, max_buffer_len);
1770 buffer[max_buffer_len] = '\0';
1772 DrawText(startx, starty, buffer, font_nr + node->color);
1774 if (node->parent_link)
1775 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1776 else if (node->level_group)
1777 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1779 initCursor(i, IMG_MENU_BUTTON);
1782 game_status = last_game_status; /* restore current game status */
1784 redraw_mask |= REDRAW_FIELD;
1787 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1789 TreeInfo *node, *node_first;
1790 int x, last_redraw_mask = redraw_mask;
1792 int ypos = MENU_TITLE2_YPOS;
1797 if (ti->type != TREE_TYPE_LEVEL_DIR)
1800 node_first = getTreeInfoFirstGroupEntry(ti);
1801 node = getTreeInfoFromPos(node_first, entry_pos);
1803 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1805 if (node->parent_link)
1806 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1808 else if (node->level_group)
1809 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1811 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1812 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1813 node->levels, node->class_desc);
1815 /* let BackToFront() redraw only what is needed */
1816 redraw_mask = last_redraw_mask | REDRAW_TILES;
1817 for (x = 0; x < SCR_FIELDX; x++)
1818 MarkTileDirty(x, 1);
1821 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1824 TreeInfo *ti = *ti_ptr;
1826 int y = ti->cl_cursor;
1827 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1828 int num_entries = numTreeInfoInGroup(ti);
1829 int num_page_entries;
1830 int last_game_status = game_status; /* save current game status */
1831 boolean position_set_by_scrollbar = (dx == 999);
1833 /* force LEVELS draw offset on choose level and artwork setup screen */
1834 game_status = GAME_MODE_LEVELS;
1836 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1837 num_page_entries = num_entries;
1839 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1841 game_status = last_game_status; /* restore current game status */
1843 if (button == MB_MENU_INITIALIZE)
1845 int num_entries = numTreeInfoInGroup(ti);
1846 int entry_pos = posTreeInfo(ti);
1848 if (ti->cl_first == -1)
1850 /* only on initialization */
1851 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1852 ti->cl_cursor = entry_pos - ti->cl_first;
1854 else if (ti->cl_cursor >= num_page_entries ||
1855 (num_entries > num_page_entries &&
1856 num_entries - ti->cl_first < num_page_entries))
1858 /* only after change of list size (by custom graphic configuration) */
1859 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1860 ti->cl_cursor = entry_pos - ti->cl_first;
1863 if (position_set_by_scrollbar)
1866 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1869 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1870 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1871 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1875 else if (button == MB_MENU_LEAVE)
1877 if (ti->node_parent)
1879 *ti_ptr = ti->node_parent;
1880 DrawChooseTree(ti_ptr);
1882 else if (game_status == GAME_MODE_SETUP)
1888 game_status = GAME_MODE_MAIN;
1895 if (mx || my) /* mouse input */
1897 int last_game_status = game_status; /* save current game status */
1899 /* force LEVELS draw offset on artwork setup screen */
1900 game_status = GAME_MODE_LEVELS;
1902 x = (mx - mSX) / 32;
1903 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1905 game_status = last_game_status; /* restore current game status */
1907 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1909 /* move cursor instead of scrolling when already at start/end of list */
1910 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1912 else if (dy == +1 * SCROLL_LINE &&
1913 ti->cl_first + num_page_entries == num_entries)
1916 /* handle scrolling screen one line or page */
1917 if (ti->cl_cursor + dy < 0 ||
1918 ti->cl_cursor + dy > num_page_entries - 1)
1920 if (ABS(dy) == SCROLL_PAGE)
1921 step = num_page_entries - 1;
1923 if (dy < 0 && ti->cl_first > 0)
1925 /* scroll page/line up */
1927 ti->cl_first -= step;
1928 if (ti->cl_first < 0)
1931 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1932 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1933 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1934 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1937 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1939 /* scroll page/line down */
1941 ti->cl_first += step;
1942 if (ti->cl_first + num_page_entries > num_entries)
1943 ti->cl_first = MAX(0, num_entries - num_page_entries);
1945 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1946 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1947 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1948 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1955 /* handle moving cursor one line */
1956 y = ti->cl_cursor + dy;
1961 TreeInfo *node_first, *node_cursor;
1962 int entry_pos = ti->cl_first + y;
1964 node_first = getTreeInfoFirstGroupEntry(ti);
1965 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1967 if (node_cursor->node_group)
1969 node_cursor->cl_first = ti->cl_first;
1970 node_cursor->cl_cursor = ti->cl_cursor;
1971 *ti_ptr = node_cursor->node_group;
1972 DrawChooseTree(ti_ptr);
1977 else if (dx == -1 && ti->node_parent)
1979 *ti_ptr = ti->node_parent;
1980 DrawChooseTree(ti_ptr);
1985 if (!anyScrollbarGadgetActive() &&
1986 IN_VIS_FIELD(x, y) &&
1987 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1988 y >= 0 && y < num_page_entries)
1992 if (y != ti->cl_cursor)
1994 drawChooseTreeCursor(y, FC_RED);
1995 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1996 drawChooseTreeInfo(ti->cl_first + y, ti);
2002 TreeInfo *node_first, *node_cursor;
2003 int entry_pos = ti->cl_first + y;
2005 node_first = getTreeInfoFirstGroupEntry(ti);
2006 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2008 if (node_cursor->node_group)
2010 node_cursor->cl_first = ti->cl_first;
2011 node_cursor->cl_cursor = ti->cl_cursor;
2012 *ti_ptr = node_cursor->node_group;
2013 DrawChooseTree(ti_ptr);
2015 else if (node_cursor->parent_link)
2017 *ti_ptr = node_cursor->node_parent;
2018 DrawChooseTree(ti_ptr);
2022 node_cursor->cl_first = ti->cl_first;
2023 node_cursor->cl_cursor = ti->cl_cursor;
2024 *ti_ptr = node_cursor;
2026 if (ti->type == TREE_TYPE_LEVEL_DIR)
2028 LoadLevelSetup_SeriesInfo();
2030 SaveLevelSetup_LastSeries();
2031 SaveLevelSetup_SeriesInfo();
2035 if (game_status == GAME_MODE_SETUP)
2041 game_status = GAME_MODE_MAIN;
2049 void DrawChooseLevel()
2051 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2053 DrawChooseTree(&leveldir_current);
2059 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2061 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2066 void DrawHallOfFame(int highlight_position)
2069 FadeSoundsAndMusic();
2070 CloseDoor(DOOR_CLOSE_2);
2072 if (highlight_position < 0)
2073 LoadScore(level_nr);
2081 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2084 static void drawHallOfFameList(int first_entry, int highlight_position)
2088 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2092 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2093 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2094 "HighScores of Level %d", level_nr);
2096 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2097 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2098 "HighScores of Level %d", level_nr);
2101 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2103 int entry = first_entry + i;
2104 boolean active = (entry == highlight_position);
2105 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2106 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2107 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2108 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2109 int dx1 = 3 * getFontWidth(font_nr1);
2110 int dx2 = dx1 + getFontWidth(font_nr1);
2111 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2112 int sy = mSY + 64 + i * 32;
2114 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2115 DrawText(mSX + dx1, sy, ".", font_nr1);
2116 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2118 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2119 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2121 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2124 redraw_mask |= REDRAW_FIELD;
2127 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2129 static int first_entry = 0;
2130 static int highlight_position = 0;
2131 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2132 int button_released = !button;
2134 if (button == MB_MENU_INITIALIZE)
2137 highlight_position = mx;
2138 drawHallOfFameList(first_entry, highlight_position);
2143 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2144 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2148 if (first_entry > 0)
2150 first_entry -= step;
2151 if (first_entry < 0)
2154 drawHallOfFameList(first_entry, highlight_position);
2159 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2161 first_entry += step;
2162 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2163 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2165 drawHallOfFameList(first_entry, highlight_position);
2168 else if (button_released)
2170 FadeSound(SND_BACKGROUND_SCORES);
2171 game_status = GAME_MODE_MAIN;
2175 if (game_status == GAME_MODE_SCORES)
2176 PlayMenuSoundIfLoop();
2182 /* ========================================================================= */
2183 /* setup screen functions */
2184 /* ========================================================================= */
2186 static struct TokenInfo *setup_info;
2187 static int num_setup_info;
2189 static char *graphics_set_name;
2190 static char *sounds_set_name;
2191 static char *music_set_name;
2193 static void execSetupMain()
2195 setup_mode = SETUP_MODE_MAIN;
2199 static void execSetupGame()
2201 setup_mode = SETUP_MODE_GAME;
2205 static void execSetupEditor()
2207 setup_mode = SETUP_MODE_EDITOR;
2211 static void execSetupGraphics()
2213 setup_mode = SETUP_MODE_GRAPHICS;
2217 static void execSetupSound()
2219 setup_mode = SETUP_MODE_SOUND;
2223 static void execSetupArtwork()
2225 setup.graphics_set = artwork.gfx_current->identifier;
2226 setup.sounds_set = artwork.snd_current->identifier;
2227 setup.music_set = artwork.mus_current->identifier;
2229 /* needed if last screen (setup choice) changed graphics, sounds or music */
2230 ReloadCustomArtwork(0);
2232 /* needed for displaying artwork name instead of artwork identifier */
2233 graphics_set_name = artwork.gfx_current->name;
2234 sounds_set_name = artwork.snd_current->name;
2235 music_set_name = artwork.mus_current->name;
2237 setup_mode = SETUP_MODE_ARTWORK;
2241 static void execSetupChooseGraphics()
2243 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2247 static void execSetupChooseSounds()
2249 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2253 static void execSetupChooseMusic()
2255 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2259 static void execSetupInput()
2261 setup_mode = SETUP_MODE_INPUT;
2265 static void execSetupShortcut1()
2267 setup_mode = SETUP_MODE_SHORTCUT_1;
2271 static void execSetupShortcut2()
2273 setup_mode = SETUP_MODE_SHORTCUT_2;
2277 static void execExitSetup()
2279 game_status = GAME_MODE_MAIN;
2283 static void execSaveAndExitSetup()
2289 static struct TokenInfo setup_info_main[] =
2291 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2292 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2293 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2294 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2295 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2296 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2297 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2298 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2299 { TYPE_EMPTY, NULL, "" },
2300 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2301 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2306 static struct TokenInfo setup_info_game[] =
2308 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2309 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2310 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2311 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2312 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2313 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2314 { TYPE_EMPTY, NULL, "" },
2315 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2320 static struct TokenInfo setup_info_editor[] =
2323 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2324 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2325 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2326 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2327 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2328 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2329 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2330 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2332 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2333 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2334 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2335 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2336 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2337 { TYPE_EMPTY, NULL, "" },
2338 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2339 { TYPE_EMPTY, NULL, "" },
2340 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2345 static struct TokenInfo setup_info_graphics[] =
2347 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen Mode:" },
2348 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2350 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2351 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2352 { TYPE_SWITCH, &setup.fading, "Fading:" },
2354 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2355 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2356 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2357 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2358 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2359 { TYPE_EMPTY, NULL, "" },
2360 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2365 static struct TokenInfo setup_info_sound[] =
2367 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2368 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2369 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2370 { TYPE_EMPTY, NULL, "" },
2371 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2376 static struct TokenInfo setup_info_artwork[] =
2378 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2379 { TYPE_STRING, &graphics_set_name, "" },
2380 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2381 { TYPE_STRING, &sounds_set_name, "" },
2382 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2383 { TYPE_STRING, &music_set_name, "" },
2384 { TYPE_EMPTY, NULL, "" },
2386 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2387 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2388 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2390 { TYPE_STRING, NULL, "Override Level Artwork:"},
2391 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2392 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2393 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2395 { TYPE_EMPTY, NULL, "" },
2396 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2401 static struct TokenInfo setup_info_shortcut_1[] =
2403 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2404 { TYPE_KEY, &setup.shortcut.save_game, "" },
2405 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2406 { TYPE_KEY, &setup.shortcut.load_game, "" },
2407 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2408 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2409 { TYPE_EMPTY, NULL, "" },
2410 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2411 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2412 { TYPE_EMPTY, NULL, "" },
2413 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2418 static struct TokenInfo setup_info_shortcut_2[] =
2420 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2421 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2422 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2423 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2424 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2425 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2426 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2427 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2428 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2429 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2430 { TYPE_EMPTY, NULL, "" },
2431 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2436 static Key getSetupKey()
2438 Key key = KSYM_UNDEFINED;
2439 boolean got_key_event = FALSE;
2441 while (!got_key_event)
2443 if (PendingEvent()) /* got event */
2451 case EVENT_KEYPRESS:
2453 key = GetEventKey((KeyEvent *)&event, TRUE);
2455 /* press 'Escape' or 'Enter' to keep the existing key binding */
2456 if (key == KSYM_Escape || key == KSYM_Return)
2457 key = KSYM_UNDEFINED; /* keep old value */
2459 got_key_event = TRUE;
2463 case EVENT_KEYRELEASE:
2464 key_joystick_mapping = 0;
2468 HandleOtherEvents(&event);
2476 /* don't eat all CPU time */
2483 static int getSetupTextFont(int type)
2485 if (type & (TYPE_SWITCH |
2495 static int getSetupValueFont(int type, void *value)
2497 if (type & TYPE_KEY)
2498 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2499 else if (type & TYPE_STRING)
2500 return FONT_VALUE_2;
2501 else if (type & TYPE_ECS_AGA)
2502 return FONT_VALUE_1;
2503 else if (type & TYPE_BOOLEAN_STYLE)
2504 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2506 return FONT_VALUE_1;
2509 static void drawSetupValue(int pos)
2511 boolean font_draw_xoffset_modified = FALSE;
2512 int font_draw_xoffset_old = -1;
2513 int xpos = MENU_SCREEN_VALUE_XPOS;
2514 int ypos = MENU_SCREEN_START_YPOS + pos;
2515 int startx = mSX + xpos * 32;
2516 int starty = mSY + ypos * 32;
2517 int font_nr, font_width;
2518 int type = setup_info[pos].type;
2519 void *value = setup_info[pos].value;
2520 char *value_string = getSetupValue(type, value);
2523 if (value_string == NULL)
2526 if (type & TYPE_KEY)
2529 xpos = MENU_SCREEN_START_XPOS;
2534 if (type & TYPE_QUERY)
2536 value_string = "<press key>";
2538 font_nr = FONT_INPUT_1_ACTIVE;
2542 else if (type & TYPE_STRING)
2544 int max_value_len = (SCR_FIELDX - 2) * 2;
2546 xpos = MENU_SCREEN_START_XPOS;
2548 font_nr = FONT_VALUE_2;
2551 if (strlen(value_string) > max_value_len)
2552 value_string[max_value_len] = '\0';
2554 else if (type & TYPE_ECS_AGA)
2557 font_nr = FONT_VALUE_1;
2560 else if (type & TYPE_BOOLEAN_STYLE)
2563 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2567 startx = mSX + xpos * 32;
2568 starty = mSY + ypos * 32;
2569 font_nr = getSetupValueFont(type, value);
2570 font_width = getFontWidth(font_nr);
2572 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2573 if (setup_mode != SETUP_MODE_INPUT)
2575 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
2576 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2577 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
2578 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
2579 int text_font_nr = getSetupTextFont(FONT_MENU_2);
2580 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
2581 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
2582 boolean correct_font_draw_xoffset = FALSE;
2584 if (xpos == MENU_SCREEN_START_XPOS &&
2585 startx + font1_xoffset < text_startx + text_font_xoffset)
2586 correct_font_draw_xoffset = TRUE;
2588 if (xpos == MENU_SCREEN_VALUE_XPOS &&
2589 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
2590 correct_font_draw_xoffset = TRUE;
2593 printf("::: %d + %d < %d + %d + %d\n",
2594 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
2595 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
2598 /* check if setup value would overlap with setup text when printed */
2599 /* (this can happen for extreme/wrong values for font draw offset) */
2600 if (correct_font_draw_xoffset)
2602 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
2603 font_draw_xoffset_modified = TRUE;
2605 if (type & TYPE_KEY)
2606 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
2607 else if (!(type & TYPE_STRING))
2608 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
2609 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
2614 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
2615 DrawText(startx + i * font_width, starty, " ", font_nr);
2618 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
2619 DrawText(mSX + i * 32, starty, " ", font_nr);
2621 DrawText(startx, starty,
2622 (xpos == 3 ? " " : " "), font_nr);
2626 DrawText(startx, starty, value_string, font_nr);
2628 if (font_draw_xoffset_modified)
2629 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
2632 static void changeSetupValue(int pos)
2634 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2636 *(boolean *)setup_info[pos].value ^= TRUE;
2638 else if (setup_info[pos].type & TYPE_KEY)
2642 setup_info[pos].type |= TYPE_QUERY;
2643 drawSetupValue(pos);
2644 setup_info[pos].type &= ~TYPE_QUERY;
2646 key = getSetupKey();
2647 if (key != KSYM_UNDEFINED)
2648 *(Key *)setup_info[pos].value = key;
2651 drawSetupValue(pos);
2654 static void DrawSetupScreen_Generic()
2656 char *title_string = NULL;
2660 CloseDoor(DOOR_CLOSE_2);
2664 if (setup_mode == SETUP_MODE_MAIN)
2666 setup_info = setup_info_main;
2667 title_string = "Setup";
2669 else if (setup_mode == SETUP_MODE_GAME)
2671 setup_info = setup_info_game;
2672 title_string = "Setup Game";
2674 else if (setup_mode == SETUP_MODE_EDITOR)
2676 setup_info = setup_info_editor;
2677 title_string = "Setup Editor";
2679 else if (setup_mode == SETUP_MODE_GRAPHICS)
2681 setup_info = setup_info_graphics;
2682 title_string = "Setup Graphics";
2684 else if (setup_mode == SETUP_MODE_SOUND)
2686 setup_info = setup_info_sound;
2687 title_string = "Setup Sound";
2689 else if (setup_mode == SETUP_MODE_ARTWORK)
2691 setup_info = setup_info_artwork;
2692 title_string = "Custom Artwork";
2694 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
2696 setup_info = setup_info_shortcut_1;
2697 title_string = "Setup Shortcuts";
2699 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
2701 setup_info = setup_info_shortcut_2;
2702 title_string = "Setup Shortcuts";
2706 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2708 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2712 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2714 void *value_ptr = setup_info[i].value;
2715 int xpos = MENU_SCREEN_START_XPOS;
2716 int ypos = MENU_SCREEN_START_YPOS + i;
2720 int font_nr = FONT_MENU_1;
2723 /* set some entries to "unchangeable" according to other variables */
2724 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2725 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2726 (value_ptr == &setup.sound_music && !audio.music_available) ||
2727 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2728 setup_info[i].type |= TYPE_GHOSTED;
2731 font_nr = getSetupTextFont(setup_info[i].type);
2734 if (setup_info[i].type & (TYPE_SWITCH |
2739 font_nr = FONT_MENU_2;
2741 if (setup_info[i].type & TYPE_STRING)
2742 font_nr = FONT_MENU_2;
2746 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2748 if (setup_info[i].type & TYPE_ENTER_MENU)
2749 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2750 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2751 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2752 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2753 initCursor(i, IMG_MENU_BUTTON);
2755 if (setup_info[i].type & TYPE_VALUE)
2762 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2763 "Joysticks deactivated in setup menu");
2768 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2771 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2773 static int choice_store[MAX_SETUP_MODES];
2774 int choice = choice_store[setup_mode]; /* always starts with 0 */
2778 if (button == MB_MENU_INITIALIZE)
2780 /* advance to first valid menu entry */
2781 while (choice < num_setup_info &&
2782 setup_info[choice].type & TYPE_SKIP_ENTRY)
2784 choice_store[setup_mode] = choice;
2786 drawCursor(choice, FC_RED);
2789 else if (button == MB_MENU_LEAVE)
2791 for (y = 0; y < num_setup_info; y++)
2793 if (setup_info[y].type & TYPE_LEAVE_MENU)
2795 void (*menu_callback_function)(void) = setup_info[y].value;
2797 menu_callback_function();
2798 break; /* absolutely needed because function changes 'setup_info'! */
2805 if (mx || my) /* mouse input */
2807 x = (mx - mSX) / 32;
2808 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2810 else if (dx || dy) /* keyboard input */
2814 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2816 if (setup_info[choice].type & menu_navigation_type ||
2817 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2818 button = MB_MENU_CHOICE;
2823 /* jump to next non-empty menu entry (up or down) */
2824 while (y > 0 && y < num_setup_info - 1 &&
2825 setup_info[y].type & TYPE_SKIP_ENTRY)
2829 if (IN_VIS_FIELD(x, y) &&
2830 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2836 drawCursor(y, FC_RED);
2837 drawCursor(choice, FC_BLUE);
2838 choice = choice_store[setup_mode] = y;
2841 else if (!(setup_info[y].type & TYPE_GHOSTED))
2843 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2845 void (*menu_callback_function)(void) = setup_info[choice].value;
2847 menu_callback_function();
2851 if (setup_info[y].type & TYPE_KEYTEXT &&
2852 setup_info[y + 1].type & TYPE_KEY)
2855 if (setup_info[y].type & TYPE_VALUE)
2856 changeSetupValue(y);
2862 void DrawSetupScreen_Input()
2867 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2869 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2872 initCursor(0, IMG_MENU_BUTTON);
2873 initCursor(1, IMG_MENU_BUTTON);
2874 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2875 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2877 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2878 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2880 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2881 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2882 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2885 DeactivateJoystickForCalibration();
2888 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2889 "Joysticks deactivated on this screen");
2892 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2897 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2899 if (device_name == NULL)
2902 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2905 if (strlen(device_name) > 1)
2907 char c1 = device_name[strlen(device_name) - 1];
2908 char c2 = device_name[strlen(device_name) - 2];
2910 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2911 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2914 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2915 strlen(device_name));
2918 static void drawPlayerSetupInputInfo(int player_nr)
2921 static struct SetupKeyboardInfo custom_key;
2928 { &custom_key.left, "Joystick Left" },
2929 { &custom_key.right, "Joystick Right" },
2930 { &custom_key.up, "Joystick Up" },
2931 { &custom_key.down, "Joystick Down" },
2932 { &custom_key.snap, "Button 1" },
2933 { &custom_key.drop, "Button 2" }
2935 static char *joystick_name[MAX_PLAYERS] =
2945 custom_key = setup.input[player_nr].key;
2947 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2948 FONT_INPUT_1_ACTIVE);
2950 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2952 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2953 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2955 if (setup.input[player_nr].use_joystick)
2957 char *device_name = setup.input[player_nr].joy.device_name;
2958 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
2959 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
2961 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
2962 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
2966 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
2967 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
2970 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
2971 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2972 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2973 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2974 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2975 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
2976 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
2977 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
2978 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
2979 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
2980 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
2982 for (i = 0; i < 6; i++)
2984 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2986 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2988 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2989 (setup.input[player_nr].use_joystick ?
2991 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2995 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2997 static int choice = 0;
2998 static int player_nr = 0;
3001 int pos_start = SETUPINPUT_SCREEN_POS_START;
3002 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
3003 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
3004 int pos_end = SETUPINPUT_SCREEN_POS_END;
3006 if (button == MB_MENU_INITIALIZE)
3008 drawPlayerSetupInputInfo(player_nr);
3009 drawCursor(choice, FC_RED);
3013 else if (button == MB_MENU_LEAVE)
3015 setup_mode = SETUP_MODE_MAIN;
3022 if (mx || my) /* mouse input */
3024 x = (mx - mSX) / 32;
3025 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3027 else if (dx || dy) /* keyboard input */
3029 if (dx && choice == 0)
3030 x = (dx < 0 ? 10 : 12);
3031 else if ((dx && choice == 1) ||
3032 (dx == +1 && choice == 2) ||
3033 (dx == -1 && choice == pos_end))
3034 button = MB_MENU_CHOICE;
3038 if (y >= pos_empty1 && y <= pos_empty2)
3039 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
3042 if (IN_VIS_FIELD(x, y) &&
3043 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
3045 static unsigned long delay = 0;
3047 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3050 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3052 drawPlayerSetupInputInfo(player_nr);
3054 else if (IN_VIS_FIELD(x, y) &&
3055 y >= pos_start && y <= pos_end &&
3056 !(y >= pos_empty1 && y <= pos_empty2))
3062 drawCursor(y, FC_RED);
3063 drawCursor(choice, FC_BLUE);
3071 char *device_name = setup.input[player_nr].joy.device_name;
3073 if (!setup.input[player_nr].use_joystick)
3075 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3077 setJoystickDeviceToNr(device_name, new_device_nr);
3078 setup.input[player_nr].use_joystick = TRUE;
3082 int device_nr = getJoystickNrFromDeviceName(device_name);
3083 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3085 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3086 setup.input[player_nr].use_joystick = FALSE;
3088 setJoystickDeviceToNr(device_name, new_device_nr);
3091 drawPlayerSetupInputInfo(player_nr);
3095 if (setup.input[player_nr].use_joystick)
3098 CalibrateJoystick(player_nr);
3101 CustomizeKeyboard(player_nr);
3103 else if (y == pos_end)
3107 setup_mode = SETUP_MODE_MAIN;
3114 void CustomizeKeyboard(int player_nr)
3118 boolean finished = FALSE;
3119 static struct SetupKeyboardInfo custom_key;
3124 } customize_step[] =
3126 { &custom_key.left, "Move Left" },
3127 { &custom_key.right, "Move Right" },
3128 { &custom_key.up, "Move Up" },
3129 { &custom_key.down, "Move Down" },
3130 { &custom_key.snap, "Snap Field" },
3131 { &custom_key.drop, "Drop Element" }
3134 /* read existing key bindings from player setup */
3135 custom_key = setup.input[player_nr].key;
3140 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3142 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3149 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3150 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3151 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3152 "Key:", FONT_INPUT_1_ACTIVE);
3153 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3154 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3158 if (PendingEvent()) /* got event */
3166 case EVENT_KEYPRESS:
3168 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3170 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3176 /* all keys configured -- wait for "Escape" or "Return" key */
3180 /* press 'Enter' to keep the existing key binding */
3181 if (key == KSYM_Return)
3182 key = *customize_step[step_nr].key;
3184 /* check if key already used */
3185 for (i = 0; i < step_nr; i++)
3186 if (*customize_step[i].key == key)
3191 /* got new key binding */
3192 *customize_step[step_nr].key = key;
3193 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3195 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3196 getKeyNameFromKey(key), FONT_VALUE_1);
3199 /* un-highlight last query */
3200 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3201 customize_step[step_nr - 1].text, FONT_MENU_1);
3202 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3203 "Key:", FONT_MENU_1);
3205 /* press 'Enter' to leave */
3208 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3209 "Press Enter", FONT_TITLE_1);
3213 /* query next key binding */
3214 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3215 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3216 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3217 "Key:", FONT_INPUT_1_ACTIVE);
3218 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3219 getKeyNameFromKey(*customize_step[step_nr].key),
3224 case EVENT_KEYRELEASE:
3225 key_joystick_mapping = 0;
3229 HandleOtherEvents(&event);
3237 /* don't eat all CPU time */
3241 /* write new key bindings back to player setup */
3242 setup.input[player_nr].key = custom_key;
3245 DrawSetupScreen_Input();
3248 static boolean CalibrateJoystickMain(int player_nr)
3250 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3251 int new_joystick_xright = JOYSTICK_XMIDDLE;
3252 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3253 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3254 int new_joystick_xmiddle, new_joystick_ymiddle;
3256 int joystick_fd = joystick.fd[player_nr];
3257 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3258 boolean check[3][3];
3259 int check_remaining = 3 * 3;
3264 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3267 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3272 for (y = 0; y < 3; y++)
3274 for (x = 0; x < 3; x++)
3276 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3277 check[x][y] = FALSE;
3281 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3282 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3283 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3284 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3285 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3286 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3287 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3289 joy_value = Joystick(player_nr);
3290 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3291 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3293 /* eventually uncalibrated center position (joystick could be uncentered) */
3294 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3297 new_joystick_xmiddle = joy_x;
3298 new_joystick_ymiddle = joy_y;
3300 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3303 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3308 if (PendingEvent()) /* got event */
3316 case EVENT_KEYPRESS:
3317 switch(GetEventKey((KeyEvent *)&event, TRUE))
3320 if (check_remaining == 0)
3333 case EVENT_KEYRELEASE:
3334 key_joystick_mapping = 0;
3338 HandleOtherEvents(&event);
3343 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3346 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3347 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3348 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3349 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3351 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3352 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3353 setup.input[player_nr].joy.xright = new_joystick_xright;
3354 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3355 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3356 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3358 CheckJoystickData();
3360 joy_value = Joystick(player_nr);
3362 if (joy_value & JOY_BUTTON && check_remaining == 0)
3365 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3366 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3368 if (x != last_x || y != last_y)
3370 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3371 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3376 if (check_remaining > 0 && !check[x+1][y+1])
3378 check[x+1][y+1] = TRUE;
3384 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3385 setup.input[player_nr].joy.xleft,
3386 setup.input[player_nr].joy.xmiddle,
3387 setup.input[player_nr].joy.xright);
3388 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3389 setup.input[player_nr].joy.yupper,
3390 setup.input[player_nr].joy.ymiddle,
3391 setup.input[player_nr].joy.ylower);
3400 /* don't eat all CPU time */
3404 /* calibrated center position (joystick should now be centered) */
3405 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3408 new_joystick_xmiddle = joy_x;
3409 new_joystick_ymiddle = joy_y;
3414 DrawSetupScreen_Input();
3417 /* wait until the last pressed button was released */
3418 while (Joystick(player_nr) & JOY_BUTTON)
3420 if (PendingEvent()) /* got event */
3425 HandleOtherEvents(&event);
3434 void CalibrateJoystick(int player_nr)
3436 if (!CalibrateJoystickMain(player_nr))
3438 char *device_name = setup.input[player_nr].joy.device_name;
3439 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3440 int xpos = mSX - SX;
3441 int ypos = mSY - SY;
3445 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3446 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3449 Delay(2000); /* show error message for a short time */
3455 DrawSetupScreen_Input();
3459 void DrawSetupScreen()
3461 DeactivateJoystick();
3463 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3465 if (setup_mode == SETUP_MODE_INPUT)
3466 DrawSetupScreen_Input();
3467 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3468 DrawChooseTree(&artwork.gfx_current);
3469 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3470 DrawChooseTree(&artwork.snd_current);
3471 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3472 DrawChooseTree(&artwork.mus_current);
3474 DrawSetupScreen_Generic();
3480 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3482 if (setup_mode == SETUP_MODE_INPUT)
3483 HandleSetupScreen_Input(mx, my, dx, dy, button);
3484 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3485 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3486 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3487 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3488 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3489 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3491 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3496 void HandleGameActions()
3498 if (game_status != GAME_MODE_PLAYING)
3501 GameActions(); /* main game loop */
3503 if (tape.auto_play && !tape.playing)
3504 AutoPlayTape(); /* continue automatically playing next tape */
3508 /* ---------- new screen button stuff -------------------------------------- */
3512 int gfx_unpressed, gfx_pressed;
3516 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3519 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3520 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3521 SCREEN_CTRL_ID_SCROLL_UP,
3525 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3526 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3527 SCREEN_CTRL_ID_SCROLL_DOWN,
3534 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3535 Bitmap **gfx_unpressed, **gfx_pressed;
3537 int gfx_unpressed, gfx_pressed;
3544 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3547 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3548 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3550 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3552 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3553 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3554 GD_TYPE_SCROLLBAR_VERTICAL,
3555 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3556 "scroll level series vertically"
3560 static void CreateScreenScrollbuttons()
3562 struct GadgetInfo *gi;
3563 unsigned long event_mask;
3566 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3568 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3569 int gfx_unpressed, gfx_pressed;
3570 int x, y, width, height;
3571 int gd_x1, gd_x2, gd_y1, gd_y2;
3572 int id = scrollbutton_info[i].gadget_id;
3574 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3576 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3577 y = mSY + scrollbutton_info[i].y;
3578 width = SC_SCROLLBUTTON_XSIZE;
3579 height = SC_SCROLLBUTTON_YSIZE;
3581 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3582 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3583 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3585 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3586 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3587 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3588 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3589 gd_x1 = graphic_info[gfx_unpressed].src_x;
3590 gd_y1 = graphic_info[gfx_unpressed].src_y;
3591 gd_x2 = graphic_info[gfx_pressed].src_x;
3592 gd_y2 = graphic_info[gfx_pressed].src_y;
3594 gi = CreateGadget(GDI_CUSTOM_ID, id,
3595 GDI_CUSTOM_TYPE_ID, i,
3596 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3601 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3602 GDI_STATE, GD_BUTTON_UNPRESSED,
3603 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3604 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3605 GDI_DIRECT_DRAW, FALSE,
3606 GDI_EVENT_MASK, event_mask,
3607 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3611 Error(ERR_EXIT, "cannot create gadget");
3613 screen_gadget[id] = gi;
3617 static void CreateScreenScrollbars()
3621 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3623 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3624 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3625 int gfx_unpressed, gfx_pressed;
3627 int x, y, width, height;
3628 int gd_x1, gd_x2, gd_y1, gd_y2;
3629 struct GadgetInfo *gi;
3630 int items_max, items_visible, item_position;
3631 unsigned long event_mask;
3632 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3633 int id = scrollbar_info[i].gadget_id;
3635 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3637 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3638 y = mSY + scrollbar_info[i].y;
3639 width = scrollbar_info[i].width;
3640 height = scrollbar_info[i].height;
3642 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3643 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3645 items_max = num_page_entries;
3646 items_visible = num_page_entries;
3649 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3650 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3651 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3657 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3658 gfx_pressed = scrollbar_info[i].gfx_pressed;
3659 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3660 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3661 gd_x1 = graphic_info[gfx_unpressed].src_x;
3662 gd_y1 = graphic_info[gfx_unpressed].src_y;
3663 gd_x2 = graphic_info[gfx_pressed].src_x;
3664 gd_y2 = graphic_info[gfx_pressed].src_y;
3667 gi = CreateGadget(GDI_CUSTOM_ID, id,
3668 GDI_CUSTOM_TYPE_ID, i,
3669 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3674 GDI_TYPE, scrollbar_info[i].type,
3675 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3676 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3677 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3678 GDI_STATE, GD_BUTTON_UNPRESSED,
3679 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3680 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3681 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3682 GDI_DIRECT_DRAW, FALSE,
3683 GDI_EVENT_MASK, event_mask,
3684 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3688 Error(ERR_EXIT, "cannot create gadget");
3690 screen_gadget[id] = gi;
3694 void CreateScreenGadgets()
3696 int last_game_status = game_status; /* save current game status */
3698 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3701 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3703 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3705 /* copy pointers to clip mask and GC */
3706 scrollbar_bitmap[i]->clip_mask =
3707 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3708 scrollbar_bitmap[i]->stored_clip_gc =
3709 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3711 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3712 scrollbar_bitmap[i],
3713 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3714 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3715 TILEX, TILEY, 0, 0);
3719 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3720 game_status = GAME_MODE_LEVELS;
3722 CreateScreenScrollbuttons();
3723 CreateScreenScrollbars();
3725 game_status = last_game_status; /* restore current game status */
3728 void FreeScreenGadgets()
3732 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3733 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3735 /* prevent freeing clip mask and GC twice */
3736 scrollbar_bitmap[i]->clip_mask = None;
3737 scrollbar_bitmap[i]->stored_clip_gc = None;
3739 FreeBitmap(scrollbar_bitmap[i]);
3743 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3744 FreeGadget(screen_gadget[i]);
3747 void MapChooseTreeGadgets(TreeInfo *ti)
3749 int num_entries = numTreeInfoInGroup(ti);
3752 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3755 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3756 MapGadget(screen_gadget[i]);
3760 void UnmapChooseTreeGadgets()
3764 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3765 UnmapGadget(screen_gadget[i]);
3769 static void HandleScreenGadgets(struct GadgetInfo *gi)
3771 int id = gi->custom_id;
3773 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3778 case SCREEN_CTRL_ID_SCROLL_UP:
3779 if (game_status == GAME_MODE_LEVELS)
3780 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3781 else if (game_status == GAME_MODE_SETUP)
3782 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3785 case SCREEN_CTRL_ID_SCROLL_DOWN:
3786 if (game_status == GAME_MODE_LEVELS)
3787 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3788 else if (game_status == GAME_MODE_SETUP)
3789 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3792 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3793 if (game_status == GAME_MODE_LEVELS)
3794 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3795 else if (game_status == GAME_MODE_SETUP)
3796 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);