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 MENU_SCREEN_START_XPOS 1
61 #define MENU_SCREEN_START_YPOS 2
62 #define MENU_SCREEN_VALUE_XPOS 14
63 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
64 #define MENU_TITLE1_YPOS 8
65 #define MENU_TITLE2_YPOS 46
66 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
67 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
68 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
69 MENU_SCREEN_START_XPOS)
70 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
72 /* buttons and scrollbars identifiers */
73 #define SCREEN_CTRL_ID_SCROLL_UP 0
74 #define SCREEN_CTRL_ID_SCROLL_DOWN 1
75 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 2
77 #define NUM_SCREEN_SCROLLBUTTONS 2
78 #define NUM_SCREEN_SCROLLBARS 1
79 #define NUM_SCREEN_GADGETS 3
81 /* graphic position and size values for buttons and scrollbars */
82 #define SC_SCROLLBUTTON_XSIZE TILEX
83 #define SC_SCROLLBUTTON_YSIZE TILEY
85 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
87 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
88 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
89 SC_SCROLLBUTTON_YSIZE)
91 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
92 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
94 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
95 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
96 SC_SCROLLBUTTON_YSIZE)
98 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
99 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
100 SC_SCROLL_VERTICAL_YSIZE)
102 #define SC_BORDER_SIZE 14
105 /* forward declarations of internal functions */
106 static void HandleScreenGadgets(struct GadgetInfo *);
107 static void HandleSetupScreen_Generic(int, int, int, int, int);
108 static void HandleSetupScreen_Input(int, int, int, int, int);
109 static void CustomizeKeyboard(int);
110 static void CalibrateJoystick(int);
111 static void execSetupArtwork(void);
112 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
114 static void DrawChooseLevel(void);
115 static void DrawInfoScreen(void);
116 static void DrawSetupScreen(void);
118 static void DrawInfoScreen_HelpAnim(int, int, boolean);
119 static void DrawInfoScreen_HelpText(int, int, int, int);
120 static void HandleInfoScreen_Main(int, int, int, int, int);
121 static void HandleInfoScreen_Elements(int);
122 static void HandleInfoScreen_Music(int);
123 static void HandleInfoScreen_Credits(int);
124 static void HandleInfoScreen_Program(int);
126 static void MapChooseTreeGadgets(TreeInfo *);
128 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
129 static int setup_mode = SETUP_MODE_MAIN;
130 static int info_mode = INFO_MODE_MAIN;
132 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
133 x <= GAME_MODE_SETUP ? x : \
134 x == GAME_MODE_PSEUDO_TYPENAME ? \
135 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
137 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
138 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
140 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
141 menu.list_size[game_status] : \
142 MAX_MENU_ENTRIES_ON_SCREEN)
144 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
145 #define NUM_SCROLLBAR_BITMAPS 2
146 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
150 static void drawCursorExt(int xpos, int ypos, int color, int g)
152 static int cursor_array[SCR_FIELDY];
157 cursor_array[ypos] = g;
159 g = cursor_array[ypos];
163 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
164 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
165 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
166 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
167 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
168 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
169 IMG_MENU_BUTTON_ACTIVE);
171 ypos += MENU_SCREEN_START_YPOS;
173 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
174 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
177 static void initCursor(int ypos, int graphic)
179 drawCursorExt(0, ypos, FC_BLUE, graphic);
182 static void drawCursor(int ypos, int color)
184 drawCursorExt(0, ypos, color, 0);
187 static void drawCursorXY(int xpos, int ypos, int graphic)
189 drawCursorExt(xpos, ypos, -1, graphic);
192 static void drawChooseTreeCursor(int ypos, int color)
194 int last_game_status = game_status; /* save current game status */
196 /* force LEVELS draw offset on artwork setup screen */
197 game_status = GAME_MODE_LEVELS;
199 drawCursorExt(0, ypos, color, 0);
201 game_status = last_game_status; /* restore current game status */
204 static void PlayMenuSound()
206 int sound = menu.sound[game_status];
208 if (sound == SND_UNDEFINED)
211 if (sound_info[sound].loop)
212 PlaySoundLoop(sound);
217 static void PlayMenuSoundIfLoop()
219 int sound = menu.sound[game_status];
221 if (sound == SND_UNDEFINED)
224 if (sound_info[sound].loop)
225 PlaySoundLoop(sound);
228 static void PlayMenuMusic()
230 int music = menu.music[game_status];
232 if (music == MUS_UNDEFINED)
240 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
241 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
244 static void ToggleFullscreenIfNeeded()
246 if (setup.fullscreen != video.fullscreen_enabled)
248 /* save old door content */
249 BlitBitmap(backbuffer, bitmap_db_door,
250 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
252 /* toggle fullscreen */
253 ChangeVideoModeIfNeeded(setup.fullscreen);
254 setup.fullscreen = video.fullscreen_enabled;
256 /* redraw background to newly created backbuffer */
257 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
258 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
260 /* restore old door content */
261 BlitBitmap(bitmap_db_door, backbuffer,
262 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
264 redraw_mask = REDRAW_ALL;
268 static int getLastLevelButtonPos()
273 static int getCurrentLevelTextPos()
275 return (getLastLevelButtonPos() + 1);
278 static int getNextLevelButtonPos()
280 return getLastLevelButtonPos() + 3 + 1;
283 static int getLevelRangeTextPos()
285 return getNextLevelButtonPos() + 1;
290 static LevelDirTree *leveldir_last_valid = NULL;
291 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
293 char *level_text = "Levelset";
295 char *level_text = "Level:";
297 int name_width, level_width;
301 FadeSoundsAndMusic();
303 KeyboardAutoRepeatOn();
306 SetDrawDeactivationMask(REDRAW_NONE);
307 SetDrawBackgroundMask(REDRAW_FIELD);
309 audio.sound_deactivated = FALSE;
311 /* needed if last screen was the playing screen, invoked from level editor */
312 if (level_editor_test_game)
314 game_status = GAME_MODE_EDITOR;
320 /* needed if last screen was the editor screen */
321 UndrawSpecialEditorDoor();
323 /* needed if last screen was the setup screen and fullscreen state changed */
324 ToggleFullscreenIfNeeded();
326 /* leveldir_current may be invalid (level group, parent link) */
327 if (!validLevelSeries(leveldir_current))
328 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
330 /* store valid level series information */
331 leveldir_last_valid = leveldir_current;
333 /* needed if last screen (level choice) changed graphics, sounds or music */
334 ReloadCustomArtwork(0);
337 SetDrawtoField(DRAW_BACKBUFFER);
341 /* map gadgets for main menu screen */
345 /* level_nr may have been set to value over handicap with level editor */
346 if (setup.handicap && level_nr > leveldir_current->handicap_level)
347 level_nr = leveldir_current->handicap_level;
352 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
357 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
358 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
359 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
360 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
361 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
362 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
363 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
364 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
366 /* calculated after (possible) reload of custom artwork */
367 name_width = getTextWidth(name_text, FONT_MENU_1);
369 level_width = 9 * 32;
372 level_width = 9 * getFontWidth(FONT_MENU_1);
374 level_width = getTextWidth(level_text, FONT_MENU_1);
378 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
382 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
383 int2str(level_nr, 3), FONT_VALUE_1);
386 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
389 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
394 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
400 int text_height = getFontHeight(FONT_TEXT_3);
402 int xpos = getLevelRangeTextPos() * 32;
404 int xpos = level_width + 6 * 32;
406 int ypos2 = -SY + 3 * 32 + 16;
407 int ypos1 = ypos2 - text_height;
409 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
410 "%03d", leveldir_current->first_level);
411 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
412 "%03d", leveldir_current->last_level);
415 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
416 "%d", leveldir_current->levels);
420 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
421 leveldir_current->first_level, leveldir_current->last_level);
425 if (leveldir_current->readonly)
427 DrawTextS(mSX + level_width + 9 * 32 - 2,
428 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
429 DrawTextS(mSX + level_width + 9 * 32 - 2,
430 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
434 for (i = 0; i < 8; i++)
435 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
439 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
440 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
443 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
444 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
446 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
447 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
451 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
456 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
459 if (TAPE_IS_EMPTY(tape))
461 DrawCompleteVideoDisplay();
466 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
469 /* map gadgets for main menu screen */
475 static void gotoTopLevelDir()
477 /* move upwards to top level directory */
478 while (leveldir_current->node_parent)
480 /* write a "path" into level tree for easy navigation to last level */
481 if (leveldir_current->node_parent->node_group->cl_first == -1)
483 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
484 int leveldir_pos = posTreeInfo(leveldir_current);
485 int num_page_entries;
486 int cl_first, cl_cursor;
488 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
489 num_page_entries = num_leveldirs;
491 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
493 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
494 cl_cursor = leveldir_pos - cl_first;
496 leveldir_current->node_parent->node_group->cl_first = cl_first;
497 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
500 leveldir_current = leveldir_current->node_parent;
505 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
507 static unsigned long level_delay = 0;
508 static int choice = 5;
512 if (button == MB_MENU_INITIALIZE)
514 drawCursor(choice, FC_RED);
518 if (mx || my) /* mouse input */
521 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
523 else if (dx || dy) /* keyboard input */
525 if (dx && choice == 1)
526 x = (dx < 0 ? 10 : 14);
529 if (choice == 4 || choice == 6)
530 button = MB_MENU_CHOICE;
536 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
537 (x == 14 && level_nr < leveldir_current->last_level)) &&
538 button && DelayReached(&level_delay, GADGET_FRAME_DELAY))
540 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
541 int old_level_nr = level_nr;
544 new_level_nr = level_nr + (x == 10 ? -step : +step);
545 if (new_level_nr < leveldir_current->first_level)
546 new_level_nr = leveldir_current->first_level;
547 if (new_level_nr > leveldir_current->last_level)
548 new_level_nr = leveldir_current->last_level;
550 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
552 /* skipping levels is only allowed when trying to skip single level */
553 if (setup.skip_levels && step == 1 &&
554 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
556 leveldir_current->handicap_level++;
557 SaveLevelSetup_SeriesInfo();
560 new_level_nr = leveldir_current->handicap_level;
563 if (new_level_nr != old_level_nr)
565 level_nr = new_level_nr;
567 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
571 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
575 DrawCompleteVideoDisplay();
577 /* needed because DrawMicroLevel() takes some time */
580 DelayReached(&level_delay, 0); /* reset delay counter */
583 else if (IN_VIS_FIELD(x, y) &&
584 y >= 0 && y <= 7 && (y != 1 || x < 10))
590 drawCursor(y, FC_RED);
591 drawCursor(choice, FC_BLUE);
599 game_status = GAME_MODE_PSEUDO_TYPENAME;
600 HandleTypeName(strlen(setup.player_name), 0);
606 game_status = GAME_MODE_LEVELS;
607 SaveLevelSetup_LastSeries();
608 SaveLevelSetup_SeriesInfo();
619 game_status = GAME_MODE_SCORES;
624 if (leveldir_current->readonly &&
625 !strEqual(setup.player_name, "Artsoft"))
626 Request("This level is read only !", REQ_CONFIRM);
627 game_status = GAME_MODE_EDITOR;
632 game_status = GAME_MODE_INFO;
633 info_mode = INFO_MODE_MAIN;
638 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
642 game_status = GAME_MODE_SETUP;
643 setup_mode = SETUP_MODE_MAIN;
649 SaveLevelSetup_LastSeries();
650 SaveLevelSetup_SeriesInfo();
652 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
653 game_status = GAME_MODE_QUIT;
658 if (game_status == GAME_MODE_MAIN)
660 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
666 /* ========================================================================= */
667 /* info screen functions */
668 /* ========================================================================= */
670 static struct TokenInfo *info_info;
671 static int num_info_info;
673 static void execInfoElements()
675 info_mode = INFO_MODE_ELEMENTS;
679 static void execInfoMusic()
681 info_mode = INFO_MODE_MUSIC;
685 static void execInfoCredits()
687 info_mode = INFO_MODE_CREDITS;
691 static void execInfoProgram()
693 info_mode = INFO_MODE_PROGRAM;
697 static void execInfoLevelSet()
699 info_mode = INFO_MODE_LEVELSET;
703 static void execExitInfo()
705 game_status = GAME_MODE_MAIN;
709 static struct TokenInfo info_info_main[] =
711 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
712 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
713 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
714 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
715 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
716 { TYPE_EMPTY, NULL, "" },
717 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
722 static void DrawInfoScreen_Main()
727 CloseDoor(DOOR_CLOSE_2);
732 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
734 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
737 info_info = info_info_main;
740 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
742 int xpos = MENU_SCREEN_START_XPOS;
743 int ypos = MENU_SCREEN_START_YPOS + i;
744 int font_nr = FONT_MENU_1;
746 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
748 if (info_info[i].type & TYPE_ENTER_MENU)
749 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
750 else if (info_info[i].type & TYPE_LEAVE_MENU)
751 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
752 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
753 initCursor(i, IMG_MENU_BUTTON);
764 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
767 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
769 static int choice_store[MAX_INFO_MODES];
770 int choice = choice_store[info_mode]; /* always starts with 0 */
774 if (button == MB_MENU_INITIALIZE)
776 /* advance to first valid menu entry */
777 while (choice < num_info_info &&
778 info_info[choice].type & TYPE_SKIP_ENTRY)
780 choice_store[info_mode] = choice;
782 drawCursor(choice, FC_RED);
785 else if (button == MB_MENU_LEAVE)
787 for (y = 0; y < num_info_info; y++)
789 if (info_info[y].type & TYPE_LEAVE_MENU)
791 void (*menu_callback_function)(void) = info_info[y].value;
793 menu_callback_function();
794 break; /* absolutely needed because function changes 'info_info'! */
801 if (mx || my) /* mouse input */
804 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
806 else if (dx || dy) /* keyboard input */
810 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
812 if (info_info[choice].type & menu_navigation_type ||
813 info_info[choice].type & TYPE_ENTER_SCREEN ||
814 info_info[choice].type & TYPE_BOOLEAN_STYLE)
815 button = MB_MENU_CHOICE;
820 /* jump to next non-empty menu entry (up or down) */
821 while (y > 0 && y < num_info_info - 1 &&
822 info_info[y].type & TYPE_SKIP_ENTRY)
826 if (IN_VIS_FIELD(x, y) &&
827 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
833 drawCursor(y, FC_RED);
834 drawCursor(choice, FC_BLUE);
835 choice = choice_store[info_mode] = y;
838 else if (!(info_info[y].type & TYPE_GHOSTED))
840 if (info_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
842 void (*menu_callback_function)(void) = info_info[choice].value;
844 menu_callback_function();
850 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
852 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
853 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
854 int xstart = mSX + 16;
855 int ystart = mSY + 64 + 2 * 32;
856 int ystep = TILEY + 4;
857 int element, action, direction;
865 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
866 infoscreen_step[i] = infoscreen_frame[i] = 0;
871 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
873 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
874 "Press any key or button for next page");
880 while (helpanim_info[j].element != HELPANIM_LIST_END)
882 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
887 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
896 j += infoscreen_step[i - start];
898 element = helpanim_info[j].element;
899 action = helpanim_info[j].action;
900 direction = helpanim_info[j].direction;
903 element = EL_UNKNOWN;
905 if (action != -1 && direction != -1)
906 graphic = el_act_dir2img(element, action, direction);
907 else if (action != -1)
908 graphic = el_act2img(element, action);
909 else if (direction != -1)
910 graphic = el_dir2img(element, direction);
912 graphic = el2img(element);
914 delay = helpanim_info[j++].delay;
919 if (infoscreen_frame[i - start] == 0)
922 infoscreen_frame[i - start] = delay - 1;
926 sync_frame = delay - infoscreen_frame[i - start];
927 infoscreen_frame[i - start]--;
930 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
932 if (!infoscreen_frame[i - start])
933 infoscreen_step[i - start] = 0;
937 if (!infoscreen_frame[i - start])
938 infoscreen_step[i - start]++;
939 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
945 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
947 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
948 graphic, sync_frame, USE_MASKING);
951 DrawInfoScreen_HelpText(element, action, direction, i - start);
956 redraw_mask |= REDRAW_FIELD;
961 static char *getHelpText(int element, int action, int direction)
963 char token[MAX_LINE_LEN];
965 strcpy(token, element_info[element].token_name);
968 strcat(token, element_action_info[action].suffix);
971 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
973 return getHashEntry(helptext_info, token);
976 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
978 int font_nr = FONT_LEVEL_NUMBER;
979 int font_width = getFontWidth(font_nr);
980 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
981 int sy = mSY + 65 + 2 * 32 + 1;
982 int ystep = TILEY + 4;
984 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
985 int max_lines_per_text = 2;
988 if (action != -1 && direction != -1) /* element.action.direction */
989 text = getHelpText(element, action, direction);
991 if (text == NULL && action != -1) /* element.action */
992 text = getHelpText(element, action, -1);
994 if (text == NULL && direction != -1) /* element.direction */
995 text = getHelpText(element, -1, direction);
997 if (text == NULL) /* base element */
998 text = getHelpText(element, -1, -1);
1000 if (text == NULL) /* not found */
1001 text = "No description available";
1003 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1004 sy += getFontHeight(font_nr) / 2;
1006 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1007 max_chars_per_line, max_lines_per_text);
1010 void DrawInfoScreen_Elements()
1012 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1017 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1023 void HandleInfoScreen_Elements(int button)
1025 static unsigned long info_delay = 0;
1026 static int num_anims;
1027 static int num_pages;
1029 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1030 int button_released = !button;
1033 if (button == MB_MENU_INITIALIZE)
1035 boolean new_element = TRUE;
1038 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1040 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1042 else if (new_element)
1045 new_element = FALSE;
1049 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1052 else if (button == MB_MENU_LEAVE)
1054 info_mode = INFO_MODE_MAIN;
1060 if (button_released || button == MB_MENU_INITIALIZE)
1062 if (button != MB_MENU_INITIALIZE)
1065 if (page >= num_pages)
1067 FadeSoundsAndMusic();
1069 info_mode = INFO_MODE_MAIN;
1075 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1079 if (DelayReached(&info_delay, GameFrameDelay))
1080 if (page < num_pages)
1081 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1083 PlayMenuSoundIfLoop();
1087 void DrawInfoScreen_Music()
1089 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1096 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1099 void HandleInfoScreen_Music(int button)
1101 static struct MusicFileInfo *list = NULL;
1102 int ystart = 150, dy = 30;
1103 int ybottom = SYSIZE - 20;
1104 int button_released = !button;
1106 if (button == MB_MENU_INITIALIZE)
1108 list = music_file_info;
1112 FadeSoundsAndMusic();
1117 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1119 DrawTextSCentered(ybottom, FONT_TEXT_4,
1120 "Press any key or button for info menu");
1125 else if (button == MB_MENU_LEAVE)
1127 info_mode = INFO_MODE_MAIN;
1133 if (button_released || button == MB_MENU_INITIALIZE)
1137 if (button != MB_MENU_INITIALIZE)
1143 info_mode = INFO_MODE_MAIN;
1149 FadeSoundsAndMusic();
1156 int sound = list->music;
1158 if (sound_info[sound].loop)
1159 PlaySoundLoop(sound);
1163 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1167 PlayMusic(list->music);
1169 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1172 if (!strEqual(list->title, UNKNOWN_NAME))
1174 if (!strEqual(list->title_header, UNKNOWN_NAME))
1175 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1177 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1180 if (!strEqual(list->artist, UNKNOWN_NAME))
1182 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1183 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1185 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1187 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1190 if (!strEqual(list->album, UNKNOWN_NAME))
1192 if (!strEqual(list->album_header, UNKNOWN_NAME))
1193 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1195 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1197 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1200 if (!strEqual(list->year, UNKNOWN_NAME))
1202 if (!strEqual(list->year_header, UNKNOWN_NAME))
1203 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1205 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1207 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1210 DrawTextSCentered(ybottom, FONT_TEXT_4,
1211 "Press any key or button for next page");
1214 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1215 PlaySoundLoop(list->music);
1218 void DrawInfoScreen_Credits()
1220 int ystart = 150, ystep = 30;
1221 int ybottom = SYSIZE - 20;
1223 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1225 FadeSoundsAndMusic();
1230 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1231 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2, "DOS port of the game:");
1232 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3, "Guido Schulz");
1233 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2, "Additional toons:");
1234 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3, "Karl Hörnell");
1235 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1236 "...and many thanks to all contributors");
1237 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2, "of new levels!");
1239 DrawTextSCentered(ybottom, FONT_TEXT_4,
1240 "Press any key or button for info menu");
1243 void HandleInfoScreen_Credits(int button)
1245 int button_released = !button;
1247 if (button == MB_MENU_LEAVE)
1249 info_mode = INFO_MODE_MAIN;
1255 if (button_released)
1257 FadeSoundsAndMusic();
1259 info_mode = INFO_MODE_MAIN;
1264 PlayMenuSoundIfLoop();
1268 void DrawInfoScreen_Program()
1270 int ystart = 150, ystep = 30;
1271 int ybottom = SYSIZE - 20;
1273 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1278 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1280 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1281 "This game is Freeware!");
1282 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1283 "If you like it, send e-mail to:");
1284 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1285 "info@artsoft.org");
1286 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1287 "or SnailMail to:");
1288 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1290 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1291 "Detmolder Strasse 189");
1292 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1294 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1297 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1298 "If you have created new levels,");
1299 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1300 "send them to me to include them!");
1301 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1304 DrawTextSCentered(ybottom, FONT_TEXT_4,
1305 "Press any key or button for info menu");
1308 void HandleInfoScreen_Program(int button)
1310 int button_released = !button;
1312 if (button == MB_MENU_LEAVE)
1314 info_mode = INFO_MODE_MAIN;
1320 if (button_released)
1322 FadeSoundsAndMusic();
1324 info_mode = INFO_MODE_MAIN;
1329 PlayMenuSoundIfLoop();
1333 void DrawInfoScreen_LevelSet()
1336 int ybottom = SYSIZE - 20;
1337 char *filename = getLevelSetInfoFilename();
1338 int font_nr = FONT_LEVEL_NUMBER;
1339 int font_width = getFontWidth(font_nr);
1340 int font_height = getFontHeight(font_nr);
1343 int sx = SX + pad_x;
1344 int sy = SY + pad_y;
1345 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1346 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1348 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1353 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1355 DrawTextSCentered(ybottom, FONT_TEXT_4,
1356 "Press any key or button for info menu");
1358 if (filename != NULL)
1359 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1360 max_lines_per_screen);
1362 DrawTextSCentered(ystart, FONT_TEXT_2,
1363 "No information for this level set.");
1366 void HandleInfoScreen_LevelSet(int button)
1368 int button_released = !button;
1370 if (button == MB_MENU_LEAVE)
1372 info_mode = INFO_MODE_MAIN;
1378 if (button_released)
1380 FadeSoundsAndMusic();
1382 info_mode = INFO_MODE_MAIN;
1387 PlayMenuSoundIfLoop();
1391 void DrawInfoScreen()
1393 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1395 if (info_mode == INFO_MODE_ELEMENTS)
1396 DrawInfoScreen_Elements();
1397 else if (info_mode == INFO_MODE_MUSIC)
1398 DrawInfoScreen_Music();
1399 else if (info_mode == INFO_MODE_CREDITS)
1400 DrawInfoScreen_Credits();
1401 else if (info_mode == INFO_MODE_PROGRAM)
1402 DrawInfoScreen_Program();
1403 else if (info_mode == INFO_MODE_LEVELSET)
1404 DrawInfoScreen_LevelSet();
1406 DrawInfoScreen_Main();
1408 if (info_mode != INFO_MODE_MUSIC)
1415 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1417 if (info_mode == INFO_MODE_ELEMENTS)
1418 HandleInfoScreen_Elements(button);
1419 else if (info_mode == INFO_MODE_MUSIC)
1420 HandleInfoScreen_Music(button);
1421 else if (info_mode == INFO_MODE_CREDITS)
1422 HandleInfoScreen_Credits(button);
1423 else if (info_mode == INFO_MODE_PROGRAM)
1424 HandleInfoScreen_Program(button);
1425 else if (info_mode == INFO_MODE_LEVELSET)
1426 HandleInfoScreen_LevelSet(button);
1428 HandleInfoScreen_Main(mx, my, dx, dy, button);
1434 /* ========================================================================= */
1435 /* type name functions */
1436 /* ========================================================================= */
1438 void HandleTypeName(int newxpos, Key key)
1440 static int xpos = 0, ypos = 2;
1441 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1442 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1443 int startx = mSX + 32 + name_width;
1444 int starty = mSY + ypos * 32;
1450 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1451 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1456 if (((key >= KSYM_A && key <= KSYM_Z) ||
1457 (key >= KSYM_a && key <= KSYM_z)) &&
1458 xpos < MAX_PLAYER_NAME_LEN)
1462 if (key >= KSYM_A && key <= KSYM_Z)
1463 ascii = 'A' + (char)(key - KSYM_A);
1465 ascii = 'a' + (char)(key - KSYM_a);
1467 setup.player_name[xpos] = ascii;
1468 setup.player_name[xpos + 1] = 0;
1471 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1472 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1474 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1477 setup.player_name[xpos] = 0;
1479 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1481 else if (key == KSYM_Return && xpos > 0)
1483 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1484 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1487 game_status = GAME_MODE_MAIN;
1492 /* ========================================================================= */
1493 /* tree menu functions */
1494 /* ========================================================================= */
1496 static void DrawChooseTree(TreeInfo **ti_ptr)
1500 FreeScreenGadgets();
1501 CreateScreenGadgets();
1503 CloseDoor(DOOR_CLOSE_2);
1507 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1508 MapChooseTreeGadgets(*ti_ptr);
1514 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1516 struct GadgetInfo *gi = screen_gadget[id];
1517 int items_max, items_visible, item_position;
1519 items_max = numTreeInfoInGroup(ti);
1520 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
1521 item_position = first_entry;
1523 if (item_position > items_max - items_visible)
1524 item_position = items_max - items_visible;
1526 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1527 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1528 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1531 static void drawChooseTreeList(int first_entry, int num_page_entries,
1535 char *title_string = NULL;
1537 int xoffset_sets = 16;
1539 int yoffset_sets = MENU_TITLE1_YPOS;
1541 int xoffset_setup = 16;
1543 int yoffset_setup = 16;
1546 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
1549 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
1552 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
1553 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
1555 int last_game_status = game_status; /* save current game status */
1558 (ti->type == TREE_TYPE_LEVEL_DIR ? "Level Sets" :
1559 ti->type == TREE_TYPE_GRAPHICS_DIR ? "Custom Graphics" :
1560 ti->type == TREE_TYPE_SOUNDS_DIR ? "Custom Sounds" :
1561 ti->type == TREE_TYPE_MUSIC_DIR ? "Custom Music" : "");
1564 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
1566 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
1569 /* force LEVELS font on artwork setup screen */
1570 game_status = GAME_MODE_LEVELS;
1572 /* clear tree list area, but not title or scrollbar */
1573 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1574 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
1575 MAX_MENU_ENTRIES_ON_SCREEN * 32);
1577 for (i = 0; i < num_page_entries; i++)
1579 TreeInfo *node, *node_first;
1580 int entry_pos = first_entry + i;
1581 int xpos = MENU_SCREEN_START_XPOS;
1582 int ypos = MENU_SCREEN_START_YPOS + i;
1583 int startx = mSX + xpos * 32;
1584 int starty = mSY + ypos * 32;
1585 int font_nr = FONT_TEXT_1;
1586 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
1587 int startx_text = startx + font_xoffset;
1588 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1589 int text_size = startx_scrollbar - startx_text;
1590 int max_buffer_len = text_size / getFontWidth(font_nr);
1591 char buffer[max_buffer_len + 1];
1593 node_first = getTreeInfoFirstGroupEntry(ti);
1594 node = getTreeInfoFromPos(node_first, entry_pos);
1596 strncpy(buffer, node->name, max_buffer_len);
1597 buffer[max_buffer_len] = '\0';
1599 DrawText(startx, starty, buffer, font_nr + node->color);
1601 if (node->parent_link)
1602 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1603 else if (node->level_group)
1604 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1606 initCursor(i, IMG_MENU_BUTTON);
1609 game_status = last_game_status; /* restore current game status */
1611 redraw_mask |= REDRAW_FIELD;
1614 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
1616 TreeInfo *node, *node_first;
1617 int x, last_redraw_mask = redraw_mask;
1619 int ypos = MENU_TITLE2_YPOS;
1624 if (ti->type != TREE_TYPE_LEVEL_DIR)
1627 node_first = getTreeInfoFirstGroupEntry(ti);
1628 node = getTreeInfoFromPos(node_first, entry_pos);
1630 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
1632 if (node->parent_link)
1633 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
1635 else if (node->level_group)
1636 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
1638 else if (ti->type == TREE_TYPE_LEVEL_DIR)
1639 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
1640 node->levels, node->class_desc);
1642 /* let BackToFront() redraw only what is needed */
1643 redraw_mask = last_redraw_mask | REDRAW_TILES;
1644 for (x = 0; x < SCR_FIELDX; x++)
1645 MarkTileDirty(x, 1);
1648 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
1651 TreeInfo *ti = *ti_ptr;
1653 int y = ti->cl_cursor;
1654 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1655 int num_entries = numTreeInfoInGroup(ti);
1656 int num_page_entries;
1657 int last_game_status = game_status; /* save current game status */
1658 boolean position_set_by_scrollbar = (dx == 999);
1660 /* force LEVELS draw offset on choose level and artwork setup screen */
1661 game_status = GAME_MODE_LEVELS;
1663 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
1664 num_page_entries = num_entries;
1666 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1668 game_status = last_game_status; /* restore current game status */
1670 if (button == MB_MENU_INITIALIZE)
1672 int num_entries = numTreeInfoInGroup(ti);
1673 int entry_pos = posTreeInfo(ti);
1675 if (ti->cl_first == -1)
1677 /* only on initialization */
1678 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1679 ti->cl_cursor = entry_pos - ti->cl_first;
1681 else if (ti->cl_cursor >= num_page_entries ||
1682 (num_entries > num_page_entries &&
1683 num_entries - ti->cl_first < num_page_entries))
1685 /* only after change of list size (by custom graphic configuration) */
1686 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
1687 ti->cl_cursor = entry_pos - ti->cl_first;
1690 if (position_set_by_scrollbar)
1693 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1696 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1697 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1698 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1702 else if (button == MB_MENU_LEAVE)
1704 if (ti->node_parent)
1706 *ti_ptr = ti->node_parent;
1707 DrawChooseTree(ti_ptr);
1709 else if (game_status == GAME_MODE_SETUP)
1715 game_status = GAME_MODE_MAIN;
1722 if (mx || my) /* mouse input */
1724 int last_game_status = game_status; /* save current game status */
1726 /* force LEVELS draw offset on artwork setup screen */
1727 game_status = GAME_MODE_LEVELS;
1729 x = (mx - mSX) / 32;
1730 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1732 game_status = last_game_status; /* restore current game status */
1734 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
1736 /* move cursor instead of scrolling when already at start/end of list */
1737 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
1739 else if (dy == +1 * SCROLL_LINE &&
1740 ti->cl_first + num_page_entries == num_entries)
1743 /* handle scrolling screen one line or page */
1744 if (ti->cl_cursor + dy < 0 ||
1745 ti->cl_cursor + dy > num_page_entries - 1)
1747 if (ABS(dy) == SCROLL_PAGE)
1748 step = num_page_entries - 1;
1750 if (dy < 0 && ti->cl_first > 0)
1752 /* scroll page/line up */
1754 ti->cl_first -= step;
1755 if (ti->cl_first < 0)
1758 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1759 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1760 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1761 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1764 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
1766 /* scroll page/line down */
1768 ti->cl_first += step;
1769 if (ti->cl_first + num_page_entries > num_entries)
1770 ti->cl_first = MAX(0, num_entries - num_page_entries);
1772 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
1773 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
1774 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
1775 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
1782 /* handle moving cursor one line */
1783 y = ti->cl_cursor + dy;
1788 TreeInfo *node_first, *node_cursor;
1789 int entry_pos = ti->cl_first + y;
1791 node_first = getTreeInfoFirstGroupEntry(ti);
1792 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1794 if (node_cursor->node_group)
1796 node_cursor->cl_first = ti->cl_first;
1797 node_cursor->cl_cursor = ti->cl_cursor;
1798 *ti_ptr = node_cursor->node_group;
1799 DrawChooseTree(ti_ptr);
1804 else if (dx == -1 && ti->node_parent)
1806 *ti_ptr = ti->node_parent;
1807 DrawChooseTree(ti_ptr);
1812 if (!anyScrollbarGadgetActive() &&
1813 IN_VIS_FIELD(x, y) &&
1814 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
1815 y >= 0 && y < num_page_entries)
1819 if (y != ti->cl_cursor)
1821 drawChooseTreeCursor(y, FC_RED);
1822 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
1823 drawChooseTreeInfo(ti->cl_first + y, ti);
1829 TreeInfo *node_first, *node_cursor;
1830 int entry_pos = ti->cl_first + y;
1832 node_first = getTreeInfoFirstGroupEntry(ti);
1833 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
1835 if (node_cursor->node_group)
1837 node_cursor->cl_first = ti->cl_first;
1838 node_cursor->cl_cursor = ti->cl_cursor;
1839 *ti_ptr = node_cursor->node_group;
1840 DrawChooseTree(ti_ptr);
1842 else if (node_cursor->parent_link)
1844 *ti_ptr = node_cursor->node_parent;
1845 DrawChooseTree(ti_ptr);
1849 node_cursor->cl_first = ti->cl_first;
1850 node_cursor->cl_cursor = ti->cl_cursor;
1851 *ti_ptr = node_cursor;
1853 if (ti->type == TREE_TYPE_LEVEL_DIR)
1855 LoadLevelSetup_SeriesInfo();
1857 SaveLevelSetup_LastSeries();
1858 SaveLevelSetup_SeriesInfo();
1862 if (game_status == GAME_MODE_SETUP)
1868 game_status = GAME_MODE_MAIN;
1876 void DrawChooseLevel()
1878 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
1880 DrawChooseTree(&leveldir_current);
1886 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
1888 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
1893 void DrawHallOfFame(int highlight_position)
1896 FadeSoundsAndMusic();
1897 CloseDoor(DOOR_CLOSE_2);
1899 if (highlight_position < 0)
1900 LoadScore(level_nr);
1908 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
1911 static void drawHallOfFameList(int first_entry, int highlight_position)
1915 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
1919 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
1920 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1921 "HighScores of Level %d", level_nr);
1923 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
1924 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1925 "HighScores of Level %d", level_nr);
1928 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1930 int entry = first_entry + i;
1931 boolean active = (entry == highlight_position);
1932 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
1933 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
1934 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
1935 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
1936 int dx1 = 3 * getFontWidth(font_nr1);
1937 int dx2 = dx1 + getFontWidth(font_nr1);
1938 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
1939 int sy = mSY + 64 + i * 32;
1941 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
1942 DrawText(mSX + dx1, sy, ".", font_nr1);
1943 DrawText(mSX + dx2, sy, ".........................", font_nr3);
1945 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
1946 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
1948 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
1951 redraw_mask |= REDRAW_FIELD;
1954 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1956 static int first_entry = 0;
1957 static int highlight_position = 0;
1958 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1959 int button_released = !button;
1961 if (button == MB_MENU_INITIALIZE)
1964 highlight_position = mx;
1965 drawHallOfFameList(first_entry, highlight_position);
1970 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
1971 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
1975 if (first_entry > 0)
1977 first_entry -= step;
1978 if (first_entry < 0)
1981 drawHallOfFameList(first_entry, highlight_position);
1986 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1988 first_entry += step;
1989 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1990 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
1992 drawHallOfFameList(first_entry, highlight_position);
1995 else if (button_released)
1997 FadeSound(SND_BACKGROUND_SCORES);
1998 game_status = GAME_MODE_MAIN;
2002 if (game_status == GAME_MODE_SCORES)
2003 PlayMenuSoundIfLoop();
2009 /* ========================================================================= */
2010 /* setup screen functions */
2011 /* ========================================================================= */
2013 static struct TokenInfo *setup_info;
2014 static int num_setup_info;
2016 static char *graphics_set_name;
2017 static char *sounds_set_name;
2018 static char *music_set_name;
2020 static void execSetupMain()
2022 setup_mode = SETUP_MODE_MAIN;
2026 static void execSetupGame()
2028 setup_mode = SETUP_MODE_GAME;
2032 static void execSetupEditor()
2034 setup_mode = SETUP_MODE_EDITOR;
2038 static void execSetupGraphics()
2040 setup_mode = SETUP_MODE_GRAPHICS;
2044 static void execSetupSound()
2046 setup_mode = SETUP_MODE_SOUND;
2050 static void execSetupArtwork()
2052 setup.graphics_set = artwork.gfx_current->identifier;
2053 setup.sounds_set = artwork.snd_current->identifier;
2054 setup.music_set = artwork.mus_current->identifier;
2056 /* needed if last screen (setup choice) changed graphics, sounds or music */
2057 ReloadCustomArtwork(0);
2059 /* needed for displaying artwork name instead of artwork identifier */
2060 graphics_set_name = artwork.gfx_current->name;
2061 sounds_set_name = artwork.snd_current->name;
2062 music_set_name = artwork.mus_current->name;
2064 setup_mode = SETUP_MODE_ARTWORK;
2068 static void execSetupChooseGraphics()
2070 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2074 static void execSetupChooseSounds()
2076 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2080 static void execSetupChooseMusic()
2082 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2086 static void execSetupInput()
2088 setup_mode = SETUP_MODE_INPUT;
2092 static void execSetupShortcut1()
2094 setup_mode = SETUP_MODE_SHORTCUT_1;
2098 static void execSetupShortcut2()
2100 setup_mode = SETUP_MODE_SHORTCUT_2;
2104 static void execExitSetup()
2106 game_status = GAME_MODE_MAIN;
2110 static void execSaveAndExitSetup()
2116 static struct TokenInfo setup_info_main[] =
2118 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2119 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2120 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2121 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2122 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2123 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2124 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2125 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2126 { TYPE_EMPTY, NULL, "" },
2127 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2128 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2133 static struct TokenInfo setup_info_game[] =
2135 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2136 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2137 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2138 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2139 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2140 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2141 { TYPE_EMPTY, NULL, "" },
2142 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2147 static struct TokenInfo setup_info_editor[] =
2149 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2150 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2151 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2152 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2153 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2154 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2155 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2156 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2157 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2158 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2159 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2160 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2161 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2162 { TYPE_EMPTY, NULL, "" },
2163 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2168 static struct TokenInfo setup_info_graphics[] =
2170 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen Mode:" },
2171 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2173 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2174 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2175 { TYPE_SWITCH, &setup.fading, "Fading:" },
2177 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2178 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2179 { TYPE_SWITCH, &setup.toons, "Toons:" },
2180 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2181 { TYPE_EMPTY, NULL, "" },
2182 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2187 static struct TokenInfo setup_info_sound[] =
2189 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2190 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2191 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2192 { TYPE_EMPTY, NULL, "" },
2193 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2198 static struct TokenInfo setup_info_artwork[] =
2200 { TYPE_ENTER_MENU, execSetupChooseGraphics,"Custom Graphics" },
2201 { TYPE_STRING, &graphics_set_name, "" },
2202 { TYPE_ENTER_MENU, execSetupChooseSounds, "Custom Sounds" },
2203 { TYPE_STRING, &sounds_set_name, "" },
2204 { TYPE_ENTER_MENU, execSetupChooseMusic, "Custom Music" },
2205 { TYPE_STRING, &music_set_name, "" },
2206 { TYPE_EMPTY, NULL, "" },
2208 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2209 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2210 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2212 { TYPE_STRING, NULL, "Override Level Artwork:"},
2213 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2214 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2215 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2217 { TYPE_EMPTY, NULL, "" },
2218 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2223 static struct TokenInfo setup_info_shortcut_1[] =
2225 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2226 { TYPE_KEY, &setup.shortcut.save_game, "" },
2227 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2228 { TYPE_KEY, &setup.shortcut.load_game, "" },
2229 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2230 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2231 { TYPE_EMPTY, NULL, "" },
2232 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2233 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2234 { TYPE_EMPTY, NULL, "" },
2235 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2240 static struct TokenInfo setup_info_shortcut_2[] =
2242 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2243 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2244 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2245 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2246 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2247 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2248 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2249 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2250 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2251 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2252 { TYPE_EMPTY, NULL, "" },
2253 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2258 static Key getSetupKey()
2260 Key key = KSYM_UNDEFINED;
2261 boolean got_key_event = FALSE;
2263 while (!got_key_event)
2265 if (PendingEvent()) /* got event */
2273 case EVENT_KEYPRESS:
2275 key = GetEventKey((KeyEvent *)&event, TRUE);
2277 /* press 'Escape' or 'Enter' to keep the existing key binding */
2278 if (key == KSYM_Escape || key == KSYM_Return)
2279 key = KSYM_UNDEFINED; /* keep old value */
2281 got_key_event = TRUE;
2285 case EVENT_KEYRELEASE:
2286 key_joystick_mapping = 0;
2290 HandleOtherEvents(&event);
2298 /* don't eat all CPU time */
2305 static int getSetupTextFont(int type)
2307 if (type & (TYPE_SWITCH |
2317 static int getSetupValueFont(int type, void *value)
2319 if (type & TYPE_KEY)
2320 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2321 else if (type & TYPE_STRING)
2322 return FONT_VALUE_2;
2323 else if (type & TYPE_ECS_AGA)
2324 return FONT_VALUE_1;
2325 else if (type & TYPE_BOOLEAN_STYLE)
2326 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2328 return FONT_VALUE_1;
2331 static void drawSetupValue(int pos)
2333 boolean font_draw_xoffset_modified = FALSE;
2334 int font_draw_xoffset_old = -1;
2335 int xpos = MENU_SCREEN_VALUE_XPOS;
2336 int ypos = MENU_SCREEN_START_YPOS + pos;
2337 int startx = mSX + xpos * 32;
2338 int starty = mSY + ypos * 32;
2339 int font_nr, font_width;
2340 int type = setup_info[pos].type;
2341 void *value = setup_info[pos].value;
2342 char *value_string = getSetupValue(type, value);
2345 if (value_string == NULL)
2348 if (type & TYPE_KEY)
2351 xpos = MENU_SCREEN_START_XPOS;
2356 if (type & TYPE_QUERY)
2358 value_string = "<press key>";
2360 font_nr = FONT_INPUT_1_ACTIVE;
2364 else if (type & TYPE_STRING)
2366 int max_value_len = (SCR_FIELDX - 2) * 2;
2368 xpos = MENU_SCREEN_START_XPOS;
2370 font_nr = FONT_VALUE_2;
2373 if (strlen(value_string) > max_value_len)
2374 value_string[max_value_len] = '\0';
2376 else if (type & TYPE_ECS_AGA)
2379 font_nr = FONT_VALUE_1;
2382 else if (type & TYPE_BOOLEAN_STYLE)
2385 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2389 startx = mSX + xpos * 32;
2390 starty = mSY + ypos * 32;
2391 font_nr = getSetupValueFont(type, value);
2392 font_width = getFontWidth(font_nr);
2394 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2395 if (setup_mode != SETUP_MODE_INPUT)
2397 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
2398 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2399 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
2400 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
2401 int text_font_nr = getSetupTextFont(FONT_MENU_2);
2402 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
2403 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
2404 boolean correct_font_draw_xoffset = FALSE;
2406 if (xpos == MENU_SCREEN_START_XPOS &&
2407 startx + font1_xoffset < text_startx + text_font_xoffset)
2408 correct_font_draw_xoffset = TRUE;
2410 if (xpos == MENU_SCREEN_VALUE_XPOS &&
2411 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
2412 correct_font_draw_xoffset = TRUE;
2415 printf("::: %d + %d < %d + %d + %d\n",
2416 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
2417 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
2420 /* check if setup value would overlap with setup text when printed */
2421 /* (this can happen for extreme/wrong values for font draw offset) */
2422 if (correct_font_draw_xoffset)
2424 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
2425 font_draw_xoffset_modified = TRUE;
2427 if (type & TYPE_KEY)
2428 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
2429 else if (!(type & TYPE_STRING))
2430 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
2431 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
2436 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
2437 DrawText(startx + i * font_width, starty, " ", font_nr);
2440 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
2441 DrawText(mSX + i * 32, starty, " ", font_nr);
2443 DrawText(startx, starty,
2444 (xpos == 3 ? " " : " "), font_nr);
2448 DrawText(startx, starty, value_string, font_nr);
2450 if (font_draw_xoffset_modified)
2451 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
2454 static void changeSetupValue(int pos)
2456 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
2458 *(boolean *)setup_info[pos].value ^= TRUE;
2460 else if (setup_info[pos].type & TYPE_KEY)
2464 setup_info[pos].type |= TYPE_QUERY;
2465 drawSetupValue(pos);
2466 setup_info[pos].type &= ~TYPE_QUERY;
2468 key = getSetupKey();
2469 if (key != KSYM_UNDEFINED)
2470 *(Key *)setup_info[pos].value = key;
2473 drawSetupValue(pos);
2476 static void DrawSetupScreen_Generic()
2478 char *title_string = NULL;
2482 CloseDoor(DOOR_CLOSE_2);
2486 if (setup_mode == SETUP_MODE_MAIN)
2488 setup_info = setup_info_main;
2489 title_string = "Setup";
2491 else if (setup_mode == SETUP_MODE_GAME)
2493 setup_info = setup_info_game;
2494 title_string = "Setup Game";
2496 else if (setup_mode == SETUP_MODE_EDITOR)
2498 setup_info = setup_info_editor;
2499 title_string = "Setup Editor";
2501 else if (setup_mode == SETUP_MODE_GRAPHICS)
2503 setup_info = setup_info_graphics;
2504 title_string = "Setup Graphics";
2506 else if (setup_mode == SETUP_MODE_SOUND)
2508 setup_info = setup_info_sound;
2509 title_string = "Setup Sound";
2511 else if (setup_mode == SETUP_MODE_ARTWORK)
2513 setup_info = setup_info_artwork;
2514 title_string = "Custom Artwork";
2516 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
2518 setup_info = setup_info_shortcut_1;
2519 title_string = "Setup Shortcuts";
2521 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
2523 setup_info = setup_info_shortcut_2;
2524 title_string = "Setup Shortcuts";
2528 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
2530 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
2534 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2536 void *value_ptr = setup_info[i].value;
2537 int xpos = MENU_SCREEN_START_XPOS;
2538 int ypos = MENU_SCREEN_START_YPOS + i;
2542 int font_nr = FONT_MENU_1;
2545 /* set some entries to "unchangeable" according to other variables */
2546 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2547 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2548 (value_ptr == &setup.sound_music && !audio.music_available) ||
2549 (value_ptr == &setup.fullscreen && !video.fullscreen_available))
2550 setup_info[i].type |= TYPE_GHOSTED;
2553 font_nr = getSetupTextFont(setup_info[i].type);
2556 if (setup_info[i].type & (TYPE_SWITCH |
2561 font_nr = FONT_MENU_2;
2563 if (setup_info[i].type & TYPE_STRING)
2564 font_nr = FONT_MENU_2;
2568 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
2570 if (setup_info[i].type & TYPE_ENTER_MENU)
2571 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2572 else if (setup_info[i].type & TYPE_LEAVE_MENU)
2573 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2574 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
2575 initCursor(i, IMG_MENU_BUTTON);
2577 if (setup_info[i].type & TYPE_VALUE)
2584 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2585 "Joysticks deactivated in setup menu");
2590 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
2593 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
2595 static int choice_store[MAX_SETUP_MODES];
2596 int choice = choice_store[setup_mode]; /* always starts with 0 */
2600 if (button == MB_MENU_INITIALIZE)
2602 /* advance to first valid menu entry */
2603 while (choice < num_setup_info &&
2604 setup_info[choice].type & TYPE_SKIP_ENTRY)
2606 choice_store[setup_mode] = choice;
2608 drawCursor(choice, FC_RED);
2611 else if (button == MB_MENU_LEAVE)
2613 for (y = 0; y < num_setup_info; y++)
2615 if (setup_info[y].type & TYPE_LEAVE_MENU)
2617 void (*menu_callback_function)(void) = setup_info[y].value;
2619 menu_callback_function();
2620 break; /* absolutely needed because function changes 'setup_info'! */
2627 if (mx || my) /* mouse input */
2629 x = (mx - mSX) / 32;
2630 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2632 else if (dx || dy) /* keyboard input */
2636 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
2638 if (setup_info[choice].type & menu_navigation_type ||
2639 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
2640 button = MB_MENU_CHOICE;
2645 /* jump to next non-empty menu entry (up or down) */
2646 while (y > 0 && y < num_setup_info - 1 &&
2647 setup_info[y].type & TYPE_SKIP_ENTRY)
2651 if (IN_VIS_FIELD(x, y) &&
2652 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
2658 drawCursor(y, FC_RED);
2659 drawCursor(choice, FC_BLUE);
2660 choice = choice_store[setup_mode] = y;
2663 else if (!(setup_info[y].type & TYPE_GHOSTED))
2665 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE_MENU)
2667 void (*menu_callback_function)(void) = setup_info[choice].value;
2669 menu_callback_function();
2673 if (setup_info[y].type & TYPE_KEYTEXT &&
2674 setup_info[y + 1].type & TYPE_KEY)
2677 if (setup_info[y].type & TYPE_VALUE)
2678 changeSetupValue(y);
2684 void DrawSetupScreen_Input()
2689 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
2691 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
2694 initCursor(0, IMG_MENU_BUTTON);
2695 initCursor(1, IMG_MENU_BUTTON);
2696 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
2697 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
2699 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
2700 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
2702 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
2703 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
2704 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
2707 DeactivateJoystickForCalibration();
2710 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
2711 "Joysticks deactivated on this screen");
2714 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
2719 static void setJoystickDeviceToNr(char *device_name, int device_nr)
2721 if (device_name == NULL)
2724 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
2727 if (strlen(device_name) > 1)
2729 char c1 = device_name[strlen(device_name) - 1];
2730 char c2 = device_name[strlen(device_name) - 2];
2732 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
2733 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
2736 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
2737 strlen(device_name));
2740 static void drawPlayerSetupInputInfo(int player_nr)
2743 static struct SetupKeyboardInfo custom_key;
2750 { &custom_key.left, "Joystick Left" },
2751 { &custom_key.right, "Joystick Right" },
2752 { &custom_key.up, "Joystick Up" },
2753 { &custom_key.down, "Joystick Down" },
2754 { &custom_key.snap, "Button 1" },
2755 { &custom_key.drop, "Button 2" }
2757 static char *joystick_name[MAX_PLAYERS] =
2767 custom_key = setup.input[player_nr].key;
2769 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
2770 FONT_INPUT_1_ACTIVE);
2772 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2774 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
2775 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
2777 if (setup.input[player_nr].use_joystick)
2779 char *device_name = setup.input[player_nr].joy.device_name;
2780 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
2781 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
2783 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
2784 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
2788 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
2789 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
2792 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
2793 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
2794 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
2795 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
2796 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
2797 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
2798 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
2799 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
2800 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
2801 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
2802 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
2804 for (i = 0; i < 6; i++)
2806 int ypos = 6 + i + (i > 3 ? i-3 : 0);
2808 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2810 DrawText(mSX + 3 * 32, mSY + ypos * 32,
2811 (setup.input[player_nr].use_joystick ?
2813 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
2817 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
2819 static int choice = 0;
2820 static int player_nr = 0;
2823 int pos_start = SETUPINPUT_SCREEN_POS_START;
2824 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
2825 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
2826 int pos_end = SETUPINPUT_SCREEN_POS_END;
2828 if (button == MB_MENU_INITIALIZE)
2830 drawPlayerSetupInputInfo(player_nr);
2831 drawCursor(choice, FC_RED);
2835 else if (button == MB_MENU_LEAVE)
2837 setup_mode = SETUP_MODE_MAIN;
2844 if (mx || my) /* mouse input */
2846 x = (mx - mSX) / 32;
2847 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2849 else if (dx || dy) /* keyboard input */
2851 if (dx && choice == 0)
2852 x = (dx < 0 ? 10 : 12);
2853 else if ((dx && choice == 1) ||
2854 (dx == +1 && choice == 2) ||
2855 (dx == -1 && choice == pos_end))
2856 button = MB_MENU_CHOICE;
2860 if (y >= pos_empty1 && y <= pos_empty2)
2861 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
2864 if (IN_VIS_FIELD(x, y) &&
2865 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
2867 static unsigned long delay = 0;
2869 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
2872 player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
2874 drawPlayerSetupInputInfo(player_nr);
2876 else if (IN_VIS_FIELD(x, y) &&
2877 y >= pos_start && y <= pos_end &&
2878 !(y >= pos_empty1 && y <= pos_empty2))
2884 drawCursor(y, FC_RED);
2885 drawCursor(choice, FC_BLUE);
2893 char *device_name = setup.input[player_nr].joy.device_name;
2895 if (!setup.input[player_nr].use_joystick)
2897 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
2899 setJoystickDeviceToNr(device_name, new_device_nr);
2900 setup.input[player_nr].use_joystick = TRUE;
2904 int device_nr = getJoystickNrFromDeviceName(device_name);
2905 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
2907 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
2908 setup.input[player_nr].use_joystick = FALSE;
2910 setJoystickDeviceToNr(device_name, new_device_nr);
2913 drawPlayerSetupInputInfo(player_nr);
2917 if (setup.input[player_nr].use_joystick)
2920 CalibrateJoystick(player_nr);
2923 CustomizeKeyboard(player_nr);
2925 else if (y == pos_end)
2929 setup_mode = SETUP_MODE_MAIN;
2936 void CustomizeKeyboard(int player_nr)
2940 boolean finished = FALSE;
2941 static struct SetupKeyboardInfo custom_key;
2946 } customize_step[] =
2948 { &custom_key.left, "Move Left" },
2949 { &custom_key.right, "Move Right" },
2950 { &custom_key.up, "Move Up" },
2951 { &custom_key.down, "Move Down" },
2952 { &custom_key.snap, "Snap Field" },
2953 { &custom_key.drop, "Drop Element" }
2956 /* read existing key bindings from player setup */
2957 custom_key = setup.input[player_nr].key;
2962 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
2964 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
2971 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
2972 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
2973 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
2974 "Key:", FONT_INPUT_1_ACTIVE);
2975 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
2976 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
2980 if (PendingEvent()) /* got event */
2988 case EVENT_KEYPRESS:
2990 Key key = GetEventKey((KeyEvent *)&event, FALSE);
2992 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
2998 /* all keys configured -- wait for "Escape" or "Return" key */
3002 /* press 'Enter' to keep the existing key binding */
3003 if (key == KSYM_Return)
3004 key = *customize_step[step_nr].key;
3006 /* check if key already used */
3007 for (i = 0; i < step_nr; i++)
3008 if (*customize_step[i].key == key)
3013 /* got new key binding */
3014 *customize_step[step_nr].key = key;
3015 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3017 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3018 getKeyNameFromKey(key), FONT_VALUE_1);
3021 /* un-highlight last query */
3022 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3023 customize_step[step_nr - 1].text, FONT_MENU_1);
3024 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3025 "Key:", FONT_MENU_1);
3027 /* press 'Enter' to leave */
3030 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3031 "Press Enter", FONT_TITLE_1);
3035 /* query next key binding */
3036 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3037 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3038 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3039 "Key:", FONT_INPUT_1_ACTIVE);
3040 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3041 getKeyNameFromKey(*customize_step[step_nr].key),
3046 case EVENT_KEYRELEASE:
3047 key_joystick_mapping = 0;
3051 HandleOtherEvents(&event);
3059 /* don't eat all CPU time */
3063 /* write new key bindings back to player setup */
3064 setup.input[player_nr].key = custom_key;
3067 DrawSetupScreen_Input();
3070 static boolean CalibrateJoystickMain(int player_nr)
3072 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3073 int new_joystick_xright = JOYSTICK_XMIDDLE;
3074 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3075 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3076 int new_joystick_xmiddle, new_joystick_ymiddle;
3078 int joystick_fd = joystick.fd[player_nr];
3079 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3080 boolean check[3][3];
3081 int check_remaining = 3 * 3;
3086 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3089 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3094 for (y = 0; y < 3; y++)
3096 for (x = 0; x < 3; x++)
3098 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3099 check[x][y] = FALSE;
3103 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3104 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3105 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3106 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3107 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3108 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3109 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3111 joy_value = Joystick(player_nr);
3112 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3113 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3115 /* eventually uncalibrated center position (joystick could be uncentered) */
3116 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3119 new_joystick_xmiddle = joy_x;
3120 new_joystick_ymiddle = joy_y;
3122 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3125 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3130 if (PendingEvent()) /* got event */
3138 case EVENT_KEYPRESS:
3139 switch(GetEventKey((KeyEvent *)&event, TRUE))
3142 if (check_remaining == 0)
3155 case EVENT_KEYRELEASE:
3156 key_joystick_mapping = 0;
3160 HandleOtherEvents(&event);
3165 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3168 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3169 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3170 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3171 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3173 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3174 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3175 setup.input[player_nr].joy.xright = new_joystick_xright;
3176 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3177 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3178 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3180 CheckJoystickData();
3182 joy_value = Joystick(player_nr);
3184 if (joy_value & JOY_BUTTON && check_remaining == 0)
3187 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3188 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3190 if (x != last_x || y != last_y)
3192 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3193 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3198 if (check_remaining > 0 && !check[x+1][y+1])
3200 check[x+1][y+1] = TRUE;
3206 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3207 setup.input[player_nr].joy.xleft,
3208 setup.input[player_nr].joy.xmiddle,
3209 setup.input[player_nr].joy.xright);
3210 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3211 setup.input[player_nr].joy.yupper,
3212 setup.input[player_nr].joy.ymiddle,
3213 setup.input[player_nr].joy.ylower);
3222 /* don't eat all CPU time */
3226 /* calibrated center position (joystick should now be centered) */
3227 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3230 new_joystick_xmiddle = joy_x;
3231 new_joystick_ymiddle = joy_y;
3236 DrawSetupScreen_Input();
3239 /* wait until the last pressed button was released */
3240 while (Joystick(player_nr) & JOY_BUTTON)
3242 if (PendingEvent()) /* got event */
3247 HandleOtherEvents(&event);
3256 void CalibrateJoystick(int player_nr)
3258 if (!CalibrateJoystickMain(player_nr))
3260 char *device_name = setup.input[player_nr].joy.device_name;
3261 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3262 int xpos = mSX - SX;
3263 int ypos = mSY - SY;
3267 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3268 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3271 Delay(2000); /* show error message for a short time */
3277 DrawSetupScreen_Input();
3281 void DrawSetupScreen()
3283 DeactivateJoystick();
3285 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3287 if (setup_mode == SETUP_MODE_INPUT)
3288 DrawSetupScreen_Input();
3289 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3290 DrawChooseTree(&artwork.gfx_current);
3291 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3292 DrawChooseTree(&artwork.snd_current);
3293 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3294 DrawChooseTree(&artwork.mus_current);
3296 DrawSetupScreen_Generic();
3302 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3304 if (setup_mode == SETUP_MODE_INPUT)
3305 HandleSetupScreen_Input(mx, my, dx, dy, button);
3306 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3307 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3308 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3309 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3310 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3311 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3313 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3318 void HandleGameActions()
3320 if (game_status != GAME_MODE_PLAYING)
3323 GameActions(); /* main game loop */
3325 if (tape.auto_play && !tape.playing)
3326 AutoPlayTape(); /* continue automatically playing next tape */
3330 /* ---------- new screen button stuff -------------------------------------- */
3334 int gfx_unpressed, gfx_pressed;
3338 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
3341 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
3342 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
3343 SCREEN_CTRL_ID_SCROLL_UP,
3347 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
3348 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
3349 SCREEN_CTRL_ID_SCROLL_DOWN,
3356 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3357 Bitmap **gfx_unpressed, **gfx_pressed;
3359 int gfx_unpressed, gfx_pressed;
3366 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
3369 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3370 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
3372 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
3374 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
3375 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
3376 GD_TYPE_SCROLLBAR_VERTICAL,
3377 SCREEN_CTRL_ID_SCROLL_VERTICAL,
3378 "scroll level series vertically"
3382 static void CreateScreenScrollbuttons()
3384 struct GadgetInfo *gi;
3385 unsigned long event_mask;
3388 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
3390 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3391 int gfx_unpressed, gfx_pressed;
3392 int x, y, width, height;
3393 int gd_x1, gd_x2, gd_y1, gd_y2;
3394 int id = scrollbutton_info[i].gadget_id;
3396 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3398 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
3399 y = mSY + scrollbutton_info[i].y;
3400 width = SC_SCROLLBUTTON_XSIZE;
3401 height = SC_SCROLLBUTTON_YSIZE;
3403 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
3404 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
3405 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
3407 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
3408 gfx_pressed = scrollbutton_info[i].gfx_pressed;
3409 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3410 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3411 gd_x1 = graphic_info[gfx_unpressed].src_x;
3412 gd_y1 = graphic_info[gfx_unpressed].src_y;
3413 gd_x2 = graphic_info[gfx_pressed].src_x;
3414 gd_y2 = graphic_info[gfx_pressed].src_y;
3416 gi = CreateGadget(GDI_CUSTOM_ID, id,
3417 GDI_CUSTOM_TYPE_ID, i,
3418 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3423 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3424 GDI_STATE, GD_BUTTON_UNPRESSED,
3425 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3426 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3427 GDI_DIRECT_DRAW, FALSE,
3428 GDI_EVENT_MASK, event_mask,
3429 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3433 Error(ERR_EXIT, "cannot create gadget");
3435 screen_gadget[id] = gi;
3439 static void CreateScreenScrollbars()
3443 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
3445 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
3446 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3447 int gfx_unpressed, gfx_pressed;
3449 int x, y, width, height;
3450 int gd_x1, gd_x2, gd_y1, gd_y2;
3451 struct GadgetInfo *gi;
3452 int items_max, items_visible, item_position;
3453 unsigned long event_mask;
3454 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3455 int id = scrollbar_info[i].gadget_id;
3457 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3459 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
3460 y = mSY + scrollbar_info[i].y;
3461 width = scrollbar_info[i].width;
3462 height = scrollbar_info[i].height;
3464 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
3465 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
3467 items_max = num_page_entries;
3468 items_visible = num_page_entries;
3471 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3472 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
3473 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
3479 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
3480 gfx_pressed = scrollbar_info[i].gfx_pressed;
3481 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
3482 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
3483 gd_x1 = graphic_info[gfx_unpressed].src_x;
3484 gd_y1 = graphic_info[gfx_unpressed].src_y;
3485 gd_x2 = graphic_info[gfx_pressed].src_x;
3486 gd_y2 = graphic_info[gfx_pressed].src_y;
3489 gi = CreateGadget(GDI_CUSTOM_ID, id,
3490 GDI_CUSTOM_TYPE_ID, i,
3491 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3496 GDI_TYPE, scrollbar_info[i].type,
3497 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3498 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3499 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3500 GDI_STATE, GD_BUTTON_UNPRESSED,
3501 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
3502 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
3503 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
3504 GDI_DIRECT_DRAW, FALSE,
3505 GDI_EVENT_MASK, event_mask,
3506 GDI_CALLBACK_ACTION, HandleScreenGadgets,
3510 Error(ERR_EXIT, "cannot create gadget");
3512 screen_gadget[id] = gi;
3516 void CreateScreenGadgets()
3518 int last_game_status = game_status; /* save current game status */
3520 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3523 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3525 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
3527 /* copy pointers to clip mask and GC */
3528 scrollbar_bitmap[i]->clip_mask =
3529 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
3530 scrollbar_bitmap[i]->stored_clip_gc =
3531 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
3533 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
3534 scrollbar_bitmap[i],
3535 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
3536 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
3537 TILEX, TILEY, 0, 0);
3541 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
3542 game_status = GAME_MODE_LEVELS;
3544 CreateScreenScrollbuttons();
3545 CreateScreenScrollbars();
3547 game_status = last_game_status; /* restore current game status */
3550 void FreeScreenGadgets()
3554 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
3555 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
3557 /* prevent freeing clip mask and GC twice */
3558 scrollbar_bitmap[i]->clip_mask = None;
3559 scrollbar_bitmap[i]->stored_clip_gc = None;
3561 FreeBitmap(scrollbar_bitmap[i]);
3565 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3566 FreeGadget(screen_gadget[i]);
3569 void MapChooseTreeGadgets(TreeInfo *ti)
3571 int num_entries = numTreeInfoInGroup(ti);
3574 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3577 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3578 MapGadget(screen_gadget[i]);
3582 void UnmapChooseTreeGadgets()
3586 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
3587 UnmapGadget(screen_gadget[i]);
3591 static void HandleScreenGadgets(struct GadgetInfo *gi)
3593 int id = gi->custom_id;
3595 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
3600 case SCREEN_CTRL_ID_SCROLL_UP:
3601 if (game_status == GAME_MODE_LEVELS)
3602 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3603 else if (game_status == GAME_MODE_SETUP)
3604 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
3607 case SCREEN_CTRL_ID_SCROLL_DOWN:
3608 if (game_status == GAME_MODE_LEVELS)
3609 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3610 else if (game_status == GAME_MODE_SETUP)
3611 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
3614 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
3615 if (game_status == GAME_MODE_LEVELS)
3616 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
3617 else if (game_status == GAME_MODE_SETUP)
3618 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);