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_1 4
33 #define SETUP_MODE_SHORTCUT_2 5
34 #define SETUP_MODE_GRAPHICS 6
35 #define SETUP_MODE_SOUND 7
36 #define SETUP_MODE_ARTWORK 8
37 #define SETUP_MODE_CHOOSE_GRAPHICS 9
38 #define SETUP_MODE_CHOOSE_SOUNDS 10
39 #define SETUP_MODE_CHOOSE_MUSIC 11
41 #define MAX_SETUP_MODES 12
43 /* for input setup functions */
44 #define SETUPINPUT_SCREEN_POS_START 0
45 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
46 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
47 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
49 /* screens on the info screen */
50 #define INFO_MODE_MAIN 0
51 #define INFO_MODE_ELEMENTS 1
52 #define INFO_MODE_MUSIC 2
53 #define INFO_MODE_CREDITS 3
54 #define INFO_MODE_PROGRAM 4
55 #define INFO_MODE_LEVELSET 5
57 #define MAX_INFO_MODES 6
59 /* for various menu stuff */
60 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
61 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - 2)
62 #define MENU_SCREEN_START_YPOS 2
63 #define MENU_SCREEN_VALUE_XPOS 14
64 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
65 #define MENU_TITLE1_YPOS 8
66 #define MENU_TITLE2_YPOS 46
68 /* buttons and scrollbars identifiers */
69 #define SCREEN_CTRL_ID_SCROLL_UP 0
70 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
71 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
73 #define NUM_SCREEN_SCROLLBUTTONS 2
74 #define NUM_SCREEN_SCROLLBARS 1
75 #define NUM_SCREEN_GADGETS 3
77 /* forward declarations of internal functions */
78 static void HandleScreenGadgets(struct GadgetInfo *);
79 static void HandleSetupScreen_Generic(int, int, int, int, int);
80 static void HandleSetupScreen_Input(int, int, int, int, int);
81 static void CustomizeKeyboard(int);
82 static void CalibrateJoystick(int);
83 static void execSetupArtwork(void);
84 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
86 static void DrawChooseLevel(void);
87 static void DrawInfoScreen(void);
88 static void DrawSetupScreen(void);
90 static void DrawInfoScreen_HelpAnim(int, int, boolean);
91 static void DrawInfoScreen_HelpText(int, int, int, int);
92 static void HandleInfoScreen_Main(int, int, int, int, int);
93 static void HandleInfoScreen_Elements(int);
94 static void HandleInfoScreen_Music(int);
95 static void HandleInfoScreen_Credits(int);
96 static void HandleInfoScreen_Program(int);
98 static void MapChooseTreeGadgets(TreeInfo *);
100 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
101 static int setup_mode = SETUP_MODE_MAIN;
102 static int info_mode = INFO_MODE_MAIN;
104 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
105 x <= GAME_MODE_SETUP ? x : \
106 x == GAME_MODE_PSEUDO_TYPENAME ? \
107 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
109 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
110 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
112 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
113 menu.list_size[game_status] : \
114 MAX_MENU_ENTRIES_ON_SCREEN)
116 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
117 #define NUM_SCROLLBAR_BITMAPS 2
118 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
122 static void drawCursorExt(int xpos, int ypos, int color, int g)
124 static int cursor_array[SCR_FIELDY];
129 cursor_array[ypos] = g;
131 g = cursor_array[ypos];
135 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
136 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
137 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
138 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
139 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
140 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
141 IMG_MENU_BUTTON_ACTIVE);
143 ypos += MENU_SCREEN_START_YPOS;
145 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
146 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
149 static void initCursor(int ypos, int graphic)
151 drawCursorExt(0, ypos, FC_BLUE, graphic);
154 static void drawCursor(int ypos, int color)
156 drawCursorExt(0, ypos, color, 0);
159 static void drawCursorXY(int xpos, int ypos, int graphic)
161 drawCursorExt(xpos, ypos, -1, graphic);
164 static void drawChooseTreeCursor(int ypos, int color)
166 int last_game_status = game_status; /* save current game status */
168 /* force LEVELS draw offset on artwork setup screen */
169 game_status = GAME_MODE_LEVELS;
171 drawCursorExt(0, ypos, color, 0);
173 game_status = last_game_status; /* restore current game status */
176 static void PlayMenuSound()
178 int sound = menu.sound[game_status];
180 if (sound == SND_UNDEFINED)
183 if (sound_info[sound].loop)
184 PlaySoundLoop(sound);
189 static void PlayMenuSoundIfLoop()
191 int sound = menu.sound[game_status];
193 if (sound == SND_UNDEFINED)
196 if (sound_info[sound].loop)
197 PlaySoundLoop(sound);
200 static void PlayMenuMusic()
202 int music = menu.music[game_status];
204 if (music == MUS_UNDEFINED)
212 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
213 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
216 static void ToggleFullscreenIfNeeded()
218 if (setup.fullscreen != video.fullscreen_enabled)
220 /* save old door content */
221 BlitBitmap(backbuffer, bitmap_db_door,
222 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
224 /* toggle fullscreen */
225 ChangeVideoModeIfNeeded(setup.fullscreen);
226 setup.fullscreen = video.fullscreen_enabled;
228 /* redraw background to newly created backbuffer */
229 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
230 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
232 /* restore old door content */
233 BlitBitmap(bitmap_db_door, backbuffer,
234 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
236 redraw_mask = REDRAW_ALL;
240 static int getLastLevelButtonPos()
245 static int getCurrentLevelTextPos()
247 return (getLastLevelButtonPos() + 1);
250 static int getNextLevelButtonPos()
252 return getLastLevelButtonPos() + 3 + 1;
255 static int getLevelRangeTextPos()
257 return getNextLevelButtonPos() + 1;
262 static LevelDirTree *leveldir_last_valid = NULL;
263 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
265 char *level_text = "Levelset";
267 char *level_text = "Level:";
269 int name_width, level_width;
273 FadeSoundsAndMusic();
275 KeyboardAutoRepeatOn();
278 SetDrawDeactivationMask(REDRAW_NONE);
279 SetDrawBackgroundMask(REDRAW_FIELD);
281 audio.sound_deactivated = FALSE;
283 /* needed if last screen was the playing screen, invoked from level editor */
284 if (level_editor_test_game)
286 game_status = GAME_MODE_EDITOR;
292 /* needed if last screen was the editor screen */
293 UndrawSpecialEditorDoor();
295 /* needed if last screen was the setup screen and fullscreen state changed */
296 ToggleFullscreenIfNeeded();
298 /* leveldir_current may be invalid (level group, parent link) */
299 if (!validLevelSeries(leveldir_current))
300 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
302 /* store valid level series information */
303 leveldir_last_valid = leveldir_current;
305 /* needed if last screen (level choice) changed graphics, sounds or music */
306 ReloadCustomArtwork(0);
309 SetDrawtoField(DRAW_BACKBUFFER);
313 /* map gadgets for main menu screen */
317 /* level_nr may have been set to value over handicap with level editor */
318 if (setup.handicap && level_nr > leveldir_current->handicap_level)
319 level_nr = leveldir_current->handicap_level;
324 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
329 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
330 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
331 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
332 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
333 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
334 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
335 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
336 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
338 /* calculated after (possible) reload of custom artwork */
339 name_width = getTextWidth(name_text, FONT_MENU_1);
341 level_width = 9 * 32;
344 level_width = 9 * getFontWidth(FONT_MENU_1);
346 level_width = getTextWidth(level_text, FONT_MENU_1);
350 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
354 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
355 int2str(level_nr, 3), FONT_VALUE_1);
358 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
361 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
366 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
372 int text_height = getFontHeight(FONT_TEXT_3);
374 int xpos = getLevelRangeTextPos() * 32;
376 int xpos = level_width + 6 * 32;
378 int ypos2 = -SY + 3 * 32 + 16;
379 int ypos1 = ypos2 - text_height;
381 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
382 "%03d", leveldir_current->first_level);
383 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
384 "%03d", leveldir_current->last_level);
387 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
388 "%d", leveldir_current->levels);
392 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
393 leveldir_current->first_level, leveldir_current->last_level);
397 if (leveldir_current->readonly)
399 DrawTextS(mSX + level_width + 9 * 32 - 2,
400 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
401 DrawTextS(mSX + level_width + 9 * 32 - 2,
402 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
406 for (i = 0; i < 8; i++)
407 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
411 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
412 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
415 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
416 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
418 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
419 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
423 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
428 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
431 if (TAPE_IS_EMPTY(tape))
433 DrawCompleteVideoDisplay();
438 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
441 /* map gadgets for main menu screen */
447 static void gotoTopLevelDir()
449 /* move upwards to top level directory */
450 while (leveldir_current->node_parent)
452 /* write a "path" into level tree for easy navigation to last level */
453 if (leveldir_current->node_parent->node_group->cl_first == -1)
455 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
456 int leveldir_pos = posTreeInfo(leveldir_current);
457 int num_page_entries;
458 int cl_first, cl_cursor;
460 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
461 num_page_entries = num_leveldirs;
463 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
465 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
466 cl_cursor = leveldir_pos - cl_first;
468 leveldir_current->node_parent->node_group->cl_first = cl_first;
469 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
472 leveldir_current = leveldir_current->node_parent;
477 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
479 static unsigned long level_delay = 0;
480 static int choice = 5;
484 if (button == MB_MENU_INITIALIZE)
486 drawCursor(choice, FC_RED);
490 if (mx || my) /* mouse input */
493 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
495 else if (dx || dy) /* keyboard input */
497 if (dx && choice == 1)
498 x = (dx < 0 ? 10 : 14);
501 if (choice == 4 || choice == 6)
502 button = MB_MENU_CHOICE;
508 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
509 (x == 14 && level_nr < leveldir_current->last_level)) &&
510 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
512 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
513 int old_level_nr = level_nr;
516 new_level_nr = level_nr + (x == 10 ? -step : +step);
517 if (new_level_nr < leveldir_current->first_level)
518 new_level_nr = leveldir_current->first_level;
519 if (new_level_nr > leveldir_current->last_level)
520 new_level_nr = leveldir_current->last_level;
522 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
524 /* skipping levels is only allowed when trying to skip single level */
525 if (setup.skip_levels && step == 1 &&
526 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
528 leveldir_current->handicap_level++;
529 SaveLevelSetup_SeriesInfo();
532 new_level_nr = leveldir_current->handicap_level;
535 if (new_level_nr != old_level_nr)
537 level_nr = new_level_nr;
539 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
543 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
547 DrawCompleteVideoDisplay();
549 /* needed because DrawMicroLevel() takes some time */
552 DelayReached(&level_delay, 0); /* reset delay counter */
555 else if (IN_VIS_FIELD(x, y) &&
556 y >= 0 && y <= 7 && (y != 1 || x < 10))
562 drawCursor(y, FC_RED);
563 drawCursor(choice, FC_BLUE);
571 game_status = GAME_MODE_PSEUDO_TYPENAME;
572 HandleTypeName(strlen(setup.player_name), 0);
578 game_status = GAME_MODE_LEVELS;
579 SaveLevelSetup_LastSeries();
580 SaveLevelSetup_SeriesInfo();
591 game_status = GAME_MODE_SCORES;
596 if (leveldir_current->readonly &&
597 !strEqual(setup.player_name, "Artsoft"))
598 Request("This level is read only !", REQ_CONFIRM);
599 game_status = GAME_MODE_EDITOR;
604 game_status = GAME_MODE_INFO;
605 info_mode = INFO_MODE_MAIN;
610 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
614 game_status = GAME_MODE_SETUP;
615 setup_mode = SETUP_MODE_MAIN;
621 SaveLevelSetup_LastSeries();
622 SaveLevelSetup_SeriesInfo();
624 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
625 game_status = GAME_MODE_QUIT;
630 if (game_status == GAME_MODE_MAIN)
632 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
638 /* ========================================================================= */
639 /* info screen functions */
640 /* ========================================================================= */
642 static struct TokenInfo *info_info;
643 static int num_info_info;
645 static void execInfoElements()
647 info_mode = INFO_MODE_ELEMENTS;
651 static void execInfoMusic()
653 info_mode = INFO_MODE_MUSIC;
657 static void execInfoCredits()
659 info_mode = INFO_MODE_CREDITS;
663 static void execInfoProgram()
665 info_mode = INFO_MODE_PROGRAM;
669 static void execInfoLevelSet()
671 info_mode = INFO_MODE_LEVELSET;
675 static void execExitInfo()
677 game_status = GAME_MODE_MAIN;
681 static struct TokenInfo info_info_main[] =
683 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
684 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
685 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
686 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
687 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
688 { TYPE_EMPTY, NULL, "" },
689 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
694 static void DrawInfoScreen_Main()
699 CloseDoor(DOOR_CLOSE_2);
704 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
706 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
709 info_info = info_info_main;
712 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
714 int ypos = MENU_SCREEN_START_YPOS + i;
715 int font_nr = FONT_MENU_1;
717 DrawText(mSX + 32, mSY + ypos * 32, info_info[i].text, font_nr);
719 if (info_info[i].type & TYPE_ENTER_MENU)
720 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
721 else if (info_info[i].type & TYPE_LEAVE_MENU)
722 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
723 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
724 initCursor(i, IMG_MENU_BUTTON);
735 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
738 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
740 static int choice_store[MAX_INFO_MODES];
741 int choice = choice_store[info_mode]; /* always starts with 0 */
745 if (button == MB_MENU_INITIALIZE)
747 /* advance to first valid menu entry */
748 while (choice < num_info_info &&
749 info_info[choice].type & TYPE_SKIP_ENTRY)
751 choice_store[info_mode] = choice;
753 drawCursor(choice, FC_RED);
756 else if (button == MB_MENU_LEAVE)
758 for (y = 0; y < num_info_info; y++)
760 if (info_info[y].type & TYPE_LEAVE_MENU)
762 void (*menu_callback_function)(void) = info_info[y].value;
764 menu_callback_function();
765 break; /* absolutely needed because function changes 'info_info'! */
772 if (mx || my) /* mouse input */
775 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
777 else if (dx || dy) /* keyboard input */
781 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
783 if (info_info[choice].type & menu_navigation_type ||
784 info_info[choice].type & TYPE_ENTER_SCREEN ||
785 info_info[choice].type & TYPE_BOOLEAN_STYLE)
786 button = MB_MENU_CHOICE;
791 /* jump to next non-empty menu entry (up or down) */
792 while (y > 0 && y < num_info_info - 1 &&
793 info_info[y].type & TYPE_SKIP_ENTRY)
797 if (IN_VIS_FIELD(x, y) &&
798 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
804 drawCursor(y, FC_RED);
805 drawCursor(choice, FC_BLUE);
806 choice = choice_store[info_mode] = y;
809 else if (!(info_info[y].type & TYPE_GHOSTED))
811 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
813 void (*menu_callback_function)(void) = info_info[choice].value;
815 menu_callback_function();
821 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
823 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
824 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
825 int xstart = mSX + 16;
826 int ystart = mSY + 64 + 2 * 32;
827 int ystep = TILEY + 4;
828 int element, action, direction;
836 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
837 infoscreen_step[i] = infoscreen_frame[i] = 0;
842 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
844 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
845 "Press any key or button for next page");
851 while (helpanim_info[j].element != HELPANIM_LIST_END)
853 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
858 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
867 j += infoscreen_step[i - start];
869 element = helpanim_info[j].element;
870 action = helpanim_info[j].action;
871 direction = helpanim_info[j].direction;
874 element = EL_UNKNOWN;
876 if (action != -1 && direction != -1)
877 graphic = el_act_dir2img(element, action, direction);
878 else if (action != -1)
879 graphic = el_act2img(element, action);
880 else if (direction != -1)
881 graphic = el_dir2img(element, direction);
883 graphic = el2img(element);
885 delay = helpanim_info[j++].delay;
890 if (infoscreen_frame[i - start] == 0)
893 infoscreen_frame[i - start] = delay - 1;
897 sync_frame = delay - infoscreen_frame[i - start];
898 infoscreen_frame[i - start]--;
901 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
903 if (!infoscreen_frame[i - start])
904 infoscreen_step[i - start] = 0;
908 if (!infoscreen_frame[i - start])
909 infoscreen_step[i - start]++;
910 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
916 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
918 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
919 graphic, sync_frame, USE_MASKING);
922 DrawInfoScreen_HelpText(element, action, direction, i - start);
927 redraw_mask |= REDRAW_FIELD;
932 static char *getHelpText(int element, int action, int direction)
934 char token[MAX_LINE_LEN];
936 strcpy(token, element_info[element].token_name);
939 strcat(token, element_action_info[action].suffix);
942 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
944 return getHashEntry(helptext_info, token);
947 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
949 int font_nr = FONT_LEVEL_NUMBER;
950 int font_width = getFontWidth(font_nr);
951 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
952 int sy = mSY + 65 + 2 * 32 + 1;
953 int ystep = TILEY + 4;
955 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
956 int max_lines_per_text = 2;
959 if (action != -1 && direction != -1) /* element.action.direction */
960 text = getHelpText(element, action, direction);
962 if (text == NULL && action != -1) /* element.action */
963 text = getHelpText(element, action, -1);
965 if (text == NULL && direction != -1) /* element.direction */
966 text = getHelpText(element, -1, direction);
968 if (text == NULL) /* base element */
969 text = getHelpText(element, -1, -1);
971 if (text == NULL) /* not found */
972 text = "No description available";
974 if (strlen(text) <= max_chars_per_line) /* only one line of text */
975 sy += getFontHeight(font_nr) / 2;
977 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
978 max_chars_per_line, max_lines_per_text);
981 void DrawInfoScreen_Elements()
983 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
988 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
994 void HandleInfoScreen_Elements(int button)
996 static unsigned long info_delay = 0;
997 static int num_anims;
998 static int num_pages;
1000 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1001 int button_released = !button;
1004 if (button == MB_MENU_INITIALIZE)
1006 boolean new_element = TRUE;
1009 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1011 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1013 else if (new_element)
1016 new_element = FALSE;
1020 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1023 else if (button == MB_MENU_LEAVE)
1025 info_mode = INFO_MODE_MAIN;
1031 if (button_released || button == MB_MENU_INITIALIZE)
1033 if (button != MB_MENU_INITIALIZE)
1036 if (page >= num_pages)
1038 FadeSoundsAndMusic();
1040 info_mode = INFO_MODE_MAIN;
1046 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1050 if (DelayReached(&info_delay, GameFrameDelay))
1051 if (page < num_pages)
1052 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1054 PlayMenuSoundIfLoop();
1058 void DrawInfoScreen_Music()
1060 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1067 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1070 void HandleInfoScreen_Music(int button)
1072 static struct MusicFileInfo *list = NULL;
1073 int ystart = 150, dy = 30;
1074 int ybottom = SYSIZE - 20;
1075 int button_released = !button;
1077 if (button == MB_MENU_INITIALIZE)
1079 list = music_file_info;
1083 FadeSoundsAndMusic();
1088 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1090 DrawTextSCentered(ybottom, FONT_TEXT_4,
1091 "Press any key or button for info menu");
1096 else if (button == MB_MENU_LEAVE)
1098 info_mode = INFO_MODE_MAIN;
1104 if (button_released || button == MB_MENU_INITIALIZE)
1108 if (button != MB_MENU_INITIALIZE)
1114 info_mode = INFO_MODE_MAIN;
1120 FadeSoundsAndMusic();
1127 int sound = list->music;
1129 if (sound_info[sound].loop)
1130 PlaySoundLoop(sound);
1134 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1138 PlayMusic(list->music);
1140 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1143 if (!strEqual(list->title, UNKNOWN_NAME))
1145 if (!strEqual(list->title_header, UNKNOWN_NAME))
1146 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1148 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1151 if (!strEqual(list->artist, UNKNOWN_NAME))
1153 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1154 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1156 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1158 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1161 if (!strEqual(list->album, UNKNOWN_NAME))
1163 if (!strEqual(list->album_header, UNKNOWN_NAME))
1164 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1166 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1168 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1171 if (!strEqual(list->year, UNKNOWN_NAME))
1173 if (!strEqual(list->year_header, UNKNOWN_NAME))
1174 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1176 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1178 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1181 DrawTextSCentered(ybottom, FONT_TEXT_4,
1182 "Press any key or button for next page");
1185 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1186 PlaySoundLoop(list->music);
1189 void DrawInfoScreen_Credits()
1191 int ystart = 150, ystep = 30;
1192 int ybottom = SYSIZE - 20;
1194 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1196 FadeSoundsAndMusic();
1201 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1202 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1203 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1204 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1205 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1206 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1207 "...and many thanks to all contributors");
1208 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1210 DrawTextSCentered(ybottom, FONT_TEXT_4,
1211 "Press any key or button for info menu");
1214 void HandleInfoScreen_Credits(int button)
1216 int button_released = !button;
1218 if (button == MB_MENU_LEAVE)
1220 info_mode = INFO_MODE_MAIN;
1226 if (button_released)
1228 FadeSoundsAndMusic();
1230 info_mode = INFO_MODE_MAIN;
1235 PlayMenuSoundIfLoop();
1239 void DrawInfoScreen_Program()
1241 int ystart = 150, ystep = 30;
1242 int ybottom = SYSIZE - 20;
1244 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1249 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1251 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1252 "This game is Freeware!");
1253 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1254 "If you like it, send e-mail to:");
1255 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1256 "info@artsoft.org");
1257 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1258 "or SnailMail to:");
1259 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1261 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1262 "Detmolder Strasse 189");
1263 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1265 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1268 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1269 "If you have created new levels,");
1270 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1271 "send them to me to include them!");
1272 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1275 DrawTextSCentered(ybottom, FONT_TEXT_4,
1276 "Press any key or button for info menu");
1279 void HandleInfoScreen_Program(int button)
1281 int button_released = !button;
1283 if (button == MB_MENU_LEAVE)
1285 info_mode = INFO_MODE_MAIN;
1291 if (button_released)
1293 FadeSoundsAndMusic();
1295 info_mode = INFO_MODE_MAIN;
1300 PlayMenuSoundIfLoop();
1304 void DrawInfoScreen_LevelSet()
1307 int ybottom = SYSIZE - 20;
1308 char *filename = getLevelSetInfoFilename();
1309 int font_nr = FONT_LEVEL_NUMBER;
1310 int font_width = getFontWidth(font_nr);
1311 int font_height = getFontHeight(font_nr);
1314 int sx = SX + pad_x;
1315 int sy = SY + pad_y;
1316 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1317 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1319 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1324 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1326 DrawTextSCentered(ybottom, FONT_TEXT_4,
1327 "Press any key or button for info menu");
1329 if (filename != NULL)
1330 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1331 max_lines_per_screen);
1333 DrawTextSCentered(ystart, FONT_TEXT_2,
1334 "No information for this level set.");
1337 void HandleInfoScreen_LevelSet(int button)
1339 int button_released = !button;
1341 if (button == MB_MENU_LEAVE)
1343 info_mode = INFO_MODE_MAIN;
1349 if (button_released)
1351 FadeSoundsAndMusic();
1353 info_mode = INFO_MODE_MAIN;
1358 PlayMenuSoundIfLoop();
1362 void DrawInfoScreen()
1364 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1366 if (info_mode == INFO_MODE_ELEMENTS)
1367 DrawInfoScreen_Elements();
1368 else if (info_mode == INFO_MODE_MUSIC)
1369 DrawInfoScreen_Music();
1370 else if (info_mode == INFO_MODE_CREDITS)
1371 DrawInfoScreen_Credits();
1372 else if (info_mode == INFO_MODE_PROGRAM)
1373 DrawInfoScreen_Program();
1374 else if (info_mode == INFO_MODE_LEVELSET)
1375 DrawInfoScreen_LevelSet();
1377 DrawInfoScreen_Main();
1379 if (info_mode != INFO_MODE_MUSIC)
1386 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1388 if (info_mode == INFO_MODE_ELEMENTS)
1389 HandleInfoScreen_Elements(button);
1390 else if (info_mode == INFO_MODE_MUSIC)
1391 HandleInfoScreen_Music(button);
1392 else if (info_mode == INFO_MODE_CREDITS)
1393 HandleInfoScreen_Credits(button);
1394 else if (info_mode == INFO_MODE_PROGRAM)
1395 HandleInfoScreen_Program(button);
1396 else if (info_mode == INFO_MODE_LEVELSET)
1397 HandleInfoScreen_LevelSet(button);
1399 HandleInfoScreen_Main(mx, my, dx, dy, button);
1405 /* ========================================================================= */
1406 /* type name functions */
1407 /* ========================================================================= */
1409 void HandleTypeName(int newxpos, Key key)
1411 static int xpos = 0, ypos = 2;
1412 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1413 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1414 int startx = mSX + 32 + name_width;
1415 int starty = mSY + ypos * 32;
1421 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1422 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1427 if (((key >= KSYM_A && key <= KSYM_Z) ||
1428 (key >= KSYM_a && key <= KSYM_z)) &&
1429 xpos < MAX_PLAYER_NAME_LEN)
1433 if (key >= KSYM_A && key <= KSYM_Z)
1434 ascii = 'A' + (char)(key - KSYM_A);
1436 ascii = 'a' + (char)(key - KSYM_a);
1438 setup.player_name[xpos] = ascii;
1439 setup.player_name[xpos + 1] = 0;
1442 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1443 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1445 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1448 setup.player_name[xpos] = 0;
1450 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1452 else if (key == KSYM_Return && xpos > 0)
1454 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1455 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1458 game_status = GAME_MODE_MAIN;
1463 /* ========================================================================= */
1464 /* tree menu functions */
1465 /* ========================================================================= */
1467 static void DrawChooseTree(TreeInfo **ti_ptr)
1471 FreeScreenGadgets();
1472 CreateScreenGadgets();
1474 CloseDoor(DOOR_CLOSE_2);
1478 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1479 MapChooseTreeGadgets(*ti_ptr);
1485 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1487 struct GadgetInfo *gi = screen_gadget[id];
1488 int items_max, items_visible, item_position;
1490 items_max = numTreeInfoInGroup(ti);
1491 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1492 item_position = first_entry;
1494 if (item_position > items_max - items_visible)
1495 item_position = items_max - items_visible;
1497 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1498 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1499 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1502 static void drawChooseTreeList(int first_entry, int num_page_entries,
1506 char buffer[SCR_FIELDX * 2];
1507 int max_buffer_len = (SCR_FIELDX - 2) * 2;
1508 char *title_string = NULL;
1510 int xoffset_sets = 16;
1512 int yoffset_sets = MENU_TITLE1_YPOS;
1514 int xoffset_setup = 16;
1516 int yoffset_setup = 16;
1519 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1522 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1525 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1526 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1528 int last_game_status = game_status; /* save current game status */
1531 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1532 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1533 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1534 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1537 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1539 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1542 /* force LEVELS font on artwork setup screen */
1543 game_status = GAME_MODE_LEVELS;
1545 /* clear tree list area, but not title or scrollbar */
1546 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1547 SXSIZE - 32 + menu.scrollbar_xoffset,
1548 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1550 for (i = 0; i < num_page_entries; i++)
1552 TreeInfo *node, *node_first;
1553 int entry_pos = first_entry + i;
1554 int ypos = MENU_SCREEN_START_YPOS + i;
1556 node_first = getTreeInfoFirstGroupEntry(ti);
1557 node = getTreeInfoFromPos(node_first, entry_pos);
1559 strncpy(buffer, node->name, max_buffer_len);
1560 buffer[max_buffer_len] = '\0';
1562 DrawText(mSX + 32, mSY + ypos * 32, buffer, FONT_TEXT_1 + node->color);
1564 if (node->parent_link)
1565 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1566 else if (node->level_group)
1567 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1569 initCursor(i, IMG_MENU_BUTTON);
1572 game_status = last_game_status; /* restore current game status */
1574 redraw_mask |= REDRAW_FIELD;
1577 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1579 TreeInfo *node, *node_first;
1580 int x, last_redraw_mask = redraw_mask;
1582 int ypos = MENU_TITLE2_YPOS;
1587 if (ti->type != TREE_TYPE_LEVEL_DIR)
1590 node_first = getTreeInfoFirstGroupEntry(ti);
1591 node = getTreeInfoFromPos(node_first, entry_pos);
1593 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1595 if (node->parent_link)
1596 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1598 else if (node->level_group)
1599 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1601 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1602 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1603 node->levels, node->class_desc);
1605 /* let BackToFront() redraw only what is needed */
1606 redraw_mask = last_redraw_mask | REDRAW_TILES;
1607 for (x = 0; x < SCR_FIELDX; x++)
1608 MarkTileDirty(x, 1);
1611 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1614 TreeInfo *ti = *ti_ptr;
1616 int y = ti->cl_cursor;
1617 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1618 int num_entries = numTreeInfoInGroup(ti);
1619 int num_page_entries;
1620 int last_game_status = game_status; /* save current game status */
1621 boolean position_set_by_scrollbar = (dx == 999);
1623 /* force LEVELS draw offset on choose level and artwork setup screen */
1624 game_status = GAME_MODE_LEVELS;
1626 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1627 num_page_entries = num_entries;
1629 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1631 game_status = last_game_status; /* restore current game status */
1633 if (button == MB_MENU_INITIALIZE)
1635 int num_entries = numTreeInfoInGroup(ti);
1636 int entry_pos = posTreeInfo(ti);
1638 if (ti->cl_first == -1)
1640 /* only on initialization */
1641 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1642 ti->cl_cursor = entry_pos - ti->cl_first;
1644 else if (ti->cl_cursor >= num_page_entries ||
1645 (num_entries > num_page_entries &&
1646 num_entries - ti->cl_first < num_page_entries))
1648 /* only after change of list size (by custom graphic configuration) */
1649 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1650 ti->cl_cursor = entry_pos - ti->cl_first;
1653 if (position_set_by_scrollbar)
1656 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1659 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1660 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1661 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1665 else if (button == MB_MENU_LEAVE)
1667 if (ti->node_parent)
1669 *ti_ptr = ti->node_parent;
1670 DrawChooseTree(ti_ptr);
1672 else if (game_status == GAME_MODE_SETUP)
1678 game_status = GAME_MODE_MAIN;
1685 if (mx || my) /* mouse input */
1687 int last_game_status = game_status; /* save current game status */
1689 /* force LEVELS draw offset on artwork setup screen */
1690 game_status = GAME_MODE_LEVELS;
1692 x = (mx - mSX) / 32;
1693 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1695 game_status = last_game_status; /* restore current game status */
1697 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1699 /* move cursor instead of scrolling when already at start/end of list */
1700 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1702 else if (dy == +1 * SCROLL_LINE &&
1703 ti->cl_first + num_page_entries == num_entries)
1706 /* handle scrolling screen one line or page */
1707 if (ti->cl_cursor + dy < 0 ||
1708 ti->cl_cursor + dy > num_page_entries - 1)
1710 if (ABS(dy) == SCROLL_PAGE)
1711 step = num_page_entries - 1;
1713 if (dy < 0 && ti->cl_first > 0)
1715 /* scroll page/line up */
1717 ti->cl_first -= step;
1718 if (ti->cl_first < 0)
1721 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1722 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1723 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1724 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1727 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1729 /* scroll page/line down */
1731 ti->cl_first += step;
1732 if (ti->cl_first + num_page_entries > num_entries)
1733 ti->cl_first = MAX(0, num_entries - num_page_entries);
1735 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1736 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1737 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1738 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1745 /* handle moving cursor one line */
1746 y = ti->cl_cursor + dy;
1751 TreeInfo *node_first, *node_cursor;
1752 int entry_pos = ti->cl_first + y;
1754 node_first = getTreeInfoFirstGroupEntry(ti);
1755 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1757 if (node_cursor->node_group)
1759 node_cursor->cl_first = ti->cl_first;
1760 node_cursor->cl_cursor = ti->cl_cursor;
1761 *ti_ptr = node_cursor->node_group;
1762 DrawChooseTree(ti_ptr);
1767 else if (dx == -1 && ti->node_parent)
1769 *ti_ptr = ti->node_parent;
1770 DrawChooseTree(ti_ptr);
1775 if (!anyScrollbarGadgetActive() &&
1776 IN_VIS_FIELD(x, y) &&
1777 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1778 y >= 0 && y < num_page_entries)
1782 if (y != ti->cl_cursor)
1784 drawChooseTreeCursor(y, FC_RED);
1785 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1786 drawChooseTreeInfo(ti->cl_first + y, ti);
1792 TreeInfo *node_first, *node_cursor;
1793 int entry_pos = ti->cl_first + y;
1795 node_first = getTreeInfoFirstGroupEntry(ti);
1796 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1798 if (node_cursor->node_group)
1800 node_cursor->cl_first = ti->cl_first;
1801 node_cursor->cl_cursor = ti->cl_cursor;
1802 *ti_ptr = node_cursor->node_group;
1803 DrawChooseTree(ti_ptr);
1805 else if (node_cursor->parent_link)
1807 *ti_ptr = node_cursor->node_parent;
1808 DrawChooseTree(ti_ptr);
1812 node_cursor->cl_first = ti->cl_first;
1813 node_cursor->cl_cursor = ti->cl_cursor;
1814 *ti_ptr = node_cursor;
1816 if (ti->type == TREE_TYPE_LEVEL_DIR)
1818 LoadLevelSetup_SeriesInfo();
1820 SaveLevelSetup_LastSeries();
1821 SaveLevelSetup_SeriesInfo();
1825 if (game_status == GAME_MODE_SETUP)
1831 game_status = GAME_MODE_MAIN;
1839 void DrawChooseLevel()
1841 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1843 DrawChooseTree(&leveldir_current);
1849 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1851 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1856 void DrawHallOfFame(int highlight_position)
1859 FadeSoundsAndMusic();
1860 CloseDoor(DOOR_CLOSE_2);
1862 if (highlight_position < 0)
1863 LoadScore(level_nr);
1871 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1874 static void drawHallOfFameList(int first_entry, int highlight_position)
1878 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1882 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
1883 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1884 "HighScores of Level %d", level_nr);
1886 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
1887 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1888 "HighScores of Level %d", level_nr);
1891 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1893 int entry = first_entry + i;
1894 boolean active = (entry == highlight_position);
1895 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1896 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1897 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1898 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1899 int dx1 = 3 * getFontWidth(font_nr1);
1900 int dx2 = dx1 + getFontWidth(font_nr1);
1901 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1902 int sy = mSY + 64 + i * 32;
1904 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1905 DrawText(mSX + dx1, sy, ".", font_nr1);
1906 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1908 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
1909 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1911 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1914 redraw_mask |= REDRAW_FIELD;
1917 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1919 static int first_entry = 0;
1920 static int highlight_position = 0;
1921 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1922 int button_released = !button;
1924 if (button == MB_MENU_INITIALIZE)
1927 highlight_position = mx;
1928 drawHallOfFameList(first_entry, highlight_position);
1933 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1934 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1938 if (first_entry > 0)
1940 first_entry -= step;
1941 if (first_entry < 0)
1944 drawHallOfFameList(first_entry, highlight_position);
1949 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1951 first_entry += step;
1952 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1953 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1955 drawHallOfFameList(first_entry, highlight_position);
1958 else if (button_released)
1960 FadeSound(SND_BACKGROUND_SCORES);
1961 game_status = GAME_MODE_MAIN;
1965 if (game_status == GAME_MODE_SCORES)
1966 PlayMenuSoundIfLoop();
1972 /* ========================================================================= */
1973 /* setup screen functions */
1974 /* ========================================================================= */
1976 static struct TokenInfo *setup_info;
1977 static int num_setup_info;
1979 static char *graphics_set_name;
1980 static char *sounds_set_name;
1981 static char *music_set_name;
1983 static void execSetupMain()
1985 setup_mode = SETUP_MODE_MAIN;
1989 static void execSetupGame()
1991 setup_mode = SETUP_MODE_GAME;
1995 static void execSetupEditor()
1997 setup_mode = SETUP_MODE_EDITOR;
2001 static void execSetupGraphics()
2003 setup_mode = SETUP_MODE_GRAPHICS;
2007 static void execSetupSound()
2009 setup_mode = SETUP_MODE_SOUND;
2013 static void execSetupArtwork()
2015 setup.graphics_set = artwork.gfx_current->identifier;
2016 setup.sounds_set = artwork.snd_current->identifier;
2017 setup.music_set = artwork.mus_current->identifier;
2019 /* needed if last screen (setup choice) changed graphics, sounds or music */
2020 ReloadCustomArtwork(0);
2022 /* needed for displaying artwork name instead of artwork identifier */
2023 graphics_set_name = artwork.gfx_current->name;
2024 sounds_set_name = artwork.snd_current->name;
2025 music_set_name = artwork.mus_current->name;
2027 setup_mode = SETUP_MODE_ARTWORK;
2031 static void execSetupChooseGraphics()
2033 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2037 static void execSetupChooseSounds()
2039 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2043 static void execSetupChooseMusic()
2045 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2049 static void execSetupInput()
2051 setup_mode = SETUP_MODE_INPUT;
2055 static void execSetupShortcut1()
2057 setup_mode = SETUP_MODE_SHORTCUT_1;
2061 static void execSetupShortcut2()
2063 setup_mode = SETUP_MODE_SHORTCUT_2;
2067 static void execExitSetup()
2069 game_status = GAME_MODE_MAIN;
2073 static void execSaveAndExitSetup()
2079 static struct TokenInfo setup_info_main[] =
2081 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2082 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2083 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2084 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2085 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2086 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2087 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2088 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2089 { TYPE_EMPTY, NULL, "" },
2090 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2091 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2096 static struct TokenInfo setup_info_game[] =
2098 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2099 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2100 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2101 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2102 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2103 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2104 { TYPE_EMPTY, NULL, "" },
2105 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2110 static struct TokenInfo setup_info_editor[] =
2112 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2113 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2114 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2115 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2116 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2117 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2118 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2119 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2120 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2121 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2122 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2123 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2124 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2125 { TYPE_EMPTY, NULL, "" },
2126 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2131 static struct TokenInfo setup_info_graphics[] =
2133 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen Mode:" },
2134 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2136 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2137 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2138 { TYPE_SWITCH, &setup.fading, "Fading:" },
2140 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2141 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2142 { TYPE_SWITCH, &setup.toons, "Toons:" },
2143 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2144 { TYPE_EMPTY, NULL, "" },
2145 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2150 static struct TokenInfo setup_info_sound[] =
2152 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2153 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2154 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2155 { TYPE_EMPTY, NULL, "" },
2156 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2161 static struct TokenInfo setup_info_artwork[] =
2163 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2164 { TYPE_STRING, &graphics_set_name, "" },
2165 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2166 { TYPE_STRING, &sounds_set_name, "" },
2167 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2168 { TYPE_STRING, &music_set_name, "" },
2169 { TYPE_EMPTY, NULL, "" },
2171 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2172 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2173 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2175 { TYPE_STRING, NULL, "Override Level Artwork:"},
2176 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2177 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2178 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2180 { TYPE_EMPTY, NULL, "" },
2181 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2186 static struct TokenInfo setup_info_shortcut_1[] =
2188 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2189 { TYPE_KEY, &setup.shortcut.save_game, "" },
2190 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2191 { TYPE_KEY, &setup.shortcut.load_game, "" },
2192 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2193 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2194 { TYPE_EMPTY, NULL, "" },
2195 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2196 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2197 { TYPE_EMPTY, NULL, "" },
2198 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2203 static struct TokenInfo setup_info_shortcut_2[] =
2205 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2206 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2207 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2208 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2209 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2210 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2211 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2212 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2213 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2214 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2215 { TYPE_EMPTY, NULL, "" },
2216 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2221 static Key getSetupKey()
2223 Key key = KSYM_UNDEFINED;
2224 boolean got_key_event = FALSE;
2226 while (!got_key_event)
2228 if (PendingEvent()) /* got event */
2236 case EVENT_KEYPRESS:
2238 key = GetEventKey((KeyEvent *)&event, TRUE);
2240 /* press 'Escape' or 'Enter' to keep the existing key binding */
2241 if (key == KSYM_Escape || key == KSYM_Return)
2242 key = KSYM_UNDEFINED; /* keep old value */
2244 got_key_event = TRUE;
2248 case EVENT_KEYRELEASE:
2249 key_joystick_mapping = 0;
2253 HandleOtherEvents(&event);
2261 /* don't eat all CPU time */
2268 static void drawSetupValue(int pos)
2270 int xpos = MENU_SCREEN_VALUE_XPOS;
2271 int ypos = MENU_SCREEN_START_YPOS + pos;
2272 int font_nr = FONT_VALUE_1;
2273 int font_width = getFontWidth(font_nr);
2274 int type = setup_info[pos].type;
2275 void *value = setup_info[pos].value;
2276 char *value_string = getSetupValue(type, value);
2279 if (value_string == NULL)
2282 if (type & TYPE_KEY)
2290 if (type & TYPE_QUERY)
2292 value_string = "<press key>";
2293 font_nr = FONT_INPUT_1_ACTIVE;
2296 else if (type & TYPE_STRING)
2298 int max_value_len = (SCR_FIELDX - 2) * 2;
2301 font_nr = FONT_VALUE_2;
2303 if (strlen(value_string) > max_value_len)
2304 value_string[max_value_len] = '\0';
2306 else if (type & TYPE_ECS_AGA)
2308 font_nr = FONT_VALUE_1;
2310 else if (type & TYPE_BOOLEAN_STYLE)
2312 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2316 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
2317 DrawText(mSX + xpos * 32 + i * font_width, mSY + ypos * 32, " ", font_nr);
2320 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
2321 DrawText(mSX + i * 32, mSY + ypos * 32, " ", font_nr);
2323 DrawText(mSX + xpos * 32, mSY + ypos * 32,
2324 (xpos == 3 ? " " : " "), font_nr);
2328 DrawText(mSX + xpos * 32, mSY + ypos * 32, value_string, font_nr);
2331 static void changeSetupValue(int pos)
2333 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2335 *(boolean *)setup_info[pos].value ^= TRUE;
2337 else if (setup_info[pos].type & TYPE_KEY)
2341 setup_info[pos].type |= TYPE_QUERY;
2342 drawSetupValue(pos);
2343 setup_info[pos].type &= ~TYPE_QUERY;
2345 key = getSetupKey();
2346 if (key != KSYM_UNDEFINED)
2347 *(Key *)setup_info[pos].value = key;
2350 drawSetupValue(pos);
2353 static void DrawSetupScreen_Generic()
2355 char *title_string = NULL;
2359 CloseDoor(DOOR_CLOSE_2);
2363 if (setup_mode == SETUP_MODE_MAIN)
2365 setup_info = setup_info_main;
2366 title_string = "Setup";
2368 else if (setup_mode == SETUP_MODE_GAME)
2370 setup_info = setup_info_game;
2371 title_string = "Setup Game";
2373 else if (setup_mode == SETUP_MODE_EDITOR)
2375 setup_info = setup_info_editor;
2376 title_string = "Setup Editor";
2378 else if (setup_mode == SETUP_MODE_GRAPHICS)
2380 setup_info = setup_info_graphics;
2381 title_string = "Setup Graphics";
2383 else if (setup_mode == SETUP_MODE_SOUND)
2385 setup_info = setup_info_sound;
2386 title_string = "Setup Sound";
2388 else if (setup_mode == SETUP_MODE_ARTWORK)
2390 setup_info = setup_info_artwork;
2391 title_string = "Custom Artwork";
2393 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
2395 setup_info = setup_info_shortcut_1;
2396 title_string = "Setup Shortcuts";
2398 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
2400 setup_info = setup_info_shortcut_2;
2401 title_string = "Setup Shortcuts";
2405 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2407 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2411 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2413 void *value_ptr = setup_info[i].value;
2414 int ypos = MENU_SCREEN_START_YPOS + i;
2415 int font_nr = FONT_MENU_1;
2417 /* set some entries to "unchangeable" according to other variables */
2418 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2419 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2420 (value_ptr == &setup.sound_music && !audio.music_available) ||
2421 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2422 setup_info[i].type |= TYPE_GHOSTED;
2425 if (setup_info[i].type & (TYPE_SWITCH |
2430 font_nr = FONT_MENU_2;
2432 if (setup_info[i].type & TYPE_STRING)
2433 font_nr = FONT_MENU_2;
2436 DrawText(mSX + 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2438 if (setup_info[i].type & TYPE_ENTER_MENU)
2439 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2440 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2441 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2442 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2443 initCursor(i, IMG_MENU_BUTTON);
2445 if (setup_info[i].type & TYPE_VALUE)
2452 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2453 "Joysticks deactivated in setup menu");
2458 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2461 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2463 static int choice_store[MAX_SETUP_MODES];
2464 int choice = choice_store[setup_mode]; /* always starts with 0 */
2468 if (button == MB_MENU_INITIALIZE)
2470 /* advance to first valid menu entry */
2471 while (choice < num_setup_info &&
2472 setup_info[choice].type & TYPE_SKIP_ENTRY)
2474 choice_store[setup_mode] = choice;
2476 drawCursor(choice, FC_RED);
2479 else if (button == MB_MENU_LEAVE)
2481 for (y = 0; y < num_setup_info; y++)
2483 if (setup_info[y].type & TYPE_LEAVE_MENU)
2485 void (*menu_callback_function)(void) = setup_info[y].value;
2487 menu_callback_function();
2488 break; /* absolutely needed because function changes 'setup_info'! */
2495 if (mx || my) /* mouse input */
2497 x = (mx - mSX) / 32;
2498 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2500 else if (dx || dy) /* keyboard input */
2504 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2506 if (setup_info[choice].type & menu_navigation_type ||
2507 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2508 button = MB_MENU_CHOICE;
2513 /* jump to next non-empty menu entry (up or down) */
2514 while (y > 0 && y < num_setup_info - 1 &&
2515 setup_info[y].type & TYPE_SKIP_ENTRY)
2519 if (IN_VIS_FIELD(x, y) &&
2520 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2526 drawCursor(y, FC_RED);
2527 drawCursor(choice, FC_BLUE);
2528 choice = choice_store[setup_mode] = y;
2531 else if (!(setup_info[y].type & TYPE_GHOSTED))
2533 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2535 void (*menu_callback_function)(void) = setup_info[choice].value;
2537 menu_callback_function();
2541 if (setup_info[y].type & TYPE_KEYTEXT &&
2542 setup_info[y + 1].type & TYPE_KEY)
2545 if (setup_info[y].type & TYPE_VALUE)
2546 changeSetupValue(y);
2552 void DrawSetupScreen_Input()
2557 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2559 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2562 initCursor(0, IMG_MENU_BUTTON);
2563 initCursor(1, IMG_MENU_BUTTON);
2564 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2565 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2567 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2568 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2570 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2571 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2572 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2575 DeactivateJoystickForCalibration();
2578 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2579 "Joysticks deactivated on this screen");
2582 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2587 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2589 if (device_name == NULL)
2592 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2595 if (strlen(device_name) > 1)
2597 char c1 = device_name[strlen(device_name) - 1];
2598 char c2 = device_name[strlen(device_name) - 2];
2600 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2601 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2604 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2605 strlen(device_name));
2608 static void drawPlayerSetupInputInfo(int player_nr)
2611 static struct SetupKeyboardInfo custom_key;
2618 { &custom_key.left, "Joystick Left" },
2619 { &custom_key.right, "Joystick Right" },
2620 { &custom_key.up, "Joystick Up" },
2621 { &custom_key.down, "Joystick Down" },
2622 { &custom_key.snap, "Button 1" },
2623 { &custom_key.drop, "Button 2" }
2625 static char *joystick_name[MAX_PLAYERS] =
2635 custom_key = setup.input[player_nr].key;
2637 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2638 FONT_INPUT_1_ACTIVE);
2640 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2642 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2643 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2645 if (setup.input[player_nr].use_joystick)
2647 char *device_name = setup.input[player_nr].joy.device_name;
2648 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
2649 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
2651 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
2652 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
2656 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
2657 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
2660 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
2661 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2662 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2663 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2664 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2665 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
2666 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
2667 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
2668 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
2669 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
2670 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
2672 for (i = 0; i < 6; i++)
2674 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2676 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2678 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2679 (setup.input[player_nr].use_joystick ?
2681 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2685 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2687 static int choice = 0;
2688 static int player_nr = 0;
2691 int pos_start = SETUPINPUT_SCREEN_POS_START;
2692 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2693 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2694 int pos_end = SETUPINPUT_SCREEN_POS_END;
2696 if (button == MB_MENU_INITIALIZE)
2698 drawPlayerSetupInputInfo(player_nr);
2699 drawCursor(choice, FC_RED);
2703 else if (button == MB_MENU_LEAVE)
2705 setup_mode = SETUP_MODE_MAIN;
2712 if (mx || my) /* mouse input */
2714 x = (mx - mSX) / 32;
2715 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2717 else if (dx || dy) /* keyboard input */
2719 if (dx && choice == 0)
2720 x = (dx < 0 ? 10 : 12);
2721 else if ((dx && choice == 1) ||
2722 (dx == +1 && choice == 2) ||
2723 (dx == -1 && choice == pos_end))
2724 button = MB_MENU_CHOICE;
2728 if (y >= pos_empty1 && y <= pos_empty2)
2729 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2732 if (IN_VIS_FIELD(x, y) &&
2733 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2735 static unsigned long delay = 0;
2737 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2740 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2742 drawPlayerSetupInputInfo(player_nr);
2744 else if (IN_VIS_FIELD(x, y) &&
2745 y >= pos_start && y <= pos_end &&
2746 !(y >= pos_empty1 && y <= pos_empty2))
2752 drawCursor(y, FC_RED);
2753 drawCursor(choice, FC_BLUE);
2761 char *device_name = setup.input[player_nr].joy.device_name;
2763 if (!setup.input[player_nr].use_joystick)
2765 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2767 setJoystickDeviceToNr(device_name, new_device_nr);
2768 setup.input[player_nr].use_joystick = TRUE;
2772 int device_nr = getJoystickNrFromDeviceName(device_name);
2773 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2775 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2776 setup.input[player_nr].use_joystick = FALSE;
2778 setJoystickDeviceToNr(device_name, new_device_nr);
2781 drawPlayerSetupInputInfo(player_nr);
2785 if (setup.input[player_nr].use_joystick)
2788 CalibrateJoystick(player_nr);
2791 CustomizeKeyboard(player_nr);
2793 else if (y == pos_end)
2797 setup_mode = SETUP_MODE_MAIN;
2804 void CustomizeKeyboard(int player_nr)
2808 boolean finished = FALSE;
2809 static struct SetupKeyboardInfo custom_key;
2814 } customize_step[] =
2816 { &custom_key.left, "Move Left" },
2817 { &custom_key.right, "Move Right" },
2818 { &custom_key.up, "Move Up" },
2819 { &custom_key.down, "Move Down" },
2820 { &custom_key.snap, "Snap Field" },
2821 { &custom_key.drop, "Drop Element" }
2824 /* read existing key bindings from player setup */
2825 custom_key = setup.input[player_nr].key;
2830 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
2832 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2839 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2840 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2841 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2842 "Key:", FONT_INPUT_1_ACTIVE);
2843 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2844 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2848 if (PendingEvent()) /* got event */
2856 case EVENT_KEYPRESS:
2858 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2860 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2866 /* all keys configured -- wait for "Escape" or "Return" key */
2870 /* press 'Enter' to keep the existing key binding */
2871 if (key == KSYM_Return)
2872 key = *customize_step[step_nr].key;
2874 /* check if key already used */
2875 for (i = 0; i < step_nr; i++)
2876 if (*customize_step[i].key == key)
2881 /* got new key binding */
2882 *customize_step[step_nr].key = key;
2883 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2885 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2886 getKeyNameFromKey(key), FONT_VALUE_1);
2889 /* un-highlight last query */
2890 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
2891 customize_step[step_nr - 1].text, FONT_MENU_1);
2892 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
2893 "Key:", FONT_MENU_1);
2895 /* press 'Enter' to leave */
2898 DrawText(mSX + 16, mSY + 15 * 32 + 16,
2899 "Press Enter", FONT_TITLE_1);
2903 /* query next key binding */
2904 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2905 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2906 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2907 "Key:", FONT_INPUT_1_ACTIVE);
2908 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2909 getKeyNameFromKey(*customize_step[step_nr].key),
2914 case EVENT_KEYRELEASE:
2915 key_joystick_mapping = 0;
2919 HandleOtherEvents(&event);
2927 /* don't eat all CPU time */
2931 /* write new key bindings back to player setup */
2932 setup.input[player_nr].key = custom_key;
2935 DrawSetupScreen_Input();
2938 static boolean CalibrateJoystickMain(int player_nr)
2940 int new_joystick_xleft = JOYSTICK_XMIDDLE;
2941 int new_joystick_xright = JOYSTICK_XMIDDLE;
2942 int new_joystick_yupper = JOYSTICK_YMIDDLE;
2943 int new_joystick_ylower = JOYSTICK_YMIDDLE;
2944 int new_joystick_xmiddle, new_joystick_ymiddle;
2946 int joystick_fd = joystick.fd[player_nr];
2947 int x, y, last_x, last_y, xpos = 8, ypos = 3;
2948 boolean check[3][3];
2949 int check_remaining = 3 * 3;
2954 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
2957 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
2962 for (y = 0; y < 3; y++)
2964 for (x = 0; x < 3; x++)
2966 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
2967 check[x][y] = FALSE;
2971 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
2972 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
2973 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
2974 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
2975 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
2976 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
2977 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
2979 joy_value = Joystick(player_nr);
2980 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
2981 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
2983 /* eventually uncalibrated center position (joystick could be uncentered) */
2984 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
2987 new_joystick_xmiddle = joy_x;
2988 new_joystick_ymiddle = joy_y;
2990 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
2993 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
2998 if (PendingEvent()) /* got event */
3006 case EVENT_KEYPRESS:
3007 switch(GetEventKey((KeyEvent *)&event, TRUE))
3010 if (check_remaining == 0)
3023 case EVENT_KEYRELEASE:
3024 key_joystick_mapping = 0;
3028 HandleOtherEvents(&event);
3033 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3036 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3037 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3038 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3039 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3041 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3042 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3043 setup.input[player_nr].joy.xright = new_joystick_xright;
3044 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3045 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3046 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3048 CheckJoystickData();
3050 joy_value = Joystick(player_nr);
3052 if (joy_value & JOY_BUTTON && check_remaining == 0)
3055 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3056 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3058 if (x != last_x || y != last_y)
3060 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3061 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3066 if (check_remaining > 0 && !check[x+1][y+1])
3068 check[x+1][y+1] = TRUE;
3074 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3075 setup.input[player_nr].joy.xleft,
3076 setup.input[player_nr].joy.xmiddle,
3077 setup.input[player_nr].joy.xright);
3078 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3079 setup.input[player_nr].joy.yupper,
3080 setup.input[player_nr].joy.ymiddle,
3081 setup.input[player_nr].joy.ylower);
3090 /* don't eat all CPU time */
3094 /* calibrated center position (joystick should now be centered) */
3095 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3098 new_joystick_xmiddle = joy_x;
3099 new_joystick_ymiddle = joy_y;
3104 DrawSetupScreen_Input();
3107 /* wait until the last pressed button was released */
3108 while (Joystick(player_nr) & JOY_BUTTON)
3110 if (PendingEvent()) /* got event */
3115 HandleOtherEvents(&event);
3124 void CalibrateJoystick(int player_nr)
3126 if (!CalibrateJoystickMain(player_nr))
3128 char *device_name = setup.input[player_nr].joy.device_name;
3129 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3130 int xpos = mSX - SX;
3131 int ypos = mSY - SY;
3135 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3136 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3139 Delay(2000); /* show error message for a short time */
3145 DrawSetupScreen_Input();
3149 void DrawSetupScreen()
3151 DeactivateJoystick();
3153 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3155 if (setup_mode == SETUP_MODE_INPUT)
3156 DrawSetupScreen_Input();
3157 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3158 DrawChooseTree(&artwork.gfx_current);
3159 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3160 DrawChooseTree(&artwork.snd_current);
3161 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3162 DrawChooseTree(&artwork.mus_current);
3164 DrawSetupScreen_Generic();
3170 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3172 if (setup_mode == SETUP_MODE_INPUT)
3173 HandleSetupScreen_Input(mx, my, dx, dy, button);
3174 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3175 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3176 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3177 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3178 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3179 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3181 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3186 void HandleGameActions()
3188 if (game_status != GAME_MODE_PLAYING)
3191 GameActions(); /* main game loop */
3193 if (tape.auto_play && !tape.playing)
3194 AutoPlayTape(); /* continue automatically playing next tape */
3197 /* ---------- new screen button stuff -------------------------------------- */
3199 /* graphic position and size values for buttons and scrollbars */
3200 #define SC_SCROLLBUTTON_XSIZE TILEX
3201 #define SC_SCROLLBUTTON_YSIZE TILEY
3203 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
3204 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
3205 SC_SCROLLBUTTON_YSIZE)
3206 #define SC_SCROLL_UP_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
3207 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
3208 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLL_UP_XPOS
3209 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
3210 SC_SCROLLBUTTON_YSIZE)
3211 #define SC_SCROLL_DOWN_XPOS SC_SCROLL_UP_XPOS
3212 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
3213 SC_SCROLL_VERTICAL_YSIZE)
3215 #define SC_BORDER_SIZE 14
3219 int gfx_unpressed, gfx_pressed;
3223 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3226 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3227 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3228 SCREEN_CTRL_ID_SCROLL_UP,
3232 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3233 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3234 SCREEN_CTRL_ID_SCROLL_DOWN,
3241 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3242 Bitmap **gfx_unpressed, **gfx_pressed;
3244 int gfx_unpressed, gfx_pressed;
3251 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3254 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3255 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3257 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3259 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3260 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3261 GD_TYPE_SCROLLBAR_VERTICAL,
3262 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3263 "scroll level series vertically"
3267 static void CreateScreenScrollbuttons()
3269 struct GadgetInfo *gi;
3270 unsigned long event_mask;
3273 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3275 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3276 int gfx_unpressed, gfx_pressed;
3277 int x, y, width, height;
3278 int gd_x1, gd_x2, gd_y1, gd_y2;
3279 int id = scrollbutton_info[i].gadget_id;
3281 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3283 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3284 y = mSY + scrollbutton_info[i].y;
3285 width = SC_SCROLLBUTTON_XSIZE;
3286 height = SC_SCROLLBUTTON_YSIZE;
3288 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3289 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3290 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3292 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3293 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3294 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3295 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3296 gd_x1 = graphic_info[gfx_unpressed].src_x;
3297 gd_y1 = graphic_info[gfx_unpressed].src_y;
3298 gd_x2 = graphic_info[gfx_pressed].src_x;
3299 gd_y2 = graphic_info[gfx_pressed].src_y;
3301 gi = CreateGadget(GDI_CUSTOM_ID, id,
3302 GDI_CUSTOM_TYPE_ID, i,
3303 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3308 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3309 GDI_STATE, GD_BUTTON_UNPRESSED,
3310 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3311 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3312 GDI_DIRECT_DRAW, FALSE,
3313 GDI_EVENT_MASK, event_mask,
3314 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3318 Error(ERR_EXIT, "cannot create gadget");
3320 screen_gadget[id] = gi;
3324 static void CreateScreenScrollbars()
3328 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3330 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3331 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3332 int gfx_unpressed, gfx_pressed;
3334 int x, y, width, height;
3335 int gd_x1, gd_x2, gd_y1, gd_y2;
3336 struct GadgetInfo *gi;
3337 int items_max, items_visible, item_position;
3338 unsigned long event_mask;
3339 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3340 int id = scrollbar_info[i].gadget_id;
3342 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3344 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3345 y = mSY + scrollbar_info[i].y;
3346 width = scrollbar_info[i].width;
3347 height = scrollbar_info[i].height;
3349 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3350 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3352 items_max = num_page_entries;
3353 items_visible = num_page_entries;
3356 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3357 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3358 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3364 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3365 gfx_pressed = scrollbar_info[i].gfx_pressed;
3366 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3367 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3368 gd_x1 = graphic_info[gfx_unpressed].src_x;
3369 gd_y1 = graphic_info[gfx_unpressed].src_y;
3370 gd_x2 = graphic_info[gfx_pressed].src_x;
3371 gd_y2 = graphic_info[gfx_pressed].src_y;
3374 gi = CreateGadget(GDI_CUSTOM_ID, id,
3375 GDI_CUSTOM_TYPE_ID, i,
3376 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3381 GDI_TYPE, scrollbar_info[i].type,
3382 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3383 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3384 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3385 GDI_STATE, GD_BUTTON_UNPRESSED,
3386 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3387 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3388 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3389 GDI_DIRECT_DRAW, FALSE,
3390 GDI_EVENT_MASK, event_mask,
3391 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3395 Error(ERR_EXIT, "cannot create gadget");
3397 screen_gadget[id] = gi;
3401 void CreateScreenGadgets()
3403 int last_game_status = game_status; /* save current game status */
3405 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3408 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3410 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3412 /* copy pointers to clip mask and GC */
3413 scrollbar_bitmap[i]->clip_mask =
3414 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3415 scrollbar_bitmap[i]->stored_clip_gc =
3416 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3418 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3419 scrollbar_bitmap[i],
3420 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3421 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3422 TILEX, TILEY, 0, 0);
3426 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3427 game_status = GAME_MODE_LEVELS;
3429 CreateScreenScrollbuttons();
3430 CreateScreenScrollbars();
3432 game_status = last_game_status; /* restore current game status */
3435 void FreeScreenGadgets()
3439 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3440 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3442 /* prevent freeing clip mask and GC twice */
3443 scrollbar_bitmap[i]->clip_mask = None;
3444 scrollbar_bitmap[i]->stored_clip_gc = None;
3446 FreeBitmap(scrollbar_bitmap[i]);
3450 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3451 FreeGadget(screen_gadget[i]);
3454 void MapChooseTreeGadgets(TreeInfo *ti)
3456 int num_entries = numTreeInfoInGroup(ti);
3459 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3462 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3463 MapGadget(screen_gadget[i]);
3467 void UnmapChooseTreeGadgets()
3471 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3472 UnmapGadget(screen_gadget[i]);
3476 static void HandleScreenGadgets(struct GadgetInfo *gi)
3478 int id = gi->custom_id;
3480 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3485 case SCREEN_CTRL_ID_SCROLL_UP:
3486 if (game_status == GAME_MODE_LEVELS)
3487 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3488 else if (game_status == GAME_MODE_SETUP)
3489 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3492 case SCREEN_CTRL_ID_SCROLL_DOWN:
3493 if (game_status == GAME_MODE_LEVELS)
3494 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3495 else if (game_status == GAME_MODE_SETUP)
3496 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3499 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3500 if (game_status == GAME_MODE_LEVELS)
3501 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3502 else if (game_status == GAME_MODE_SETUP)
3503 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);