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 DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
101 x <= GAME_MODE_SETUP ? x : \
102 x == GAME_MODE_PSEUDO_TYPENAME ? \
103 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
105 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
106 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
108 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
109 menu.list_size[game_status] : \
110 MAX_MENU_ENTRIES_ON_SCREEN)
112 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
113 #define NUM_SCROLLBAR_BITMAPS 2
114 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
118 static void drawCursorExt(int xpos, int ypos, int color, int g)
120 static int cursor_array[SCR_FIELDY];
125 cursor_array[ypos] = g;
127 g = cursor_array[ypos];
131 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
132 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
133 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
134 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
135 IMG_MENU_BUTTON_ACTIVE);
137 ypos += MENU_SCREEN_START_YPOS;
139 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
140 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
143 static void initCursor(int ypos, int graphic)
145 drawCursorExt(0, ypos, FC_BLUE, graphic);
148 static void drawCursor(int ypos, int color)
150 drawCursorExt(0, ypos, color, 0);
153 static void drawCursorXY(int xpos, int ypos, int graphic)
155 drawCursorExt(xpos, ypos, -1, graphic);
158 static void drawChooseTreeCursor(int ypos, int color)
160 int last_game_status = game_status; /* save current game status */
162 /* force LEVELS draw offset on artwork setup screen */
163 game_status = GAME_MODE_LEVELS;
165 drawCursorExt(0, ypos, color, 0);
167 game_status = last_game_status; /* restore current game status */
170 static void PlayMenuSound()
172 int sound = menu.sound[game_status];
174 if (sound == SND_UNDEFINED)
177 if (sound_info[sound].loop)
178 PlaySoundLoop(sound);
183 static void PlayMenuSoundIfLoop()
185 int sound = menu.sound[game_status];
187 if (sound == SND_UNDEFINED)
190 if (sound_info[sound].loop)
191 PlaySoundLoop(sound);
194 static void PlayMenuMusic()
196 int music = menu.music[game_status];
198 if (music == MUS_UNDEFINED)
206 DrawTextSCentered(8, FONT_TITLE_1, PROGRAM_TITLE_STRING);
207 DrawTextSCentered(46, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
210 static void ToggleFullscreenIfNeeded()
212 if (setup.fullscreen != video.fullscreen_enabled)
214 /* save old door content */
215 BlitBitmap(backbuffer, bitmap_db_door,
216 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
218 /* toggle fullscreen */
219 ChangeVideoModeIfNeeded(setup.fullscreen);
220 setup.fullscreen = video.fullscreen_enabled;
222 /* redraw background to newly created backbuffer */
223 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
224 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
226 /* restore old door content */
227 BlitBitmap(bitmap_db_door, backbuffer,
228 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
230 redraw_mask = REDRAW_ALL;
236 static LevelDirTree *leveldir_last_valid = NULL;
237 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
238 int name_width, level_width;
242 FadeSoundsAndMusic();
244 KeyboardAutoRepeatOn();
247 SetDrawDeactivationMask(REDRAW_NONE);
248 SetDrawBackgroundMask(REDRAW_FIELD);
250 audio.sound_deactivated = FALSE;
252 /* needed if last screen was the playing screen, invoked from level editor */
253 if (level_editor_test_game)
255 game_status = GAME_MODE_EDITOR;
261 /* needed if last screen was the editor screen */
262 UndrawSpecialEditorDoor();
264 /* needed if last screen was the setup screen and fullscreen state changed */
265 ToggleFullscreenIfNeeded();
267 /* leveldir_current may be invalid (level group, parent link) */
268 if (!validLevelSeries(leveldir_current))
269 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
271 /* store valid level series information */
272 leveldir_last_valid = leveldir_current;
274 /* needed if last screen (level choice) changed graphics, sounds or music */
275 ReloadCustomArtwork(0);
278 SetDrawtoField(DRAW_BACKBUFFER);
281 /* map gadgets for main menu screen */
284 /* level_nr may have been set to value over handicap with level editor */
285 if (setup.handicap && level_nr > leveldir_current->handicap_level)
286 level_nr = leveldir_current->handicap_level;
291 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
296 DrawText(mSX + 32, mSY + 2*32, name_text, FONT_MENU_1);
297 DrawText(mSX + 32, mSY + 3*32, "Level:", FONT_MENU_1);
298 DrawText(mSX + 32, mSY + 4*32, "Hall Of Fame", FONT_MENU_1);
299 DrawText(mSX + 32, mSY + 5*32, "Level Creator", FONT_MENU_1);
300 DrawText(mSX + 32, mSY + 6*32, "Info Screen", FONT_MENU_1);
301 DrawText(mSX + 32, mSY + 7*32, "Start Game", FONT_MENU_1);
302 DrawText(mSX + 32, mSY + 8*32, "Setup", FONT_MENU_1);
303 DrawText(mSX + 32, mSY + 9*32, "Quit", FONT_MENU_1);
305 /* calculated after (possible) reload of custom artwork */
306 name_width = getTextWidth(name_text, FONT_MENU_1);
307 level_width = getTextWidth("Level:", FONT_MENU_1);
309 DrawText(mSX + 32 + name_width, mSY + 2*32, setup.player_name, FONT_INPUT_1);
310 DrawText(mSX + level_width + 5 * 32, mSY + 3*32, int2str(level_nr,3),
313 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
315 DrawTextF(mSX + 32 + level_width - 2, mSY + 3*32 + 1, FONT_TEXT_3, "%d-%d",
316 leveldir_current->first_level, leveldir_current->last_level);
318 if (leveldir_current->readonly)
320 DrawTextS(mSX + level_width + 9 * 32 - 2,
321 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
322 DrawTextS(mSX + level_width + 9 * 32 - 2,
323 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
326 for (i = 0; i < 8; i++)
327 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
330 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
331 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
333 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
338 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
341 if (TAPE_IS_EMPTY(tape))
343 DrawCompleteVideoDisplay();
348 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
352 static void gotoTopLevelDir()
354 /* move upwards to top level directory */
355 while (leveldir_current->node_parent)
357 /* write a "path" into level tree for easy navigation to last level */
358 if (leveldir_current->node_parent->node_group->cl_first == -1)
360 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
361 int leveldir_pos = posTreeInfo(leveldir_current);
362 int num_page_entries;
363 int cl_first, cl_cursor;
365 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
366 num_page_entries = num_leveldirs;
368 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
370 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
371 cl_cursor = leveldir_pos - cl_first;
373 leveldir_current->node_parent->node_group->cl_first = cl_first;
374 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
377 leveldir_current = leveldir_current->node_parent;
382 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
384 static unsigned long level_delay = 0;
385 static int choice = 5;
389 if (button == MB_MENU_INITIALIZE)
391 drawCursor(choice, FC_RED);
395 if (mx || my) /* mouse input */
398 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
400 else if (dx || dy) /* keyboard input */
402 if (dx && choice == 1)
403 x = (dx < 0 ? 10 : 14);
408 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
409 (x == 14 && level_nr < leveldir_current->last_level)) &&
410 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
412 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
413 int old_level_nr = level_nr;
416 new_level_nr = level_nr + (x == 10 ? -step : +step);
417 if (new_level_nr < leveldir_current->first_level)
418 new_level_nr = leveldir_current->first_level;
419 if (new_level_nr > leveldir_current->last_level)
420 new_level_nr = leveldir_current->last_level;
422 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
424 /* skipping levels is only allowed when trying to skip single level */
425 if (setup.skip_levels && step == 1 &&
426 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
428 leveldir_current->handicap_level++;
429 SaveLevelSetup_SeriesInfo();
432 new_level_nr = leveldir_current->handicap_level;
435 if (new_level_nr != old_level_nr)
437 level_nr = new_level_nr;
439 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
443 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
447 DrawCompleteVideoDisplay();
449 /* needed because DrawMicroLevel() takes some time */
452 DelayReached(&level_delay, 0); /* reset delay counter */
455 else if (IN_VIS_FIELD(x, y) &&
456 y >= 0 && y <= 7 && (y != 1 || x < 10))
462 drawCursor(y, FC_RED);
463 drawCursor(choice, FC_BLUE);
471 game_status = GAME_MODE_PSEUDO_TYPENAME;
472 HandleTypeName(strlen(setup.player_name), 0);
478 game_status = GAME_MODE_LEVELS;
479 SaveLevelSetup_LastSeries();
480 SaveLevelSetup_SeriesInfo();
491 game_status = GAME_MODE_SCORES;
496 if (leveldir_current->readonly &&
497 strcmp(setup.player_name, "Artsoft") != 0)
498 Request("This level is read only !", REQ_CONFIRM);
499 game_status = GAME_MODE_EDITOR;
504 game_status = GAME_MODE_INFO;
505 info_mode = INFO_MODE_MAIN;
510 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
514 game_status = GAME_MODE_SETUP;
515 setup_mode = SETUP_MODE_MAIN;
521 SaveLevelSetup_LastSeries();
522 SaveLevelSetup_SeriesInfo();
524 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
525 game_status = GAME_MODE_QUIT;
530 if (game_status == GAME_MODE_MAIN)
532 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
538 /* ========================================================================= */
539 /* info screen functions */
540 /* ========================================================================= */
542 static struct TokenInfo *info_info;
543 static int num_info_info;
545 static void execInfoElements()
547 info_mode = INFO_MODE_ELEMENTS;
551 static void execInfoMusic()
553 info_mode = INFO_MODE_MUSIC;
557 static void execInfoCredits()
559 info_mode = INFO_MODE_CREDITS;
563 static void execInfoProgram()
565 info_mode = INFO_MODE_PROGRAM;
569 static void execInfoLevelSet()
571 info_mode = INFO_MODE_LEVELSET;
575 static void execExitInfo()
577 game_status = GAME_MODE_MAIN;
581 static struct TokenInfo info_info_main[] =
583 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
584 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
585 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
586 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
587 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
588 { TYPE_EMPTY, NULL, "" },
589 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
594 static void DrawInfoScreen_Main()
599 CloseDoor(DOOR_CLOSE_2);
603 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
605 info_info = info_info_main;
608 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
610 int ypos = MENU_SCREEN_START_YPOS + i;
611 int font_nr = FONT_MENU_1;
613 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
615 if (info_info[i].type & TYPE_ENTER_MENU)
616 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
617 else if (info_info[i].type & TYPE_LEAVE_MENU)
618 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
619 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
620 initCursor(i, IMG_MENU_BUTTON);
631 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
634 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
636 static int choice_store[MAX_INFO_MODES];
637 int choice = choice_store[info_mode]; /* always starts with 0 */
641 if (button == MB_MENU_INITIALIZE)
643 /* advance to first valid menu entry */
644 while (choice < num_info_info &&
645 info_info[choice].type & TYPE_SKIP_ENTRY)
647 choice_store[info_mode] = choice;
649 drawCursor(choice, FC_RED);
652 else if (button == MB_MENU_LEAVE)
654 for (y = 0; y < num_info_info; y++)
656 if (info_info[y].type & TYPE_LEAVE_MENU)
658 void (*menu_callback_function)(void) = info_info[y].value;
660 menu_callback_function();
661 break; /* absolutely needed because function changes 'info_info'! */
668 if (mx || my) /* mouse input */
671 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
673 else if (dx || dy) /* keyboard input */
677 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
679 if (info_info[choice].type & menu_navigation_type ||
680 info_info[choice].type & TYPE_ENTER_SCREEN ||
681 info_info[choice].type & TYPE_BOOLEAN_STYLE)
682 button = MB_MENU_CHOICE;
687 /* jump to next non-empty menu entry (up or down) */
688 while (y > 0 && y < num_info_info - 1 &&
689 info_info[y].type & TYPE_SKIP_ENTRY)
693 if (IN_VIS_FIELD(x, y) &&
694 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
700 drawCursor(y, FC_RED);
701 drawCursor(choice, FC_BLUE);
702 choice = choice_store[info_mode] = y;
705 else if (!(info_info[y].type & TYPE_GHOSTED))
707 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
709 void (*menu_callback_function)(void) = info_info[choice].value;
711 menu_callback_function();
717 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
719 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
720 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
721 int xstart = mSX + 16;
722 int ystart = mSY + 64 + 2 * 32;
723 int ystep = TILEY + 4;
724 int element, action, direction;
732 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
733 infoscreen_step[i] = infoscreen_frame[i] = 0;
738 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
740 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
741 "Press any key or button for next page");
747 while (helpanim_info[j].element != HELPANIM_LIST_END)
749 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
754 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
763 j += infoscreen_step[i - start];
765 element = helpanim_info[j].element;
766 action = helpanim_info[j].action;
767 direction = helpanim_info[j].direction;
769 if (action != -1 && direction != -1)
770 graphic = el_act_dir2img(element, action, direction);
771 else if (action != -1)
772 graphic = el_act2img(element, action);
773 else if (direction != -1)
774 graphic = el_act2img(element, direction);
776 graphic = el2img(element);
778 delay = helpanim_info[j++].delay;
783 if (infoscreen_frame[i - start] == 0)
786 infoscreen_frame[i - start] = delay - 1;
790 sync_frame = delay - infoscreen_frame[i - start];
791 infoscreen_frame[i - start]--;
794 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
796 if (!infoscreen_frame[i - start])
797 infoscreen_step[i - start] = 0;
801 if (!infoscreen_frame[i - start])
802 infoscreen_step[i - start]++;
803 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
809 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
811 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
812 graphic, sync_frame, USE_MASKING);
815 DrawInfoScreen_HelpText(element, action, direction, i - start);
820 redraw_mask |= REDRAW_FIELD;
825 static char *getHelpText(int element, int action, int direction)
827 char token[MAX_LINE_LEN];
829 strcpy(token, element_info[element].token_name);
832 strcat(token, element_action_info[action].suffix);
835 strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
837 return getHashEntry(helptext_info, token);
840 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
842 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()
876 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
881 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
887 void HandleInfoScreen_Elements(int button)
889 static unsigned long info_delay = 0;
890 static int num_anims;
891 static int num_pages;
893 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
894 int button_released = !button;
897 if (button == MB_MENU_INITIALIZE)
899 boolean new_element = TRUE;
902 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
904 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
906 else if (new_element)
913 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
916 else if (button == MB_MENU_LEAVE)
918 info_mode = INFO_MODE_MAIN;
924 if (button_released || button == MB_MENU_INITIALIZE)
926 if (button != MB_MENU_INITIALIZE)
929 if (page >= num_pages)
931 FadeSoundsAndMusic();
933 info_mode = INFO_MODE_MAIN;
939 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
943 if (DelayReached(&info_delay, GAME_FRAME_DELAY))
944 if (page < num_pages)
945 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
947 PlayMenuSoundIfLoop();
951 void DrawInfoScreen_Music()
953 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
960 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
963 void HandleInfoScreen_Music(int button)
965 static struct MusicFileInfo *list = NULL;
966 int ystart = 150, dy = 30;
967 int ybottom = SYSIZE - 20;
968 int button_released = !button;
970 if (button == MB_MENU_INITIALIZE)
972 list = music_file_info;
976 FadeSoundsAndMusic();
981 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
983 DrawTextSCentered(ybottom, FONT_TEXT_4,
984 "Press any key or button for info menu");
989 else if (button == MB_MENU_LEAVE)
991 info_mode = INFO_MODE_MAIN;
997 if (button_released || button == MB_MENU_INITIALIZE)
1001 if (button != MB_MENU_INITIALIZE)
1007 info_mode = INFO_MODE_MAIN;
1013 FadeSoundsAndMusic();
1020 int sound = list->music;
1022 if (sound_info[sound].loop)
1023 PlaySoundLoop(sound);
1027 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1031 PlayMusic(list->music);
1033 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1036 if (strcmp(list->title, UNKNOWN_NAME) != 0)
1038 if (strcmp(list->title_header, UNKNOWN_NAME) != 0)
1039 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1041 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1044 if (strcmp(list->artist, UNKNOWN_NAME) != 0)
1046 if (strcmp(list->artist_header, UNKNOWN_NAME) != 0)
1047 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1049 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1051 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1054 if (strcmp(list->album, UNKNOWN_NAME) != 0)
1056 if (strcmp(list->album_header, UNKNOWN_NAME) != 0)
1057 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1059 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1061 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1064 if (strcmp(list->year, UNKNOWN_NAME) != 0)
1066 if (strcmp(list->year_header, UNKNOWN_NAME) != 0)
1067 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1069 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1071 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1074 DrawTextSCentered(ybottom, FONT_TEXT_4,
1075 "Press any key or button for next page");
1078 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1079 PlaySoundLoop(list->music);
1082 void DrawInfoScreen_Credits()
1084 int ystart = 150, ystep = 30;
1085 int ybottom = SYSIZE - 20;
1087 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1089 FadeSoundsAndMusic();
1094 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1095 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1096 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1097 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1098 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1099 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1100 "...and many thanks to all contributors");
1101 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1103 DrawTextSCentered(ybottom, FONT_TEXT_4,
1104 "Press any key or button for info menu");
1107 void HandleInfoScreen_Credits(int button)
1109 int button_released = !button;
1111 if (button == MB_MENU_LEAVE)
1113 info_mode = INFO_MODE_MAIN;
1119 if (button_released)
1121 FadeSoundsAndMusic();
1123 info_mode = INFO_MODE_MAIN;
1128 PlayMenuSoundIfLoop();
1132 void DrawInfoScreen_Program()
1134 int ystart = 150, ystep = 30;
1135 int ybottom = SYSIZE - 20;
1137 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1142 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1144 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1145 "This game is Freeware!");
1146 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1147 "If you like it, send e-mail to:");
1148 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1149 "info@artsoft.org");
1150 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1151 "or SnailMail to:");
1152 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1154 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1155 "Detmolder Strasse 189");
1156 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1158 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1161 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1162 "If you have created new levels,");
1163 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1164 "send them to me to include them!");
1165 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1168 DrawTextSCentered(ybottom, FONT_TEXT_4,
1169 "Press any key or button for info menu");
1172 void HandleInfoScreen_Program(int button)
1174 int button_released = !button;
1176 if (button == MB_MENU_LEAVE)
1178 info_mode = INFO_MODE_MAIN;
1184 if (button_released)
1186 FadeSoundsAndMusic();
1188 info_mode = INFO_MODE_MAIN;
1193 PlayMenuSoundIfLoop();
1197 void DrawInfoScreen_LevelSet()
1200 int ybottom = SYSIZE - 20;
1201 char *filename = getLevelSetInfoFilename();
1202 int font_nr = FONT_LEVEL_NUMBER;
1203 int font_width = getFontWidth(font_nr);
1204 int font_height = getFontHeight(font_nr);
1207 int sx = SX + pad_x;
1208 int sy = SY + pad_y;
1209 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1210 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1212 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1217 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1219 DrawTextSCentered(ybottom, FONT_TEXT_4,
1220 "Press any key or button for info menu");
1222 if (filename != NULL)
1223 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1224 max_lines_per_screen);
1226 DrawTextSCentered(ystart, FONT_TEXT_2,
1227 "No information for this level set.");
1230 void HandleInfoScreen_LevelSet(int button)
1232 int button_released = !button;
1234 if (button == MB_MENU_LEAVE)
1236 info_mode = INFO_MODE_MAIN;
1242 if (button_released)
1244 FadeSoundsAndMusic();
1246 info_mode = INFO_MODE_MAIN;
1251 PlayMenuSoundIfLoop();
1255 void DrawInfoScreen()
1257 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1259 if (info_mode == INFO_MODE_ELEMENTS)
1260 DrawInfoScreen_Elements();
1261 else if (info_mode == INFO_MODE_MUSIC)
1262 DrawInfoScreen_Music();
1263 else if (info_mode == INFO_MODE_CREDITS)
1264 DrawInfoScreen_Credits();
1265 else if (info_mode == INFO_MODE_PROGRAM)
1266 DrawInfoScreen_Program();
1267 else if (info_mode == INFO_MODE_LEVELSET)
1268 DrawInfoScreen_LevelSet();
1270 DrawInfoScreen_Main();
1272 if (info_mode != INFO_MODE_MUSIC)
1279 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1281 if (info_mode == INFO_MODE_ELEMENTS)
1282 HandleInfoScreen_Elements(button);
1283 else if (info_mode == INFO_MODE_MUSIC)
1284 HandleInfoScreen_Music(button);
1285 else if (info_mode == INFO_MODE_CREDITS)
1286 HandleInfoScreen_Credits(button);
1287 else if (info_mode == INFO_MODE_PROGRAM)
1288 HandleInfoScreen_Program(button);
1289 else if (info_mode == INFO_MODE_LEVELSET)
1290 HandleInfoScreen_LevelSet(button);
1292 HandleInfoScreen_Main(mx, my, dx, dy, button);
1298 /* ========================================================================= */
1299 /* type name functions */
1300 /* ========================================================================= */
1302 void HandleTypeName(int newxpos, Key key)
1304 static int xpos = 0, ypos = 2;
1305 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1306 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1307 int startx = mSX + 32 + name_width;
1308 int starty = mSY + ypos * 32;
1314 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1315 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1320 if (((key >= KSYM_A && key <= KSYM_Z) ||
1321 (key >= KSYM_a && key <= KSYM_z)) &&
1322 xpos < MAX_PLAYER_NAME_LEN)
1326 if (key >= KSYM_A && key <= KSYM_Z)
1327 ascii = 'A' + (char)(key - KSYM_A);
1329 ascii = 'a' + (char)(key - KSYM_a);
1331 setup.player_name[xpos] = ascii;
1332 setup.player_name[xpos + 1] = 0;
1335 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1336 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1338 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1341 setup.player_name[xpos] = 0;
1343 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1345 else if (key == KSYM_Return && xpos > 0)
1347 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1348 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1351 game_status = GAME_MODE_MAIN;
1356 /* ========================================================================= */
1357 /* tree menu functions */
1358 /* ========================================================================= */
1360 static void DrawChooseTree(TreeInfo **ti_ptr)
1364 FreeScreenGadgets();
1365 CreateScreenGadgets();
1367 CloseDoor(DOOR_CLOSE_2);
1371 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1372 MapChooseTreeGadgets(*ti_ptr);
1378 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1380 struct GadgetInfo *gi = screen_gadget[id];
1381 int items_max, items_visible, item_position;
1383 items_max = numTreeInfoInGroup(ti);
1384 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1385 item_position = first_entry;
1387 if (item_position > items_max - items_visible)
1388 item_position = items_max - items_visible;
1390 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1391 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1392 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1395 static void drawChooseTreeList(int first_entry, int num_page_entries,
1399 char buffer[SCR_FIELDX * 2];
1400 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1401 char *title_string = NULL;
1402 int xoffset_setup = 16;
1403 int yoffset_setup = 16;
1404 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1405 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1406 int last_game_status = game_status; /* save current game status */
1409 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Directories" :
1410 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1411 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1412 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1414 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1416 /* force LEVELS font on artwork setup screen */
1417 game_status = GAME_MODE_LEVELS;
1419 /* clear tree list area, but not title or scrollbar */
1420 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1421 SXSIZE - 32 + menu.scrollbar_xoffset,
1422 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1424 for (i = 0; i < num_page_entries; i++)
1426 TreeInfo *node, *node_first;
1427 int entry_pos = first_entry + i;
1428 int ypos = MENU_SCREEN_START_YPOS + i;
1430 node_first = getTreeInfoFirstGroupEntry(ti);
1431 node = getTreeInfoFromPos(node_first, entry_pos);
1433 strncpy(buffer, node->name , max_buffer_len);
1434 buffer[max_buffer_len] = '\0';
1436 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1438 if (node->parent_link)
1439 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1440 else if (node->level_group)
1441 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1443 initCursor(i, IMG_MENU_BUTTON);
1446 game_status = last_game_status; /* restore current game status */
1448 redraw_mask |= REDRAW_FIELD;
1451 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1453 TreeInfo *node, *node_first;
1454 int x, last_redraw_mask = redraw_mask;
1456 if (ti->type != TREE_TYPE_LEVEL_DIR)
1459 node_first = getTreeInfoFirstGroupEntry(ti);
1460 node = getTreeInfoFromPos(node_first, entry_pos);
1462 DrawBackground(SX + 32, SY + 32, SXSIZE - 64, 32);
1464 if (node->parent_link)
1465 DrawTextFCentered(40, FONT_TITLE_2, "leave group \"%s\"",
1467 else if (node->level_group)
1468 DrawTextFCentered(40, FONT_TITLE_2, "enter group \"%s\"",
1470 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1471 DrawTextFCentered(40, FONT_TITLE_2, "%3d levels (%s)",
1472 node->levels, node->class_desc);
1474 /* let BackToFront() redraw only what is needed */
1475 redraw_mask = last_redraw_mask | REDRAW_TILES;
1476 for (x = 0; x < SCR_FIELDX; x++)
1477 MarkTileDirty(x, 1);
1480 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1483 TreeInfo *ti = *ti_ptr;
1485 int y = ti->cl_cursor;
1486 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1487 int num_entries = numTreeInfoInGroup(ti);
1488 int num_page_entries;
1489 int last_game_status = game_status; /* save current game status */
1490 boolean position_set_by_scrollbar = (dx == 999);
1492 /* force LEVELS draw offset on choose level and artwork setup screen */
1493 game_status = GAME_MODE_LEVELS;
1495 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1496 num_page_entries = num_entries;
1498 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1500 game_status = last_game_status; /* restore current game status */
1502 if (button == MB_MENU_INITIALIZE)
1504 int num_entries = numTreeInfoInGroup(ti);
1505 int entry_pos = posTreeInfo(ti);
1507 if (ti->cl_first == -1)
1509 /* only on initialization */
1510 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1511 ti->cl_cursor = entry_pos - ti->cl_first;
1513 else if (ti->cl_cursor >= num_page_entries ||
1514 (num_entries > num_page_entries &&
1515 num_entries - ti->cl_first < num_page_entries))
1517 /* only after change of list size (by custom graphic configuration) */
1518 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1519 ti->cl_cursor = entry_pos - ti->cl_first;
1522 if (position_set_by_scrollbar)
1525 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1528 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1529 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1530 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1534 else if (button == MB_MENU_LEAVE)
1536 if (ti->node_parent)
1538 *ti_ptr = ti->node_parent;
1539 DrawChooseTree(ti_ptr);
1541 else if (game_status == GAME_MODE_SETUP)
1547 game_status = GAME_MODE_MAIN;
1554 if (mx || my) /* mouse input */
1556 int last_game_status = game_status; /* save current game status */
1558 /* force LEVELS draw offset on artwork setup screen */
1559 game_status = GAME_MODE_LEVELS;
1561 x = (mx - mSX) / 32;
1562 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1564 game_status = last_game_status; /* restore current game status */
1566 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1568 /* move cursor instead of scrolling when already at start/end of list */
1569 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1571 else if (dy == +1 * SCROLL_LINE &&
1572 ti->cl_first + num_page_entries == num_entries)
1575 /* handle scrolling screen one line or page */
1576 if (ti->cl_cursor + dy < 0 ||
1577 ti->cl_cursor + dy > num_page_entries - 1)
1579 if (ABS(dy) == SCROLL_PAGE)
1580 step = num_page_entries - 1;
1582 if (dy < 0 && ti->cl_first > 0)
1584 /* scroll page/line up */
1586 ti->cl_first -= step;
1587 if (ti->cl_first < 0)
1590 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1591 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1592 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1593 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1596 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1598 /* scroll page/line down */
1600 ti->cl_first += step;
1601 if (ti->cl_first + num_page_entries > num_entries)
1602 ti->cl_first = MAX(0, num_entries - num_page_entries);
1604 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1605 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1606 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1607 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1614 /* handle moving cursor one line */
1615 y = ti->cl_cursor + dy;
1620 TreeInfo *node_first, *node_cursor;
1621 int entry_pos = ti->cl_first + y;
1623 node_first = getTreeInfoFirstGroupEntry(ti);
1624 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1626 if (node_cursor->node_group)
1628 node_cursor->cl_first = ti->cl_first;
1629 node_cursor->cl_cursor = ti->cl_cursor;
1630 *ti_ptr = node_cursor->node_group;
1631 DrawChooseTree(ti_ptr);
1636 else if (dx == -1 && ti->node_parent)
1638 *ti_ptr = ti->node_parent;
1639 DrawChooseTree(ti_ptr);
1644 if (!anyScrollbarGadgetActive() &&
1645 IN_VIS_FIELD(x, y) &&
1646 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1647 y >= 0 && y < num_page_entries)
1651 if (y != ti->cl_cursor)
1653 drawChooseTreeCursor(y, FC_RED);
1654 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1655 drawChooseTreeInfo(ti->cl_first + y, ti);
1661 TreeInfo *node_first, *node_cursor;
1662 int entry_pos = ti->cl_first + y;
1664 node_first = getTreeInfoFirstGroupEntry(ti);
1665 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1667 if (node_cursor->node_group)
1669 node_cursor->cl_first = ti->cl_first;
1670 node_cursor->cl_cursor = ti->cl_cursor;
1671 *ti_ptr = node_cursor->node_group;
1672 DrawChooseTree(ti_ptr);
1674 else if (node_cursor->parent_link)
1676 *ti_ptr = node_cursor->node_parent;
1677 DrawChooseTree(ti_ptr);
1681 node_cursor->cl_first = ti->cl_first;
1682 node_cursor->cl_cursor = ti->cl_cursor;
1683 *ti_ptr = node_cursor;
1685 if (ti->type == TREE_TYPE_LEVEL_DIR)
1687 LoadLevelSetup_SeriesInfo();
1689 SaveLevelSetup_LastSeries();
1690 SaveLevelSetup_SeriesInfo();
1694 if (game_status == GAME_MODE_SETUP)
1700 game_status = GAME_MODE_MAIN;
1708 void DrawChooseLevel()
1710 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1712 DrawChooseTree(&leveldir_current);
1718 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1720 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1725 void DrawHallOfFame(int highlight_position)
1728 FadeSoundsAndMusic();
1729 CloseDoor(DOOR_CLOSE_2);
1731 if (highlight_position < 0)
1732 LoadScore(level_nr);
1740 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1743 static void drawHallOfFameList(int first_entry, int highlight_position)
1747 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1750 DrawText(mSX + 80, mSY + 8, "Hall Of Fame", FONT_TITLE_1);
1751 DrawTextFCentered(46, FONT_TITLE_2, "HighScores of Level %d", level_nr);
1753 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1755 int entry = first_entry + i;
1756 boolean active = (entry == highlight_position);
1757 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1758 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1759 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1760 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1761 int dx1 = 3 * getFontWidth(font_nr1);
1762 int dx2 = dx1 + getFontWidth(font_nr1);
1763 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1764 int sy = mSY + 64 + i * 32;
1766 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1767 DrawText(mSX + dx1, sy, ".", font_nr1);
1768 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1769 if (strcmp(highscore[entry].Name, EMPTY_PLAYER_NAME) != 0)
1770 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1771 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1774 redraw_mask |= REDRAW_FIELD;
1777 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1779 static int first_entry = 0;
1780 static int highlight_position = 0;
1781 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1782 int button_released = !button;
1784 if (button == MB_MENU_INITIALIZE)
1787 highlight_position = mx;
1788 drawHallOfFameList(first_entry, highlight_position);
1793 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1794 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1798 if (first_entry > 0)
1800 first_entry -= step;
1801 if (first_entry < 0)
1804 drawHallOfFameList(first_entry, highlight_position);
1809 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1811 first_entry += step;
1812 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1813 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1815 drawHallOfFameList(first_entry, highlight_position);
1818 else if (button_released)
1820 FadeSound(SND_BACKGROUND_SCORES);
1821 game_status = GAME_MODE_MAIN;
1825 if (game_status == GAME_MODE_SCORES)
1826 PlayMenuSoundIfLoop();
1832 /* ========================================================================= */
1833 /* setup screen functions */
1834 /* ========================================================================= */
1836 static struct TokenInfo *setup_info;
1837 static int num_setup_info;
1839 static char *graphics_set_name;
1840 static char *sounds_set_name;
1841 static char *music_set_name;
1843 static void execSetupMain()
1845 setup_mode = SETUP_MODE_MAIN;
1849 static void execSetupGame()
1851 setup_mode = SETUP_MODE_GAME;
1855 static void execSetupEditor()
1857 setup_mode = SETUP_MODE_EDITOR;
1861 static void execSetupGraphics()
1863 setup_mode = SETUP_MODE_GRAPHICS;
1867 static void execSetupSound()
1869 setup_mode = SETUP_MODE_SOUND;
1873 static void execSetupArtwork()
1875 setup.graphics_set = artwork.gfx_current->identifier;
1876 setup.sounds_set = artwork.snd_current->identifier;
1877 setup.music_set = artwork.mus_current->identifier;
1879 /* needed if last screen (setup choice) changed graphics, sounds or music */
1880 ReloadCustomArtwork(0);
1882 /* needed for displaying artwork name instead of artwork identifier */
1883 graphics_set_name = artwork.gfx_current->name;
1884 sounds_set_name = artwork.snd_current->name;
1885 music_set_name = artwork.mus_current->name;
1887 setup_mode = SETUP_MODE_ARTWORK;
1891 static void execSetupChooseGraphics()
1893 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
1897 static void execSetupChooseSounds()
1899 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
1903 static void execSetupChooseMusic()
1905 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
1909 static void execSetupInput()
1911 setup_mode = SETUP_MODE_INPUT;
1915 static void execSetupShortcut()
1917 setup_mode = SETUP_MODE_SHORTCUT;
1921 static void execExitSetup()
1923 game_status = GAME_MODE_MAIN;
1927 static void execSaveAndExitSetup()
1933 static struct TokenInfo setup_info_main[] =
1935 { TYPE_ENTER_MENU, execSetupGame, "Game Settings" },
1936 { TYPE_ENTER_MENU, execSetupEditor, "Editor Settings" },
1937 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
1938 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
1939 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
1940 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
1941 { TYPE_ENTER_MENU, execSetupShortcut, "Key Shortcuts" },
1942 { TYPE_EMPTY, NULL, "" },
1943 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
1944 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
1949 static struct TokenInfo setup_info_game[] =
1951 { TYPE_SWITCH, &setup.team_mode, "Team-Mode:" },
1952 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
1953 { TYPE_SWITCH, &setup.skip_levels, "Skip Levels:" },
1954 { TYPE_SWITCH, &setup.time_limit, "Timelimit:" },
1955 { TYPE_SWITCH, &setup.autorecord, "Auto-Record:" },
1956 { TYPE_EMPTY, NULL, "" },
1957 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1962 static struct TokenInfo setup_info_editor[] =
1965 { TYPE_STRING, NULL, "Offer Special Elements:"},
1967 { TYPE_SWITCH, &setup.editor.el_boulderdash, "BoulderDash:" },
1968 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
1969 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,"E.M. Club:" },
1970 { TYPE_SWITCH, &setup.editor.el_more, "More:" },
1971 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
1972 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
1973 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamd. Caves:" },
1974 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX Boulderd.:" },
1975 { TYPE_SWITCH, &setup.editor.el_chars, "Characters:" },
1976 { TYPE_SWITCH, &setup.editor.el_custom, "Custom:" },
1977 { TYPE_SWITCH, &setup.editor.el_custom_more, "More Custom:" },
1978 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
1979 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined:" },
1980 { TYPE_EMPTY, NULL, "" },
1981 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
1986 static struct TokenInfo setup_info_graphics[] =
1988 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
1989 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
1990 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scroll.:" },
1992 { TYPE_SWITCH, &setup.double_buffering,"Buffered gfx:" },
1993 { TYPE_SWITCH, &setup.fading, "Fading:" },
1995 { TYPE_SWITCH, &setup.quick_doors, "Quick Doors:" },
1996 { TYPE_SWITCH, &setup.toons, "Toons:" },
1997 { TYPE_EMPTY, NULL, "" },
1998 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2003 static struct TokenInfo setup_info_sound[] =
2005 { TYPE_SWITCH, &setup.sound_simple, "Simple Sound:" },
2006 { TYPE_SWITCH, &setup.sound_loops, "Sound Loops:" },
2007 { TYPE_SWITCH, &setup.sound_music, "Game Music:" },
2008 { TYPE_EMPTY, NULL, "" },
2009 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2014 static struct TokenInfo setup_info_artwork[] =
2016 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2017 { TYPE_STRING, &graphics_set_name, "" },
2018 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2019 { TYPE_STRING, &sounds_set_name, "" },
2020 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2021 { TYPE_STRING, &music_set_name, "" },
2022 { TYPE_EMPTY, NULL, "" },
2023 { TYPE_STRING, NULL, "Override Level Artwork:"},
2024 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2025 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2026 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2027 { TYPE_EMPTY, NULL, "" },
2028 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2033 static struct TokenInfo setup_info_shortcut[] =
2035 { TYPE_KEYTEXT, NULL, "Quick Save Game:", },
2036 { TYPE_KEY, &setup.shortcut.save_game, "" },
2037 { TYPE_KEYTEXT, NULL, "Quick Load Game:", },
2038 { TYPE_KEY, &setup.shortcut.load_game, "" },
2039 { TYPE_KEYTEXT, NULL, "Toggle Pause:", },
2040 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2041 { TYPE_EMPTY, NULL, "" },
2042 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on Esc:" },
2043 { TYPE_EMPTY, NULL, "" },
2044 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2049 static Key getSetupKey()
2051 Key key = KSYM_UNDEFINED;
2052 boolean got_key_event = FALSE;
2054 while (!got_key_event)
2056 if (PendingEvent()) /* got event */
2064 case EVENT_KEYPRESS:
2066 key = GetEventKey((KeyEvent *)&event, TRUE);
2068 /* press 'Escape' or 'Enter' to keep the existing key binding */
2069 if (key == KSYM_Escape || key == KSYM_Return)
2070 key = KSYM_UNDEFINED; /* keep old value */
2072 got_key_event = TRUE;
2076 case EVENT_KEYRELEASE:
2077 key_joystick_mapping = 0;
2081 HandleOtherEvents(&event);
2089 /* don't eat all CPU time */
2096 static void drawSetupValue(int pos)
2098 int xpos = MENU_SCREEN_VALUE_XPOS;
2099 int ypos = MENU_SCREEN_START_YPOS + pos;
2100 int font_nr = FONT_VALUE_1;
2101 int type = setup_info[pos].type;
2102 void *value = setup_info[pos].value;
2103 char *value_string = (!(type & TYPE_GHOSTED) ? getSetupValue(type, value) :
2106 if (value_string == NULL)
2109 if (type & TYPE_KEY)
2113 if (type & TYPE_QUERY)
2115 value_string = "<press key>";
2116 font_nr = FONT_INPUT_1_ACTIVE;
2119 else if (type & TYPE_STRING)
2121 int max_value_len = (SCR_FIELDX - 2) * 2;
2124 font_nr = FONT_VALUE_2;
2126 if (strlen(value_string) > max_value_len)
2127 value_string[max_value_len] = '\0';
2129 else if (type & TYPE_BOOLEAN_STYLE)
2131 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2134 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2135 (xpos == 3 ? " " : " "), font_nr);
2136 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2139 static void changeSetupValue(int pos)
2141 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2143 *(boolean *)setup_info[pos].value ^= TRUE;
2145 else if (setup_info[pos].type & TYPE_KEY)
2149 setup_info[pos].type |= TYPE_QUERY;
2150 drawSetupValue(pos);
2151 setup_info[pos].type &= ~TYPE_QUERY;
2153 key = getSetupKey();
2154 if (key != KSYM_UNDEFINED)
2155 *(Key *)setup_info[pos].value = key;
2158 drawSetupValue(pos);
2161 static void DrawSetupScreen_Generic()
2163 char *title_string = NULL;
2167 CloseDoor(DOOR_CLOSE_2);
2171 if (setup_mode == SETUP_MODE_MAIN)
2173 setup_info = setup_info_main;
2174 title_string = "Setup";
2176 else if (setup_mode == SETUP_MODE_GAME)
2178 setup_info = setup_info_game;
2179 title_string = "Setup Game";
2181 else if (setup_mode == SETUP_MODE_EDITOR)
2183 setup_info = setup_info_editor;
2184 title_string = "Setup Editor";
2186 else if (setup_mode == SETUP_MODE_GRAPHICS)
2188 setup_info = setup_info_graphics;
2189 title_string = "Setup Graphics";
2191 else if (setup_mode == SETUP_MODE_SOUND)
2193 setup_info = setup_info_sound;
2194 title_string = "Setup Sound";
2196 else if (setup_mode == SETUP_MODE_ARTWORK)
2198 setup_info = setup_info_artwork;
2199 title_string = "Custom Artwork";
2201 else if (setup_mode == SETUP_MODE_SHORTCUT)
2203 setup_info = setup_info_shortcut;
2204 title_string = "Setup Shortcuts";
2207 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2210 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2212 void *value_ptr = setup_info[i].value;
2213 int ypos = MENU_SCREEN_START_YPOS + i;
2214 int font_nr = FONT_MENU_1;
2216 /* set some entries to "unchangeable" according to other variables */
2217 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2218 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2219 (value_ptr == &setup.sound_music && !audio.music_available) ||
2220 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2221 setup_info[i].type |= TYPE_GHOSTED;
2223 if (setup_info[i].type & TYPE_STRING)
2224 font_nr = FONT_MENU_2;
2226 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2228 if (setup_info[i].type & TYPE_ENTER_MENU)
2229 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2230 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2231 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2232 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2233 initCursor(i, IMG_MENU_BUTTON);
2235 if (setup_info[i].type & TYPE_VALUE)
2243 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2246 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2248 static int choice_store[MAX_SETUP_MODES];
2249 int choice = choice_store[setup_mode]; /* always starts with 0 */
2253 if (button == MB_MENU_INITIALIZE)
2255 /* advance to first valid menu entry */
2256 while (choice < num_setup_info &&
2257 setup_info[choice].type & TYPE_SKIP_ENTRY)
2259 choice_store[setup_mode] = choice;
2261 drawCursor(choice, FC_RED);
2264 else if (button == MB_MENU_LEAVE)
2266 for (y = 0; y < num_setup_info; y++)
2268 if (setup_info[y].type & TYPE_LEAVE_MENU)
2270 void (*menu_callback_function)(void) = setup_info[y].value;
2272 menu_callback_function();
2273 break; /* absolutely needed because function changes 'setup_info'! */
2280 if (mx || my) /* mouse input */
2282 x = (mx - mSX) / 32;
2283 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2285 else if (dx || dy) /* keyboard input */
2289 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2291 if (setup_info[choice].type & menu_navigation_type ||
2292 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2293 button = MB_MENU_CHOICE;
2298 /* jump to next non-empty menu entry (up or down) */
2299 while (y > 0 && y < num_setup_info - 1 &&
2300 setup_info[y].type & TYPE_SKIP_ENTRY)
2304 if (IN_VIS_FIELD(x, y) &&
2305 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2311 drawCursor(y, FC_RED);
2312 drawCursor(choice, FC_BLUE);
2313 choice = choice_store[setup_mode] = y;
2316 else if (!(setup_info[y].type & TYPE_GHOSTED))
2318 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2320 void (*menu_callback_function)(void) = setup_info[choice].value;
2322 menu_callback_function();
2326 if (setup_info[y].type & TYPE_KEYTEXT &&
2327 setup_info[y + 1].type & TYPE_KEY)
2330 if (setup_info[y].type & TYPE_VALUE)
2331 changeSetupValue(y);
2337 void DrawSetupScreen_Input()
2341 DrawText(mSX+16, mSY+16, "Setup Input", FONT_TITLE_1);
2343 initCursor(0, IMG_MENU_BUTTON);
2344 initCursor(1, IMG_MENU_BUTTON);
2345 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2346 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2348 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2349 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2351 DrawText(mSX+32, mSY+2*32, "Player:", FONT_MENU_1);
2352 DrawText(mSX+32, mSY+3*32, "Device:", FONT_MENU_1);
2353 DrawText(mSX+32, mSY+15*32, "Back", FONT_MENU_1);
2356 DeactivateJoystickForCalibration();
2357 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2358 "Joysticks deactivated on this screen");
2361 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2366 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2368 if (device_name == NULL)
2371 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2374 if (strlen(device_name) > 1)
2376 char c1 = device_name[strlen(device_name) - 1];
2377 char c2 = device_name[strlen(device_name) - 2];
2379 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2380 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2383 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2384 strlen(device_name));
2387 static void drawPlayerSetupInputInfo(int player_nr)
2390 static struct SetupKeyboardInfo custom_key;
2397 { &custom_key.left, "Joystick Left" },
2398 { &custom_key.right, "Joystick Right" },
2399 { &custom_key.up, "Joystick Up" },
2400 { &custom_key.down, "Joystick Down" },
2401 { &custom_key.snap, "Button 1" },
2402 { &custom_key.drop, "Button 2" }
2404 static char *joystick_name[MAX_PLAYERS] =
2412 custom_key = setup.input[player_nr].key;
2414 DrawText(mSX+11*32, mSY+2*32, int2str(player_nr +1, 1), FONT_INPUT_1_ACTIVE);
2416 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2418 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2419 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 (!level.use_step_counter)
3037 if (TimeLeft <= 10 && setup.time_limit)
3038 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
3040 DrawGameValue_Time(TimeLeft);
3042 if (!TimeLeft && setup.time_limit)
3043 level.native_em_level->lev->killed_out_of_time = TRUE;
3045 else if (level.time == 0 && level.native_em_level->lev->home > 0)
3046 DrawGameValue_Time(TimePlayed);
3048 level.native_em_level->lev->time =
3049 (level.time == 0 ? TimePlayed : TimeLeft);
3052 if (tape.recording || tape.playing)
3053 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
3063 if (game.restart_level)
3064 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
3066 if (local_player->LevelSolved)
3069 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
3075 if (tape.auto_play && !tape.playing)
3076 AutoPlayTape(); /* continue automatically playing next tape */
3080 void StartGameActions(boolean init_network_game, boolean record_tape,
3084 TapeStartRecording(random_seed);
3086 #if defined(NETWORK_AVALIABLE)
3087 if (init_network_game)
3089 SendToServer_StartPlaying();
3097 game_status = GAME_MODE_PLAYING;
3099 InitRND(random_seed);
3104 /* ---------- new screen button stuff -------------------------------------- */
3106 /* graphic position and size values for buttons and scrollbars */
3107 #define SC_SCROLLBUTTON_XSIZE TILEX
3108 #define SC_SCROLLBUTTON_YSIZE TILEY
3110 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3111 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3112 SC_SCROLLBUTTON_YSIZE)
3113 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3114 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3115 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3116 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3117 SC_SCROLLBUTTON_YSIZE)
3118 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3119 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3120 SC_SCROLL_VERTICAL_YSIZE)
3122 #define SC_BORDER_SIZE 14
3126 int gfx_unpressed, gfx_pressed;
3130 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3133 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3134 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3135 SCREEN_CTRL_ID_SCROLL_UP,
3139 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3140 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3141 SCREEN_CTRL_ID_SCROLL_DOWN,
3148 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3149 Bitmap **gfx_unpressed, **gfx_pressed;
3151 int gfx_unpressed, gfx_pressed;
3158 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3161 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3162 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3164 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3166 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3167 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3168 GD_TYPE_SCROLLBAR_VERTICAL,
3169 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3170 "scroll level series vertically"
3174 static void CreateScreenScrollbuttons()
3176 struct GadgetInfo *gi;
3177 unsigned long event_mask;
3180 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3182 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3183 int gfx_unpressed, gfx_pressed;
3184 int x, y, width, height;
3185 int gd_x1, gd_x2, gd_y1, gd_y2;
3186 int id = scrollbutton_info[i].gadget_id;
3188 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3190 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3191 y = mSY + scrollbutton_info[i].y;
3192 width = SC_SCROLLBUTTON_XSIZE;
3193 height = SC_SCROLLBUTTON_YSIZE;
3195 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3196 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3197 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3199 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3200 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3201 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3202 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3203 gd_x1 = graphic_info[gfx_unpressed].src_x;
3204 gd_y1 = graphic_info[gfx_unpressed].src_y;
3205 gd_x2 = graphic_info[gfx_pressed].src_x;
3206 gd_y2 = graphic_info[gfx_pressed].src_y;
3208 gi = CreateGadget(GDI_CUSTOM_ID, id,
3209 GDI_CUSTOM_TYPE_ID, i,
3210 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3215 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3216 GDI_STATE, GD_BUTTON_UNPRESSED,
3217 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3218 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3219 GDI_DIRECT_DRAW, FALSE,
3220 GDI_EVENT_MASK, event_mask,
3221 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3225 Error(ERR_EXIT, "cannot create gadget");
3227 screen_gadget[id] = gi;
3231 static void CreateScreenScrollbars()
3235 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3237 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3238 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3239 int gfx_unpressed, gfx_pressed;
3241 int x, y, width, height;
3242 int gd_x1, gd_x2, gd_y1, gd_y2;
3243 struct GadgetInfo *gi;
3244 int items_max, items_visible, item_position;
3245 unsigned long event_mask;
3246 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3247 int id = scrollbar_info[i].gadget_id;
3249 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3251 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3252 y = mSY + scrollbar_info[i].y;
3253 width = scrollbar_info[i].width;
3254 height = scrollbar_info[i].height;
3256 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3257 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3259 items_max = num_page_entries;
3260 items_visible = num_page_entries;
3263 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3264 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3265 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3271 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3272 gfx_pressed = scrollbar_info[i].gfx_pressed;
3273 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3274 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3275 gd_x1 = graphic_info[gfx_unpressed].src_x;
3276 gd_y1 = graphic_info[gfx_unpressed].src_y;
3277 gd_x2 = graphic_info[gfx_pressed].src_x;
3278 gd_y2 = graphic_info[gfx_pressed].src_y;
3281 gi = CreateGadget(GDI_CUSTOM_ID, id,
3282 GDI_CUSTOM_TYPE_ID, i,
3283 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3288 GDI_TYPE, scrollbar_info[i].type,
3289 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3290 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3291 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3292 GDI_STATE, GD_BUTTON_UNPRESSED,
3293 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3294 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3295 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3296 GDI_DIRECT_DRAW, FALSE,
3297 GDI_EVENT_MASK, event_mask,
3298 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3302 Error(ERR_EXIT, "cannot create gadget");
3304 screen_gadget[id] = gi;
3308 void CreateScreenGadgets()
3310 int last_game_status = game_status; /* save current game status */
3312 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3315 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3317 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3319 /* copy pointers to clip mask and GC */
3320 scrollbar_bitmap[i]->clip_mask =
3321 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3322 scrollbar_bitmap[i]->stored_clip_gc =
3323 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3325 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3326 scrollbar_bitmap[i],
3327 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3328 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3329 TILEX, TILEY, 0, 0);
3333 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3334 game_status = GAME_MODE_LEVELS;
3336 CreateScreenScrollbuttons();
3337 CreateScreenScrollbars();
3339 game_status = last_game_status; /* restore current game status */
3342 void FreeScreenGadgets()
3346 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3347 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3349 /* prevent freeing clip mask and GC twice */
3350 scrollbar_bitmap[i]->clip_mask = None;
3351 scrollbar_bitmap[i]->stored_clip_gc = None;
3353 FreeBitmap(scrollbar_bitmap[i]);
3357 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3358 FreeGadget(screen_gadget[i]);
3361 void MapChooseTreeGadgets(TreeInfo *ti)
3363 int num_entries = numTreeInfoInGroup(ti);
3366 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3369 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3370 MapGadget(screen_gadget[i]);
3374 void UnmapChooseTreeGadgets()
3378 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3379 UnmapGadget(screen_gadget[i]);
3383 static void HandleScreenGadgets(struct GadgetInfo *gi)
3385 int id = gi->custom_id;
3387 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3392 case SCREEN_CTRL_ID_SCROLL_UP:
3393 if (game_status == GAME_MODE_LEVELS)
3394 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3395 else if (game_status == GAME_MODE_SETUP)
3396 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3399 case SCREEN_CTRL_ID_SCROLL_DOWN:
3400 if (game_status == GAME_MODE_LEVELS)
3401 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3402 else if (game_status == GAME_MODE_SETUP)
3403 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3406 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3407 if (game_status == GAME_MODE_LEVELS)
3408 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3409 else if (game_status == GAME_MODE_SETUP)
3410 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);