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_CHOOSE_SCREEN_MODE 7
36 #define SETUP_MODE_SOUND 8
37 #define SETUP_MODE_ARTWORK 9
38 #define SETUP_MODE_CHOOSE_GRAPHICS 10
39 #define SETUP_MODE_CHOOSE_SOUNDS 11
40 #define SETUP_MODE_CHOOSE_MUSIC 12
42 #define MAX_SETUP_MODES 13
44 /* for input setup functions */
45 #define SETUPINPUT_SCREEN_POS_START 0
46 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
47 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
48 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
50 /* screens on the info screen */
51 #define INFO_MODE_MAIN 0
52 #define INFO_MODE_TITLE 1
53 #define INFO_MODE_ELEMENTS 2
54 #define INFO_MODE_MUSIC 3
55 #define INFO_MODE_CREDITS 4
56 #define INFO_MODE_PROGRAM 5
57 #define INFO_MODE_LEVELSET 6
59 #define MAX_INFO_MODES 7
61 /* for various menu stuff */
62 #define MENU_SCREEN_START_XPOS 1
63 #define MENU_SCREEN_START_YPOS 2
64 #define MENU_SCREEN_VALUE_XPOS 14
65 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
66 #define MENU_TITLE1_YPOS 8
67 #define MENU_TITLE2_YPOS 46
68 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
69 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
70 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
71 MENU_SCREEN_START_XPOS)
72 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
74 /* buttons and scrollbars identifiers */
75 #define SCREEN_CTRL_ID_LAST_LEVEL 0
76 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
77 #define SCREEN_CTRL_ID_LAST_PLAYER 2
78 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
79 #define SCREEN_CTRL_ID_SCROLL_UP 4
80 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
81 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
83 #define NUM_SCREEN_GADGETS 7
85 #define NUM_SCREEN_MENUBUTTONS 4
86 #define NUM_SCREEN_SCROLLBUTTONS 2
87 #define NUM_SCREEN_SCROLLBARS 1
89 #define SCREEN_MASK_MAIN (1 << 0)
90 #define SCREEN_MASK_INPUT (1 << 1)
92 /* graphic position and size values for buttons and scrollbars */
93 #define SC_MENUBUTTON_XSIZE TILEX
94 #define SC_MENUBUTTON_YSIZE TILEY
96 #define SC_SCROLLBUTTON_XSIZE TILEX
97 #define SC_SCROLLBUTTON_YSIZE TILEY
99 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
101 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
102 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
103 SC_SCROLLBUTTON_YSIZE)
105 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
106 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
108 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
109 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
110 SC_SCROLLBUTTON_YSIZE)
112 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
113 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
114 SC_SCROLL_VERTICAL_YSIZE)
116 #define SC_BORDER_SIZE 14
119 /* forward declarations of internal functions */
120 static void HandleScreenGadgets(struct GadgetInfo *);
121 static void HandleSetupScreen_Generic(int, int, int, int, int);
122 static void HandleSetupScreen_Input(int, int, int, int, int);
123 static void CustomizeKeyboard(int);
124 static void CalibrateJoystick(int);
125 static void execSetupGraphics(void);
126 static void execSetupArtwork(void);
127 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
129 static void DrawChooseLevel(void);
130 static void DrawInfoScreen(void);
131 static void DrawSetupScreen(void);
133 static void DrawInfoScreenExt(int);
134 static void DrawInfoScreen_NotAvailable(char *, char *);
135 static void DrawInfoScreen_HelpAnim(int, int, boolean);
136 static void DrawInfoScreen_HelpText(int, int, int, int);
137 static void HandleInfoScreen_Main(int, int, int, int, int);
138 static void HandleInfoScreen_TitleScreen(int);
139 static void HandleInfoScreen_Elements(int);
140 static void HandleInfoScreen_Music(int);
141 static void HandleInfoScreen_Credits(int);
142 static void HandleInfoScreen_Program(int);
144 static void MapScreenMenuGadgets(int);
145 static void MapScreenTreeGadgets(TreeInfo *);
147 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
148 static int setup_mode = SETUP_MODE_MAIN;
149 static int info_mode = INFO_MODE_MAIN;
151 static TreeInfo *screen_modes = NULL;
152 static TreeInfo *screen_mode_current = NULL;
154 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
155 x <= GAME_MODE_SETUP ? x : \
156 x == GAME_MODE_PSEUDO_TYPENAME ? \
157 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
159 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
160 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
162 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
163 menu.list_size[game_status] : \
164 MAX_MENU_ENTRIES_ON_SCREEN)
166 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
167 #define NUM_SCROLLBAR_BITMAPS 2
168 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
172 static void drawCursorExt(int xpos, int ypos, int color, int g)
174 static int cursor_array[SCR_FIELDY];
179 cursor_array[ypos] = g;
181 g = cursor_array[ypos];
185 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
186 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
187 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
188 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
189 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
190 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
191 IMG_MENU_BUTTON_ACTIVE);
193 ypos += MENU_SCREEN_START_YPOS;
195 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
196 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
199 static void initCursor(int ypos, int graphic)
201 drawCursorExt(0, ypos, FC_BLUE, graphic);
204 static void drawCursor(int ypos, int color)
206 drawCursorExt(0, ypos, color, 0);
209 static void drawCursorXY(int xpos, int ypos, int graphic)
211 drawCursorExt(xpos, ypos, -1, graphic);
214 static void drawChooseTreeCursor(int ypos, int color)
216 int last_game_status = game_status; /* save current game status */
218 /* force LEVELS draw offset on artwork setup screen */
219 game_status = GAME_MODE_LEVELS;
221 drawCursorExt(0, ypos, color, 0);
223 game_status = last_game_status; /* restore current game status */
228 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
229 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
232 static void ToggleFullscreenIfNeeded()
234 if (setup.fullscreen != video.fullscreen_enabled)
236 /* save old door content */
237 BlitBitmap(backbuffer, bitmap_db_door,
238 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
240 /* toggle fullscreen */
241 ChangeVideoModeIfNeeded(setup.fullscreen);
242 setup.fullscreen = video.fullscreen_enabled;
244 /* redraw background to newly created backbuffer */
245 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
246 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
248 /* restore old door content */
249 BlitBitmap(bitmap_db_door, backbuffer,
250 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
252 redraw_mask = REDRAW_ALL;
256 static int getLastLevelButtonPos()
261 static int getCurrentLevelTextPos()
263 return (getLastLevelButtonPos() + 1);
266 static int getNextLevelButtonPos()
268 return getLastLevelButtonPos() + 3 + 1;
271 static int getLevelRangeTextPos()
273 return getNextLevelButtonPos() + 1;
276 void DrawTitleScreenImage(int nr)
278 int graphic = IMG_TITLESCREEN_1 + nr;
279 Bitmap *bitmap = graphic_info[graphic].bitmap;
280 int width = graphic_info[graphic].src_image_width;
281 int height = graphic_info[graphic].src_image_height;
282 int src_x = 0, src_y = 0;
288 if (width > WIN_XSIZE)
290 /* image width too large for window => center image horizontally */
291 src_x = (width - WIN_XSIZE) / 2;
295 if (height > WIN_YSIZE)
297 /* image height too large for window => center image vertically */
298 src_y = (height - WIN_YSIZE) / 2;
302 dst_x = (WIN_XSIZE - width) / 2;
303 dst_y = (WIN_YSIZE - height) / 2;
305 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
307 if (DrawingOnBackground(dst_x, dst_y))
308 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
310 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
312 redraw_mask = REDRAW_ALL;
315 void DrawTitleScreen()
317 KeyboardAutoRepeatOff();
319 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
321 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
326 static void DrawMainMenuExt(int fade_delay)
328 static LevelDirTree *leveldir_last_valid = NULL;
329 boolean levelset_has_changed = FALSE;
330 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
332 char *level_text = "Levelset";
334 char *level_text = "Level:";
336 int name_width, level_width;
340 FadeSoundsAndMusic();
342 KeyboardAutoRepeatOn();
345 SetDrawDeactivationMask(REDRAW_NONE);
346 SetDrawBackgroundMask(REDRAW_FIELD);
348 audio.sound_deactivated = FALSE;
354 /* needed if last screen was the playing screen, invoked from level editor */
355 if (level_editor_test_game)
357 game_status = GAME_MODE_EDITOR;
363 /* needed if last screen was the editor screen */
364 UndrawSpecialEditorDoor();
366 /* needed if last screen was the setup screen and fullscreen state changed */
367 ToggleFullscreenIfNeeded();
369 /* leveldir_current may be invalid (level group, parent link) */
370 if (!validLevelSeries(leveldir_current))
371 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
373 if (leveldir_current != leveldir_last_valid)
374 levelset_has_changed = TRUE;
376 /* store valid level series information */
377 leveldir_last_valid = leveldir_current;
379 /* needed if last screen (level choice) changed graphics, sounds or music */
380 ReloadCustomArtwork(0);
383 SetDrawtoField(DRAW_BACKBUFFER);
386 if (setup.show_titlescreen &&
387 levelset_has_changed &&
388 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
390 game_status = GAME_MODE_TITLE;
397 /* map gadgets for main menu screen */
401 /* level_nr may have been set to value over handicap with level editor */
402 if (setup.handicap && level_nr > leveldir_current->handicap_level)
403 level_nr = leveldir_current->handicap_level;
410 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
415 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
416 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
417 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
418 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
419 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
420 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
421 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
422 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
424 /* calculated after (possible) reload of custom artwork */
425 name_width = getTextWidth(name_text, FONT_MENU_1);
427 level_width = 9 * 32;
430 level_width = 9 * getFontWidth(FONT_MENU_1);
432 level_width = getTextWidth(level_text, FONT_MENU_1);
436 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
440 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
441 int2str(level_nr, 3), FONT_VALUE_1);
444 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
447 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
452 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
458 int text_height = getFontHeight(FONT_TEXT_3);
460 int xpos = getLevelRangeTextPos() * 32;
462 int xpos = level_width + 6 * 32;
464 int ypos2 = -SY + 3 * 32 + 16;
465 int ypos1 = ypos2 - text_height;
467 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
468 "%03d", leveldir_current->first_level);
469 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
470 "%03d", leveldir_current->last_level);
473 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
474 "%d", leveldir_current->levels);
478 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
479 leveldir_current->first_level, leveldir_current->last_level);
483 if (leveldir_current->readonly)
485 DrawTextS(mSX + level_width + 9 * 32 - 2,
486 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
487 DrawTextS(mSX + level_width + 9 * 32 - 2,
488 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
492 for (i = 0; i < 8; i++)
493 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
499 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
500 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
503 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
504 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
506 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
507 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
513 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
522 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
525 if (TAPE_IS_EMPTY(tape))
527 DrawCompleteVideoDisplay();
534 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
537 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
539 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
548 /* create gadgets for main menu screen */
550 CreateScreenGadgets();
552 /* map gadgets for main menu screen */
554 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
570 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
580 static void gotoTopLevelDir()
582 /* move upwards to top level directory */
583 while (leveldir_current->node_parent)
585 /* write a "path" into level tree for easy navigation to last level */
586 if (leveldir_current->node_parent->node_group->cl_first == -1)
588 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
589 int leveldir_pos = posTreeInfo(leveldir_current);
590 int num_page_entries;
591 int cl_first, cl_cursor;
593 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
594 num_page_entries = num_leveldirs;
596 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
598 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
599 cl_cursor = leveldir_pos - cl_first;
601 leveldir_current->node_parent->node_group->cl_first = cl_first;
602 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
605 leveldir_current = leveldir_current->node_parent;
610 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
612 static int title_nr = 0;
613 boolean return_to_main_menu = FALSE;
614 boolean use_fading_main_menu = TRUE;
615 boolean use_cross_fading = TRUE;
616 int fade_delay = 500;
617 int post_delay = fade_delay / 2;
619 if (button == MB_MENU_INITIALIZE)
621 int last_game_status = game_status; /* save current game status */
624 if (game_status == GAME_MODE_INFO)
626 if (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
628 DrawInfoScreen_NotAvailable("Title screen information:",
629 "No title screen for this level set.");
634 FadeSoundsAndMusic();
636 FadeOut(fade_delay, post_delay);
639 /* force TITLE music on title info screen */
640 game_status = GAME_MODE_TITLE;
645 game_status = last_game_status; /* restore current game status */
647 DrawTitleScreenImage(title_nr);
653 else if (button == MB_MENU_LEAVE)
655 return_to_main_menu = TRUE;
656 use_fading_main_menu = FALSE;
658 else if (button == MB_MENU_CHOICE)
660 if (game_status == GAME_MODE_INFO &&
661 graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
663 info_mode = INFO_MODE_MAIN;
671 if (!use_cross_fading)
672 FadeOut(fade_delay, post_delay);
674 if (title_nr < MAX_NUM_TITLE_SCREENS &&
675 graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
677 Bitmap *drawto_last = drawto;
679 if (use_cross_fading)
680 drawto = bitmap_db_title;
682 DrawTitleScreenImage(title_nr);
684 drawto = drawto_last;
686 if (use_cross_fading)
687 FadeCross(fade_delay);
693 FadeSoundsAndMusic();
695 FadeOut(fade_delay, post_delay);
697 return_to_main_menu = TRUE;
701 if (return_to_main_menu)
703 int menu_fade_delay = (use_fading_main_menu ? fade_delay : 0);
707 if (game_status == GAME_MODE_INFO)
709 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
711 info_mode = INFO_MODE_MAIN;
712 DrawInfoScreenExt(menu_fade_delay);
714 else /* default: return to main menu */
716 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
718 game_status = GAME_MODE_MAIN;
719 DrawMainMenuExt(menu_fade_delay);
724 void HandleMainMenu_SelectLevel(int step, int direction)
726 int old_level_nr = level_nr;
729 new_level_nr = old_level_nr + step * direction;
730 if (new_level_nr < leveldir_current->first_level)
731 new_level_nr = leveldir_current->first_level;
732 if (new_level_nr > leveldir_current->last_level)
733 new_level_nr = leveldir_current->last_level;
735 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
737 /* skipping levels is only allowed when trying to skip single level */
738 if (setup.skip_levels && step == 1 &&
739 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
741 leveldir_current->handicap_level++;
742 SaveLevelSetup_SeriesInfo();
745 new_level_nr = leveldir_current->handicap_level;
748 if (new_level_nr != old_level_nr)
750 level_nr = new_level_nr;
752 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
755 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
759 DrawCompleteVideoDisplay();
761 /* needed because DrawMicroLevel() takes some time */
767 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
770 static unsigned long level_delay = 0;
771 static unsigned long level_delay_value = GADGET_FRAME_DELAY;
773 static int choice = 5;
777 if (button == MB_MENU_INITIALIZE)
779 drawCursor(choice, FC_RED);
783 if (mx || my) /* mouse input */
786 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
788 else if (dx || dy) /* keyboard input */
790 if (dx && choice == 1)
791 x = (dx < 0 ? 10 : 14);
794 if (choice == 4 || choice == 6)
795 button = MB_MENU_CHOICE;
802 /* start gadget delay with longer delay after first click on gadget */
804 pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
809 if (y == 1 && dx != 0 && button)
811 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
816 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
817 (x == 14 && level_nr < leveldir_current->last_level)) &&
818 button && DelayReached(&level_delay, level_delay_value))
820 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
821 int old_level_nr = level_nr;
824 new_level_nr = level_nr + (x == 10 ? -step : +step);
825 if (new_level_nr < leveldir_current->first_level)
826 new_level_nr = leveldir_current->first_level;
827 if (new_level_nr > leveldir_current->last_level)
828 new_level_nr = leveldir_current->last_level;
830 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
832 /* skipping levels is only allowed when trying to skip single level */
833 if (setup.skip_levels && step == 1 &&
834 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
836 leveldir_current->handicap_level++;
837 SaveLevelSetup_SeriesInfo();
840 new_level_nr = leveldir_current->handicap_level;
843 if (new_level_nr != old_level_nr)
845 level_nr = new_level_nr;
847 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
851 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
855 DrawCompleteVideoDisplay();
857 /* needed because DrawMicroLevel() takes some time */
861 DelayReached(&level_delay, 0); /* reset delay counter */
863 pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
870 else if (IN_VIS_FIELD(x, y) &&
871 y >= 0 && y <= 7 && (y != 1 || x < 10))
877 drawCursor(y, FC_RED);
878 drawCursor(choice, FC_BLUE);
886 game_status = GAME_MODE_PSEUDO_TYPENAME;
887 HandleTypeName(strlen(setup.player_name), 0);
893 game_status = GAME_MODE_LEVELS;
894 SaveLevelSetup_LastSeries();
895 SaveLevelSetup_SeriesInfo();
906 game_status = GAME_MODE_SCORES;
911 if (leveldir_current->readonly &&
912 !strEqual(setup.player_name, "Artsoft"))
913 Request("This level is read only !", REQ_CONFIRM);
914 game_status = GAME_MODE_EDITOR;
919 game_status = GAME_MODE_INFO;
920 info_mode = INFO_MODE_MAIN;
925 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
929 game_status = GAME_MODE_SETUP;
930 setup_mode = SETUP_MODE_MAIN;
936 SaveLevelSetup_LastSeries();
937 SaveLevelSetup_SeriesInfo();
939 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
940 game_status = GAME_MODE_QUIT;
945 if (game_status == GAME_MODE_MAIN)
947 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
953 /* ========================================================================= */
954 /* info screen functions */
955 /* ========================================================================= */
957 static struct TokenInfo *info_info;
958 static int num_info_info;
960 static void execInfoTitleScreen()
962 info_mode = INFO_MODE_TITLE;
966 static void execInfoElements()
968 info_mode = INFO_MODE_ELEMENTS;
972 static void execInfoMusic()
974 info_mode = INFO_MODE_MUSIC;
978 static void execInfoCredits()
980 info_mode = INFO_MODE_CREDITS;
984 static void execInfoProgram()
986 info_mode = INFO_MODE_PROGRAM;
990 static void execInfoLevelSet()
992 info_mode = INFO_MODE_LEVELSET;
996 static void execExitInfo()
998 game_status = GAME_MODE_MAIN;
1002 static struct TokenInfo info_info_main[] =
1004 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1005 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1006 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1007 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1008 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1009 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1010 { TYPE_EMPTY, NULL, "" },
1011 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1016 static void DrawInfoScreen_Main(int fade_delay)
1021 CloseDoor(DOOR_CLOSE_2);
1026 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1028 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
1031 info_info = info_info_main;
1034 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1036 int xpos = MENU_SCREEN_START_XPOS;
1037 int ypos = MENU_SCREEN_START_YPOS + i;
1038 int font_nr = FONT_MENU_1;
1040 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
1042 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1043 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1044 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1045 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1046 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1047 initCursor(i, IMG_MENU_BUTTON);
1054 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1070 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1074 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1076 static int choice_store[MAX_INFO_MODES];
1077 int choice = choice_store[info_mode]; /* always starts with 0 */
1081 if (button == MB_MENU_INITIALIZE)
1083 /* advance to first valid menu entry */
1084 while (choice < num_info_info &&
1085 info_info[choice].type & TYPE_SKIP_ENTRY)
1087 choice_store[info_mode] = choice;
1089 drawCursor(choice, FC_RED);
1092 else if (button == MB_MENU_LEAVE)
1094 for (y = 0; y < num_info_info; y++)
1096 if (info_info[y].type & TYPE_LEAVE_MENU)
1098 void (*menu_callback_function)(void) = info_info[y].value;
1100 menu_callback_function();
1101 break; /* absolutely needed because function changes 'info_info'! */
1108 if (mx || my) /* mouse input */
1110 x = (mx - mSX) / 32;
1111 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1113 else if (dx || dy) /* keyboard input */
1117 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
1119 if (info_info[choice].type & menu_navigation_type ||
1120 info_info[choice].type & TYPE_ENTER_SCREEN ||
1121 info_info[choice].type & TYPE_BOOLEAN_STYLE)
1122 button = MB_MENU_CHOICE;
1127 /* jump to next non-empty menu entry (up or down) */
1128 while (y > 0 && y < num_info_info - 1 &&
1129 info_info[y].type & TYPE_SKIP_ENTRY)
1133 if (IN_VIS_FIELD(x, y) &&
1134 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
1140 drawCursor(y, FC_RED);
1141 drawCursor(choice, FC_BLUE);
1142 choice = choice_store[info_mode] = y;
1145 else if (!(info_info[y].type & TYPE_GHOSTED))
1147 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
1149 void (*menu_callback_function)(void) = info_info[choice].value;
1151 menu_callback_function();
1157 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
1160 int ybottom = SYSIZE - 20;
1162 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1167 DrawTextSCentered(100, FONT_TEXT_1, text_title);
1169 DrawTextSCentered(ybottom, FONT_TEXT_4,
1170 "Press any key or button for info menu");
1172 DrawTextSCentered(ystart, FONT_TEXT_2, text_error);
1175 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
1177 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
1178 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
1179 int xstart = mSX + 16;
1180 int ystart = mSY + 64 + 2 * 32;
1181 int ystep = TILEY + 4;
1182 int element, action, direction;
1190 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
1191 infoscreen_step[i] = infoscreen_frame[i] = 0;
1196 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
1198 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1199 "Press any key or button for next page");
1205 while (helpanim_info[j].element != HELPANIM_LIST_END)
1207 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1212 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1221 j += infoscreen_step[i - start];
1223 element = helpanim_info[j].element;
1224 action = helpanim_info[j].action;
1225 direction = helpanim_info[j].direction;
1228 element = EL_UNKNOWN;
1230 if (action != -1 && direction != -1)
1231 graphic = el_act_dir2img(element, action, direction);
1232 else if (action != -1)
1233 graphic = el_act2img(element, action);
1234 else if (direction != -1)
1235 graphic = el_dir2img(element, direction);
1237 graphic = el2img(element);
1239 delay = helpanim_info[j++].delay;
1244 if (infoscreen_frame[i - start] == 0)
1247 infoscreen_frame[i - start] = delay - 1;
1251 sync_frame = delay - infoscreen_frame[i - start];
1252 infoscreen_frame[i - start]--;
1255 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1257 if (!infoscreen_frame[i - start])
1258 infoscreen_step[i - start] = 0;
1262 if (!infoscreen_frame[i - start])
1263 infoscreen_step[i - start]++;
1264 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1270 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1272 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1273 graphic, sync_frame, USE_MASKING);
1276 DrawInfoScreen_HelpText(element, action, direction, i - start);
1281 redraw_mask |= REDRAW_FIELD;
1286 static char *getHelpText(int element, int action, int direction)
1288 char token[MAX_LINE_LEN];
1290 strcpy(token, element_info[element].token_name);
1293 strcat(token, element_action_info[action].suffix);
1295 if (direction != -1)
1296 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1298 return getHashEntry(helptext_info, token);
1301 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1303 int font_nr = FONT_LEVEL_NUMBER;
1304 int font_width = getFontWidth(font_nr);
1305 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1306 int sy = mSY + 65 + 2 * 32 + 1;
1307 int ystep = TILEY + 4;
1308 int pad_x = sx - SX;
1309 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1310 int max_lines_per_text = 2;
1313 if (action != -1 && direction != -1) /* element.action.direction */
1314 text = getHelpText(element, action, direction);
1316 if (text == NULL && action != -1) /* element.action */
1317 text = getHelpText(element, action, -1);
1319 if (text == NULL && direction != -1) /* element.direction */
1320 text = getHelpText(element, -1, direction);
1322 if (text == NULL) /* base element */
1323 text = getHelpText(element, -1, -1);
1325 if (text == NULL) /* not found */
1326 text = "No description available";
1328 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1329 sy += getFontHeight(font_nr) / 2;
1331 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1332 max_chars_per_line, max_lines_per_text);
1335 void DrawInfoScreen_TitleScreen()
1340 void HandleInfoScreen_TitleScreen(int button)
1342 HandleTitleScreen(0, 0, 0, 0, button);
1345 void DrawInfoScreen_Elements()
1347 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1352 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1358 void HandleInfoScreen_Elements(int button)
1360 static unsigned long info_delay = 0;
1361 static int num_anims;
1362 static int num_pages;
1364 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1365 int button_released = !button;
1368 if (button == MB_MENU_INITIALIZE)
1370 boolean new_element = TRUE;
1373 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1375 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1377 else if (new_element)
1380 new_element = FALSE;
1384 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1387 else if (button == MB_MENU_LEAVE)
1389 info_mode = INFO_MODE_MAIN;
1395 if (button_released || button == MB_MENU_INITIALIZE)
1397 if (button != MB_MENU_INITIALIZE)
1400 if (page >= num_pages)
1402 FadeSoundsAndMusic();
1404 info_mode = INFO_MODE_MAIN;
1410 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1414 if (DelayReached(&info_delay, GameFrameDelay))
1415 if (page < num_pages)
1416 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1418 PlayMenuSoundIfLoop();
1422 void DrawInfoScreen_Music()
1424 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1431 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1434 void HandleInfoScreen_Music(int button)
1436 static struct MusicFileInfo *list = NULL;
1437 int ystart = 150, dy = 30;
1438 int ybottom = SYSIZE - 20;
1439 int button_released = !button;
1441 if (button == MB_MENU_INITIALIZE)
1443 list = music_file_info;
1447 FadeSoundsAndMusic();
1452 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1454 DrawTextSCentered(ybottom, FONT_TEXT_4,
1455 "Press any key or button for info menu");
1460 else if (button == MB_MENU_LEAVE)
1462 info_mode = INFO_MODE_MAIN;
1468 if (button_released || button == MB_MENU_INITIALIZE)
1472 if (button != MB_MENU_INITIALIZE)
1478 info_mode = INFO_MODE_MAIN;
1484 FadeSoundsAndMusic();
1491 int sound = list->music;
1493 if (sound_info[sound].loop)
1494 PlaySoundLoop(sound);
1498 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1502 PlayMusic(list->music);
1504 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1507 if (!strEqual(list->title, UNKNOWN_NAME))
1509 if (!strEqual(list->title_header, UNKNOWN_NAME))
1510 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1512 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1515 if (!strEqual(list->artist, UNKNOWN_NAME))
1517 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1518 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1520 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1522 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1525 if (!strEqual(list->album, UNKNOWN_NAME))
1527 if (!strEqual(list->album_header, UNKNOWN_NAME))
1528 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1530 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1532 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1535 if (!strEqual(list->year, UNKNOWN_NAME))
1537 if (!strEqual(list->year_header, UNKNOWN_NAME))
1538 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1540 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1542 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1545 DrawTextSCentered(ybottom, FONT_TEXT_4,
1546 "Press any key or button for next page");
1549 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1550 PlaySoundLoop(list->music);
1553 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
1555 int ystart = 150, ystep = 30;
1556 int ybottom = SYSIZE - 20;
1561 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1565 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1566 "Special thanks to");
1567 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1569 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1571 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1572 "\"Boulder Dash\"");
1573 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1575 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1577 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1579 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1580 "First Star Software");
1582 else if (screen_nr == 1)
1584 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1585 "Special thanks to");
1586 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1587 "Klaus Heinz & Volker Wertich");
1588 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1590 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1591 "\"Emerald Mine\"");
1592 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1594 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1596 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1598 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1601 else if (screen_nr == 2)
1603 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1604 "Special thanks to");
1605 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1606 "Michael Stopp & Philip Jespersen");
1607 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1609 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1611 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1613 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1615 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1617 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1618 "Digital Integration");
1620 else if (screen_nr == 3)
1622 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1623 "Special thanks to");
1624 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1625 "Hiroyuki Imabayashi");
1626 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1628 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1630 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1632 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1634 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1636 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1639 else if (screen_nr == 4)
1641 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1642 "Special thanks to");
1643 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1645 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1647 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1648 "Jürgen Bonhagen");
1649 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1650 "for the continuous creation");
1651 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1652 "of outstanding level sets");
1654 else if (screen_nr == 5)
1656 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1658 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1660 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1661 "for ideas and inspiration by");
1662 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1665 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1667 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_3,
1669 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1670 "for ideas and inspiration by");
1671 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
1674 else if (screen_nr == 6)
1676 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1678 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1680 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1681 "for the new Emerald Mine engine");
1683 else if (screen_nr == 7)
1685 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1687 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1689 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1690 "for the initial DOS port");
1692 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1694 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1696 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1697 "for some additional toons");
1699 else if (screen_nr == 8)
1701 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1702 "And not to forget:");
1703 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1705 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1706 "All those who contributed");
1707 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1708 "levels to this game");
1709 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_3,
1717 DrawTextSCentered(ybottom, FONT_TEXT_4,
1718 "Press any key or button for next page");
1723 void DrawInfoScreen_Credits()
1725 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1727 FadeSoundsAndMusic();
1729 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
1732 void HandleInfoScreen_Credits(int button)
1734 static int screen_nr = 0;
1736 if (button == MB_MENU_INITIALIZE)
1740 DrawInfoScreen_CreditsScreen(screen_nr);
1742 else if (button == MB_MENU_LEAVE)
1744 info_mode = INFO_MODE_MAIN;
1749 else if (button == MB_MENU_CHOICE)
1753 if (!DrawInfoScreen_CreditsScreen(screen_nr))
1755 FadeSoundsAndMusic();
1757 info_mode = INFO_MODE_MAIN;
1763 PlayMenuSoundIfLoop();
1767 void DrawInfoScreen_Program()
1769 int ystart = 150, ystep = 30;
1770 int ybottom = SYSIZE - 20;
1772 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1777 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1779 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1780 "This game is Freeware!");
1781 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1782 "If you like it, send e-mail to:");
1783 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1784 "info@artsoft.org");
1785 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1786 "or SnailMail to:");
1787 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1789 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1790 "Detmolder Strasse 189");
1791 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1793 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1796 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1797 "If you have created new levels,");
1798 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1799 "send them to me to include them!");
1800 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1803 DrawTextSCentered(ybottom, FONT_TEXT_4,
1804 "Press any key or button for info menu");
1807 void HandleInfoScreen_Program(int button)
1809 int button_released = !button;
1811 if (button == MB_MENU_LEAVE)
1813 info_mode = INFO_MODE_MAIN;
1819 if (button_released)
1821 FadeSoundsAndMusic();
1823 info_mode = INFO_MODE_MAIN;
1828 PlayMenuSoundIfLoop();
1832 void DrawInfoScreen_LevelSet()
1835 int ybottom = SYSIZE - 20;
1836 char *filename = getLevelSetInfoFilename();
1837 int font_nr = FONT_LEVEL_NUMBER;
1838 int font_width = getFontWidth(font_nr);
1839 int font_height = getFontHeight(font_nr);
1842 int sx = SX + pad_x;
1843 int sy = SY + pad_y;
1844 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1845 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1847 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1852 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1854 DrawTextSCentered(ybottom, FONT_TEXT_4,
1855 "Press any key or button for info menu");
1857 if (filename != NULL)
1858 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1859 max_lines_per_screen);
1861 DrawTextSCentered(ystart, FONT_TEXT_2,
1862 "No information for this level set.");
1865 void HandleInfoScreen_LevelSet(int button)
1867 int button_released = !button;
1869 if (button == MB_MENU_LEAVE)
1871 info_mode = INFO_MODE_MAIN;
1877 if (button_released)
1879 FadeSoundsAndMusic();
1881 info_mode = INFO_MODE_MAIN;
1886 PlayMenuSoundIfLoop();
1890 static void DrawInfoScreenExt(int fade_delay)
1892 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1894 if (info_mode == INFO_MODE_TITLE)
1895 DrawInfoScreen_TitleScreen();
1896 else if (info_mode == INFO_MODE_ELEMENTS)
1897 DrawInfoScreen_Elements();
1898 else if (info_mode == INFO_MODE_MUSIC)
1899 DrawInfoScreen_Music();
1900 else if (info_mode == INFO_MODE_CREDITS)
1901 DrawInfoScreen_Credits();
1902 else if (info_mode == INFO_MODE_PROGRAM)
1903 DrawInfoScreen_Program();
1904 else if (info_mode == INFO_MODE_LEVELSET)
1905 DrawInfoScreen_LevelSet();
1907 DrawInfoScreen_Main(fade_delay);
1909 if (info_mode != INFO_MODE_MAIN &&
1910 info_mode != INFO_MODE_TITLE &&
1911 info_mode != INFO_MODE_MUSIC)
1918 void DrawInfoScreen()
1920 DrawInfoScreenExt(0);
1923 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1925 if (info_mode == INFO_MODE_TITLE)
1926 HandleInfoScreen_TitleScreen(button);
1927 else if (info_mode == INFO_MODE_ELEMENTS)
1928 HandleInfoScreen_Elements(button);
1929 else if (info_mode == INFO_MODE_MUSIC)
1930 HandleInfoScreen_Music(button);
1931 else if (info_mode == INFO_MODE_CREDITS)
1932 HandleInfoScreen_Credits(button);
1933 else if (info_mode == INFO_MODE_PROGRAM)
1934 HandleInfoScreen_Program(button);
1935 else if (info_mode == INFO_MODE_LEVELSET)
1936 HandleInfoScreen_LevelSet(button);
1938 HandleInfoScreen_Main(mx, my, dx, dy, button);
1944 /* ========================================================================= */
1945 /* type name functions */
1946 /* ========================================================================= */
1948 void HandleTypeName(int newxpos, Key key)
1950 static int xpos = 0, ypos = 2;
1951 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1952 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1953 int startx = mSX + 32 + name_width;
1954 int starty = mSY + ypos * 32;
1960 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1961 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1966 if (((key >= KSYM_A && key <= KSYM_Z) ||
1967 (key >= KSYM_a && key <= KSYM_z)) &&
1968 xpos < MAX_PLAYER_NAME_LEN)
1972 if (key >= KSYM_A && key <= KSYM_Z)
1973 ascii = 'A' + (char)(key - KSYM_A);
1975 ascii = 'a' + (char)(key - KSYM_a);
1977 setup.player_name[xpos] = ascii;
1978 setup.player_name[xpos + 1] = 0;
1981 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1982 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1984 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1987 setup.player_name[xpos] = 0;
1989 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1991 else if (key == KSYM_Return && xpos > 0)
1993 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1994 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1997 game_status = GAME_MODE_MAIN;
2002 /* ========================================================================= */
2003 /* tree menu functions */
2004 /* ========================================================================= */
2006 static void DrawChooseTree(TreeInfo **ti_ptr)
2010 FreeScreenGadgets();
2011 CreateScreenGadgets();
2013 CloseDoor(DOOR_CLOSE_2);
2017 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
2018 MapScreenTreeGadgets(*ti_ptr);
2024 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
2026 struct GadgetInfo *gi = screen_gadget[id];
2027 int items_max, items_visible, item_position;
2029 items_max = numTreeInfoInGroup(ti);
2030 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
2031 item_position = first_entry;
2033 if (item_position > items_max - items_visible)
2034 item_position = items_max - items_visible;
2036 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
2037 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2038 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
2041 static void drawChooseTreeList(int first_entry, int num_page_entries,
2045 char *title_string = NULL;
2047 int xoffset_sets = 16;
2049 int yoffset_sets = MENU_TITLE1_YPOS;
2051 int xoffset_setup = 16;
2053 int yoffset_setup = 16;
2056 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
2059 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
2062 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
2063 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
2065 int last_game_status = game_status; /* save current game status */
2067 title_string = ti->infotext;
2070 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
2072 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
2075 /* force LEVELS font on artwork setup screen */
2076 game_status = GAME_MODE_LEVELS;
2078 /* clear tree list area, but not title or scrollbar */
2079 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
2080 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
2081 MAX_MENU_ENTRIES_ON_SCREEN * 32);
2083 for (i = 0; i < num_page_entries; i++)
2085 TreeInfo *node, *node_first;
2086 int entry_pos = first_entry + i;
2087 int xpos = MENU_SCREEN_START_XPOS;
2088 int ypos = MENU_SCREEN_START_YPOS + i;
2089 int startx = mSX + xpos * 32;
2090 int starty = mSY + ypos * 32;
2091 int font_nr = FONT_TEXT_1;
2092 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2093 int startx_text = startx + font_xoffset;
2094 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
2095 int text_size = startx_scrollbar - startx_text;
2096 int max_buffer_len = text_size / getFontWidth(font_nr);
2097 char buffer[max_buffer_len + 1];
2099 node_first = getTreeInfoFirstGroupEntry(ti);
2100 node = getTreeInfoFromPos(node_first, entry_pos);
2102 strncpy(buffer, node->name, max_buffer_len);
2103 buffer[max_buffer_len] = '\0';
2105 DrawText(startx, starty, buffer, font_nr + node->color);
2107 if (node->parent_link)
2108 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2109 else if (node->level_group)
2110 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2112 initCursor(i, IMG_MENU_BUTTON);
2115 game_status = last_game_status; /* restore current game status */
2117 redraw_mask |= REDRAW_FIELD;
2120 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
2122 TreeInfo *node, *node_first;
2123 int x, last_redraw_mask = redraw_mask;
2125 int ypos = MENU_TITLE2_YPOS;
2130 if (ti->type != TREE_TYPE_LEVEL_DIR)
2133 node_first = getTreeInfoFirstGroupEntry(ti);
2134 node = getTreeInfoFromPos(node_first, entry_pos);
2136 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
2138 if (node->parent_link)
2139 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
2141 else if (node->level_group)
2142 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
2144 else if (ti->type == TREE_TYPE_LEVEL_DIR)
2145 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
2146 node->levels, node->class_desc);
2148 /* let BackToFront() redraw only what is needed */
2149 redraw_mask = last_redraw_mask | REDRAW_TILES;
2150 for (x = 0; x < SCR_FIELDX; x++)
2151 MarkTileDirty(x, 1);
2154 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
2157 TreeInfo *ti = *ti_ptr;
2159 int y = ti->cl_cursor;
2160 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2161 int num_entries = numTreeInfoInGroup(ti);
2162 int num_page_entries;
2163 int last_game_status = game_status; /* save current game status */
2164 boolean position_set_by_scrollbar = (dx == 999);
2166 /* force LEVELS draw offset on choose level and artwork setup screen */
2167 game_status = GAME_MODE_LEVELS;
2169 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
2170 num_page_entries = num_entries;
2172 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2174 game_status = last_game_status; /* restore current game status */
2176 if (button == MB_MENU_INITIALIZE)
2178 int num_entries = numTreeInfoInGroup(ti);
2179 int entry_pos = posTreeInfo(ti);
2181 if (ti->cl_first == -1)
2183 /* only on initialization */
2184 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2185 ti->cl_cursor = entry_pos - ti->cl_first;
2187 else if (ti->cl_cursor >= num_page_entries ||
2188 (num_entries > num_page_entries &&
2189 num_entries - ti->cl_first < num_page_entries))
2191 /* only after change of list size (by custom graphic configuration) */
2192 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2193 ti->cl_cursor = entry_pos - ti->cl_first;
2196 if (position_set_by_scrollbar)
2199 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2202 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2203 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2204 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2208 else if (button == MB_MENU_LEAVE)
2210 if (ti->node_parent)
2212 *ti_ptr = ti->node_parent;
2213 DrawChooseTree(ti_ptr);
2215 else if (game_status == GAME_MODE_SETUP)
2217 if (game_status == GAME_MODE_SETUP)
2219 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2220 execSetupGraphics();
2227 game_status = GAME_MODE_MAIN;
2234 if (mx || my) /* mouse input */
2236 int last_game_status = game_status; /* save current game status */
2238 /* force LEVELS draw offset on artwork setup screen */
2239 game_status = GAME_MODE_LEVELS;
2241 x = (mx - mSX) / 32;
2242 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2244 game_status = last_game_status; /* restore current game status */
2246 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2248 /* move cursor instead of scrolling when already at start/end of list */
2249 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
2251 else if (dy == +1 * SCROLL_LINE &&
2252 ti->cl_first + num_page_entries == num_entries)
2255 /* handle scrolling screen one line or page */
2256 if (ti->cl_cursor + dy < 0 ||
2257 ti->cl_cursor + dy > num_page_entries - 1)
2259 if (ABS(dy) == SCROLL_PAGE)
2260 step = num_page_entries - 1;
2262 if (dy < 0 && ti->cl_first > 0)
2264 /* scroll page/line up */
2266 ti->cl_first -= step;
2267 if (ti->cl_first < 0)
2270 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2271 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2272 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2273 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2276 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
2278 /* scroll page/line down */
2280 ti->cl_first += step;
2281 if (ti->cl_first + num_page_entries > num_entries)
2282 ti->cl_first = MAX(0, num_entries - num_page_entries);
2284 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2285 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2286 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2287 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2294 /* handle moving cursor one line */
2295 y = ti->cl_cursor + dy;
2300 TreeInfo *node_first, *node_cursor;
2301 int entry_pos = ti->cl_first + y;
2303 node_first = getTreeInfoFirstGroupEntry(ti);
2304 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2306 if (node_cursor->node_group)
2308 node_cursor->cl_first = ti->cl_first;
2309 node_cursor->cl_cursor = ti->cl_cursor;
2310 *ti_ptr = node_cursor->node_group;
2311 DrawChooseTree(ti_ptr);
2316 else if (dx == -1 && ti->node_parent)
2318 *ti_ptr = ti->node_parent;
2319 DrawChooseTree(ti_ptr);
2324 if (!anyScrollbarGadgetActive() &&
2325 IN_VIS_FIELD(x, y) &&
2326 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2327 y >= 0 && y < num_page_entries)
2331 if (y != ti->cl_cursor)
2333 drawChooseTreeCursor(y, FC_RED);
2334 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
2335 drawChooseTreeInfo(ti->cl_first + y, ti);
2341 TreeInfo *node_first, *node_cursor;
2342 int entry_pos = ti->cl_first + y;
2344 node_first = getTreeInfoFirstGroupEntry(ti);
2345 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2347 if (node_cursor->node_group)
2349 node_cursor->cl_first = ti->cl_first;
2350 node_cursor->cl_cursor = ti->cl_cursor;
2351 *ti_ptr = node_cursor->node_group;
2352 DrawChooseTree(ti_ptr);
2354 else if (node_cursor->parent_link)
2356 *ti_ptr = node_cursor->node_parent;
2357 DrawChooseTree(ti_ptr);
2361 node_cursor->cl_first = ti->cl_first;
2362 node_cursor->cl_cursor = ti->cl_cursor;
2363 *ti_ptr = node_cursor;
2365 if (ti->type == TREE_TYPE_LEVEL_DIR)
2367 LoadLevelSetup_SeriesInfo();
2369 SaveLevelSetup_LastSeries();
2370 SaveLevelSetup_SeriesInfo();
2374 if (game_status == GAME_MODE_SETUP)
2376 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2377 execSetupGraphics();
2383 game_status = GAME_MODE_MAIN;
2391 void DrawChooseLevel()
2393 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2395 DrawChooseTree(&leveldir_current);
2401 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2403 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2408 void DrawHallOfFame(int highlight_position)
2411 FadeSoundsAndMusic();
2412 CloseDoor(DOOR_CLOSE_2);
2414 if (highlight_position < 0)
2415 LoadScore(level_nr);
2423 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2426 static void drawHallOfFameList(int first_entry, int highlight_position)
2430 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2434 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2435 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2436 "HighScores of Level %d", level_nr);
2438 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2439 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2440 "HighScores of Level %d", level_nr);
2443 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2445 int entry = first_entry + i;
2446 boolean active = (entry == highlight_position);
2447 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2448 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2449 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2450 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2451 int dx1 = 3 * getFontWidth(font_nr1);
2452 int dx2 = dx1 + getFontWidth(font_nr1);
2453 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2454 int sy = mSY + 64 + i * 32;
2456 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2457 DrawText(mSX + dx1, sy, ".", font_nr1);
2458 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2460 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2461 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2463 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2466 redraw_mask |= REDRAW_FIELD;
2469 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2471 static int first_entry = 0;
2472 static int highlight_position = 0;
2473 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2474 int button_released = !button;
2476 if (button == MB_MENU_INITIALIZE)
2479 highlight_position = mx;
2480 drawHallOfFameList(first_entry, highlight_position);
2485 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2486 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2490 if (first_entry > 0)
2492 first_entry -= step;
2493 if (first_entry < 0)
2496 drawHallOfFameList(first_entry, highlight_position);
2501 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2503 first_entry += step;
2504 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2505 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2507 drawHallOfFameList(first_entry, highlight_position);
2510 else if (button_released)
2512 FadeSound(SND_BACKGROUND_SCORES);
2513 game_status = GAME_MODE_MAIN;
2517 if (game_status == GAME_MODE_SCORES)
2518 PlayMenuSoundIfLoop();
2524 /* ========================================================================= */
2525 /* setup screen functions */
2526 /* ========================================================================= */
2528 static struct TokenInfo *setup_info;
2529 static int num_setup_info;
2531 static char *screen_mode_text;
2532 static char *graphics_set_name;
2533 static char *sounds_set_name;
2534 static char *music_set_name;
2536 static void execSetupMain()
2538 setup_mode = SETUP_MODE_MAIN;
2542 static void execSetupGame()
2544 setup_mode = SETUP_MODE_GAME;
2548 static void execSetupEditor()
2550 setup_mode = SETUP_MODE_EDITOR;
2554 static void execSetupGraphics()
2556 if (video.fullscreen_available && screen_modes == NULL)
2560 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
2562 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
2563 char identifier[20], name[20];
2564 int x = video.fullscreen_modes[i].width;
2565 int y = video.fullscreen_modes[i].height;
2567 ti->node_top = &screen_modes;
2568 ti->sort_priority = x * y;
2570 sprintf(identifier, "%dx%d", x, y);
2571 sprintf(name, "%d x %d", x, y);
2573 setString(&ti->identifier, identifier);
2574 setString(&ti->name, name);
2575 setString(&ti->name_sorting, name);
2576 setString(&ti->infotext, "Fullscreen Mode");
2578 pushTreeInfo(&screen_modes, ti);
2581 sortTreeInfo(&screen_modes);
2583 /* set current screen mode for fullscreen mode to reliable default value */
2584 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2585 DEFAULT_FULLSCREEN_MODE);
2586 if (screen_mode_current == NULL)
2587 screen_mode_current = screen_modes;
2589 if (screen_mode_current == NULL)
2590 video.fullscreen_available = FALSE;
2593 if (video.fullscreen_available)
2595 setup.fullscreen_mode = screen_mode_current->identifier;
2597 /* needed for displaying screen mode name instead of identifier */
2598 screen_mode_text = screen_mode_current->name;
2601 setup_mode = SETUP_MODE_GRAPHICS;
2605 static void execSetupChooseScreenMode()
2607 if (!video.fullscreen_available)
2610 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
2614 static void execSetupSound()
2616 setup_mode = SETUP_MODE_SOUND;
2620 static void execSetupArtwork()
2622 setup.graphics_set = artwork.gfx_current->identifier;
2623 setup.sounds_set = artwork.snd_current->identifier;
2624 setup.music_set = artwork.mus_current->identifier;
2626 /* needed if last screen (setup choice) changed graphics, sounds or music */
2627 ReloadCustomArtwork(0);
2629 /* needed for displaying artwork name instead of artwork identifier */
2630 graphics_set_name = artwork.gfx_current->name;
2631 sounds_set_name = artwork.snd_current->name;
2632 music_set_name = artwork.mus_current->name;
2634 setup_mode = SETUP_MODE_ARTWORK;
2638 static void execSetupChooseGraphics()
2640 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2644 static void execSetupChooseSounds()
2646 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2650 static void execSetupChooseMusic()
2652 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2656 static void execSetupInput()
2658 setup_mode = SETUP_MODE_INPUT;
2662 static void execSetupShortcut1()
2664 setup_mode = SETUP_MODE_SHORTCUT_1;
2668 static void execSetupShortcut2()
2670 setup_mode = SETUP_MODE_SHORTCUT_2;
2674 static void execExitSetup()
2676 game_status = GAME_MODE_MAIN;
2680 static void execSaveAndExitSetup()
2686 static struct TokenInfo setup_info_main[] =
2688 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2689 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2690 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2691 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2692 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2693 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2694 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2695 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2696 { TYPE_EMPTY, NULL, "" },
2697 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2698 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2703 static struct TokenInfo setup_info_game[] =
2705 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2706 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2707 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2708 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2709 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2710 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2711 { TYPE_EMPTY, NULL, "" },
2712 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2717 static struct TokenInfo setup_info_editor[] =
2720 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2721 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2722 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2723 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2724 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2725 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2726 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2727 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2729 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2730 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2732 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2734 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2735 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2736 { TYPE_EMPTY, NULL, "" },
2738 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
2739 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
2740 { TYPE_EMPTY, NULL, "" },
2742 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2743 { TYPE_EMPTY, NULL, "" },
2744 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2749 static struct TokenInfo setup_info_graphics[] =
2751 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2752 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
2753 { TYPE_STRING, &screen_mode_text, "" },
2754 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2756 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2757 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2758 { TYPE_SWITCH, &setup.fading, "Fading:" },
2760 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2761 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2762 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2763 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2764 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2765 { TYPE_EMPTY, NULL, "" },
2766 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2771 static struct TokenInfo setup_info_sound[] =
2773 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2774 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2775 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2776 { TYPE_EMPTY, NULL, "" },
2777 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2782 static struct TokenInfo setup_info_artwork[] =
2784 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
2785 { TYPE_STRING, &graphics_set_name, "" },
2786 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
2787 { TYPE_STRING, &sounds_set_name, "" },
2788 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
2789 { TYPE_STRING, &music_set_name, "" },
2790 { TYPE_EMPTY, NULL, "" },
2792 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2793 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2794 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2796 { TYPE_STRING, NULL, "Override Level Artwork:"},
2797 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2798 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2799 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2801 { TYPE_EMPTY, NULL, "" },
2802 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2807 static struct TokenInfo setup_info_shortcut_1[] =
2809 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2810 { TYPE_KEY, &setup.shortcut.save_game, "" },
2811 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2812 { TYPE_KEY, &setup.shortcut.load_game, "" },
2813 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2814 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2815 { TYPE_EMPTY, NULL, "" },
2816 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2817 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2818 { TYPE_EMPTY, NULL, "" },
2819 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2824 static struct TokenInfo setup_info_shortcut_2[] =
2826 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2827 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2828 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2829 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2830 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2831 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2832 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2833 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2834 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2835 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2836 { TYPE_EMPTY, NULL, "" },
2837 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2842 static Key getSetupKey()
2844 Key key = KSYM_UNDEFINED;
2845 boolean got_key_event = FALSE;
2847 while (!got_key_event)
2849 if (PendingEvent()) /* got event */
2857 case EVENT_KEYPRESS:
2859 key = GetEventKey((KeyEvent *)&event, TRUE);
2861 /* press 'Escape' or 'Enter' to keep the existing key binding */
2862 if (key == KSYM_Escape || key == KSYM_Return)
2863 key = KSYM_UNDEFINED; /* keep old value */
2865 got_key_event = TRUE;
2869 case EVENT_KEYRELEASE:
2870 key_joystick_mapping = 0;
2874 HandleOtherEvents(&event);
2882 /* don't eat all CPU time */
2889 static int getSetupTextFont(int type)
2891 if (type & (TYPE_SWITCH |
2902 static int getSetupValueFont(int type, void *value)
2904 if (type & TYPE_KEY)
2905 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2906 else if (type & TYPE_STRING)
2907 return FONT_VALUE_2;
2908 else if (type & TYPE_ECS_AGA)
2909 return FONT_VALUE_1;
2910 else if (type & TYPE_BOOLEAN_STYLE)
2911 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2913 return FONT_VALUE_1;
2916 static void drawSetupValue(int pos)
2918 boolean font_draw_xoffset_modified = FALSE;
2919 int font_draw_xoffset_old = -1;
2920 int xpos = MENU_SCREEN_VALUE_XPOS;
2921 int ypos = MENU_SCREEN_START_YPOS + pos;
2922 int startx = mSX + xpos * 32;
2923 int starty = mSY + ypos * 32;
2924 int font_nr, font_width;
2925 int type = setup_info[pos].type;
2926 void *value = setup_info[pos].value;
2927 char *value_string = getSetupValue(type, value);
2930 if (value_string == NULL)
2933 if (type & TYPE_KEY)
2936 xpos = MENU_SCREEN_START_XPOS;
2941 if (type & TYPE_QUERY)
2943 value_string = "<press key>";
2945 font_nr = FONT_INPUT_1_ACTIVE;
2949 else if (type & TYPE_STRING)
2951 int max_value_len = (SCR_FIELDX - 2) * 2;
2953 xpos = MENU_SCREEN_START_XPOS;
2955 font_nr = FONT_VALUE_2;
2958 if (strlen(value_string) > max_value_len)
2959 value_string[max_value_len] = '\0';
2961 else if (type & TYPE_ECS_AGA)
2964 font_nr = FONT_VALUE_1;
2967 else if (type & TYPE_BOOLEAN_STYLE)
2970 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2974 startx = mSX + xpos * 32;
2975 starty = mSY + ypos * 32;
2976 font_nr = getSetupValueFont(type, value);
2977 font_width = getFontWidth(font_nr);
2979 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2980 if (setup_mode != SETUP_MODE_INPUT)
2982 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
2983 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2984 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
2985 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
2986 int text_font_nr = getSetupTextFont(FONT_MENU_2);
2987 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
2988 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
2989 boolean correct_font_draw_xoffset = FALSE;
2991 if (xpos == MENU_SCREEN_START_XPOS &&
2992 startx + font1_xoffset < text_startx + text_font_xoffset)
2993 correct_font_draw_xoffset = TRUE;
2995 if (xpos == MENU_SCREEN_VALUE_XPOS &&
2996 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
2997 correct_font_draw_xoffset = TRUE;
3000 printf("::: %d + %d < %d + %d + %d\n",
3001 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
3002 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
3005 /* check if setup value would overlap with setup text when printed */
3006 /* (this can happen for extreme/wrong values for font draw offset) */
3007 if (correct_font_draw_xoffset)
3009 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
3010 font_draw_xoffset_modified = TRUE;
3012 if (type & TYPE_KEY)
3013 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
3014 else if (!(type & TYPE_STRING))
3015 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
3016 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
3021 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
3022 DrawText(startx + i * font_width, starty, " ", font_nr);
3025 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
3026 DrawText(mSX + i * 32, starty, " ", font_nr);
3028 DrawText(startx, starty,
3029 (xpos == 3 ? " " : " "), font_nr);
3033 DrawText(startx, starty, value_string, font_nr);
3035 if (font_draw_xoffset_modified)
3036 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
3039 static void changeSetupValue(int pos)
3041 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
3043 *(boolean *)setup_info[pos].value ^= TRUE;
3045 else if (setup_info[pos].type & TYPE_KEY)
3049 setup_info[pos].type |= TYPE_QUERY;
3050 drawSetupValue(pos);
3051 setup_info[pos].type &= ~TYPE_QUERY;
3053 key = getSetupKey();
3054 if (key != KSYM_UNDEFINED)
3055 *(Key *)setup_info[pos].value = key;
3058 drawSetupValue(pos);
3061 static void DrawSetupScreen_Generic()
3063 char *title_string = NULL;
3067 CloseDoor(DOOR_CLOSE_2);
3071 if (setup_mode == SETUP_MODE_MAIN)
3073 setup_info = setup_info_main;
3074 title_string = "Setup";
3076 else if (setup_mode == SETUP_MODE_GAME)
3078 setup_info = setup_info_game;
3079 title_string = "Setup Game";
3081 else if (setup_mode == SETUP_MODE_EDITOR)
3083 setup_info = setup_info_editor;
3084 title_string = "Setup Editor";
3086 else if (setup_mode == SETUP_MODE_GRAPHICS)
3088 setup_info = setup_info_graphics;
3089 title_string = "Setup Graphics";
3091 else if (setup_mode == SETUP_MODE_SOUND)
3093 setup_info = setup_info_sound;
3094 title_string = "Setup Sound";
3096 else if (setup_mode == SETUP_MODE_ARTWORK)
3098 setup_info = setup_info_artwork;
3099 title_string = "Custom Artwork";
3101 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
3103 setup_info = setup_info_shortcut_1;
3104 title_string = "Setup Shortcuts";
3106 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
3108 setup_info = setup_info_shortcut_2;
3109 title_string = "Setup Shortcuts";
3113 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
3115 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
3119 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3121 void *value_ptr = setup_info[i].value;
3122 int xpos = MENU_SCREEN_START_XPOS;
3123 int ypos = MENU_SCREEN_START_YPOS + i;
3127 int font_nr = FONT_MENU_1;
3130 /* set some entries to "unchangeable" according to other variables */
3131 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
3132 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
3133 (value_ptr == &setup.sound_music && !audio.music_available) ||
3134 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
3135 (value_ptr == &screen_mode_text && !video.fullscreen_available))
3136 setup_info[i].type |= TYPE_GHOSTED;
3139 font_nr = getSetupTextFont(setup_info[i].type);
3142 if (setup_info[i].type & (TYPE_SWITCH |
3147 font_nr = FONT_MENU_2;
3149 if (setup_info[i].type & TYPE_STRING)
3150 font_nr = FONT_MENU_2;
3154 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
3156 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
3157 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3158 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
3159 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3160 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
3161 initCursor(i, IMG_MENU_BUTTON);
3163 if (setup_info[i].type & TYPE_VALUE)
3170 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3171 "Joysticks deactivated in setup menu");
3176 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
3179 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
3181 static int choice_store[MAX_SETUP_MODES];
3182 int choice = choice_store[setup_mode]; /* always starts with 0 */
3186 if (button == MB_MENU_INITIALIZE)
3188 /* advance to first valid menu entry */
3189 while (choice < num_setup_info &&
3190 setup_info[choice].type & TYPE_SKIP_ENTRY)
3192 choice_store[setup_mode] = choice;
3194 drawCursor(choice, FC_RED);
3197 else if (button == MB_MENU_LEAVE)
3199 for (y = 0; y < num_setup_info; y++)
3201 if (setup_info[y].type & TYPE_LEAVE_MENU)
3203 void (*menu_callback_function)(void) = setup_info[y].value;
3205 menu_callback_function();
3206 break; /* absolutely needed because function changes 'setup_info'! */
3213 if (mx || my) /* mouse input */
3215 x = (mx - mSX) / 32;
3216 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3218 else if (dx || dy) /* keyboard input */
3222 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE_MENU : TYPE_ENTER_MENU);
3224 if (setup_info[choice].type & menu_navigation_type ||
3225 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
3226 button = MB_MENU_CHOICE;
3231 /* jump to next non-empty menu entry (up or down) */
3232 while (y > 0 && y < num_setup_info - 1 &&
3233 setup_info[y].type & TYPE_SKIP_ENTRY)
3237 if (IN_VIS_FIELD(x, y) &&
3238 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3244 drawCursor(y, FC_RED);
3245 drawCursor(choice, FC_BLUE);
3246 choice = choice_store[setup_mode] = y;
3249 else if (!(setup_info[y].type & TYPE_GHOSTED))
3251 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3253 void (*menu_callback_function)(void) = setup_info[choice].value;
3255 menu_callback_function();
3259 if (setup_info[y].type & TYPE_KEYTEXT &&
3260 setup_info[y + 1].type & TYPE_KEY)
3263 if (setup_info[y].type & TYPE_VALUE)
3264 changeSetupValue(y);
3270 void DrawSetupScreen_Input()
3275 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
3277 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
3280 initCursor(0, IMG_MENU_BUTTON);
3281 initCursor(1, IMG_MENU_BUTTON);
3282 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
3283 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
3286 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
3287 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
3290 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
3291 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
3292 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
3295 DeactivateJoystickForCalibration();
3298 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3299 "Joysticks deactivated on this screen");
3303 /* create gadgets for setup input menu screen */
3304 FreeScreenGadgets();
3305 CreateScreenGadgets();
3307 /* map gadgets for setup input menu screen */
3308 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
3311 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
3316 static void setJoystickDeviceToNr(char *device_name, int device_nr)
3318 if (device_name == NULL)
3321 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
3324 if (strlen(device_name) > 1)
3326 char c1 = device_name[strlen(device_name) - 1];
3327 char c2 = device_name[strlen(device_name) - 2];
3329 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
3330 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
3333 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
3334 strlen(device_name));
3337 static void drawPlayerSetupInputInfo(int player_nr)
3340 static struct SetupKeyboardInfo custom_key;
3347 { &custom_key.left, "Joystick Left" },
3348 { &custom_key.right, "Joystick Right" },
3349 { &custom_key.up, "Joystick Up" },
3350 { &custom_key.down, "Joystick Down" },
3351 { &custom_key.snap, "Button 1" },
3352 { &custom_key.drop, "Button 2" }
3354 static char *joystick_name[MAX_PLAYERS] =
3364 custom_key = setup.input[player_nr].key;
3366 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
3367 FONT_INPUT_1_ACTIVE);
3369 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3371 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3372 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
3374 if (setup.input[player_nr].use_joystick)
3376 char *device_name = setup.input[player_nr].joy.device_name;
3377 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
3378 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
3380 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
3381 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
3385 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
3386 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
3389 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
3390 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
3391 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
3392 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
3393 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
3394 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
3395 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
3396 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
3397 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
3398 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
3399 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
3401 for (i = 0; i < 6; i++)
3403 int ypos = 6 + i + (i > 3 ? i-3 : 0);
3405 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3407 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3408 (setup.input[player_nr].use_joystick ?
3410 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
3414 static int input_player_nr = 0;
3416 void HandleSetupScreen_Input_Player(int step, int direction)
3418 int old_player_nr = input_player_nr;
3421 new_player_nr = old_player_nr + step * direction;
3422 if (new_player_nr < 0)
3424 if (new_player_nr > MAX_PLAYERS - 1)
3425 new_player_nr = MAX_PLAYERS - 1;
3427 if (new_player_nr != old_player_nr)
3429 input_player_nr = new_player_nr;
3431 drawPlayerSetupInputInfo(input_player_nr);
3435 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
3437 static int choice = 0;
3440 int pos_start = SETUPINPUT_SCREEN_POS_START;
3441 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
3442 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
3443 int pos_end = SETUPINPUT_SCREEN_POS_END;
3445 if (button == MB_MENU_INITIALIZE)
3447 drawPlayerSetupInputInfo(input_player_nr);
3448 drawCursor(choice, FC_RED);
3452 else if (button == MB_MENU_LEAVE)
3454 setup_mode = SETUP_MODE_MAIN;
3461 if (mx || my) /* mouse input */
3463 x = (mx - mSX) / 32;
3464 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3466 else if (dx || dy) /* keyboard input */
3468 if (dx && choice == 0)
3469 x = (dx < 0 ? 10 : 12);
3470 else if ((dx && choice == 1) ||
3471 (dx == +1 && choice == 2) ||
3472 (dx == -1 && choice == pos_end))
3473 button = MB_MENU_CHOICE;
3477 if (y >= pos_empty1 && y <= pos_empty2)
3478 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
3483 if (y == 0 && dx != 0 && button)
3485 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
3490 if (IN_VIS_FIELD(x, y) &&
3491 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
3493 static unsigned long delay = 0;
3495 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3499 (input_player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3501 drawPlayerSetupInputInfo(input_player_nr);
3506 else if (IN_VIS_FIELD(x, y) &&
3507 y >= pos_start && y <= pos_end &&
3508 !(y >= pos_empty1 && y <= pos_empty2))
3514 drawCursor(y, FC_RED);
3515 drawCursor(choice, FC_BLUE);
3523 char *device_name = setup.input[input_player_nr].joy.device_name;
3525 if (!setup.input[input_player_nr].use_joystick)
3527 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3529 setJoystickDeviceToNr(device_name, new_device_nr);
3530 setup.input[input_player_nr].use_joystick = TRUE;
3534 int device_nr = getJoystickNrFromDeviceName(device_name);
3535 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3537 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3538 setup.input[input_player_nr].use_joystick = FALSE;
3540 setJoystickDeviceToNr(device_name, new_device_nr);
3543 drawPlayerSetupInputInfo(input_player_nr);
3547 if (setup.input[input_player_nr].use_joystick)
3550 CalibrateJoystick(input_player_nr);
3553 CustomizeKeyboard(input_player_nr);
3555 else if (y == pos_end)
3559 setup_mode = SETUP_MODE_MAIN;
3566 void CustomizeKeyboard(int player_nr)
3570 boolean finished = FALSE;
3571 static struct SetupKeyboardInfo custom_key;
3576 } customize_step[] =
3578 { &custom_key.left, "Move Left" },
3579 { &custom_key.right, "Move Right" },
3580 { &custom_key.up, "Move Up" },
3581 { &custom_key.down, "Move Down" },
3582 { &custom_key.snap, "Snap Field" },
3583 { &custom_key.drop, "Drop Element" }
3586 /* read existing key bindings from player setup */
3587 custom_key = setup.input[player_nr].key;
3592 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3594 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3601 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3602 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3603 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3604 "Key:", FONT_INPUT_1_ACTIVE);
3605 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3606 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3610 if (PendingEvent()) /* got event */
3618 case EVENT_KEYPRESS:
3620 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3622 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3628 /* all keys configured -- wait for "Escape" or "Return" key */
3632 /* press 'Enter' to keep the existing key binding */
3633 if (key == KSYM_Return)
3634 key = *customize_step[step_nr].key;
3636 /* check if key already used */
3637 for (i = 0; i < step_nr; i++)
3638 if (*customize_step[i].key == key)
3643 /* got new key binding */
3644 *customize_step[step_nr].key = key;
3645 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3647 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3648 getKeyNameFromKey(key), FONT_VALUE_1);
3651 /* un-highlight last query */
3652 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3653 customize_step[step_nr - 1].text, FONT_MENU_1);
3654 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3655 "Key:", FONT_MENU_1);
3657 /* press 'Enter' to leave */
3660 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3661 "Press Enter", FONT_TITLE_1);
3665 /* query next key binding */
3666 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3667 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3668 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3669 "Key:", FONT_INPUT_1_ACTIVE);
3670 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3671 getKeyNameFromKey(*customize_step[step_nr].key),
3676 case EVENT_KEYRELEASE:
3677 key_joystick_mapping = 0;
3681 HandleOtherEvents(&event);
3689 /* don't eat all CPU time */
3693 /* write new key bindings back to player setup */
3694 setup.input[player_nr].key = custom_key;
3697 DrawSetupScreen_Input();
3700 static boolean CalibrateJoystickMain(int player_nr)
3702 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3703 int new_joystick_xright = JOYSTICK_XMIDDLE;
3704 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3705 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3706 int new_joystick_xmiddle, new_joystick_ymiddle;
3708 int joystick_fd = joystick.fd[player_nr];
3709 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3710 boolean check[3][3];
3711 int check_remaining = 3 * 3;
3716 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3719 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3724 for (y = 0; y < 3; y++)
3726 for (x = 0; x < 3; x++)
3728 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3729 check[x][y] = FALSE;
3733 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3734 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3735 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3736 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3737 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3738 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3739 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3741 joy_value = Joystick(player_nr);
3742 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3743 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3745 /* eventually uncalibrated center position (joystick could be uncentered) */
3746 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3749 new_joystick_xmiddle = joy_x;
3750 new_joystick_ymiddle = joy_y;
3752 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3755 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3760 if (PendingEvent()) /* got event */
3768 case EVENT_KEYPRESS:
3769 switch(GetEventKey((KeyEvent *)&event, TRUE))
3772 if (check_remaining == 0)
3785 case EVENT_KEYRELEASE:
3786 key_joystick_mapping = 0;
3790 HandleOtherEvents(&event);
3795 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3798 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3799 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3800 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3801 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3803 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3804 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3805 setup.input[player_nr].joy.xright = new_joystick_xright;
3806 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3807 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3808 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3810 CheckJoystickData();
3812 joy_value = Joystick(player_nr);
3814 if (joy_value & JOY_BUTTON && check_remaining == 0)
3817 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3818 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3820 if (x != last_x || y != last_y)
3822 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3823 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3828 if (check_remaining > 0 && !check[x+1][y+1])
3830 check[x+1][y+1] = TRUE;
3836 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3837 setup.input[player_nr].joy.xleft,
3838 setup.input[player_nr].joy.xmiddle,
3839 setup.input[player_nr].joy.xright);
3840 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3841 setup.input[player_nr].joy.yupper,
3842 setup.input[player_nr].joy.ymiddle,
3843 setup.input[player_nr].joy.ylower);
3852 /* don't eat all CPU time */
3856 /* calibrated center position (joystick should now be centered) */
3857 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3860 new_joystick_xmiddle = joy_x;
3861 new_joystick_ymiddle = joy_y;
3866 DrawSetupScreen_Input();
3869 /* wait until the last pressed button was released */
3870 while (Joystick(player_nr) & JOY_BUTTON)
3872 if (PendingEvent()) /* got event */
3877 HandleOtherEvents(&event);
3886 void CalibrateJoystick(int player_nr)
3888 if (!CalibrateJoystickMain(player_nr))
3890 char *device_name = setup.input[player_nr].joy.device_name;
3891 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3892 int xpos = mSX - SX;
3893 int ypos = mSY - SY;
3897 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3898 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3901 Delay(2000); /* show error message for a short time */
3907 DrawSetupScreen_Input();
3911 void DrawSetupScreen()
3913 DeactivateJoystick();
3915 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3917 if (setup_mode == SETUP_MODE_INPUT)
3918 DrawSetupScreen_Input();
3919 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3920 DrawChooseTree(&screen_mode_current);
3921 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3922 DrawChooseTree(&artwork.gfx_current);
3923 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3924 DrawChooseTree(&artwork.snd_current);
3925 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3926 DrawChooseTree(&artwork.mus_current);
3928 DrawSetupScreen_Generic();
3934 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3936 if (setup_mode == SETUP_MODE_INPUT)
3937 HandleSetupScreen_Input(mx, my, dx, dy, button);
3938 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3939 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
3940 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3941 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3942 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3943 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3944 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3945 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3947 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3952 void HandleGameActions()
3954 if (game_status != GAME_MODE_PLAYING)
3957 GameActions(); /* main game loop */
3959 if (tape.auto_play && !tape.playing)
3960 AutoPlayTape(); /* continue automatically playing next tape */
3964 /* ---------- new screen button stuff -------------------------------------- */
3966 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
3970 case SCREEN_CTRL_ID_LAST_LEVEL:
3971 *x = mSX + TILEX * getLastLevelButtonPos();
3972 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
3975 case SCREEN_CTRL_ID_NEXT_LEVEL:
3976 *x = mSX + TILEX * getNextLevelButtonPos();
3977 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
3980 case SCREEN_CTRL_ID_LAST_PLAYER:
3981 *x = mSX + TILEX * 10;
3982 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
3985 case SCREEN_CTRL_ID_NEXT_PLAYER:
3986 *x = mSX + TILEX * 12;
3987 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
3991 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
3997 int gfx_unpressed, gfx_pressed;
3998 void (*get_gadget_position)(int *, int *, int);
4002 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
4005 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
4006 getScreenMenuButtonPos,
4007 SCREEN_CTRL_ID_LAST_LEVEL,
4012 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
4013 getScreenMenuButtonPos,
4014 SCREEN_CTRL_ID_NEXT_LEVEL,
4019 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
4020 getScreenMenuButtonPos,
4021 SCREEN_CTRL_ID_LAST_PLAYER,
4026 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
4027 getScreenMenuButtonPos,
4028 SCREEN_CTRL_ID_NEXT_PLAYER,
4036 int gfx_unpressed, gfx_pressed;
4040 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
4043 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
4044 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
4045 SCREEN_CTRL_ID_SCROLL_UP,
4049 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
4050 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
4051 SCREEN_CTRL_ID_SCROLL_DOWN,
4058 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4059 Bitmap **gfx_unpressed, **gfx_pressed;
4061 int gfx_unpressed, gfx_pressed;
4068 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
4071 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4072 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
4074 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
4076 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
4077 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
4078 GD_TYPE_SCROLLBAR_VERTICAL,
4079 SCREEN_CTRL_ID_SCROLL_VERTICAL,
4080 "scroll level series vertically"
4084 static void CreateScreenMenubuttons()
4086 struct GadgetInfo *gi;
4087 unsigned long event_mask;
4090 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4092 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4093 int gfx_unpressed, gfx_pressed;
4094 int x, y, width, height;
4095 int gd_x1, gd_x2, gd_y1, gd_y2;
4096 int id = menubutton_info[i].gadget_id;
4098 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4100 menubutton_info[i].get_gadget_position(&x, &y, id);
4102 width = SC_MENUBUTTON_XSIZE;
4103 height = SC_MENUBUTTON_YSIZE;
4105 gfx_unpressed = menubutton_info[i].gfx_unpressed;
4106 gfx_pressed = menubutton_info[i].gfx_pressed;
4107 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4108 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4109 gd_x1 = graphic_info[gfx_unpressed].src_x;
4110 gd_y1 = graphic_info[gfx_unpressed].src_y;
4111 gd_x2 = graphic_info[gfx_pressed].src_x;
4112 gd_y2 = graphic_info[gfx_pressed].src_y;
4114 gi = CreateGadget(GDI_CUSTOM_ID, id,
4115 GDI_CUSTOM_TYPE_ID, i,
4116 GDI_INFO_TEXT, menubutton_info[i].infotext,
4121 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4122 GDI_STATE, GD_BUTTON_UNPRESSED,
4123 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4124 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4125 GDI_DIRECT_DRAW, FALSE,
4126 GDI_EVENT_MASK, event_mask,
4127 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4131 Error(ERR_EXIT, "cannot create gadget");
4133 screen_gadget[id] = gi;
4137 static void CreateScreenScrollbuttons()
4139 struct GadgetInfo *gi;
4140 unsigned long event_mask;
4143 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4145 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4146 int gfx_unpressed, gfx_pressed;
4147 int x, y, width, height;
4148 int gd_x1, gd_x2, gd_y1, gd_y2;
4149 int id = scrollbutton_info[i].gadget_id;
4151 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4153 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
4154 y = mSY + scrollbutton_info[i].y;
4155 width = SC_SCROLLBUTTON_XSIZE;
4156 height = SC_SCROLLBUTTON_YSIZE;
4158 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
4159 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
4160 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
4162 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
4163 gfx_pressed = scrollbutton_info[i].gfx_pressed;
4164 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4165 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4166 gd_x1 = graphic_info[gfx_unpressed].src_x;
4167 gd_y1 = graphic_info[gfx_unpressed].src_y;
4168 gd_x2 = graphic_info[gfx_pressed].src_x;
4169 gd_y2 = graphic_info[gfx_pressed].src_y;
4171 gi = CreateGadget(GDI_CUSTOM_ID, id,
4172 GDI_CUSTOM_TYPE_ID, i,
4173 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4178 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4179 GDI_STATE, GD_BUTTON_UNPRESSED,
4180 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4181 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4182 GDI_DIRECT_DRAW, FALSE,
4183 GDI_EVENT_MASK, event_mask,
4184 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4188 Error(ERR_EXIT, "cannot create gadget");
4190 screen_gadget[id] = gi;
4194 static void CreateScreenScrollbars()
4198 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4200 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4201 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4202 int gfx_unpressed, gfx_pressed;
4204 int x, y, width, height;
4205 int gd_x1, gd_x2, gd_y1, gd_y2;
4206 struct GadgetInfo *gi;
4207 int items_max, items_visible, item_position;
4208 unsigned long event_mask;
4209 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4210 int id = scrollbar_info[i].gadget_id;
4212 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
4214 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
4215 y = mSY + scrollbar_info[i].y;
4216 width = scrollbar_info[i].width;
4217 height = scrollbar_info[i].height;
4219 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
4220 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
4222 items_max = num_page_entries;
4223 items_visible = num_page_entries;
4226 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4227 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
4228 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
4234 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
4235 gfx_pressed = scrollbar_info[i].gfx_pressed;
4236 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4237 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4238 gd_x1 = graphic_info[gfx_unpressed].src_x;
4239 gd_y1 = graphic_info[gfx_unpressed].src_y;
4240 gd_x2 = graphic_info[gfx_pressed].src_x;
4241 gd_y2 = graphic_info[gfx_pressed].src_y;
4244 gi = CreateGadget(GDI_CUSTOM_ID, id,
4245 GDI_CUSTOM_TYPE_ID, i,
4246 GDI_INFO_TEXT, scrollbar_info[i].infotext,
4251 GDI_TYPE, scrollbar_info[i].type,
4252 GDI_SCROLLBAR_ITEMS_MAX, items_max,
4253 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
4254 GDI_SCROLLBAR_ITEM_POSITION, item_position,
4255 GDI_WHEEL_AREA_X, 0,
4256 GDI_WHEEL_AREA_Y, 0,
4257 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
4258 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
4259 GDI_STATE, GD_BUTTON_UNPRESSED,
4260 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4261 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4262 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
4263 GDI_DIRECT_DRAW, FALSE,
4264 GDI_EVENT_MASK, event_mask,
4265 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4269 Error(ERR_EXIT, "cannot create gadget");
4271 screen_gadget[id] = gi;
4275 void CreateScreenGadgets()
4277 int last_game_status = game_status; /* save current game status */
4279 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4282 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4284 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
4286 /* copy pointers to clip mask and GC */
4287 scrollbar_bitmap[i]->clip_mask =
4288 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
4289 scrollbar_bitmap[i]->stored_clip_gc =
4290 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
4292 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
4293 scrollbar_bitmap[i],
4294 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
4295 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
4296 TILEX, TILEY, 0, 0);
4300 CreateScreenMenubuttons();
4302 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
4303 game_status = GAME_MODE_LEVELS;
4305 CreateScreenScrollbuttons();
4306 CreateScreenScrollbars();
4308 game_status = last_game_status; /* restore current game status */
4311 void FreeScreenGadgets()
4315 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4316 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4318 /* prevent freeing clip mask and GC twice */
4319 scrollbar_bitmap[i]->clip_mask = None;
4320 scrollbar_bitmap[i]->stored_clip_gc = None;
4322 FreeBitmap(scrollbar_bitmap[i]);
4326 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
4327 FreeGadget(screen_gadget[i]);
4330 void MapScreenMenuGadgets(int screen_mask)
4334 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4335 if (screen_mask & menubutton_info[i].screen_mask)
4336 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
4339 void MapScreenTreeGadgets(TreeInfo *ti)
4341 int num_entries = numTreeInfoInGroup(ti);
4344 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4347 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4348 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
4350 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4351 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
4354 static void HandleScreenGadgets(struct GadgetInfo *gi)
4356 int id = gi->custom_id;
4357 int button = gi->event.button;
4358 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4361 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
4367 case SCREEN_CTRL_ID_LAST_LEVEL:
4368 HandleMainMenu_SelectLevel(step, -1);
4371 case SCREEN_CTRL_ID_NEXT_LEVEL:
4372 HandleMainMenu_SelectLevel(step, +1);
4375 case SCREEN_CTRL_ID_LAST_PLAYER:
4376 HandleSetupScreen_Input_Player(step, -1);
4379 case SCREEN_CTRL_ID_NEXT_PLAYER:
4380 HandleSetupScreen_Input_Player(step, +1);
4383 case SCREEN_CTRL_ID_SCROLL_UP:
4384 if (game_status == GAME_MODE_LEVELS)
4385 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4386 else if (game_status == GAME_MODE_SETUP)
4387 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4390 case SCREEN_CTRL_ID_SCROLL_DOWN:
4391 if (game_status == GAME_MODE_LEVELS)
4392 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4393 else if (game_status == GAME_MODE_SETUP)
4394 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4397 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
4398 if (game_status == GAME_MODE_LEVELS)
4399 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
4400 else if (game_status == GAME_MODE_SETUP)
4401 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);