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
118 #define TITLE_SCREEN_FADE_DELAY 250
121 /* forward declarations of internal functions */
122 static void HandleScreenGadgets(struct GadgetInfo *);
123 static void HandleSetupScreen_Generic(int, int, int, int, int);
124 static void HandleSetupScreen_Input(int, int, int, int, int);
125 static void CustomizeKeyboard(int);
126 static void CalibrateJoystick(int);
127 static void execSetupGraphics(void);
128 static void execSetupArtwork(void);
129 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
131 static void DrawChooseLevel(void);
132 static void DrawInfoScreen(void);
133 static void DrawSetupScreen(void);
135 static void DrawInfoScreenExt(int);
136 static void DrawInfoScreen_NotAvailable(char *, char *);
137 static void DrawInfoScreen_HelpAnim(int, int, boolean);
138 static void DrawInfoScreen_HelpText(int, int, int, int);
139 static void HandleInfoScreen_Main(int, int, int, int, int);
140 static void HandleInfoScreen_TitleScreen(int);
141 static void HandleInfoScreen_Elements(int);
142 static void HandleInfoScreen_Music(int);
143 static void HandleInfoScreen_Credits(int);
144 static void HandleInfoScreen_Program(int);
146 static void MapScreenMenuGadgets(int);
147 static void MapScreenTreeGadgets(TreeInfo *);
149 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
150 static int setup_mode = SETUP_MODE_MAIN;
151 static int info_mode = INFO_MODE_MAIN;
153 static TreeInfo *screen_modes = NULL;
154 static TreeInfo *screen_mode_current = NULL;
156 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
157 x <= GAME_MODE_SETUP ? x : \
158 x == GAME_MODE_PSEUDO_TYPENAME ? \
159 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
161 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
162 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
164 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
165 menu.list_size[game_status] : \
166 MAX_MENU_ENTRIES_ON_SCREEN)
168 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
169 #define NUM_SCROLLBAR_BITMAPS 2
170 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
174 static void drawCursorExt(int xpos, int ypos, int color, int g)
176 static int cursor_array[SCR_FIELDY];
181 cursor_array[ypos] = g;
183 g = cursor_array[ypos];
187 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
188 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
189 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
190 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
191 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
192 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
193 IMG_MENU_BUTTON_ACTIVE);
195 ypos += MENU_SCREEN_START_YPOS;
197 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
198 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
201 static void initCursor(int ypos, int graphic)
203 drawCursorExt(0, ypos, FC_BLUE, graphic);
206 static void drawCursor(int ypos, int color)
208 drawCursorExt(0, ypos, color, 0);
211 static void drawCursorXY(int xpos, int ypos, int graphic)
213 drawCursorExt(xpos, ypos, -1, graphic);
216 static void drawChooseTreeCursor(int ypos, int color)
218 int last_game_status = game_status; /* save current game status */
220 /* force LEVELS draw offset on artwork setup screen */
221 game_status = GAME_MODE_LEVELS;
223 drawCursorExt(0, ypos, color, 0);
225 game_status = last_game_status; /* restore current game status */
230 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
231 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
234 static int getLastLevelButtonPos()
239 static int getCurrentLevelTextPos()
241 return (getLastLevelButtonPos() + 1);
244 static int getNextLevelButtonPos()
246 return getLastLevelButtonPos() + 3 + 1;
249 static int getLevelRangeTextPos()
251 return getNextLevelButtonPos() + 1;
254 void DrawTitleScreenImage(int nr)
256 int graphic = IMG_TITLESCREEN_1 + nr;
257 Bitmap *bitmap = graphic_info[graphic].bitmap;
258 int width = graphic_info[graphic].src_image_width;
259 int height = graphic_info[graphic].src_image_height;
260 int src_x = 0, src_y = 0;
266 if (width > WIN_XSIZE)
268 /* image width too large for window => center image horizontally */
269 src_x = (width - WIN_XSIZE) / 2;
273 if (height > WIN_YSIZE)
275 /* image height too large for window => center image vertically */
276 src_y = (height - WIN_YSIZE) / 2;
280 dst_x = (WIN_XSIZE - width) / 2;
281 dst_y = (WIN_YSIZE - height) / 2;
283 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
285 if (DrawingOnBackground(dst_x, dst_y))
286 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
288 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
290 redraw_mask = REDRAW_ALL;
293 void DrawTitleScreen()
295 KeyboardAutoRepeatOff();
297 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
299 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
304 static void DrawMainMenuExt(int fade_delay)
306 static LevelDirTree *leveldir_last_valid = NULL;
307 boolean levelset_has_changed = FALSE;
308 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
310 char *level_text = "Levelset";
312 char *level_text = "Level:";
314 int name_width, level_width;
318 FadeSoundsAndMusic();
320 KeyboardAutoRepeatOn();
323 SetDrawDeactivationMask(REDRAW_NONE);
324 SetDrawBackgroundMask(REDRAW_FIELD);
326 audio.sound_deactivated = FALSE;
332 /* needed if last screen was the playing screen, invoked from level editor */
333 if (level_editor_test_game)
335 game_status = GAME_MODE_EDITOR;
341 /* needed if last screen was the editor screen */
342 UndrawSpecialEditorDoor();
344 /* needed if last screen was the setup screen and fullscreen state changed */
345 ToggleFullscreenIfNeeded();
347 /* leveldir_current may be invalid (level group, parent link) */
348 if (!validLevelSeries(leveldir_current))
349 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
351 if (leveldir_current != leveldir_last_valid)
352 levelset_has_changed = TRUE;
354 /* store valid level series information */
355 leveldir_last_valid = leveldir_current;
357 /* needed if last screen (level choice) changed graphics, sounds or music */
358 ReloadCustomArtwork(0);
361 SetDrawtoField(DRAW_BACKBUFFER);
364 if (setup.show_titlescreen &&
365 levelset_has_changed &&
366 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
368 game_status = GAME_MODE_TITLE;
375 /* map gadgets for main menu screen */
379 /* level_nr may have been set to value over handicap with level editor */
380 if (setup.handicap && level_nr > leveldir_current->handicap_level)
381 level_nr = leveldir_current->handicap_level;
388 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
393 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
394 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
395 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
396 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
397 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
398 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
399 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
400 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
402 /* calculated after (possible) reload of custom artwork */
403 name_width = getTextWidth(name_text, FONT_MENU_1);
405 level_width = 9 * 32;
408 level_width = 9 * getFontWidth(FONT_MENU_1);
410 level_width = getTextWidth(level_text, FONT_MENU_1);
414 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
418 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
419 int2str(level_nr, 3), FONT_VALUE_1);
422 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
425 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
430 DrawPreviewLevel(TRUE);
436 int text_height = getFontHeight(FONT_TEXT_3);
438 int xpos = getLevelRangeTextPos() * 32;
440 int xpos = level_width + 6 * 32;
442 int ypos2 = -SY + 3 * 32 + 16;
443 int ypos1 = ypos2 - text_height;
445 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
446 "%03d", leveldir_current->first_level);
447 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
448 "%03d", leveldir_current->last_level);
451 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
452 "%d", leveldir_current->levels);
456 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
457 leveldir_current->first_level, leveldir_current->last_level);
461 if (leveldir_current->readonly)
463 DrawTextS(mSX + level_width + 9 * 32 - 2,
464 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
465 DrawTextS(mSX + level_width + 9 * 32 - 2,
466 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
470 for (i = 0; i < 8; i++)
471 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
477 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
478 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
481 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
482 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
484 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
485 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
491 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
500 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
503 if (TAPE_IS_EMPTY(tape))
505 DrawCompleteVideoDisplay();
512 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
515 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
517 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
526 /* create gadgets for main menu screen */
528 CreateScreenGadgets();
530 /* map gadgets for main menu screen */
532 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
548 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
558 static void gotoTopLevelDir()
560 /* move upwards to top level directory */
561 while (leveldir_current->node_parent)
563 /* write a "path" into level tree for easy navigation to last level */
564 if (leveldir_current->node_parent->node_group->cl_first == -1)
566 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
567 int leveldir_pos = posTreeInfo(leveldir_current);
568 int num_page_entries;
569 int cl_first, cl_cursor;
571 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
572 num_page_entries = num_leveldirs;
574 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
576 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
577 cl_cursor = leveldir_pos - cl_first;
579 leveldir_current->node_parent->node_group->cl_first = cl_first;
580 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
583 leveldir_current = leveldir_current->node_parent;
588 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
590 static int title_nr = 0;
591 boolean return_to_main_menu = FALSE;
592 boolean use_fading_main_menu = TRUE;
593 boolean use_cross_fading = TRUE;
594 int fade_delay = TITLE_SCREEN_FADE_DELAY;
595 int post_delay = fade_delay / 2;
597 if (button == MB_MENU_INITIALIZE)
599 int last_game_status = game_status; /* save current game status */
602 if (game_status == GAME_MODE_INFO)
604 if (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
606 DrawInfoScreen_NotAvailable("Title screen information:",
607 "No title screen for this level set.");
612 FadeSoundsAndMusic();
614 FadeOut(fade_delay, post_delay);
617 /* force TITLE music on title info screen */
618 game_status = GAME_MODE_TITLE;
623 game_status = last_game_status; /* restore current game status */
625 DrawTitleScreenImage(title_nr);
631 else if (button == MB_MENU_LEAVE)
633 return_to_main_menu = TRUE;
634 use_fading_main_menu = FALSE;
636 else if (button == MB_MENU_CHOICE)
638 if (game_status == GAME_MODE_INFO &&
639 graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
641 info_mode = INFO_MODE_MAIN;
649 if (!use_cross_fading)
650 FadeOut(fade_delay, post_delay);
652 if (title_nr < MAX_NUM_TITLE_SCREENS &&
653 graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
655 Bitmap *drawto_last = drawto;
657 if (use_cross_fading)
658 drawto = bitmap_db_title;
660 DrawTitleScreenImage(title_nr);
662 drawto = drawto_last;
664 if (use_cross_fading)
665 FadeCross(fade_delay);
671 FadeSoundsAndMusic();
673 FadeOut(fade_delay, post_delay);
675 return_to_main_menu = TRUE;
679 if (return_to_main_menu)
681 int menu_fade_delay = (use_fading_main_menu ? fade_delay : 0);
685 if (game_status == GAME_MODE_INFO)
687 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
689 info_mode = INFO_MODE_MAIN;
690 DrawInfoScreenExt(menu_fade_delay);
692 else /* default: return to main menu */
694 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
696 game_status = GAME_MODE_MAIN;
697 DrawMainMenuExt(menu_fade_delay);
702 void HandleMainMenu_SelectLevel(int step, int direction)
704 int old_level_nr = level_nr;
707 new_level_nr = old_level_nr + step * direction;
708 if (new_level_nr < leveldir_current->first_level)
709 new_level_nr = leveldir_current->first_level;
710 if (new_level_nr > leveldir_current->last_level)
711 new_level_nr = leveldir_current->last_level;
713 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
715 /* skipping levels is only allowed when trying to skip single level */
716 if (setup.skip_levels && step == 1 &&
717 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
719 leveldir_current->handicap_level++;
720 SaveLevelSetup_SeriesInfo();
723 new_level_nr = leveldir_current->handicap_level;
726 if (new_level_nr != old_level_nr)
728 level_nr = new_level_nr;
730 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
733 DrawPreviewLevel(TRUE);
737 DrawCompleteVideoDisplay();
739 /* needed because DrawPreviewLevel() takes some time */
745 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
748 static unsigned long level_delay = 0;
749 static unsigned long level_delay_value = GADGET_FRAME_DELAY;
751 static int choice = 5;
755 if (button == MB_MENU_INITIALIZE)
757 drawCursor(choice, FC_RED);
761 if (mx || my) /* mouse input */
764 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
766 else if (dx || dy) /* keyboard input */
768 if (dx && choice == 1)
769 x = (dx < 0 ? 10 : 14);
772 if (choice == 4 || choice == 6)
773 button = MB_MENU_CHOICE;
780 /* start gadget delay with longer delay after first click on gadget */
782 pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
787 if (y == 1 && dx != 0 && button)
789 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
794 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
795 (x == 14 && level_nr < leveldir_current->last_level)) &&
796 button && DelayReached(&level_delay, level_delay_value))
798 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
799 int old_level_nr = level_nr;
802 new_level_nr = level_nr + (x == 10 ? -step : +step);
803 if (new_level_nr < leveldir_current->first_level)
804 new_level_nr = leveldir_current->first_level;
805 if (new_level_nr > leveldir_current->last_level)
806 new_level_nr = leveldir_current->last_level;
808 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
810 /* skipping levels is only allowed when trying to skip single level */
811 if (setup.skip_levels && step == 1 &&
812 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
814 leveldir_current->handicap_level++;
815 SaveLevelSetup_SeriesInfo();
818 new_level_nr = leveldir_current->handicap_level;
821 if (new_level_nr != old_level_nr)
823 level_nr = new_level_nr;
825 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
829 DrawPreviewLevel(TRUE);
833 DrawCompleteVideoDisplay();
835 /* needed because DrawPreviewLevel() takes some time */
839 DelayReached(&level_delay, 0); /* reset delay counter */
841 pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
848 else if (IN_VIS_FIELD(x, y) &&
849 y >= 0 && y <= 7 && (y != 1 || x < 10))
855 drawCursor(y, FC_RED);
856 drawCursor(choice, FC_BLUE);
864 game_status = GAME_MODE_PSEUDO_TYPENAME;
865 HandleTypeName(strlen(setup.player_name), 0);
871 game_status = GAME_MODE_LEVELS;
872 SaveLevelSetup_LastSeries();
873 SaveLevelSetup_SeriesInfo();
884 game_status = GAME_MODE_SCORES;
889 if (leveldir_current->readonly &&
890 !strEqual(setup.player_name, "Artsoft"))
891 Request("This level is read only !", REQ_CONFIRM);
892 game_status = GAME_MODE_EDITOR;
897 game_status = GAME_MODE_INFO;
898 info_mode = INFO_MODE_MAIN;
903 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
907 game_status = GAME_MODE_SETUP;
908 setup_mode = SETUP_MODE_MAIN;
914 SaveLevelSetup_LastSeries();
915 SaveLevelSetup_SeriesInfo();
917 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
918 game_status = GAME_MODE_QUIT;
923 if (game_status == GAME_MODE_MAIN)
925 DrawPreviewLevel(FALSE);
931 /* ========================================================================= */
932 /* info screen functions */
933 /* ========================================================================= */
935 static struct TokenInfo *info_info;
936 static int num_info_info;
938 static void execInfoTitleScreen()
940 info_mode = INFO_MODE_TITLE;
944 static void execInfoElements()
946 info_mode = INFO_MODE_ELEMENTS;
950 static void execInfoMusic()
952 info_mode = INFO_MODE_MUSIC;
956 static void execInfoCredits()
958 info_mode = INFO_MODE_CREDITS;
962 static void execInfoProgram()
964 info_mode = INFO_MODE_PROGRAM;
968 static void execInfoLevelSet()
970 info_mode = INFO_MODE_LEVELSET;
974 static void execExitInfo()
976 game_status = GAME_MODE_MAIN;
980 static struct TokenInfo info_info_main[] =
982 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
983 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
984 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
985 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
986 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
987 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
988 { TYPE_EMPTY, NULL, "" },
989 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
994 static void DrawInfoScreen_Main(int fade_delay)
999 CloseDoor(DOOR_CLOSE_2);
1004 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1006 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
1009 info_info = info_info_main;
1012 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1014 int xpos = MENU_SCREEN_START_XPOS;
1015 int ypos = MENU_SCREEN_START_YPOS + i;
1016 int font_nr = FONT_MENU_1;
1018 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
1020 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1021 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1022 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1023 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1024 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1025 initCursor(i, IMG_MENU_BUTTON);
1032 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1048 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1052 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1054 static int choice_store[MAX_INFO_MODES];
1055 int choice = choice_store[info_mode]; /* always starts with 0 */
1059 if (button == MB_MENU_INITIALIZE)
1061 /* advance to first valid menu entry */
1062 while (choice < num_info_info &&
1063 info_info[choice].type & TYPE_SKIP_ENTRY)
1065 choice_store[info_mode] = choice;
1067 drawCursor(choice, FC_RED);
1070 else if (button == MB_MENU_LEAVE)
1072 for (y = 0; y < num_info_info; y++)
1074 if (info_info[y].type & TYPE_LEAVE_MENU)
1076 void (*menu_callback_function)(void) = info_info[y].value;
1078 menu_callback_function();
1079 break; /* absolutely needed because function changes 'info_info'! */
1086 if (mx || my) /* mouse input */
1088 x = (mx - mSX) / 32;
1089 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1091 else if (dx || dy) /* keyboard input */
1095 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
1097 if (info_info[choice].type & menu_navigation_type ||
1098 info_info[choice].type & TYPE_ENTER_SCREEN ||
1099 info_info[choice].type & TYPE_BOOLEAN_STYLE)
1100 button = MB_MENU_CHOICE;
1105 /* jump to next non-empty menu entry (up or down) */
1106 while (y > 0 && y < num_info_info - 1 &&
1107 info_info[y].type & TYPE_SKIP_ENTRY)
1111 if (IN_VIS_FIELD(x, y) &&
1112 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
1118 drawCursor(y, FC_RED);
1119 drawCursor(choice, FC_BLUE);
1120 choice = choice_store[info_mode] = y;
1123 else if (!(info_info[y].type & TYPE_GHOSTED))
1125 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
1127 void (*menu_callback_function)(void) = info_info[choice].value;
1129 menu_callback_function();
1135 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
1138 int ybottom = SYSIZE - 20;
1140 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1145 DrawTextSCentered(100, FONT_TEXT_1, text_title);
1147 DrawTextSCentered(ybottom, FONT_TEXT_4,
1148 "Press any key or button for info menu");
1150 DrawTextSCentered(ystart, FONT_TEXT_2, text_error);
1153 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
1155 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
1156 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
1157 int xstart = mSX + 16;
1158 int ystart = mSY + 64 + 2 * 32;
1159 int ystep = TILEY + 4;
1160 int element, action, direction;
1168 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
1169 infoscreen_step[i] = infoscreen_frame[i] = 0;
1174 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
1176 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1177 "Press any key or button for next page");
1183 while (helpanim_info[j].element != HELPANIM_LIST_END)
1185 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1190 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1199 j += infoscreen_step[i - start];
1201 element = helpanim_info[j].element;
1202 action = helpanim_info[j].action;
1203 direction = helpanim_info[j].direction;
1206 element = EL_UNKNOWN;
1208 if (action != -1 && direction != -1)
1209 graphic = el_act_dir2img(element, action, direction);
1210 else if (action != -1)
1211 graphic = el_act2img(element, action);
1212 else if (direction != -1)
1213 graphic = el_dir2img(element, direction);
1215 graphic = el2img(element);
1217 delay = helpanim_info[j++].delay;
1222 if (infoscreen_frame[i - start] == 0)
1225 infoscreen_frame[i - start] = delay - 1;
1229 sync_frame = delay - infoscreen_frame[i - start];
1230 infoscreen_frame[i - start]--;
1233 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1235 if (!infoscreen_frame[i - start])
1236 infoscreen_step[i - start] = 0;
1240 if (!infoscreen_frame[i - start])
1241 infoscreen_step[i - start]++;
1242 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1248 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1250 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1251 graphic, sync_frame, USE_MASKING);
1254 DrawInfoScreen_HelpText(element, action, direction, i - start);
1259 redraw_mask |= REDRAW_FIELD;
1264 static char *getHelpText(int element, int action, int direction)
1266 char token[MAX_LINE_LEN];
1268 strcpy(token, element_info[element].token_name);
1271 strcat(token, element_action_info[action].suffix);
1273 if (direction != -1)
1274 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1276 return getHashEntry(helptext_info, token);
1279 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1281 int font_nr = FONT_LEVEL_NUMBER;
1282 int font_width = getFontWidth(font_nr);
1283 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1284 int sy = mSY + 65 + 2 * 32 + 1;
1285 int ystep = TILEY + 4;
1286 int pad_x = sx - SX;
1287 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1288 int max_lines_per_text = 2;
1291 if (action != -1 && direction != -1) /* element.action.direction */
1292 text = getHelpText(element, action, direction);
1294 if (text == NULL && action != -1) /* element.action */
1295 text = getHelpText(element, action, -1);
1297 if (text == NULL && direction != -1) /* element.direction */
1298 text = getHelpText(element, -1, direction);
1300 if (text == NULL) /* base element */
1301 text = getHelpText(element, -1, -1);
1303 if (text == NULL) /* not found */
1304 text = "No description available";
1306 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1307 sy += getFontHeight(font_nr) / 2;
1309 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1310 max_chars_per_line, max_lines_per_text);
1313 void DrawInfoScreen_TitleScreen()
1318 void HandleInfoScreen_TitleScreen(int button)
1320 HandleTitleScreen(0, 0, 0, 0, button);
1323 void DrawInfoScreen_Elements()
1325 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1330 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1336 void HandleInfoScreen_Elements(int button)
1338 static unsigned long info_delay = 0;
1339 static int num_anims;
1340 static int num_pages;
1342 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1343 int button_released = !button;
1346 if (button == MB_MENU_INITIALIZE)
1348 boolean new_element = TRUE;
1351 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1353 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1355 else if (new_element)
1358 new_element = FALSE;
1362 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1365 else if (button == MB_MENU_LEAVE)
1367 info_mode = INFO_MODE_MAIN;
1373 if (button_released || button == MB_MENU_INITIALIZE)
1375 if (button != MB_MENU_INITIALIZE)
1378 if (page >= num_pages)
1380 FadeSoundsAndMusic();
1382 info_mode = INFO_MODE_MAIN;
1388 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1392 if (DelayReached(&info_delay, GameFrameDelay))
1393 if (page < num_pages)
1394 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1396 PlayMenuSoundIfLoop();
1400 void DrawInfoScreen_Music()
1402 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1409 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1412 void HandleInfoScreen_Music(int button)
1414 static struct MusicFileInfo *list = NULL;
1415 int ystart = 150, dy = 30;
1416 int ybottom = SYSIZE - 20;
1417 int button_released = !button;
1419 if (button == MB_MENU_INITIALIZE)
1421 list = music_file_info;
1425 FadeSoundsAndMusic();
1430 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1432 DrawTextSCentered(ybottom, FONT_TEXT_4,
1433 "Press any key or button for info menu");
1438 else if (button == MB_MENU_LEAVE)
1440 info_mode = INFO_MODE_MAIN;
1446 if (button_released || button == MB_MENU_INITIALIZE)
1450 if (button != MB_MENU_INITIALIZE)
1456 info_mode = INFO_MODE_MAIN;
1462 FadeSoundsAndMusic();
1469 int sound = list->music;
1471 if (sound_info[sound].loop)
1472 PlaySoundLoop(sound);
1476 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1480 PlayMusic(list->music);
1482 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1485 if (!strEqual(list->title, UNKNOWN_NAME))
1487 if (!strEqual(list->title_header, UNKNOWN_NAME))
1488 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1490 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1493 if (!strEqual(list->artist, UNKNOWN_NAME))
1495 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1496 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1498 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1500 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1503 if (!strEqual(list->album, UNKNOWN_NAME))
1505 if (!strEqual(list->album_header, UNKNOWN_NAME))
1506 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1508 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1510 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1513 if (!strEqual(list->year, UNKNOWN_NAME))
1515 if (!strEqual(list->year_header, UNKNOWN_NAME))
1516 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1518 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1520 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1523 DrawTextSCentered(ybottom, FONT_TEXT_4,
1524 "Press any key or button for next page");
1527 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1528 PlaySoundLoop(list->music);
1531 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
1533 int ystart = 150, ystep = 30;
1534 int ybottom = SYSIZE - 20;
1539 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1543 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1544 "Special thanks to");
1545 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1547 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1549 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1550 "\"Boulder Dash\"");
1551 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1553 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1555 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1557 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1558 "First Star Software");
1560 else if (screen_nr == 1)
1562 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1563 "Special thanks to");
1564 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1565 "Klaus Heinz & Volker Wertich");
1566 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1568 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1569 "\"Emerald Mine\"");
1570 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1572 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1574 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1576 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1579 else if (screen_nr == 2)
1581 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1582 "Special thanks to");
1583 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1584 "Michael Stopp & Philip Jespersen");
1585 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1587 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1589 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1591 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1593 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1595 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1596 "Digital Integration");
1598 else if (screen_nr == 3)
1600 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1601 "Special thanks to");
1602 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1603 "Hiroyuki Imabayashi");
1604 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1606 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1608 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1610 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1612 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1614 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1617 else if (screen_nr == 4)
1619 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1620 "Special thanks to");
1621 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1623 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1625 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1626 "Jürgen Bonhagen");
1627 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1628 "for the continuous creation");
1629 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1630 "of outstanding level sets");
1632 else if (screen_nr == 5)
1634 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1636 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1638 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1639 "for ideas and inspiration by");
1640 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1643 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1645 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_3,
1647 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1648 "for ideas and inspiration by");
1649 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
1652 else if (screen_nr == 6)
1654 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1656 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1658 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1659 "for the new Emerald Mine engine");
1661 else if (screen_nr == 7)
1663 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1665 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1667 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1668 "for the initial DOS port");
1670 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1672 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1674 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1675 "for some additional toons");
1677 else if (screen_nr == 8)
1679 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1680 "And not to forget:");
1681 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1683 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1684 "All those who contributed");
1685 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1686 "levels to this game");
1687 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_3,
1695 DrawTextSCentered(ybottom, FONT_TEXT_4,
1696 "Press any key or button for next page");
1701 void DrawInfoScreen_Credits()
1703 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1705 FadeSoundsAndMusic();
1707 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
1710 void HandleInfoScreen_Credits(int button)
1712 static int screen_nr = 0;
1714 if (button == MB_MENU_INITIALIZE)
1718 DrawInfoScreen_CreditsScreen(screen_nr);
1720 else if (button == MB_MENU_LEAVE)
1722 info_mode = INFO_MODE_MAIN;
1727 else if (button == MB_MENU_CHOICE)
1731 if (!DrawInfoScreen_CreditsScreen(screen_nr))
1733 FadeSoundsAndMusic();
1735 info_mode = INFO_MODE_MAIN;
1741 PlayMenuSoundIfLoop();
1745 void DrawInfoScreen_Program()
1747 int ystart = 150, ystep = 30;
1748 int ybottom = SYSIZE - 20;
1750 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1755 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1757 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1758 "This game is Freeware!");
1759 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1760 "If you like it, send e-mail to:");
1761 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1762 PROGRAM_EMAIL_STRING);
1763 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1764 "or SnailMail to:");
1765 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1767 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1768 "Detmolder Strasse 189");
1769 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1771 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1773 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1774 "More information and levels:");
1775 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
1776 PROGRAM_WEBSITE_STRING);
1777 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1778 "If you have created new levels,");
1779 DrawTextSCentered(ystart + 10 * ystep, FONT_TEXT_2,
1780 "send them to me to include them!");
1781 DrawTextSCentered(ystart + 11 * ystep, FONT_TEXT_2,
1784 DrawTextSCentered(ybottom, FONT_TEXT_4,
1785 "Press any key or button for info menu");
1788 void HandleInfoScreen_Program(int button)
1790 int button_released = !button;
1792 if (button == MB_MENU_LEAVE)
1794 info_mode = INFO_MODE_MAIN;
1800 if (button_released)
1802 FadeSoundsAndMusic();
1804 info_mode = INFO_MODE_MAIN;
1809 PlayMenuSoundIfLoop();
1813 void DrawInfoScreen_LevelSet()
1816 int ybottom = SYSIZE - 20;
1817 char *filename = getLevelSetInfoFilename();
1818 int font_nr = FONT_LEVEL_NUMBER;
1819 int font_width = getFontWidth(font_nr);
1820 int font_height = getFontHeight(font_nr);
1823 int sx = SX + pad_x;
1824 int sy = SY + pad_y;
1825 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1826 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1828 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1833 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1835 DrawTextSCentered(ybottom, FONT_TEXT_4,
1836 "Press any key or button for info menu");
1838 if (filename != NULL)
1839 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1840 max_lines_per_screen);
1842 DrawTextSCentered(ystart, FONT_TEXT_2,
1843 "No information for this level set.");
1846 void HandleInfoScreen_LevelSet(int button)
1848 int button_released = !button;
1850 if (button == MB_MENU_LEAVE)
1852 info_mode = INFO_MODE_MAIN;
1858 if (button_released)
1860 FadeSoundsAndMusic();
1862 info_mode = INFO_MODE_MAIN;
1867 PlayMenuSoundIfLoop();
1871 static void DrawInfoScreenExt(int fade_delay)
1873 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1875 if (info_mode == INFO_MODE_TITLE)
1876 DrawInfoScreen_TitleScreen();
1877 else if (info_mode == INFO_MODE_ELEMENTS)
1878 DrawInfoScreen_Elements();
1879 else if (info_mode == INFO_MODE_MUSIC)
1880 DrawInfoScreen_Music();
1881 else if (info_mode == INFO_MODE_CREDITS)
1882 DrawInfoScreen_Credits();
1883 else if (info_mode == INFO_MODE_PROGRAM)
1884 DrawInfoScreen_Program();
1885 else if (info_mode == INFO_MODE_LEVELSET)
1886 DrawInfoScreen_LevelSet();
1888 DrawInfoScreen_Main(fade_delay);
1890 if (info_mode != INFO_MODE_MAIN &&
1891 info_mode != INFO_MODE_TITLE &&
1892 info_mode != INFO_MODE_MUSIC)
1899 void DrawInfoScreen()
1901 DrawInfoScreenExt(0);
1904 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1906 if (info_mode == INFO_MODE_TITLE)
1907 HandleInfoScreen_TitleScreen(button);
1908 else if (info_mode == INFO_MODE_ELEMENTS)
1909 HandleInfoScreen_Elements(button);
1910 else if (info_mode == INFO_MODE_MUSIC)
1911 HandleInfoScreen_Music(button);
1912 else if (info_mode == INFO_MODE_CREDITS)
1913 HandleInfoScreen_Credits(button);
1914 else if (info_mode == INFO_MODE_PROGRAM)
1915 HandleInfoScreen_Program(button);
1916 else if (info_mode == INFO_MODE_LEVELSET)
1917 HandleInfoScreen_LevelSet(button);
1919 HandleInfoScreen_Main(mx, my, dx, dy, button);
1925 /* ========================================================================= */
1926 /* type name functions */
1927 /* ========================================================================= */
1929 void HandleTypeName(int newxpos, Key key)
1931 static int xpos = 0, ypos = 2;
1932 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1933 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1934 int startx = mSX + 32 + name_width;
1935 int starty = mSY + ypos * 32;
1941 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1942 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1947 if (((key >= KSYM_A && key <= KSYM_Z) ||
1948 (key >= KSYM_a && key <= KSYM_z)) &&
1949 xpos < MAX_PLAYER_NAME_LEN)
1953 if (key >= KSYM_A && key <= KSYM_Z)
1954 ascii = 'A' + (char)(key - KSYM_A);
1956 ascii = 'a' + (char)(key - KSYM_a);
1958 setup.player_name[xpos] = ascii;
1959 setup.player_name[xpos + 1] = 0;
1962 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1963 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1965 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1968 setup.player_name[xpos] = 0;
1970 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1972 else if (key == KSYM_Return && xpos > 0)
1974 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
1975 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
1978 game_status = GAME_MODE_MAIN;
1983 /* ========================================================================= */
1984 /* tree menu functions */
1985 /* ========================================================================= */
1987 static void DrawChooseTree(TreeInfo **ti_ptr)
1991 FreeScreenGadgets();
1992 CreateScreenGadgets();
1994 CloseDoor(DOOR_CLOSE_2);
1998 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
1999 MapScreenTreeGadgets(*ti_ptr);
2005 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
2007 struct GadgetInfo *gi = screen_gadget[id];
2008 int items_max, items_visible, item_position;
2010 items_max = numTreeInfoInGroup(ti);
2011 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
2012 item_position = first_entry;
2014 if (item_position > items_max - items_visible)
2015 item_position = items_max - items_visible;
2017 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
2018 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2019 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
2022 static void drawChooseTreeList(int first_entry, int num_page_entries,
2026 char *title_string = NULL;
2028 int xoffset_sets = 16;
2030 int yoffset_sets = MENU_TITLE1_YPOS;
2032 int xoffset_setup = 16;
2034 int yoffset_setup = 16;
2037 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
2040 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
2043 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
2044 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
2046 int last_game_status = game_status; /* save current game status */
2048 title_string = ti->infotext;
2051 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
2053 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
2056 /* force LEVELS font on artwork setup screen */
2057 game_status = GAME_MODE_LEVELS;
2059 /* clear tree list area, but not title or scrollbar */
2060 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
2061 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
2062 MAX_MENU_ENTRIES_ON_SCREEN * 32);
2064 for (i = 0; i < num_page_entries; i++)
2066 TreeInfo *node, *node_first;
2067 int entry_pos = first_entry + i;
2068 int xpos = MENU_SCREEN_START_XPOS;
2069 int ypos = MENU_SCREEN_START_YPOS + i;
2070 int startx = mSX + xpos * 32;
2071 int starty = mSY + ypos * 32;
2072 int font_nr = FONT_TEXT_1;
2073 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2074 int startx_text = startx + font_xoffset;
2075 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
2076 int text_size = startx_scrollbar - startx_text;
2077 int max_buffer_len = text_size / getFontWidth(font_nr);
2078 char buffer[max_buffer_len + 1];
2080 node_first = getTreeInfoFirstGroupEntry(ti);
2081 node = getTreeInfoFromPos(node_first, entry_pos);
2083 strncpy(buffer, node->name, max_buffer_len);
2084 buffer[max_buffer_len] = '\0';
2086 DrawText(startx, starty, buffer, font_nr + node->color);
2088 if (node->parent_link)
2089 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2090 else if (node->level_group)
2091 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2093 initCursor(i, IMG_MENU_BUTTON);
2096 game_status = last_game_status; /* restore current game status */
2098 redraw_mask |= REDRAW_FIELD;
2101 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
2103 TreeInfo *node, *node_first;
2104 int x, last_redraw_mask = redraw_mask;
2106 int ypos = MENU_TITLE2_YPOS;
2111 if (ti->type != TREE_TYPE_LEVEL_DIR)
2114 node_first = getTreeInfoFirstGroupEntry(ti);
2115 node = getTreeInfoFromPos(node_first, entry_pos);
2117 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
2119 if (node->parent_link)
2120 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
2122 else if (node->level_group)
2123 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
2125 else if (ti->type == TREE_TYPE_LEVEL_DIR)
2126 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
2127 node->levels, node->class_desc);
2129 /* let BackToFront() redraw only what is needed */
2130 redraw_mask = last_redraw_mask | REDRAW_TILES;
2131 for (x = 0; x < SCR_FIELDX; x++)
2132 MarkTileDirty(x, 1);
2135 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
2138 TreeInfo *ti = *ti_ptr;
2140 int y = ti->cl_cursor;
2141 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2142 int num_entries = numTreeInfoInGroup(ti);
2143 int num_page_entries;
2144 int last_game_status = game_status; /* save current game status */
2145 boolean position_set_by_scrollbar = (dx == 999);
2147 /* force LEVELS draw offset on choose level and artwork setup screen */
2148 game_status = GAME_MODE_LEVELS;
2150 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
2151 num_page_entries = num_entries;
2153 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2155 game_status = last_game_status; /* restore current game status */
2157 if (button == MB_MENU_INITIALIZE)
2159 int num_entries = numTreeInfoInGroup(ti);
2160 int entry_pos = posTreeInfo(ti);
2162 if (ti->cl_first == -1)
2164 /* only on initialization */
2165 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2166 ti->cl_cursor = entry_pos - ti->cl_first;
2168 else if (ti->cl_cursor >= num_page_entries ||
2169 (num_entries > num_page_entries &&
2170 num_entries - ti->cl_first < num_page_entries))
2172 /* only after change of list size (by custom graphic configuration) */
2173 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2174 ti->cl_cursor = entry_pos - ti->cl_first;
2177 if (position_set_by_scrollbar)
2180 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2183 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2184 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2185 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2189 else if (button == MB_MENU_LEAVE)
2191 if (ti->node_parent)
2193 *ti_ptr = ti->node_parent;
2194 DrawChooseTree(ti_ptr);
2196 else if (game_status == GAME_MODE_SETUP)
2198 if (game_status == GAME_MODE_SETUP)
2200 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2201 execSetupGraphics();
2208 game_status = GAME_MODE_MAIN;
2215 if (mx || my) /* mouse input */
2217 int last_game_status = game_status; /* save current game status */
2219 /* force LEVELS draw offset on artwork setup screen */
2220 game_status = GAME_MODE_LEVELS;
2222 x = (mx - mSX) / 32;
2223 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2225 game_status = last_game_status; /* restore current game status */
2227 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2229 /* move cursor instead of scrolling when already at start/end of list */
2230 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
2232 else if (dy == +1 * SCROLL_LINE &&
2233 ti->cl_first + num_page_entries == num_entries)
2236 /* handle scrolling screen one line or page */
2237 if (ti->cl_cursor + dy < 0 ||
2238 ti->cl_cursor + dy > num_page_entries - 1)
2240 if (ABS(dy) == SCROLL_PAGE)
2241 step = num_page_entries - 1;
2243 if (dy < 0 && ti->cl_first > 0)
2245 /* scroll page/line up */
2247 ti->cl_first -= step;
2248 if (ti->cl_first < 0)
2251 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2252 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2253 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2254 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2257 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
2259 /* scroll page/line down */
2261 ti->cl_first += step;
2262 if (ti->cl_first + num_page_entries > num_entries)
2263 ti->cl_first = MAX(0, num_entries - num_page_entries);
2265 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2266 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2267 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2268 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2275 /* handle moving cursor one line */
2276 y = ti->cl_cursor + dy;
2281 TreeInfo *node_first, *node_cursor;
2282 int entry_pos = ti->cl_first + y;
2284 node_first = getTreeInfoFirstGroupEntry(ti);
2285 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2287 if (node_cursor->node_group)
2289 node_cursor->cl_first = ti->cl_first;
2290 node_cursor->cl_cursor = ti->cl_cursor;
2291 *ti_ptr = node_cursor->node_group;
2292 DrawChooseTree(ti_ptr);
2297 else if (dx == -1 && ti->node_parent)
2299 *ti_ptr = ti->node_parent;
2300 DrawChooseTree(ti_ptr);
2305 if (!anyScrollbarGadgetActive() &&
2306 IN_VIS_FIELD(x, y) &&
2307 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2308 y >= 0 && y < num_page_entries)
2312 if (y != ti->cl_cursor)
2314 drawChooseTreeCursor(y, FC_RED);
2315 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
2316 drawChooseTreeInfo(ti->cl_first + y, ti);
2322 TreeInfo *node_first, *node_cursor;
2323 int entry_pos = ti->cl_first + y;
2325 node_first = getTreeInfoFirstGroupEntry(ti);
2326 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2328 if (node_cursor->node_group)
2330 node_cursor->cl_first = ti->cl_first;
2331 node_cursor->cl_cursor = ti->cl_cursor;
2332 *ti_ptr = node_cursor->node_group;
2333 DrawChooseTree(ti_ptr);
2335 else if (node_cursor->parent_link)
2337 *ti_ptr = node_cursor->node_parent;
2338 DrawChooseTree(ti_ptr);
2342 node_cursor->cl_first = ti->cl_first;
2343 node_cursor->cl_cursor = ti->cl_cursor;
2344 *ti_ptr = node_cursor;
2346 if (ti->type == TREE_TYPE_LEVEL_DIR)
2348 LoadLevelSetup_SeriesInfo();
2350 SaveLevelSetup_LastSeries();
2351 SaveLevelSetup_SeriesInfo();
2355 if (game_status == GAME_MODE_SETUP)
2357 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2358 execSetupGraphics();
2364 game_status = GAME_MODE_MAIN;
2372 void DrawChooseLevel()
2374 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2376 DrawChooseTree(&leveldir_current);
2382 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2384 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2389 void DrawHallOfFame(int highlight_position)
2392 FadeSoundsAndMusic();
2393 CloseDoor(DOOR_CLOSE_2);
2395 if (highlight_position < 0)
2396 LoadScore(level_nr);
2404 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2407 static void drawHallOfFameList(int first_entry, int highlight_position)
2411 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2415 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2416 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2417 "HighScores of Level %d", level_nr);
2419 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2420 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2421 "HighScores of Level %d", level_nr);
2424 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2426 int entry = first_entry + i;
2427 boolean active = (entry == highlight_position);
2428 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2429 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2430 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2431 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2432 int dx1 = 3 * getFontWidth(font_nr1);
2433 int dx2 = dx1 + getFontWidth(font_nr1);
2434 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2435 int sy = mSY + 64 + i * 32;
2437 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2438 DrawText(mSX + dx1, sy, ".", font_nr1);
2439 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2441 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2442 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2444 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2447 redraw_mask |= REDRAW_FIELD;
2450 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2452 static int first_entry = 0;
2453 static int highlight_position = 0;
2454 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2455 int button_released = !button;
2457 if (button == MB_MENU_INITIALIZE)
2460 highlight_position = mx;
2461 drawHallOfFameList(first_entry, highlight_position);
2466 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2467 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2471 if (first_entry > 0)
2473 first_entry -= step;
2474 if (first_entry < 0)
2477 drawHallOfFameList(first_entry, highlight_position);
2482 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2484 first_entry += step;
2485 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2486 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2488 drawHallOfFameList(first_entry, highlight_position);
2491 else if (button_released)
2493 FadeSound(SND_BACKGROUND_SCORES);
2494 game_status = GAME_MODE_MAIN;
2498 if (game_status == GAME_MODE_SCORES)
2499 PlayMenuSoundIfLoop();
2505 /* ========================================================================= */
2506 /* setup screen functions */
2507 /* ========================================================================= */
2509 static struct TokenInfo *setup_info;
2510 static int num_setup_info;
2512 static char *screen_mode_text;
2513 static char *graphics_set_name;
2514 static char *sounds_set_name;
2515 static char *music_set_name;
2517 static void execSetupMain()
2519 setup_mode = SETUP_MODE_MAIN;
2523 static void execSetupGame()
2525 setup_mode = SETUP_MODE_GAME;
2529 static void execSetupEditor()
2531 setup_mode = SETUP_MODE_EDITOR;
2535 static void execSetupGraphics()
2537 if (video.fullscreen_available && screen_modes == NULL)
2541 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
2543 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
2544 char identifier[32], name[32];
2545 int x = video.fullscreen_modes[i].width;
2546 int y = video.fullscreen_modes[i].height;
2549 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
2551 ti->node_top = &screen_modes;
2552 ti->sort_priority = x * 10000 + y;
2554 sprintf(identifier, "%dx%d", x, y);
2555 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
2557 setString(&ti->identifier, identifier);
2558 setString(&ti->name, name);
2559 setString(&ti->name_sorting, name);
2560 setString(&ti->infotext, "Fullscreen Mode");
2562 pushTreeInfo(&screen_modes, ti);
2565 /* sort fullscreen modes to start with lowest available screen resolution */
2566 sortTreeInfo(&screen_modes);
2568 /* set current screen mode for fullscreen mode to configured setup value */
2569 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2570 setup.fullscreen_mode);
2572 /* if that fails, set current screen mode to reliable default value */
2573 if (screen_mode_current == NULL)
2574 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2575 DEFAULT_FULLSCREEN_MODE);
2577 /* if that also fails, set current screen mode to first available mode */
2578 if (screen_mode_current == NULL)
2579 screen_mode_current = screen_modes;
2581 if (screen_mode_current == NULL)
2582 video.fullscreen_available = FALSE;
2585 if (video.fullscreen_available)
2587 setup.fullscreen_mode = screen_mode_current->identifier;
2589 /* needed for displaying screen mode name instead of identifier */
2590 screen_mode_text = screen_mode_current->name;
2593 setup_mode = SETUP_MODE_GRAPHICS;
2597 static void execSetupChooseScreenMode()
2599 if (!video.fullscreen_available)
2602 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
2606 static void execSetupSound()
2608 setup_mode = SETUP_MODE_SOUND;
2612 static void execSetupArtwork()
2614 setup.graphics_set = artwork.gfx_current->identifier;
2615 setup.sounds_set = artwork.snd_current->identifier;
2616 setup.music_set = artwork.mus_current->identifier;
2618 /* needed if last screen (setup choice) changed graphics, sounds or music */
2619 ReloadCustomArtwork(0);
2621 /* needed for displaying artwork name instead of artwork identifier */
2622 graphics_set_name = artwork.gfx_current->name;
2623 sounds_set_name = artwork.snd_current->name;
2624 music_set_name = artwork.mus_current->name;
2626 setup_mode = SETUP_MODE_ARTWORK;
2630 static void execSetupChooseGraphics()
2632 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2636 static void execSetupChooseSounds()
2638 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2642 static void execSetupChooseMusic()
2644 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2648 static void execSetupInput()
2650 setup_mode = SETUP_MODE_INPUT;
2654 static void execSetupShortcut1()
2656 setup_mode = SETUP_MODE_SHORTCUT_1;
2660 static void execSetupShortcut2()
2662 setup_mode = SETUP_MODE_SHORTCUT_2;
2666 static void execExitSetup()
2668 game_status = GAME_MODE_MAIN;
2672 static void execSaveAndExitSetup()
2678 static struct TokenInfo setup_info_main[] =
2680 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2681 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2682 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2683 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2684 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2685 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2686 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2687 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2688 { TYPE_EMPTY, NULL, "" },
2689 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2690 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2695 static struct TokenInfo setup_info_game[] =
2697 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2698 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2699 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2700 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2701 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2702 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2703 { TYPE_EMPTY, NULL, "" },
2704 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2709 static struct TokenInfo setup_info_editor[] =
2712 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2713 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2714 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2715 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2716 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2717 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2718 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2719 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2721 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2722 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2724 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2726 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2727 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2728 { TYPE_EMPTY, NULL, "" },
2730 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
2731 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
2732 { TYPE_EMPTY, NULL, "" },
2734 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2735 { TYPE_EMPTY, NULL, "" },
2736 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2741 static struct TokenInfo setup_info_graphics[] =
2743 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2744 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
2745 { TYPE_STRING, &screen_mode_text, "" },
2746 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2748 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2749 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2750 { TYPE_SWITCH, &setup.fading, "Fading:" },
2752 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2753 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2754 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2755 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2756 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2757 { TYPE_EMPTY, NULL, "" },
2758 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2763 static struct TokenInfo setup_info_sound[] =
2765 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2766 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2767 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2768 { TYPE_EMPTY, NULL, "" },
2769 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2774 static struct TokenInfo setup_info_artwork[] =
2776 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
2777 { TYPE_STRING, &graphics_set_name, "" },
2778 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
2779 { TYPE_STRING, &sounds_set_name, "" },
2780 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
2781 { TYPE_STRING, &music_set_name, "" },
2782 { TYPE_EMPTY, NULL, "" },
2784 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2785 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2786 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2788 { TYPE_STRING, NULL, "Override Level Artwork:"},
2789 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2790 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2791 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2793 { TYPE_EMPTY, NULL, "" },
2794 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2799 static struct TokenInfo setup_info_shortcut_1[] =
2801 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2802 { TYPE_KEY, &setup.shortcut.save_game, "" },
2803 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2804 { TYPE_KEY, &setup.shortcut.load_game, "" },
2805 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2806 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2807 { TYPE_EMPTY, NULL, "" },
2808 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2809 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2810 { TYPE_EMPTY, NULL, "" },
2811 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2816 static struct TokenInfo setup_info_shortcut_2[] =
2818 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2819 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2820 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2821 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2822 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2823 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2824 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2825 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2826 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2827 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2828 { TYPE_EMPTY, NULL, "" },
2829 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2834 static Key getSetupKey()
2836 Key key = KSYM_UNDEFINED;
2837 boolean got_key_event = FALSE;
2839 while (!got_key_event)
2841 if (PendingEvent()) /* got event */
2849 case EVENT_KEYPRESS:
2851 key = GetEventKey((KeyEvent *)&event, TRUE);
2853 /* press 'Escape' or 'Enter' to keep the existing key binding */
2854 if (key == KSYM_Escape || key == KSYM_Return)
2855 key = KSYM_UNDEFINED; /* keep old value */
2857 got_key_event = TRUE;
2861 case EVENT_KEYRELEASE:
2862 key_joystick_mapping = 0;
2866 HandleOtherEvents(&event);
2874 /* don't eat all CPU time */
2881 static int getSetupTextFont(int type)
2883 if (type & (TYPE_SWITCH |
2894 static int getSetupValueFont(int type, void *value)
2896 if (type & TYPE_KEY)
2897 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2898 else if (type & TYPE_STRING)
2899 return FONT_VALUE_2;
2900 else if (type & TYPE_ECS_AGA)
2901 return FONT_VALUE_1;
2902 else if (type & TYPE_BOOLEAN_STYLE)
2903 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2905 return FONT_VALUE_1;
2908 static void drawSetupValue(int pos)
2910 boolean font_draw_xoffset_modified = FALSE;
2911 int font_draw_xoffset_old = -1;
2912 int xpos = MENU_SCREEN_VALUE_XPOS;
2913 int ypos = MENU_SCREEN_START_YPOS + pos;
2914 int startx = mSX + xpos * 32;
2915 int starty = mSY + ypos * 32;
2916 int font_nr, font_width;
2917 int type = setup_info[pos].type;
2918 void *value = setup_info[pos].value;
2919 char *value_string = getSetupValue(type, value);
2922 if (value_string == NULL)
2925 if (type & TYPE_KEY)
2928 xpos = MENU_SCREEN_START_XPOS;
2933 if (type & TYPE_QUERY)
2935 value_string = "<press key>";
2937 font_nr = FONT_INPUT_1_ACTIVE;
2941 else if (type & TYPE_STRING)
2943 int max_value_len = (SCR_FIELDX - 2) * 2;
2945 xpos = MENU_SCREEN_START_XPOS;
2947 font_nr = FONT_VALUE_2;
2950 if (strlen(value_string) > max_value_len)
2951 value_string[max_value_len] = '\0';
2953 else if (type & TYPE_ECS_AGA)
2956 font_nr = FONT_VALUE_1;
2959 else if (type & TYPE_BOOLEAN_STYLE)
2962 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2966 startx = mSX + xpos * 32;
2967 starty = mSY + ypos * 32;
2968 font_nr = getSetupValueFont(type, value);
2969 font_width = getFontWidth(font_nr);
2971 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2972 if (setup_mode != SETUP_MODE_INPUT)
2974 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
2975 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2976 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
2977 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
2978 int text_font_nr = getSetupTextFont(FONT_MENU_2);
2979 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
2980 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
2981 boolean correct_font_draw_xoffset = FALSE;
2983 if (xpos == MENU_SCREEN_START_XPOS &&
2984 startx + font1_xoffset < text_startx + text_font_xoffset)
2985 correct_font_draw_xoffset = TRUE;
2987 if (xpos == MENU_SCREEN_VALUE_XPOS &&
2988 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
2989 correct_font_draw_xoffset = TRUE;
2992 printf("::: %d + %d < %d + %d + %d\n",
2993 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
2994 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
2997 /* check if setup value would overlap with setup text when printed */
2998 /* (this can happen for extreme/wrong values for font draw offset) */
2999 if (correct_font_draw_xoffset)
3001 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
3002 font_draw_xoffset_modified = TRUE;
3004 if (type & TYPE_KEY)
3005 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
3006 else if (!(type & TYPE_STRING))
3007 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
3008 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
3013 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
3014 DrawText(startx + i * font_width, starty, " ", font_nr);
3017 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
3018 DrawText(mSX + i * 32, starty, " ", font_nr);
3020 DrawText(startx, starty,
3021 (xpos == 3 ? " " : " "), font_nr);
3025 DrawText(startx, starty, value_string, font_nr);
3027 if (font_draw_xoffset_modified)
3028 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
3031 static void changeSetupValue(int pos)
3033 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
3035 *(boolean *)setup_info[pos].value ^= TRUE;
3037 else if (setup_info[pos].type & TYPE_KEY)
3041 setup_info[pos].type |= TYPE_QUERY;
3042 drawSetupValue(pos);
3043 setup_info[pos].type &= ~TYPE_QUERY;
3045 key = getSetupKey();
3046 if (key != KSYM_UNDEFINED)
3047 *(Key *)setup_info[pos].value = key;
3050 drawSetupValue(pos);
3053 static void DrawSetupScreen_Generic()
3055 char *title_string = NULL;
3059 CloseDoor(DOOR_CLOSE_2);
3063 if (setup_mode == SETUP_MODE_MAIN)
3065 setup_info = setup_info_main;
3066 title_string = "Setup";
3068 else if (setup_mode == SETUP_MODE_GAME)
3070 setup_info = setup_info_game;
3071 title_string = "Setup Game";
3073 else if (setup_mode == SETUP_MODE_EDITOR)
3075 setup_info = setup_info_editor;
3076 title_string = "Setup Editor";
3078 else if (setup_mode == SETUP_MODE_GRAPHICS)
3080 setup_info = setup_info_graphics;
3081 title_string = "Setup Graphics";
3083 else if (setup_mode == SETUP_MODE_SOUND)
3085 setup_info = setup_info_sound;
3086 title_string = "Setup Sound";
3088 else if (setup_mode == SETUP_MODE_ARTWORK)
3090 setup_info = setup_info_artwork;
3091 title_string = "Custom Artwork";
3093 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
3095 setup_info = setup_info_shortcut_1;
3096 title_string = "Setup Shortcuts";
3098 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
3100 setup_info = setup_info_shortcut_2;
3101 title_string = "Setup Shortcuts";
3105 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
3107 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
3111 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3113 void *value_ptr = setup_info[i].value;
3114 int xpos = MENU_SCREEN_START_XPOS;
3115 int ypos = MENU_SCREEN_START_YPOS + i;
3119 int font_nr = FONT_MENU_1;
3122 /* set some entries to "unchangeable" according to other variables */
3123 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
3124 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
3125 (value_ptr == &setup.sound_music && !audio.music_available) ||
3126 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
3127 (value_ptr == &screen_mode_text && !video.fullscreen_available))
3128 setup_info[i].type |= TYPE_GHOSTED;
3131 font_nr = getSetupTextFont(setup_info[i].type);
3134 if (setup_info[i].type & (TYPE_SWITCH |
3139 font_nr = FONT_MENU_2;
3141 if (setup_info[i].type & TYPE_STRING)
3142 font_nr = FONT_MENU_2;
3146 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
3148 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
3149 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3150 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
3151 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3152 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
3153 initCursor(i, IMG_MENU_BUTTON);
3155 if (setup_info[i].type & TYPE_VALUE)
3162 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3163 "Joysticks deactivated in setup menu");
3168 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
3171 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
3173 static int choice_store[MAX_SETUP_MODES];
3174 int choice = choice_store[setup_mode]; /* always starts with 0 */
3178 if (button == MB_MENU_INITIALIZE)
3180 /* advance to first valid menu entry */
3181 while (choice < num_setup_info &&
3182 setup_info[choice].type & TYPE_SKIP_ENTRY)
3184 choice_store[setup_mode] = choice;
3186 drawCursor(choice, FC_RED);
3190 else if (button == MB_MENU_LEAVE)
3192 for (y = 0; y < num_setup_info; y++)
3194 if (setup_info[y].type & TYPE_LEAVE_MENU)
3196 void (*menu_callback_function)(void) = setup_info[y].value;
3198 menu_callback_function();
3200 break; /* absolutely needed because function changes 'setup_info'! */
3207 if (mx || my) /* mouse input */
3209 x = (mx - mSX) / 32;
3210 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3212 else if (dx || dy) /* keyboard input */
3216 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
3218 if (setup_info[choice].type & menu_navigation_type ||
3219 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
3220 button = MB_MENU_CHOICE;
3225 /* jump to next non-empty menu entry (up or down) */
3226 while (y > 0 && y < num_setup_info - 1 &&
3227 setup_info[y].type & TYPE_SKIP_ENTRY)
3232 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
3236 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3238 drawCursor(y, FC_RED);
3239 drawCursor(choice, FC_BLUE);
3240 choice = choice_store[setup_mode] = y;
3243 else if (!(setup_info[y].type & TYPE_GHOSTED))
3245 /* when selecting key headline, execute function for key value change */
3246 if (setup_info[y].type & TYPE_KEYTEXT &&
3247 setup_info[y + 1].type & TYPE_KEY)
3250 /* when selecting string value, execute function for list selection */
3251 if (setup_info[y].type & TYPE_STRING && y > 0 &&
3252 setup_info[y - 1].type & TYPE_ENTER_LIST)
3255 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3257 void (*menu_callback_function)(void) = setup_info[y].value;
3259 menu_callback_function();
3263 if (setup_info[y].type & TYPE_VALUE)
3264 changeSetupValue(y);
3269 if (IN_VIS_FIELD(x, y) &&
3270 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3276 drawCursor(y, FC_RED);
3277 drawCursor(choice, FC_BLUE);
3278 choice = choice_store[setup_mode] = y;
3281 else if (!(setup_info[y].type & TYPE_GHOSTED))
3283 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3285 void (*menu_callback_function)(void) = setup_info[choice].value;
3287 menu_callback_function();
3291 if (setup_info[y].type & TYPE_KEYTEXT &&
3292 setup_info[y + 1].type & TYPE_KEY)
3295 if (setup_info[y].type & TYPE_VALUE)
3296 changeSetupValue(y);
3303 void DrawSetupScreen_Input()
3308 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
3310 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
3313 initCursor(0, IMG_MENU_BUTTON);
3314 initCursor(1, IMG_MENU_BUTTON);
3315 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
3316 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
3319 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
3320 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
3323 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
3324 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
3325 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
3328 DeactivateJoystickForCalibration();
3331 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3332 "Joysticks deactivated on this screen");
3336 /* create gadgets for setup input menu screen */
3337 FreeScreenGadgets();
3338 CreateScreenGadgets();
3340 /* map gadgets for setup input menu screen */
3341 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
3344 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
3349 static void setJoystickDeviceToNr(char *device_name, int device_nr)
3351 if (device_name == NULL)
3354 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
3357 if (strlen(device_name) > 1)
3359 char c1 = device_name[strlen(device_name) - 1];
3360 char c2 = device_name[strlen(device_name) - 2];
3362 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
3363 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
3366 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
3367 strlen(device_name));
3370 static void drawPlayerSetupInputInfo(int player_nr)
3373 static struct SetupKeyboardInfo custom_key;
3380 { &custom_key.left, "Joystick Left" },
3381 { &custom_key.right, "Joystick Right" },
3382 { &custom_key.up, "Joystick Up" },
3383 { &custom_key.down, "Joystick Down" },
3384 { &custom_key.snap, "Button 1" },
3385 { &custom_key.drop, "Button 2" }
3387 static char *joystick_name[MAX_PLAYERS] =
3397 custom_key = setup.input[player_nr].key;
3399 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
3400 FONT_INPUT_1_ACTIVE);
3402 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3404 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3405 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
3407 if (setup.input[player_nr].use_joystick)
3409 char *device_name = setup.input[player_nr].joy.device_name;
3410 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
3411 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
3413 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
3414 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
3418 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
3419 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
3422 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
3423 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
3424 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
3425 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
3426 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
3427 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
3428 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
3429 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
3430 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
3431 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
3432 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
3434 for (i = 0; i < 6; i++)
3436 int ypos = 6 + i + (i > 3 ? i-3 : 0);
3438 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3440 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3441 (setup.input[player_nr].use_joystick ?
3443 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
3447 static int input_player_nr = 0;
3449 void HandleSetupScreen_Input_Player(int step, int direction)
3451 int old_player_nr = input_player_nr;
3454 new_player_nr = old_player_nr + step * direction;
3455 if (new_player_nr < 0)
3457 if (new_player_nr > MAX_PLAYERS - 1)
3458 new_player_nr = MAX_PLAYERS - 1;
3460 if (new_player_nr != old_player_nr)
3462 input_player_nr = new_player_nr;
3464 drawPlayerSetupInputInfo(input_player_nr);
3468 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
3470 static int choice = 0;
3473 int pos_start = SETUPINPUT_SCREEN_POS_START;
3474 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
3475 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
3476 int pos_end = SETUPINPUT_SCREEN_POS_END;
3478 if (button == MB_MENU_INITIALIZE)
3480 drawPlayerSetupInputInfo(input_player_nr);
3481 drawCursor(choice, FC_RED);
3485 else if (button == MB_MENU_LEAVE)
3487 setup_mode = SETUP_MODE_MAIN;
3494 if (mx || my) /* mouse input */
3496 x = (mx - mSX) / 32;
3497 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3499 else if (dx || dy) /* keyboard input */
3501 if (dx && choice == 0)
3502 x = (dx < 0 ? 10 : 12);
3503 else if ((dx && choice == 1) ||
3504 (dx == +1 && choice == 2) ||
3505 (dx == -1 && choice == pos_end))
3506 button = MB_MENU_CHOICE;
3510 if (y >= pos_empty1 && y <= pos_empty2)
3511 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
3516 if (y == 0 && dx != 0 && button)
3518 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
3523 if (IN_VIS_FIELD(x, y) &&
3524 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
3526 static unsigned long delay = 0;
3528 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3532 (input_player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3534 drawPlayerSetupInputInfo(input_player_nr);
3539 else if (IN_VIS_FIELD(x, y) &&
3540 y >= pos_start && y <= pos_end &&
3541 !(y >= pos_empty1 && y <= pos_empty2))
3547 drawCursor(y, FC_RED);
3548 drawCursor(choice, FC_BLUE);
3556 char *device_name = setup.input[input_player_nr].joy.device_name;
3558 if (!setup.input[input_player_nr].use_joystick)
3560 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3562 setJoystickDeviceToNr(device_name, new_device_nr);
3563 setup.input[input_player_nr].use_joystick = TRUE;
3567 int device_nr = getJoystickNrFromDeviceName(device_name);
3568 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3570 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3571 setup.input[input_player_nr].use_joystick = FALSE;
3573 setJoystickDeviceToNr(device_name, new_device_nr);
3576 drawPlayerSetupInputInfo(input_player_nr);
3580 if (setup.input[input_player_nr].use_joystick)
3583 CalibrateJoystick(input_player_nr);
3586 CustomizeKeyboard(input_player_nr);
3588 else if (y == pos_end)
3592 setup_mode = SETUP_MODE_MAIN;
3599 void CustomizeKeyboard(int player_nr)
3603 boolean finished = FALSE;
3604 static struct SetupKeyboardInfo custom_key;
3609 } customize_step[] =
3611 { &custom_key.left, "Move Left" },
3612 { &custom_key.right, "Move Right" },
3613 { &custom_key.up, "Move Up" },
3614 { &custom_key.down, "Move Down" },
3615 { &custom_key.snap, "Snap Field" },
3616 { &custom_key.drop, "Drop Element" }
3619 /* read existing key bindings from player setup */
3620 custom_key = setup.input[player_nr].key;
3625 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3627 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3634 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3635 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3636 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3637 "Key:", FONT_INPUT_1_ACTIVE);
3638 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3639 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3643 if (PendingEvent()) /* got event */
3651 case EVENT_KEYPRESS:
3653 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3655 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3661 /* all keys configured -- wait for "Escape" or "Return" key */
3665 /* press 'Enter' to keep the existing key binding */
3666 if (key == KSYM_Return)
3667 key = *customize_step[step_nr].key;
3669 /* check if key already used */
3670 for (i = 0; i < step_nr; i++)
3671 if (*customize_step[i].key == key)
3676 /* got new key binding */
3677 *customize_step[step_nr].key = key;
3678 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3680 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3681 getKeyNameFromKey(key), FONT_VALUE_1);
3684 /* un-highlight last query */
3685 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3686 customize_step[step_nr - 1].text, FONT_MENU_1);
3687 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3688 "Key:", FONT_MENU_1);
3690 /* press 'Enter' to leave */
3693 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3694 "Press Enter", FONT_TITLE_1);
3698 /* query next key binding */
3699 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3700 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3701 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3702 "Key:", FONT_INPUT_1_ACTIVE);
3703 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3704 getKeyNameFromKey(*customize_step[step_nr].key),
3709 case EVENT_KEYRELEASE:
3710 key_joystick_mapping = 0;
3714 HandleOtherEvents(&event);
3722 /* don't eat all CPU time */
3726 /* write new key bindings back to player setup */
3727 setup.input[player_nr].key = custom_key;
3730 DrawSetupScreen_Input();
3733 static boolean CalibrateJoystickMain(int player_nr)
3735 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3736 int new_joystick_xright = JOYSTICK_XMIDDLE;
3737 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3738 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3739 int new_joystick_xmiddle, new_joystick_ymiddle;
3741 int joystick_fd = joystick.fd[player_nr];
3742 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3743 boolean check[3][3];
3744 int check_remaining = 3 * 3;
3749 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3752 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3757 for (y = 0; y < 3; y++)
3759 for (x = 0; x < 3; x++)
3761 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3762 check[x][y] = FALSE;
3766 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3767 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3768 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3769 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3770 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3771 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3772 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3774 joy_value = Joystick(player_nr);
3775 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3776 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3778 /* eventually uncalibrated center position (joystick could be uncentered) */
3779 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3782 new_joystick_xmiddle = joy_x;
3783 new_joystick_ymiddle = joy_y;
3785 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3788 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3793 if (PendingEvent()) /* got event */
3801 case EVENT_KEYPRESS:
3802 switch(GetEventKey((KeyEvent *)&event, TRUE))
3805 if (check_remaining == 0)
3818 case EVENT_KEYRELEASE:
3819 key_joystick_mapping = 0;
3823 HandleOtherEvents(&event);
3828 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3831 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3832 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3833 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3834 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3836 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3837 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3838 setup.input[player_nr].joy.xright = new_joystick_xright;
3839 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3840 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3841 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3843 CheckJoystickData();
3845 joy_value = Joystick(player_nr);
3847 if (joy_value & JOY_BUTTON && check_remaining == 0)
3850 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3851 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3853 if (x != last_x || y != last_y)
3855 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3856 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3861 if (check_remaining > 0 && !check[x+1][y+1])
3863 check[x+1][y+1] = TRUE;
3869 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3870 setup.input[player_nr].joy.xleft,
3871 setup.input[player_nr].joy.xmiddle,
3872 setup.input[player_nr].joy.xright);
3873 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3874 setup.input[player_nr].joy.yupper,
3875 setup.input[player_nr].joy.ymiddle,
3876 setup.input[player_nr].joy.ylower);
3885 /* don't eat all CPU time */
3889 /* calibrated center position (joystick should now be centered) */
3890 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3893 new_joystick_xmiddle = joy_x;
3894 new_joystick_ymiddle = joy_y;
3899 DrawSetupScreen_Input();
3902 /* wait until the last pressed button was released */
3903 while (Joystick(player_nr) & JOY_BUTTON)
3905 if (PendingEvent()) /* got event */
3910 HandleOtherEvents(&event);
3919 void CalibrateJoystick(int player_nr)
3921 if (!CalibrateJoystickMain(player_nr))
3923 char *device_name = setup.input[player_nr].joy.device_name;
3924 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3925 int xpos = mSX - SX;
3926 int ypos = mSY - SY;
3930 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3931 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3934 Delay(2000); /* show error message for a short time */
3940 DrawSetupScreen_Input();
3944 void DrawSetupScreen()
3946 DeactivateJoystick();
3948 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3950 if (setup_mode == SETUP_MODE_INPUT)
3951 DrawSetupScreen_Input();
3952 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3953 DrawChooseTree(&screen_mode_current);
3954 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3955 DrawChooseTree(&artwork.gfx_current);
3956 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3957 DrawChooseTree(&artwork.snd_current);
3958 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3959 DrawChooseTree(&artwork.mus_current);
3961 DrawSetupScreen_Generic();
3967 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3969 if (setup_mode == SETUP_MODE_INPUT)
3970 HandleSetupScreen_Input(mx, my, dx, dy, button);
3971 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3972 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
3973 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3974 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
3975 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3976 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
3977 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3978 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
3980 HandleSetupScreen_Generic(mx, my, dx, dy, button);
3985 void HandleGameActions()
3987 if (game_status != GAME_MODE_PLAYING)
3990 GameActions(); /* main game loop */
3992 if (tape.auto_play && !tape.playing)
3993 AutoPlayTape(); /* continue automatically playing next tape */
3997 /* ---------- new screen button stuff -------------------------------------- */
3999 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
4003 case SCREEN_CTRL_ID_LAST_LEVEL:
4004 *x = mSX + TILEX * getLastLevelButtonPos();
4005 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4008 case SCREEN_CTRL_ID_NEXT_LEVEL:
4009 *x = mSX + TILEX * getNextLevelButtonPos();
4010 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4013 case SCREEN_CTRL_ID_LAST_PLAYER:
4014 *x = mSX + TILEX * 10;
4015 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4018 case SCREEN_CTRL_ID_NEXT_PLAYER:
4019 *x = mSX + TILEX * 12;
4020 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4024 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
4030 int gfx_unpressed, gfx_pressed;
4031 void (*get_gadget_position)(int *, int *, int);
4035 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
4038 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
4039 getScreenMenuButtonPos,
4040 SCREEN_CTRL_ID_LAST_LEVEL,
4045 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
4046 getScreenMenuButtonPos,
4047 SCREEN_CTRL_ID_NEXT_LEVEL,
4052 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
4053 getScreenMenuButtonPos,
4054 SCREEN_CTRL_ID_LAST_PLAYER,
4059 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
4060 getScreenMenuButtonPos,
4061 SCREEN_CTRL_ID_NEXT_PLAYER,
4069 int gfx_unpressed, gfx_pressed;
4073 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
4076 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
4077 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
4078 SCREEN_CTRL_ID_SCROLL_UP,
4082 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
4083 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
4084 SCREEN_CTRL_ID_SCROLL_DOWN,
4091 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4092 Bitmap **gfx_unpressed, **gfx_pressed;
4094 int gfx_unpressed, gfx_pressed;
4101 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
4104 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4105 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
4107 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
4109 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
4110 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
4111 GD_TYPE_SCROLLBAR_VERTICAL,
4112 SCREEN_CTRL_ID_SCROLL_VERTICAL,
4113 "scroll level series vertically"
4117 static void CreateScreenMenubuttons()
4119 struct GadgetInfo *gi;
4120 unsigned long event_mask;
4123 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4125 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4126 int gfx_unpressed, gfx_pressed;
4127 int x, y, width, height;
4128 int gd_x1, gd_x2, gd_y1, gd_y2;
4129 int id = menubutton_info[i].gadget_id;
4131 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4133 menubutton_info[i].get_gadget_position(&x, &y, id);
4135 width = SC_MENUBUTTON_XSIZE;
4136 height = SC_MENUBUTTON_YSIZE;
4138 gfx_unpressed = menubutton_info[i].gfx_unpressed;
4139 gfx_pressed = menubutton_info[i].gfx_pressed;
4140 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4141 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4142 gd_x1 = graphic_info[gfx_unpressed].src_x;
4143 gd_y1 = graphic_info[gfx_unpressed].src_y;
4144 gd_x2 = graphic_info[gfx_pressed].src_x;
4145 gd_y2 = graphic_info[gfx_pressed].src_y;
4147 gi = CreateGadget(GDI_CUSTOM_ID, id,
4148 GDI_CUSTOM_TYPE_ID, i,
4149 GDI_INFO_TEXT, menubutton_info[i].infotext,
4154 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4155 GDI_STATE, GD_BUTTON_UNPRESSED,
4156 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4157 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4158 GDI_DIRECT_DRAW, FALSE,
4159 GDI_EVENT_MASK, event_mask,
4160 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4164 Error(ERR_EXIT, "cannot create gadget");
4166 screen_gadget[id] = gi;
4170 static void CreateScreenScrollbuttons()
4172 struct GadgetInfo *gi;
4173 unsigned long event_mask;
4176 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4178 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4179 int gfx_unpressed, gfx_pressed;
4180 int x, y, width, height;
4181 int gd_x1, gd_x2, gd_y1, gd_y2;
4182 int id = scrollbutton_info[i].gadget_id;
4184 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4186 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
4187 y = mSY + scrollbutton_info[i].y;
4188 width = SC_SCROLLBUTTON_XSIZE;
4189 height = SC_SCROLLBUTTON_YSIZE;
4191 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
4192 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
4193 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
4195 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
4196 gfx_pressed = scrollbutton_info[i].gfx_pressed;
4197 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4198 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4199 gd_x1 = graphic_info[gfx_unpressed].src_x;
4200 gd_y1 = graphic_info[gfx_unpressed].src_y;
4201 gd_x2 = graphic_info[gfx_pressed].src_x;
4202 gd_y2 = graphic_info[gfx_pressed].src_y;
4204 gi = CreateGadget(GDI_CUSTOM_ID, id,
4205 GDI_CUSTOM_TYPE_ID, i,
4206 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4211 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4212 GDI_STATE, GD_BUTTON_UNPRESSED,
4213 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4214 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4215 GDI_DIRECT_DRAW, FALSE,
4216 GDI_EVENT_MASK, event_mask,
4217 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4221 Error(ERR_EXIT, "cannot create gadget");
4223 screen_gadget[id] = gi;
4227 static void CreateScreenScrollbars()
4231 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4233 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4234 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4235 int gfx_unpressed, gfx_pressed;
4237 int x, y, width, height;
4238 int gd_x1, gd_x2, gd_y1, gd_y2;
4239 struct GadgetInfo *gi;
4240 int items_max, items_visible, item_position;
4241 unsigned long event_mask;
4242 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4243 int id = scrollbar_info[i].gadget_id;
4245 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
4247 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
4248 y = mSY + scrollbar_info[i].y;
4249 width = scrollbar_info[i].width;
4250 height = scrollbar_info[i].height;
4252 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
4253 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
4255 items_max = num_page_entries;
4256 items_visible = num_page_entries;
4259 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4260 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
4261 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
4267 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
4268 gfx_pressed = scrollbar_info[i].gfx_pressed;
4269 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4270 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4271 gd_x1 = graphic_info[gfx_unpressed].src_x;
4272 gd_y1 = graphic_info[gfx_unpressed].src_y;
4273 gd_x2 = graphic_info[gfx_pressed].src_x;
4274 gd_y2 = graphic_info[gfx_pressed].src_y;
4277 gi = CreateGadget(GDI_CUSTOM_ID, id,
4278 GDI_CUSTOM_TYPE_ID, i,
4279 GDI_INFO_TEXT, scrollbar_info[i].infotext,
4284 GDI_TYPE, scrollbar_info[i].type,
4285 GDI_SCROLLBAR_ITEMS_MAX, items_max,
4286 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
4287 GDI_SCROLLBAR_ITEM_POSITION, item_position,
4288 GDI_WHEEL_AREA_X, 0,
4289 GDI_WHEEL_AREA_Y, 0,
4290 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
4291 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
4292 GDI_STATE, GD_BUTTON_UNPRESSED,
4293 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4294 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4295 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
4296 GDI_DIRECT_DRAW, FALSE,
4297 GDI_EVENT_MASK, event_mask,
4298 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4302 Error(ERR_EXIT, "cannot create gadget");
4304 screen_gadget[id] = gi;
4308 void CreateScreenGadgets()
4310 int last_game_status = game_status; /* save current game status */
4312 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4315 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4317 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
4319 /* copy pointers to clip mask and GC */
4320 scrollbar_bitmap[i]->clip_mask =
4321 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
4322 scrollbar_bitmap[i]->stored_clip_gc =
4323 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
4325 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
4326 scrollbar_bitmap[i],
4327 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
4328 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
4329 TILEX, TILEY, 0, 0);
4333 CreateScreenMenubuttons();
4335 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
4336 game_status = GAME_MODE_LEVELS;
4338 CreateScreenScrollbuttons();
4339 CreateScreenScrollbars();
4341 game_status = last_game_status; /* restore current game status */
4344 void FreeScreenGadgets()
4348 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4349 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4351 /* prevent freeing clip mask and GC twice */
4352 scrollbar_bitmap[i]->clip_mask = None;
4353 scrollbar_bitmap[i]->stored_clip_gc = None;
4355 FreeBitmap(scrollbar_bitmap[i]);
4359 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
4360 FreeGadget(screen_gadget[i]);
4363 void MapScreenMenuGadgets(int screen_mask)
4367 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4368 if (screen_mask & menubutton_info[i].screen_mask)
4369 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
4372 void MapScreenTreeGadgets(TreeInfo *ti)
4374 int num_entries = numTreeInfoInGroup(ti);
4377 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4380 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4381 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
4383 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4384 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
4387 static void HandleScreenGadgets(struct GadgetInfo *gi)
4389 int id = gi->custom_id;
4390 int button = gi->event.button;
4391 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4394 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
4400 case SCREEN_CTRL_ID_LAST_LEVEL:
4401 HandleMainMenu_SelectLevel(step, -1);
4404 case SCREEN_CTRL_ID_NEXT_LEVEL:
4405 HandleMainMenu_SelectLevel(step, +1);
4408 case SCREEN_CTRL_ID_LAST_PLAYER:
4409 HandleSetupScreen_Input_Player(step, -1);
4412 case SCREEN_CTRL_ID_NEXT_PLAYER:
4413 HandleSetupScreen_Input_Player(step, +1);
4416 case SCREEN_CTRL_ID_SCROLL_UP:
4417 if (game_status == GAME_MODE_LEVELS)
4418 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4419 else if (game_status == GAME_MODE_SETUP)
4420 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4423 case SCREEN_CTRL_ID_SCROLL_DOWN:
4424 if (game_status == GAME_MODE_LEVELS)
4425 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4426 else if (game_status == GAME_MODE_SETUP)
4427 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4430 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
4431 if (game_status == GAME_MODE_LEVELS)
4432 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
4433 else if (game_status == GAME_MODE_SETUP)
4434 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);