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(MICROLEV_XPOS, MICROLEV_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);
349 static void gotoTopLevelDir()
351 /* move upwards to top level directory */
352 while (leveldir_current->node_parent)
354 /* write a "path" into level tree for easy navigation to last level */
355 if (leveldir_current->node_parent->node_group->cl_first == -1)
357 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
358 int leveldir_pos = posTreeInfo(leveldir_current);
359 int num_page_entries;
360 int cl_first, cl_cursor;
362 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
363 num_page_entries = num_leveldirs;
365 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
367 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
368 cl_cursor = leveldir_pos - cl_first;
370 leveldir_current->node_parent->node_group->cl_first = cl_first;
371 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
374 leveldir_current = leveldir_current->node_parent;
378 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
380 static int choice = 5;
384 if (button == MB_MENU_INITIALIZE)
386 drawCursor(choice, FC_RED);
390 if (mx || my) /* mouse input */
393 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
395 else if (dx || dy) /* keyboard input */
397 if (dx && choice == 1)
398 x = (dx < 0 ? 10 : 14);
403 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
404 (x == 14 && level_nr < leveldir_current->last_level)) &&
407 static unsigned long level_delay = 0;
408 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
409 int old_level_nr = level_nr;
412 new_level_nr = level_nr + (x == 10 ? -step : +step);
413 if (new_level_nr < leveldir_current->first_level)
414 new_level_nr = leveldir_current->first_level;
415 if (new_level_nr > leveldir_current->last_level)
416 new_level_nr = leveldir_current->last_level;
418 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
419 new_level_nr = leveldir_current->handicap_level;
421 if (new_level_nr != old_level_nr &&
422 DelayReached(&level_delay, GADGET_FRAME_DELAY))
424 level_nr = new_level_nr;
426 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
430 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
434 DrawCompleteVideoDisplay();
436 /* needed because DrawMicroLevel() takes some time */
439 DelayReached(&level_delay, 0); /* reset delay counter */
442 else if (IN_VIS_FIELD(x, y) &&
443 y >= 0 && y <= 7 && (y != 1 || x < 10))
449 drawCursor(y, FC_RED);
450 drawCursor(choice, FC_BLUE);
458 game_status = GAME_MODE_PSEUDO_TYPENAME;
459 HandleTypeName(strlen(setup.player_name), 0);
465 game_status = GAME_MODE_LEVELS;
466 SaveLevelSetup_LastSeries();
467 SaveLevelSetup_SeriesInfo();
476 game_status = GAME_MODE_SCORES;
481 if (leveldir_current->readonly &&
482 strcmp(setup.player_name, "Artsoft") != 0)
483 Request("This level is read only !", REQ_CONFIRM);
484 game_status = GAME_MODE_EDITOR;
489 game_status = GAME_MODE_INFO;
490 info_mode = INFO_MODE_MAIN;
495 if (setup.autorecord)
496 TapeStartRecording();
498 #if defined(NETWORK_AVALIABLE)
500 SendToServer_StartPlaying();
504 game_status = GAME_MODE_PLAYING;
511 game_status = GAME_MODE_SETUP;
512 setup_mode = SETUP_MODE_MAIN;
517 SaveLevelSetup_LastSeries();
518 SaveLevelSetup_SeriesInfo();
519 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
520 game_status = GAME_MODE_QUIT;
525 if (game_status == GAME_MODE_MAIN)
527 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
533 /* ========================================================================= */
534 /* info screen functions */
535 /* ========================================================================= */
537 static struct TokenInfo *info_info;
538 static int num_info_info;
540 static void execInfoElements()
542 info_mode = INFO_MODE_ELEMENTS;
546 static void execInfoMusic()
548 info_mode = INFO_MODE_MUSIC;
552 static void execInfoCredits()
554 info_mode = INFO_MODE_CREDITS;
558 static void execInfoProgram()
560 info_mode = INFO_MODE_PROGRAM;
564 static void execInfoLevelSet()
566 info_mode = INFO_MODE_LEVELSET;
570 static void execExitInfo()
572 game_status = GAME_MODE_MAIN;
576 static struct TokenInfo info_info_main[] =
578 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
579 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
580 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
581 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
582 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
583 { TYPE_EMPTY, NULL, "" },
584 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
589 static void DrawInfoScreen_Main()
594 CloseDoor(DOOR_CLOSE_2);
598 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
600 info_info = info_info_main;
603 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
605 int ypos = MENU_SCREEN_START_YPOS + i;
606 int font_nr = FONT_MENU_1;
608 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
610 if (info_info[i].type & TYPE_ENTER_MENU)
611 initCursor(i, IMG_MENU_BUTTON_RIGHT);
612 else if (info_info[i].type & TYPE_LEAVE_MENU)
613 initCursor(i, IMG_MENU_BUTTON_LEFT);
614 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
615 initCursor(i, IMG_MENU_BUTTON);
626 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
629 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
631 static int choice_store[MAX_INFO_MODES];
632 int choice = choice_store[info_mode]; /* always starts with 0 */
636 if (button == MB_MENU_INITIALIZE)
638 /* advance to first valid menu entry */
639 while (choice < num_info_info &&
640 info_info[choice].type & TYPE_SKIP_ENTRY)
642 choice_store[info_mode] = choice;
644 drawCursor(choice, FC_RED);
647 else if (button == MB_MENU_LEAVE)
649 for (y = 0; y < num_info_info; y++)
651 if (info_info[y].type & TYPE_LEAVE_MENU)
653 void (*menu_callback_function)(void) = info_info[y].value;
655 menu_callback_function();
656 break; /* absolutely needed because function changes 'info_info'! */
663 if (mx || my) /* mouse input */
666 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
668 else if (dx || dy) /* keyboard input */
672 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
674 if (info_info[choice].type & menu_navigation_type ||
675 info_info[choice].type & TYPE_ENTER_SCREEN ||
676 info_info[choice].type & TYPE_BOOLEAN_STYLE)
677 button = MB_MENU_CHOICE;
682 /* jump to next non-empty menu entry (up or down) */
683 while (y > 0 && y < num_info_info - 1 &&
684 info_info[y].type & TYPE_SKIP_ENTRY)
688 if (IN_VIS_FIELD(x, y) &&
689 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
695 drawCursor(y, FC_RED);
696 drawCursor(choice, FC_BLUE);
697 choice = choice_store[info_mode] = y;
700 else if (!(info_info[y].type & TYPE_GHOSTED))
702 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
704 void (*menu_callback_function)(void) = info_info[choice].value;
706 menu_callback_function();
712 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
714 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
715 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
716 int xstart = mSX + 16;
717 int ystart = mSY + 64 + 2 * 32;
718 int ystep = TILEY + 4;
719 int element, action, direction;
727 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
728 infoscreen_step[i] = infoscreen_frame[i] = 0;
730 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
734 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
736 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
737 "Press any key or button for next page");
743 while (helpanim_info[j].element != HELPANIM_LIST_END)
745 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
750 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
759 j += infoscreen_step[i - start];
761 element = helpanim_info[j].element;
762 action = helpanim_info[j].action;
763 direction = helpanim_info[j].direction;
765 if (action != -1 && direction != -1)
766 graphic = el_act_dir2img(element, action, direction);
767 else if (action != -1)
768 graphic = el_act2img(element, action);
769 else if (direction != -1)
770 graphic = el_act2img(element, direction);
772 graphic = el2img(element);
774 delay = helpanim_info[j++].delay;
779 if (infoscreen_frame[i - start] == 0)
782 infoscreen_frame[i - start] = delay - 1;
786 sync_frame = delay - infoscreen_frame[i - start];
787 infoscreen_frame[i - start]--;
790 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
792 if (!infoscreen_frame[i - start])
793 infoscreen_step[i - start] = 0;
797 if (!infoscreen_frame[i - start])
798 infoscreen_step[i - start]++;
799 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
805 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
807 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
808 graphic, sync_frame, USE_MASKING);
811 DrawInfoScreen_HelpText(element, action, direction, i - start);
816 redraw_mask |= REDRAW_FIELD;
821 static char *getHelpText(int element, int action, int direction)
823 char token[MAX_LINE_LEN];
825 strcpy(token, element_info[element].token_name);
828 strcat(token, element_action_info[action].suffix);
831 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
833 return getHashEntry(helptext_info, token);
836 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
839 int font_nr = FONT_TEXT_2;
841 int font_nr = FONT_LEVEL_NUMBER;
843 int font_width = getFontWidth(font_nr);
844 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
845 int sy = mSY + 65 + 2 * 32 + 1;
846 int ystep = TILEY + 4;
848 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
849 int max_lines_per_text = 2;
852 if (action != -1 && direction != -1) /* element.action.direction */
853 text = getHelpText(element, action, direction);
855 if (text == NULL && action != -1) /* element.action */
856 text = getHelpText(element, action, -1);
858 if (text == NULL && direction != -1) /* element.direction */
859 text = getHelpText(element, -1, direction);
861 if (text == NULL) /* base element */
862 text = getHelpText(element, -1, -1);
864 if (text == NULL) /* not found */
865 text = "No description available";
867 if (strlen(text) <= max_chars_per_line) /* only one line of text */
868 sy += getFontHeight(font_nr) / 2;
870 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
871 max_chars_per_line, max_lines_per_text);
874 void DrawInfoScreen_Elements()
879 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
885 void HandleInfoScreen_Elements(int button)
887 static unsigned long info_delay = 0;
888 static int num_anims;
889 static int num_pages;
891 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
892 int button_released = !button;
895 if (button == MB_MENU_INITIALIZE)
897 boolean new_element = TRUE;
900 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
902 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
904 else if (new_element)
911 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
914 else if (button == MB_MENU_LEAVE)
916 info_mode = INFO_MODE_MAIN;
922 if (button_released || button == MB_MENU_INITIALIZE)
924 if (button != MB_MENU_INITIALIZE)
927 if (page >= num_pages)
929 FadeSoundsAndMusic();
931 info_mode = INFO_MODE_MAIN;
937 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
941 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
942 if (page < num_pages)
943 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
945 PlayMenuSoundIfLoop();
949 void DrawInfoScreen_Music()
956 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
959 void HandleInfoScreen_Music(int button)
961 static struct MusicFileInfo *list = NULL;
962 int ystart = 150, dy = 30;
963 int ybottom = SYSIZE - 20;
964 int button_released = !button;
966 if (button == MB_MENU_INITIALIZE)
968 list = music_file_info;
972 FadeSoundsAndMusic();
977 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
979 DrawTextSCentered(ybottom, FONT_TEXT_4,
980 "Press any key or button for info menu");
985 else if (button == MB_MENU_LEAVE)
987 info_mode = INFO_MODE_MAIN;
993 if (button_released || button == MB_MENU_INITIALIZE)
997 if (button != MB_MENU_INITIALIZE)
1003 info_mode = INFO_MODE_MAIN;
1009 FadeSoundsAndMusic();
1016 int sound = list->music;
1018 if (sound_info[sound].loop)
1019 PlaySoundLoop(sound);
1023 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1027 PlayMusic(list->music);
1029 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1032 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1034 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1035 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1037 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1040 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1042 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1043 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1045 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1047 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1050 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1052 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1053 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1055 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1057 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1060 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1062 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1063 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1065 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1067 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1070 DrawTextSCentered(ybottom, FONT_TEXT_4,
1071 "Press any key or button for next page");
1074 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1075 PlaySoundLoop(list->music);
1078 void DrawInfoScreen_Credits()
1080 int ystart = 150, ystep = 30;
1081 int ybottom = SYSIZE - 20;
1083 FadeSoundsAndMusic();
1088 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1089 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1090 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1091 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1092 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1093 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1094 "...and many thanks to all contributors");
1095 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1097 DrawTextSCentered(ybottom, FONT_TEXT_4,
1098 "Press any key or button for info menu");
1101 void HandleInfoScreen_Credits(int button)
1103 int button_released = !button;
1105 if (button == MB_MENU_LEAVE)
1107 info_mode = INFO_MODE_MAIN;
1113 if (button_released)
1115 FadeSoundsAndMusic();
1117 info_mode = INFO_MODE_MAIN;
1122 PlayMenuSoundIfLoop();
1126 void DrawInfoScreen_Program()
1128 int ystart = 150, ystep = 30;
1129 int ybottom = SYSIZE - 20;
1134 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1136 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1137 "This game is Freeware!");
1138 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1139 "If you like it, send e-mail to:");
1140 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1141 "info@artsoft.org");
1142 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1143 "or SnailMail to:");
1144 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1146 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1147 "Detmolder Strasse 189");
1148 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1150 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1153 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1154 "If you have created new levels,");
1155 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1156 "send them to me to include them!");
1157 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1160 DrawTextSCentered(ybottom, FONT_TEXT_4,
1161 "Press any key or button for info menu");
1164 void HandleInfoScreen_Program(int button)
1166 int button_released = !button;
1168 if (button == MB_MENU_LEAVE)
1170 info_mode = INFO_MODE_MAIN;
1176 if (button_released)
1178 FadeSoundsAndMusic();
1180 info_mode = INFO_MODE_MAIN;
1185 PlayMenuSoundIfLoop();
1189 void DrawInfoScreen_LevelSet()
1192 int ybottom = SYSIZE - 20;
1193 char *filename = getLevelSetInfoFilename();
1195 int font_nr = FONT_TEXT_2;
1197 int font_nr = FONT_LEVEL_NUMBER;
1199 int font_width = getFontWidth(font_nr);
1200 int font_height = getFontHeight(font_nr);
1203 int sx = SX + pad_x;
1204 int sy = SY + pad_y;
1205 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1206 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1211 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1213 DrawTextSCentered(ybottom, FONT_TEXT_4,
1214 "Press any key or button for info menu");
1216 if (filename != NULL)
1217 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1218 max_lines_per_screen);
1220 DrawTextSCentered(ystart, FONT_TEXT_2,
1221 "No information for this level set.");
1224 void HandleInfoScreen_LevelSet(int button)
1226 int button_released = !button;
1228 if (button == MB_MENU_LEAVE)
1230 info_mode = INFO_MODE_MAIN;
1236 if (button_released)
1238 FadeSoundsAndMusic();
1240 info_mode = INFO_MODE_MAIN;
1245 PlayMenuSoundIfLoop();
1249 void DrawInfoScreen()
1251 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1253 if (info_mode == INFO_MODE_ELEMENTS)
1254 DrawInfoScreen_Elements();
1255 else if (info_mode == INFO_MODE_MUSIC)
1256 DrawInfoScreen_Music();
1257 else if (info_mode == INFO_MODE_CREDITS)
1258 DrawInfoScreen_Credits();
1259 else if (info_mode == INFO_MODE_PROGRAM)
1260 DrawInfoScreen_Program();
1261 else if (info_mode == INFO_MODE_LEVELSET)
1262 DrawInfoScreen_LevelSet();
1264 DrawInfoScreen_Main();
1266 if (info_mode != INFO_MODE_MUSIC)
1273 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1275 if (info_mode == INFO_MODE_ELEMENTS)
1276 HandleInfoScreen_Elements(button);
1277 else if (info_mode == INFO_MODE_MUSIC)
1278 HandleInfoScreen_Music(button);
1279 else if (info_mode == INFO_MODE_CREDITS)
1280 HandleInfoScreen_Credits(button);
1281 else if (info_mode == INFO_MODE_PROGRAM)
1282 HandleInfoScreen_Program(button);
1283 else if (info_mode == INFO_MODE_LEVELSET)
1284 HandleInfoScreen_LevelSet(button);
1286 HandleInfoScreen_Main(mx, my, dx, dy, button);
1292 /* ========================================================================= */
1293 /* type name functions */
1294 /* ========================================================================= */
1296 void HandleTypeName(int newxpos, Key key)
1298 static int xpos = 0, ypos = 2;
1299 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1300 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1301 int startx = mSX + 32 + name_width;
1302 int starty = mSY + ypos * 32;
1308 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1309 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1314 if (((key >= KSYM_A && key <= KSYM_Z) ||
1315 (key >= KSYM_a && key <= KSYM_z)) &&
1316 xpos < MAX_PLAYER_NAME_LEN)
1320 if (key >= KSYM_A && key <= KSYM_Z)
1321 ascii = 'A' + (char)(key - KSYM_A);
1323 ascii = 'a' + (char)(key - KSYM_a);
1325 setup.player_name[xpos] = ascii;
1326 setup.player_name[xpos + 1] = 0;
1329 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1330 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1332 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1335 setup.player_name[xpos] = 0;
1337 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1339 else if (key == KSYM_Return && xpos > 0)
1341 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1342 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1345 game_status = GAME_MODE_MAIN;
1350 /* ========================================================================= */
1351 /* tree menu functions */
1352 /* ========================================================================= */
1354 static void DrawChooseTree(TreeInfo **ti_ptr)
1358 FreeScreenGadgets();
1359 CreateScreenGadgets();
1361 CloseDoor(DOOR_CLOSE_2);
1365 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1366 MapChooseTreeGadgets(*ti_ptr);
1372 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1374 struct GadgetInfo *gi = screen_gadget[id];
1375 int items_max, items_visible, item_position;
1377 items_max = numTreeInfoInGroup(ti);
1378 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1379 item_position = first_entry;
1381 if (item_position > items_max - items_visible)
1382 item_position = items_max - items_visible;
1384 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1385 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1386 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1389 static void drawChooseTreeList(int first_entry, int num_page_entries,
1393 char buffer[SCR_FIELDX * 2];
1394 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1395 char *title_string = NULL;
1396 int xoffset_setup = 16;
1397 int yoffset_setup = 16;
1398 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1399 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1400 int last_game_status = game_status; /* save current game status */
1403 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1404 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1405 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1406 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1408 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1410 /* force LEVELS font on artwork setup screen */
1411 game_status = GAME_MODE_LEVELS;
1413 /* clear tree list area, but not title or scrollbar */
1414 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1415 SXSIZE - 32 + menu.scrollbar_xoffset,
1416 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1418 for (i = 0; i < num_page_entries; i++)
1420 TreeInfo *node, *node_first;
1421 int entry_pos = first_entry + i;
1422 int ypos = MENU_SCREEN_START_YPOS + i;
1424 node_first = getTreeInfoFirstGroupEntry(ti);
1425 node = getTreeInfoFromPos(node_first, entry_pos);
1427 strncpy(buffer, node->name , max_buffer_len);
1428 buffer[max_buffer_len] = '\0';
1430 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1432 if (node->parent_link)
1433 initCursor(i, IMG_MENU_BUTTON_LEFT);
1434 else if (node->level_group)
1435 initCursor(i, IMG_MENU_BUTTON_RIGHT);
1437 initCursor(i, IMG_MENU_BUTTON);
1440 game_status = last_game_status; /* restore current game status */
1442 redraw_mask |= REDRAW_FIELD;
1445 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1447 TreeInfo *node, *node_first;
1448 int x, last_redraw_mask = redraw_mask;
1450 if (ti->type != TREE_TYPE_LEVEL_DIR)
1453 node_first = getTreeInfoFirstGroupEntry(ti);
1454 node = getTreeInfoFromPos(node_first, entry_pos);
1456 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1458 if (node->parent_link)
1459 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1461 else if (node->level_group)
1462 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1464 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1465 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1466 node->levels, node->class_desc);
1468 /* let BackToFront() redraw only what is needed */
1469 redraw_mask = last_redraw_mask | REDRAW_TILES;
1470 for (x = 0; x < SCR_FIELDX; x++)
1471 MarkTileDirty(x, 1);
1474 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1477 TreeInfo *ti = *ti_ptr;
1479 int y = ti->cl_cursor;
1480 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1481 int num_entries = numTreeInfoInGroup(ti);
1482 int num_page_entries;
1483 int last_game_status = game_status; /* save current game status */
1485 /* force LEVELS draw offset on choose level and artwork setup screen */
1486 game_status = GAME_MODE_LEVELS;
1488 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1489 num_page_entries = num_entries;
1491 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1493 game_status = last_game_status; /* restore current game status */
1495 if (button == MB_MENU_INITIALIZE)
1497 int num_entries = numTreeInfoInGroup(ti);
1498 int entry_pos = posTreeInfo(ti);
1500 if (ti->cl_first == -1)
1502 /* only on initialization */
1503 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1504 ti->cl_cursor = entry_pos - ti->cl_first;
1506 else if (ti->cl_cursor >= num_page_entries ||
1507 (num_entries > num_page_entries &&
1508 num_entries - ti->cl_first < num_page_entries))
1510 /* only after change of list size (by custom graphic configuration) */
1511 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1512 ti->cl_cursor = entry_pos - ti->cl_first;
1515 if (dx == 999) /* first entry is set by scrollbar position */
1518 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1521 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1522 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1523 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1527 else if (button == MB_MENU_LEAVE)
1529 if (ti->node_parent)
1531 *ti_ptr = ti->node_parent;
1532 DrawChooseTree(ti_ptr);
1534 else if (game_status == GAME_MODE_SETUP)
1540 game_status = GAME_MODE_MAIN;
1547 if (mx || my) /* mouse input */
1549 int last_game_status = game_status; /* save current game status */
1551 /* force LEVELS draw offset on artwork setup screen */
1552 game_status = GAME_MODE_LEVELS;
1554 x = (mx - mSX) / 32;
1555 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1557 game_status = last_game_status; /* restore current game status */
1559 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1561 /* move cursor instead of scrolling when already at start/end of list */
1562 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1564 else if (dy == +1 * SCROLL_LINE &&
1565 ti->cl_first + num_page_entries == num_entries)
1568 /* handle scrolling screen one line or page */
1569 if (ti->cl_cursor + dy < 0 ||
1570 ti->cl_cursor + dy > num_page_entries - 1)
1572 if (ABS(dy) == SCROLL_PAGE)
1573 step = num_page_entries - 1;
1575 if (dy < 0 && ti->cl_first > 0)
1577 /* scroll page/line up */
1579 ti->cl_first -= step;
1580 if (ti->cl_first < 0)
1583 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1584 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1585 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1586 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1589 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1591 /* scroll page/line down */
1593 ti->cl_first += step;
1594 if (ti->cl_first + num_page_entries > num_entries)
1595 ti->cl_first = MAX(0, num_entries - num_page_entries);
1597 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1598 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1599 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1600 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1607 /* handle moving cursor one line */
1608 y = ti->cl_cursor + dy;
1613 TreeInfo *node_first, *node_cursor;
1614 int entry_pos = ti->cl_first + y;
1616 node_first = getTreeInfoFirstGroupEntry(ti);
1617 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1619 if (node_cursor->node_group)
1621 node_cursor->cl_first = ti->cl_first;
1622 node_cursor->cl_cursor = ti->cl_cursor;
1623 *ti_ptr = node_cursor->node_group;
1624 DrawChooseTree(ti_ptr);
1629 else if (dx == -1 && ti->node_parent)
1631 *ti_ptr = ti->node_parent;
1632 DrawChooseTree(ti_ptr);
1637 if (IN_VIS_FIELD(x, y) &&
1638 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1639 y >= 0 && y < num_page_entries)
1643 if (y != ti->cl_cursor)
1645 drawChooseTreeCursor(y, FC_RED);
1646 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1647 drawChooseTreeInfo(ti->cl_first + y, ti);
1653 TreeInfo *node_first, *node_cursor;
1654 int entry_pos = ti->cl_first + y;
1656 node_first = getTreeInfoFirstGroupEntry(ti);
1657 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1659 if (node_cursor->node_group)
1661 node_cursor->cl_first = ti->cl_first;
1662 node_cursor->cl_cursor = ti->cl_cursor;
1663 *ti_ptr = node_cursor->node_group;
1664 DrawChooseTree(ti_ptr);
1666 else if (node_cursor->parent_link)
1668 *ti_ptr = node_cursor->node_parent;
1669 DrawChooseTree(ti_ptr);
1673 node_cursor->cl_first = ti->cl_first;
1674 node_cursor->cl_cursor = ti->cl_cursor;
1675 *ti_ptr = node_cursor;
1677 if (ti->type == TREE_TYPE_LEVEL_DIR)
1679 LoadLevelSetup_SeriesInfo();
1681 SaveLevelSetup_LastSeries();
1682 SaveLevelSetup_SeriesInfo();
1686 if (game_status == GAME_MODE_SETUP)
1692 game_status = GAME_MODE_MAIN;
1700 void DrawChooseLevel()
1702 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1704 DrawChooseTree(&leveldir_current);
1710 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1712 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1717 void DrawHallOfFame(int highlight_position)
1720 FadeSoundsAndMusic();
1721 CloseDoor(DOOR_CLOSE_2);
1723 if (highlight_position < 0)
1724 LoadScore(level_nr);
1732 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1735 static void drawHallOfFameList(int first_entry, int highlight_position)
1739 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1742 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1743 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1745 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1747 int entry = first_entry + i;
1748 boolean active = (entry == highlight_position);
1749 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1750 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1751 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1752 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1753 int dx1 = 3 * getFontWidth(font_nr1);
1754 int dx2 = dx1 + getFontWidth(font_nr1);
1755 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1756 int sy = mSY + 64 + i * 32;
1758 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1759 DrawText(mSX + dx1, sy, ".", font_nr1);
1760 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1761 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1762 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1763 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1766 redraw_mask |= REDRAW_FIELD;
1769 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1771 static int first_entry = 0;
1772 static int highlight_position = 0;
1773 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1774 int button_released = !button;
1776 if (button == MB_MENU_INITIALIZE)
1779 highlight_position = mx;
1780 drawHallOfFameList(first_entry, highlight_position);
1785 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1786 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1790 if (first_entry > 0)
1792 first_entry -= step;
1793 if (first_entry < 0)
1796 drawHallOfFameList(first_entry, highlight_position);
1801 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1803 first_entry += step;
1804 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1805 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1807 drawHallOfFameList(first_entry, highlight_position);
1810 else if (button_released)
1812 FadeSound(SND_BACKGROUND_SCORES);
1813 game_status = GAME_MODE_MAIN;
1817 if (game_status == GAME_MODE_SCORES)
1818 PlayMenuSoundIfLoop();
1824 /* ========================================================================= */
1825 /* setup screen functions */
1826 /* ========================================================================= */
1828 static struct TokenInfo *setup_info;
1829 static int num_setup_info;
1831 static char *graphics_set_name;
1832 static char *sounds_set_name;
1833 static char *music_set_name;
1835 static void execSetupMain()
1837 setup_mode = SETUP_MODE_MAIN;
1841 static void execSetupGame()
1843 setup_mode = SETUP_MODE_GAME;
1847 static void execSetupEditor()
1849 setup_mode = SETUP_MODE_EDITOR;
1853 static void execSetupGraphics()
1855 setup_mode = SETUP_MODE_GRAPHICS;
1859 static void execSetupSound()
1861 setup_mode = SETUP_MODE_SOUND;
1865 static void execSetupArtwork()
1867 setup.graphics_set = artwork.gfx_current->identifier;
1868 setup.sounds_set = artwork.snd_current->identifier;
1869 setup.music_set = artwork.mus_current->identifier;
1871 /* needed if last screen (setup choice) changed graphics, sounds or music */
1872 ReloadCustomArtwork(0);
1874 /* needed for displaying artwork name instead of artwork identifier */
1875 graphics_set_name = artwork.gfx_current->name;
1876 sounds_set_name = artwork.snd_current->name;
1877 music_set_name = artwork.mus_current->name;
1879 setup_mode = SETUP_MODE_ARTWORK;
1883 static void execSetupChooseGraphics()
1885 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1889 static void execSetupChooseSounds()
1891 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1895 static void execSetupChooseMusic()
1897 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1901 static void execSetupInput()
1903 setup_mode = SETUP_MODE_INPUT;
1907 static void execSetupShortcut()
1909 setup_mode = SETUP_MODE_SHORTCUT;
1913 static void execExitSetup()
1915 game_status = GAME_MODE_MAIN;
1919 static void execSaveAndExitSetup()
1925 static struct TokenInfo setup_info_main[] =
1927 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1928 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1929 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1930 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1931 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1932 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1933 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1934 { TYPE_EMPTY, NULL, "" },
1935 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1936 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1941 static struct TokenInfo setup_info_game[] =
1943 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1944 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1945 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1946 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1947 { TYPE_EMPTY, NULL, "" },
1948 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1953 static struct TokenInfo setup_info_editor[] =
1956 { TYPE_STRING, NULL, "Offer Special Elements:"},
1958 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1959 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1960 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,"E.M. Club:" },
1961 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1962 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1963 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1964 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1965 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1966 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1967 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1968 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1969 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1970 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1971 { TYPE_EMPTY, NULL, "" },
1972 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1977 static struct TokenInfo setup_info_graphics[] =
1979 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1980 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1981 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1983 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1984 { TYPE_SWITCH, &setup.fading, "Fading:" },
1986 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1987 { TYPE_SWITCH, &setup.toons, "Toons:" },
1988 { TYPE_EMPTY, NULL, "" },
1989 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1994 static struct TokenInfo setup_info_sound[] =
1996 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
1997 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
1998 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
1999 { TYPE_EMPTY, NULL, "" },
2000 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2005 static struct TokenInfo setup_info_artwork[] =
2007 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2008 { TYPE_STRING, &graphics_set_name, "" },
2009 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2010 { TYPE_STRING, &sounds_set_name, "" },
2011 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2012 { TYPE_STRING, &music_set_name, "" },
2013 { TYPE_EMPTY, NULL, "" },
2014 { TYPE_STRING, NULL, "Override Level Artwork:"},
2015 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2016 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2017 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2018 { TYPE_EMPTY, NULL, "" },
2019 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2024 static struct TokenInfo setup_info_shortcut[] =
2026 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2027 { TYPE_KEY, &setup.shortcut.save_game, "" },
2028 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2029 { TYPE_KEY, &setup.shortcut.load_game, "" },
2030 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2031 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2032 { TYPE_EMPTY, NULL, "" },
2033 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2034 { TYPE_EMPTY, NULL, "" },
2035 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2040 static Key getSetupKey()
2042 Key key = KSYM_UNDEFINED;
2043 boolean got_key_event = FALSE;
2045 while (!got_key_event)
2047 if (PendingEvent()) /* got event */
2055 case EVENT_KEYPRESS:
2057 key = GetEventKey((KeyEvent *)&event, TRUE);
2059 /* press 'Escape' or 'Enter' to keep the existing key binding */
2060 if (key == KSYM_Escape || key == KSYM_Return)
2061 key = KSYM_UNDEFINED; /* keep old value */
2063 got_key_event = TRUE;
2067 case EVENT_KEYRELEASE:
2068 key_joystick_mapping = 0;
2072 HandleOtherEvents(&event);
2080 /* don't eat all CPU time */
2087 static void drawSetupValue(int pos)
2089 int xpos = MENU_SCREEN_VALUE_XPOS;
2090 int ypos = MENU_SCREEN_START_YPOS + pos;
2091 int font_nr = FONT_VALUE_1;
2092 int type = setup_info[pos].type;
2093 void *value = setup_info[pos].value;
2094 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2097 if (value_string == NULL)
2100 if (type & TYPE_KEY)
2104 if (type & TYPE_QUERY)
2106 value_string = "<press key>";
2107 font_nr = FONT_INPUT_1_ACTIVE;
2110 else if (type & TYPE_STRING)
2112 int max_value_len = (SCR_FIELDX - 2) * 2;
2115 font_nr = FONT_VALUE_2;
2117 if (strlen(value_string) > max_value_len)
2118 value_string[max_value_len] = '\0';
2120 else if (type & TYPE_BOOLEAN_STYLE)
2122 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2125 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2126 (xpos == 3 ? " " : " "), font_nr);
2127 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2130 static void changeSetupValue(int pos)
2132 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2134 *(boolean *)setup_info[pos].value ^= TRUE;
2136 else if (setup_info[pos].type & TYPE_KEY)
2140 setup_info[pos].type |= TYPE_QUERY;
2141 drawSetupValue(pos);
2142 setup_info[pos].type &= ~TYPE_QUERY;
2144 key = getSetupKey();
2145 if (key != KSYM_UNDEFINED)
2146 *(Key *)setup_info[pos].value = key;
2149 drawSetupValue(pos);
2152 static void DrawSetupScreen_Generic()
2154 char *title_string = NULL;
2158 CloseDoor(DOOR_CLOSE_2);
2162 if (setup_mode == SETUP_MODE_MAIN)
2164 setup_info = setup_info_main;
2165 title_string = "Setup";
2167 else if (setup_mode == SETUP_MODE_GAME)
2169 setup_info = setup_info_game;
2170 title_string = "Setup Game";
2172 else if (setup_mode == SETUP_MODE_EDITOR)
2174 setup_info = setup_info_editor;
2175 title_string = "Setup Editor";
2177 else if (setup_mode == SETUP_MODE_GRAPHICS)
2179 setup_info = setup_info_graphics;
2180 title_string = "Setup Graphics";
2182 else if (setup_mode == SETUP_MODE_SOUND)
2184 setup_info = setup_info_sound;
2185 title_string = "Setup Sound";
2187 else if (setup_mode == SETUP_MODE_ARTWORK)
2189 setup_info = setup_info_artwork;
2190 title_string = "Custom Artwork";
2192 else if (setup_mode == SETUP_MODE_SHORTCUT)
2194 setup_info = setup_info_shortcut;
2195 title_string = "Setup Shortcuts";
2198 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2201 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2203 void *value_ptr = setup_info[i].value;
2204 int ypos = MENU_SCREEN_START_YPOS + i;
2205 int font_nr = FONT_MENU_1;
2207 /* set some entries to "unchangeable" according to other variables */
2208 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2209 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2210 (value_ptr == &setup.sound_music && !audio.music_available) ||
2211 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2212 setup_info[i].type |= TYPE_GHOSTED;
2215 if (setup_info[i].type & TYPE_STRING ||
2216 (setup_info[i].type & TYPE_SWITCH && setup_mode == SETUP_MODE_EDITOR))
2217 font_nr = FONT_MENU_2;
2219 if (setup_info[i].type & TYPE_STRING)
2220 font_nr = FONT_MENU_2;
2223 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2225 if (setup_info[i].type & TYPE_ENTER_MENU)
2226 initCursor(i, IMG_MENU_BUTTON_RIGHT);
2227 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2228 initCursor(i, IMG_MENU_BUTTON_LEFT);
2229 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2230 initCursor(i, IMG_MENU_BUTTON);
2232 if (setup_info[i].type & TYPE_VALUE)
2240 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2243 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2245 static int choice_store[MAX_SETUP_MODES];
2246 int choice = choice_store[setup_mode]; /* always starts with 0 */
2250 if (button == MB_MENU_INITIALIZE)
2252 /* advance to first valid menu entry */
2253 while (choice < num_setup_info &&
2254 setup_info[choice].type & TYPE_SKIP_ENTRY)
2256 choice_store[setup_mode] = choice;
2258 drawCursor(choice, FC_RED);
2261 else if (button == MB_MENU_LEAVE)
2263 for (y = 0; y < num_setup_info; y++)
2265 if (setup_info[y].type & TYPE_LEAVE_MENU)
2267 void (*menu_callback_function)(void) = setup_info[y].value;
2269 menu_callback_function();
2270 break; /* absolutely needed because function changes 'setup_info'! */
2277 if (mx || my) /* mouse input */
2279 x = (mx - mSX) / 32;
2280 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2282 else if (dx || dy) /* keyboard input */
2286 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2288 if (setup_info[choice].type & menu_navigation_type ||
2289 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2290 button = MB_MENU_CHOICE;
2295 /* jump to next non-empty menu entry (up or down) */
2296 while (y > 0 && y < num_setup_info - 1 &&
2297 setup_info[y].type & TYPE_SKIP_ENTRY)
2301 if (IN_VIS_FIELD(x, y) &&
2302 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2308 drawCursor(y, FC_RED);
2309 drawCursor(choice, FC_BLUE);
2310 choice = choice_store[setup_mode] = y;
2313 else if (!(setup_info[y].type & TYPE_GHOSTED))
2315 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2317 void (*menu_callback_function)(void) = setup_info[choice].value;
2319 menu_callback_function();
2323 if (setup_info[y].type & TYPE_KEYTEXT &&
2324 setup_info[y + 1].type & TYPE_KEY)
2327 if (setup_info[y].type & TYPE_VALUE)
2328 changeSetupValue(y);
2334 void DrawSetupScreen_Input()
2338 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2340 initCursor(0, IMG_MENU_BUTTON);
2341 initCursor(1, IMG_MENU_BUTTON);
2342 initCursor(2, IMG_MENU_BUTTON_RIGHT);
2343 initCursor(13, IMG_MENU_BUTTON_LEFT);
2345 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2346 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2348 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2349 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2350 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2353 DeactivateJoystickForCalibration();
2354 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2355 "Joysticks deactivated on this screen");
2358 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2363 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2365 if (device_name == NULL)
2368 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2371 if (strlen(device_name) > 1)
2373 char c1 = device_name[strlen(device_name) - 1];
2374 char c2 = device_name[strlen(device_name) - 2];
2376 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2377 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2380 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2381 strlen(device_name));
2384 static void drawPlayerSetupInputInfo(int player_nr)
2387 static struct SetupKeyboardInfo custom_key;
2394 { &custom_key.left, "Joystick Left" },
2395 { &custom_key.right, "Joystick Right" },
2396 { &custom_key.up, "Joystick Up" },
2397 { &custom_key.down, "Joystick Down" },
2398 { &custom_key.snap, "Button 1" },
2399 { &custom_key.drop, "Button 2" }
2401 static char *joystick_name[MAX_PLAYERS] =
2409 custom_key = setup.input[player_nr].key;
2411 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2413 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2415 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2416 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2418 DrawGraphicThruMask(8, 2, PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2421 if (setup.input[player_nr].use_joystick)
2423 char *device_name = setup.input[player_nr].joy.device_name;
2425 DrawText(mSX+8*32, mSY+3*32,
2426 joystick_name[getJoystickNrFromDeviceName(device_name)],
2428 DrawText(mSX+32, mSY+4*32, "Calibrate", FONT_MENU_1);
2432 DrawText(mSX+8*32, mSY+3*32, "Keyboard ", FONT_VALUE_1);
2433 DrawText(mSX+32, mSY+4*32, "Customize", FONT_MENU_1);
2436 DrawText(mSX+32, mSY+5*32, "Actual Settings:", FONT_MENU_1);
2437 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2438 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2439 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2440 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2441 DrawText(mSX+2*32, mSY+6*32, ":", FONT_VALUE_OLD);
2442 DrawText(mSX+2*32, mSY+7*32, ":", FONT_VALUE_OLD);
2443 DrawText(mSX+2*32, mSY+8*32, ":", FONT_VALUE_OLD);
2444 DrawText(mSX+2*32, mSY+9*32, ":", FONT_VALUE_OLD);
2445 DrawText(mSX+32, mSY+10*32, "Snap Field:", FONT_VALUE_OLD);
2446 DrawText(mSX+32, mSY+12*32, "Drop Element:", FONT_VALUE_OLD);
2448 for (i = 0; i < 6; i++)
2450 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2452 DrawText(mSX + 3*32, mSY + ypos*32,
2454 DrawText(mSX + 3*32, mSY + ypos*32,
2455 (setup.input[player_nr].use_joystick ?
2457 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2461 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2463 static int choice = 0;
2464 static int player_nr = 0;
2467 int pos_start = SETUPINPUT_SCREEN_POS_START;
2468 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2469 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2470 int pos_end = SETUPINPUT_SCREEN_POS_END;
2472 if (button == MB_MENU_INITIALIZE)
2474 drawPlayerSetupInputInfo(player_nr);
2475 drawCursor(choice, FC_RED);
2479 else if (button == MB_MENU_LEAVE)
2481 setup_mode = SETUP_MODE_MAIN;
2488 if (mx || my) /* mouse input */
2490 x = (mx - mSX) / 32;
2491 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2493 else if (dx || dy) /* keyboard input */
2495 if (dx && choice == 0)
2496 x = (dx < 0 ? 10 : 12);
2497 else if ((dx && choice == 1) ||
2498 (dx == +1 && choice == 2) ||
2499 (dx == -1 && choice == pos_end))
2500 button = MB_MENU_CHOICE;
2504 if (y >= pos_empty1 && y <= pos_empty2)
2505 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2508 if (IN_VIS_FIELD(x, y) &&
2509 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2511 static unsigned long delay = 0;
2513 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2516 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2518 drawPlayerSetupInputInfo(player_nr);
2520 else if (IN_VIS_FIELD(x, y) &&
2521 y >= pos_start && y <= pos_end &&
2522 !(y >= pos_empty1 && y <= pos_empty2))
2528 drawCursor(y, FC_RED);
2529 drawCursor(choice, FC_BLUE);
2537 char *device_name = setup.input[player_nr].joy.device_name;
2539 if (!setup.input[player_nr].use_joystick)
2541 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2543 setJoystickDeviceToNr(device_name, new_device_nr);
2544 setup.input[player_nr].use_joystick = TRUE;
2548 int device_nr = getJoystickNrFromDeviceName(device_name);
2549 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2551 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2552 setup.input[player_nr].use_joystick = FALSE;
2554 setJoystickDeviceToNr(device_name, new_device_nr);
2557 drawPlayerSetupInputInfo(player_nr);
2561 if (setup.input[player_nr].use_joystick)
2564 CalibrateJoystick(player_nr);
2567 CustomizeKeyboard(player_nr);
2569 else if (y == pos_end)
2573 setup_mode = SETUP_MODE_MAIN;
2580 void CustomizeKeyboard(int player_nr)
2584 boolean finished = FALSE;
2585 static struct SetupKeyboardInfo custom_key;
2590 } customize_step[] =
2592 { &custom_key.left, "Move Left" },
2593 { &custom_key.right, "Move Right" },
2594 { &custom_key.up, "Move Up" },
2595 { &custom_key.down, "Move Down" },
2596 { &custom_key.snap, "Snap Field" },
2597 { &custom_key.drop, "Drop Element" }
2600 /* read existing key bindings from player setup */
2601 custom_key = setup.input[player_nr].key;
2604 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2610 DrawText(mSX, mSY + (2+2*step_nr)*32,
2611 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2612 DrawText(mSX, mSY + (2+2*step_nr+1)*32,
2613 "Key:", FONT_INPUT_1_ACTIVE);
2614 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2615 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2619 if (PendingEvent()) /* got event */
2627 case EVENT_KEYPRESS:
2629 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2631 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2637 /* all keys configured -- wait for "Escape" or "Return" key */
2641 /* press 'Enter' to keep the existing key binding */
2642 if (key == KSYM_Return)
2643 key = *customize_step[step_nr].key;
2645 /* check if key already used */
2646 for (i = 0; i < step_nr; i++)
2647 if (*customize_step[i].key == key)
2652 /* got new key binding */
2653 *customize_step[step_nr].key = key;
2654 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2656 DrawText(mSX + 4*32, mSY + (2+2*step_nr+1)*32,
2657 getKeyNameFromKey(key), FONT_VALUE_1);
2660 /* un-highlight last query */
2661 DrawText(mSX, mSY+(2+2*(step_nr-1))*32,
2662 customize_step[step_nr-1].text, FONT_MENU_1);
2663 DrawText(mSX, mSY+(2+2*(step_nr-1)+1)*32,
2664 "Key:", FONT_MENU_1);
2666 /* press 'Enter' to leave */
2669 DrawText(mSX + 16, mSY + 15*32+16,
2670 "Press Enter", FONT_TITLE_1);
2674 /* query next key binding */
2675 DrawText(mSX, mSY+(2+2*step_nr)*32,
2676 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2677 DrawText(mSX, mSY+(2+2*step_nr+1)*32,
2678 "Key:", FONT_INPUT_1_ACTIVE);
2679 DrawText(mSX + 4*32, mSY+(2+2*step_nr+1)*32,
2680 getKeyNameFromKey(*customize_step[step_nr].key),
2685 case EVENT_KEYRELEASE:
2686 key_joystick_mapping = 0;
2690 HandleOtherEvents(&event);
2698 /* don't eat all CPU time */
2702 /* write new key bindings back to player setup */
2703 setup.input[player_nr].key = custom_key;
2706 DrawSetupScreen_Input();
2709 static boolean CalibrateJoystickMain(int player_nr)
2711 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2712 int new_joystick_xright = JOYSTICK_XMIDDLE;
2713 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2714 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2715 int new_joystick_xmiddle, new_joystick_ymiddle;
2717 int joystick_fd = joystick.fd[player_nr];
2718 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2719 boolean check[3][3];
2720 int check_remaining = 3 * 3;
2725 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2728 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2733 for (y = 0; y < 3; y++)
2735 for (x = 0; x < 3; x++)
2737 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2738 check[x][y] = FALSE;
2742 DrawText(mSX, mSY + 6 * 32, " ROTATE JOYSTICK ", FONT_TITLE_1);
2743 DrawText(mSX, mSY + 7 * 32, "IN ALL DIRECTIONS", FONT_TITLE_1);
2744 DrawText(mSX + 16, mSY + 9 * 32, " IF ALL BALLS ", FONT_TITLE_1);
2745 DrawText(mSX, mSY + 10 * 32, " ARE YELLOW, ", FONT_TITLE_1);
2746 DrawText(mSX, mSY + 11 * 32, " CENTER JOYSTICK ", FONT_TITLE_1);
2747 DrawText(mSX, mSY + 12 * 32, " AND ", FONT_TITLE_1);
2748 DrawText(mSX, mSY + 13 * 32, "PRESS ANY BUTTON!", FONT_TITLE_1);
2750 joy_value = Joystick(player_nr);
2751 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2752 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2754 /* eventually uncalibrated center position (joystick could be uncentered) */
2755 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2758 new_joystick_xmiddle = joy_x;
2759 new_joystick_ymiddle = joy_y;
2761 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2764 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2769 if (PendingEvent()) /* got event */
2777 case EVENT_KEYPRESS:
2778 switch(GetEventKey((KeyEvent *)&event, TRUE))
2781 if (check_remaining == 0)
2794 case EVENT_KEYRELEASE:
2795 key_joystick_mapping = 0;
2799 HandleOtherEvents(&event);
2804 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2807 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2808 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2809 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2810 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2812 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2813 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2814 setup.input[player_nr].joy.xright = new_joystick_xright;
2815 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2816 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2817 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2819 CheckJoystickData();
2821 joy_value = Joystick(player_nr);
2823 if (joy_value & JOY_BUTTON && check_remaining == 0)
2826 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2827 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2829 if (x != last_x || y != last_y)
2831 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2832 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2837 if (check_remaining > 0 && !check[x+1][y+1])
2839 check[x+1][y+1] = TRUE;
2845 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2846 setup.input[player_nr].joy.xleft,
2847 setup.input[player_nr].joy.xmiddle,
2848 setup.input[player_nr].joy.xright);
2849 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2850 setup.input[player_nr].joy.yupper,
2851 setup.input[player_nr].joy.ymiddle,
2852 setup.input[player_nr].joy.ylower);
2861 /* don't eat all CPU time */
2865 /* calibrated center position (joystick should now be centered) */
2866 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2869 new_joystick_xmiddle = joy_x;
2870 new_joystick_ymiddle = joy_y;
2874 DrawSetupScreen_Input();
2876 /* wait until the last pressed button was released */
2877 while (Joystick(player_nr) & JOY_BUTTON)
2879 if (PendingEvent()) /* got event */
2884 HandleOtherEvents(&event);
2893 void CalibrateJoystick(int player_nr)
2895 if (!CalibrateJoystickMain(player_nr))
2899 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
2900 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
2902 Delay(2000); /* show error message for two seconds */
2906 void DrawSetupScreen()
2908 DeactivateJoystick();
2910 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
2912 if (setup_mode == SETUP_MODE_INPUT)
2913 DrawSetupScreen_Input();
2914 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2915 DrawChooseTree(&artwork.gfx_current);
2916 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2917 DrawChooseTree(&artwork.snd_current);
2918 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2919 DrawChooseTree(&artwork.mus_current);
2921 DrawSetupScreen_Generic();
2927 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
2929 if (setup_mode == SETUP_MODE_INPUT)
2930 HandleSetupScreen_Input(mx, my, dx, dy, button);
2931 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
2932 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
2933 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
2934 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
2935 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
2936 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
2938 HandleSetupScreen_Generic(mx, my, dx, dy, button);
2943 void HandleGameActions()
2945 if (game_status != GAME_MODE_PLAYING)
2948 /* !!! FIX THIS (START) !!! */
2949 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2951 byte *recorded_player_action;
2952 byte summarized_player_action = 0;
2953 byte tape_action[MAX_PLAYERS];
2956 if (level.native_em_level->lev->home == 0) /* all players at home */
2960 if (!TAPE_IS_STOPPED(tape))
2963 if (game_status != GAME_MODE_PLAYING)
2967 if (level.native_em_level->ply1->alive == 0 &&
2968 level.native_em_level->ply2->alive == 0) /* all dead */
2969 AllPlayersGone = TRUE;
2971 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
2974 /* --- game actions --- */
2978 /* don't use 100% CPU while in pause mode -- this should better be solved
2979 like in the R'n'D game engine! */
2986 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
2989 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
2990 if (recorded_player_action == NULL && tape.pausing)
2994 for (i = 0; i < MAX_PLAYERS; i++)
2996 summarized_player_action |= stored_player[i].action;
2998 if (!network_playing)
2999 stored_player[i].effective_action = stored_player[i].action;
3002 if (!options.network && !setup.team_mode)
3003 local_player->effective_action = summarized_player_action;
3005 if (recorded_player_action != NULL)
3006 for (i = 0; i < MAX_PLAYERS; i++)
3007 stored_player[i].effective_action = recorded_player_action[i];
3009 for (i = 0; i < MAX_PLAYERS; i++)
3011 tape_action[i] = stored_player[i].effective_action;
3013 /* !!! (this does not happen in the EM engine) !!! */
3014 if (tape.recording && tape_action[i] && !tape.player_participates[i])
3015 tape.player_participates[i] = TRUE; /* player just appeared from CE */
3018 /* only save actions from input devices, but not programmed actions */
3020 TapeRecordAction(tape_action);
3022 GameActions_EM(local_player->effective_action);
3024 if (TimeFrames >= FRAMES_PER_SECOND)
3029 if (tape.recording || tape.playing)
3030 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
3040 if (local_player->LevelSolved)
3043 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3049 if (tape.auto_play && !tape.playing)
3050 AutoPlayTape(); /* continue automatically playing next tape */
3054 /* ---------- new screen button stuff -------------------------------------- */
3056 /* graphic position and size values for buttons and scrollbars */
3057 #define SC_SCROLLBUTTON_XSIZE TILEX
3058 #define SC_SCROLLBUTTON_YSIZE TILEY
3060 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3061 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3062 SC_SCROLLBUTTON_YSIZE)
3063 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3064 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3065 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3066 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3067 SC_SCROLLBUTTON_YSIZE)
3068 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3069 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3070 SC_SCROLL_VERTICAL_YSIZE)
3072 #define SC_BORDER_SIZE 14
3076 int gfx_unpressed, gfx_pressed;
3080 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3083 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3084 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3085 SCREEN_CTRL_ID_SCROLL_UP,
3089 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3090 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3091 SCREEN_CTRL_ID_SCROLL_DOWN,
3098 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3099 Bitmap **gfx_unpressed, **gfx_pressed;
3101 int gfx_unpressed, gfx_pressed;
3108 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3111 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3112 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3114 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3116 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3117 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3118 GD_TYPE_SCROLLBAR_VERTICAL,
3119 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3120 "scroll level series vertically"
3124 static void CreateScreenScrollbuttons()
3126 struct GadgetInfo *gi;
3127 unsigned long event_mask;
3130 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3132 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3133 int gfx_unpressed, gfx_pressed;
3134 int x, y, width, height;
3135 int gd_x1, gd_x2, gd_y1, gd_y2;
3136 int id = scrollbutton_info[i].gadget_id;
3138 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3140 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3141 y = mSY + scrollbutton_info[i].y;
3142 width = SC_SCROLLBUTTON_XSIZE;
3143 height = SC_SCROLLBUTTON_YSIZE;
3145 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3146 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3147 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3149 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3150 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3151 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3152 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3153 gd_x1 = graphic_info[gfx_unpressed].src_x;
3154 gd_y1 = graphic_info[gfx_unpressed].src_y;
3155 gd_x2 = graphic_info[gfx_pressed].src_x;
3156 gd_y2 = graphic_info[gfx_pressed].src_y;
3158 gi = CreateGadget(GDI_CUSTOM_ID, id,
3159 GDI_CUSTOM_TYPE_ID, i,
3160 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3165 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3166 GDI_STATE, GD_BUTTON_UNPRESSED,
3167 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3168 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3169 GDI_DIRECT_DRAW, FALSE,
3170 GDI_EVENT_MASK, event_mask,
3171 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3175 Error(ERR_EXIT, "cannot create gadget");
3177 screen_gadget[id] = gi;
3181 static void CreateScreenScrollbars()
3185 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3187 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3188 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3189 int gfx_unpressed, gfx_pressed;
3191 int x, y, width, height;
3192 int gd_x1, gd_x2, gd_y1, gd_y2;
3193 struct GadgetInfo *gi;
3194 int items_max, items_visible, item_position;
3195 unsigned long event_mask;
3196 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3197 int id = scrollbar_info[i].gadget_id;
3199 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3201 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3202 y = mSY + scrollbar_info[i].y;
3203 width = scrollbar_info[i].width;
3204 height = scrollbar_info[i].height;
3206 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3207 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3209 items_max = num_page_entries;
3210 items_visible = num_page_entries;
3213 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3214 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3215 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3221 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3222 gfx_pressed = scrollbar_info[i].gfx_pressed;
3223 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3224 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3225 gd_x1 = graphic_info[gfx_unpressed].src_x;
3226 gd_y1 = graphic_info[gfx_unpressed].src_y;
3227 gd_x2 = graphic_info[gfx_pressed].src_x;
3228 gd_y2 = graphic_info[gfx_pressed].src_y;
3231 gi = CreateGadget(GDI_CUSTOM_ID, id,
3232 GDI_CUSTOM_TYPE_ID, i,
3233 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3238 GDI_TYPE, scrollbar_info[i].type,
3239 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3240 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3241 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3242 GDI_STATE, GD_BUTTON_UNPRESSED,
3243 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3244 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3245 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3246 GDI_DIRECT_DRAW, FALSE,
3247 GDI_EVENT_MASK, event_mask,
3248 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3252 Error(ERR_EXIT, "cannot create gadget");
3254 screen_gadget[id] = gi;
3258 void CreateScreenGadgets()
3260 int last_game_status = game_status; /* save current game status */
3262 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3265 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3267 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3269 /* copy pointers to clip mask and GC */
3270 scrollbar_bitmap[i]->clip_mask =
3271 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3272 scrollbar_bitmap[i]->stored_clip_gc =
3273 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3275 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3276 scrollbar_bitmap[i],
3277 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3278 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3279 TILEX, TILEY, 0, 0);
3283 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3284 game_status = GAME_MODE_LEVELS;
3286 CreateScreenScrollbuttons();
3287 CreateScreenScrollbars();
3289 game_status = last_game_status; /* restore current game status */
3292 void FreeScreenGadgets()
3296 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3297 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3299 /* prevent freeing clip mask and GC twice */
3300 scrollbar_bitmap[i]->clip_mask = None;
3301 scrollbar_bitmap[i]->stored_clip_gc = None;
3303 FreeBitmap(scrollbar_bitmap[i]);
3307 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3308 FreeGadget(screen_gadget[i]);
3311 void MapChooseTreeGadgets(TreeInfo *ti)
3313 int num_entries = numTreeInfoInGroup(ti);
3316 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3319 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3320 MapGadget(screen_gadget[i]);
3324 void UnmapChooseTreeGadgets()
3328 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3329 UnmapGadget(screen_gadget[i]);
3333 static void HandleScreenGadgets(struct GadgetInfo *gi)
3335 int id = gi->custom_id;
3337 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3342 case SCREEN_CTRL_ID_SCROLL_UP:
3343 if (game_status == GAME_MODE_LEVELS)
3344 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3345 else if (game_status == GAME_MODE_SETUP)
3346 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3349 case SCREEN_CTRL_ID_SCROLL_DOWN:
3350 if (game_status == GAME_MODE_LEVELS)
3351 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3352 else if (game_status == GAME_MODE_SETUP)
3353 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3356 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3357 if (game_status == GAME_MODE_LEVELS)
3358 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3359 else if (game_status == GAME_MODE_SETUP)
3360 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);