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
64 /* buttons and scrollbars identifiers */
65 #define SCREEN_CTRL_ID_SCROLL_UP 0
66 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
67 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
69 #define NUM_SCREEN_SCROLLBUTTONS 2
70 #define NUM_SCREEN_SCROLLBARS 1
71 #define NUM_SCREEN_GADGETS 3
73 /* forward declarations of internal functions */
74 static void HandleScreenGadgets(struct GadgetInfo *);
75 static void HandleSetupScreen_Generic(int, int, int, int, int);
76 static void HandleSetupScreen_Input(int, int, int, int, int);
77 static void CustomizeKeyboard(int);
78 static void CalibrateJoystick(int);
79 static void execSetupArtwork(void);
80 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
82 static void DrawChooseLevel(void);
83 static void DrawInfoScreen(void);
84 static void DrawSetupScreen(void);
86 static void DrawInfoScreen_HelpAnim(int, int, boolean);
87 static void DrawInfoScreen_HelpText(int, int, int, int);
88 static void HandleInfoScreen_Main(int, int, int, int, int);
89 static void HandleInfoScreen_Elements(int);
90 static void HandleInfoScreen_Music(int);
91 static void HandleInfoScreen_Credits(int);
92 static void HandleInfoScreen_Program(int);
94 static void MapChooseTreeGadgets(TreeInfo *);
96 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
97 static int setup_mode = SETUP_MODE_MAIN;
98 static int info_mode = INFO_MODE_MAIN;
100 #define mSX (SX + (game_status >= GAME_MODE_MAIN && \
101 game_status <= GAME_MODE_SETUP ? \
102 menu.draw_xoffset[game_status] : menu.draw_xoffset_default))
103 #define mSY (SY + (game_status >= GAME_MODE_MAIN && \
104 game_status <= GAME_MODE_SETUP ? \
105 menu.draw_yoffset[game_status] : menu.draw_yoffset_default))
107 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
108 menu.list_size[game_status] : \
109 MAX_MENU_ENTRIES_ON_SCREEN)
111 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
112 #define NUM_SCROLLBAR_BITMAPS 2
113 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
117 static void drawCursorExt(int xpos, int ypos, int color, int graphic)
119 static int cursor_array[SCR_FIELDY];
124 cursor_array[ypos] = graphic;
126 graphic = cursor_array[ypos];
130 graphic = (graphic == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
131 graphic == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE:
132 IMG_MENU_BUTTON_ACTIVE);
134 ypos += MENU_SCREEN_START_YPOS;
136 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
137 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY,
141 static void initCursor(int ypos, int graphic)
143 drawCursorExt(0, ypos, FC_BLUE, graphic);
146 static void drawCursor(int ypos, int color)
148 drawCursorExt(0, ypos, color, 0);
151 static void drawCursorXY(int xpos, int ypos, int graphic)
153 drawCursorExt(xpos, ypos, -1, graphic);
156 static void drawChooseTreeCursor(int ypos, int color)
158 int last_game_status = game_status; /* save current game status */
160 /* force LEVELS draw offset on artwork setup screen */
161 game_status = GAME_MODE_LEVELS;
163 drawCursorExt(0, ypos, color, 0);
165 game_status = last_game_status; /* restore current game status */
168 static void PlayMenuSound()
170 int sound = menu.sound[game_status];
172 if (sound == SND_UNDEFINED)
175 if (sound_info[sound].loop)
176 PlaySoundLoop(sound);
181 static void PlayMenuSoundIfLoop()
183 int sound = menu.sound[game_status];
185 if (sound == SND_UNDEFINED)
188 if (sound_info[sound].loop)
189 PlaySoundLoop(sound);
192 static void PlayMenuMusic()
194 int music = menu.music[game_status];
196 if (music == MUS_UNDEFINED)
204 DrawTextSCentered(8, FONT_TITLE_1, PROGRAM_TITLE_STRING);
205 DrawTextSCentered(46, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
208 static void ToggleFullscreenIfNeeded()
210 if (setup.fullscreen != video.fullscreen_enabled)
212 /* save old door content */
213 BlitBitmap(backbuffer, bitmap_db_door,
214 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
216 /* toggle fullscreen */
217 ChangeVideoModeIfNeeded(setup.fullscreen);
218 setup.fullscreen = video.fullscreen_enabled;
220 /* redraw background to newly created backbuffer */
221 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
222 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
224 /* restore old door content */
225 BlitBitmap(bitmap_db_door, backbuffer,
226 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
228 redraw_mask = REDRAW_ALL;
234 static LevelDirTree *leveldir_last_valid = NULL;
235 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
236 int name_width, level_width;
240 FadeSoundsAndMusic();
242 KeyboardAutoRepeatOn();
245 SetDrawDeactivationMask(REDRAW_NONE);
246 SetDrawBackgroundMask(REDRAW_FIELD);
248 audio.sound_deactivated = FALSE;
250 /* needed if last screen was the playing screen, invoked from level editor */
251 if (level_editor_test_game)
253 game_status = GAME_MODE_EDITOR;
259 /* needed if last screen was the editor screen */
260 UndrawSpecialEditorDoor();
262 /* needed if last screen was the setup screen and fullscreen state changed */
263 ToggleFullscreenIfNeeded();
265 /* leveldir_current may be invalid (level group, parent link) */
266 if (!validLevelSeries(leveldir_current))
267 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
269 /* store valid level series information */
270 leveldir_last_valid = leveldir_current;
272 /* needed if last screen (level choice) changed graphics, sounds or music */
273 ReloadCustomArtwork(0);
276 SetDrawtoField(DRAW_BACKBUFFER);
279 /* map gadgets for main menu screen */
282 /* level_nr may have been set to value over handicap with level editor */
283 if (setup.handicap && level_nr > leveldir_current->handicap_level)
284 level_nr = leveldir_current->handicap_level;
289 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
294 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
295 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
296 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
297 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
298 DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
299 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
300 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
301 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
303 /* calculated after (possible) reload of custom artwork */
304 name_width = getTextWidth(name_text, FONT_MENU_1);
305 level_width = getTextWidth("Level:", FONT_MENU_1);
307 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
308 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
311 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
313 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
314 leveldir_current->first_level, leveldir_current->last_level);
316 if (leveldir_current->readonly)
318 DrawTextS(mSX + level_width + 9 * 32 - 2,
319 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
320 DrawTextS(mSX + level_width + 9 * 32 - 2,
321 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
324 for (i = 0; i < 8; i++)
325 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_RIGHT :
328 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
329 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
331 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
336 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
339 if (TAPE_IS_EMPTY(tape))
341 DrawCompleteVideoDisplay();
346 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
350 static void gotoTopLevelDir()
352 /* move upwards to top level directory */
353 while (leveldir_current->node_parent)
355 /* write a "path" into level tree for easy navigation to last level */
356 if (leveldir_current->node_parent->node_group->cl_first == -1)
358 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
359 int leveldir_pos = posTreeInfo(leveldir_current);
360 int num_page_entries;
361 int cl_first, cl_cursor;
363 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
364 num_page_entries = num_leveldirs;
366 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
368 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
369 cl_cursor = leveldir_pos - cl_first;
371 leveldir_current->node_parent->node_group->cl_first = cl_first;
372 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
375 leveldir_current = leveldir_current->node_parent;
380 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
382 static unsigned long level_delay = 0;
383 static int choice = 5;
387 if (button == MB_MENU_INITIALIZE)
389 drawCursor(choice, FC_RED);
393 if (mx || my) /* mouse input */
396 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
398 else if (dx || dy) /* keyboard input */
400 if (dx && choice == 1)
401 x = (dx < 0 ? 10 : 14);
406 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
407 (x == 14 && level_nr < leveldir_current->last_level)) &&
408 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
410 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
411 int old_level_nr = level_nr;
414 new_level_nr = level_nr + (x == 10 ? -step : +step);
415 if (new_level_nr < leveldir_current->first_level)
416 new_level_nr = leveldir_current->first_level;
417 if (new_level_nr > leveldir_current->last_level)
418 new_level_nr = leveldir_current->last_level;
421 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
423 /* skipping levels is only allowed when trying to skip single level */
424 if (setup.skip_levels && step == 1 &&
425 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
427 leveldir_current->handicap_level++;
428 SaveLevelSetup_SeriesInfo();
431 new_level_nr = leveldir_current->handicap_level;
434 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
435 new_level_nr = leveldir_current->handicap_level;
438 if (new_level_nr != old_level_nr)
440 level_nr = new_level_nr;
442 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
446 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
450 DrawCompleteVideoDisplay();
452 /* needed because DrawMicroLevel() takes some time */
455 DelayReached(&level_delay, 0); /* reset delay counter */
458 else if (IN_VIS_FIELD(x, y) &&
459 y >= 0 && y <= 7 && (y != 1 || x < 10))
465 drawCursor(y, FC_RED);
466 drawCursor(choice, FC_BLUE);
474 game_status = GAME_MODE_PSEUDO_TYPENAME;
475 HandleTypeName(strlen(setup.player_name), 0);
481 game_status = GAME_MODE_LEVELS;
482 SaveLevelSetup_LastSeries();
483 SaveLevelSetup_SeriesInfo();
494 game_status = GAME_MODE_SCORES;
499 if (leveldir_current->readonly &&
500 strcmp(setup.player_name, "Artsoft") != 0)
501 Request("This level is read only !", REQ_CONFIRM);
502 game_status = GAME_MODE_EDITOR;
507 game_status = GAME_MODE_INFO;
508 info_mode = INFO_MODE_MAIN;
513 if (setup.autorecord)
514 TapeStartRecording();
516 #if defined(NETWORK_AVALIABLE)
518 SendToServer_StartPlaying();
522 game_status = GAME_MODE_PLAYING;
529 game_status = GAME_MODE_SETUP;
530 setup_mode = SETUP_MODE_MAIN;
535 SaveLevelSetup_LastSeries();
536 SaveLevelSetup_SeriesInfo();
537 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
538 game_status = GAME_MODE_QUIT;
543 if (game_status == GAME_MODE_MAIN)
545 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
551 /* ========================================================================= */
552 /* info screen functions */
553 /* ========================================================================= */
555 static struct TokenInfo *info_info;
556 static int num_info_info;
558 static void execInfoElements()
560 info_mode = INFO_MODE_ELEMENTS;
564 static void execInfoMusic()
566 info_mode = INFO_MODE_MUSIC;
570 static void execInfoCredits()
572 info_mode = INFO_MODE_CREDITS;
576 static void execInfoProgram()
578 info_mode = INFO_MODE_PROGRAM;
582 static void execInfoLevelSet()
584 info_mode = INFO_MODE_LEVELSET;
588 static void execExitInfo()
590 game_status = GAME_MODE_MAIN;
594 static struct TokenInfo info_info_main[] =
596 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
597 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
598 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
599 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
600 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
601 { TYPE_EMPTY, NULL, "" },
602 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
607 static void DrawInfoScreen_Main()
612 CloseDoor(DOOR_CLOSE_2);
616 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
618 info_info = info_info_main;
621 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
623 int ypos = MENU_SCREEN_START_YPOS + i;
624 int font_nr = FONT_MENU_1;
626 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
628 if (info_info[i].type & TYPE_ENTER_MENU)
629 initCursor(i, IMG_MENU_BUTTON_RIGHT);
630 else if (info_info[i].type & TYPE_LEAVE_MENU)
631 initCursor(i, IMG_MENU_BUTTON_LEFT);
632 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
633 initCursor(i, IMG_MENU_BUTTON);
644 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
647 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
649 static int choice_store[MAX_INFO_MODES];
650 int choice = choice_store[info_mode]; /* always starts with 0 */
654 if (button == MB_MENU_INITIALIZE)
656 /* advance to first valid menu entry */
657 while (choice < num_info_info &&
658 info_info[choice].type & TYPE_SKIP_ENTRY)
660 choice_store[info_mode] = choice;
662 drawCursor(choice, FC_RED);
665 else if (button == MB_MENU_LEAVE)
667 for (y = 0; y < num_info_info; y++)
669 if (info_info[y].type & TYPE_LEAVE_MENU)
671 void (*menu_callback_function)(void) = info_info[y].value;
673 menu_callback_function();
674 break; /* absolutely needed because function changes 'info_info'! */
681 if (mx || my) /* mouse input */
684 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
686 else if (dx || dy) /* keyboard input */
690 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
692 if (info_info[choice].type & menu_navigation_type ||
693 info_info[choice].type & TYPE_ENTER_SCREEN ||
694 info_info[choice].type & TYPE_BOOLEAN_STYLE)
695 button = MB_MENU_CHOICE;
700 /* jump to next non-empty menu entry (up or down) */
701 while (y > 0 && y < num_info_info - 1 &&
702 info_info[y].type & TYPE_SKIP_ENTRY)
706 if (IN_VIS_FIELD(x, y) &&
707 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
713 drawCursor(y, FC_RED);
714 drawCursor(choice, FC_BLUE);
715 choice = choice_store[info_mode] = y;
718 else if (!(info_info[y].type & TYPE_GHOSTED))
720 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
722 void (*menu_callback_function)(void) = info_info[choice].value;
724 menu_callback_function();
730 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
732 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
733 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
734 int xstart = mSX + 16;
735 int ystart = mSY + 64 + 2 * 32;
736 int ystep = TILEY + 4;
737 int element, action, direction;
745 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
746 infoscreen_step[i] = infoscreen_frame[i] = 0;
748 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
752 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
754 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
755 "Press any key or button for next page");
761 while (helpanim_info[j].element != HELPANIM_LIST_END)
763 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
768 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
777 j += infoscreen_step[i - start];
779 element = helpanim_info[j].element;
780 action = helpanim_info[j].action;
781 direction = helpanim_info[j].direction;
783 if (action != -1 && direction != -1)
784 graphic = el_act_dir2img(element, action, direction);
785 else if (action != -1)
786 graphic = el_act2img(element, action);
787 else if (direction != -1)
788 graphic = el_act2img(element, direction);
790 graphic = el2img(element);
792 delay = helpanim_info[j++].delay;
797 if (infoscreen_frame[i - start] == 0)
800 infoscreen_frame[i - start] = delay - 1;
804 sync_frame = delay - infoscreen_frame[i - start];
805 infoscreen_frame[i - start]--;
808 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
810 if (!infoscreen_frame[i - start])
811 infoscreen_step[i - start] = 0;
815 if (!infoscreen_frame[i - start])
816 infoscreen_step[i - start]++;
817 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
823 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
825 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
826 graphic, sync_frame, USE_MASKING);
829 DrawInfoScreen_HelpText(element, action, direction, i - start);
834 redraw_mask |= REDRAW_FIELD;
839 static char *getHelpText(int element, int action, int direction)
841 char token[MAX_LINE_LEN];
843 strcpy(token, element_info[element].token_name);
846 strcat(token, element_action_info[action].suffix);
849 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
851 return getHashEntry(helptext_info, token);
854 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
857 int font_nr = FONT_TEXT_2;
859 int font_nr = FONT_LEVEL_NUMBER;
861 int font_width = getFontWidth(font_nr);
862 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
863 int sy = mSY + 65 + 2 * 32 + 1;
864 int ystep = TILEY + 4;
866 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
867 int max_lines_per_text = 2;
870 if (action != -1 && direction != -1) /* element.action.direction */
871 text = getHelpText(element, action, direction);
873 if (text == NULL && action != -1) /* element.action */
874 text = getHelpText(element, action, -1);
876 if (text == NULL && direction != -1) /* element.direction */
877 text = getHelpText(element, -1, direction);
879 if (text == NULL) /* base element */
880 text = getHelpText(element, -1, -1);
882 if (text == NULL) /* not found */
883 text = "No description available";
885 if (strlen(text) <= max_chars_per_line) /* only one line of text */
886 sy += getFontHeight(font_nr) / 2;
888 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
889 max_chars_per_line, max_lines_per_text);
892 void DrawInfoScreen_Elements()
897 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
903 void HandleInfoScreen_Elements(int button)
905 static unsigned long info_delay = 0;
906 static int num_anims;
907 static int num_pages;
909 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
910 int button_released = !button;
913 if (button == MB_MENU_INITIALIZE)
915 boolean new_element = TRUE;
918 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
920 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
922 else if (new_element)
929 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
932 else if (button == MB_MENU_LEAVE)
934 info_mode = INFO_MODE_MAIN;
940 if (button_released || button == MB_MENU_INITIALIZE)
942 if (button != MB_MENU_INITIALIZE)
945 if (page >= num_pages)
947 FadeSoundsAndMusic();
949 info_mode = INFO_MODE_MAIN;
955 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
959 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
960 if (page < num_pages)
961 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
963 PlayMenuSoundIfLoop();
967 void DrawInfoScreen_Music()
974 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
977 void HandleInfoScreen_Music(int button)
979 static struct MusicFileInfo *list = NULL;
980 int ystart = 150, dy = 30;
981 int ybottom = SYSIZE - 20;
982 int button_released = !button;
984 if (button == MB_MENU_INITIALIZE)
986 list = music_file_info;
990 FadeSoundsAndMusic();
995 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
997 DrawTextSCentered(ybottom, FONT_TEXT_4,
998 "Press any key or button for info menu");
1003 else if (button == MB_MENU_LEAVE)
1005 info_mode = INFO_MODE_MAIN;
1011 if (button_released || button == MB_MENU_INITIALIZE)
1015 if (button != MB_MENU_INITIALIZE)
1021 info_mode = INFO_MODE_MAIN;
1027 FadeSoundsAndMusic();
1034 int sound = list->music;
1036 if (sound_info[sound].loop)
1037 PlaySoundLoop(sound);
1041 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1045 PlayMusic(list->music);
1047 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1050 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1052 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1053 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1055 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1058 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1060 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1061 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1063 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1065 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1068 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1070 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1071 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1073 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1075 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1078 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1080 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1081 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1083 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1085 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1088 DrawTextSCentered(ybottom, FONT_TEXT_4,
1089 "Press any key or button for next page");
1092 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1093 PlaySoundLoop(list->music);
1096 void DrawInfoScreen_Credits()
1098 int ystart = 150, ystep = 30;
1099 int ybottom = SYSIZE - 20;
1101 FadeSoundsAndMusic();
1106 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1107 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1108 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1109 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1110 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1111 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1112 "...and many thanks to all contributors");
1113 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1115 DrawTextSCentered(ybottom, FONT_TEXT_4,
1116 "Press any key or button for info menu");
1119 void HandleInfoScreen_Credits(int button)
1121 int button_released = !button;
1123 if (button == MB_MENU_LEAVE)
1125 info_mode = INFO_MODE_MAIN;
1131 if (button_released)
1133 FadeSoundsAndMusic();
1135 info_mode = INFO_MODE_MAIN;
1140 PlayMenuSoundIfLoop();
1144 void DrawInfoScreen_Program()
1146 int ystart = 150, ystep = 30;
1147 int ybottom = SYSIZE - 20;
1152 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1154 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1155 "This game is Freeware!");
1156 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1157 "If you like it, send e-mail to:");
1158 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1159 "info@artsoft.org");
1160 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1161 "or SnailMail to:");
1162 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1164 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1165 "Detmolder Strasse 189");
1166 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1168 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1171 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1172 "If you have created new levels,");
1173 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1174 "send them to me to include them!");
1175 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1178 DrawTextSCentered(ybottom, FONT_TEXT_4,
1179 "Press any key or button for info menu");
1182 void HandleInfoScreen_Program(int button)
1184 int button_released = !button;
1186 if (button == MB_MENU_LEAVE)
1188 info_mode = INFO_MODE_MAIN;
1194 if (button_released)
1196 FadeSoundsAndMusic();
1198 info_mode = INFO_MODE_MAIN;
1203 PlayMenuSoundIfLoop();
1207 void DrawInfoScreen_LevelSet()
1210 int ybottom = SYSIZE - 20;
1211 char *filename = getLevelSetInfoFilename();
1213 int font_nr = FONT_TEXT_2;
1215 int font_nr = FONT_LEVEL_NUMBER;
1217 int font_width = getFontWidth(font_nr);
1218 int font_height = getFontHeight(font_nr);
1221 int sx = SX + pad_x;
1222 int sy = SY + pad_y;
1223 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1224 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1229 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1231 DrawTextSCentered(ybottom, FONT_TEXT_4,
1232 "Press any key or button for info menu");
1234 if (filename != NULL)
1235 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1236 max_lines_per_screen);
1238 DrawTextSCentered(ystart, FONT_TEXT_2,
1239 "No information for this level set.");
1242 void HandleInfoScreen_LevelSet(int button)
1244 int button_released = !button;
1246 if (button == MB_MENU_LEAVE)
1248 info_mode = INFO_MODE_MAIN;
1254 if (button_released)
1256 FadeSoundsAndMusic();
1258 info_mode = INFO_MODE_MAIN;
1263 PlayMenuSoundIfLoop();
1267 void DrawInfoScreen()
1269 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1271 if (info_mode == INFO_MODE_ELEMENTS)
1272 DrawInfoScreen_Elements();
1273 else if (info_mode == INFO_MODE_MUSIC)
1274 DrawInfoScreen_Music();
1275 else if (info_mode == INFO_MODE_CREDITS)
1276 DrawInfoScreen_Credits();
1277 else if (info_mode == INFO_MODE_PROGRAM)
1278 DrawInfoScreen_Program();
1279 else if (info_mode == INFO_MODE_LEVELSET)
1280 DrawInfoScreen_LevelSet();
1282 DrawInfoScreen_Main();
1284 if (info_mode != INFO_MODE_MUSIC)
1291 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1293 if (info_mode == INFO_MODE_ELEMENTS)
1294 HandleInfoScreen_Elements(button);
1295 else if (info_mode == INFO_MODE_MUSIC)
1296 HandleInfoScreen_Music(button);
1297 else if (info_mode == INFO_MODE_CREDITS)
1298 HandleInfoScreen_Credits(button);
1299 else if (info_mode == INFO_MODE_PROGRAM)
1300 HandleInfoScreen_Program(button);
1301 else if (info_mode == INFO_MODE_LEVELSET)
1302 HandleInfoScreen_LevelSet(button);
1304 HandleInfoScreen_Main(mx, my, dx, dy, button);
1310 /* ========================================================================= */
1311 /* type name functions */
1312 /* ========================================================================= */
1314 void HandleTypeName(int newxpos, Key key)
1316 static int xpos = 0, ypos = 2;
1317 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1318 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1319 int startx = mSX + 32 + name_width;
1320 int starty = mSY + ypos * 32;
1326 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1327 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1332 if (((key >= KSYM_A && key <= KSYM_Z) ||
1333 (key >= KSYM_a && key <= KSYM_z)) &&
1334 xpos < MAX_PLAYER_NAME_LEN)
1338 if (key >= KSYM_A && key <= KSYM_Z)
1339 ascii = 'A' + (char)(key - KSYM_A);
1341 ascii = 'a' + (char)(key - KSYM_a);
1343 setup.player_name[xpos] = ascii;
1344 setup.player_name[xpos + 1] = 0;
1347 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1348 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1350 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1353 setup.player_name[xpos] = 0;
1355 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1357 else if (key == KSYM_Return && xpos > 0)
1359 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1360 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1363 game_status = GAME_MODE_MAIN;
1368 /* ========================================================================= */
1369 /* tree menu functions */
1370 /* ========================================================================= */
1372 static void DrawChooseTree(TreeInfo **ti_ptr)
1376 FreeScreenGadgets();
1377 CreateScreenGadgets();
1379 CloseDoor(DOOR_CLOSE_2);
1383 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1384 MapChooseTreeGadgets(*ti_ptr);
1390 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1392 struct GadgetInfo *gi = screen_gadget[id];
1393 int items_max, items_visible, item_position;
1395 items_max = numTreeInfoInGroup(ti);
1396 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1397 item_position = first_entry;
1399 if (item_position > items_max - items_visible)
1400 item_position = items_max - items_visible;
1402 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1403 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1404 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1407 static void drawChooseTreeList(int first_entry, int num_page_entries,
1411 char buffer[SCR_FIELDX * 2];
1412 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1413 char *title_string = NULL;
1414 int xoffset_setup = 16;
1415 int yoffset_setup = 16;
1416 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1417 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1418 int last_game_status = game_status; /* save current game status */
1421 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1422 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1423 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1424 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1426 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1428 /* force LEVELS font on artwork setup screen */
1429 game_status = GAME_MODE_LEVELS;
1431 /* clear tree list area, but not title or scrollbar */
1432 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1433 SXSIZE - 32 + menu.scrollbar_xoffset,
1434 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1436 for (i = 0; i < num_page_entries; i++)
1438 TreeInfo *node, *node_first;
1439 int entry_pos = first_entry + i;
1440 int ypos = MENU_SCREEN_START_YPOS + i;
1442 node_first = getTreeInfoFirstGroupEntry(ti);
1443 node = getTreeInfoFromPos(node_first, entry_pos);
1445 strncpy(buffer, node->name , max_buffer_len);
1446 buffer[max_buffer_len] = '\0';
1448 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1450 if (node->parent_link)
1451 initCursor(i, IMG_MENU_BUTTON_LEFT);
1452 else if (node->level_group)
1453 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1455 initCursor(i, IMG_MENU_BUTTON);
1458 game_status = last_game_status; /* restore current game status */
1460 redraw_mask |= REDRAW_FIELD;
1463 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1465 TreeInfo *node, *node_first;
1466 int x, last_redraw_mask = redraw_mask;
1468 if (ti->type != TREE_TYPE_LEVEL_DIR)
1471 node_first = getTreeInfoFirstGroupEntry(ti);
1472 node = getTreeInfoFromPos(node_first, entry_pos);
1474 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1476 if (node->parent_link)
1477 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1479 else if (node->level_group)
1480 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1482 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1483 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1484 node->levels, node->class_desc);
1486 /* let BackToFront() redraw only what is needed */
1487 redraw_mask = last_redraw_mask | REDRAW_TILES;
1488 for (x = 0; x < SCR_FIELDX; x++)
1489 MarkTileDirty(x, 1);
1492 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1495 TreeInfo *ti = *ti_ptr;
1497 int y = ti->cl_cursor;
1498 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1499 int num_entries = numTreeInfoInGroup(ti);
1500 int num_page_entries;
1501 int last_game_status = game_status; /* save current game status */
1502 boolean position_set_by_scrollbar = (dx == 999);
1504 /* force LEVELS draw offset on choose level and artwork setup screen */
1505 game_status = GAME_MODE_LEVELS;
1507 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1508 num_page_entries = num_entries;
1510 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1512 game_status = last_game_status; /* restore current game status */
1514 if (button == MB_MENU_INITIALIZE)
1516 int num_entries = numTreeInfoInGroup(ti);
1517 int entry_pos = posTreeInfo(ti);
1519 if (ti->cl_first == -1)
1521 /* only on initialization */
1522 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1523 ti->cl_cursor = entry_pos - ti->cl_first;
1525 else if (ti->cl_cursor >= num_page_entries ||
1526 (num_entries > num_page_entries &&
1527 num_entries - ti->cl_first < num_page_entries))
1529 /* only after change of list size (by custom graphic configuration) */
1530 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1531 ti->cl_cursor = entry_pos - ti->cl_first;
1534 if (position_set_by_scrollbar)
1537 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1540 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1541 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1542 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1546 else if (button == MB_MENU_LEAVE)
1548 if (ti->node_parent)
1550 *ti_ptr = ti->node_parent;
1551 DrawChooseTree(ti_ptr);
1553 else if (game_status == GAME_MODE_SETUP)
1559 game_status = GAME_MODE_MAIN;
1566 if (mx || my) /* mouse input */
1568 int last_game_status = game_status; /* save current game status */
1570 /* force LEVELS draw offset on artwork setup screen */
1571 game_status = GAME_MODE_LEVELS;
1573 x = (mx - mSX) / 32;
1574 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1576 game_status = last_game_status; /* restore current game status */
1578 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1580 /* move cursor instead of scrolling when already at start/end of list */
1581 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1583 else if (dy == +1 * SCROLL_LINE &&
1584 ti->cl_first + num_page_entries == num_entries)
1587 /* handle scrolling screen one line or page */
1588 if (ti->cl_cursor + dy < 0 ||
1589 ti->cl_cursor + dy > num_page_entries - 1)
1591 if (ABS(dy) == SCROLL_PAGE)
1592 step = num_page_entries - 1;
1594 if (dy < 0 && ti->cl_first > 0)
1596 /* scroll page/line up */
1598 ti->cl_first -= step;
1599 if (ti->cl_first < 0)
1602 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1603 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1604 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1605 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1608 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1610 /* scroll page/line down */
1612 ti->cl_first += step;
1613 if (ti->cl_first + num_page_entries > num_entries)
1614 ti->cl_first = MAX(0, num_entries - num_page_entries);
1616 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1617 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1618 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1619 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1626 /* handle moving cursor one line */
1627 y = ti->cl_cursor + dy;
1632 TreeInfo *node_first, *node_cursor;
1633 int entry_pos = ti->cl_first + y;
1635 node_first = getTreeInfoFirstGroupEntry(ti);
1636 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1638 if (node_cursor->node_group)
1640 node_cursor->cl_first = ti->cl_first;
1641 node_cursor->cl_cursor = ti->cl_cursor;
1642 *ti_ptr = node_cursor->node_group;
1643 DrawChooseTree(ti_ptr);
1648 else if (dx == -1 && ti->node_parent)
1650 *ti_ptr = ti->node_parent;
1651 DrawChooseTree(ti_ptr);
1656 if (!anyScrollbarGadgetActive() &&
1657 IN_VIS_FIELD(x, y) &&
1658 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1659 y >= 0 && y < num_page_entries)
1663 if (y != ti->cl_cursor)
1665 drawChooseTreeCursor(y, FC_RED);
1666 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1667 drawChooseTreeInfo(ti->cl_first + y, ti);
1673 TreeInfo *node_first, *node_cursor;
1674 int entry_pos = ti->cl_first + y;
1676 node_first = getTreeInfoFirstGroupEntry(ti);
1677 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1679 if (node_cursor->node_group)
1681 node_cursor->cl_first = ti->cl_first;
1682 node_cursor->cl_cursor = ti->cl_cursor;
1683 *ti_ptr = node_cursor->node_group;
1684 DrawChooseTree(ti_ptr);
1686 else if (node_cursor->parent_link)
1688 *ti_ptr = node_cursor->node_parent;
1689 DrawChooseTree(ti_ptr);
1693 node_cursor->cl_first = ti->cl_first;
1694 node_cursor->cl_cursor = ti->cl_cursor;
1695 *ti_ptr = node_cursor;
1697 if (ti->type == TREE_TYPE_LEVEL_DIR)
1699 LoadLevelSetup_SeriesInfo();
1701 SaveLevelSetup_LastSeries();
1702 SaveLevelSetup_SeriesInfo();
1706 if (game_status == GAME_MODE_SETUP)
1712 game_status = GAME_MODE_MAIN;
1720 void DrawChooseLevel()
1722 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1724 DrawChooseTree(&leveldir_current);
1730 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1732 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1737 void DrawHallOfFame(int highlight_position)
1740 FadeSoundsAndMusic();
1741 CloseDoor(DOOR_CLOSE_2);
1743 if (highlight_position < 0)
1744 LoadScore(level_nr);
1752 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1755 static void drawHallOfFameList(int first_entry, int highlight_position)
1759 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1762 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1763 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1765 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1767 int entry = first_entry + i;
1768 boolean active = (entry == highlight_position);
1769 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1770 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1771 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1772 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1773 int dx1 = 3 * getFontWidth(font_nr1);
1774 int dx2 = dx1 + getFontWidth(font_nr1);
1775 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1776 int sy = mSY + 64 + i * 32;
1778 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1779 DrawText(mSX + dx1, sy, ".", font_nr1);
1780 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1781 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1782 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1783 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1786 redraw_mask |= REDRAW_FIELD;
1789 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1791 static int first_entry = 0;
1792 static int highlight_position = 0;
1793 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1794 int button_released = !button;
1796 if (button == MB_MENU_INITIALIZE)
1799 highlight_position = mx;
1800 drawHallOfFameList(first_entry, highlight_position);
1805 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1806 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1810 if (first_entry > 0)
1812 first_entry -= step;
1813 if (first_entry < 0)
1816 drawHallOfFameList(first_entry, highlight_position);
1821 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1823 first_entry += step;
1824 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1825 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1827 drawHallOfFameList(first_entry, highlight_position);
1830 else if (button_released)
1832 FadeSound(SND_BACKGROUND_SCORES);
1833 game_status = GAME_MODE_MAIN;
1837 if (game_status == GAME_MODE_SCORES)
1838 PlayMenuSoundIfLoop();
1844 /* ========================================================================= */
1845 /* setup screen functions */
1846 /* ========================================================================= */
1848 static struct TokenInfo *setup_info;
1849 static int num_setup_info;
1851 static char *graphics_set_name;
1852 static char *sounds_set_name;
1853 static char *music_set_name;
1855 static void execSetupMain()
1857 setup_mode = SETUP_MODE_MAIN;
1861 static void execSetupGame()
1863 setup_mode = SETUP_MODE_GAME;
1867 static void execSetupEditor()
1869 setup_mode = SETUP_MODE_EDITOR;
1873 static void execSetupGraphics()
1875 setup_mode = SETUP_MODE_GRAPHICS;
1879 static void execSetupSound()
1881 setup_mode = SETUP_MODE_SOUND;
1885 static void execSetupArtwork()
1887 setup.graphics_set = artwork.gfx_current->identifier;
1888 setup.sounds_set = artwork.snd_current->identifier;
1889 setup.music_set = artwork.mus_current->identifier;
1891 /* needed if last screen (setup choice) changed graphics, sounds or music */
1892 ReloadCustomArtwork(0);
1894 /* needed for displaying artwork name instead of artwork identifier */
1895 graphics_set_name = artwork.gfx_current->name;
1896 sounds_set_name = artwork.snd_current->name;
1897 music_set_name = artwork.mus_current->name;
1899 setup_mode = SETUP_MODE_ARTWORK;
1903 static void execSetupChooseGraphics()
1905 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1909 static void execSetupChooseSounds()
1911 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1915 static void execSetupChooseMusic()
1917 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1921 static void execSetupInput()
1923 setup_mode = SETUP_MODE_INPUT;
1927 static void execSetupShortcut()
1929 setup_mode = SETUP_MODE_SHORTCUT;
1933 static void execExitSetup()
1935 game_status = GAME_MODE_MAIN;
1939 static void execSaveAndExitSetup()
1945 static struct TokenInfo setup_info_main[] =
1947 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1948 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1949 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1950 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1951 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1952 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1953 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1954 { TYPE_EMPTY, NULL, "" },
1955 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1956 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1961 static struct TokenInfo setup_info_game[] =
1963 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1964 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1965 { TYPE_SWITCH, &setup.skip_levels, "Skip Levels:" },
1966 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1967 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1968 { TYPE_EMPTY, NULL, "" },
1969 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1974 static struct TokenInfo setup_info_editor[] =
1977 { TYPE_STRING, NULL, "Offer Special Elements:"},
1979 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1980 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1981 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,"E.M. Club:" },
1982 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1983 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1984 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1985 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1986 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1987 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1988 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1989 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1990 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1991 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1992 { TYPE_EMPTY, NULL, "" },
1993 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1998 static struct TokenInfo setup_info_graphics[] =
2000 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2001 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
2002 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
2004 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
2005 { TYPE_SWITCH, &setup.fading, "Fading:" },
2007 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
2008 { TYPE_SWITCH, &setup.toons, "Toons:" },
2009 { TYPE_EMPTY, NULL, "" },
2010 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2015 static struct TokenInfo setup_info_sound[] =
2017 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
2018 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
2019 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
2020 { TYPE_EMPTY, NULL, "" },
2021 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2026 static struct TokenInfo setup_info_artwork[] =
2028 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2029 { TYPE_STRING, &graphics_set_name, "" },
2030 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2031 { TYPE_STRING, &sounds_set_name, "" },
2032 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2033 { TYPE_STRING, &music_set_name, "" },
2034 { TYPE_EMPTY, NULL, "" },
2035 { TYPE_STRING, NULL, "Override Level Artwork:"},
2036 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2037 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2038 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2039 { TYPE_EMPTY, NULL, "" },
2040 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2045 static struct TokenInfo setup_info_shortcut[] =
2047 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2048 { TYPE_KEY, &setup.shortcut.save_game, "" },
2049 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2050 { TYPE_KEY, &setup.shortcut.load_game, "" },
2051 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2052 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2053 { TYPE_EMPTY, NULL, "" },
2054 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2055 { TYPE_EMPTY, NULL, "" },
2056 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2061 static Key getSetupKey()
2063 Key key = KSYM_UNDEFINED;
2064 boolean got_key_event = FALSE;
2066 while (!got_key_event)
2068 if (PendingEvent()) /* got event */
2076 case EVENT_KEYPRESS:
2078 key = GetEventKey((KeyEvent *)&event, TRUE);
2080 /* press 'Escape' or 'Enter' to keep the existing key binding */
2081 if (key == KSYM_Escape || key == KSYM_Return)
2082 key = KSYM_UNDEFINED; /* keep old value */
2084 got_key_event = TRUE;
2088 case EVENT_KEYRELEASE:
2089 key_joystick_mapping = 0;
2093 HandleOtherEvents(&event);
2101 /* don't eat all CPU time */
2108 static void drawSetupValue(int pos)
2110 int xpos = MENU_SCREEN_VALUE_XPOS;
2111 int ypos = MENU_SCREEN_START_YPOS + pos;
2112 int font_nr = FONT_VALUE_1;
2113 int type = setup_info[pos].type;
2114 void *value = setup_info[pos].value;
2115 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2118 if (value_string == NULL)
2121 if (type & TYPE_KEY)
2125 if (type & TYPE_QUERY)
2127 value_string = "<press key>";
2128 font_nr = FONT_INPUT_1_ACTIVE;
2131 else if (type & TYPE_STRING)
2133 int max_value_len = (SCR_FIELDX - 2) * 2;
2136 font_nr = FONT_VALUE_2;
2138 if (strlen(value_string) > max_value_len)
2139 value_string[max_value_len] = '\0';
2141 else if (type & TYPE_BOOLEAN_STYLE)
2143 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2146 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2147 (xpos == 3 ? " " : " "), font_nr);
2148 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2151 static void changeSetupValue(int pos)
2153 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2155 *(boolean *)setup_info[pos].value ^= TRUE;
2157 else if (setup_info[pos].type & TYPE_KEY)
2161 setup_info[pos].type |= TYPE_QUERY;
2162 drawSetupValue(pos);
2163 setup_info[pos].type &= ~TYPE_QUERY;
2165 key = getSetupKey();
2166 if (key != KSYM_UNDEFINED)
2167 *(Key *)setup_info[pos].value = key;
2170 drawSetupValue(pos);
2173 static void DrawSetupScreen_Generic()
2175 char *title_string = NULL;
2179 CloseDoor(DOOR_CLOSE_2);
2183 if (setup_mode == SETUP_MODE_MAIN)
2185 setup_info = setup_info_main;
2186 title_string = "Setup";
2188 else if (setup_mode == SETUP_MODE_GAME)
2190 setup_info = setup_info_game;
2191 title_string = "Setup Game";
2193 else if (setup_mode == SETUP_MODE_EDITOR)
2195 setup_info = setup_info_editor;
2196 title_string = "Setup Editor";
2198 else if (setup_mode == SETUP_MODE_GRAPHICS)
2200 setup_info = setup_info_graphics;
2201 title_string = "Setup Graphics";
2203 else if (setup_mode == SETUP_MODE_SOUND)
2205 setup_info = setup_info_sound;
2206 title_string = "Setup Sound";
2208 else if (setup_mode == SETUP_MODE_ARTWORK)
2210 setup_info = setup_info_artwork;
2211 title_string = "Custom Artwork";
2213 else if (setup_mode == SETUP_MODE_SHORTCUT)
2215 setup_info = setup_info_shortcut;
2216 title_string = "Setup Shortcuts";
2219 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2222 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2224 void *value_ptr = setup_info[i].value;
2225 int ypos = MENU_SCREEN_START_YPOS + i;
2226 int font_nr = FONT_MENU_1;
2228 /* set some entries to "unchangeable" according to other variables */
2229 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2230 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2231 (value_ptr == &setup.sound_music && !audio.music_available) ||
2232 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2233 setup_info[i].type |= TYPE_GHOSTED;
2236 if (setup_info[i].type & TYPE_STRING ||
2237 (setup_info[i].type & TYPE_SWITCH && setup_mode == SETUP_MODE_EDITOR))
2238 font_nr = FONT_MENU_2;
2240 if (setup_info[i].type & TYPE_STRING)
2241 font_nr = FONT_MENU_2;
2244 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2246 if (setup_info[i].type & TYPE_ENTER_MENU)
2247 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2248 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2249 initCursor(i, IMG_MENU_BUTTON_LEFT);
2250 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2251 initCursor(i, IMG_MENU_BUTTON);
2253 if (setup_info[i].type & TYPE_VALUE)
2261 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2264 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2266 static int choice_store[MAX_SETUP_MODES];
2267 int choice = choice_store[setup_mode]; /* always starts with 0 */
2271 if (button == MB_MENU_INITIALIZE)
2273 /* advance to first valid menu entry */
2274 while (choice < num_setup_info &&
2275 setup_info[choice].type & TYPE_SKIP_ENTRY)
2277 choice_store[setup_mode] = choice;
2279 drawCursor(choice, FC_RED);
2282 else if (button == MB_MENU_LEAVE)
2284 for (y = 0; y < num_setup_info; y++)
2286 if (setup_info[y].type & TYPE_LEAVE_MENU)
2288 void (*menu_callback_function)(void) = setup_info[y].value;
2290 menu_callback_function();
2291 break; /* absolutely needed because function changes 'setup_info'! */
2298 if (mx || my) /* mouse input */
2300 x = (mx - mSX) / 32;
2301 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2303 else if (dx || dy) /* keyboard input */
2307 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2309 if (setup_info[choice].type & menu_navigation_type ||
2310 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2311 button = MB_MENU_CHOICE;
2316 /* jump to next non-empty menu entry (up or down) */
2317 while (y > 0 && y < num_setup_info - 1 &&
2318 setup_info[y].type & TYPE_SKIP_ENTRY)
2322 if (IN_VIS_FIELD(x, y) &&
2323 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2329 drawCursor(y, FC_RED);
2330 drawCursor(choice, FC_BLUE);
2331 choice = choice_store[setup_mode] = y;
2334 else if (!(setup_info[y].type & TYPE_GHOSTED))
2336 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2338 void (*menu_callback_function)(void) = setup_info[choice].value;
2340 menu_callback_function();
2344 if (setup_info[y].type & TYPE_KEYTEXT &&
2345 setup_info[y + 1].type & TYPE_KEY)
2348 if (setup_info[y].type & TYPE_VALUE)
2349 changeSetupValue(y);
2355 void DrawSetupScreen_Input()
2359 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2361 initCursor(0, IMG_MENU_BUTTON);
2362 initCursor(1, IMG_MENU_BUTTON);
2363 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2364 initCursor(13, IMG_MENU_BUTTON_LEFT);
2366 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2367 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2369 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2370 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2371 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2374 DeactivateJoystickForCalibration();
2375 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2376 "Joysticks deactivated on this screen");
2379 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2384 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2386 if (device_name == NULL)
2389 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2392 if (strlen(device_name) > 1)
2394 char c1 = device_name[strlen(device_name) - 1];
2395 char c2 = device_name[strlen(device_name) - 2];
2397 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2398 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2401 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2402 strlen(device_name));
2405 static void drawPlayerSetupInputInfo(int player_nr)
2408 static struct SetupKeyboardInfo custom_key;
2415 { &custom_key.left, "Joystick Left" },
2416 { &custom_key.right, "Joystick Right" },
2417 { &custom_key.up, "Joystick Up" },
2418 { &custom_key.down, "Joystick Down" },
2419 { &custom_key.snap, "Button 1" },
2420 { &custom_key.drop, "Button 2" }
2422 static char *joystick_name[MAX_PLAYERS] =
2430 custom_key = setup.input[player_nr].key;
2432 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2434 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2436 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2437 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2439 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2442 if (setup.input[player_nr].use_joystick)
2444 char *device_name = setup.input[player_nr].joy.device_name;
2446 DrawText(mSX+8*32, mSY+3*32,
2447 joystick_name[getJoystickNrFromDeviceName(device_name)],
2449 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2453 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2454 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2457 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2458 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2459 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2460 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2461 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2462 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2463 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2464 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2465 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2466 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2467 DrawText(mSX+32, mSY+12*32, "Drop Element:", FONT_VALUE_OLD);
2469 for (i = 0; i < 6; i++)
2471 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2473 DrawText(mSX + 3*32, mSY + ypos*32,
2475 DrawText(mSX + 3*32, mSY + ypos*32,
2476 (setup.input[player_nr].use_joystick ?
2478 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2482 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2484 static int choice = 0;
2485 static int player_nr = 0;
2488 int pos_start = SETUPINPUT_SCREEN_POS_START;
2489 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2490 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2491 int pos_end = SETUPINPUT_SCREEN_POS_END;
2493 if (button == MB_MENU_INITIALIZE)
2495 drawPlayerSetupInputInfo(player_nr);
2496 drawCursor(choice, FC_RED);
2500 else if (button == MB_MENU_LEAVE)
2502 setup_mode = SETUP_MODE_MAIN;
2509 if (mx || my) /* mouse input */
2511 x = (mx - mSX) / 32;
2512 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2514 else if (dx || dy) /* keyboard input */
2516 if (dx && choice == 0)
2517 x = (dx < 0 ? 10 : 12);
2518 else if ((dx && choice == 1) ||
2519 (dx == +1 && choice == 2) ||
2520 (dx == -1 && choice == pos_end))
2521 button = MB_MENU_CHOICE;
2525 if (y >= pos_empty1 && y <= pos_empty2)
2526 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2529 if (IN_VIS_FIELD(x, y) &&
2530 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2532 static unsigned long delay = 0;
2534 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2537 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2539 drawPlayerSetupInputInfo(player_nr);
2541 else if (IN_VIS_FIELD(x, y) &&
2542 y >= pos_start && y <= pos_end &&
2543 !(y >= pos_empty1 && y <= pos_empty2))
2549 drawCursor(y, FC_RED);
2550 drawCursor(choice, FC_BLUE);
2558 char *device_name = setup.input[player_nr].joy.device_name;
2560 if (!setup.input[player_nr].use_joystick)
2562 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2564 setJoystickDeviceToNr(device_name, new_device_nr);
2565 setup.input[player_nr].use_joystick = TRUE;
2569 int device_nr = getJoystickNrFromDeviceName(device_name);
2570 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2572 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2573 setup.input[player_nr].use_joystick = FALSE;
2575 setJoystickDeviceToNr(device_name, new_device_nr);
2578 drawPlayerSetupInputInfo(player_nr);
2582 if (setup.input[player_nr].use_joystick)
2585 CalibrateJoystick(player_nr);
2588 CustomizeKeyboard(player_nr);
2590 else if (y == pos_end)
2594 setup_mode = SETUP_MODE_MAIN;
2601 void CustomizeKeyboard(int player_nr)
2605 boolean finished = FALSE;
2606 static struct SetupKeyboardInfo custom_key;
2611 } customize_step[] =
2613 { &custom_key.left, "Move Left" },
2614 { &custom_key.right, "Move Right" },
2615 { &custom_key.up, "Move Up" },
2616 { &custom_key.down, "Move Down" },
2617 { &custom_key.snap, "Snap Field" },
2618 { &custom_key.drop, "Drop Element" }
2621 /* read existing key bindings from player setup */
2622 custom_key = setup.input[player_nr].key;
2625 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2631 DrawText(mSX, mSY + (2+2*step_nr)*32,
2632 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2633 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2634 "Key:", FONT_INPUT_1_ACTIVE);
2635 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2636 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2640 if (PendingEvent()) /* got event */
2648 case EVENT_KEYPRESS:
2650 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2652 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2658 /* all keys configured -- wait for "Escape" or "Return" key */
2662 /* press 'Enter' to keep the existing key binding */
2663 if (key == KSYM_Return)
2664 key = *customize_step[step_nr].key;
2666 /* check if key already used */
2667 for (i = 0; i < step_nr; i++)
2668 if (*customize_step[i].key == key)
2673 /* got new key binding */
2674 *customize_step[step_nr].key = key;
2675 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2677 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2678 getKeyNameFromKey(key), FONT_VALUE_1);
2681 /* un-highlight last query */
2682 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2683 customize_step[step_nr-1].text, FONT_MENU_1);
2684 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2685 "Key:", FONT_MENU_1);
2687 /* press 'Enter' to leave */
2690 DrawText(mSX + 16, mSY + 15*32+16,
2691 "Press Enter", FONT_TITLE_1);
2695 /* query next key binding */
2696 DrawText(mSX, mSY+(2+2*step_nr)*32,
2697 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2698 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2699 "Key:", FONT_INPUT_1_ACTIVE);
2700 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2701 getKeyNameFromKey(*customize_step[step_nr].key),
2706 case EVENT_KEYRELEASE:
2707 key_joystick_mapping = 0;
2711 HandleOtherEvents(&event);
2719 /* don't eat all CPU time */
2723 /* write new key bindings back to player setup */
2724 setup.input[player_nr].key = custom_key;
2727 DrawSetupScreen_Input();
2730 static boolean CalibrateJoystickMain(int player_nr)
2732 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2733 int new_joystick_xright = JOYSTICK_XMIDDLE;
2734 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2735 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2736 int new_joystick_xmiddle, new_joystick_ymiddle;
2738 int joystick_fd = joystick.fd[player_nr];
2739 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2740 boolean check[3][3];
2741 int check_remaining = 3 * 3;
2746 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2749 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2754 for (y = 0; y < 3; y++)
2756 for (x = 0; x < 3; x++)
2758 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2759 check[x][y] = FALSE;
2763 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2764 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2765 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2766 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2767 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2768 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2769 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2771 joy_value = Joystick(player_nr);
2772 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2773 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2775 /* eventually uncalibrated center position (joystick could be uncentered) */
2776 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2779 new_joystick_xmiddle = joy_x;
2780 new_joystick_ymiddle = joy_y;
2782 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2785 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2790 if (PendingEvent()) /* got event */
2798 case EVENT_KEYPRESS:
2799 switch(GetEventKey((KeyEvent *)&event, TRUE))
2802 if (check_remaining == 0)
2815 case EVENT_KEYRELEASE:
2816 key_joystick_mapping = 0;
2820 HandleOtherEvents(&event);
2825 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2828 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2829 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2830 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2831 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2833 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2834 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2835 setup.input[player_nr].joy.xright = new_joystick_xright;
2836 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2837 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2838 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2840 CheckJoystickData();
2842 joy_value = Joystick(player_nr);
2844 if (joy_value & JOY_BUTTON && check_remaining == 0)
2847 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2848 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2850 if (x != last_x || y != last_y)
2852 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2853 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2858 if (check_remaining > 0 && !check[x+1][y+1])
2860 check[x+1][y+1] = TRUE;
2866 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2867 setup.input[player_nr].joy.xleft,
2868 setup.input[player_nr].joy.xmiddle,
2869 setup.input[player_nr].joy.xright);
2870 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2871 setup.input[player_nr].joy.yupper,
2872 setup.input[player_nr].joy.ymiddle,
2873 setup.input[player_nr].joy.ylower);
2882 /* don't eat all CPU time */
2886 /* calibrated center position (joystick should now be centered) */
2887 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2890 new_joystick_xmiddle = joy_x;
2891 new_joystick_ymiddle = joy_y;
2895 DrawSetupScreen_Input();
2897 /* wait until the last pressed button was released */
2898 while (Joystick(player_nr) & JOY_BUTTON)
2900 if (PendingEvent()) /* got event */
2905 HandleOtherEvents(&event);
2914 void CalibrateJoystick(int player_nr)
2916 if (!CalibrateJoystickMain(player_nr))
2920 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
2921 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
2923 Delay(2000); /* show error message for two seconds */
2927 void DrawSetupScreen()
2929 DeactivateJoystick();
2931 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2933 if (setup_mode == SETUP_MODE_INPUT)
2934 DrawSetupScreen_Input();
2935 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2936 DrawChooseTree(&artwork.gfx_current);
2937 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2938 DrawChooseTree(&artwork.snd_current);
2939 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2940 DrawChooseTree(&artwork.mus_current);
2942 DrawSetupScreen_Generic();
2948 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2950 if (setup_mode == SETUP_MODE_INPUT)
2951 HandleSetupScreen_Input(mx, my, dx, dy, button);
2952 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2953 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2954 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2955 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2956 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2957 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2959 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2964 void HandleGameActions()
2966 if (game_status != GAME_MODE_PLAYING)
2969 /* !!! FIX THIS (START) !!! */
2970 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2972 byte *recorded_player_action;
2973 byte summarized_player_action = 0;
2974 byte tape_action[MAX_PLAYERS];
2977 if (level.native_em_level->lev->home == 0) /* all players at home */
2981 if (!TAPE_IS_STOPPED(tape))
2984 if (game_status != GAME_MODE_PLAYING)
2988 if (level.native_em_level->ply1->alive == 0 &&
2989 level.native_em_level->ply2->alive == 0) /* all dead */
2990 AllPlayersGone = TRUE;
2992 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2995 /* --- game actions --- */
2999 /* don't use 100% CPU while in pause mode -- this should better be solved
3000 like in the R'n'D game engine! */
3007 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
3010 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
3011 if (recorded_player_action == NULL && tape.pausing)
3015 for (i = 0; i < MAX_PLAYERS; i++)
3017 summarized_player_action |= stored_player[i].action;
3019 if (!network_playing)
3020 stored_player[i].effective_action = stored_player[i].action;
3023 if (!options.network && !setup.team_mode)
3024 local_player->effective_action = summarized_player_action;
3026 if (recorded_player_action != NULL)
3027 for (i = 0; i < MAX_PLAYERS; i++)
3028 stored_player[i].effective_action = recorded_player_action[i];
3030 for (i = 0; i < MAX_PLAYERS; i++)
3032 tape_action[i] = stored_player[i].effective_action;
3034 /* !!! (this does not happen in the EM engine) !!! */
3035 if (tape.recording && tape_action[i] && !tape.player_participates[i])
3036 tape.player_participates[i] = TRUE; /* player just appeared from CE */
3039 /* only save actions from input devices, but not programmed actions */
3041 TapeRecordAction(tape_action);
3043 GameActions_EM(local_player->effective_action);
3045 if (TimeFrames >= FRAMES_PER_SECOND)
3050 if (!level.use_step_counter)
3058 if (TimeLeft <= 10 && setup.time_limit)
3059 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
3061 DrawGameValue_Time(TimeLeft);
3063 if (!TimeLeft && setup.time_limit)
3064 level.native_em_level->lev->killed_out_of_time = TRUE;
3066 else if (level.time == 0 && level.native_em_level->lev->home > 0)
3067 DrawGameValue_Time(TimePlayed);
3069 level.native_em_level->lev->time =
3070 (level.time == 0 ? TimePlayed : TimeLeft);
3073 if (tape.recording || tape.playing)
3074 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
3084 if (local_player->LevelSolved)
3087 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3093 if (tape.auto_play && !tape.playing)
3094 AutoPlayTape(); /* continue automatically playing next tape */
3098 /* ---------- new screen button stuff -------------------------------------- */
3100 /* graphic position and size values for buttons and scrollbars */
3101 #define SC_SCROLLBUTTON_XSIZE TILEX
3102 #define SC_SCROLLBUTTON_YSIZE TILEY
3104 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3105 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3106 SC_SCROLLBUTTON_YSIZE)
3107 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3108 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3109 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3110 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3111 SC_SCROLLBUTTON_YSIZE)
3112 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3113 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3114 SC_SCROLL_VERTICAL_YSIZE)
3116 #define SC_BORDER_SIZE 14
3120 int gfx_unpressed, gfx_pressed;
3124 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3127 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3128 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3129 SCREEN_CTRL_ID_SCROLL_UP,
3133 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3134 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3135 SCREEN_CTRL_ID_SCROLL_DOWN,
3142 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3143 Bitmap **gfx_unpressed, **gfx_pressed;
3145 int gfx_unpressed, gfx_pressed;
3152 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3155 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3156 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3158 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3160 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3161 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3162 GD_TYPE_SCROLLBAR_VERTICAL,
3163 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3164 "scroll level series vertically"
3168 static void CreateScreenScrollbuttons()
3170 struct GadgetInfo *gi;
3171 unsigned long event_mask;
3174 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3176 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3177 int gfx_unpressed, gfx_pressed;
3178 int x, y, width, height;
3179 int gd_x1, gd_x2, gd_y1, gd_y2;
3180 int id = scrollbutton_info[i].gadget_id;
3182 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3184 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3185 y = mSY + scrollbutton_info[i].y;
3186 width = SC_SCROLLBUTTON_XSIZE;
3187 height = SC_SCROLLBUTTON_YSIZE;
3189 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3190 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3191 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3193 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3194 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3195 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3196 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3197 gd_x1 = graphic_info[gfx_unpressed].src_x;
3198 gd_y1 = graphic_info[gfx_unpressed].src_y;
3199 gd_x2 = graphic_info[gfx_pressed].src_x;
3200 gd_y2 = graphic_info[gfx_pressed].src_y;
3202 gi = CreateGadget(GDI_CUSTOM_ID, id,
3203 GDI_CUSTOM_TYPE_ID, i,
3204 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3209 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3210 GDI_STATE, GD_BUTTON_UNPRESSED,
3211 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3212 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3213 GDI_DIRECT_DRAW, FALSE,
3214 GDI_EVENT_MASK, event_mask,
3215 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3219 Error(ERR_EXIT, "cannot create gadget");
3221 screen_gadget[id] = gi;
3225 static void CreateScreenScrollbars()
3229 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3231 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3232 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3233 int gfx_unpressed, gfx_pressed;
3235 int x, y, width, height;
3236 int gd_x1, gd_x2, gd_y1, gd_y2;
3237 struct GadgetInfo *gi;
3238 int items_max, items_visible, item_position;
3239 unsigned long event_mask;
3240 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3241 int id = scrollbar_info[i].gadget_id;
3243 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3245 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3246 y = mSY + scrollbar_info[i].y;
3247 width = scrollbar_info[i].width;
3248 height = scrollbar_info[i].height;
3250 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3251 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3253 items_max = num_page_entries;
3254 items_visible = num_page_entries;
3257 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3258 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3259 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3265 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3266 gfx_pressed = scrollbar_info[i].gfx_pressed;
3267 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3268 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3269 gd_x1 = graphic_info[gfx_unpressed].src_x;
3270 gd_y1 = graphic_info[gfx_unpressed].src_y;
3271 gd_x2 = graphic_info[gfx_pressed].src_x;
3272 gd_y2 = graphic_info[gfx_pressed].src_y;
3275 gi = CreateGadget(GDI_CUSTOM_ID, id,
3276 GDI_CUSTOM_TYPE_ID, i,
3277 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3282 GDI_TYPE, scrollbar_info[i].type,
3283 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3284 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3285 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3286 GDI_STATE, GD_BUTTON_UNPRESSED,
3287 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3288 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3289 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3290 GDI_DIRECT_DRAW, FALSE,
3291 GDI_EVENT_MASK, event_mask,
3292 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3296 Error(ERR_EXIT, "cannot create gadget");
3298 screen_gadget[id] = gi;
3302 void CreateScreenGadgets()
3304 int last_game_status = game_status; /* save current game status */
3306 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3309 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3311 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3313 /* copy pointers to clip mask and GC */
3314 scrollbar_bitmap[i]->clip_mask =
3315 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3316 scrollbar_bitmap[i]->stored_clip_gc =
3317 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3319 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3320 scrollbar_bitmap[i],
3321 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3322 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3323 TILEX, TILEY, 0, 0);
3327 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3328 game_status = GAME_MODE_LEVELS;
3330 CreateScreenScrollbuttons();
3331 CreateScreenScrollbars();
3333 game_status = last_game_status; /* restore current game status */
3336 void FreeScreenGadgets()
3340 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3341 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3343 /* prevent freeing clip mask and GC twice */
3344 scrollbar_bitmap[i]->clip_mask = None;
3345 scrollbar_bitmap[i]->stored_clip_gc = None;
3347 FreeBitmap(scrollbar_bitmap[i]);
3351 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3352 FreeGadget(screen_gadget[i]);
3355 void MapChooseTreeGadgets(TreeInfo *ti)
3357 int num_entries = numTreeInfoInGroup(ti);
3360 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3363 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3364 MapGadget(screen_gadget[i]);
3368 void UnmapChooseTreeGadgets()
3372 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3373 UnmapGadget(screen_gadget[i]);
3377 static void HandleScreenGadgets(struct GadgetInfo *gi)
3379 int id = gi->custom_id;
3381 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3386 case SCREEN_CTRL_ID_SCROLL_UP:
3387 if (game_status == GAME_MODE_LEVELS)
3388 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3389 else if (game_status == GAME_MODE_SETUP)
3390 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3393 case SCREEN_CTRL_ID_SCROLL_DOWN:
3394 if (game_status == GAME_MODE_LEVELS)
3395 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3396 else if (game_status == GAME_MODE_SETUP)
3397 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3400 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3401 if (game_status == GAME_MODE_LEVELS)
3402 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3403 else if (game_status == GAME_MODE_SETUP)
3404 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);