1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT 4
33 #define SETUP_MODE_GRAPHICS 5
34 #define SETUP_MODE_SOUND 6
35 #define SETUP_MODE_ARTWORK 7
36 #define SETUP_MODE_CHOOSE_GRAPHICS 8
37 #define SETUP_MODE_CHOOSE_SOUNDS 9
38 #define SETUP_MODE_CHOOSE_MUSIC 10
40 #define MAX_SETUP_MODES 11
42 /* for input setup functions */
43 #define SETUPINPUT_SCREEN_POS_START 0
44 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
45 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
46 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
48 /* screens on the info screen */
49 #define INFO_MODE_MAIN 0
50 #define INFO_MODE_ELEMENTS 1
51 #define INFO_MODE_MUSIC 2
52 #define INFO_MODE_CREDITS 3
53 #define INFO_MODE_PROGRAM 4
54 #define INFO_MODE_LEVELSET 5
56 #define MAX_INFO_MODES 6
58 /* for various menu stuff */
59 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
60 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
61 #define MENU_SCREEN_START_YPOS 2
62 #define MENU_SCREEN_VALUE_XPOS 14
63 #define MENU_TITLE1_YPOS 8
64 #define MENU_TITLE2_YPOS 46
66 /* buttons and scrollbars identifiers */
67 #define SCREEN_CTRL_ID_SCROLL_UP 0
68 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
69 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
71 #define NUM_SCREEN_SCROLLBUTTONS 2
72 #define NUM_SCREEN_SCROLLBARS 1
73 #define NUM_SCREEN_GADGETS 3
75 /* forward declarations of internal functions */
76 static void HandleScreenGadgets(struct GadgetInfo *);
77 static void HandleSetupScreen_Generic(int, int, int, int, int);
78 static void HandleSetupScreen_Input(int, int, int, int, int);
79 static void CustomizeKeyboard(int);
80 static void CalibrateJoystick(int);
81 static void execSetupArtwork(void);
82 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
84 static void DrawChooseLevel(void);
85 static void DrawInfoScreen(void);
86 static void DrawSetupScreen(void);
88 static void DrawInfoScreen_HelpAnim(int, int, boolean);
89 static void DrawInfoScreen_HelpText(int, int, int, int);
90 static void HandleInfoScreen_Main(int, int, int, int, int);
91 static void HandleInfoScreen_Elements(int);
92 static void HandleInfoScreen_Music(int);
93 static void HandleInfoScreen_Credits(int);
94 static void HandleInfoScreen_Program(int);
96 static void MapChooseTreeGadgets(TreeInfo *);
98 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
99 static int setup_mode = SETUP_MODE_MAIN;
100 static int info_mode = INFO_MODE_MAIN;
102 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
103 x <= GAME_MODE_SETUP ? x : \
104 x == GAME_MODE_PSEUDO_TYPENAME ? \
105 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
107 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
108 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
110 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
111 menu.list_size[game_status] : \
112 MAX_MENU_ENTRIES_ON_SCREEN)
114 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
115 #define NUM_SCROLLBAR_BITMAPS 2
116 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
120 static void drawCursorExt(int xpos, int ypos, int color, int g)
122 static int cursor_array[SCR_FIELDY];
127 cursor_array[ypos] = g;
129 g = cursor_array[ypos];
133 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
134 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
135 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
136 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
137 IMG_MENU_BUTTON_ACTIVE);
139 ypos += MENU_SCREEN_START_YPOS;
141 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
142 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
145 static void initCursor(int ypos, int graphic)
147 drawCursorExt(0, ypos, FC_BLUE, graphic);
150 static void drawCursor(int ypos, int color)
152 drawCursorExt(0, ypos, color, 0);
155 static void drawCursorXY(int xpos, int ypos, int graphic)
157 drawCursorExt(xpos, ypos, -1, graphic);
160 static void drawChooseTreeCursor(int ypos, int color)
162 int last_game_status = game_status; /* save current game status */
164 /* force LEVELS draw offset on artwork setup screen */
165 game_status = GAME_MODE_LEVELS;
167 drawCursorExt(0, ypos, color, 0);
169 game_status = last_game_status; /* restore current game status */
172 static void PlayMenuSound()
174 int sound = menu.sound[game_status];
176 if (sound == SND_UNDEFINED)
179 if (sound_info[sound].loop)
180 PlaySoundLoop(sound);
185 static void PlayMenuSoundIfLoop()
187 int sound = menu.sound[game_status];
189 if (sound == SND_UNDEFINED)
192 if (sound_info[sound].loop)
193 PlaySoundLoop(sound);
196 static void PlayMenuMusic()
198 int music = menu.music[game_status];
200 if (music == MUS_UNDEFINED)
208 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
209 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
212 static void ToggleFullscreenIfNeeded()
214 if (setup.fullscreen != video.fullscreen_enabled)
216 /* save old door content */
217 BlitBitmap(backbuffer, bitmap_db_door,
218 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
220 /* toggle fullscreen */
221 ChangeVideoModeIfNeeded(setup.fullscreen);
222 setup.fullscreen = video.fullscreen_enabled;
224 /* redraw background to newly created backbuffer */
225 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
226 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
228 /* restore old door content */
229 BlitBitmap(bitmap_db_door, backbuffer,
230 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
232 redraw_mask = REDRAW_ALL;
238 static LevelDirTree *leveldir_last_valid = NULL;
239 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
241 char *level_text = "Levelset";
243 char *level_text = "Level:";
245 int name_width, level_width;
249 FadeSoundsAndMusic();
251 KeyboardAutoRepeatOn();
254 SetDrawDeactivationMask(REDRAW_NONE);
255 SetDrawBackgroundMask(REDRAW_FIELD);
257 audio.sound_deactivated = FALSE;
259 /* needed if last screen was the playing screen, invoked from level editor */
260 if (level_editor_test_game)
262 game_status = GAME_MODE_EDITOR;
268 /* needed if last screen was the editor screen */
269 UndrawSpecialEditorDoor();
271 /* needed if last screen was the setup screen and fullscreen state changed */
272 ToggleFullscreenIfNeeded();
274 /* leveldir_current may be invalid (level group, parent link) */
275 if (!validLevelSeries(leveldir_current))
276 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
278 /* store valid level series information */
279 leveldir_last_valid = leveldir_current;
281 /* needed if last screen (level choice) changed graphics, sounds or music */
282 ReloadCustomArtwork(0);
285 SetDrawtoField(DRAW_BACKBUFFER);
289 /* map gadgets for main menu screen */
293 /* level_nr may have been set to value over handicap with level editor */
294 if (setup.handicap && level_nr > leveldir_current->handicap_level)
295 level_nr = leveldir_current->handicap_level;
300 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
305 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
306 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
307 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
308 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
309 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
310 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
311 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
312 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
314 /* calculated after (possible) reload of custom artwork */
315 name_width = getTextWidth(name_text, FONT_MENU_1);
317 level_width = 9 * getFontWidth(FONT_MENU_1);
319 level_width = getTextWidth(level_text, FONT_MENU_1);
322 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
325 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
328 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
332 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
338 int text_height = getFontHeight(FONT_TEXT_3);
339 int ypos2 = -SY + 3 * 32 + 16;
340 int ypos1 = ypos2 - text_height;
342 DrawTextF(mSX + level_width + 6 * 32, mSY + ypos1, FONT_TEXT_3,
343 "%03d", leveldir_current->first_level);
344 DrawTextF(mSX + level_width + 6 * 32, mSY + ypos2, FONT_TEXT_3,
345 "%03d", leveldir_current->last_level);
348 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
349 "%d", leveldir_current->levels);
353 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
354 leveldir_current->first_level, leveldir_current->last_level);
358 if (leveldir_current->readonly)
360 DrawTextS(mSX + level_width + 9 * 32 - 2,
361 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
362 DrawTextS(mSX + level_width + 9 * 32 - 2,
363 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
367 for (i = 0; i < 8; i++)
368 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
372 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
373 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
375 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
376 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
379 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
384 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
387 if (TAPE_IS_EMPTY(tape))
389 DrawCompleteVideoDisplay();
394 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
397 /* map gadgets for main menu screen */
403 static void gotoTopLevelDir()
405 /* move upwards to top level directory */
406 while (leveldir_current->node_parent)
408 /* write a "path" into level tree for easy navigation to last level */
409 if (leveldir_current->node_parent->node_group->cl_first == -1)
411 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
412 int leveldir_pos = posTreeInfo(leveldir_current);
413 int num_page_entries;
414 int cl_first, cl_cursor;
416 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
417 num_page_entries = num_leveldirs;
419 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
421 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
422 cl_cursor = leveldir_pos - cl_first;
424 leveldir_current->node_parent->node_group->cl_first = cl_first;
425 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
428 leveldir_current = leveldir_current->node_parent;
433 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
435 static unsigned long level_delay = 0;
436 static int choice = 5;
440 if (button == MB_MENU_INITIALIZE)
442 drawCursor(choice, FC_RED);
446 if (mx || my) /* mouse input */
449 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
451 else if (dx || dy) /* keyboard input */
453 if (dx && choice == 1)
454 x = (dx < 0 ? 10 : 14);
459 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
460 (x == 14 && level_nr < leveldir_current->last_level)) &&
461 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
463 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
464 int old_level_nr = level_nr;
467 new_level_nr = level_nr + (x == 10 ? -step : +step);
468 if (new_level_nr < leveldir_current->first_level)
469 new_level_nr = leveldir_current->first_level;
470 if (new_level_nr > leveldir_current->last_level)
471 new_level_nr = leveldir_current->last_level;
473 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
475 /* skipping levels is only allowed when trying to skip single level */
476 if (setup.skip_levels && step == 1 &&
477 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
479 leveldir_current->handicap_level++;
480 SaveLevelSetup_SeriesInfo();
483 new_level_nr = leveldir_current->handicap_level;
486 if (new_level_nr != old_level_nr)
488 level_nr = new_level_nr;
490 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
494 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
498 DrawCompleteVideoDisplay();
500 /* needed because DrawMicroLevel() takes some time */
503 DelayReached(&level_delay, 0); /* reset delay counter */
506 else if (IN_VIS_FIELD(x, y) &&
507 y >= 0 && y <= 7 && (y != 1 || x < 10))
513 drawCursor(y, FC_RED);
514 drawCursor(choice, FC_BLUE);
522 game_status = GAME_MODE_PSEUDO_TYPENAME;
523 HandleTypeName(strlen(setup.player_name), 0);
529 game_status = GAME_MODE_LEVELS;
530 SaveLevelSetup_LastSeries();
531 SaveLevelSetup_SeriesInfo();
542 game_status = GAME_MODE_SCORES;
547 if (leveldir_current->readonly &&
548 strcmp(setup.player_name, "Artsoft") != 0)
549 Request("This level is read only !", REQ_CONFIRM);
550 game_status = GAME_MODE_EDITOR;
555 game_status = GAME_MODE_INFO;
556 info_mode = INFO_MODE_MAIN;
561 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
565 game_status = GAME_MODE_SETUP;
566 setup_mode = SETUP_MODE_MAIN;
572 SaveLevelSetup_LastSeries();
573 SaveLevelSetup_SeriesInfo();
575 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
576 game_status = GAME_MODE_QUIT;
581 if (game_status == GAME_MODE_MAIN)
583 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
589 /* ========================================================================= */
590 /* info screen functions */
591 /* ========================================================================= */
593 static struct TokenInfo *info_info;
594 static int num_info_info;
596 static void execInfoElements()
598 info_mode = INFO_MODE_ELEMENTS;
602 static void execInfoMusic()
604 info_mode = INFO_MODE_MUSIC;
608 static void execInfoCredits()
610 info_mode = INFO_MODE_CREDITS;
614 static void execInfoProgram()
616 info_mode = INFO_MODE_PROGRAM;
620 static void execInfoLevelSet()
622 info_mode = INFO_MODE_LEVELSET;
626 static void execExitInfo()
628 game_status = GAME_MODE_MAIN;
632 static struct TokenInfo info_info_main[] =
634 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
635 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
636 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
637 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
638 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
639 { TYPE_EMPTY, NULL, "" },
640 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
645 static void DrawInfoScreen_Main()
650 CloseDoor(DOOR_CLOSE_2);
655 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
657 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
660 info_info = info_info_main;
663 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
665 int ypos = MENU_SCREEN_START_YPOS + i;
666 int font_nr = FONT_MENU_1;
668 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
670 if (info_info[i].type & TYPE_ENTER_MENU)
671 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
672 else if (info_info[i].type & TYPE_LEAVE_MENU)
673 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
674 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
675 initCursor(i, IMG_MENU_BUTTON);
686 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
689 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
691 static int choice_store[MAX_INFO_MODES];
692 int choice = choice_store[info_mode]; /* always starts with 0 */
696 if (button == MB_MENU_INITIALIZE)
698 /* advance to first valid menu entry */
699 while (choice < num_info_info &&
700 info_info[choice].type & TYPE_SKIP_ENTRY)
702 choice_store[info_mode] = choice;
704 drawCursor(choice, FC_RED);
707 else if (button == MB_MENU_LEAVE)
709 for (y = 0; y < num_info_info; y++)
711 if (info_info[y].type & TYPE_LEAVE_MENU)
713 void (*menu_callback_function)(void) = info_info[y].value;
715 menu_callback_function();
716 break; /* absolutely needed because function changes 'info_info'! */
723 if (mx || my) /* mouse input */
726 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
728 else if (dx || dy) /* keyboard input */
732 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
734 if (info_info[choice].type & menu_navigation_type ||
735 info_info[choice].type & TYPE_ENTER_SCREEN ||
736 info_info[choice].type & TYPE_BOOLEAN_STYLE)
737 button = MB_MENU_CHOICE;
742 /* jump to next non-empty menu entry (up or down) */
743 while (y > 0 && y < num_info_info - 1 &&
744 info_info[y].type & TYPE_SKIP_ENTRY)
748 if (IN_VIS_FIELD(x, y) &&
749 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
755 drawCursor(y, FC_RED);
756 drawCursor(choice, FC_BLUE);
757 choice = choice_store[info_mode] = y;
760 else if (!(info_info[y].type & TYPE_GHOSTED))
762 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
764 void (*menu_callback_function)(void) = info_info[choice].value;
766 menu_callback_function();
772 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
774 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
775 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
776 int xstart = mSX + 16;
777 int ystart = mSY + 64 + 2 * 32;
778 int ystep = TILEY + 4;
779 int element, action, direction;
787 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
788 infoscreen_step[i] = infoscreen_frame[i] = 0;
793 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
795 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
796 "Press any key or button for next page");
802 while (helpanim_info[j].element != HELPANIM_LIST_END)
804 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
809 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
818 j += infoscreen_step[i - start];
820 element = helpanim_info[j].element;
821 action = helpanim_info[j].action;
822 direction = helpanim_info[j].direction;
824 if (action != -1 && direction != -1)
825 graphic = el_act_dir2img(element, action, direction);
826 else if (action != -1)
827 graphic = el_act2img(element, action);
828 else if (direction != -1)
829 graphic = el_act2img(element, direction);
831 graphic = el2img(element);
833 delay = helpanim_info[j++].delay;
838 if (infoscreen_frame[i - start] == 0)
841 infoscreen_frame[i - start] = delay - 1;
845 sync_frame = delay - infoscreen_frame[i - start];
846 infoscreen_frame[i - start]--;
849 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
851 if (!infoscreen_frame[i - start])
852 infoscreen_step[i - start] = 0;
856 if (!infoscreen_frame[i - start])
857 infoscreen_step[i - start]++;
858 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
864 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
866 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
867 graphic, sync_frame, USE_MASKING);
870 DrawInfoScreen_HelpText(element, action, direction, i - start);
875 redraw_mask |= REDRAW_FIELD;
880 static char *getHelpText(int element, int action, int direction)
882 char token[MAX_LINE_LEN];
884 strcpy(token, element_info[element].token_name);
887 strcat(token, element_action_info[action].suffix);
890 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
892 return getHashEntry(helptext_info, token);
895 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
897 int font_nr = FONT_LEVEL_NUMBER;
898 int font_width = getFontWidth(font_nr);
899 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
900 int sy = mSY + 65 + 2 * 32 + 1;
901 int ystep = TILEY + 4;
903 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
904 int max_lines_per_text = 2;
907 if (action != -1 && direction != -1) /* element.action.direction */
908 text = getHelpText(element, action, direction);
910 if (text == NULL && action != -1) /* element.action */
911 text = getHelpText(element, action, -1);
913 if (text == NULL && direction != -1) /* element.direction */
914 text = getHelpText(element, -1, direction);
916 if (text == NULL) /* base element */
917 text = getHelpText(element, -1, -1);
919 if (text == NULL) /* not found */
920 text = "No description available";
922 if (strlen(text) <= max_chars_per_line) /* only one line of text */
923 sy += getFontHeight(font_nr) / 2;
925 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
926 max_chars_per_line, max_lines_per_text);
929 void DrawInfoScreen_Elements()
931 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
936 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
942 void HandleInfoScreen_Elements(int button)
944 static unsigned long info_delay = 0;
945 static int num_anims;
946 static int num_pages;
948 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
949 int button_released = !button;
952 if (button == MB_MENU_INITIALIZE)
954 boolean new_element = TRUE;
957 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
959 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
961 else if (new_element)
968 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
971 else if (button == MB_MENU_LEAVE)
973 info_mode = INFO_MODE_MAIN;
979 if (button_released || button == MB_MENU_INITIALIZE)
981 if (button != MB_MENU_INITIALIZE)
984 if (page >= num_pages)
986 FadeSoundsAndMusic();
988 info_mode = INFO_MODE_MAIN;
994 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
998 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
999 if (page < num_pages)
1000 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1002 PlayMenuSoundIfLoop();
1006 void DrawInfoScreen_Music()
1008 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1015 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1018 void HandleInfoScreen_Music(int button)
1020 static struct MusicFileInfo *list = NULL;
1021 int ystart = 150, dy = 30;
1022 int ybottom = SYSIZE - 20;
1023 int button_released = !button;
1025 if (button == MB_MENU_INITIALIZE)
1027 list = music_file_info;
1031 FadeSoundsAndMusic();
1036 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1038 DrawTextSCentered(ybottom, FONT_TEXT_4,
1039 "Press any key or button for info menu");
1044 else if (button == MB_MENU_LEAVE)
1046 info_mode = INFO_MODE_MAIN;
1052 if (button_released || button == MB_MENU_INITIALIZE)
1056 if (button != MB_MENU_INITIALIZE)
1062 info_mode = INFO_MODE_MAIN;
1068 FadeSoundsAndMusic();
1075 int sound = list->music;
1077 if (sound_info[sound].loop)
1078 PlaySoundLoop(sound);
1082 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1086 PlayMusic(list->music);
1088 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1091 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1093 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1094 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1096 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1099 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1101 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1102 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1104 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1106 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1109 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1111 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1112 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1114 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1116 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1119 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1121 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1122 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1124 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1126 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1129 DrawTextSCentered(ybottom, FONT_TEXT_4,
1130 "Press any key or button for next page");
1133 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1134 PlaySoundLoop(list->music);
1137 void DrawInfoScreen_Credits()
1139 int ystart = 150, ystep = 30;
1140 int ybottom = SYSIZE - 20;
1142 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1144 FadeSoundsAndMusic();
1149 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1150 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1151 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1152 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1153 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1154 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1155 "...and many thanks to all contributors");
1156 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1158 DrawTextSCentered(ybottom, FONT_TEXT_4,
1159 "Press any key or button for info menu");
1162 void HandleInfoScreen_Credits(int button)
1164 int button_released = !button;
1166 if (button == MB_MENU_LEAVE)
1168 info_mode = INFO_MODE_MAIN;
1174 if (button_released)
1176 FadeSoundsAndMusic();
1178 info_mode = INFO_MODE_MAIN;
1183 PlayMenuSoundIfLoop();
1187 void DrawInfoScreen_Program()
1189 int ystart = 150, ystep = 30;
1190 int ybottom = SYSIZE - 20;
1192 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1197 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1199 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1200 "This game is Freeware!");
1201 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1202 "If you like it, send e-mail to:");
1203 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1204 "info@artsoft.org");
1205 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1206 "or SnailMail to:");
1207 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1209 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1210 "Detmolder Strasse 189");
1211 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1213 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1216 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1217 "If you have created new levels,");
1218 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1219 "send them to me to include them!");
1220 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1223 DrawTextSCentered(ybottom, FONT_TEXT_4,
1224 "Press any key or button for info menu");
1227 void HandleInfoScreen_Program(int button)
1229 int button_released = !button;
1231 if (button == MB_MENU_LEAVE)
1233 info_mode = INFO_MODE_MAIN;
1239 if (button_released)
1241 FadeSoundsAndMusic();
1243 info_mode = INFO_MODE_MAIN;
1248 PlayMenuSoundIfLoop();
1252 void DrawInfoScreen_LevelSet()
1255 int ybottom = SYSIZE - 20;
1256 char *filename = getLevelSetInfoFilename();
1257 int font_nr = FONT_LEVEL_NUMBER;
1258 int font_width = getFontWidth(font_nr);
1259 int font_height = getFontHeight(font_nr);
1262 int sx = SX + pad_x;
1263 int sy = SY + pad_y;
1264 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1265 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1267 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1272 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1274 DrawTextSCentered(ybottom, FONT_TEXT_4,
1275 "Press any key or button for info menu");
1277 if (filename != NULL)
1278 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1279 max_lines_per_screen);
1281 DrawTextSCentered(ystart, FONT_TEXT_2,
1282 "No information for this level set.");
1285 void HandleInfoScreen_LevelSet(int button)
1287 int button_released = !button;
1289 if (button == MB_MENU_LEAVE)
1291 info_mode = INFO_MODE_MAIN;
1297 if (button_released)
1299 FadeSoundsAndMusic();
1301 info_mode = INFO_MODE_MAIN;
1306 PlayMenuSoundIfLoop();
1310 void DrawInfoScreen()
1312 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1314 if (info_mode == INFO_MODE_ELEMENTS)
1315 DrawInfoScreen_Elements();
1316 else if (info_mode == INFO_MODE_MUSIC)
1317 DrawInfoScreen_Music();
1318 else if (info_mode == INFO_MODE_CREDITS)
1319 DrawInfoScreen_Credits();
1320 else if (info_mode == INFO_MODE_PROGRAM)
1321 DrawInfoScreen_Program();
1322 else if (info_mode == INFO_MODE_LEVELSET)
1323 DrawInfoScreen_LevelSet();
1325 DrawInfoScreen_Main();
1327 if (info_mode != INFO_MODE_MUSIC)
1334 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1336 if (info_mode == INFO_MODE_ELEMENTS)
1337 HandleInfoScreen_Elements(button);
1338 else if (info_mode == INFO_MODE_MUSIC)
1339 HandleInfoScreen_Music(button);
1340 else if (info_mode == INFO_MODE_CREDITS)
1341 HandleInfoScreen_Credits(button);
1342 else if (info_mode == INFO_MODE_PROGRAM)
1343 HandleInfoScreen_Program(button);
1344 else if (info_mode == INFO_MODE_LEVELSET)
1345 HandleInfoScreen_LevelSet(button);
1347 HandleInfoScreen_Main(mx, my, dx, dy, button);
1353 /* ========================================================================= */
1354 /* type name functions */
1355 /* ========================================================================= */
1357 void HandleTypeName(int newxpos, Key key)
1359 static int xpos = 0, ypos = 2;
1360 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1361 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1362 int startx = mSX + 32 + name_width;
1363 int starty = mSY + ypos * 32;
1369 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1370 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1375 if (((key >= KSYM_A && key <= KSYM_Z) ||
1376 (key >= KSYM_a && key <= KSYM_z)) &&
1377 xpos < MAX_PLAYER_NAME_LEN)
1381 if (key >= KSYM_A && key <= KSYM_Z)
1382 ascii = 'A' + (char)(key - KSYM_A);
1384 ascii = 'a' + (char)(key - KSYM_a);
1386 setup.player_name[xpos] = ascii;
1387 setup.player_name[xpos + 1] = 0;
1390 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1391 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1393 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1396 setup.player_name[xpos] = 0;
1398 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1400 else if (key == KSYM_Return && xpos > 0)
1402 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1403 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1406 game_status = GAME_MODE_MAIN;
1411 /* ========================================================================= */
1412 /* tree menu functions */
1413 /* ========================================================================= */
1415 static void DrawChooseTree(TreeInfo **ti_ptr)
1419 FreeScreenGadgets();
1420 CreateScreenGadgets();
1422 CloseDoor(DOOR_CLOSE_2);
1426 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1427 MapChooseTreeGadgets(*ti_ptr);
1433 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1435 struct GadgetInfo *gi = screen_gadget[id];
1436 int items_max, items_visible, item_position;
1438 items_max = numTreeInfoInGroup(ti);
1439 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1440 item_position = first_entry;
1442 if (item_position > items_max - items_visible)
1443 item_position = items_max - items_visible;
1445 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1446 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1447 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1450 static void drawChooseTreeList(int first_entry, int num_page_entries,
1454 char buffer[SCR_FIELDX * 2];
1455 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1456 char *title_string = NULL;
1458 int xoffset_sets = 16;
1460 int yoffset_sets = MENU_TITLE1_YPOS;
1462 int xoffset_setup = 16;
1464 int yoffset_setup = 16;
1467 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1470 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1473 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1474 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1476 int last_game_status = game_status; /* save current game status */
1479 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1480 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1481 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1482 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1485 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1487 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1490 /* force LEVELS font on artwork setup screen */
1491 game_status = GAME_MODE_LEVELS;
1493 /* clear tree list area, but not title or scrollbar */
1494 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1495 SXSIZE - 32 + menu.scrollbar_xoffset,
1496 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1498 for (i = 0; i < num_page_entries; i++)
1500 TreeInfo *node, *node_first;
1501 int entry_pos = first_entry + i;
1502 int ypos = MENU_SCREEN_START_YPOS + i;
1504 node_first = getTreeInfoFirstGroupEntry(ti);
1505 node = getTreeInfoFromPos(node_first, entry_pos);
1507 strncpy(buffer, node->name, max_buffer_len);
1508 buffer[max_buffer_len] = '\0';
1510 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1512 if (node->parent_link)
1513 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1514 else if (node->level_group)
1515 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1517 initCursor(i, IMG_MENU_BUTTON);
1520 game_status = last_game_status; /* restore current game status */
1522 redraw_mask |= REDRAW_FIELD;
1525 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1527 TreeInfo *node, *node_first;
1528 int x, last_redraw_mask = redraw_mask;
1530 int ypos = MENU_TITLE2_YPOS;
1535 if (ti->type != TREE_TYPE_LEVEL_DIR)
1538 node_first = getTreeInfoFirstGroupEntry(ti);
1539 node = getTreeInfoFromPos(node_first, entry_pos);
1541 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1543 if (node->parent_link)
1544 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1546 else if (node->level_group)
1547 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1549 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1550 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1551 node->levels, node->class_desc);
1553 /* let BackToFront() redraw only what is needed */
1554 redraw_mask = last_redraw_mask | REDRAW_TILES;
1555 for (x = 0; x < SCR_FIELDX; x++)
1556 MarkTileDirty(x, 1);
1559 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1562 TreeInfo *ti = *ti_ptr;
1564 int y = ti->cl_cursor;
1565 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1566 int num_entries = numTreeInfoInGroup(ti);
1567 int num_page_entries;
1568 int last_game_status = game_status; /* save current game status */
1569 boolean position_set_by_scrollbar = (dx == 999);
1571 /* force LEVELS draw offset on choose level and artwork setup screen */
1572 game_status = GAME_MODE_LEVELS;
1574 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1575 num_page_entries = num_entries;
1577 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1579 game_status = last_game_status; /* restore current game status */
1581 if (button == MB_MENU_INITIALIZE)
1583 int num_entries = numTreeInfoInGroup(ti);
1584 int entry_pos = posTreeInfo(ti);
1586 if (ti->cl_first == -1)
1588 /* only on initialization */
1589 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1590 ti->cl_cursor = entry_pos - ti->cl_first;
1592 else if (ti->cl_cursor >= num_page_entries ||
1593 (num_entries > num_page_entries &&
1594 num_entries - ti->cl_first < num_page_entries))
1596 /* only after change of list size (by custom graphic configuration) */
1597 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1598 ti->cl_cursor = entry_pos - ti->cl_first;
1601 if (position_set_by_scrollbar)
1604 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1607 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1608 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1609 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1613 else if (button == MB_MENU_LEAVE)
1615 if (ti->node_parent)
1617 *ti_ptr = ti->node_parent;
1618 DrawChooseTree(ti_ptr);
1620 else if (game_status == GAME_MODE_SETUP)
1626 game_status = GAME_MODE_MAIN;
1633 if (mx || my) /* mouse input */
1635 int last_game_status = game_status; /* save current game status */
1637 /* force LEVELS draw offset on artwork setup screen */
1638 game_status = GAME_MODE_LEVELS;
1640 x = (mx - mSX) / 32;
1641 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1643 game_status = last_game_status; /* restore current game status */
1645 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1647 /* move cursor instead of scrolling when already at start/end of list */
1648 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1650 else if (dy == +1 * SCROLL_LINE &&
1651 ti->cl_first + num_page_entries == num_entries)
1654 /* handle scrolling screen one line or page */
1655 if (ti->cl_cursor + dy < 0 ||
1656 ti->cl_cursor + dy > num_page_entries - 1)
1658 if (ABS(dy) == SCROLL_PAGE)
1659 step = num_page_entries - 1;
1661 if (dy < 0 && ti->cl_first > 0)
1663 /* scroll page/line up */
1665 ti->cl_first -= step;
1666 if (ti->cl_first < 0)
1669 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1670 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1671 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1672 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1675 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1677 /* scroll page/line down */
1679 ti->cl_first += step;
1680 if (ti->cl_first + num_page_entries > num_entries)
1681 ti->cl_first = MAX(0, num_entries - num_page_entries);
1683 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1684 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1685 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1686 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1693 /* handle moving cursor one line */
1694 y = ti->cl_cursor + dy;
1699 TreeInfo *node_first, *node_cursor;
1700 int entry_pos = ti->cl_first + y;
1702 node_first = getTreeInfoFirstGroupEntry(ti);
1703 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1705 if (node_cursor->node_group)
1707 node_cursor->cl_first = ti->cl_first;
1708 node_cursor->cl_cursor = ti->cl_cursor;
1709 *ti_ptr = node_cursor->node_group;
1710 DrawChooseTree(ti_ptr);
1715 else if (dx == -1 && ti->node_parent)
1717 *ti_ptr = ti->node_parent;
1718 DrawChooseTree(ti_ptr);
1723 if (!anyScrollbarGadgetActive() &&
1724 IN_VIS_FIELD(x, y) &&
1725 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1726 y >= 0 && y < num_page_entries)
1730 if (y != ti->cl_cursor)
1732 drawChooseTreeCursor(y, FC_RED);
1733 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1734 drawChooseTreeInfo(ti->cl_first + y, ti);
1740 TreeInfo *node_first, *node_cursor;
1741 int entry_pos = ti->cl_first + y;
1743 node_first = getTreeInfoFirstGroupEntry(ti);
1744 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1746 if (node_cursor->node_group)
1748 node_cursor->cl_first = ti->cl_first;
1749 node_cursor->cl_cursor = ti->cl_cursor;
1750 *ti_ptr = node_cursor->node_group;
1751 DrawChooseTree(ti_ptr);
1753 else if (node_cursor->parent_link)
1755 *ti_ptr = node_cursor->node_parent;
1756 DrawChooseTree(ti_ptr);
1760 node_cursor->cl_first = ti->cl_first;
1761 node_cursor->cl_cursor = ti->cl_cursor;
1762 *ti_ptr = node_cursor;
1764 if (ti->type == TREE_TYPE_LEVEL_DIR)
1766 LoadLevelSetup_SeriesInfo();
1768 SaveLevelSetup_LastSeries();
1769 SaveLevelSetup_SeriesInfo();
1773 if (game_status == GAME_MODE_SETUP)
1779 game_status = GAME_MODE_MAIN;
1787 void DrawChooseLevel()
1789 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1791 DrawChooseTree(&leveldir_current);
1797 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1799 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1804 void DrawHallOfFame(int highlight_position)
1807 FadeSoundsAndMusic();
1808 CloseDoor(DOOR_CLOSE_2);
1810 if (highlight_position < 0)
1811 LoadScore(level_nr);
1819 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1822 static void drawHallOfFameList(int first_entry, int highlight_position)
1826 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1830 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
1831 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1832 "HighScores of Level %d", level_nr);
1834 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
1835 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1836 "HighScores of Level %d", level_nr);
1839 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1841 int entry = first_entry + i;
1842 boolean active = (entry == highlight_position);
1843 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1844 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1845 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1846 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1847 int dx1 = 3 * getFontWidth(font_nr1);
1848 int dx2 = dx1 + getFontWidth(font_nr1);
1849 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1850 int sy = mSY + 64 + i * 32;
1852 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1853 DrawText(mSX + dx1, sy, ".", font_nr1);
1854 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1855 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1856 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1857 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1860 redraw_mask |= REDRAW_FIELD;
1863 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1865 static int first_entry = 0;
1866 static int highlight_position = 0;
1867 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1868 int button_released = !button;
1870 if (button == MB_MENU_INITIALIZE)
1873 highlight_position = mx;
1874 drawHallOfFameList(first_entry, highlight_position);
1879 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1880 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1884 if (first_entry > 0)
1886 first_entry -= step;
1887 if (first_entry < 0)
1890 drawHallOfFameList(first_entry, highlight_position);
1895 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1897 first_entry += step;
1898 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1899 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1901 drawHallOfFameList(first_entry, highlight_position);
1904 else if (button_released)
1906 FadeSound(SND_BACKGROUND_SCORES);
1907 game_status = GAME_MODE_MAIN;
1911 if (game_status == GAME_MODE_SCORES)
1912 PlayMenuSoundIfLoop();
1918 /* ========================================================================= */
1919 /* setup screen functions */
1920 /* ========================================================================= */
1922 static struct TokenInfo *setup_info;
1923 static int num_setup_info;
1925 static char *graphics_set_name;
1926 static char *sounds_set_name;
1927 static char *music_set_name;
1929 static void execSetupMain()
1931 setup_mode = SETUP_MODE_MAIN;
1935 static void execSetupGame()
1937 setup_mode = SETUP_MODE_GAME;
1941 static void execSetupEditor()
1943 setup_mode = SETUP_MODE_EDITOR;
1947 static void execSetupGraphics()
1949 setup_mode = SETUP_MODE_GRAPHICS;
1953 static void execSetupSound()
1955 setup_mode = SETUP_MODE_SOUND;
1959 static void execSetupArtwork()
1961 setup.graphics_set = artwork.gfx_current->identifier;
1962 setup.sounds_set = artwork.snd_current->identifier;
1963 setup.music_set = artwork.mus_current->identifier;
1965 /* needed if last screen (setup choice) changed graphics, sounds or music */
1966 ReloadCustomArtwork(0);
1968 /* needed for displaying artwork name instead of artwork identifier */
1969 graphics_set_name = artwork.gfx_current->name;
1970 sounds_set_name = artwork.snd_current->name;
1971 music_set_name = artwork.mus_current->name;
1973 setup_mode = SETUP_MODE_ARTWORK;
1977 static void execSetupChooseGraphics()
1979 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1983 static void execSetupChooseSounds()
1985 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1989 static void execSetupChooseMusic()
1991 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1995 static void execSetupInput()
1997 setup_mode = SETUP_MODE_INPUT;
2001 static void execSetupShortcut()
2003 setup_mode = SETUP_MODE_SHORTCUT;
2007 static void execExitSetup()
2009 game_status = GAME_MODE_MAIN;
2013 static void execSaveAndExitSetup()
2019 static struct TokenInfo setup_info_main[] =
2021 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
2022 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
2023 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2024 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2025 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2026 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2027 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
2028 { TYPE_EMPTY, NULL, "" },
2029 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2030 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2035 static struct TokenInfo setup_info_game[] =
2037 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
2038 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2039 { TYPE_SWITCH, &setup.skip_levels, "Skip Levels:" },
2040 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
2041 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
2042 { TYPE_EMPTY, NULL, "" },
2043 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2048 static struct TokenInfo setup_info_editor[] =
2051 { TYPE_STRING, NULL, "Offer Special Elements:"},
2056 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
2057 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2058 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,"E.M.C.:" },
2059 { TYPE_SWITCH, &setup.editor.el_more, "R'n'D:" },
2060 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2061 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2062 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "DC II:" },
2063 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX BD:" },
2065 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
2066 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
2067 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2068 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
2069 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic:" },
2070 { TYPE_EMPTY, NULL, "" },
2071 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2076 static struct TokenInfo setup_info_graphics[] =
2078 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2079 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
2080 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
2082 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
2083 { TYPE_SWITCH, &setup.fading, "Fading:" },
2085 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
2086 { TYPE_SWITCH, &setup.toons, "Toons:" },
2087 { TYPE_EMPTY, NULL, "" },
2088 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2093 static struct TokenInfo setup_info_sound[] =
2095 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
2096 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
2097 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
2098 { TYPE_EMPTY, NULL, "" },
2099 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2104 static struct TokenInfo setup_info_artwork[] =
2106 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2107 { TYPE_STRING, &graphics_set_name, "" },
2108 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2109 { TYPE_STRING, &sounds_set_name, "" },
2110 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2111 { TYPE_STRING, &music_set_name, "" },
2112 { TYPE_EMPTY, NULL, "" },
2113 { TYPE_STRING, NULL, "Override Level Artwork:"},
2114 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2115 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2116 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2117 { TYPE_EMPTY, NULL, "" },
2118 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2123 static struct TokenInfo setup_info_shortcut[] =
2125 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2126 { TYPE_KEY, &setup.shortcut.save_game, "" },
2127 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2128 { TYPE_KEY, &setup.shortcut.load_game, "" },
2129 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2130 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2131 { TYPE_EMPTY, NULL, "" },
2132 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2133 { TYPE_EMPTY, NULL, "" },
2134 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2139 static Key getSetupKey()
2141 Key key = KSYM_UNDEFINED;
2142 boolean got_key_event = FALSE;
2144 while (!got_key_event)
2146 if (PendingEvent()) /* got event */
2154 case EVENT_KEYPRESS:
2156 key = GetEventKey((KeyEvent *)&event, TRUE);
2158 /* press 'Escape' or 'Enter' to keep the existing key binding */
2159 if (key == KSYM_Escape || key == KSYM_Return)
2160 key = KSYM_UNDEFINED; /* keep old value */
2162 got_key_event = TRUE;
2166 case EVENT_KEYRELEASE:
2167 key_joystick_mapping = 0;
2171 HandleOtherEvents(&event);
2179 /* don't eat all CPU time */
2186 static void drawSetupValue(int pos)
2188 int xpos = MENU_SCREEN_VALUE_XPOS;
2189 int ypos = MENU_SCREEN_START_YPOS + pos;
2190 int font_nr = FONT_VALUE_1;
2191 int type = setup_info[pos].type;
2192 void *value = setup_info[pos].value;
2193 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2196 if (value_string == NULL)
2199 if (type & TYPE_KEY)
2203 if (type & TYPE_QUERY)
2205 value_string = "<press key>";
2206 font_nr = FONT_INPUT_1_ACTIVE;
2209 else if (type & TYPE_STRING)
2211 int max_value_len = (SCR_FIELDX - 2) * 2;
2214 font_nr = FONT_VALUE_2;
2216 if (strlen(value_string) > max_value_len)
2217 value_string[max_value_len] = '\0';
2219 else if (type & TYPE_BOOLEAN_STYLE)
2221 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2224 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2225 (xpos == 3 ? " " : " "), font_nr);
2226 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2229 static void changeSetupValue(int pos)
2231 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2233 *(boolean *)setup_info[pos].value ^= TRUE;
2235 else if (setup_info[pos].type & TYPE_KEY)
2239 setup_info[pos].type |= TYPE_QUERY;
2240 drawSetupValue(pos);
2241 setup_info[pos].type &= ~TYPE_QUERY;
2243 key = getSetupKey();
2244 if (key != KSYM_UNDEFINED)
2245 *(Key *)setup_info[pos].value = key;
2248 drawSetupValue(pos);
2251 static void DrawSetupScreen_Generic()
2253 char *title_string = NULL;
2257 CloseDoor(DOOR_CLOSE_2);
2261 if (setup_mode == SETUP_MODE_MAIN)
2263 setup_info = setup_info_main;
2264 title_string = "Setup";
2266 else if (setup_mode == SETUP_MODE_GAME)
2268 setup_info = setup_info_game;
2269 title_string = "Setup Game";
2271 else if (setup_mode == SETUP_MODE_EDITOR)
2273 setup_info = setup_info_editor;
2274 title_string = "Setup Editor";
2276 else if (setup_mode == SETUP_MODE_GRAPHICS)
2278 setup_info = setup_info_graphics;
2279 title_string = "Setup Graphics";
2281 else if (setup_mode == SETUP_MODE_SOUND)
2283 setup_info = setup_info_sound;
2284 title_string = "Setup Sound";
2286 else if (setup_mode == SETUP_MODE_ARTWORK)
2288 setup_info = setup_info_artwork;
2289 title_string = "Custom Artwork";
2291 else if (setup_mode == SETUP_MODE_SHORTCUT)
2293 setup_info = setup_info_shortcut;
2294 title_string = "Setup Shortcuts";
2298 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2300 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2304 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2306 void *value_ptr = setup_info[i].value;
2307 int ypos = MENU_SCREEN_START_YPOS + i;
2308 int font_nr = FONT_MENU_1;
2310 /* set some entries to "unchangeable" according to other variables */
2311 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2312 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2313 (value_ptr == &setup.sound_music && !audio.music_available) ||
2314 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2315 setup_info[i].type |= TYPE_GHOSTED;
2317 if (setup_info[i].type & TYPE_STRING)
2318 font_nr = FONT_MENU_2;
2320 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2322 if (setup_info[i].type & TYPE_ENTER_MENU)
2323 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2324 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2325 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2326 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2327 initCursor(i, IMG_MENU_BUTTON);
2329 if (setup_info[i].type & TYPE_VALUE)
2336 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2337 "Joysticks deactivated in setup menu");
2342 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2345 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2347 static int choice_store[MAX_SETUP_MODES];
2348 int choice = choice_store[setup_mode]; /* always starts with 0 */
2352 if (button == MB_MENU_INITIALIZE)
2354 /* advance to first valid menu entry */
2355 while (choice < num_setup_info &&
2356 setup_info[choice].type & TYPE_SKIP_ENTRY)
2358 choice_store[setup_mode] = choice;
2360 drawCursor(choice, FC_RED);
2363 else if (button == MB_MENU_LEAVE)
2365 for (y = 0; y < num_setup_info; y++)
2367 if (setup_info[y].type & TYPE_LEAVE_MENU)
2369 void (*menu_callback_function)(void) = setup_info[y].value;
2371 menu_callback_function();
2372 break; /* absolutely needed because function changes 'setup_info'! */
2379 if (mx || my) /* mouse input */
2381 x = (mx - mSX) / 32;
2382 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2384 else if (dx || dy) /* keyboard input */
2388 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2390 if (setup_info[choice].type & menu_navigation_type ||
2391 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2392 button = MB_MENU_CHOICE;
2397 /* jump to next non-empty menu entry (up or down) */
2398 while (y > 0 && y < num_setup_info - 1 &&
2399 setup_info[y].type & TYPE_SKIP_ENTRY)
2403 if (IN_VIS_FIELD(x, y) &&
2404 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2410 drawCursor(y, FC_RED);
2411 drawCursor(choice, FC_BLUE);
2412 choice = choice_store[setup_mode] = y;
2415 else if (!(setup_info[y].type & TYPE_GHOSTED))
2417 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2419 void (*menu_callback_function)(void) = setup_info[choice].value;
2421 menu_callback_function();
2425 if (setup_info[y].type & TYPE_KEYTEXT &&
2426 setup_info[y + 1].type & TYPE_KEY)
2429 if (setup_info[y].type & TYPE_VALUE)
2430 changeSetupValue(y);
2436 void DrawSetupScreen_Input()
2441 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2443 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2446 initCursor(0, IMG_MENU_BUTTON);
2447 initCursor(1, IMG_MENU_BUTTON);
2448 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2449 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2451 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2452 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2454 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2455 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2456 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2459 DeactivateJoystickForCalibration();
2462 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2463 "Joysticks deactivated on this screen");
2466 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2471 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2473 if (device_name == NULL)
2476 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2479 if (strlen(device_name) > 1)
2481 char c1 = device_name[strlen(device_name) - 1];
2482 char c2 = device_name[strlen(device_name) - 2];
2484 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2485 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2488 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2489 strlen(device_name));
2492 static void drawPlayerSetupInputInfo(int player_nr)
2495 static struct SetupKeyboardInfo custom_key;
2502 { &custom_key.left, "Joystick Left" },
2503 { &custom_key.right, "Joystick Right" },
2504 { &custom_key.up, "Joystick Up" },
2505 { &custom_key.down, "Joystick Down" },
2506 { &custom_key.snap, "Button 1" },
2507 { &custom_key.drop, "Button 2" }
2509 static char *joystick_name[MAX_PLAYERS] =
2517 custom_key = setup.input[player_nr].key;
2519 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2520 FONT_INPUT_1_ACTIVE);
2522 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2524 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2525 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2527 if (setup.input[player_nr].use_joystick)
2529 char *device_name = setup.input[player_nr].joy.device_name;
2531 DrawText(mSX + 8 * 32, mSY + 3 * 32,
2532 joystick_name[getJoystickNrFromDeviceName(device_name)],
2534 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
2538 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
2539 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
2542 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
2543 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2544 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2545 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2546 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2547 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
2548 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
2549 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
2550 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
2551 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
2552 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
2554 for (i = 0; i < 6; i++)
2556 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2558 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2560 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2561 (setup.input[player_nr].use_joystick ?
2563 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2567 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2569 static int choice = 0;
2570 static int player_nr = 0;
2573 int pos_start = SETUPINPUT_SCREEN_POS_START;
2574 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2575 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2576 int pos_end = SETUPINPUT_SCREEN_POS_END;
2578 if (button == MB_MENU_INITIALIZE)
2580 drawPlayerSetupInputInfo(player_nr);
2581 drawCursor(choice, FC_RED);
2585 else if (button == MB_MENU_LEAVE)
2587 setup_mode = SETUP_MODE_MAIN;
2594 if (mx || my) /* mouse input */
2596 x = (mx - mSX) / 32;
2597 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2599 else if (dx || dy) /* keyboard input */
2601 if (dx && choice == 0)
2602 x = (dx < 0 ? 10 : 12);
2603 else if ((dx && choice == 1) ||
2604 (dx == +1 && choice == 2) ||
2605 (dx == -1 && choice == pos_end))
2606 button = MB_MENU_CHOICE;
2610 if (y >= pos_empty1 && y <= pos_empty2)
2611 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2614 if (IN_VIS_FIELD(x, y) &&
2615 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2617 static unsigned long delay = 0;
2619 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2622 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2624 drawPlayerSetupInputInfo(player_nr);
2626 else if (IN_VIS_FIELD(x, y) &&
2627 y >= pos_start && y <= pos_end &&
2628 !(y >= pos_empty1 && y <= pos_empty2))
2634 drawCursor(y, FC_RED);
2635 drawCursor(choice, FC_BLUE);
2643 char *device_name = setup.input[player_nr].joy.device_name;
2645 if (!setup.input[player_nr].use_joystick)
2647 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2649 setJoystickDeviceToNr(device_name, new_device_nr);
2650 setup.input[player_nr].use_joystick = TRUE;
2654 int device_nr = getJoystickNrFromDeviceName(device_name);
2655 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2657 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2658 setup.input[player_nr].use_joystick = FALSE;
2660 setJoystickDeviceToNr(device_name, new_device_nr);
2663 drawPlayerSetupInputInfo(player_nr);
2667 if (setup.input[player_nr].use_joystick)
2670 CalibrateJoystick(player_nr);
2673 CustomizeKeyboard(player_nr);
2675 else if (y == pos_end)
2679 setup_mode = SETUP_MODE_MAIN;
2686 void CustomizeKeyboard(int player_nr)
2690 boolean finished = FALSE;
2691 static struct SetupKeyboardInfo custom_key;
2696 } customize_step[] =
2698 { &custom_key.left, "Move Left" },
2699 { &custom_key.right, "Move Right" },
2700 { &custom_key.up, "Move Up" },
2701 { &custom_key.down, "Move Down" },
2702 { &custom_key.snap, "Snap Field" },
2703 { &custom_key.drop, "Drop Element" }
2706 /* read existing key bindings from player setup */
2707 custom_key = setup.input[player_nr].key;
2712 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
2714 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2721 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2722 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2723 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2724 "Key:", FONT_INPUT_1_ACTIVE);
2725 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2726 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2730 if (PendingEvent()) /* got event */
2738 case EVENT_KEYPRESS:
2740 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2742 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2748 /* all keys configured -- wait for "Escape" or "Return" key */
2752 /* press 'Enter' to keep the existing key binding */
2753 if (key == KSYM_Return)
2754 key = *customize_step[step_nr].key;
2756 /* check if key already used */
2757 for (i = 0; i < step_nr; i++)
2758 if (*customize_step[i].key == key)
2763 /* got new key binding */
2764 *customize_step[step_nr].key = key;
2765 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2767 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2768 getKeyNameFromKey(key), FONT_VALUE_1);
2771 /* un-highlight last query */
2772 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
2773 customize_step[step_nr - 1].text, FONT_MENU_1);
2774 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
2775 "Key:", FONT_MENU_1);
2777 /* press 'Enter' to leave */
2780 DrawText(mSX + 16, mSY + 15 * 32 + 16,
2781 "Press Enter", FONT_TITLE_1);
2785 /* query next key binding */
2786 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2787 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2788 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2789 "Key:", FONT_INPUT_1_ACTIVE);
2790 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2791 getKeyNameFromKey(*customize_step[step_nr].key),
2796 case EVENT_KEYRELEASE:
2797 key_joystick_mapping = 0;
2801 HandleOtherEvents(&event);
2809 /* don't eat all CPU time */
2813 /* write new key bindings back to player setup */
2814 setup.input[player_nr].key = custom_key;
2817 DrawSetupScreen_Input();
2820 static boolean CalibrateJoystickMain(int player_nr)
2822 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2823 int new_joystick_xright = JOYSTICK_XMIDDLE;
2824 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2825 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2826 int new_joystick_xmiddle, new_joystick_ymiddle;
2828 int joystick_fd = joystick.fd[player_nr];
2829 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2830 boolean check[3][3];
2831 int check_remaining = 3 * 3;
2836 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2839 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2844 for (y = 0; y < 3; y++)
2846 for (x = 0; x < 3; x++)
2848 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2849 check[x][y] = FALSE;
2853 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
2854 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
2855 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
2856 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
2857 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
2858 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
2859 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
2861 joy_value = Joystick(player_nr);
2862 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2863 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2865 /* eventually uncalibrated center position (joystick could be uncentered) */
2866 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2869 new_joystick_xmiddle = joy_x;
2870 new_joystick_ymiddle = joy_y;
2872 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2875 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2880 if (PendingEvent()) /* got event */
2888 case EVENT_KEYPRESS:
2889 switch(GetEventKey((KeyEvent *)&event, TRUE))
2892 if (check_remaining == 0)
2905 case EVENT_KEYRELEASE:
2906 key_joystick_mapping = 0;
2910 HandleOtherEvents(&event);
2915 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2918 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
2919 new_joystick_xright = MAX(new_joystick_xright, joy_x);
2920 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
2921 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
2923 setup.input[player_nr].joy.xleft = new_joystick_xleft;
2924 setup.input[player_nr].joy.yupper = new_joystick_yupper;
2925 setup.input[player_nr].joy.xright = new_joystick_xright;
2926 setup.input[player_nr].joy.ylower = new_joystick_ylower;
2927 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
2928 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
2930 CheckJoystickData();
2932 joy_value = Joystick(player_nr);
2934 if (joy_value & JOY_BUTTON && check_remaining == 0)
2937 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2938 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2940 if (x != last_x || y != last_y)
2942 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
2943 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
2948 if (check_remaining > 0 && !check[x+1][y+1])
2950 check[x+1][y+1] = TRUE;
2956 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2957 setup.input[player_nr].joy.xleft,
2958 setup.input[player_nr].joy.xmiddle,
2959 setup.input[player_nr].joy.xright);
2960 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2961 setup.input[player_nr].joy.yupper,
2962 setup.input[player_nr].joy.ymiddle,
2963 setup.input[player_nr].joy.ylower);
2972 /* don't eat all CPU time */
2976 /* calibrated center position (joystick should now be centered) */
2977 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2980 new_joystick_xmiddle = joy_x;
2981 new_joystick_ymiddle = joy_y;
2985 DrawSetupScreen_Input();
2987 /* wait until the last pressed button was released */
2988 while (Joystick(player_nr) & JOY_BUTTON)
2990 if (PendingEvent()) /* got event */
2995 HandleOtherEvents(&event);
3004 void CalibrateJoystick(int player_nr)
3006 if (!CalibrateJoystickMain(player_nr))
3010 DrawText(mSX + 16, mSY + 6 * 32, " JOYSTICK NOT ", FONT_TITLE_1);
3011 DrawText(mSX, mSY + 7 * 32, " AVAILABLE ", FONT_TITLE_1);
3013 Delay(2000); /* show error message for two seconds */
3017 void DrawSetupScreen()
3019 DeactivateJoystick();
3021 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3023 if (setup_mode == SETUP_MODE_INPUT)
3024 DrawSetupScreen_Input();
3025 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3026 DrawChooseTree(&artwork.gfx_current);
3027 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3028 DrawChooseTree(&artwork.snd_current);
3029 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3030 DrawChooseTree(&artwork.mus_current);
3032 DrawSetupScreen_Generic();
3038 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3040 if (setup_mode == SETUP_MODE_INPUT)
3041 HandleSetupScreen_Input(mx, my, dx, dy, button);
3042 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3043 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3044 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3045 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3046 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3047 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3049 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3054 void HandleGameActions()
3056 if (game_status != GAME_MODE_PLAYING)
3059 /* !!! FIX THIS (START) !!! */
3060 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
3062 byte *recorded_player_action;
3063 byte summarized_player_action = 0;
3064 byte tape_action[MAX_PLAYERS];
3067 if (level.native_em_level->lev->home == 0) /* all players at home */
3071 if (!TAPE_IS_STOPPED(tape))
3074 if (game_status != GAME_MODE_PLAYING)
3078 if (level.native_em_level->ply1->alive == 0 &&
3079 level.native_em_level->ply2->alive == 0) /* all dead */
3080 AllPlayersGone = TRUE;
3082 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3085 /* --- game actions --- */
3089 /* don't use 100% CPU while in pause mode -- this should better be solved
3090 like in the R'n'D game engine! */
3097 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
3100 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
3101 if (recorded_player_action == NULL && tape.pausing)
3105 for (i = 0; i < MAX_PLAYERS; i++)
3107 summarized_player_action |= stored_player[i].action;
3109 if (!network_playing)
3110 stored_player[i].effective_action = stored_player[i].action;
3113 if (!options.network && !setup.team_mode)
3114 local_player->effective_action = summarized_player_action;
3116 if (recorded_player_action != NULL)
3117 for (i = 0; i < MAX_PLAYERS; i++)
3118 stored_player[i].effective_action = recorded_player_action[i];
3120 for (i = 0; i < MAX_PLAYERS; i++)
3122 tape_action[i] = stored_player[i].effective_action;
3124 /* !!! (this does not happen in the EM engine) !!! */
3125 if (tape.recording && tape_action[i] && !tape.player_participates[i])
3126 tape.player_participates[i] = TRUE; /* player just appeared from CE */
3129 /* only save actions from input devices, but not programmed actions */
3131 TapeRecordAction(tape_action);
3133 GameActions_EM(local_player->effective_action);
3135 if (TimeFrames >= FRAMES_PER_SECOND)
3140 if (!level.use_step_counter)
3148 if (TimeLeft <= 10 && setup.time_limit)
3149 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
3151 DrawGameValue_Time(TimeLeft);
3153 if (!TimeLeft && setup.time_limit)
3154 level.native_em_level->lev->killed_out_of_time = TRUE;
3156 else if (level.time == 0 && level.native_em_level->lev->home > 0)
3157 DrawGameValue_Time(TimePlayed);
3159 level.native_em_level->lev->time =
3160 (level.time == 0 ? TimePlayed : TimeLeft);
3163 if (tape.recording || tape.playing)
3164 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
3174 if (game.restart_level)
3175 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
3177 if (local_player->LevelSolved)
3180 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3186 if (tape.auto_play && !tape.playing)
3187 AutoPlayTape(); /* continue automatically playing next tape */
3191 void StartGameActions(boolean init_network_game, boolean record_tape,
3195 TapeStartRecording(random_seed);
3197 #if defined(NETWORK_AVALIABLE)
3198 if (init_network_game)
3200 SendToServer_StartPlaying();
3208 game_status = GAME_MODE_PLAYING;
3210 InitRND(random_seed);
3215 /* ---------- new screen button stuff -------------------------------------- */
3217 /* graphic position and size values for buttons and scrollbars */
3218 #define SC_SCROLLBUTTON_XSIZE TILEX
3219 #define SC_SCROLLBUTTON_YSIZE TILEY
3221 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3222 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3223 SC_SCROLLBUTTON_YSIZE)
3224 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3225 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3226 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3227 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3228 SC_SCROLLBUTTON_YSIZE)
3229 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3230 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3231 SC_SCROLL_VERTICAL_YSIZE)
3233 #define SC_BORDER_SIZE 14
3237 int gfx_unpressed, gfx_pressed;
3241 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3244 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3245 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3246 SCREEN_CTRL_ID_SCROLL_UP,
3250 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3251 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3252 SCREEN_CTRL_ID_SCROLL_DOWN,
3259 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3260 Bitmap **gfx_unpressed, **gfx_pressed;
3262 int gfx_unpressed, gfx_pressed;
3269 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3272 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3273 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3275 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3277 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3278 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3279 GD_TYPE_SCROLLBAR_VERTICAL,
3280 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3281 "scroll level series vertically"
3285 static void CreateScreenScrollbuttons()
3287 struct GadgetInfo *gi;
3288 unsigned long event_mask;
3291 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3293 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3294 int gfx_unpressed, gfx_pressed;
3295 int x, y, width, height;
3296 int gd_x1, gd_x2, gd_y1, gd_y2;
3297 int id = scrollbutton_info[i].gadget_id;
3299 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3301 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3302 y = mSY + scrollbutton_info[i].y;
3303 width = SC_SCROLLBUTTON_XSIZE;
3304 height = SC_SCROLLBUTTON_YSIZE;
3306 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3307 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3308 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3310 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3311 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3312 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3313 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3314 gd_x1 = graphic_info[gfx_unpressed].src_x;
3315 gd_y1 = graphic_info[gfx_unpressed].src_y;
3316 gd_x2 = graphic_info[gfx_pressed].src_x;
3317 gd_y2 = graphic_info[gfx_pressed].src_y;
3319 gi = CreateGadget(GDI_CUSTOM_ID, id,
3320 GDI_CUSTOM_TYPE_ID, i,
3321 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3326 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3327 GDI_STATE, GD_BUTTON_UNPRESSED,
3328 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3329 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3330 GDI_DIRECT_DRAW, FALSE,
3331 GDI_EVENT_MASK, event_mask,
3332 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3336 Error(ERR_EXIT, "cannot create gadget");
3338 screen_gadget[id] = gi;
3342 static void CreateScreenScrollbars()
3346 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3348 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3349 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3350 int gfx_unpressed, gfx_pressed;
3352 int x, y, width, height;
3353 int gd_x1, gd_x2, gd_y1, gd_y2;
3354 struct GadgetInfo *gi;
3355 int items_max, items_visible, item_position;
3356 unsigned long event_mask;
3357 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3358 int id = scrollbar_info[i].gadget_id;
3360 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3362 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3363 y = mSY + scrollbar_info[i].y;
3364 width = scrollbar_info[i].width;
3365 height = scrollbar_info[i].height;
3367 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3368 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3370 items_max = num_page_entries;
3371 items_visible = num_page_entries;
3374 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3375 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3376 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3382 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3383 gfx_pressed = scrollbar_info[i].gfx_pressed;
3384 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3385 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3386 gd_x1 = graphic_info[gfx_unpressed].src_x;
3387 gd_y1 = graphic_info[gfx_unpressed].src_y;
3388 gd_x2 = graphic_info[gfx_pressed].src_x;
3389 gd_y2 = graphic_info[gfx_pressed].src_y;
3392 gi = CreateGadget(GDI_CUSTOM_ID, id,
3393 GDI_CUSTOM_TYPE_ID, i,
3394 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3399 GDI_TYPE, scrollbar_info[i].type,
3400 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3401 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3402 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3403 GDI_STATE, GD_BUTTON_UNPRESSED,
3404 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3405 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3406 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3407 GDI_DIRECT_DRAW, FALSE,
3408 GDI_EVENT_MASK, event_mask,
3409 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3413 Error(ERR_EXIT, "cannot create gadget");
3415 screen_gadget[id] = gi;
3419 void CreateScreenGadgets()
3421 int last_game_status = game_status; /* save current game status */
3423 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3426 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3428 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3430 /* copy pointers to clip mask and GC */
3431 scrollbar_bitmap[i]->clip_mask =
3432 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3433 scrollbar_bitmap[i]->stored_clip_gc =
3434 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3436 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3437 scrollbar_bitmap[i],
3438 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3439 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3440 TILEX, TILEY, 0, 0);
3444 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3445 game_status = GAME_MODE_LEVELS;
3447 CreateScreenScrollbuttons();
3448 CreateScreenScrollbars();
3450 game_status = last_game_status; /* restore current game status */
3453 void FreeScreenGadgets()
3457 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3458 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3460 /* prevent freeing clip mask and GC twice */
3461 scrollbar_bitmap[i]->clip_mask = None;
3462 scrollbar_bitmap[i]->stored_clip_gc = None;
3464 FreeBitmap(scrollbar_bitmap[i]);
3468 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3469 FreeGadget(screen_gadget[i]);
3472 void MapChooseTreeGadgets(TreeInfo *ti)
3474 int num_entries = numTreeInfoInGroup(ti);
3477 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3480 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3481 MapGadget(screen_gadget[i]);
3485 void UnmapChooseTreeGadgets()
3489 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3490 UnmapGadget(screen_gadget[i]);
3494 static void HandleScreenGadgets(struct GadgetInfo *gi)
3496 int id = gi->custom_id;
3498 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3503 case SCREEN_CTRL_ID_SCROLL_UP:
3504 if (game_status == GAME_MODE_LEVELS)
3505 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3506 else if (game_status == GAME_MODE_SETUP)
3507 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3510 case SCREEN_CTRL_ID_SCROLL_DOWN:
3511 if (game_status == GAME_MODE_LEVELS)
3512 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3513 else if (game_status == GAME_MODE_SETUP)
3514 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3517 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3518 if (game_status == GAME_MODE_LEVELS)
3519 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3520 else if (game_status == GAME_MODE_SETUP)
3521 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);