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 int text1_width = getTextWidth(PROGRAM_TITLE_STRING, FONT_TITLE_1);
205 int text2_width = getTextWidth(PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2);
206 int x1 = SX + (SXSIZE - text1_width) / 2;
207 int x2 = SX + (SXSIZE - text2_width) / 2;
209 DrawText(x1, SY + 8, PROGRAM_TITLE_STRING, FONT_TITLE_1);
210 DrawText(x2, SY + 46, PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2);
213 static void ToggleFullscreenIfNeeded()
215 if (setup.fullscreen != video.fullscreen_enabled)
217 /* save old door content */
218 BlitBitmap(backbuffer, bitmap_db_door,
219 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
221 /* toggle fullscreen */
222 ChangeVideoModeIfNeeded(setup.fullscreen);
223 setup.fullscreen = video.fullscreen_enabled;
225 /* redraw background to newly created backbuffer */
226 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
227 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
229 /* restore old door content */
230 BlitBitmap(bitmap_db_door, backbuffer,
231 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
233 redraw_mask = REDRAW_ALL;
239 static LevelDirTree *leveldir_last_valid = NULL;
240 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
241 int name_width = getTextWidth("Name:", FONT_MENU_1);
242 int level_width = getTextWidth("Level:", FONT_MENU_1);
246 FadeSoundsAndMusic();
248 KeyboardAutoRepeatOn();
251 SetDrawDeactivationMask(REDRAW_NONE);
252 SetDrawBackgroundMask(REDRAW_FIELD);
254 audio.sound_deactivated = FALSE;
256 /* needed if last screen was the playing screen, invoked from level editor */
257 if (level_editor_test_game)
259 game_status = GAME_MODE_EDITOR;
265 /* needed if last screen was the editor screen */
266 UndrawSpecialEditorDoor();
268 /* needed if last screen was the setup screen and fullscreen state changed */
269 ToggleFullscreenIfNeeded();
271 /* leveldir_current may be invalid (level group, parent link) */
272 if (!validLevelSeries(leveldir_current))
273 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
275 /* store valid level series information */
276 leveldir_last_valid = leveldir_current;
278 /* needed if last screen (level choice) changed graphics, sounds or music */
279 ReloadCustomArtwork();
282 SetDrawtoField(DRAW_BACKBUFFER);
285 /* map gadgets for main menu screen */
288 /* level_nr may have been set to value over handicap with level editor */
289 if (setup.handicap && level_nr > leveldir_current->handicap_level)
290 level_nr = leveldir_current->handicap_level;
295 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
300 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
301 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
302 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
303 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
304 DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
305 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
306 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
307 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
309 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
310 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
313 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
315 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
316 leveldir_current->first_level, leveldir_current->last_level);
318 if (leveldir_current->readonly)
320 DrawTextS(mSX + level_width + 9 * 32 - 2,
321 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
322 DrawTextS(mSX + level_width + 9 * 32 - 2,
323 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
326 for (i = 0; i < 8; i++)
327 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_RIGHT :
330 drawCursorXY(level_width/32 + 4, 1, IMG_MENU_BUTTON_LEFT);
331 drawCursorXY(level_width/32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
333 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment", FONT_TITLE_2);
338 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
341 if (TAPE_IS_EMPTY(tape))
343 DrawCompleteVideoDisplay();
348 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
351 static void gotoTopLevelDir()
353 /* move upwards to top level directory */
354 while (leveldir_current->node_parent)
356 /* write a "path" into level tree for easy navigation to last level */
357 if (leveldir_current->node_parent->node_group->cl_first == -1)
359 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
360 int leveldir_pos = posTreeInfo(leveldir_current);
361 int num_page_entries;
362 int cl_first, cl_cursor;
364 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
365 num_page_entries = num_leveldirs;
367 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
369 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
370 cl_cursor = leveldir_pos - cl_first;
372 leveldir_current->node_parent->node_group->cl_first = cl_first;
373 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
376 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;
420 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
421 new_level_nr = leveldir_current->handicap_level;
423 if (new_level_nr != old_level_nr &&
424 DelayReached(&level_delay, GADGET_FRAME_DELAY))
426 level_nr = new_level_nr;
428 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
432 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
436 DrawCompleteVideoDisplay();
438 /* needed because DrawMicroLevel() takes some time */
441 DelayReached(&level_delay, 0); /* reset delay counter */
444 else if (IN_VIS_FIELD(x, y) &&
445 y >= 0 && y <= 7 && (y != 1 || x < 10))
451 drawCursor(y, FC_RED);
452 drawCursor(choice, FC_BLUE);
460 game_status = GAME_MODE_PSEUDO_TYPENAME;
461 HandleTypeName(strlen(setup.player_name), 0);
467 game_status = GAME_MODE_LEVELS;
468 SaveLevelSetup_LastSeries();
469 SaveLevelSetup_SeriesInfo();
478 game_status = GAME_MODE_SCORES;
483 if (leveldir_current->readonly &&
484 strcmp(setup.player_name, "Artsoft") != 0)
485 Request("This level is read only !", REQ_CONFIRM);
486 game_status = GAME_MODE_EDITOR;
491 game_status = GAME_MODE_INFO;
492 info_mode = INFO_MODE_MAIN;
497 if (setup.autorecord)
498 TapeStartRecording();
500 #if defined(PLATFORM_UNIX)
502 SendToServer_StartPlaying();
506 game_status = GAME_MODE_PLAYING;
513 game_status = GAME_MODE_SETUP;
514 setup_mode = SETUP_MODE_MAIN;
519 SaveLevelSetup_LastSeries();
520 SaveLevelSetup_SeriesInfo();
521 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
522 game_status = GAME_MODE_QUIT;
527 if (game_status == GAME_MODE_MAIN)
529 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
535 /* ========================================================================= */
536 /* info screen functions */
537 /* ========================================================================= */
539 static struct TokenInfo *info_info;
540 static int num_info_info;
542 static void execInfoElements()
544 info_mode = INFO_MODE_ELEMENTS;
548 static void execInfoMusic()
550 info_mode = INFO_MODE_MUSIC;
554 static void execInfoCredits()
556 info_mode = INFO_MODE_CREDITS;
560 static void execInfoProgram()
562 info_mode = INFO_MODE_PROGRAM;
566 static void execInfoLevelSet()
568 info_mode = INFO_MODE_LEVELSET;
572 static void execExitInfo()
574 game_status = GAME_MODE_MAIN;
578 static struct TokenInfo info_info_main[] =
580 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
581 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
582 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
583 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
584 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
585 { TYPE_EMPTY, NULL, "" },
586 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
591 static void DrawInfoScreen_Main()
596 CloseDoor(DOOR_CLOSE_2);
600 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
602 info_info = info_info_main;
605 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
607 int ypos = MENU_SCREEN_START_YPOS + i;
608 int font_nr = FONT_MENU_1;
610 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
612 if (info_info[i].type & TYPE_ENTER_MENU)
613 initCursor(i, IMG_MENU_BUTTON_RIGHT);
614 else if (info_info[i].type & TYPE_LEAVE_MENU)
615 initCursor(i, IMG_MENU_BUTTON_LEFT);
616 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
617 initCursor(i, IMG_MENU_BUTTON);
628 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
631 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
633 static int choice_store[MAX_INFO_MODES];
634 int choice = choice_store[info_mode]; /* always starts with 0 */
638 if (button == MB_MENU_INITIALIZE)
640 /* advance to first valid menu entry */
641 while (choice < num_info_info &&
642 info_info[choice].type & TYPE_SKIP_ENTRY)
644 choice_store[info_mode] = choice;
646 drawCursor(choice, FC_RED);
649 else if (button == MB_MENU_LEAVE)
651 for (y = 0; y < num_info_info; y++)
653 if (info_info[y].type & TYPE_LEAVE_MENU)
655 void (*menu_callback_function)(void) = info_info[y].value;
657 menu_callback_function();
658 break; /* absolutely needed because function changes 'info_info'! */
665 if (mx || my) /* mouse input */
668 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
670 else if (dx || dy) /* keyboard input */
674 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
676 if (info_info[choice].type & menu_navigation_type ||
677 info_info[choice].type & TYPE_ENTER_SCREEN ||
678 info_info[choice].type & TYPE_BOOLEAN_STYLE)
679 button = MB_MENU_CHOICE;
684 /* jump to next non-empty menu entry (up or down) */
685 while (y > 0 && y < num_info_info - 1 &&
686 info_info[y].type & TYPE_SKIP_ENTRY)
690 if (IN_VIS_FIELD(x, y) &&
691 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
697 drawCursor(y, FC_RED);
698 drawCursor(choice, FC_BLUE);
699 choice = choice_store[info_mode] = y;
702 else if (!(info_info[y].type & TYPE_GHOSTED))
704 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
706 void (*menu_callback_function)(void) = info_info[choice].value;
708 menu_callback_function();
714 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
716 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
717 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
718 int xstart = mSX + 16;
719 int ystart = mSY + 64 + 2 * 32;
720 int ystep = TILEY + 4;
721 int element, action, direction;
729 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
730 infoscreen_step[i] = infoscreen_frame[i] = 0;
732 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
736 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
738 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
739 "Press any key or button for next page");
745 while (helpanim_info[j].element != HELPANIM_LIST_END)
747 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
752 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
761 j += infoscreen_step[i - start];
763 element = helpanim_info[j].element;
764 action = helpanim_info[j].action;
765 direction = helpanim_info[j].direction;
767 if (action != -1 && direction != -1)
768 graphic = el_act_dir2img(element, action, direction);
769 else if (action != -1)
770 graphic = el_act2img(element, action);
771 else if (direction != -1)
772 graphic = el_act2img(element, direction);
774 graphic = el2img(element);
776 delay = helpanim_info[j++].delay;
781 if (infoscreen_frame[i - start] == 0)
784 infoscreen_frame[i - start] = delay - 1;
788 sync_frame = delay - infoscreen_frame[i - start];
789 infoscreen_frame[i - start]--;
792 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
794 if (!infoscreen_frame[i - start])
795 infoscreen_step[i - start] = 0;
799 if (!infoscreen_frame[i - start])
800 infoscreen_step[i - start]++;
801 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
807 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
809 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
810 graphic, sync_frame, USE_MASKING);
813 DrawInfoScreen_HelpText(element, action, direction, i - start);
818 redraw_mask |= REDRAW_FIELD;
823 static char *getHelpText(int element, int action, int direction)
825 char token[MAX_LINE_LEN];
827 strcpy(token, element_info[element].token_name);
830 strcat(token, element_action_info[action].suffix);
833 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
835 return getHashEntry(helptext_info, token);
838 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
841 int font_nr = FONT_TEXT_2;
843 int font_nr = FONT_LEVEL_NUMBER;
845 int font_width = getFontWidth(font_nr);
846 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
847 int sy = mSY + 65 + 2 * 32 + 1;
848 int ystep = TILEY + 4;
850 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
851 int max_lines_per_text = 2;
854 if (action != -1 && direction != -1) /* element.action.direction */
855 text = getHelpText(element, action, direction);
857 if (text == NULL && action != -1) /* element.action */
858 text = getHelpText(element, action, -1);
860 if (text == NULL && direction != -1) /* element.direction */
861 text = getHelpText(element, -1, direction);
863 if (text == NULL) /* base element */
864 text = getHelpText(element, -1, -1);
866 if (text == NULL) /* not found */
867 text = "No description available";
869 if (strlen(text) <= max_chars_per_line) /* only one line of text */
870 sy += getFontHeight(font_nr) / 2;
872 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
873 max_chars_per_line, max_lines_per_text);
876 void DrawInfoScreen_Elements()
881 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
887 void HandleInfoScreen_Elements(int button)
889 static unsigned long info_delay = 0;
890 static int num_anims;
891 static int num_pages;
893 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
894 int button_released = !button;
897 if (button == MB_MENU_INITIALIZE)
899 boolean new_element = TRUE;
902 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
904 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
906 else if (new_element)
913 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
916 else if (button == MB_MENU_LEAVE)
918 info_mode = INFO_MODE_MAIN;
924 if (button_released || button == MB_MENU_INITIALIZE)
926 if (button != MB_MENU_INITIALIZE)
929 if (page >= num_pages)
931 FadeSoundsAndMusic();
933 info_mode = INFO_MODE_MAIN;
939 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
943 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
944 if (page < num_pages)
945 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
947 PlayMenuSoundIfLoop();
951 void DrawInfoScreen_Music()
958 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
961 void HandleInfoScreen_Music(int button)
963 static struct MusicFileInfo *list = NULL;
964 int ystart = 150, dy = 30;
965 int ybottom = SYSIZE - 20;
966 int button_released = !button;
968 if (button == MB_MENU_INITIALIZE)
970 list = music_file_info;
974 FadeSoundsAndMusic();
979 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
981 DrawTextSCentered(ybottom, FONT_TEXT_4,
982 "Press any key or button for info menu");
987 else if (button == MB_MENU_LEAVE)
989 info_mode = INFO_MODE_MAIN;
995 if (button_released || button == MB_MENU_INITIALIZE)
1001 info_mode = INFO_MODE_MAIN;
1007 FadeSoundsAndMusic();
1014 PlaySound(list->music);
1016 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1020 PlayMusic(list->music);
1022 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1025 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1027 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1028 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1030 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1033 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1035 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1036 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1038 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1040 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1043 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1045 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1046 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1048 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1050 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1053 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1055 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1056 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1058 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1060 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1063 DrawTextSCentered(ybottom, FONT_TEXT_4,
1064 "Press any key or button for next page");
1070 void DrawInfoScreen_Credits()
1072 int ystart = 150, ystep = 30;
1073 int ybottom = SYSIZE - 20;
1075 FadeSoundsAndMusic();
1080 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1081 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1082 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1083 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1084 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1085 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1086 "...and many thanks to all contributors");
1087 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1089 DrawTextSCentered(ybottom, FONT_TEXT_4,
1090 "Press any key or button for info menu");
1093 void HandleInfoScreen_Credits(int button)
1095 int button_released = !button;
1097 if (button == MB_MENU_LEAVE)
1099 info_mode = INFO_MODE_MAIN;
1105 if (button_released)
1107 FadeSoundsAndMusic();
1109 info_mode = INFO_MODE_MAIN;
1114 PlayMenuSoundIfLoop();
1118 void DrawInfoScreen_Program()
1120 int ystart = 150, ystep = 30;
1121 int ybottom = SYSIZE - 20;
1126 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1128 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1129 "This game is Freeware!");
1130 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1131 "If you like it, send e-mail to:");
1132 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1133 "info@artsoft.org");
1134 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1135 "or SnailMail to:");
1136 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1138 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1139 "Detmolder Strasse 189");
1140 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1142 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1145 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1146 "If you have created new levels,");
1147 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1148 "send them to me to include them!");
1149 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1152 DrawTextSCentered(ybottom, FONT_TEXT_4,
1153 "Press any key or button for info menu");
1156 void HandleInfoScreen_Program(int button)
1158 int button_released = !button;
1160 if (button == MB_MENU_LEAVE)
1162 info_mode = INFO_MODE_MAIN;
1168 if (button_released)
1170 FadeSoundsAndMusic();
1172 info_mode = INFO_MODE_MAIN;
1177 PlayMenuSoundIfLoop();
1181 void DrawInfoScreen_LevelSet()
1184 int ybottom = SYSIZE - 20;
1185 char *filename = getLevelSetInfoFilename();
1187 int font_nr = FONT_TEXT_2;
1189 int font_nr = FONT_LEVEL_NUMBER;
1191 int font_width = getFontWidth(font_nr);
1192 int font_height = getFontHeight(font_nr);
1195 int sx = SX + pad_x;
1196 int sy = SY + pad_y;
1197 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1198 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1203 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1205 DrawTextSCentered(ybottom, FONT_TEXT_4,
1206 "Press any key or button for info menu");
1208 if (filename != NULL)
1209 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1210 max_lines_per_screen);
1212 DrawTextSCentered(ystart, FONT_TEXT_2,
1213 "No information for this level set.");
1216 void HandleInfoScreen_LevelSet(int button)
1218 int button_released = !button;
1220 if (button == MB_MENU_LEAVE)
1222 info_mode = INFO_MODE_MAIN;
1228 if (button_released)
1230 FadeSoundsAndMusic();
1232 info_mode = INFO_MODE_MAIN;
1237 PlayMenuSoundIfLoop();
1241 void DrawInfoScreen()
1243 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1245 if (info_mode == INFO_MODE_ELEMENTS)
1246 DrawInfoScreen_Elements();
1247 else if (info_mode == INFO_MODE_MUSIC)
1248 DrawInfoScreen_Music();
1249 else if (info_mode == INFO_MODE_CREDITS)
1250 DrawInfoScreen_Credits();
1251 else if (info_mode == INFO_MODE_PROGRAM)
1252 DrawInfoScreen_Program();
1253 else if (info_mode == INFO_MODE_LEVELSET)
1254 DrawInfoScreen_LevelSet();
1256 DrawInfoScreen_Main();
1258 if (info_mode != INFO_MODE_MUSIC)
1265 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1267 if (info_mode == INFO_MODE_ELEMENTS)
1268 HandleInfoScreen_Elements(button);
1269 else if (info_mode == INFO_MODE_MUSIC)
1270 HandleInfoScreen_Music(button);
1271 else if (info_mode == INFO_MODE_CREDITS)
1272 HandleInfoScreen_Credits(button);
1273 else if (info_mode == INFO_MODE_PROGRAM)
1274 HandleInfoScreen_Program(button);
1275 else if (info_mode == INFO_MODE_LEVELSET)
1276 HandleInfoScreen_LevelSet(button);
1278 HandleInfoScreen_Main(mx, my, dx, dy, button);
1284 /* ========================================================================= */
1285 /* type name functions */
1286 /* ========================================================================= */
1288 void HandleTypeName(int newxpos, Key key)
1290 static int xpos = 0, ypos = 2;
1291 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1292 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1293 int startx = mSX + 32 + name_width;
1294 int starty = mSY + ypos * 32;
1300 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1301 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1306 if (((key >= KSYM_A && key <= KSYM_Z) ||
1307 (key >= KSYM_a && key <= KSYM_z)) &&
1308 xpos < MAX_PLAYER_NAME_LEN)
1312 if (key >= KSYM_A && key <= KSYM_Z)
1313 ascii = 'A' + (char)(key - KSYM_A);
1315 ascii = 'a' + (char)(key - KSYM_a);
1317 setup.player_name[xpos] = ascii;
1318 setup.player_name[xpos + 1] = 0;
1321 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1322 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1324 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1327 setup.player_name[xpos] = 0;
1329 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1331 else if (key == KSYM_Return && xpos > 0)
1333 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1334 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1337 game_status = GAME_MODE_MAIN;
1342 /* ========================================================================= */
1343 /* tree menu functions */
1344 /* ========================================================================= */
1346 static void DrawChooseTree(TreeInfo **ti_ptr)
1350 FreeScreenGadgets();
1351 CreateScreenGadgets();
1353 CloseDoor(DOOR_CLOSE_2);
1357 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1358 MapChooseTreeGadgets(*ti_ptr);
1364 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1366 struct GadgetInfo *gi = screen_gadget[id];
1367 int items_max, items_visible, item_position;
1369 items_max = numTreeInfoInGroup(ti);
1370 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1371 item_position = first_entry;
1373 if (item_position > items_max - items_visible)
1374 item_position = items_max - items_visible;
1376 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1377 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1378 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1381 static void drawChooseTreeList(int first_entry, int num_page_entries,
1385 char buffer[SCR_FIELDX * 2];
1386 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1387 char *title_string = NULL;
1388 int xoffset_setup = 16;
1389 int yoffset_setup = 16;
1390 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1391 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1392 int last_game_status = game_status; /* save current game status */
1395 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1396 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1397 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1398 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1400 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1402 /* force LEVELS font on artwork setup screen */
1403 game_status = GAME_MODE_LEVELS;
1405 /* clear tree list area, but not title or scrollbar */
1406 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1407 SXSIZE - 32 + menu.scrollbar_xoffset,
1408 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1410 for (i = 0; i < num_page_entries; i++)
1412 TreeInfo *node, *node_first;
1413 int entry_pos = first_entry + i;
1414 int ypos = MENU_SCREEN_START_YPOS + i;
1416 node_first = getTreeInfoFirstGroupEntry(ti);
1417 node = getTreeInfoFromPos(node_first, entry_pos);
1419 strncpy(buffer, node->name , max_buffer_len);
1420 buffer[max_buffer_len] = '\0';
1422 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1424 if (node->parent_link)
1425 initCursor(i, IMG_MENU_BUTTON_LEFT);
1426 else if (node->level_group)
1427 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1429 initCursor(i, IMG_MENU_BUTTON);
1432 game_status = last_game_status; /* restore current game status */
1434 redraw_mask |= REDRAW_FIELD;
1437 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1439 TreeInfo *node, *node_first;
1440 int x, last_redraw_mask = redraw_mask;
1442 if (ti->type != TREE_TYPE_LEVEL_DIR)
1445 node_first = getTreeInfoFirstGroupEntry(ti);
1446 node = getTreeInfoFromPos(node_first, entry_pos);
1448 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1450 if (node->parent_link)
1451 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1453 else if (node->level_group)
1454 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1456 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1457 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1458 node->levels, node->class_desc);
1460 /* let BackToFront() redraw only what is needed */
1461 redraw_mask = last_redraw_mask | REDRAW_TILES;
1462 for (x = 0; x < SCR_FIELDX; x++)
1463 MarkTileDirty(x, 1);
1466 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1469 TreeInfo *ti = *ti_ptr;
1471 int y = ti->cl_cursor;
1472 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1473 int num_entries = numTreeInfoInGroup(ti);
1474 int num_page_entries;
1475 int last_game_status = game_status; /* save current game status */
1477 /* force LEVELS draw offset on choose level and artwork setup screen */
1478 game_status = GAME_MODE_LEVELS;
1480 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1481 num_page_entries = num_entries;
1483 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1485 game_status = last_game_status; /* restore current game status */
1487 if (button == MB_MENU_INITIALIZE)
1489 int num_entries = numTreeInfoInGroup(ti);
1490 int entry_pos = posTreeInfo(ti);
1492 if (ti->cl_first == -1)
1494 /* only on initialization */
1495 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1496 ti->cl_cursor = entry_pos - ti->cl_first;
1498 else if (ti->cl_cursor >= num_page_entries ||
1499 (num_entries > num_page_entries &&
1500 num_entries - ti->cl_first < num_page_entries))
1502 /* only after change of list size (by custom graphic configuration) */
1503 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1504 ti->cl_cursor = entry_pos - ti->cl_first;
1507 if (dx == 999) /* first entry is set by scrollbar position */
1510 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1513 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1514 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1515 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1519 else if (button == MB_MENU_LEAVE)
1521 if (ti->node_parent)
1523 *ti_ptr = ti->node_parent;
1524 DrawChooseTree(ti_ptr);
1526 else if (game_status == GAME_MODE_SETUP)
1532 game_status = GAME_MODE_MAIN;
1539 if (mx || my) /* mouse input */
1541 int last_game_status = game_status; /* save current game status */
1543 /* force LEVELS draw offset on artwork setup screen */
1544 game_status = GAME_MODE_LEVELS;
1546 x = (mx - mSX) / 32;
1547 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1549 game_status = last_game_status; /* restore current game status */
1551 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1553 /* move cursor instead of scrolling when already at start/end of list */
1554 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1556 else if (dy == +1 * SCROLL_LINE &&
1557 ti->cl_first + num_page_entries == num_entries)
1560 /* handle scrolling screen one line or page */
1561 if (ti->cl_cursor + dy < 0 ||
1562 ti->cl_cursor + dy > num_page_entries - 1)
1564 if (ABS(dy) == SCROLL_PAGE)
1565 step = num_page_entries - 1;
1567 if (dy < 0 && ti->cl_first > 0)
1569 /* scroll page/line up */
1571 ti->cl_first -= step;
1572 if (ti->cl_first < 0)
1575 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1576 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1577 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1578 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1581 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1583 /* scroll page/line down */
1585 ti->cl_first += step;
1586 if (ti->cl_first + num_page_entries > num_entries)
1587 ti->cl_first = MAX(0, num_entries - num_page_entries);
1589 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1590 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1591 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1592 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1599 /* handle moving cursor one line */
1600 y = ti->cl_cursor + dy;
1605 TreeInfo *node_first, *node_cursor;
1606 int entry_pos = ti->cl_first + y;
1608 node_first = getTreeInfoFirstGroupEntry(ti);
1609 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1611 if (node_cursor->node_group)
1613 node_cursor->cl_first = ti->cl_first;
1614 node_cursor->cl_cursor = ti->cl_cursor;
1615 *ti_ptr = node_cursor->node_group;
1616 DrawChooseTree(ti_ptr);
1621 else if (dx == -1 && ti->node_parent)
1623 *ti_ptr = ti->node_parent;
1624 DrawChooseTree(ti_ptr);
1629 if (IN_VIS_FIELD(x, y) &&
1630 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1631 y >= 0 && y < num_page_entries)
1635 if (y != ti->cl_cursor)
1637 drawChooseTreeCursor(y, FC_RED);
1638 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1639 drawChooseTreeInfo(ti->cl_first + y, ti);
1645 TreeInfo *node_first, *node_cursor;
1646 int entry_pos = ti->cl_first + y;
1648 node_first = getTreeInfoFirstGroupEntry(ti);
1649 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1651 if (node_cursor->node_group)
1653 node_cursor->cl_first = ti->cl_first;
1654 node_cursor->cl_cursor = ti->cl_cursor;
1655 *ti_ptr = node_cursor->node_group;
1656 DrawChooseTree(ti_ptr);
1658 else if (node_cursor->parent_link)
1660 *ti_ptr = node_cursor->node_parent;
1661 DrawChooseTree(ti_ptr);
1665 node_cursor->cl_first = ti->cl_first;
1666 node_cursor->cl_cursor = ti->cl_cursor;
1667 *ti_ptr = node_cursor;
1669 if (ti->type == TREE_TYPE_LEVEL_DIR)
1671 LoadLevelSetup_SeriesInfo();
1673 SaveLevelSetup_LastSeries();
1674 SaveLevelSetup_SeriesInfo();
1678 if (game_status == GAME_MODE_SETUP)
1684 game_status = GAME_MODE_MAIN;
1692 void DrawChooseLevel()
1694 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1696 DrawChooseTree(&leveldir_current);
1702 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1704 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1709 void DrawHallOfFame(int highlight_position)
1712 FadeSoundsAndMusic();
1713 CloseDoor(DOOR_CLOSE_2);
1715 if (highlight_position < 0)
1716 LoadScore(level_nr);
1724 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1727 static void drawHallOfFameList(int first_entry, int highlight_position)
1731 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1734 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1735 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1737 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1739 int entry = first_entry + i;
1740 boolean active = (entry == highlight_position);
1741 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1742 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1743 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1744 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1745 int dx1 = 3 * getFontWidth(font_nr1);
1746 int dx2 = dx1 + getFontWidth(font_nr1);
1747 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1748 int sy = mSY + 64 + i * 32;
1750 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1751 DrawText(mSX + dx1, sy, ".", font_nr1);
1752 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1753 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1754 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1755 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1758 redraw_mask |= REDRAW_FIELD;
1761 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1763 static int first_entry = 0;
1764 static int highlight_position = 0;
1765 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1766 int button_released = !button;
1768 if (button == MB_MENU_INITIALIZE)
1771 highlight_position = mx;
1772 drawHallOfFameList(first_entry, highlight_position);
1777 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1778 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1782 if (first_entry > 0)
1784 first_entry -= step;
1785 if (first_entry < 0)
1788 drawHallOfFameList(first_entry, highlight_position);
1793 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1795 first_entry += step;
1796 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1797 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1799 drawHallOfFameList(first_entry, highlight_position);
1802 else if (button_released)
1804 FadeSound(SND_BACKGROUND_SCORES);
1805 game_status = GAME_MODE_MAIN;
1809 if (game_status == GAME_MODE_SCORES)
1810 PlayMenuSoundIfLoop();
1816 /* ========================================================================= */
1817 /* setup screen functions */
1818 /* ========================================================================= */
1820 static struct TokenInfo *setup_info;
1821 static int num_setup_info;
1823 static char *graphics_set_name;
1824 static char *sounds_set_name;
1825 static char *music_set_name;
1827 static void execSetupMain()
1829 setup_mode = SETUP_MODE_MAIN;
1833 static void execSetupGame()
1835 setup_mode = SETUP_MODE_GAME;
1839 static void execSetupEditor()
1841 setup_mode = SETUP_MODE_EDITOR;
1845 static void execSetupGraphics()
1847 setup_mode = SETUP_MODE_GRAPHICS;
1851 static void execSetupSound()
1853 setup_mode = SETUP_MODE_SOUND;
1857 static void execSetupArtwork()
1859 setup.graphics_set = artwork.gfx_current->identifier;
1860 setup.sounds_set = artwork.snd_current->identifier;
1861 setup.music_set = artwork.mus_current->identifier;
1863 /* needed if last screen (setup choice) changed graphics, sounds or music */
1864 ReloadCustomArtwork();
1866 /* needed for displaying artwork name instead of artwork identifier */
1867 graphics_set_name = artwork.gfx_current->name;
1868 sounds_set_name = artwork.snd_current->name;
1869 music_set_name = artwork.mus_current->name;
1871 setup_mode = SETUP_MODE_ARTWORK;
1875 static void execSetupChooseGraphics()
1877 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1881 static void execSetupChooseSounds()
1883 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1887 static void execSetupChooseMusic()
1889 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1893 static void execSetupInput()
1895 setup_mode = SETUP_MODE_INPUT;
1899 static void execSetupShortcut()
1901 setup_mode = SETUP_MODE_SHORTCUT;
1905 static void execExitSetup()
1907 game_status = GAME_MODE_MAIN;
1911 static void execSaveAndExitSetup()
1917 static struct TokenInfo setup_info_main[] =
1919 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1920 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1921 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1922 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1923 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1924 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1925 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1926 { TYPE_EMPTY, NULL, "" },
1927 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1928 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1933 static struct TokenInfo setup_info_game[] =
1935 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1936 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1937 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1938 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1939 { TYPE_EMPTY, NULL, "" },
1940 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1945 static struct TokenInfo setup_info_editor[] =
1947 { TYPE_STRING, NULL, "Offer Special Elements:"},
1948 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1949 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1950 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1951 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1952 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1953 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1954 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1955 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1956 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1957 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1958 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1959 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1960 { TYPE_EMPTY, NULL, "" },
1961 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1966 static struct TokenInfo setup_info_graphics[] =
1968 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1969 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1970 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1972 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1973 { TYPE_SWITCH, &setup.fading, "Fading:" },
1975 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1976 { TYPE_SWITCH, &setup.toons, "Toons:" },
1977 { TYPE_EMPTY, NULL, "" },
1978 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1983 static struct TokenInfo setup_info_sound[] =
1985 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1986 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1987 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1988 { TYPE_EMPTY, NULL, "" },
1989 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1994 static struct TokenInfo setup_info_artwork[] =
1996 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
1997 { TYPE_STRING, &graphics_set_name, "" },
1998 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
1999 { TYPE_STRING, &sounds_set_name, "" },
2000 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2001 { TYPE_STRING, &music_set_name, "" },
2002 { TYPE_EMPTY, NULL, "" },
2003 { TYPE_STRING, NULL, "Override Level Artwork:"},
2004 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2005 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2006 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2007 { TYPE_EMPTY, NULL, "" },
2008 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2013 static struct TokenInfo setup_info_shortcut[] =
2015 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2016 { TYPE_KEY, &setup.shortcut.save_game, "" },
2017 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2018 { TYPE_KEY, &setup.shortcut.load_game, "" },
2019 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2020 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2021 { TYPE_EMPTY, NULL, "" },
2022 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2023 { TYPE_EMPTY, NULL, "" },
2024 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2029 static Key getSetupKey()
2031 Key key = KSYM_UNDEFINED;
2032 boolean got_key_event = FALSE;
2034 while (!got_key_event)
2036 if (PendingEvent()) /* got event */
2044 case EVENT_KEYPRESS:
2046 key = GetEventKey((KeyEvent *)&event, TRUE);
2048 /* press 'Escape' or 'Enter' to keep the existing key binding */
2049 if (key == KSYM_Escape || key == KSYM_Return)
2050 key = KSYM_UNDEFINED; /* keep old value */
2052 got_key_event = TRUE;
2056 case EVENT_KEYRELEASE:
2057 key_joystick_mapping = 0;
2061 HandleOtherEvents(&event);
2069 /* don't eat all CPU time */
2076 static void drawSetupValue(int pos)
2078 int xpos = MENU_SCREEN_VALUE_XPOS;
2079 int ypos = MENU_SCREEN_START_YPOS + pos;
2080 int font_nr = FONT_VALUE_1;
2081 int type = setup_info[pos].type;
2082 void *value = setup_info[pos].value;
2083 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2086 if (value_string == NULL)
2089 if (type & TYPE_KEY)
2093 if (type & TYPE_QUERY)
2095 value_string = "<press key>";
2096 font_nr = FONT_INPUT_1_ACTIVE;
2099 else if (type & TYPE_STRING)
2101 int max_value_len = (SCR_FIELDX - 2) * 2;
2104 font_nr = FONT_VALUE_2;
2106 if (strlen(value_string) > max_value_len)
2107 value_string[max_value_len] = '\0';
2109 else if (type & TYPE_BOOLEAN_STYLE)
2111 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2114 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2115 (xpos == 3 ? " " : " "), font_nr);
2116 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2119 static void changeSetupValue(int pos)
2121 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2123 *(boolean *)setup_info[pos].value ^= TRUE;
2125 else if (setup_info[pos].type & TYPE_KEY)
2129 setup_info[pos].type |= TYPE_QUERY;
2130 drawSetupValue(pos);
2131 setup_info[pos].type &= ~TYPE_QUERY;
2133 key = getSetupKey();
2134 if (key != KSYM_UNDEFINED)
2135 *(Key *)setup_info[pos].value = key;
2138 drawSetupValue(pos);
2141 static void DrawSetupScreen_Generic()
2143 char *title_string = NULL;
2147 CloseDoor(DOOR_CLOSE_2);
2151 if (setup_mode == SETUP_MODE_MAIN)
2153 setup_info = setup_info_main;
2154 title_string = "Setup";
2156 else if (setup_mode == SETUP_MODE_GAME)
2158 setup_info = setup_info_game;
2159 title_string = "Setup Game";
2161 else if (setup_mode == SETUP_MODE_EDITOR)
2163 setup_info = setup_info_editor;
2164 title_string = "Setup Editor";
2166 else if (setup_mode == SETUP_MODE_GRAPHICS)
2168 setup_info = setup_info_graphics;
2169 title_string = "Setup Graphics";
2171 else if (setup_mode == SETUP_MODE_SOUND)
2173 setup_info = setup_info_sound;
2174 title_string = "Setup Sound";
2176 else if (setup_mode == SETUP_MODE_ARTWORK)
2178 setup_info = setup_info_artwork;
2179 title_string = "Custom Artwork";
2181 else if (setup_mode == SETUP_MODE_SHORTCUT)
2183 setup_info = setup_info_shortcut;
2184 title_string = "Setup Shortcuts";
2187 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2190 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2192 void *value_ptr = setup_info[i].value;
2193 int ypos = MENU_SCREEN_START_YPOS + i;
2194 int font_nr = FONT_MENU_1;
2196 /* set some entries to "unchangeable" according to other variables */
2197 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2198 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2199 (value_ptr == &setup.sound_music && !audio.music_available) ||
2200 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2201 setup_info[i].type |= TYPE_GHOSTED;
2203 if (setup_info[i].type & TYPE_STRING)
2204 font_nr = FONT_MENU_2;
2206 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2208 if (setup_info[i].type & TYPE_ENTER_MENU)
2209 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2210 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2211 initCursor(i, IMG_MENU_BUTTON_LEFT);
2212 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2213 initCursor(i, IMG_MENU_BUTTON);
2215 if (setup_info[i].type & TYPE_VALUE)
2223 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2226 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2228 static int choice_store[MAX_SETUP_MODES];
2229 int choice = choice_store[setup_mode]; /* always starts with 0 */
2233 if (button == MB_MENU_INITIALIZE)
2235 /* advance to first valid menu entry */
2236 while (choice < num_setup_info &&
2237 setup_info[choice].type & TYPE_SKIP_ENTRY)
2239 choice_store[setup_mode] = choice;
2241 drawCursor(choice, FC_RED);
2244 else if (button == MB_MENU_LEAVE)
2246 for (y = 0; y < num_setup_info; y++)
2248 if (setup_info[y].type & TYPE_LEAVE_MENU)
2250 void (*menu_callback_function)(void) = setup_info[y].value;
2252 menu_callback_function();
2253 break; /* absolutely needed because function changes 'setup_info'! */
2260 if (mx || my) /* mouse input */
2262 x = (mx - mSX) / 32;
2263 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2265 else if (dx || dy) /* keyboard input */
2269 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2271 if (setup_info[choice].type & menu_navigation_type ||
2272 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2273 button = MB_MENU_CHOICE;
2278 /* jump to next non-empty menu entry (up or down) */
2279 while (y > 0 && y < num_setup_info - 1 &&
2280 setup_info[y].type & TYPE_SKIP_ENTRY)
2284 if (IN_VIS_FIELD(x, y) &&
2285 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2291 drawCursor(y, FC_RED);
2292 drawCursor(choice, FC_BLUE);
2293 choice = choice_store[setup_mode] = y;
2296 else if (!(setup_info[y].type & TYPE_GHOSTED))
2298 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2300 void (*menu_callback_function)(void) = setup_info[choice].value;
2302 menu_callback_function();
2306 if (setup_info[y].type & TYPE_KEYTEXT &&
2307 setup_info[y + 1].type & TYPE_KEY)
2310 if (setup_info[y].type & TYPE_VALUE)
2311 changeSetupValue(y);
2317 void DrawSetupScreen_Input()
2321 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2323 initCursor(0, IMG_MENU_BUTTON);
2324 initCursor(1, IMG_MENU_BUTTON);
2325 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2326 initCursor(13, IMG_MENU_BUTTON_LEFT);
2328 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2329 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2331 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2332 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2333 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2336 DeactivateJoystickForCalibration();
2337 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2338 "Joysticks deactivated on this screen");
2341 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2346 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2348 if (device_name == NULL)
2351 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2354 if (strlen(device_name) > 1)
2356 char c1 = device_name[strlen(device_name) - 1];
2357 char c2 = device_name[strlen(device_name) - 2];
2359 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2360 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2363 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2364 strlen(device_name));
2367 static void drawPlayerSetupInputInfo(int player_nr)
2370 static struct SetupKeyboardInfo custom_key;
2377 { &custom_key.left, "Joystick Left" },
2378 { &custom_key.right, "Joystick Right" },
2379 { &custom_key.up, "Joystick Up" },
2380 { &custom_key.down, "Joystick Down" },
2381 { &custom_key.snap, "Button 1" },
2382 { &custom_key.bomb, "Button 2" }
2384 static char *joystick_name[MAX_PLAYERS] =
2392 custom_key = setup.input[player_nr].key;
2394 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2396 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2397 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2399 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2402 if (setup.input[player_nr].use_joystick)
2404 char *device_name = setup.input[player_nr].joy.device_name;
2406 DrawText(mSX+8*32, mSY+3*32,
2407 joystick_name[getJoystickNrFromDeviceName(device_name)],
2409 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2413 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2414 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2417 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2418 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2419 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2420 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2421 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2422 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2423 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2424 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2425 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2426 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2427 DrawText(mSX+32, mSY+12*32, "Place Bomb:", FONT_VALUE_OLD);
2429 for (i = 0; i < 6; i++)
2431 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2433 DrawText(mSX + 3*32, mSY + ypos*32,
2435 DrawText(mSX + 3*32, mSY + ypos*32,
2436 (setup.input[player_nr].use_joystick ?
2438 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2442 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2444 static int choice = 0;
2445 static int player_nr = 0;
2448 int pos_start = SETUPINPUT_SCREEN_POS_START;
2449 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2450 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2451 int pos_end = SETUPINPUT_SCREEN_POS_END;
2453 if (button == MB_MENU_INITIALIZE)
2455 drawPlayerSetupInputInfo(player_nr);
2456 drawCursor(choice, FC_RED);
2460 else if (button == MB_MENU_LEAVE)
2462 setup_mode = SETUP_MODE_MAIN;
2469 if (mx || my) /* mouse input */
2471 x = (mx - mSX) / 32;
2472 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2474 else if (dx || dy) /* keyboard input */
2476 if (dx && choice == 0)
2477 x = (dx < 0 ? 10 : 12);
2478 else if ((dx && choice == 1) ||
2479 (dx == +1 && choice == 2) ||
2480 (dx == -1 && choice == pos_end))
2481 button = MB_MENU_CHOICE;
2485 if (y >= pos_empty1 && y <= pos_empty2)
2486 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2489 if (IN_VIS_FIELD(x, y) &&
2490 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2492 static unsigned long delay = 0;
2494 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2497 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2499 drawPlayerSetupInputInfo(player_nr);
2501 else if (IN_VIS_FIELD(x, y) &&
2502 y >= pos_start && y <= pos_end &&
2503 !(y >= pos_empty1 && y <= pos_empty2))
2509 drawCursor(y, FC_RED);
2510 drawCursor(choice, FC_BLUE);
2518 char *device_name = setup.input[player_nr].joy.device_name;
2520 if (!setup.input[player_nr].use_joystick)
2522 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2524 setJoystickDeviceToNr(device_name, new_device_nr);
2525 setup.input[player_nr].use_joystick = TRUE;
2529 int device_nr = getJoystickNrFromDeviceName(device_name);
2530 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2532 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2533 setup.input[player_nr].use_joystick = FALSE;
2535 setJoystickDeviceToNr(device_name, new_device_nr);
2538 drawPlayerSetupInputInfo(player_nr);
2542 if (setup.input[player_nr].use_joystick)
2545 CalibrateJoystick(player_nr);
2548 CustomizeKeyboard(player_nr);
2550 else if (y == pos_end)
2554 setup_mode = SETUP_MODE_MAIN;
2561 void CustomizeKeyboard(int player_nr)
2565 boolean finished = FALSE;
2566 static struct SetupKeyboardInfo custom_key;
2571 } customize_step[] =
2573 { &custom_key.left, "Move Left" },
2574 { &custom_key.right, "Move Right" },
2575 { &custom_key.up, "Move Up" },
2576 { &custom_key.down, "Move Down" },
2577 { &custom_key.snap, "Snap Field" },
2578 { &custom_key.bomb, "Place Bomb" }
2581 /* read existing key bindings from player setup */
2582 custom_key = setup.input[player_nr].key;
2585 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2591 DrawText(mSX, mSY + (2+2*step_nr)*32,
2592 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2593 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2594 "Key:", FONT_INPUT_1_ACTIVE);
2595 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2596 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2600 if (PendingEvent()) /* got event */
2608 case EVENT_KEYPRESS:
2610 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2612 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2618 /* all keys configured -- wait for "Escape" or "Return" key */
2622 /* press 'Enter' to keep the existing key binding */
2623 if (key == KSYM_Return)
2624 key = *customize_step[step_nr].key;
2626 /* check if key already used */
2627 for (i = 0; i < step_nr; i++)
2628 if (*customize_step[i].key == key)
2633 /* got new key binding */
2634 *customize_step[step_nr].key = key;
2635 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2637 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2638 getKeyNameFromKey(key), FONT_VALUE_1);
2641 /* un-highlight last query */
2642 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2643 customize_step[step_nr-1].text, FONT_MENU_1);
2644 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2645 "Key:", FONT_MENU_1);
2647 /* press 'Enter' to leave */
2650 DrawText(mSX + 16, mSY + 15*32+16,
2651 "Press Enter", FONT_TITLE_1);
2655 /* query next key binding */
2656 DrawText(mSX, mSY+(2+2*step_nr)*32,
2657 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2658 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2659 "Key:", FONT_INPUT_1_ACTIVE);
2660 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2661 getKeyNameFromKey(*customize_step[step_nr].key),
2666 case EVENT_KEYRELEASE:
2667 key_joystick_mapping = 0;
2671 HandleOtherEvents(&event);
2679 /* don't eat all CPU time */
2683 /* write new key bindings back to player setup */
2684 setup.input[player_nr].key = custom_key;
2687 DrawSetupScreen_Input();
2690 static boolean CalibrateJoystickMain(int player_nr)
2692 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2693 int new_joystick_xright = JOYSTICK_XMIDDLE;
2694 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2695 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2696 int new_joystick_xmiddle, new_joystick_ymiddle;
2698 int joystick_fd = joystick.fd[player_nr];
2699 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2700 boolean check[3][3];
2701 int check_remaining = 3 * 3;
2706 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2709 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2714 for (y = 0; y < 3; y++)
2716 for (x = 0; x < 3; x++)
2718 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2719 check[x][y] = FALSE;
2723 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2724 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2725 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2726 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2727 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2728 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2729 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2731 joy_value = Joystick(player_nr);
2732 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2733 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2735 /* eventually uncalibrated center position (joystick could be uncentered) */
2736 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2739 new_joystick_xmiddle = joy_x;
2740 new_joystick_ymiddle = joy_y;
2742 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2745 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2750 if (PendingEvent()) /* got event */
2758 case EVENT_KEYPRESS:
2759 switch(GetEventKey((KeyEvent *)&event, TRUE))
2762 if (check_remaining == 0)
2775 case EVENT_KEYRELEASE:
2776 key_joystick_mapping = 0;
2780 HandleOtherEvents(&event);
2785 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2788 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2789 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2790 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2791 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2793 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2794 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2795 setup.input[player_nr].joy.xright = new_joystick_xright;
2796 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2797 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2798 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2800 CheckJoystickData();
2802 joy_value = Joystick(player_nr);
2804 if (joy_value & JOY_BUTTON && check_remaining == 0)
2807 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2808 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2810 if (x != last_x || y != last_y)
2812 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2813 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2818 if (check_remaining > 0 && !check[x+1][y+1])
2820 check[x+1][y+1] = TRUE;
2826 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2827 setup.input[player_nr].joy.xleft,
2828 setup.input[player_nr].joy.xmiddle,
2829 setup.input[player_nr].joy.xright);
2830 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2831 setup.input[player_nr].joy.yupper,
2832 setup.input[player_nr].joy.ymiddle,
2833 setup.input[player_nr].joy.ylower);
2842 /* don't eat all CPU time */
2846 /* calibrated center position (joystick should now be centered) */
2847 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2850 new_joystick_xmiddle = joy_x;
2851 new_joystick_ymiddle = joy_y;
2855 DrawSetupScreen_Input();
2857 /* wait until the last pressed button was released */
2858 while (Joystick(player_nr) & JOY_BUTTON)
2860 if (PendingEvent()) /* got event */
2865 HandleOtherEvents(&event);
2874 void CalibrateJoystick(int player_nr)
2876 if (!CalibrateJoystickMain(player_nr))
2880 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
2881 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
2883 Delay(2000); /* show error message for two seconds */
2887 void DrawSetupScreen()
2889 DeactivateJoystick();
2891 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2893 if (setup_mode == SETUP_MODE_INPUT)
2894 DrawSetupScreen_Input();
2895 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2896 DrawChooseTree(&artwork.gfx_current);
2897 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2898 DrawChooseTree(&artwork.snd_current);
2899 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2900 DrawChooseTree(&artwork.mus_current);
2902 DrawSetupScreen_Generic();
2908 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2910 if (setup_mode == SETUP_MODE_INPUT)
2911 HandleSetupScreen_Input(mx, my, dx, dy, button);
2912 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2913 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2914 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2915 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2916 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2917 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2919 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2924 void HandleGameActions()
2926 if (game_status != GAME_MODE_PLAYING)
2929 if (local_player->LevelSolved)
2932 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2938 if (tape.auto_play && !tape.playing)
2939 AutoPlayTape(); /* continue automatically playing next tape */
2942 /* ---------- new screen button stuff -------------------------------------- */
2944 /* graphic position and size values for buttons and scrollbars */
2945 #define SC_SCROLLBUTTON_XSIZE TILEX
2946 #define SC_SCROLLBUTTON_YSIZE TILEY
2948 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
2949 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
2950 SC_SCROLLBUTTON_YSIZE)
2951 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
2952 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
2953 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
2954 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
2955 SC_SCROLLBUTTON_YSIZE)
2956 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
2957 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
2958 SC_SCROLL_VERTICAL_YSIZE)
2960 #define SC_BORDER_SIZE 14
2964 int gfx_unpressed, gfx_pressed;
2968 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
2971 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
2972 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
2973 SCREEN_CTRL_ID_SCROLL_UP,
2977 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
2978 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
2979 SCREEN_CTRL_ID_SCROLL_DOWN,
2986 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
2987 Bitmap **gfx_unpressed, **gfx_pressed;
2989 int gfx_unpressed, gfx_pressed;
2996 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
2999 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3000 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3002 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3004 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3005 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3006 GD_TYPE_SCROLLBAR_VERTICAL,
3007 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3008 "scroll level series vertically"
3012 static void CreateScreenScrollbuttons()
3014 struct GadgetInfo *gi;
3015 unsigned long event_mask;
3018 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3020 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3021 int gfx_unpressed, gfx_pressed;
3022 int x, y, width, height;
3023 int gd_x1, gd_x2, gd_y1, gd_y2;
3024 int id = scrollbutton_info[i].gadget_id;
3026 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3028 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3029 y = mSY + scrollbutton_info[i].y;
3030 width = SC_SCROLLBUTTON_XSIZE;
3031 height = SC_SCROLLBUTTON_YSIZE;
3033 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3034 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3035 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3037 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3038 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3039 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3040 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3041 gd_x1 = graphic_info[gfx_unpressed].src_x;
3042 gd_y1 = graphic_info[gfx_unpressed].src_y;
3043 gd_x2 = graphic_info[gfx_pressed].src_x;
3044 gd_y2 = graphic_info[gfx_pressed].src_y;
3046 gi = CreateGadget(GDI_CUSTOM_ID, id,
3047 GDI_CUSTOM_TYPE_ID, i,
3048 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3053 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3054 GDI_STATE, GD_BUTTON_UNPRESSED,
3055 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3056 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3057 GDI_DIRECT_DRAW, FALSE,
3058 GDI_EVENT_MASK, event_mask,
3059 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3063 Error(ERR_EXIT, "cannot create gadget");
3065 screen_gadget[id] = gi;
3069 static void CreateScreenScrollbars()
3073 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3075 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3076 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3077 int gfx_unpressed, gfx_pressed;
3079 int x, y, width, height;
3080 int gd_x1, gd_x2, gd_y1, gd_y2;
3081 struct GadgetInfo *gi;
3082 int items_max, items_visible, item_position;
3083 unsigned long event_mask;
3084 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3085 int id = scrollbar_info[i].gadget_id;
3087 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3089 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3090 y = mSY + scrollbar_info[i].y;
3091 width = scrollbar_info[i].width;
3092 height = scrollbar_info[i].height;
3094 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3095 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3097 items_max = num_page_entries;
3098 items_visible = num_page_entries;
3101 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3102 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3103 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3109 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3110 gfx_pressed = scrollbar_info[i].gfx_pressed;
3111 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3112 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3113 gd_x1 = graphic_info[gfx_unpressed].src_x;
3114 gd_y1 = graphic_info[gfx_unpressed].src_y;
3115 gd_x2 = graphic_info[gfx_pressed].src_x;
3116 gd_y2 = graphic_info[gfx_pressed].src_y;
3119 gi = CreateGadget(GDI_CUSTOM_ID, id,
3120 GDI_CUSTOM_TYPE_ID, i,
3121 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3126 GDI_TYPE, scrollbar_info[i].type,
3127 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3128 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3129 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3130 GDI_STATE, GD_BUTTON_UNPRESSED,
3131 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3132 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3133 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3134 GDI_DIRECT_DRAW, FALSE,
3135 GDI_EVENT_MASK, event_mask,
3136 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3140 Error(ERR_EXIT, "cannot create gadget");
3142 screen_gadget[id] = gi;
3146 void CreateScreenGadgets()
3148 int last_game_status = game_status; /* save current game status */
3150 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3153 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3155 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3157 /* copy pointers to clip mask and GC */
3158 scrollbar_bitmap[i]->clip_mask =
3159 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3160 scrollbar_bitmap[i]->stored_clip_gc =
3161 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3163 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3164 scrollbar_bitmap[i],
3165 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3166 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3167 TILEX, TILEY, 0, 0);
3171 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3172 game_status = GAME_MODE_LEVELS;
3174 CreateScreenScrollbuttons();
3175 CreateScreenScrollbars();
3177 game_status = last_game_status; /* restore current game status */
3180 void FreeScreenGadgets()
3184 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3185 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3187 /* prevent freeing clip mask and GC twice */
3188 scrollbar_bitmap[i]->clip_mask = None;
3189 scrollbar_bitmap[i]->stored_clip_gc = None;
3191 FreeBitmap(scrollbar_bitmap[i]);
3195 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3196 FreeGadget(screen_gadget[i]);
3199 void MapChooseTreeGadgets(TreeInfo *ti)
3201 int num_entries = numTreeInfoInGroup(ti);
3204 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3207 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3208 MapGadget(screen_gadget[i]);
3212 void UnmapChooseTreeGadgets()
3216 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3217 UnmapGadget(screen_gadget[i]);
3221 static void HandleScreenGadgets(struct GadgetInfo *gi)
3223 int id = gi->custom_id;
3225 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3230 case SCREEN_CTRL_ID_SCROLL_UP:
3231 if (game_status == GAME_MODE_LEVELS)
3232 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3233 else if (game_status == GAME_MODE_SETUP)
3234 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3237 case SCREEN_CTRL_ID_SCROLL_DOWN:
3238 if (game_status == GAME_MODE_LEVELS)
3239 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3240 else if (game_status == GAME_MODE_SETUP)
3241 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3244 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3245 if (game_status == GAME_MODE_LEVELS)
3246 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3247 else if (game_status == GAME_MODE_SETUP)
3248 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);