1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT 4
33 #define SETUP_MODE_GRAPHICS 5
34 #define SETUP_MODE_SOUND 6
35 #define SETUP_MODE_ARTWORK 7
36 #define SETUP_MODE_CHOOSE_GRAPHICS 8
37 #define SETUP_MODE_CHOOSE_SOUNDS 9
38 #define SETUP_MODE_CHOOSE_MUSIC 10
40 #define MAX_SETUP_MODES 11
42 /* for input setup functions */
43 #define SETUPINPUT_SCREEN_POS_START 0
44 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
45 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
46 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
48 /* screens on the info screen */
49 #define INFO_MODE_MAIN 0
50 #define INFO_MODE_ELEMENTS 1
51 #define INFO_MODE_MUSIC 2
52 #define INFO_MODE_CREDITS 3
53 #define INFO_MODE_PROGRAM 4
54 #define INFO_MODE_LEVELSET 5
56 #define MAX_INFO_MODES 6
58 /* for various menu stuff */
59 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
60 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
61 #define MENU_SCREEN_START_YPOS 2
62 #define MENU_SCREEN_VALUE_XPOS 14
63 #define MENU_TITLE1_YPOS 8
64 #define MENU_TITLE2_YPOS 46
66 /* buttons and scrollbars identifiers */
67 #define SCREEN_CTRL_ID_SCROLL_UP 0
68 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
69 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
71 #define NUM_SCREEN_SCROLLBUTTONS 2
72 #define NUM_SCREEN_SCROLLBARS 1
73 #define NUM_SCREEN_GADGETS 3
75 /* forward declarations of internal functions */
76 static void HandleScreenGadgets(struct GadgetInfo *);
77 static void HandleSetupScreen_Generic(int, int, int, int, int);
78 static void HandleSetupScreen_Input(int, int, int, int, int);
79 static void CustomizeKeyboard(int);
80 static void CalibrateJoystick(int);
81 static void execSetupArtwork(void);
82 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
84 static void DrawChooseLevel(void);
85 static void DrawInfoScreen(void);
86 static void DrawSetupScreen(void);
88 static void DrawInfoScreen_HelpAnim(int, int, boolean);
89 static void DrawInfoScreen_HelpText(int, int, int, int);
90 static void HandleInfoScreen_Main(int, int, int, int, int);
91 static void HandleInfoScreen_Elements(int);
92 static void HandleInfoScreen_Music(int);
93 static void HandleInfoScreen_Credits(int);
94 static void HandleInfoScreen_Program(int);
96 static void MapChooseTreeGadgets(TreeInfo *);
98 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
99 static int setup_mode = SETUP_MODE_MAIN;
100 static int info_mode = INFO_MODE_MAIN;
102 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
103 x <= GAME_MODE_SETUP ? x : \
104 x == GAME_MODE_PSEUDO_TYPENAME ? \
105 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
107 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
108 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
110 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
111 menu.list_size[game_status] : \
112 MAX_MENU_ENTRIES_ON_SCREEN)
114 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
115 #define NUM_SCROLLBAR_BITMAPS 2
116 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
120 static void drawCursorExt(int xpos, int ypos, int color, int g)
122 static int cursor_array[SCR_FIELDY];
127 cursor_array[ypos] = g;
129 g = cursor_array[ypos];
133 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
134 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
135 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
136 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
137 IMG_MENU_BUTTON_ACTIVE);
139 ypos += MENU_SCREEN_START_YPOS;
141 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
142 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
145 static void initCursor(int ypos, int graphic)
147 drawCursorExt(0, ypos, FC_BLUE, graphic);
150 static void drawCursor(int ypos, int color)
152 drawCursorExt(0, ypos, color, 0);
155 static void drawCursorXY(int xpos, int ypos, int graphic)
157 drawCursorExt(xpos, ypos, -1, graphic);
160 static void drawChooseTreeCursor(int ypos, int color)
162 int last_game_status = game_status; /* save current game status */
164 /* force LEVELS draw offset on artwork setup screen */
165 game_status = GAME_MODE_LEVELS;
167 drawCursorExt(0, ypos, color, 0);
169 game_status = last_game_status; /* restore current game status */
172 static void PlayMenuSound()
174 int sound = menu.sound[game_status];
176 if (sound == SND_UNDEFINED)
179 if (sound_info[sound].loop)
180 PlaySoundLoop(sound);
185 static void PlayMenuSoundIfLoop()
187 int sound = menu.sound[game_status];
189 if (sound == SND_UNDEFINED)
192 if (sound_info[sound].loop)
193 PlaySoundLoop(sound);
196 static void PlayMenuMusic()
198 int music = menu.music[game_status];
200 if (music == MUS_UNDEFINED)
208 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
209 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
212 static void ToggleFullscreenIfNeeded()
214 if (setup.fullscreen != video.fullscreen_enabled)
216 /* save old door content */
217 BlitBitmap(backbuffer, bitmap_db_door,
218 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
220 /* toggle fullscreen */
221 ChangeVideoModeIfNeeded(setup.fullscreen);
222 setup.fullscreen = video.fullscreen_enabled;
224 /* redraw background to newly created backbuffer */
225 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
226 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
228 /* restore old door content */
229 BlitBitmap(bitmap_db_door, backbuffer,
230 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
232 redraw_mask = REDRAW_ALL;
238 static LevelDirTree *leveldir_last_valid = NULL;
239 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
241 char *level_text = "Levelset";
243 char *level_text = "Level:";
245 int name_width, level_width;
249 FadeSoundsAndMusic();
251 KeyboardAutoRepeatOn();
254 SetDrawDeactivationMask(REDRAW_NONE);
255 SetDrawBackgroundMask(REDRAW_FIELD);
257 audio.sound_deactivated = FALSE;
259 /* needed if last screen was the playing screen, invoked from level editor */
260 if (level_editor_test_game)
262 game_status = GAME_MODE_EDITOR;
268 /* needed if last screen was the editor screen */
269 UndrawSpecialEditorDoor();
271 /* needed if last screen was the setup screen and fullscreen state changed */
272 ToggleFullscreenIfNeeded();
274 /* leveldir_current may be invalid (level group, parent link) */
275 if (!validLevelSeries(leveldir_current))
276 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
278 /* store valid level series information */
279 leveldir_last_valid = leveldir_current;
281 /* needed if last screen (level choice) changed graphics, sounds or music */
282 ReloadCustomArtwork(0);
285 SetDrawtoField(DRAW_BACKBUFFER);
289 /* map gadgets for main menu screen */
293 /* level_nr may have been set to value over handicap with level editor */
294 if (setup.handicap && level_nr > leveldir_current->handicap_level)
295 level_nr = leveldir_current->handicap_level;
300 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
305 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
306 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
307 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
308 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
309 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
310 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
311 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
312 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
314 /* calculated after (possible) reload of custom artwork */
315 name_width = getTextWidth(name_text, FONT_MENU_1);
317 level_width = 9 * getFontWidth(FONT_MENU_1);
319 level_width = getTextWidth(level_text, FONT_MENU_1);
322 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
325 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
328 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
332 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
338 int text_height = getFontHeight(FONT_TEXT_3);
339 int ypos2 = -SY + 3 * 32 + 16;
340 int ypos1 = ypos2 - text_height;
342 DrawTextF(mSX + level_width + 6 * 32, mSY + ypos1, FONT_TEXT_3,
343 "%03d", leveldir_current->first_level);
344 DrawTextF(mSX + level_width + 6 * 32, mSY + ypos2, FONT_TEXT_3,
345 "%03d", leveldir_current->last_level);
348 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
349 "%d", leveldir_current->levels);
353 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
354 leveldir_current->first_level, leveldir_current->last_level);
358 if (leveldir_current->readonly)
360 DrawTextS(mSX + level_width + 9 * 32 - 2,
361 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
362 DrawTextS(mSX + level_width + 9 * 32 - 2,
363 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
367 for (i = 0; i < 8; i++)
368 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
372 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
373 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
375 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
376 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
379 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
384 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
387 if (TAPE_IS_EMPTY(tape))
389 DrawCompleteVideoDisplay();
394 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
397 /* map gadgets for main menu screen */
403 static void gotoTopLevelDir()
405 /* move upwards to top level directory */
406 while (leveldir_current->node_parent)
408 /* write a "path" into level tree for easy navigation to last level */
409 if (leveldir_current->node_parent->node_group->cl_first == -1)
411 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
412 int leveldir_pos = posTreeInfo(leveldir_current);
413 int num_page_entries;
414 int cl_first, cl_cursor;
416 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
417 num_page_entries = num_leveldirs;
419 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
421 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
422 cl_cursor = leveldir_pos - cl_first;
424 leveldir_current->node_parent->node_group->cl_first = cl_first;
425 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
428 leveldir_current = leveldir_current->node_parent;
433 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
435 static unsigned long level_delay = 0;
436 static int choice = 5;
440 if (button == MB_MENU_INITIALIZE)
442 drawCursor(choice, FC_RED);
446 if (mx || my) /* mouse input */
449 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
451 else if (dx || dy) /* keyboard input */
453 if (dx && choice == 1)
454 x = (dx < 0 ? 10 : 14);
457 if (choice == 4 || choice == 6)
458 button = MB_MENU_CHOICE;
464 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
465 (x == 14 && level_nr < leveldir_current->last_level)) &&
466 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
468 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
469 int old_level_nr = level_nr;
472 new_level_nr = level_nr + (x == 10 ? -step : +step);
473 if (new_level_nr < leveldir_current->first_level)
474 new_level_nr = leveldir_current->first_level;
475 if (new_level_nr > leveldir_current->last_level)
476 new_level_nr = leveldir_current->last_level;
478 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
480 /* skipping levels is only allowed when trying to skip single level */
481 if (setup.skip_levels && step == 1 &&
482 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
484 leveldir_current->handicap_level++;
485 SaveLevelSetup_SeriesInfo();
488 new_level_nr = leveldir_current->handicap_level;
491 if (new_level_nr != old_level_nr)
493 level_nr = new_level_nr;
495 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
499 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
503 DrawCompleteVideoDisplay();
505 /* needed because DrawMicroLevel() takes some time */
508 DelayReached(&level_delay, 0); /* reset delay counter */
511 else if (IN_VIS_FIELD(x, y) &&
512 y >= 0 && y <= 7 && (y != 1 || x < 10))
518 drawCursor(y, FC_RED);
519 drawCursor(choice, FC_BLUE);
527 game_status = GAME_MODE_PSEUDO_TYPENAME;
528 HandleTypeName(strlen(setup.player_name), 0);
534 game_status = GAME_MODE_LEVELS;
535 SaveLevelSetup_LastSeries();
536 SaveLevelSetup_SeriesInfo();
547 game_status = GAME_MODE_SCORES;
552 if (leveldir_current->readonly &&
553 strcmp(setup.player_name, "Artsoft") != 0)
554 Request("This level is read only !", REQ_CONFIRM);
555 game_status = GAME_MODE_EDITOR;
560 game_status = GAME_MODE_INFO;
561 info_mode = INFO_MODE_MAIN;
566 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
570 game_status = GAME_MODE_SETUP;
571 setup_mode = SETUP_MODE_MAIN;
577 SaveLevelSetup_LastSeries();
578 SaveLevelSetup_SeriesInfo();
580 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
581 game_status = GAME_MODE_QUIT;
586 if (game_status == GAME_MODE_MAIN)
588 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
594 /* ========================================================================= */
595 /* info screen functions */
596 /* ========================================================================= */
598 static struct TokenInfo *info_info;
599 static int num_info_info;
601 static void execInfoElements()
603 info_mode = INFO_MODE_ELEMENTS;
607 static void execInfoMusic()
609 info_mode = INFO_MODE_MUSIC;
613 static void execInfoCredits()
615 info_mode = INFO_MODE_CREDITS;
619 static void execInfoProgram()
621 info_mode = INFO_MODE_PROGRAM;
625 static void execInfoLevelSet()
627 info_mode = INFO_MODE_LEVELSET;
631 static void execExitInfo()
633 game_status = GAME_MODE_MAIN;
637 static struct TokenInfo info_info_main[] =
639 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
640 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
641 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
642 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
643 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
644 { TYPE_EMPTY, NULL, "" },
645 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
650 static void DrawInfoScreen_Main()
655 CloseDoor(DOOR_CLOSE_2);
660 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
662 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
665 info_info = info_info_main;
668 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
670 int ypos = MENU_SCREEN_START_YPOS + i;
671 int font_nr = FONT_MENU_1;
673 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
675 if (info_info[i].type & TYPE_ENTER_MENU)
676 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
677 else if (info_info[i].type & TYPE_LEAVE_MENU)
678 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
679 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
680 initCursor(i, IMG_MENU_BUTTON);
691 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
694 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
696 static int choice_store[MAX_INFO_MODES];
697 int choice = choice_store[info_mode]; /* always starts with 0 */
701 if (button == MB_MENU_INITIALIZE)
703 /* advance to first valid menu entry */
704 while (choice < num_info_info &&
705 info_info[choice].type & TYPE_SKIP_ENTRY)
707 choice_store[info_mode] = choice;
709 drawCursor(choice, FC_RED);
712 else if (button == MB_MENU_LEAVE)
714 for (y = 0; y < num_info_info; y++)
716 if (info_info[y].type & TYPE_LEAVE_MENU)
718 void (*menu_callback_function)(void) = info_info[y].value;
720 menu_callback_function();
721 break; /* absolutely needed because function changes 'info_info'! */
728 if (mx || my) /* mouse input */
731 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
733 else if (dx || dy) /* keyboard input */
737 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
739 if (info_info[choice].type & menu_navigation_type ||
740 info_info[choice].type & TYPE_ENTER_SCREEN ||
741 info_info[choice].type & TYPE_BOOLEAN_STYLE)
742 button = MB_MENU_CHOICE;
747 /* jump to next non-empty menu entry (up or down) */
748 while (y > 0 && y < num_info_info - 1 &&
749 info_info[y].type & TYPE_SKIP_ENTRY)
753 if (IN_VIS_FIELD(x, y) &&
754 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
760 drawCursor(y, FC_RED);
761 drawCursor(choice, FC_BLUE);
762 choice = choice_store[info_mode] = y;
765 else if (!(info_info[y].type & TYPE_GHOSTED))
767 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
769 void (*menu_callback_function)(void) = info_info[choice].value;
771 menu_callback_function();
777 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
779 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
780 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
781 int xstart = mSX + 16;
782 int ystart = mSY + 64 + 2 * 32;
783 int ystep = TILEY + 4;
784 int element, action, direction;
792 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
793 infoscreen_step[i] = infoscreen_frame[i] = 0;
798 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
800 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
801 "Press any key or button for next page");
807 while (helpanim_info[j].element != HELPANIM_LIST_END)
809 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
814 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
823 j += infoscreen_step[i - start];
825 element = helpanim_info[j].element;
826 action = helpanim_info[j].action;
827 direction = helpanim_info[j].direction;
830 element = EL_UNKNOWN;
832 if (action != -1 && direction != -1)
833 graphic = el_act_dir2img(element, action, direction);
834 else if (action != -1)
835 graphic = el_act2img(element, action);
836 else if (direction != -1)
837 graphic = el_dir2img(element, direction);
839 graphic = el2img(element);
841 delay = helpanim_info[j++].delay;
846 if (infoscreen_frame[i - start] == 0)
849 infoscreen_frame[i - start] = delay - 1;
853 sync_frame = delay - infoscreen_frame[i - start];
854 infoscreen_frame[i - start]--;
857 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
859 if (!infoscreen_frame[i - start])
860 infoscreen_step[i - start] = 0;
864 if (!infoscreen_frame[i - start])
865 infoscreen_step[i - start]++;
866 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
872 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
874 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
875 graphic, sync_frame, USE_MASKING);
878 DrawInfoScreen_HelpText(element, action, direction, i - start);
883 redraw_mask |= REDRAW_FIELD;
888 static char *getHelpText(int element, int action, int direction)
890 char token[MAX_LINE_LEN];
892 strcpy(token, element_info[element].token_name);
895 strcat(token, element_action_info[action].suffix);
898 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
900 return getHashEntry(helptext_info, token);
903 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
905 int font_nr = FONT_LEVEL_NUMBER;
906 int font_width = getFontWidth(font_nr);
907 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
908 int sy = mSY + 65 + 2 * 32 + 1;
909 int ystep = TILEY + 4;
911 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
912 int max_lines_per_text = 2;
915 if (action != -1 && direction != -1) /* element.action.direction */
916 text = getHelpText(element, action, direction);
918 if (text == NULL && action != -1) /* element.action */
919 text = getHelpText(element, action, -1);
921 if (text == NULL && direction != -1) /* element.direction */
922 text = getHelpText(element, -1, direction);
924 if (text == NULL) /* base element */
925 text = getHelpText(element, -1, -1);
927 if (text == NULL) /* not found */
928 text = "No description available";
930 if (strlen(text) <= max_chars_per_line) /* only one line of text */
931 sy += getFontHeight(font_nr) / 2;
933 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
934 max_chars_per_line, max_lines_per_text);
937 void DrawInfoScreen_Elements()
939 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
944 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
950 void HandleInfoScreen_Elements(int button)
952 static unsigned long info_delay = 0;
953 static int num_anims;
954 static int num_pages;
956 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
957 int button_released = !button;
960 if (button == MB_MENU_INITIALIZE)
962 boolean new_element = TRUE;
965 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
967 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
969 else if (new_element)
976 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
979 else if (button == MB_MENU_LEAVE)
981 info_mode = INFO_MODE_MAIN;
987 if (button_released || button == MB_MENU_INITIALIZE)
989 if (button != MB_MENU_INITIALIZE)
992 if (page >= num_pages)
994 FadeSoundsAndMusic();
996 info_mode = INFO_MODE_MAIN;
1002 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1006 if (DelayReached(&info_delay, GameFrameDelay))
1007 if (page < num_pages)
1008 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1010 PlayMenuSoundIfLoop();
1014 void DrawInfoScreen_Music()
1016 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1023 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1026 void HandleInfoScreen_Music(int button)
1028 static struct MusicFileInfo *list = NULL;
1029 int ystart = 150, dy = 30;
1030 int ybottom = SYSIZE - 20;
1031 int button_released = !button;
1033 if (button == MB_MENU_INITIALIZE)
1035 list = music_file_info;
1039 FadeSoundsAndMusic();
1044 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1046 DrawTextSCentered(ybottom, FONT_TEXT_4,
1047 "Press any key or button for info menu");
1052 else if (button == MB_MENU_LEAVE)
1054 info_mode = INFO_MODE_MAIN;
1060 if (button_released || button == MB_MENU_INITIALIZE)
1064 if (button != MB_MENU_INITIALIZE)
1070 info_mode = INFO_MODE_MAIN;
1076 FadeSoundsAndMusic();
1083 int sound = list->music;
1085 if (sound_info[sound].loop)
1086 PlaySoundLoop(sound);
1090 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1094 PlayMusic(list->music);
1096 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1099 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1101 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1102 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1104 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1107 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1109 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1110 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1112 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1114 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1117 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1119 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1120 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1122 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1124 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1127 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1129 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1130 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1132 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1134 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1137 DrawTextSCentered(ybottom, FONT_TEXT_4,
1138 "Press any key or button for next page");
1141 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1142 PlaySoundLoop(list->music);
1145 void DrawInfoScreen_Credits()
1147 int ystart = 150, ystep = 30;
1148 int ybottom = SYSIZE - 20;
1150 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1152 FadeSoundsAndMusic();
1157 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1158 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1159 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1160 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1161 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1162 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1163 "...and many thanks to all contributors");
1164 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1166 DrawTextSCentered(ybottom, FONT_TEXT_4,
1167 "Press any key or button for info menu");
1170 void HandleInfoScreen_Credits(int button)
1172 int button_released = !button;
1174 if (button == MB_MENU_LEAVE)
1176 info_mode = INFO_MODE_MAIN;
1182 if (button_released)
1184 FadeSoundsAndMusic();
1186 info_mode = INFO_MODE_MAIN;
1191 PlayMenuSoundIfLoop();
1195 void DrawInfoScreen_Program()
1197 int ystart = 150, ystep = 30;
1198 int ybottom = SYSIZE - 20;
1200 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1205 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1207 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1208 "This game is Freeware!");
1209 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1210 "If you like it, send e-mail to:");
1211 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1212 "info@artsoft.org");
1213 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1214 "or SnailMail to:");
1215 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1217 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1218 "Detmolder Strasse 189");
1219 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1221 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1224 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1225 "If you have created new levels,");
1226 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1227 "send them to me to include them!");
1228 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1231 DrawTextSCentered(ybottom, FONT_TEXT_4,
1232 "Press any key or button for info menu");
1235 void HandleInfoScreen_Program(int button)
1237 int button_released = !button;
1239 if (button == MB_MENU_LEAVE)
1241 info_mode = INFO_MODE_MAIN;
1247 if (button_released)
1249 FadeSoundsAndMusic();
1251 info_mode = INFO_MODE_MAIN;
1256 PlayMenuSoundIfLoop();
1260 void DrawInfoScreen_LevelSet()
1263 int ybottom = SYSIZE - 20;
1264 char *filename = getLevelSetInfoFilename();
1265 int font_nr = FONT_LEVEL_NUMBER;
1266 int font_width = getFontWidth(font_nr);
1267 int font_height = getFontHeight(font_nr);
1270 int sx = SX + pad_x;
1271 int sy = SY + pad_y;
1272 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1273 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1275 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1280 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1282 DrawTextSCentered(ybottom, FONT_TEXT_4,
1283 "Press any key or button for info menu");
1285 if (filename != NULL)
1286 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1287 max_lines_per_screen);
1289 DrawTextSCentered(ystart, FONT_TEXT_2,
1290 "No information for this level set.");
1293 void HandleInfoScreen_LevelSet(int button)
1295 int button_released = !button;
1297 if (button == MB_MENU_LEAVE)
1299 info_mode = INFO_MODE_MAIN;
1305 if (button_released)
1307 FadeSoundsAndMusic();
1309 info_mode = INFO_MODE_MAIN;
1314 PlayMenuSoundIfLoop();
1318 void DrawInfoScreen()
1320 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1322 if (info_mode == INFO_MODE_ELEMENTS)
1323 DrawInfoScreen_Elements();
1324 else if (info_mode == INFO_MODE_MUSIC)
1325 DrawInfoScreen_Music();
1326 else if (info_mode == INFO_MODE_CREDITS)
1327 DrawInfoScreen_Credits();
1328 else if (info_mode == INFO_MODE_PROGRAM)
1329 DrawInfoScreen_Program();
1330 else if (info_mode == INFO_MODE_LEVELSET)
1331 DrawInfoScreen_LevelSet();
1333 DrawInfoScreen_Main();
1335 if (info_mode != INFO_MODE_MUSIC)
1342 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1344 if (info_mode == INFO_MODE_ELEMENTS)
1345 HandleInfoScreen_Elements(button);
1346 else if (info_mode == INFO_MODE_MUSIC)
1347 HandleInfoScreen_Music(button);
1348 else if (info_mode == INFO_MODE_CREDITS)
1349 HandleInfoScreen_Credits(button);
1350 else if (info_mode == INFO_MODE_PROGRAM)
1351 HandleInfoScreen_Program(button);
1352 else if (info_mode == INFO_MODE_LEVELSET)
1353 HandleInfoScreen_LevelSet(button);
1355 HandleInfoScreen_Main(mx, my, dx, dy, button);
1361 /* ========================================================================= */
1362 /* type name functions */
1363 /* ========================================================================= */
1365 void HandleTypeName(int newxpos, Key key)
1367 static int xpos = 0, ypos = 2;
1368 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1369 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1370 int startx = mSX + 32 + name_width;
1371 int starty = mSY + ypos * 32;
1377 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1378 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1383 if (((key >= KSYM_A && key <= KSYM_Z) ||
1384 (key >= KSYM_a && key <= KSYM_z)) &&
1385 xpos < MAX_PLAYER_NAME_LEN)
1389 if (key >= KSYM_A && key <= KSYM_Z)
1390 ascii = 'A' + (char)(key - KSYM_A);
1392 ascii = 'a' + (char)(key - KSYM_a);
1394 setup.player_name[xpos] = ascii;
1395 setup.player_name[xpos + 1] = 0;
1398 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1399 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1401 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1404 setup.player_name[xpos] = 0;
1406 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1408 else if (key == KSYM_Return && xpos > 0)
1410 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1411 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1414 game_status = GAME_MODE_MAIN;
1419 /* ========================================================================= */
1420 /* tree menu functions */
1421 /* ========================================================================= */
1423 static void DrawChooseTree(TreeInfo **ti_ptr)
1427 FreeScreenGadgets();
1428 CreateScreenGadgets();
1430 CloseDoor(DOOR_CLOSE_2);
1434 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1435 MapChooseTreeGadgets(*ti_ptr);
1441 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1443 struct GadgetInfo *gi = screen_gadget[id];
1444 int items_max, items_visible, item_position;
1446 items_max = numTreeInfoInGroup(ti);
1447 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1448 item_position = first_entry;
1450 if (item_position > items_max - items_visible)
1451 item_position = items_max - items_visible;
1453 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1454 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1455 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1458 static void drawChooseTreeList(int first_entry, int num_page_entries,
1462 char buffer[SCR_FIELDX * 2];
1463 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1464 char *title_string = NULL;
1466 int xoffset_sets = 16;
1468 int yoffset_sets = MENU_TITLE1_YPOS;
1470 int xoffset_setup = 16;
1472 int yoffset_setup = 16;
1475 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1478 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1481 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1482 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1484 int last_game_status = game_status; /* save current game status */
1487 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1488 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1489 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1490 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1493 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1495 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1498 /* force LEVELS font on artwork setup screen */
1499 game_status = GAME_MODE_LEVELS;
1501 /* clear tree list area, but not title or scrollbar */
1502 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1503 SXSIZE - 32 + menu.scrollbar_xoffset,
1504 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1506 for (i = 0; i < num_page_entries; i++)
1508 TreeInfo *node, *node_first;
1509 int entry_pos = first_entry + i;
1510 int ypos = MENU_SCREEN_START_YPOS + i;
1512 node_first = getTreeInfoFirstGroupEntry(ti);
1513 node = getTreeInfoFromPos(node_first, entry_pos);
1515 strncpy(buffer, node->name, max_buffer_len);
1516 buffer[max_buffer_len] = '\0';
1518 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1520 if (node->parent_link)
1521 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1522 else if (node->level_group)
1523 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1525 initCursor(i, IMG_MENU_BUTTON);
1528 game_status = last_game_status; /* restore current game status */
1530 redraw_mask |= REDRAW_FIELD;
1533 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1535 TreeInfo *node, *node_first;
1536 int x, last_redraw_mask = redraw_mask;
1538 int ypos = MENU_TITLE2_YPOS;
1543 if (ti->type != TREE_TYPE_LEVEL_DIR)
1546 node_first = getTreeInfoFirstGroupEntry(ti);
1547 node = getTreeInfoFromPos(node_first, entry_pos);
1549 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1551 if (node->parent_link)
1552 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1554 else if (node->level_group)
1555 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1557 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1558 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1559 node->levels, node->class_desc);
1561 /* let BackToFront() redraw only what is needed */
1562 redraw_mask = last_redraw_mask | REDRAW_TILES;
1563 for (x = 0; x < SCR_FIELDX; x++)
1564 MarkTileDirty(x, 1);
1567 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1570 TreeInfo *ti = *ti_ptr;
1572 int y = ti->cl_cursor;
1573 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1574 int num_entries = numTreeInfoInGroup(ti);
1575 int num_page_entries;
1576 int last_game_status = game_status; /* save current game status */
1577 boolean position_set_by_scrollbar = (dx == 999);
1579 /* force LEVELS draw offset on choose level and artwork setup screen */
1580 game_status = GAME_MODE_LEVELS;
1582 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1583 num_page_entries = num_entries;
1585 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1587 game_status = last_game_status; /* restore current game status */
1589 if (button == MB_MENU_INITIALIZE)
1591 int num_entries = numTreeInfoInGroup(ti);
1592 int entry_pos = posTreeInfo(ti);
1594 if (ti->cl_first == -1)
1596 /* only on initialization */
1597 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1598 ti->cl_cursor = entry_pos - ti->cl_first;
1600 else if (ti->cl_cursor >= num_page_entries ||
1601 (num_entries > num_page_entries &&
1602 num_entries - ti->cl_first < num_page_entries))
1604 /* only after change of list size (by custom graphic configuration) */
1605 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1606 ti->cl_cursor = entry_pos - ti->cl_first;
1609 if (position_set_by_scrollbar)
1612 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1615 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1616 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1617 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1621 else if (button == MB_MENU_LEAVE)
1623 if (ti->node_parent)
1625 *ti_ptr = ti->node_parent;
1626 DrawChooseTree(ti_ptr);
1628 else if (game_status == GAME_MODE_SETUP)
1634 game_status = GAME_MODE_MAIN;
1641 if (mx || my) /* mouse input */
1643 int last_game_status = game_status; /* save current game status */
1645 /* force LEVELS draw offset on artwork setup screen */
1646 game_status = GAME_MODE_LEVELS;
1648 x = (mx - mSX) / 32;
1649 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1651 game_status = last_game_status; /* restore current game status */
1653 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1655 /* move cursor instead of scrolling when already at start/end of list */
1656 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1658 else if (dy == +1 * SCROLL_LINE &&
1659 ti->cl_first + num_page_entries == num_entries)
1662 /* handle scrolling screen one line or page */
1663 if (ti->cl_cursor + dy < 0 ||
1664 ti->cl_cursor + dy > num_page_entries - 1)
1666 if (ABS(dy) == SCROLL_PAGE)
1667 step = num_page_entries - 1;
1669 if (dy < 0 && ti->cl_first > 0)
1671 /* scroll page/line up */
1673 ti->cl_first -= step;
1674 if (ti->cl_first < 0)
1677 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1678 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1679 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1680 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1683 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1685 /* scroll page/line down */
1687 ti->cl_first += step;
1688 if (ti->cl_first + num_page_entries > num_entries)
1689 ti->cl_first = MAX(0, num_entries - num_page_entries);
1691 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1692 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1693 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1694 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1701 /* handle moving cursor one line */
1702 y = ti->cl_cursor + dy;
1707 TreeInfo *node_first, *node_cursor;
1708 int entry_pos = ti->cl_first + y;
1710 node_first = getTreeInfoFirstGroupEntry(ti);
1711 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1713 if (node_cursor->node_group)
1715 node_cursor->cl_first = ti->cl_first;
1716 node_cursor->cl_cursor = ti->cl_cursor;
1717 *ti_ptr = node_cursor->node_group;
1718 DrawChooseTree(ti_ptr);
1723 else if (dx == -1 && ti->node_parent)
1725 *ti_ptr = ti->node_parent;
1726 DrawChooseTree(ti_ptr);
1731 if (!anyScrollbarGadgetActive() &&
1732 IN_VIS_FIELD(x, y) &&
1733 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1734 y >= 0 && y < num_page_entries)
1738 if (y != ti->cl_cursor)
1740 drawChooseTreeCursor(y, FC_RED);
1741 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1742 drawChooseTreeInfo(ti->cl_first + y, ti);
1748 TreeInfo *node_first, *node_cursor;
1749 int entry_pos = ti->cl_first + y;
1751 node_first = getTreeInfoFirstGroupEntry(ti);
1752 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1754 if (node_cursor->node_group)
1756 node_cursor->cl_first = ti->cl_first;
1757 node_cursor->cl_cursor = ti->cl_cursor;
1758 *ti_ptr = node_cursor->node_group;
1759 DrawChooseTree(ti_ptr);
1761 else if (node_cursor->parent_link)
1763 *ti_ptr = node_cursor->node_parent;
1764 DrawChooseTree(ti_ptr);
1768 node_cursor->cl_first = ti->cl_first;
1769 node_cursor->cl_cursor = ti->cl_cursor;
1770 *ti_ptr = node_cursor;
1772 if (ti->type == TREE_TYPE_LEVEL_DIR)
1774 LoadLevelSetup_SeriesInfo();
1776 SaveLevelSetup_LastSeries();
1777 SaveLevelSetup_SeriesInfo();
1781 if (game_status == GAME_MODE_SETUP)
1787 game_status = GAME_MODE_MAIN;
1795 void DrawChooseLevel()
1797 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1799 DrawChooseTree(&leveldir_current);
1805 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1807 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1812 void DrawHallOfFame(int highlight_position)
1815 FadeSoundsAndMusic();
1816 CloseDoor(DOOR_CLOSE_2);
1818 if (highlight_position < 0)
1819 LoadScore(level_nr);
1827 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1830 static void drawHallOfFameList(int first_entry, int highlight_position)
1834 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1838 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
1839 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1840 "HighScores of Level %d", level_nr);
1842 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
1843 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1844 "HighScores of Level %d", level_nr);
1847 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1849 int entry = first_entry + i;
1850 boolean active = (entry == highlight_position);
1851 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1852 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1853 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1854 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1855 int dx1 = 3 * getFontWidth(font_nr1);
1856 int dx2 = dx1 + getFontWidth(font_nr1);
1857 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1858 int sy = mSY + 64 + i * 32;
1860 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1861 DrawText(mSX + dx1, sy, ".", font_nr1);
1862 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1863 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1864 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1865 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1868 redraw_mask |= REDRAW_FIELD;
1871 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1873 static int first_entry = 0;
1874 static int highlight_position = 0;
1875 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1876 int button_released = !button;
1878 if (button == MB_MENU_INITIALIZE)
1881 highlight_position = mx;
1882 drawHallOfFameList(first_entry, highlight_position);
1887 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1888 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1892 if (first_entry > 0)
1894 first_entry -= step;
1895 if (first_entry < 0)
1898 drawHallOfFameList(first_entry, highlight_position);
1903 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1905 first_entry += step;
1906 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1907 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1909 drawHallOfFameList(first_entry, highlight_position);
1912 else if (button_released)
1914 FadeSound(SND_BACKGROUND_SCORES);
1915 game_status = GAME_MODE_MAIN;
1919 if (game_status == GAME_MODE_SCORES)
1920 PlayMenuSoundIfLoop();
1926 /* ========================================================================= */
1927 /* setup screen functions */
1928 /* ========================================================================= */
1930 static struct TokenInfo *setup_info;
1931 static int num_setup_info;
1933 static char *graphics_set_name;
1934 static char *sounds_set_name;
1935 static char *music_set_name;
1937 static void execSetupMain()
1939 setup_mode = SETUP_MODE_MAIN;
1943 static void execSetupGame()
1945 setup_mode = SETUP_MODE_GAME;
1949 static void execSetupEditor()
1951 setup_mode = SETUP_MODE_EDITOR;
1955 static void execSetupGraphics()
1957 setup_mode = SETUP_MODE_GRAPHICS;
1961 static void execSetupSound()
1963 setup_mode = SETUP_MODE_SOUND;
1967 static void execSetupArtwork()
1969 setup.graphics_set = artwork.gfx_current->identifier;
1970 setup.sounds_set = artwork.snd_current->identifier;
1971 setup.music_set = artwork.mus_current->identifier;
1973 /* needed if last screen (setup choice) changed graphics, sounds or music */
1974 ReloadCustomArtwork(0);
1976 /* needed for displaying artwork name instead of artwork identifier */
1977 graphics_set_name = artwork.gfx_current->name;
1978 sounds_set_name = artwork.snd_current->name;
1979 music_set_name = artwork.mus_current->name;
1981 setup_mode = SETUP_MODE_ARTWORK;
1985 static void execSetupChooseGraphics()
1987 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1991 static void execSetupChooseSounds()
1993 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1997 static void execSetupChooseMusic()
1999 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2003 static void execSetupInput()
2005 setup_mode = SETUP_MODE_INPUT;
2009 static void execSetupShortcut()
2011 setup_mode = SETUP_MODE_SHORTCUT;
2015 static void execExitSetup()
2017 game_status = GAME_MODE_MAIN;
2021 static void execSaveAndExitSetup()
2027 static struct TokenInfo setup_info_main[] =
2029 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
2030 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
2031 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2032 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2033 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2034 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2035 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
2036 { TYPE_EMPTY, NULL, "" },
2037 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2038 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2043 static struct TokenInfo setup_info_game[] =
2045 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
2046 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2047 { TYPE_SWITCH, &setup.skip_levels, "Skip Levels:" },
2048 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
2049 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
2050 { TYPE_SWITCH, &setup.quick_switch, "Quick Switch:" },
2051 { TYPE_EMPTY, NULL, "" },
2052 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2057 static struct TokenInfo setup_info_editor[] =
2060 { TYPE_STRING, NULL, "Offer Special Elements:"},
2065 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
2066 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2067 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,"E.M.C.:" },
2068 { TYPE_SWITCH, &setup.editor.el_more, "R'n'D:" },
2069 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2070 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2071 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "DC II:" },
2072 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX BD:" },
2074 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
2075 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
2076 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2077 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
2078 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic:" },
2079 { TYPE_EMPTY, NULL, "" },
2080 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2085 static struct TokenInfo setup_info_graphics[] =
2087 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2088 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
2089 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
2091 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
2092 { TYPE_SWITCH, &setup.fading, "Fading:" },
2094 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
2095 { TYPE_SWITCH, &setup.toons, "Toons:" },
2096 { TYPE_EMPTY, NULL, "" },
2097 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2102 static struct TokenInfo setup_info_sound[] =
2104 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
2105 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
2106 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
2107 { TYPE_EMPTY, NULL, "" },
2108 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2113 static struct TokenInfo setup_info_artwork[] =
2115 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2116 { TYPE_STRING, &graphics_set_name, "" },
2117 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2118 { TYPE_STRING, &sounds_set_name, "" },
2119 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2120 { TYPE_STRING, &music_set_name, "" },
2121 { TYPE_EMPTY, NULL, "" },
2122 { TYPE_STRING, NULL, "Override Level Artwork:"},
2123 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2124 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2125 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2126 { TYPE_EMPTY, NULL, "" },
2127 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2132 static struct TokenInfo setup_info_shortcut[] =
2134 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2135 { TYPE_KEY, &setup.shortcut.save_game, "" },
2136 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2137 { TYPE_KEY, &setup.shortcut.load_game, "" },
2138 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2139 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2140 { TYPE_EMPTY, NULL, "" },
2141 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2142 { TYPE_EMPTY, NULL, "" },
2143 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2148 static Key getSetupKey()
2150 Key key = KSYM_UNDEFINED;
2151 boolean got_key_event = FALSE;
2153 while (!got_key_event)
2155 if (PendingEvent()) /* got event */
2163 case EVENT_KEYPRESS:
2165 key = GetEventKey((KeyEvent *)&event, TRUE);
2167 /* press 'Escape' or 'Enter' to keep the existing key binding */
2168 if (key == KSYM_Escape || key == KSYM_Return)
2169 key = KSYM_UNDEFINED; /* keep old value */
2171 got_key_event = TRUE;
2175 case EVENT_KEYRELEASE:
2176 key_joystick_mapping = 0;
2180 HandleOtherEvents(&event);
2188 /* don't eat all CPU time */
2195 static void drawSetupValue(int pos)
2197 int xpos = MENU_SCREEN_VALUE_XPOS;
2198 int ypos = MENU_SCREEN_START_YPOS + pos;
2199 int font_nr = FONT_VALUE_1;
2200 int type = setup_info[pos].type;
2201 void *value = setup_info[pos].value;
2202 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2205 if (value_string == NULL)
2208 if (type & TYPE_KEY)
2212 if (type & TYPE_QUERY)
2214 value_string = "<press key>";
2215 font_nr = FONT_INPUT_1_ACTIVE;
2218 else if (type & TYPE_STRING)
2220 int max_value_len = (SCR_FIELDX - 2) * 2;
2223 font_nr = FONT_VALUE_2;
2225 if (strlen(value_string) > max_value_len)
2226 value_string[max_value_len] = '\0';
2228 else if (type & TYPE_BOOLEAN_STYLE)
2230 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2233 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2234 (xpos == 3 ? " " : " "), font_nr);
2235 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2238 static void changeSetupValue(int pos)
2240 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2242 *(boolean *)setup_info[pos].value ^= TRUE;
2244 else if (setup_info[pos].type & TYPE_KEY)
2248 setup_info[pos].type |= TYPE_QUERY;
2249 drawSetupValue(pos);
2250 setup_info[pos].type &= ~TYPE_QUERY;
2252 key = getSetupKey();
2253 if (key != KSYM_UNDEFINED)
2254 *(Key *)setup_info[pos].value = key;
2257 drawSetupValue(pos);
2260 static void DrawSetupScreen_Generic()
2262 char *title_string = NULL;
2266 CloseDoor(DOOR_CLOSE_2);
2270 if (setup_mode == SETUP_MODE_MAIN)
2272 setup_info = setup_info_main;
2273 title_string = "Setup";
2275 else if (setup_mode == SETUP_MODE_GAME)
2277 setup_info = setup_info_game;
2278 title_string = "Setup Game";
2280 else if (setup_mode == SETUP_MODE_EDITOR)
2282 setup_info = setup_info_editor;
2283 title_string = "Setup Editor";
2285 else if (setup_mode == SETUP_MODE_GRAPHICS)
2287 setup_info = setup_info_graphics;
2288 title_string = "Setup Graphics";
2290 else if (setup_mode == SETUP_MODE_SOUND)
2292 setup_info = setup_info_sound;
2293 title_string = "Setup Sound";
2295 else if (setup_mode == SETUP_MODE_ARTWORK)
2297 setup_info = setup_info_artwork;
2298 title_string = "Custom Artwork";
2300 else if (setup_mode == SETUP_MODE_SHORTCUT)
2302 setup_info = setup_info_shortcut;
2303 title_string = "Setup Shortcuts";
2307 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2309 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2313 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2315 void *value_ptr = setup_info[i].value;
2316 int ypos = MENU_SCREEN_START_YPOS + i;
2317 int font_nr = FONT_MENU_1;
2319 /* set some entries to "unchangeable" according to other variables */
2320 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2321 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2322 (value_ptr == &setup.sound_music && !audio.music_available) ||
2323 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2324 setup_info[i].type |= TYPE_GHOSTED;
2326 if (setup_info[i].type & TYPE_STRING)
2327 font_nr = FONT_MENU_2;
2329 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2331 if (setup_info[i].type & TYPE_ENTER_MENU)
2332 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2333 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2334 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2335 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2336 initCursor(i, IMG_MENU_BUTTON);
2338 if (setup_info[i].type & TYPE_VALUE)
2345 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2346 "Joysticks deactivated in setup menu");
2351 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2354 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2356 static int choice_store[MAX_SETUP_MODES];
2357 int choice = choice_store[setup_mode]; /* always starts with 0 */
2361 if (button == MB_MENU_INITIALIZE)
2363 /* advance to first valid menu entry */
2364 while (choice < num_setup_info &&
2365 setup_info[choice].type & TYPE_SKIP_ENTRY)
2367 choice_store[setup_mode] = choice;
2369 drawCursor(choice, FC_RED);
2372 else if (button == MB_MENU_LEAVE)
2374 for (y = 0; y < num_setup_info; y++)
2376 if (setup_info[y].type & TYPE_LEAVE_MENU)
2378 void (*menu_callback_function)(void) = setup_info[y].value;
2380 menu_callback_function();
2381 break; /* absolutely needed because function changes 'setup_info'! */
2388 if (mx || my) /* mouse input */
2390 x = (mx - mSX) / 32;
2391 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2393 else if (dx || dy) /* keyboard input */
2397 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2399 if (setup_info[choice].type & menu_navigation_type ||
2400 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2401 button = MB_MENU_CHOICE;
2406 /* jump to next non-empty menu entry (up or down) */
2407 while (y > 0 && y < num_setup_info - 1 &&
2408 setup_info[y].type & TYPE_SKIP_ENTRY)
2412 if (IN_VIS_FIELD(x, y) &&
2413 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2419 drawCursor(y, FC_RED);
2420 drawCursor(choice, FC_BLUE);
2421 choice = choice_store[setup_mode] = y;
2424 else if (!(setup_info[y].type & TYPE_GHOSTED))
2426 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2428 void (*menu_callback_function)(void) = setup_info[choice].value;
2430 menu_callback_function();
2434 if (setup_info[y].type & TYPE_KEYTEXT &&
2435 setup_info[y + 1].type & TYPE_KEY)
2438 if (setup_info[y].type & TYPE_VALUE)
2439 changeSetupValue(y);
2445 void DrawSetupScreen_Input()
2450 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2452 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2455 initCursor(0, IMG_MENU_BUTTON);
2456 initCursor(1, IMG_MENU_BUTTON);
2457 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2458 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2460 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2461 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2463 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2464 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2465 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2468 DeactivateJoystickForCalibration();
2471 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2472 "Joysticks deactivated on this screen");
2475 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2480 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2482 if (device_name == NULL)
2485 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2488 if (strlen(device_name) > 1)
2490 char c1 = device_name[strlen(device_name) - 1];
2491 char c2 = device_name[strlen(device_name) - 2];
2493 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2494 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2497 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2498 strlen(device_name));
2501 static void drawPlayerSetupInputInfo(int player_nr)
2504 static struct SetupKeyboardInfo custom_key;
2511 { &custom_key.left, "Joystick Left" },
2512 { &custom_key.right, "Joystick Right" },
2513 { &custom_key.up, "Joystick Up" },
2514 { &custom_key.down, "Joystick Down" },
2515 { &custom_key.snap, "Button 1" },
2516 { &custom_key.drop, "Button 2" }
2518 static char *joystick_name[MAX_PLAYERS] =
2528 custom_key = setup.input[player_nr].key;
2530 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2531 FONT_INPUT_1_ACTIVE);
2533 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2535 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2536 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2538 if (setup.input[player_nr].use_joystick)
2540 char *device_name = setup.input[player_nr].joy.device_name;
2541 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
2542 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
2544 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
2545 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
2549 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
2550 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
2553 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
2554 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2555 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2556 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2557 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2558 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
2559 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
2560 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
2561 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
2562 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
2563 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
2565 for (i = 0; i < 6; i++)
2567 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2569 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2571 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2572 (setup.input[player_nr].use_joystick ?
2574 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2578 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2580 static int choice = 0;
2581 static int player_nr = 0;
2584 int pos_start = SETUPINPUT_SCREEN_POS_START;
2585 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2586 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2587 int pos_end = SETUPINPUT_SCREEN_POS_END;
2589 if (button == MB_MENU_INITIALIZE)
2591 drawPlayerSetupInputInfo(player_nr);
2592 drawCursor(choice, FC_RED);
2596 else if (button == MB_MENU_LEAVE)
2598 setup_mode = SETUP_MODE_MAIN;
2605 if (mx || my) /* mouse input */
2607 x = (mx - mSX) / 32;
2608 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2610 else if (dx || dy) /* keyboard input */
2612 if (dx && choice == 0)
2613 x = (dx < 0 ? 10 : 12);
2614 else if ((dx && choice == 1) ||
2615 (dx == +1 && choice == 2) ||
2616 (dx == -1 && choice == pos_end))
2617 button = MB_MENU_CHOICE;
2621 if (y >= pos_empty1 && y <= pos_empty2)
2622 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2625 if (IN_VIS_FIELD(x, y) &&
2626 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2628 static unsigned long delay = 0;
2630 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2633 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2635 drawPlayerSetupInputInfo(player_nr);
2637 else if (IN_VIS_FIELD(x, y) &&
2638 y >= pos_start && y <= pos_end &&
2639 !(y >= pos_empty1 && y <= pos_empty2))
2645 drawCursor(y, FC_RED);
2646 drawCursor(choice, FC_BLUE);
2654 char *device_name = setup.input[player_nr].joy.device_name;
2656 if (!setup.input[player_nr].use_joystick)
2658 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2660 setJoystickDeviceToNr(device_name, new_device_nr);
2661 setup.input[player_nr].use_joystick = TRUE;
2665 int device_nr = getJoystickNrFromDeviceName(device_name);
2666 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2668 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2669 setup.input[player_nr].use_joystick = FALSE;
2671 setJoystickDeviceToNr(device_name, new_device_nr);
2674 drawPlayerSetupInputInfo(player_nr);
2678 if (setup.input[player_nr].use_joystick)
2681 CalibrateJoystick(player_nr);
2684 CustomizeKeyboard(player_nr);
2686 else if (y == pos_end)
2690 setup_mode = SETUP_MODE_MAIN;
2697 void CustomizeKeyboard(int player_nr)
2701 boolean finished = FALSE;
2702 static struct SetupKeyboardInfo custom_key;
2707 } customize_step[] =
2709 { &custom_key.left, "Move Left" },
2710 { &custom_key.right, "Move Right" },
2711 { &custom_key.up, "Move Up" },
2712 { &custom_key.down, "Move Down" },
2713 { &custom_key.snap, "Snap Field" },
2714 { &custom_key.drop, "Drop Element" }
2717 /* read existing key bindings from player setup */
2718 custom_key = setup.input[player_nr].key;
2723 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
2725 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2732 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2733 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2734 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2735 "Key:", FONT_INPUT_1_ACTIVE);
2736 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2737 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2741 if (PendingEvent()) /* got event */
2749 case EVENT_KEYPRESS:
2751 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2753 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2759 /* all keys configured -- wait for "Escape" or "Return" key */
2763 /* press 'Enter' to keep the existing key binding */
2764 if (key == KSYM_Return)
2765 key = *customize_step[step_nr].key;
2767 /* check if key already used */
2768 for (i = 0; i < step_nr; i++)
2769 if (*customize_step[i].key == key)
2774 /* got new key binding */
2775 *customize_step[step_nr].key = key;
2776 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2778 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2779 getKeyNameFromKey(key), FONT_VALUE_1);
2782 /* un-highlight last query */
2783 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
2784 customize_step[step_nr - 1].text, FONT_MENU_1);
2785 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
2786 "Key:", FONT_MENU_1);
2788 /* press 'Enter' to leave */
2791 DrawText(mSX + 16, mSY + 15 * 32 + 16,
2792 "Press Enter", FONT_TITLE_1);
2796 /* query next key binding */
2797 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2798 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2799 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2800 "Key:", FONT_INPUT_1_ACTIVE);
2801 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2802 getKeyNameFromKey(*customize_step[step_nr].key),
2807 case EVENT_KEYRELEASE:
2808 key_joystick_mapping = 0;
2812 HandleOtherEvents(&event);
2820 /* don't eat all CPU time */
2824 /* write new key bindings back to player setup */
2825 setup.input[player_nr].key = custom_key;
2828 DrawSetupScreen_Input();
2831 static boolean CalibrateJoystickMain(int player_nr)
2833 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2834 int new_joystick_xright = JOYSTICK_XMIDDLE;
2835 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2836 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2837 int new_joystick_xmiddle, new_joystick_ymiddle;
2839 int joystick_fd = joystick.fd[player_nr];
2840 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2841 boolean check[3][3];
2842 int check_remaining = 3 * 3;
2847 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2850 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2855 for (y = 0; y < 3; y++)
2857 for (x = 0; x < 3; x++)
2859 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2860 check[x][y] = FALSE;
2864 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
2865 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
2866 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
2867 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
2868 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
2869 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
2870 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
2872 joy_value = Joystick(player_nr);
2873 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2874 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2876 /* eventually uncalibrated center position (joystick could be uncentered) */
2877 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2880 new_joystick_xmiddle = joy_x;
2881 new_joystick_ymiddle = joy_y;
2883 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2886 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2891 if (PendingEvent()) /* got event */
2899 case EVENT_KEYPRESS:
2900 switch(GetEventKey((KeyEvent *)&event, TRUE))
2903 if (check_remaining == 0)
2916 case EVENT_KEYRELEASE:
2917 key_joystick_mapping = 0;
2921 HandleOtherEvents(&event);
2926 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2929 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2930 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2931 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2932 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2934 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2935 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2936 setup.input[player_nr].joy.xright = new_joystick_xright;
2937 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2938 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2939 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2941 CheckJoystickData();
2943 joy_value = Joystick(player_nr);
2945 if (joy_value & JOY_BUTTON && check_remaining == 0)
2948 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2949 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2951 if (x != last_x || y != last_y)
2953 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2954 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2959 if (check_remaining > 0 && !check[x+1][y+1])
2961 check[x+1][y+1] = TRUE;
2967 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2968 setup.input[player_nr].joy.xleft,
2969 setup.input[player_nr].joy.xmiddle,
2970 setup.input[player_nr].joy.xright);
2971 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2972 setup.input[player_nr].joy.yupper,
2973 setup.input[player_nr].joy.ymiddle,
2974 setup.input[player_nr].joy.ylower);
2983 /* don't eat all CPU time */
2987 /* calibrated center position (joystick should now be centered) */
2988 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2991 new_joystick_xmiddle = joy_x;
2992 new_joystick_ymiddle = joy_y;
2997 DrawSetupScreen_Input();
3000 /* wait until the last pressed button was released */
3001 while (Joystick(player_nr) & JOY_BUTTON)
3003 if (PendingEvent()) /* got event */
3008 HandleOtherEvents(&event);
3017 void CalibrateJoystick(int player_nr)
3019 if (!CalibrateJoystickMain(player_nr))
3021 char *device_name = setup.input[player_nr].joy.device_name;
3022 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3023 int xpos = mSX - SX;
3024 int ypos = mSY - SY;
3028 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3029 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3032 Delay(2000); /* show error message for a short time */
3038 DrawSetupScreen_Input();
3042 void DrawSetupScreen()
3044 DeactivateJoystick();
3046 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3048 if (setup_mode == SETUP_MODE_INPUT)
3049 DrawSetupScreen_Input();
3050 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3051 DrawChooseTree(&artwork.gfx_current);
3052 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3053 DrawChooseTree(&artwork.snd_current);
3054 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3055 DrawChooseTree(&artwork.mus_current);
3057 DrawSetupScreen_Generic();
3063 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3065 if (setup_mode == SETUP_MODE_INPUT)
3066 HandleSetupScreen_Input(mx, my, dx, dy, button);
3067 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3068 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3069 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3070 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3071 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3072 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3074 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3079 void HandleGameActions()
3081 if (game_status != GAME_MODE_PLAYING)
3084 /* !!! FIX THIS (START) !!! */
3085 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
3087 byte *recorded_player_action;
3088 byte summarized_player_action = 0;
3089 byte tape_action[MAX_PLAYERS];
3093 if (level.native_em_level->lev->home == 0) /* all players at home */
3095 local_player->LevelSolved = TRUE;
3096 AllPlayersGone = TRUE;
3098 level.native_em_level->lev->home = -1;
3101 if (local_player->LevelSolved)
3104 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3107 if (game_status != GAME_MODE_PLAYING)
3110 if (level.native_em_level->lev->home == 0) /* all players at home */
3112 if (local_player->LevelSolved)
3115 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3118 if (game_status != GAME_MODE_PLAYING)
3123 if (level.native_em_level->ply[0]->alive == 0 &&
3124 level.native_em_level->ply[1]->alive == 0 &&
3125 level.native_em_level->ply[2]->alive == 0 &&
3126 level.native_em_level->ply[3]->alive == 0) /* all dead */
3127 AllPlayersGone = TRUE;
3129 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3132 /* --- game actions --- */
3136 /* don't use 100% CPU while in pause mode -- this should better be solved
3137 like in the R'n'D game engine! */
3144 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
3147 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
3148 if (recorded_player_action == NULL && tape.pausing)
3152 for (i = 0; i < MAX_PLAYERS; i++)
3154 summarized_player_action |= stored_player[i].action;
3156 if (!network_playing)
3157 stored_player[i].effective_action = stored_player[i].action;
3160 if (!options.network && !setup.team_mode)
3161 local_player->effective_action = summarized_player_action;
3163 if (recorded_player_action != NULL)
3164 for (i = 0; i < MAX_PLAYERS; i++)
3165 stored_player[i].effective_action = recorded_player_action[i];
3167 for (i = 0; i < MAX_PLAYERS; i++)
3169 tape_action[i] = stored_player[i].effective_action;
3171 /* !!! (this does not happen in the EM engine) !!! */
3172 if (tape.recording && tape_action[i] && !tape.player_participates[i])
3173 tape.player_participates[i] = TRUE; /* player just appeared from CE */
3176 /* only save actions from input devices, but not programmed actions */
3178 TapeRecordAction(tape_action);
3182 byte effective_action[MAX_PLAYERS];
3184 for (i = 0; i < MAX_PLAYERS; i++)
3185 effective_action[i] = stored_player[i].effective_action;
3187 GameActions_EM(effective_action);
3190 GameActions_EM(local_player->effective_action);
3193 if (TimeFrames >= FRAMES_PER_SECOND)
3198 if (!level.use_step_counter)
3206 if (TimeLeft <= 10 && setup.time_limit)
3207 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
3209 DrawGameValue_Time(TimeLeft);
3211 if (!TimeLeft && setup.time_limit)
3212 level.native_em_level->lev->killed_out_of_time = TRUE;
3214 else if (level.time == 0 && level.native_em_level->lev->home > 0)
3215 DrawGameValue_Time(TimePlayed);
3217 level.native_em_level->lev->time =
3218 (level.time == 0 ? TimePlayed : TimeLeft);
3221 if (tape.recording || tape.playing)
3222 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
3232 if (game.restart_level)
3233 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
3235 if (local_player->LevelSolved)
3238 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3244 if (tape.auto_play && !tape.playing)
3245 AutoPlayTape(); /* continue automatically playing next tape */
3249 void StartGameActions(boolean init_network_game, boolean record_tape,
3253 TapeStartRecording(random_seed);
3255 #if defined(NETWORK_AVALIABLE)
3256 if (init_network_game)
3258 SendToServer_StartPlaying();
3266 game_status = GAME_MODE_PLAYING;
3268 InitRND(random_seed);
3273 /* ---------- new screen button stuff -------------------------------------- */
3275 /* graphic position and size values for buttons and scrollbars */
3276 #define SC_SCROLLBUTTON_XSIZE TILEX
3277 #define SC_SCROLLBUTTON_YSIZE TILEY
3279 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3280 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3281 SC_SCROLLBUTTON_YSIZE)
3282 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3283 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3284 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3285 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3286 SC_SCROLLBUTTON_YSIZE)
3287 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3288 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3289 SC_SCROLL_VERTICAL_YSIZE)
3291 #define SC_BORDER_SIZE 14
3295 int gfx_unpressed, gfx_pressed;
3299 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3302 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3303 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3304 SCREEN_CTRL_ID_SCROLL_UP,
3308 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3309 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3310 SCREEN_CTRL_ID_SCROLL_DOWN,
3317 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3318 Bitmap **gfx_unpressed, **gfx_pressed;
3320 int gfx_unpressed, gfx_pressed;
3327 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3330 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3331 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3333 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3335 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3336 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3337 GD_TYPE_SCROLLBAR_VERTICAL,
3338 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3339 "scroll level series vertically"
3343 static void CreateScreenScrollbuttons()
3345 struct GadgetInfo *gi;
3346 unsigned long event_mask;
3349 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3351 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3352 int gfx_unpressed, gfx_pressed;
3353 int x, y, width, height;
3354 int gd_x1, gd_x2, gd_y1, gd_y2;
3355 int id = scrollbutton_info[i].gadget_id;
3357 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3359 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3360 y = mSY + scrollbutton_info[i].y;
3361 width = SC_SCROLLBUTTON_XSIZE;
3362 height = SC_SCROLLBUTTON_YSIZE;
3364 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3365 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3366 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3368 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3369 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3370 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3371 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3372 gd_x1 = graphic_info[gfx_unpressed].src_x;
3373 gd_y1 = graphic_info[gfx_unpressed].src_y;
3374 gd_x2 = graphic_info[gfx_pressed].src_x;
3375 gd_y2 = graphic_info[gfx_pressed].src_y;
3377 gi = CreateGadget(GDI_CUSTOM_ID, id,
3378 GDI_CUSTOM_TYPE_ID, i,
3379 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3384 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3385 GDI_STATE, GD_BUTTON_UNPRESSED,
3386 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3387 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3388 GDI_DIRECT_DRAW, FALSE,
3389 GDI_EVENT_MASK, event_mask,
3390 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3394 Error(ERR_EXIT, "cannot create gadget");
3396 screen_gadget[id] = gi;
3400 static void CreateScreenScrollbars()
3404 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3406 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3407 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3408 int gfx_unpressed, gfx_pressed;
3410 int x, y, width, height;
3411 int gd_x1, gd_x2, gd_y1, gd_y2;
3412 struct GadgetInfo *gi;
3413 int items_max, items_visible, item_position;
3414 unsigned long event_mask;
3415 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3416 int id = scrollbar_info[i].gadget_id;
3418 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3420 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3421 y = mSY + scrollbar_info[i].y;
3422 width = scrollbar_info[i].width;
3423 height = scrollbar_info[i].height;
3425 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3426 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3428 items_max = num_page_entries;
3429 items_visible = num_page_entries;
3432 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3433 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3434 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3440 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3441 gfx_pressed = scrollbar_info[i].gfx_pressed;
3442 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3443 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3444 gd_x1 = graphic_info[gfx_unpressed].src_x;
3445 gd_y1 = graphic_info[gfx_unpressed].src_y;
3446 gd_x2 = graphic_info[gfx_pressed].src_x;
3447 gd_y2 = graphic_info[gfx_pressed].src_y;
3450 gi = CreateGadget(GDI_CUSTOM_ID, id,
3451 GDI_CUSTOM_TYPE_ID, i,
3452 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3457 GDI_TYPE, scrollbar_info[i].type,
3458 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3459 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3460 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3461 GDI_STATE, GD_BUTTON_UNPRESSED,
3462 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3463 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3464 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3465 GDI_DIRECT_DRAW, FALSE,
3466 GDI_EVENT_MASK, event_mask,
3467 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3471 Error(ERR_EXIT, "cannot create gadget");
3473 screen_gadget[id] = gi;
3477 void CreateScreenGadgets()
3479 int last_game_status = game_status; /* save current game status */
3481 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3484 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3486 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3488 /* copy pointers to clip mask and GC */
3489 scrollbar_bitmap[i]->clip_mask =
3490 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3491 scrollbar_bitmap[i]->stored_clip_gc =
3492 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3494 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3495 scrollbar_bitmap[i],
3496 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3497 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3498 TILEX, TILEY, 0, 0);
3502 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3503 game_status = GAME_MODE_LEVELS;
3505 CreateScreenScrollbuttons();
3506 CreateScreenScrollbars();
3508 game_status = last_game_status; /* restore current game status */
3511 void FreeScreenGadgets()
3515 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3516 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3518 /* prevent freeing clip mask and GC twice */
3519 scrollbar_bitmap[i]->clip_mask = None;
3520 scrollbar_bitmap[i]->stored_clip_gc = None;
3522 FreeBitmap(scrollbar_bitmap[i]);
3526 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3527 FreeGadget(screen_gadget[i]);
3530 void MapChooseTreeGadgets(TreeInfo *ti)
3532 int num_entries = numTreeInfoInGroup(ti);
3535 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3538 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3539 MapGadget(screen_gadget[i]);
3543 void UnmapChooseTreeGadgets()
3547 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3548 UnmapGadget(screen_gadget[i]);
3552 static void HandleScreenGadgets(struct GadgetInfo *gi)
3554 int id = gi->custom_id;
3556 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3561 case SCREEN_CTRL_ID_SCROLL_UP:
3562 if (game_status == GAME_MODE_LEVELS)
3563 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3564 else if (game_status == GAME_MODE_SETUP)
3565 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3568 case SCREEN_CTRL_ID_SCROLL_DOWN:
3569 if (game_status == GAME_MODE_LEVELS)
3570 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3571 else if (game_status == GAME_MODE_SETUP)
3572 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3575 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3576 if (game_status == GAME_MODE_LEVELS)
3577 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3578 else if (game_status == GAME_MODE_SETUP)
3579 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);