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 int choice = 5;
386 if (button == MB_MENU_INITIALIZE)
388 drawCursor(choice, FC_RED);
392 if (mx || my) /* mouse input */
395 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
397 else if (dx || dy) /* keyboard input */
399 if (dx && choice == 1)
400 x = (dx < 0 ? 10 : 14);
405 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
406 (x == 14 && level_nr < leveldir_current->last_level)) &&
409 static unsigned long level_delay = 0;
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 + 1)
422 new_level_nr = leveldir_current->handicap_level;
424 if (setup.handicap && new_level_nr > leveldir_current->handicap_level &&
425 leveldir_current->handicap_level < leveldir_current->last_level)
427 if (setup.skip_levels &&
428 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
430 leveldir_current->handicap_level++;
431 SaveLevelSetup_SeriesInfo();
434 new_level_nr = leveldir_current->handicap_level;
437 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
438 new_level_nr = leveldir_current->handicap_level;
441 if (new_level_nr != old_level_nr &&
442 DelayReached(&level_delay, GADGET_FRAME_DELAY))
444 level_nr = new_level_nr;
446 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
450 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
454 DrawCompleteVideoDisplay();
456 /* needed because DrawMicroLevel() takes some time */
459 DelayReached(&level_delay, 0); /* reset delay counter */
462 else if (IN_VIS_FIELD(x, y) &&
463 y >= 0 && y <= 7 && (y != 1 || x < 10))
469 drawCursor(y, FC_RED);
470 drawCursor(choice, FC_BLUE);
478 game_status = GAME_MODE_PSEUDO_TYPENAME;
479 HandleTypeName(strlen(setup.player_name), 0);
485 game_status = GAME_MODE_LEVELS;
486 SaveLevelSetup_LastSeries();
487 SaveLevelSetup_SeriesInfo();
498 game_status = GAME_MODE_SCORES;
503 if (leveldir_current->readonly &&
504 strcmp(setup.player_name, "Artsoft") != 0)
505 Request("This level is read only !", REQ_CONFIRM);
506 game_status = GAME_MODE_EDITOR;
511 game_status = GAME_MODE_INFO;
512 info_mode = INFO_MODE_MAIN;
517 if (setup.autorecord)
518 TapeStartRecording();
520 #if defined(NETWORK_AVALIABLE)
522 SendToServer_StartPlaying();
526 game_status = GAME_MODE_PLAYING;
533 game_status = GAME_MODE_SETUP;
534 setup_mode = SETUP_MODE_MAIN;
539 SaveLevelSetup_LastSeries();
540 SaveLevelSetup_SeriesInfo();
541 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
542 game_status = GAME_MODE_QUIT;
547 if (game_status == GAME_MODE_MAIN)
549 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
555 /* ========================================================================= */
556 /* info screen functions */
557 /* ========================================================================= */
559 static struct TokenInfo *info_info;
560 static int num_info_info;
562 static void execInfoElements()
564 info_mode = INFO_MODE_ELEMENTS;
568 static void execInfoMusic()
570 info_mode = INFO_MODE_MUSIC;
574 static void execInfoCredits()
576 info_mode = INFO_MODE_CREDITS;
580 static void execInfoProgram()
582 info_mode = INFO_MODE_PROGRAM;
586 static void execInfoLevelSet()
588 info_mode = INFO_MODE_LEVELSET;
592 static void execExitInfo()
594 game_status = GAME_MODE_MAIN;
598 static struct TokenInfo info_info_main[] =
600 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
601 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
602 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
603 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
604 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
605 { TYPE_EMPTY, NULL, "" },
606 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
611 static void DrawInfoScreen_Main()
616 CloseDoor(DOOR_CLOSE_2);
620 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
622 info_info = info_info_main;
625 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
627 int ypos = MENU_SCREEN_START_YPOS + i;
628 int font_nr = FONT_MENU_1;
630 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
632 if (info_info[i].type & TYPE_ENTER_MENU)
633 initCursor(i, IMG_MENU_BUTTON_RIGHT);
634 else if (info_info[i].type & TYPE_LEAVE_MENU)
635 initCursor(i, IMG_MENU_BUTTON_LEFT);
636 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
637 initCursor(i, IMG_MENU_BUTTON);
648 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
651 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
653 static int choice_store[MAX_INFO_MODES];
654 int choice = choice_store[info_mode]; /* always starts with 0 */
658 if (button == MB_MENU_INITIALIZE)
660 /* advance to first valid menu entry */
661 while (choice < num_info_info &&
662 info_info[choice].type & TYPE_SKIP_ENTRY)
664 choice_store[info_mode] = choice;
666 drawCursor(choice, FC_RED);
669 else if (button == MB_MENU_LEAVE)
671 for (y = 0; y < num_info_info; y++)
673 if (info_info[y].type & TYPE_LEAVE_MENU)
675 void (*menu_callback_function)(void) = info_info[y].value;
677 menu_callback_function();
678 break; /* absolutely needed because function changes 'info_info'! */
685 if (mx || my) /* mouse input */
688 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
690 else if (dx || dy) /* keyboard input */
694 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
696 if (info_info[choice].type & menu_navigation_type ||
697 info_info[choice].type & TYPE_ENTER_SCREEN ||
698 info_info[choice].type & TYPE_BOOLEAN_STYLE)
699 button = MB_MENU_CHOICE;
704 /* jump to next non-empty menu entry (up or down) */
705 while (y > 0 && y < num_info_info - 1 &&
706 info_info[y].type & TYPE_SKIP_ENTRY)
710 if (IN_VIS_FIELD(x, y) &&
711 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
717 drawCursor(y, FC_RED);
718 drawCursor(choice, FC_BLUE);
719 choice = choice_store[info_mode] = y;
722 else if (!(info_info[y].type & TYPE_GHOSTED))
724 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
726 void (*menu_callback_function)(void) = info_info[choice].value;
728 menu_callback_function();
734 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
736 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
737 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
738 int xstart = mSX + 16;
739 int ystart = mSY + 64 + 2 * 32;
740 int ystep = TILEY + 4;
741 int element, action, direction;
749 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
750 infoscreen_step[i] = infoscreen_frame[i] = 0;
752 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
756 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
758 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
759 "Press any key or button for next page");
765 while (helpanim_info[j].element != HELPANIM_LIST_END)
767 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
772 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
781 j += infoscreen_step[i - start];
783 element = helpanim_info[j].element;
784 action = helpanim_info[j].action;
785 direction = helpanim_info[j].direction;
787 if (action != -1 && direction != -1)
788 graphic = el_act_dir2img(element, action, direction);
789 else if (action != -1)
790 graphic = el_act2img(element, action);
791 else if (direction != -1)
792 graphic = el_act2img(element, direction);
794 graphic = el2img(element);
796 delay = helpanim_info[j++].delay;
801 if (infoscreen_frame[i - start] == 0)
804 infoscreen_frame[i - start] = delay - 1;
808 sync_frame = delay - infoscreen_frame[i - start];
809 infoscreen_frame[i - start]--;
812 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
814 if (!infoscreen_frame[i - start])
815 infoscreen_step[i - start] = 0;
819 if (!infoscreen_frame[i - start])
820 infoscreen_step[i - start]++;
821 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
827 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
829 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
830 graphic, sync_frame, USE_MASKING);
833 DrawInfoScreen_HelpText(element, action, direction, i - start);
838 redraw_mask |= REDRAW_FIELD;
843 static char *getHelpText(int element, int action, int direction)
845 char token[MAX_LINE_LEN];
847 strcpy(token, element_info[element].token_name);
850 strcat(token, element_action_info[action].suffix);
853 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
855 return getHashEntry(helptext_info, token);
858 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
861 int font_nr = FONT_TEXT_2;
863 int font_nr = FONT_LEVEL_NUMBER;
865 int font_width = getFontWidth(font_nr);
866 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
867 int sy = mSY + 65 + 2 * 32 + 1;
868 int ystep = TILEY + 4;
870 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
871 int max_lines_per_text = 2;
874 if (action != -1 && direction != -1) /* element.action.direction */
875 text = getHelpText(element, action, direction);
877 if (text == NULL && action != -1) /* element.action */
878 text = getHelpText(element, action, -1);
880 if (text == NULL && direction != -1) /* element.direction */
881 text = getHelpText(element, -1, direction);
883 if (text == NULL) /* base element */
884 text = getHelpText(element, -1, -1);
886 if (text == NULL) /* not found */
887 text = "No description available";
889 if (strlen(text) <= max_chars_per_line) /* only one line of text */
890 sy += getFontHeight(font_nr) / 2;
892 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
893 max_chars_per_line, max_lines_per_text);
896 void DrawInfoScreen_Elements()
901 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
907 void HandleInfoScreen_Elements(int button)
909 static unsigned long info_delay = 0;
910 static int num_anims;
911 static int num_pages;
913 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
914 int button_released = !button;
917 if (button == MB_MENU_INITIALIZE)
919 boolean new_element = TRUE;
922 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
924 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
926 else if (new_element)
933 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
936 else if (button == MB_MENU_LEAVE)
938 info_mode = INFO_MODE_MAIN;
944 if (button_released || button == MB_MENU_INITIALIZE)
946 if (button != MB_MENU_INITIALIZE)
949 if (page >= num_pages)
951 FadeSoundsAndMusic();
953 info_mode = INFO_MODE_MAIN;
959 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
963 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
964 if (page < num_pages)
965 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
967 PlayMenuSoundIfLoop();
971 void DrawInfoScreen_Music()
978 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
981 void HandleInfoScreen_Music(int button)
983 static struct MusicFileInfo *list = NULL;
984 int ystart = 150, dy = 30;
985 int ybottom = SYSIZE - 20;
986 int button_released = !button;
988 if (button == MB_MENU_INITIALIZE)
990 list = music_file_info;
994 FadeSoundsAndMusic();
999 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1001 DrawTextSCentered(ybottom, FONT_TEXT_4,
1002 "Press any key or button for info menu");
1007 else if (button == MB_MENU_LEAVE)
1009 info_mode = INFO_MODE_MAIN;
1015 if (button_released || button == MB_MENU_INITIALIZE)
1019 if (button != MB_MENU_INITIALIZE)
1025 info_mode = INFO_MODE_MAIN;
1031 FadeSoundsAndMusic();
1038 int sound = list->music;
1040 if (sound_info[sound].loop)
1041 PlaySoundLoop(sound);
1045 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1049 PlayMusic(list->music);
1051 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1054 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1056 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1057 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1059 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1062 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1064 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1065 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1067 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1069 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1072 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1074 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1075 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1077 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1079 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1082 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1084 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1085 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1087 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1089 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1092 DrawTextSCentered(ybottom, FONT_TEXT_4,
1093 "Press any key or button for next page");
1096 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1097 PlaySoundLoop(list->music);
1100 void DrawInfoScreen_Credits()
1102 int ystart = 150, ystep = 30;
1103 int ybottom = SYSIZE - 20;
1105 FadeSoundsAndMusic();
1110 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1111 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1112 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1113 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1114 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1115 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1116 "...and many thanks to all contributors");
1117 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1119 DrawTextSCentered(ybottom, FONT_TEXT_4,
1120 "Press any key or button for info menu");
1123 void HandleInfoScreen_Credits(int button)
1125 int button_released = !button;
1127 if (button == MB_MENU_LEAVE)
1129 info_mode = INFO_MODE_MAIN;
1135 if (button_released)
1137 FadeSoundsAndMusic();
1139 info_mode = INFO_MODE_MAIN;
1144 PlayMenuSoundIfLoop();
1148 void DrawInfoScreen_Program()
1150 int ystart = 150, ystep = 30;
1151 int ybottom = SYSIZE - 20;
1156 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1158 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1159 "This game is Freeware!");
1160 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1161 "If you like it, send e-mail to:");
1162 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1163 "info@artsoft.org");
1164 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1165 "or SnailMail to:");
1166 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1168 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1169 "Detmolder Strasse 189");
1170 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1172 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1175 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1176 "If you have created new levels,");
1177 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1178 "send them to me to include them!");
1179 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1182 DrawTextSCentered(ybottom, FONT_TEXT_4,
1183 "Press any key or button for info menu");
1186 void HandleInfoScreen_Program(int button)
1188 int button_released = !button;
1190 if (button == MB_MENU_LEAVE)
1192 info_mode = INFO_MODE_MAIN;
1198 if (button_released)
1200 FadeSoundsAndMusic();
1202 info_mode = INFO_MODE_MAIN;
1207 PlayMenuSoundIfLoop();
1211 void DrawInfoScreen_LevelSet()
1214 int ybottom = SYSIZE - 20;
1215 char *filename = getLevelSetInfoFilename();
1217 int font_nr = FONT_TEXT_2;
1219 int font_nr = FONT_LEVEL_NUMBER;
1221 int font_width = getFontWidth(font_nr);
1222 int font_height = getFontHeight(font_nr);
1225 int sx = SX + pad_x;
1226 int sy = SY + pad_y;
1227 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1228 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1233 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1235 DrawTextSCentered(ybottom, FONT_TEXT_4,
1236 "Press any key or button for info menu");
1238 if (filename != NULL)
1239 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1240 max_lines_per_screen);
1242 DrawTextSCentered(ystart, FONT_TEXT_2,
1243 "No information for this level set.");
1246 void HandleInfoScreen_LevelSet(int button)
1248 int button_released = !button;
1250 if (button == MB_MENU_LEAVE)
1252 info_mode = INFO_MODE_MAIN;
1258 if (button_released)
1260 FadeSoundsAndMusic();
1262 info_mode = INFO_MODE_MAIN;
1267 PlayMenuSoundIfLoop();
1271 void DrawInfoScreen()
1273 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1275 if (info_mode == INFO_MODE_ELEMENTS)
1276 DrawInfoScreen_Elements();
1277 else if (info_mode == INFO_MODE_MUSIC)
1278 DrawInfoScreen_Music();
1279 else if (info_mode == INFO_MODE_CREDITS)
1280 DrawInfoScreen_Credits();
1281 else if (info_mode == INFO_MODE_PROGRAM)
1282 DrawInfoScreen_Program();
1283 else if (info_mode == INFO_MODE_LEVELSET)
1284 DrawInfoScreen_LevelSet();
1286 DrawInfoScreen_Main();
1288 if (info_mode != INFO_MODE_MUSIC)
1295 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1297 if (info_mode == INFO_MODE_ELEMENTS)
1298 HandleInfoScreen_Elements(button);
1299 else if (info_mode == INFO_MODE_MUSIC)
1300 HandleInfoScreen_Music(button);
1301 else if (info_mode == INFO_MODE_CREDITS)
1302 HandleInfoScreen_Credits(button);
1303 else if (info_mode == INFO_MODE_PROGRAM)
1304 HandleInfoScreen_Program(button);
1305 else if (info_mode == INFO_MODE_LEVELSET)
1306 HandleInfoScreen_LevelSet(button);
1308 HandleInfoScreen_Main(mx, my, dx, dy, button);
1314 /* ========================================================================= */
1315 /* type name functions */
1316 /* ========================================================================= */
1318 void HandleTypeName(int newxpos, Key key)
1320 static int xpos = 0, ypos = 2;
1321 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1322 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1323 int startx = mSX + 32 + name_width;
1324 int starty = mSY + ypos * 32;
1330 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1331 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1336 if (((key >= KSYM_A && key <= KSYM_Z) ||
1337 (key >= KSYM_a && key <= KSYM_z)) &&
1338 xpos < MAX_PLAYER_NAME_LEN)
1342 if (key >= KSYM_A && key <= KSYM_Z)
1343 ascii = 'A' + (char)(key - KSYM_A);
1345 ascii = 'a' + (char)(key - KSYM_a);
1347 setup.player_name[xpos] = ascii;
1348 setup.player_name[xpos + 1] = 0;
1351 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1352 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1354 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1357 setup.player_name[xpos] = 0;
1359 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1361 else if (key == KSYM_Return && xpos > 0)
1363 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1364 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1367 game_status = GAME_MODE_MAIN;
1372 /* ========================================================================= */
1373 /* tree menu functions */
1374 /* ========================================================================= */
1376 static void DrawChooseTree(TreeInfo **ti_ptr)
1380 FreeScreenGadgets();
1381 CreateScreenGadgets();
1383 CloseDoor(DOOR_CLOSE_2);
1387 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1388 MapChooseTreeGadgets(*ti_ptr);
1394 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1396 struct GadgetInfo *gi = screen_gadget[id];
1397 int items_max, items_visible, item_position;
1399 items_max = numTreeInfoInGroup(ti);
1400 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1401 item_position = first_entry;
1403 if (item_position > items_max - items_visible)
1404 item_position = items_max - items_visible;
1406 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1407 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1408 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1411 static void drawChooseTreeList(int first_entry, int num_page_entries,
1415 char buffer[SCR_FIELDX * 2];
1416 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1417 char *title_string = NULL;
1418 int xoffset_setup = 16;
1419 int yoffset_setup = 16;
1420 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1421 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1422 int last_game_status = game_status; /* save current game status */
1425 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1426 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1427 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1428 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1430 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1432 /* force LEVELS font on artwork setup screen */
1433 game_status = GAME_MODE_LEVELS;
1435 /* clear tree list area, but not title or scrollbar */
1436 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1437 SXSIZE - 32 + menu.scrollbar_xoffset,
1438 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1440 for (i = 0; i < num_page_entries; i++)
1442 TreeInfo *node, *node_first;
1443 int entry_pos = first_entry + i;
1444 int ypos = MENU_SCREEN_START_YPOS + i;
1446 node_first = getTreeInfoFirstGroupEntry(ti);
1447 node = getTreeInfoFromPos(node_first, entry_pos);
1449 strncpy(buffer, node->name , max_buffer_len);
1450 buffer[max_buffer_len] = '\0';
1452 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1454 if (node->parent_link)
1455 initCursor(i, IMG_MENU_BUTTON_LEFT);
1456 else if (node->level_group)
1457 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1459 initCursor(i, IMG_MENU_BUTTON);
1462 game_status = last_game_status; /* restore current game status */
1464 redraw_mask |= REDRAW_FIELD;
1467 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1469 TreeInfo *node, *node_first;
1470 int x, last_redraw_mask = redraw_mask;
1472 if (ti->type != TREE_TYPE_LEVEL_DIR)
1475 node_first = getTreeInfoFirstGroupEntry(ti);
1476 node = getTreeInfoFromPos(node_first, entry_pos);
1478 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1480 if (node->parent_link)
1481 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1483 else if (node->level_group)
1484 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1486 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1487 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1488 node->levels, node->class_desc);
1490 /* let BackToFront() redraw only what is needed */
1491 redraw_mask = last_redraw_mask | REDRAW_TILES;
1492 for (x = 0; x < SCR_FIELDX; x++)
1493 MarkTileDirty(x, 1);
1496 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1499 TreeInfo *ti = *ti_ptr;
1501 int y = ti->cl_cursor;
1502 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1503 int num_entries = numTreeInfoInGroup(ti);
1504 int num_page_entries;
1505 int last_game_status = game_status; /* save current game status */
1506 boolean position_set_by_scrollbar = (dx == 999);
1508 /* force LEVELS draw offset on choose level and artwork setup screen */
1509 game_status = GAME_MODE_LEVELS;
1511 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1512 num_page_entries = num_entries;
1514 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1516 game_status = last_game_status; /* restore current game status */
1518 if (button == MB_MENU_INITIALIZE)
1520 int num_entries = numTreeInfoInGroup(ti);
1521 int entry_pos = posTreeInfo(ti);
1523 if (ti->cl_first == -1)
1525 /* only on initialization */
1526 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1527 ti->cl_cursor = entry_pos - ti->cl_first;
1529 else if (ti->cl_cursor >= num_page_entries ||
1530 (num_entries > num_page_entries &&
1531 num_entries - ti->cl_first < num_page_entries))
1533 /* only after change of list size (by custom graphic configuration) */
1534 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1535 ti->cl_cursor = entry_pos - ti->cl_first;
1538 if (position_set_by_scrollbar)
1541 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1544 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1545 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1546 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1550 else if (button == MB_MENU_LEAVE)
1552 if (ti->node_parent)
1554 *ti_ptr = ti->node_parent;
1555 DrawChooseTree(ti_ptr);
1557 else if (game_status == GAME_MODE_SETUP)
1563 game_status = GAME_MODE_MAIN;
1570 if (mx || my) /* mouse input */
1572 int last_game_status = game_status; /* save current game status */
1574 /* force LEVELS draw offset on artwork setup screen */
1575 game_status = GAME_MODE_LEVELS;
1577 x = (mx - mSX) / 32;
1578 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1580 game_status = last_game_status; /* restore current game status */
1582 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1584 /* move cursor instead of scrolling when already at start/end of list */
1585 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1587 else if (dy == +1 * SCROLL_LINE &&
1588 ti->cl_first + num_page_entries == num_entries)
1591 /* handle scrolling screen one line or page */
1592 if (ti->cl_cursor + dy < 0 ||
1593 ti->cl_cursor + dy > num_page_entries - 1)
1595 if (ABS(dy) == SCROLL_PAGE)
1596 step = num_page_entries - 1;
1598 if (dy < 0 && ti->cl_first > 0)
1600 /* scroll page/line up */
1602 ti->cl_first -= step;
1603 if (ti->cl_first < 0)
1606 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1607 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1608 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1609 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1612 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1614 /* scroll page/line down */
1616 ti->cl_first += step;
1617 if (ti->cl_first + num_page_entries > num_entries)
1618 ti->cl_first = MAX(0, num_entries - num_page_entries);
1620 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1621 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1622 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1623 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1630 /* handle moving cursor one line */
1631 y = ti->cl_cursor + dy;
1636 TreeInfo *node_first, *node_cursor;
1637 int entry_pos = ti->cl_first + y;
1639 node_first = getTreeInfoFirstGroupEntry(ti);
1640 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1642 if (node_cursor->node_group)
1644 node_cursor->cl_first = ti->cl_first;
1645 node_cursor->cl_cursor = ti->cl_cursor;
1646 *ti_ptr = node_cursor->node_group;
1647 DrawChooseTree(ti_ptr);
1652 else if (dx == -1 && ti->node_parent)
1654 *ti_ptr = ti->node_parent;
1655 DrawChooseTree(ti_ptr);
1660 if (!anyScrollbarGadgetActive() &&
1661 IN_VIS_FIELD(x, y) &&
1662 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1663 y >= 0 && y < num_page_entries)
1667 if (y != ti->cl_cursor)
1669 drawChooseTreeCursor(y, FC_RED);
1670 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1671 drawChooseTreeInfo(ti->cl_first + y, ti);
1677 TreeInfo *node_first, *node_cursor;
1678 int entry_pos = ti->cl_first + y;
1680 node_first = getTreeInfoFirstGroupEntry(ti);
1681 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1683 if (node_cursor->node_group)
1685 node_cursor->cl_first = ti->cl_first;
1686 node_cursor->cl_cursor = ti->cl_cursor;
1687 *ti_ptr = node_cursor->node_group;
1688 DrawChooseTree(ti_ptr);
1690 else if (node_cursor->parent_link)
1692 *ti_ptr = node_cursor->node_parent;
1693 DrawChooseTree(ti_ptr);
1697 node_cursor->cl_first = ti->cl_first;
1698 node_cursor->cl_cursor = ti->cl_cursor;
1699 *ti_ptr = node_cursor;
1701 if (ti->type == TREE_TYPE_LEVEL_DIR)
1703 LoadLevelSetup_SeriesInfo();
1705 SaveLevelSetup_LastSeries();
1706 SaveLevelSetup_SeriesInfo();
1710 if (game_status == GAME_MODE_SETUP)
1716 game_status = GAME_MODE_MAIN;
1724 void DrawChooseLevel()
1726 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1728 DrawChooseTree(&leveldir_current);
1734 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1736 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1741 void DrawHallOfFame(int highlight_position)
1744 FadeSoundsAndMusic();
1745 CloseDoor(DOOR_CLOSE_2);
1747 if (highlight_position < 0)
1748 LoadScore(level_nr);
1756 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1759 static void drawHallOfFameList(int first_entry, int highlight_position)
1763 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1766 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1767 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1769 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1771 int entry = first_entry + i;
1772 boolean active = (entry == highlight_position);
1773 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1774 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1775 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1776 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1777 int dx1 = 3 * getFontWidth(font_nr1);
1778 int dx2 = dx1 + getFontWidth(font_nr1);
1779 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1780 int sy = mSY + 64 + i * 32;
1782 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1783 DrawText(mSX + dx1, sy, ".", font_nr1);
1784 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1785 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1786 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1787 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1790 redraw_mask |= REDRAW_FIELD;
1793 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1795 static int first_entry = 0;
1796 static int highlight_position = 0;
1797 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1798 int button_released = !button;
1800 if (button == MB_MENU_INITIALIZE)
1803 highlight_position = mx;
1804 drawHallOfFameList(first_entry, highlight_position);
1809 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1810 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1814 if (first_entry > 0)
1816 first_entry -= step;
1817 if (first_entry < 0)
1820 drawHallOfFameList(first_entry, highlight_position);
1825 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1827 first_entry += step;
1828 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1829 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1831 drawHallOfFameList(first_entry, highlight_position);
1834 else if (button_released)
1836 FadeSound(SND_BACKGROUND_SCORES);
1837 game_status = GAME_MODE_MAIN;
1841 if (game_status == GAME_MODE_SCORES)
1842 PlayMenuSoundIfLoop();
1848 /* ========================================================================= */
1849 /* setup screen functions */
1850 /* ========================================================================= */
1852 static struct TokenInfo *setup_info;
1853 static int num_setup_info;
1855 static char *graphics_set_name;
1856 static char *sounds_set_name;
1857 static char *music_set_name;
1859 static void execSetupMain()
1861 setup_mode = SETUP_MODE_MAIN;
1865 static void execSetupGame()
1867 setup_mode = SETUP_MODE_GAME;
1871 static void execSetupEditor()
1873 setup_mode = SETUP_MODE_EDITOR;
1877 static void execSetupGraphics()
1879 setup_mode = SETUP_MODE_GRAPHICS;
1883 static void execSetupSound()
1885 setup_mode = SETUP_MODE_SOUND;
1889 static void execSetupArtwork()
1891 setup.graphics_set = artwork.gfx_current->identifier;
1892 setup.sounds_set = artwork.snd_current->identifier;
1893 setup.music_set = artwork.mus_current->identifier;
1895 /* needed if last screen (setup choice) changed graphics, sounds or music */
1896 ReloadCustomArtwork(0);
1898 /* needed for displaying artwork name instead of artwork identifier */
1899 graphics_set_name = artwork.gfx_current->name;
1900 sounds_set_name = artwork.snd_current->name;
1901 music_set_name = artwork.mus_current->name;
1903 setup_mode = SETUP_MODE_ARTWORK;
1907 static void execSetupChooseGraphics()
1909 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1913 static void execSetupChooseSounds()
1915 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1919 static void execSetupChooseMusic()
1921 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1925 static void execSetupInput()
1927 setup_mode = SETUP_MODE_INPUT;
1931 static void execSetupShortcut()
1933 setup_mode = SETUP_MODE_SHORTCUT;
1937 static void execExitSetup()
1939 game_status = GAME_MODE_MAIN;
1943 static void execSaveAndExitSetup()
1949 static struct TokenInfo setup_info_main[] =
1951 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1952 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1953 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1954 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1955 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1956 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1957 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1958 { TYPE_EMPTY, NULL, "" },
1959 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1960 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1965 static struct TokenInfo setup_info_game[] =
1967 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1968 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1969 { TYPE_SWITCH, &setup.skip_levels, "Skip Levels:" },
1970 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1971 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1972 { TYPE_EMPTY, NULL, "" },
1973 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1978 static struct TokenInfo setup_info_editor[] =
1981 { TYPE_STRING, NULL, "Offer Special Elements:"},
1983 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1984 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1985 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,"E.M. Club:" },
1986 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1987 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1988 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1989 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1990 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1991 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1992 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1993 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1994 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1995 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1996 { TYPE_EMPTY, NULL, "" },
1997 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2002 static struct TokenInfo setup_info_graphics[] =
2004 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2005 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
2006 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
2008 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
2009 { TYPE_SWITCH, &setup.fading, "Fading:" },
2011 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
2012 { TYPE_SWITCH, &setup.toons, "Toons:" },
2013 { TYPE_EMPTY, NULL, "" },
2014 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2019 static struct TokenInfo setup_info_sound[] =
2021 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
2022 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
2023 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
2024 { TYPE_EMPTY, NULL, "" },
2025 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2030 static struct TokenInfo setup_info_artwork[] =
2032 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2033 { TYPE_STRING, &graphics_set_name, "" },
2034 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2035 { TYPE_STRING, &sounds_set_name, "" },
2036 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2037 { TYPE_STRING, &music_set_name, "" },
2038 { TYPE_EMPTY, NULL, "" },
2039 { TYPE_STRING, NULL, "Override Level Artwork:"},
2040 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2041 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2042 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2043 { TYPE_EMPTY, NULL, "" },
2044 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2049 static struct TokenInfo setup_info_shortcut[] =
2051 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2052 { TYPE_KEY, &setup.shortcut.save_game, "" },
2053 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2054 { TYPE_KEY, &setup.shortcut.load_game, "" },
2055 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2056 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2057 { TYPE_EMPTY, NULL, "" },
2058 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2059 { TYPE_EMPTY, NULL, "" },
2060 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2065 static Key getSetupKey()
2067 Key key = KSYM_UNDEFINED;
2068 boolean got_key_event = FALSE;
2070 while (!got_key_event)
2072 if (PendingEvent()) /* got event */
2080 case EVENT_KEYPRESS:
2082 key = GetEventKey((KeyEvent *)&event, TRUE);
2084 /* press 'Escape' or 'Enter' to keep the existing key binding */
2085 if (key == KSYM_Escape || key == KSYM_Return)
2086 key = KSYM_UNDEFINED; /* keep old value */
2088 got_key_event = TRUE;
2092 case EVENT_KEYRELEASE:
2093 key_joystick_mapping = 0;
2097 HandleOtherEvents(&event);
2105 /* don't eat all CPU time */
2112 static void drawSetupValue(int pos)
2114 int xpos = MENU_SCREEN_VALUE_XPOS;
2115 int ypos = MENU_SCREEN_START_YPOS + pos;
2116 int font_nr = FONT_VALUE_1;
2117 int type = setup_info[pos].type;
2118 void *value = setup_info[pos].value;
2119 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2122 if (value_string == NULL)
2125 if (type & TYPE_KEY)
2129 if (type & TYPE_QUERY)
2131 value_string = "<press key>";
2132 font_nr = FONT_INPUT_1_ACTIVE;
2135 else if (type & TYPE_STRING)
2137 int max_value_len = (SCR_FIELDX - 2) * 2;
2140 font_nr = FONT_VALUE_2;
2142 if (strlen(value_string) > max_value_len)
2143 value_string[max_value_len] = '\0';
2145 else if (type & TYPE_BOOLEAN_STYLE)
2147 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2150 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2151 (xpos == 3 ? " " : " "), font_nr);
2152 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2155 static void changeSetupValue(int pos)
2157 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2159 *(boolean *)setup_info[pos].value ^= TRUE;
2161 else if (setup_info[pos].type & TYPE_KEY)
2165 setup_info[pos].type |= TYPE_QUERY;
2166 drawSetupValue(pos);
2167 setup_info[pos].type &= ~TYPE_QUERY;
2169 key = getSetupKey();
2170 if (key != KSYM_UNDEFINED)
2171 *(Key *)setup_info[pos].value = key;
2174 drawSetupValue(pos);
2177 static void DrawSetupScreen_Generic()
2179 char *title_string = NULL;
2183 CloseDoor(DOOR_CLOSE_2);
2187 if (setup_mode == SETUP_MODE_MAIN)
2189 setup_info = setup_info_main;
2190 title_string = "Setup";
2192 else if (setup_mode == SETUP_MODE_GAME)
2194 setup_info = setup_info_game;
2195 title_string = "Setup Game";
2197 else if (setup_mode == SETUP_MODE_EDITOR)
2199 setup_info = setup_info_editor;
2200 title_string = "Setup Editor";
2202 else if (setup_mode == SETUP_MODE_GRAPHICS)
2204 setup_info = setup_info_graphics;
2205 title_string = "Setup Graphics";
2207 else if (setup_mode == SETUP_MODE_SOUND)
2209 setup_info = setup_info_sound;
2210 title_string = "Setup Sound";
2212 else if (setup_mode == SETUP_MODE_ARTWORK)
2214 setup_info = setup_info_artwork;
2215 title_string = "Custom Artwork";
2217 else if (setup_mode == SETUP_MODE_SHORTCUT)
2219 setup_info = setup_info_shortcut;
2220 title_string = "Setup Shortcuts";
2223 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2226 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2228 void *value_ptr = setup_info[i].value;
2229 int ypos = MENU_SCREEN_START_YPOS + i;
2230 int font_nr = FONT_MENU_1;
2232 /* set some entries to "unchangeable" according to other variables */
2233 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2234 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2235 (value_ptr == &setup.sound_music && !audio.music_available) ||
2236 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2237 setup_info[i].type |= TYPE_GHOSTED;
2240 if (setup_info[i].type & TYPE_STRING ||
2241 (setup_info[i].type & TYPE_SWITCH && setup_mode == SETUP_MODE_EDITOR))
2242 font_nr = FONT_MENU_2;
2244 if (setup_info[i].type & TYPE_STRING)
2245 font_nr = FONT_MENU_2;
2248 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2250 if (setup_info[i].type & TYPE_ENTER_MENU)
2251 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2252 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2253 initCursor(i, IMG_MENU_BUTTON_LEFT);
2254 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2255 initCursor(i, IMG_MENU_BUTTON);
2257 if (setup_info[i].type & TYPE_VALUE)
2265 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2268 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2270 static int choice_store[MAX_SETUP_MODES];
2271 int choice = choice_store[setup_mode]; /* always starts with 0 */
2275 if (button == MB_MENU_INITIALIZE)
2277 /* advance to first valid menu entry */
2278 while (choice < num_setup_info &&
2279 setup_info[choice].type & TYPE_SKIP_ENTRY)
2281 choice_store[setup_mode] = choice;
2283 drawCursor(choice, FC_RED);
2286 else if (button == MB_MENU_LEAVE)
2288 for (y = 0; y < num_setup_info; y++)
2290 if (setup_info[y].type & TYPE_LEAVE_MENU)
2292 void (*menu_callback_function)(void) = setup_info[y].value;
2294 menu_callback_function();
2295 break; /* absolutely needed because function changes 'setup_info'! */
2302 if (mx || my) /* mouse input */
2304 x = (mx - mSX) / 32;
2305 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2307 else if (dx || dy) /* keyboard input */
2311 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2313 if (setup_info[choice].type & menu_navigation_type ||
2314 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2315 button = MB_MENU_CHOICE;
2320 /* jump to next non-empty menu entry (up or down) */
2321 while (y > 0 && y < num_setup_info - 1 &&
2322 setup_info[y].type & TYPE_SKIP_ENTRY)
2326 if (IN_VIS_FIELD(x, y) &&
2327 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2333 drawCursor(y, FC_RED);
2334 drawCursor(choice, FC_BLUE);
2335 choice = choice_store[setup_mode] = y;
2338 else if (!(setup_info[y].type & TYPE_GHOSTED))
2340 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2342 void (*menu_callback_function)(void) = setup_info[choice].value;
2344 menu_callback_function();
2348 if (setup_info[y].type & TYPE_KEYTEXT &&
2349 setup_info[y + 1].type & TYPE_KEY)
2352 if (setup_info[y].type & TYPE_VALUE)
2353 changeSetupValue(y);
2359 void DrawSetupScreen_Input()
2363 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2365 initCursor(0, IMG_MENU_BUTTON);
2366 initCursor(1, IMG_MENU_BUTTON);
2367 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2368 initCursor(13, IMG_MENU_BUTTON_LEFT);
2370 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2371 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2373 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2374 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2375 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2378 DeactivateJoystickForCalibration();
2379 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2380 "Joysticks deactivated on this screen");
2383 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2388 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2390 if (device_name == NULL)
2393 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2396 if (strlen(device_name) > 1)
2398 char c1 = device_name[strlen(device_name) - 1];
2399 char c2 = device_name[strlen(device_name) - 2];
2401 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2402 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2405 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2406 strlen(device_name));
2409 static void drawPlayerSetupInputInfo(int player_nr)
2412 static struct SetupKeyboardInfo custom_key;
2419 { &custom_key.left, "Joystick Left" },
2420 { &custom_key.right, "Joystick Right" },
2421 { &custom_key.up, "Joystick Up" },
2422 { &custom_key.down, "Joystick Down" },
2423 { &custom_key.snap, "Button 1" },
2424 { &custom_key.drop, "Button 2" }
2426 static char *joystick_name[MAX_PLAYERS] =
2434 custom_key = setup.input[player_nr].key;
2436 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2438 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2440 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2441 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2443 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2446 if (setup.input[player_nr].use_joystick)
2448 char *device_name = setup.input[player_nr].joy.device_name;
2450 DrawText(mSX+8*32, mSY+3*32,
2451 joystick_name[getJoystickNrFromDeviceName(device_name)],
2453 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2457 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2458 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2461 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2462 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2463 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2464 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2465 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2466 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2467 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2468 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2469 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2470 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2471 DrawText(mSX+32, mSY+12*32, "Drop Element:", FONT_VALUE_OLD);
2473 for (i = 0; i < 6; i++)
2475 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2477 DrawText(mSX + 3*32, mSY + ypos*32,
2479 DrawText(mSX + 3*32, mSY + ypos*32,
2480 (setup.input[player_nr].use_joystick ?
2482 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2486 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2488 static int choice = 0;
2489 static int player_nr = 0;
2492 int pos_start = SETUPINPUT_SCREEN_POS_START;
2493 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2494 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2495 int pos_end = SETUPINPUT_SCREEN_POS_END;
2497 if (button == MB_MENU_INITIALIZE)
2499 drawPlayerSetupInputInfo(player_nr);
2500 drawCursor(choice, FC_RED);
2504 else if (button == MB_MENU_LEAVE)
2506 setup_mode = SETUP_MODE_MAIN;
2513 if (mx || my) /* mouse input */
2515 x = (mx - mSX) / 32;
2516 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2518 else if (dx || dy) /* keyboard input */
2520 if (dx && choice == 0)
2521 x = (dx < 0 ? 10 : 12);
2522 else if ((dx && choice == 1) ||
2523 (dx == +1 && choice == 2) ||
2524 (dx == -1 && choice == pos_end))
2525 button = MB_MENU_CHOICE;
2529 if (y >= pos_empty1 && y <= pos_empty2)
2530 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2533 if (IN_VIS_FIELD(x, y) &&
2534 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2536 static unsigned long delay = 0;
2538 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2541 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2543 drawPlayerSetupInputInfo(player_nr);
2545 else if (IN_VIS_FIELD(x, y) &&
2546 y >= pos_start && y <= pos_end &&
2547 !(y >= pos_empty1 && y <= pos_empty2))
2553 drawCursor(y, FC_RED);
2554 drawCursor(choice, FC_BLUE);
2562 char *device_name = setup.input[player_nr].joy.device_name;
2564 if (!setup.input[player_nr].use_joystick)
2566 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2568 setJoystickDeviceToNr(device_name, new_device_nr);
2569 setup.input[player_nr].use_joystick = TRUE;
2573 int device_nr = getJoystickNrFromDeviceName(device_name);
2574 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2576 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2577 setup.input[player_nr].use_joystick = FALSE;
2579 setJoystickDeviceToNr(device_name, new_device_nr);
2582 drawPlayerSetupInputInfo(player_nr);
2586 if (setup.input[player_nr].use_joystick)
2589 CalibrateJoystick(player_nr);
2592 CustomizeKeyboard(player_nr);
2594 else if (y == pos_end)
2598 setup_mode = SETUP_MODE_MAIN;
2605 void CustomizeKeyboard(int player_nr)
2609 boolean finished = FALSE;
2610 static struct SetupKeyboardInfo custom_key;
2615 } customize_step[] =
2617 { &custom_key.left, "Move Left" },
2618 { &custom_key.right, "Move Right" },
2619 { &custom_key.up, "Move Up" },
2620 { &custom_key.down, "Move Down" },
2621 { &custom_key.snap, "Snap Field" },
2622 { &custom_key.drop, "Drop Element" }
2625 /* read existing key bindings from player setup */
2626 custom_key = setup.input[player_nr].key;
2629 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2635 DrawText(mSX, mSY + (2+2*step_nr)*32,
2636 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2637 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2638 "Key:", FONT_INPUT_1_ACTIVE);
2639 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2640 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2644 if (PendingEvent()) /* got event */
2652 case EVENT_KEYPRESS:
2654 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2656 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2662 /* all keys configured -- wait for "Escape" or "Return" key */
2666 /* press 'Enter' to keep the existing key binding */
2667 if (key == KSYM_Return)
2668 key = *customize_step[step_nr].key;
2670 /* check if key already used */
2671 for (i = 0; i < step_nr; i++)
2672 if (*customize_step[i].key == key)
2677 /* got new key binding */
2678 *customize_step[step_nr].key = key;
2679 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2681 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2682 getKeyNameFromKey(key), FONT_VALUE_1);
2685 /* un-highlight last query */
2686 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2687 customize_step[step_nr-1].text, FONT_MENU_1);
2688 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2689 "Key:", FONT_MENU_1);
2691 /* press 'Enter' to leave */
2694 DrawText(mSX + 16, mSY + 15*32+16,
2695 "Press Enter", FONT_TITLE_1);
2699 /* query next key binding */
2700 DrawText(mSX, mSY+(2+2*step_nr)*32,
2701 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2702 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2703 "Key:", FONT_INPUT_1_ACTIVE);
2704 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2705 getKeyNameFromKey(*customize_step[step_nr].key),
2710 case EVENT_KEYRELEASE:
2711 key_joystick_mapping = 0;
2715 HandleOtherEvents(&event);
2723 /* don't eat all CPU time */
2727 /* write new key bindings back to player setup */
2728 setup.input[player_nr].key = custom_key;
2731 DrawSetupScreen_Input();
2734 static boolean CalibrateJoystickMain(int player_nr)
2736 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2737 int new_joystick_xright = JOYSTICK_XMIDDLE;
2738 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2739 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2740 int new_joystick_xmiddle, new_joystick_ymiddle;
2742 int joystick_fd = joystick.fd[player_nr];
2743 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2744 boolean check[3][3];
2745 int check_remaining = 3 * 3;
2750 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2753 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2758 for (y = 0; y < 3; y++)
2760 for (x = 0; x < 3; x++)
2762 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2763 check[x][y] = FALSE;
2767 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2768 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2769 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2770 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2771 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2772 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2773 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2775 joy_value = Joystick(player_nr);
2776 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2777 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2779 /* eventually uncalibrated center position (joystick could be uncentered) */
2780 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2783 new_joystick_xmiddle = joy_x;
2784 new_joystick_ymiddle = joy_y;
2786 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2789 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2794 if (PendingEvent()) /* got event */
2802 case EVENT_KEYPRESS:
2803 switch(GetEventKey((KeyEvent *)&event, TRUE))
2806 if (check_remaining == 0)
2819 case EVENT_KEYRELEASE:
2820 key_joystick_mapping = 0;
2824 HandleOtherEvents(&event);
2829 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2832 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2833 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2834 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2835 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2837 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2838 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2839 setup.input[player_nr].joy.xright = new_joystick_xright;
2840 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2841 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2842 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2844 CheckJoystickData();
2846 joy_value = Joystick(player_nr);
2848 if (joy_value & JOY_BUTTON && check_remaining == 0)
2851 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2852 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2854 if (x != last_x || y != last_y)
2856 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2857 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2862 if (check_remaining > 0 && !check[x+1][y+1])
2864 check[x+1][y+1] = TRUE;
2870 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2871 setup.input[player_nr].joy.xleft,
2872 setup.input[player_nr].joy.xmiddle,
2873 setup.input[player_nr].joy.xright);
2874 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2875 setup.input[player_nr].joy.yupper,
2876 setup.input[player_nr].joy.ymiddle,
2877 setup.input[player_nr].joy.ylower);
2886 /* don't eat all CPU time */
2890 /* calibrated center position (joystick should now be centered) */
2891 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2894 new_joystick_xmiddle = joy_x;
2895 new_joystick_ymiddle = joy_y;
2899 DrawSetupScreen_Input();
2901 /* wait until the last pressed button was released */
2902 while (Joystick(player_nr) & JOY_BUTTON)
2904 if (PendingEvent()) /* got event */
2909 HandleOtherEvents(&event);
2918 void CalibrateJoystick(int player_nr)
2920 if (!CalibrateJoystickMain(player_nr))
2924 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
2925 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
2927 Delay(2000); /* show error message for two seconds */
2931 void DrawSetupScreen()
2933 DeactivateJoystick();
2935 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2937 if (setup_mode == SETUP_MODE_INPUT)
2938 DrawSetupScreen_Input();
2939 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2940 DrawChooseTree(&artwork.gfx_current);
2941 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2942 DrawChooseTree(&artwork.snd_current);
2943 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2944 DrawChooseTree(&artwork.mus_current);
2946 DrawSetupScreen_Generic();
2952 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2954 if (setup_mode == SETUP_MODE_INPUT)
2955 HandleSetupScreen_Input(mx, my, dx, dy, button);
2956 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2957 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2958 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2959 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2960 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2961 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2963 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2968 void HandleGameActions()
2970 if (game_status != GAME_MODE_PLAYING)
2973 /* !!! FIX THIS (START) !!! */
2974 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2976 byte *recorded_player_action;
2977 byte summarized_player_action = 0;
2978 byte tape_action[MAX_PLAYERS];
2981 if (level.native_em_level->lev->home == 0) /* all players at home */
2985 if (!TAPE_IS_STOPPED(tape))
2988 if (game_status != GAME_MODE_PLAYING)
2992 if (level.native_em_level->ply1->alive == 0 &&
2993 level.native_em_level->ply2->alive == 0) /* all dead */
2994 AllPlayersGone = TRUE;
2996 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2999 /* --- game actions --- */
3003 /* don't use 100% CPU while in pause mode -- this should better be solved
3004 like in the R'n'D game engine! */
3011 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
3014 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
3015 if (recorded_player_action == NULL && tape.pausing)
3019 for (i = 0; i < MAX_PLAYERS; i++)
3021 summarized_player_action |= stored_player[i].action;
3023 if (!network_playing)
3024 stored_player[i].effective_action = stored_player[i].action;
3027 if (!options.network && !setup.team_mode)
3028 local_player->effective_action = summarized_player_action;
3030 if (recorded_player_action != NULL)
3031 for (i = 0; i < MAX_PLAYERS; i++)
3032 stored_player[i].effective_action = recorded_player_action[i];
3034 for (i = 0; i < MAX_PLAYERS; i++)
3036 tape_action[i] = stored_player[i].effective_action;
3038 /* !!! (this does not happen in the EM engine) !!! */
3039 if (tape.recording && tape_action[i] && !tape.player_participates[i])
3040 tape.player_participates[i] = TRUE; /* player just appeared from CE */
3043 /* only save actions from input devices, but not programmed actions */
3045 TapeRecordAction(tape_action);
3047 GameActions_EM(local_player->effective_action);
3049 if (TimeFrames >= FRAMES_PER_SECOND)
3054 if (!level.use_step_counter)
3062 if (TimeLeft <= 10 && setup.time_limit)
3063 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
3065 DrawGameValue_Time(TimeLeft);
3067 if (!TimeLeft && setup.time_limit)
3068 level.native_em_level->lev->killed_out_of_time = TRUE;
3070 else if (level.time == 0 && level.native_em_level->lev->home > 0)
3071 DrawGameValue_Time(TimePlayed);
3073 level.native_em_level->lev->time =
3074 (level.time == 0 ? TimePlayed : TimeLeft);
3077 if (tape.recording || tape.playing)
3078 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
3088 if (local_player->LevelSolved)
3091 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3097 if (tape.auto_play && !tape.playing)
3098 AutoPlayTape(); /* continue automatically playing next tape */
3102 /* ---------- new screen button stuff -------------------------------------- */
3104 /* graphic position and size values for buttons and scrollbars */
3105 #define SC_SCROLLBUTTON_XSIZE TILEX
3106 #define SC_SCROLLBUTTON_YSIZE TILEY
3108 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3109 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3110 SC_SCROLLBUTTON_YSIZE)
3111 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3112 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3113 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3114 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3115 SC_SCROLLBUTTON_YSIZE)
3116 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3117 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3118 SC_SCROLL_VERTICAL_YSIZE)
3120 #define SC_BORDER_SIZE 14
3124 int gfx_unpressed, gfx_pressed;
3128 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3131 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3132 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3133 SCREEN_CTRL_ID_SCROLL_UP,
3137 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3138 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3139 SCREEN_CTRL_ID_SCROLL_DOWN,
3146 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3147 Bitmap **gfx_unpressed, **gfx_pressed;
3149 int gfx_unpressed, gfx_pressed;
3156 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3159 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3160 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3162 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3164 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3165 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3166 GD_TYPE_SCROLLBAR_VERTICAL,
3167 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3168 "scroll level series vertically"
3172 static void CreateScreenScrollbuttons()
3174 struct GadgetInfo *gi;
3175 unsigned long event_mask;
3178 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3180 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3181 int gfx_unpressed, gfx_pressed;
3182 int x, y, width, height;
3183 int gd_x1, gd_x2, gd_y1, gd_y2;
3184 int id = scrollbutton_info[i].gadget_id;
3186 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3188 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3189 y = mSY + scrollbutton_info[i].y;
3190 width = SC_SCROLLBUTTON_XSIZE;
3191 height = SC_SCROLLBUTTON_YSIZE;
3193 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3194 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3195 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3197 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3198 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3199 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3200 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3201 gd_x1 = graphic_info[gfx_unpressed].src_x;
3202 gd_y1 = graphic_info[gfx_unpressed].src_y;
3203 gd_x2 = graphic_info[gfx_pressed].src_x;
3204 gd_y2 = graphic_info[gfx_pressed].src_y;
3206 gi = CreateGadget(GDI_CUSTOM_ID, id,
3207 GDI_CUSTOM_TYPE_ID, i,
3208 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3213 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3214 GDI_STATE, GD_BUTTON_UNPRESSED,
3215 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3216 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3217 GDI_DIRECT_DRAW, FALSE,
3218 GDI_EVENT_MASK, event_mask,
3219 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3223 Error(ERR_EXIT, "cannot create gadget");
3225 screen_gadget[id] = gi;
3229 static void CreateScreenScrollbars()
3233 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3235 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3236 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3237 int gfx_unpressed, gfx_pressed;
3239 int x, y, width, height;
3240 int gd_x1, gd_x2, gd_y1, gd_y2;
3241 struct GadgetInfo *gi;
3242 int items_max, items_visible, item_position;
3243 unsigned long event_mask;
3244 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3245 int id = scrollbar_info[i].gadget_id;
3247 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3249 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3250 y = mSY + scrollbar_info[i].y;
3251 width = scrollbar_info[i].width;
3252 height = scrollbar_info[i].height;
3254 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3255 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3257 items_max = num_page_entries;
3258 items_visible = num_page_entries;
3261 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3262 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3263 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3269 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3270 gfx_pressed = scrollbar_info[i].gfx_pressed;
3271 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3272 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3273 gd_x1 = graphic_info[gfx_unpressed].src_x;
3274 gd_y1 = graphic_info[gfx_unpressed].src_y;
3275 gd_x2 = graphic_info[gfx_pressed].src_x;
3276 gd_y2 = graphic_info[gfx_pressed].src_y;
3279 gi = CreateGadget(GDI_CUSTOM_ID, id,
3280 GDI_CUSTOM_TYPE_ID, i,
3281 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3286 GDI_TYPE, scrollbar_info[i].type,
3287 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3288 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3289 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3290 GDI_STATE, GD_BUTTON_UNPRESSED,
3291 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3292 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3293 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3294 GDI_DIRECT_DRAW, FALSE,
3295 GDI_EVENT_MASK, event_mask,
3296 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3300 Error(ERR_EXIT, "cannot create gadget");
3302 screen_gadget[id] = gi;
3306 void CreateScreenGadgets()
3308 int last_game_status = game_status; /* save current game status */
3310 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3313 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3315 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3317 /* copy pointers to clip mask and GC */
3318 scrollbar_bitmap[i]->clip_mask =
3319 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3320 scrollbar_bitmap[i]->stored_clip_gc =
3321 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3323 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3324 scrollbar_bitmap[i],
3325 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3326 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3327 TILEX, TILEY, 0, 0);
3331 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3332 game_status = GAME_MODE_LEVELS;
3334 CreateScreenScrollbuttons();
3335 CreateScreenScrollbars();
3337 game_status = last_game_status; /* restore current game status */
3340 void FreeScreenGadgets()
3344 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3345 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3347 /* prevent freeing clip mask and GC twice */
3348 scrollbar_bitmap[i]->clip_mask = None;
3349 scrollbar_bitmap[i]->stored_clip_gc = None;
3351 FreeBitmap(scrollbar_bitmap[i]);
3355 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3356 FreeGadget(screen_gadget[i]);
3359 void MapChooseTreeGadgets(TreeInfo *ti)
3361 int num_entries = numTreeInfoInGroup(ti);
3364 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3367 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3368 MapGadget(screen_gadget[i]);
3372 void UnmapChooseTreeGadgets()
3376 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3377 UnmapGadget(screen_gadget[i]);
3381 static void HandleScreenGadgets(struct GadgetInfo *gi)
3383 int id = gi->custom_id;
3385 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3390 case SCREEN_CTRL_ID_SCROLL_UP:
3391 if (game_status == GAME_MODE_LEVELS)
3392 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3393 else if (game_status == GAME_MODE_SETUP)
3394 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3397 case SCREEN_CTRL_ID_SCROLL_DOWN:
3398 if (game_status == GAME_MODE_LEVELS)
3399 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3400 else if (game_status == GAME_MODE_SETUP)
3401 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3404 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3405 if (game_status == GAME_MODE_LEVELS)
3406 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3407 else if (game_status == GAME_MODE_SETUP)
3408 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);