1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
27 /* screens in the setup menu */
28 #define SETUP_MODE_MAIN 0
29 #define SETUP_MODE_GAME 1
30 #define SETUP_MODE_EDITOR 2
31 #define SETUP_MODE_INPUT 3
32 #define SETUP_MODE_SHORTCUT_1 4
33 #define SETUP_MODE_SHORTCUT_2 5
34 #define SETUP_MODE_GRAPHICS 6
35 #define SETUP_MODE_CHOOSE_SCREEN_MODE 7
36 #define SETUP_MODE_SOUND 8
37 #define SETUP_MODE_ARTWORK 9
38 #define SETUP_MODE_CHOOSE_GRAPHICS 10
39 #define SETUP_MODE_CHOOSE_SOUNDS 11
40 #define SETUP_MODE_CHOOSE_MUSIC 12
42 #define MAX_SETUP_MODES 13
44 /* for input setup functions */
45 #define SETUPINPUT_SCREEN_POS_START 0
46 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
47 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
48 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
50 /* screens on the info screen */
51 #define INFO_MODE_MAIN 0
52 #define INFO_MODE_TITLE 1
53 #define INFO_MODE_ELEMENTS 2
54 #define INFO_MODE_MUSIC 3
55 #define INFO_MODE_CREDITS 4
56 #define INFO_MODE_PROGRAM 5
57 #define INFO_MODE_LEVELSET 6
59 #define MAX_INFO_MODES 7
61 /* for various menu stuff */
62 #define MENU_SCREEN_START_XPOS 1
63 #define MENU_SCREEN_START_YPOS 2
64 #define MENU_SCREEN_VALUE_XPOS 14
65 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
66 #define MENU_TITLE1_YPOS 8
67 #define MENU_TITLE2_YPOS 46
68 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
69 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
70 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
71 MENU_SCREEN_START_XPOS)
72 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
74 /* buttons and scrollbars identifiers */
75 #define SCREEN_CTRL_ID_LAST_LEVEL 0
76 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
77 #define SCREEN_CTRL_ID_LAST_PLAYER 2
78 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
79 #define SCREEN_CTRL_ID_SCROLL_UP 4
80 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
81 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
83 #define NUM_SCREEN_GADGETS 7
85 #define NUM_SCREEN_MENUBUTTONS 4
86 #define NUM_SCREEN_SCROLLBUTTONS 2
87 #define NUM_SCREEN_SCROLLBARS 1
89 #define SCREEN_MASK_MAIN (1 << 0)
90 #define SCREEN_MASK_INPUT (1 << 1)
92 /* graphic position and size values for buttons and scrollbars */
93 #define SC_MENUBUTTON_XSIZE TILEX
94 #define SC_MENUBUTTON_YSIZE TILEY
96 #define SC_SCROLLBUTTON_XSIZE TILEX
97 #define SC_SCROLLBUTTON_YSIZE TILEY
99 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
101 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
102 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
103 SC_SCROLLBUTTON_YSIZE)
105 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
106 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
108 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
109 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
110 SC_SCROLLBUTTON_YSIZE)
112 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
113 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
114 SC_SCROLL_VERTICAL_YSIZE)
116 #define SC_BORDER_SIZE 14
119 /* forward declarations of internal functions */
120 static void HandleScreenGadgets(struct GadgetInfo *);
121 static void HandleSetupScreen_Generic(int, int, int, int, int);
122 static void HandleSetupScreen_Input(int, int, int, int, int);
123 static void CustomizeKeyboard(int);
124 static void CalibrateJoystick(int);
125 static void execSetupGraphics(void);
126 static void execSetupArtwork(void);
127 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
129 static void DrawChooseLevel(void);
130 static void DrawInfoScreen(void);
131 static void DrawSetupScreen(void);
133 static void DrawInfoScreenExt(int);
134 static void DrawInfoScreen_NotAvailable(char *, char *);
135 static void DrawInfoScreen_HelpAnim(int, int, boolean);
136 static void DrawInfoScreen_HelpText(int, int, int, int);
137 static void HandleInfoScreen_Main(int, int, int, int, int);
138 static void HandleInfoScreen_TitleScreen(int);
139 static void HandleInfoScreen_Elements(int);
140 static void HandleInfoScreen_Music(int);
141 static void HandleInfoScreen_Credits(int);
142 static void HandleInfoScreen_Program(int);
144 static void MapScreenMenuGadgets(int);
145 static void MapScreenTreeGadgets(TreeInfo *);
147 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
148 static int setup_mode = SETUP_MODE_MAIN;
149 static int info_mode = INFO_MODE_MAIN;
151 static TreeInfo *screen_modes = NULL;
152 static TreeInfo *screen_mode_current = NULL;
154 #define DRAW_OFFSET_MODE(x) (x >= GAME_MODE_MAIN && \
155 x <= GAME_MODE_SETUP ? x : \
156 x == GAME_MODE_PSEUDO_TYPENAME ? \
157 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
159 #define mSX (SX + menu.draw_xoffset[DRAW_OFFSET_MODE(game_status)])
160 #define mSY (SY + menu.draw_yoffset[DRAW_OFFSET_MODE(game_status)])
162 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
163 menu.list_size[game_status] : \
164 MAX_MENU_ENTRIES_ON_SCREEN)
166 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
167 #define NUM_SCROLLBAR_BITMAPS 2
168 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
172 static void drawCursorExt(int xpos, int ypos, int color, int g)
174 static int cursor_array[SCR_FIELDY];
179 cursor_array[ypos] = g;
181 g = cursor_array[ypos];
185 g = (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE :
186 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE :
187 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE :
188 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE :
189 g == IMG_MENU_BUTTON_LAST_LEVEL ? IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE :
190 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE :
191 IMG_MENU_BUTTON_ACTIVE);
193 ypos += MENU_SCREEN_START_YPOS;
195 DrawBackground(mSX + xpos * TILEX, mSY + ypos * TILEY, TILEX, TILEY);
196 DrawGraphicThruMaskExt(drawto, mSX + xpos * TILEX, mSY + ypos * TILEY, g, 0);
199 static void initCursor(int ypos, int graphic)
201 drawCursorExt(0, ypos, FC_BLUE, graphic);
204 static void drawCursor(int ypos, int color)
206 drawCursorExt(0, ypos, color, 0);
209 static void drawCursorXY(int xpos, int ypos, int graphic)
211 drawCursorExt(xpos, ypos, -1, graphic);
214 static void drawChooseTreeCursor(int ypos, int color)
216 int last_game_status = game_status; /* save current game status */
218 /* force LEVELS draw offset on artwork setup screen */
219 game_status = GAME_MODE_LEVELS;
221 drawCursorExt(0, ypos, color, 0);
223 game_status = last_game_status; /* restore current game status */
228 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
229 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
232 static void ToggleFullscreenIfNeeded()
234 if (setup.fullscreen != video.fullscreen_enabled ||
235 setup.fullscreen_mode != video.fullscreen_mode_current)
237 /* save old door content */
238 BlitBitmap(backbuffer, bitmap_db_door,
239 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
241 if (setup.fullscreen && video.fullscreen_enabled)
243 /* keep fullscreen mode, but change screen mode */
244 video.fullscreen_mode_current = setup.fullscreen_mode;
245 video.fullscreen_enabled = FALSE;
248 /* toggle fullscreen */
249 ChangeVideoModeIfNeeded(setup.fullscreen);
250 setup.fullscreen = video.fullscreen_enabled;
252 /* redraw background to newly created backbuffer */
253 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
254 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
256 /* restore old door content */
257 BlitBitmap(bitmap_db_door, backbuffer,
258 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
260 redraw_mask = REDRAW_ALL;
264 static int getLastLevelButtonPos()
269 static int getCurrentLevelTextPos()
271 return (getLastLevelButtonPos() + 1);
274 static int getNextLevelButtonPos()
276 return getLastLevelButtonPos() + 3 + 1;
279 static int getLevelRangeTextPos()
281 return getNextLevelButtonPos() + 1;
284 void DrawTitleScreenImage(int nr)
286 int graphic = IMG_TITLESCREEN_1 + nr;
287 Bitmap *bitmap = graphic_info[graphic].bitmap;
288 int width = graphic_info[graphic].src_image_width;
289 int height = graphic_info[graphic].src_image_height;
290 int src_x = 0, src_y = 0;
296 if (width > WIN_XSIZE)
298 /* image width too large for window => center image horizontally */
299 src_x = (width - WIN_XSIZE) / 2;
303 if (height > WIN_YSIZE)
305 /* image height too large for window => center image vertically */
306 src_y = (height - WIN_YSIZE) / 2;
310 dst_x = (WIN_XSIZE - width) / 2;
311 dst_y = (WIN_YSIZE - height) / 2;
313 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
315 if (DrawingOnBackground(dst_x, dst_y))
316 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
318 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
320 redraw_mask = REDRAW_ALL;
323 void DrawTitleScreen()
325 KeyboardAutoRepeatOff();
327 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
329 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
334 static void DrawMainMenuExt(int fade_delay)
336 static LevelDirTree *leveldir_last_valid = NULL;
337 boolean levelset_has_changed = FALSE;
338 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
340 char *level_text = "Levelset";
342 char *level_text = "Level:";
344 int name_width, level_width;
348 FadeSoundsAndMusic();
350 KeyboardAutoRepeatOn();
353 SetDrawDeactivationMask(REDRAW_NONE);
354 SetDrawBackgroundMask(REDRAW_FIELD);
356 audio.sound_deactivated = FALSE;
362 /* needed if last screen was the playing screen, invoked from level editor */
363 if (level_editor_test_game)
365 game_status = GAME_MODE_EDITOR;
371 /* needed if last screen was the editor screen */
372 UndrawSpecialEditorDoor();
374 /* needed if last screen was the setup screen and fullscreen state changed */
375 ToggleFullscreenIfNeeded();
377 /* leveldir_current may be invalid (level group, parent link) */
378 if (!validLevelSeries(leveldir_current))
379 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
381 if (leveldir_current != leveldir_last_valid)
382 levelset_has_changed = TRUE;
384 /* store valid level series information */
385 leveldir_last_valid = leveldir_current;
387 /* needed if last screen (level choice) changed graphics, sounds or music */
388 ReloadCustomArtwork(0);
391 SetDrawtoField(DRAW_BACKBUFFER);
394 if (setup.show_titlescreen &&
395 levelset_has_changed &&
396 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL)
398 game_status = GAME_MODE_TITLE;
405 /* map gadgets for main menu screen */
409 /* level_nr may have been set to value over handicap with level editor */
410 if (setup.handicap && level_nr > leveldir_current->handicap_level)
411 level_nr = leveldir_current->handicap_level;
418 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
423 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
424 DrawText(mSX + 32, mSY + 3 * 32, level_text, FONT_MENU_1);
425 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
426 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
427 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
428 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
429 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
430 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
432 /* calculated after (possible) reload of custom artwork */
433 name_width = getTextWidth(name_text, FONT_MENU_1);
435 level_width = 9 * 32;
438 level_width = 9 * getFontWidth(FONT_MENU_1);
440 level_width = getTextWidth(level_text, FONT_MENU_1);
444 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
448 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
449 int2str(level_nr, 3), FONT_VALUE_1);
452 DrawText(mSX + level_width + 2 * 32, mSY + 3 * 32, int2str(level_nr, 3),
455 DrawText(mSX + level_width + 5 * 32, mSY + 3 * 32, int2str(level_nr, 3),
460 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
466 int text_height = getFontHeight(FONT_TEXT_3);
468 int xpos = getLevelRangeTextPos() * 32;
470 int xpos = level_width + 6 * 32;
472 int ypos2 = -SY + 3 * 32 + 16;
473 int ypos1 = ypos2 - text_height;
475 DrawTextF(mSX + xpos, mSY + ypos1, FONT_TEXT_3,
476 "%03d", leveldir_current->first_level);
477 DrawTextF(mSX + xpos, mSY + ypos2, FONT_TEXT_3,
478 "%03d", leveldir_current->last_level);
481 DrawTextF(mSX + level_width + 6 * 32, mSY + 3 * 32 + 1, FONT_TEXT_3,
482 "%d", leveldir_current->levels);
486 DrawTextF(mSX + 32 + level_width - 2, mSY + 3 * 32 + 1, FONT_TEXT_3, "%d-%d",
487 leveldir_current->first_level, leveldir_current->last_level);
491 if (leveldir_current->readonly)
493 DrawTextS(mSX + level_width + 9 * 32 - 2,
494 mSY + 3 * 32 + 1 - 7, FONT_TEXT_3, "READ");
495 DrawTextS(mSX + level_width + 9 * 32 - 2,
496 mSY + 3 * 32 + 1 + 7, FONT_TEXT_3, "ONLY");
500 for (i = 0; i < 8; i++)
501 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
507 drawCursorXY(getLastLevelButtonPos(), 1, IMG_MENU_BUTTON_LAST_LEVEL);
508 drawCursorXY(getNextLevelButtonPos(), 1, IMG_MENU_BUTTON_NEXT_LEVEL);
511 drawCursorXY(level_width / 32 + 1, 1, IMG_MENU_BUTTON_LEFT);
512 drawCursorXY(level_width / 32 + 5, 1, IMG_MENU_BUTTON_RIGHT);
514 drawCursorXY(level_width / 32 + 4, 1, IMG_MENU_BUTTON_LEFT);
515 drawCursorXY(level_width / 32 + 8, 1, IMG_MENU_BUTTON_RIGHT);
521 DrawTextSCentered(326, FONT_TITLE_2, "A Game by Artsoft Entertainment");
530 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
533 if (TAPE_IS_EMPTY(tape))
535 DrawCompleteVideoDisplay();
542 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
545 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
547 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
556 /* create gadgets for main menu screen */
558 CreateScreenGadgets();
560 /* map gadgets for main menu screen */
562 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
578 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
588 static void gotoTopLevelDir()
590 /* move upwards to top level directory */
591 while (leveldir_current->node_parent)
593 /* write a "path" into level tree for easy navigation to last level */
594 if (leveldir_current->node_parent->node_group->cl_first == -1)
596 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
597 int leveldir_pos = posTreeInfo(leveldir_current);
598 int num_page_entries;
599 int cl_first, cl_cursor;
601 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
602 num_page_entries = num_leveldirs;
604 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
606 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
607 cl_cursor = leveldir_pos - cl_first;
609 leveldir_current->node_parent->node_group->cl_first = cl_first;
610 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
613 leveldir_current = leveldir_current->node_parent;
618 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
620 static int title_nr = 0;
621 boolean return_to_main_menu = FALSE;
622 boolean use_fading_main_menu = TRUE;
623 boolean use_cross_fading = TRUE;
624 int fade_delay = 500;
625 int post_delay = fade_delay / 2;
627 if (button == MB_MENU_INITIALIZE)
629 int last_game_status = game_status; /* save current game status */
632 if (game_status == GAME_MODE_INFO)
634 if (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
636 DrawInfoScreen_NotAvailable("Title screen information:",
637 "No title screen for this level set.");
642 FadeSoundsAndMusic();
644 FadeOut(fade_delay, post_delay);
647 /* force TITLE music on title info screen */
648 game_status = GAME_MODE_TITLE;
653 game_status = last_game_status; /* restore current game status */
655 DrawTitleScreenImage(title_nr);
661 else if (button == MB_MENU_LEAVE)
663 return_to_main_menu = TRUE;
664 use_fading_main_menu = FALSE;
666 else if (button == MB_MENU_CHOICE)
668 if (game_status == GAME_MODE_INFO &&
669 graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
671 info_mode = INFO_MODE_MAIN;
679 if (!use_cross_fading)
680 FadeOut(fade_delay, post_delay);
682 if (title_nr < MAX_NUM_TITLE_SCREENS &&
683 graphic_info[IMG_TITLESCREEN_1 + title_nr].bitmap != NULL)
685 Bitmap *drawto_last = drawto;
687 if (use_cross_fading)
688 drawto = bitmap_db_title;
690 DrawTitleScreenImage(title_nr);
692 drawto = drawto_last;
694 if (use_cross_fading)
695 FadeCross(fade_delay);
701 FadeSoundsAndMusic();
703 FadeOut(fade_delay, post_delay);
705 return_to_main_menu = TRUE;
709 if (return_to_main_menu)
711 int menu_fade_delay = (use_fading_main_menu ? fade_delay : 0);
715 if (game_status == GAME_MODE_INFO)
717 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
719 info_mode = INFO_MODE_MAIN;
720 DrawInfoScreenExt(menu_fade_delay);
722 else /* default: return to main menu */
724 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
726 game_status = GAME_MODE_MAIN;
727 DrawMainMenuExt(menu_fade_delay);
732 void HandleMainMenu_SelectLevel(int step, int direction)
734 int old_level_nr = level_nr;
737 new_level_nr = old_level_nr + step * direction;
738 if (new_level_nr < leveldir_current->first_level)
739 new_level_nr = leveldir_current->first_level;
740 if (new_level_nr > leveldir_current->last_level)
741 new_level_nr = leveldir_current->last_level;
743 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
745 /* skipping levels is only allowed when trying to skip single level */
746 if (setup.skip_levels && step == 1 &&
747 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
749 leveldir_current->handicap_level++;
750 SaveLevelSetup_SeriesInfo();
753 new_level_nr = leveldir_current->handicap_level;
756 if (new_level_nr != old_level_nr)
758 level_nr = new_level_nr;
760 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
763 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
767 DrawCompleteVideoDisplay();
769 /* needed because DrawMicroLevel() takes some time */
775 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
778 static unsigned long level_delay = 0;
779 static unsigned long level_delay_value = GADGET_FRAME_DELAY;
781 static int choice = 5;
785 if (button == MB_MENU_INITIALIZE)
787 drawCursor(choice, FC_RED);
791 if (mx || my) /* mouse input */
794 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
796 else if (dx || dy) /* keyboard input */
798 if (dx && choice == 1)
799 x = (dx < 0 ? 10 : 14);
802 if (choice == 4 || choice == 6)
803 button = MB_MENU_CHOICE;
810 /* start gadget delay with longer delay after first click on gadget */
812 pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
817 if (y == 1 && dx != 0 && button)
819 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
824 if (y == 1 && ((x == 10 && level_nr > leveldir_current->first_level) ||
825 (x == 14 && level_nr < leveldir_current->last_level)) &&
826 button && DelayReached(&level_delay, level_delay_value))
828 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
829 int old_level_nr = level_nr;
832 new_level_nr = level_nr + (x == 10 ? -step : +step);
833 if (new_level_nr < leveldir_current->first_level)
834 new_level_nr = leveldir_current->first_level;
835 if (new_level_nr > leveldir_current->last_level)
836 new_level_nr = leveldir_current->last_level;
838 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
840 /* skipping levels is only allowed when trying to skip single level */
841 if (setup.skip_levels && step == 1 &&
842 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
844 leveldir_current->handicap_level++;
845 SaveLevelSetup_SeriesInfo();
848 new_level_nr = leveldir_current->handicap_level;
851 if (new_level_nr != old_level_nr)
853 level_nr = new_level_nr;
855 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3),
859 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, TRUE);
863 DrawCompleteVideoDisplay();
865 /* needed because DrawMicroLevel() takes some time */
869 DelayReached(&level_delay, 0); /* reset delay counter */
871 pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
878 else if (IN_VIS_FIELD(x, y) &&
879 y >= 0 && y <= 7 && (y != 1 || x < 10))
885 drawCursor(y, FC_RED);
886 drawCursor(choice, FC_BLUE);
894 game_status = GAME_MODE_PSEUDO_TYPENAME;
895 HandleTypeName(strlen(setup.player_name), 0);
901 game_status = GAME_MODE_LEVELS;
902 SaveLevelSetup_LastSeries();
903 SaveLevelSetup_SeriesInfo();
914 game_status = GAME_MODE_SCORES;
919 if (leveldir_current->readonly &&
920 !strEqual(setup.player_name, "Artsoft"))
921 Request("This level is read only !", REQ_CONFIRM);
922 game_status = GAME_MODE_EDITOR;
927 game_status = GAME_MODE_INFO;
928 info_mode = INFO_MODE_MAIN;
933 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
937 game_status = GAME_MODE_SETUP;
938 setup_mode = SETUP_MODE_MAIN;
944 SaveLevelSetup_LastSeries();
945 SaveLevelSetup_SeriesInfo();
947 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
948 game_status = GAME_MODE_QUIT;
953 if (game_status == GAME_MODE_MAIN)
955 DrawMicroLevel(MICROLEVEL_XPOS, MICROLEVEL_YPOS, FALSE);
961 /* ========================================================================= */
962 /* info screen functions */
963 /* ========================================================================= */
965 static struct TokenInfo *info_info;
966 static int num_info_info;
968 static void execInfoTitleScreen()
970 info_mode = INFO_MODE_TITLE;
974 static void execInfoElements()
976 info_mode = INFO_MODE_ELEMENTS;
980 static void execInfoMusic()
982 info_mode = INFO_MODE_MUSIC;
986 static void execInfoCredits()
988 info_mode = INFO_MODE_CREDITS;
992 static void execInfoProgram()
994 info_mode = INFO_MODE_PROGRAM;
998 static void execInfoLevelSet()
1000 info_mode = INFO_MODE_LEVELSET;
1004 static void execExitInfo()
1006 game_status = GAME_MODE_MAIN;
1010 static struct TokenInfo info_info_main[] =
1012 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1013 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1014 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1015 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1016 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1017 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1018 { TYPE_EMPTY, NULL, "" },
1019 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1024 static void DrawInfoScreen_Main(int fade_delay)
1029 CloseDoor(DOOR_CLOSE_2);
1034 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1036 DrawText(mSX + 16, mSY + 16, "Info Screen", FONT_TITLE_1);
1039 info_info = info_info_main;
1042 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1044 int xpos = MENU_SCREEN_START_XPOS;
1045 int ypos = MENU_SCREEN_START_YPOS + i;
1046 int font_nr = FONT_MENU_1;
1048 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
1050 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1051 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1052 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1053 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1054 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1055 initCursor(i, IMG_MENU_BUTTON);
1062 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1078 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1082 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1084 static int choice_store[MAX_INFO_MODES];
1085 int choice = choice_store[info_mode]; /* always starts with 0 */
1089 if (button == MB_MENU_INITIALIZE)
1091 /* advance to first valid menu entry */
1092 while (choice < num_info_info &&
1093 info_info[choice].type & TYPE_SKIP_ENTRY)
1095 choice_store[info_mode] = choice;
1097 drawCursor(choice, FC_RED);
1100 else if (button == MB_MENU_LEAVE)
1102 for (y = 0; y < num_info_info; y++)
1104 if (info_info[y].type & TYPE_LEAVE_MENU)
1106 void (*menu_callback_function)(void) = info_info[y].value;
1108 menu_callback_function();
1109 break; /* absolutely needed because function changes 'info_info'! */
1116 if (mx || my) /* mouse input */
1118 x = (mx - mSX) / 32;
1119 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1121 else if (dx || dy) /* keyboard input */
1125 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
1127 if (info_info[choice].type & menu_navigation_type ||
1128 info_info[choice].type & TYPE_ENTER_SCREEN ||
1129 info_info[choice].type & TYPE_BOOLEAN_STYLE)
1130 button = MB_MENU_CHOICE;
1135 /* jump to next non-empty menu entry (up or down) */
1136 while (y > 0 && y < num_info_info - 1 &&
1137 info_info[y].type & TYPE_SKIP_ENTRY)
1141 if (IN_VIS_FIELD(x, y) &&
1142 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
1148 drawCursor(y, FC_RED);
1149 drawCursor(choice, FC_BLUE);
1150 choice = choice_store[info_mode] = y;
1153 else if (!(info_info[y].type & TYPE_GHOSTED))
1155 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
1157 void (*menu_callback_function)(void) = info_info[choice].value;
1159 menu_callback_function();
1165 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
1168 int ybottom = SYSIZE - 20;
1170 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1175 DrawTextSCentered(100, FONT_TEXT_1, text_title);
1177 DrawTextSCentered(ybottom, FONT_TEXT_4,
1178 "Press any key or button for info menu");
1180 DrawTextSCentered(ystart, FONT_TEXT_2, text_error);
1183 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
1185 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
1186 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
1187 int xstart = mSX + 16;
1188 int ystart = mSY + 64 + 2 * 32;
1189 int ystep = TILEY + 4;
1190 int element, action, direction;
1198 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
1199 infoscreen_step[i] = infoscreen_frame[i] = 0;
1204 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
1206 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1207 "Press any key or button for next page");
1213 while (helpanim_info[j].element != HELPANIM_LIST_END)
1215 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1220 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1229 j += infoscreen_step[i - start];
1231 element = helpanim_info[j].element;
1232 action = helpanim_info[j].action;
1233 direction = helpanim_info[j].direction;
1236 element = EL_UNKNOWN;
1238 if (action != -1 && direction != -1)
1239 graphic = el_act_dir2img(element, action, direction);
1240 else if (action != -1)
1241 graphic = el_act2img(element, action);
1242 else if (direction != -1)
1243 graphic = el_dir2img(element, direction);
1245 graphic = el2img(element);
1247 delay = helpanim_info[j++].delay;
1252 if (infoscreen_frame[i - start] == 0)
1255 infoscreen_frame[i - start] = delay - 1;
1259 sync_frame = delay - infoscreen_frame[i - start];
1260 infoscreen_frame[i - start]--;
1263 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1265 if (!infoscreen_frame[i - start])
1266 infoscreen_step[i - start] = 0;
1270 if (!infoscreen_frame[i - start])
1271 infoscreen_step[i - start]++;
1272 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1278 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1280 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1281 graphic, sync_frame, USE_MASKING);
1284 DrawInfoScreen_HelpText(element, action, direction, i - start);
1289 redraw_mask |= REDRAW_FIELD;
1294 static char *getHelpText(int element, int action, int direction)
1296 char token[MAX_LINE_LEN];
1298 strcpy(token, element_info[element].token_name);
1301 strcat(token, element_action_info[action].suffix);
1303 if (direction != -1)
1304 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1306 return getHashEntry(helptext_info, token);
1309 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1311 int font_nr = FONT_LEVEL_NUMBER;
1312 int font_width = getFontWidth(font_nr);
1313 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1314 int sy = mSY + 65 + 2 * 32 + 1;
1315 int ystep = TILEY + 4;
1316 int pad_x = sx - SX;
1317 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1318 int max_lines_per_text = 2;
1321 if (action != -1 && direction != -1) /* element.action.direction */
1322 text = getHelpText(element, action, direction);
1324 if (text == NULL && action != -1) /* element.action */
1325 text = getHelpText(element, action, -1);
1327 if (text == NULL && direction != -1) /* element.direction */
1328 text = getHelpText(element, -1, direction);
1330 if (text == NULL) /* base element */
1331 text = getHelpText(element, -1, -1);
1333 if (text == NULL) /* not found */
1334 text = "No description available";
1336 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1337 sy += getFontHeight(font_nr) / 2;
1339 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1340 max_chars_per_line, max_lines_per_text);
1343 void DrawInfoScreen_TitleScreen()
1348 void HandleInfoScreen_TitleScreen(int button)
1350 HandleTitleScreen(0, 0, 0, 0, button);
1353 void DrawInfoScreen_Elements()
1355 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1360 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1366 void HandleInfoScreen_Elements(int button)
1368 static unsigned long info_delay = 0;
1369 static int num_anims;
1370 static int num_pages;
1372 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1373 int button_released = !button;
1376 if (button == MB_MENU_INITIALIZE)
1378 boolean new_element = TRUE;
1381 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1383 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1385 else if (new_element)
1388 new_element = FALSE;
1392 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1395 else if (button == MB_MENU_LEAVE)
1397 info_mode = INFO_MODE_MAIN;
1403 if (button_released || button == MB_MENU_INITIALIZE)
1405 if (button != MB_MENU_INITIALIZE)
1408 if (page >= num_pages)
1410 FadeSoundsAndMusic();
1412 info_mode = INFO_MODE_MAIN;
1418 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1422 if (DelayReached(&info_delay, GameFrameDelay))
1423 if (page < num_pages)
1424 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1426 PlayMenuSoundIfLoop();
1430 void DrawInfoScreen_Music()
1432 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1439 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1442 void HandleInfoScreen_Music(int button)
1444 static struct MusicFileInfo *list = NULL;
1445 int ystart = 150, dy = 30;
1446 int ybottom = SYSIZE - 20;
1447 int button_released = !button;
1449 if (button == MB_MENU_INITIALIZE)
1451 list = music_file_info;
1455 FadeSoundsAndMusic();
1460 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1462 DrawTextSCentered(ybottom, FONT_TEXT_4,
1463 "Press any key or button for info menu");
1468 else if (button == MB_MENU_LEAVE)
1470 info_mode = INFO_MODE_MAIN;
1476 if (button_released || button == MB_MENU_INITIALIZE)
1480 if (button != MB_MENU_INITIALIZE)
1486 info_mode = INFO_MODE_MAIN;
1492 FadeSoundsAndMusic();
1499 int sound = list->music;
1501 if (sound_info[sound].loop)
1502 PlaySoundLoop(sound);
1506 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
1510 PlayMusic(list->music);
1512 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
1515 if (!strEqual(list->title, UNKNOWN_NAME))
1517 if (!strEqual(list->title_header, UNKNOWN_NAME))
1518 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
1520 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
1523 if (!strEqual(list->artist, UNKNOWN_NAME))
1525 if (!strEqual(list->artist_header, UNKNOWN_NAME))
1526 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
1528 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
1530 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
1533 if (!strEqual(list->album, UNKNOWN_NAME))
1535 if (!strEqual(list->album_header, UNKNOWN_NAME))
1536 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
1538 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
1540 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
1543 if (!strEqual(list->year, UNKNOWN_NAME))
1545 if (!strEqual(list->year_header, UNKNOWN_NAME))
1546 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
1548 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
1550 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
1553 DrawTextSCentered(ybottom, FONT_TEXT_4,
1554 "Press any key or button for next page");
1557 if (list != NULL && list->is_sound && sound_info[list->music].loop)
1558 PlaySoundLoop(list->music);
1561 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
1563 int ystart = 150, ystep = 30;
1564 int ybottom = SYSIZE - 20;
1569 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
1573 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1574 "Special thanks to");
1575 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1577 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1579 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1580 "\"Boulder Dash\"");
1581 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1583 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1585 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1587 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1588 "First Star Software");
1590 else if (screen_nr == 1)
1592 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1593 "Special thanks to");
1594 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1595 "Klaus Heinz & Volker Wertich");
1596 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1598 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1599 "\"Emerald Mine\"");
1600 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1602 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1604 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1606 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1609 else if (screen_nr == 2)
1611 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1612 "Special thanks to");
1613 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1614 "Michael Stopp & Philip Jespersen");
1615 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1617 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1619 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1621 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1623 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1625 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1626 "Digital Integration");
1628 else if (screen_nr == 3)
1630 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1631 "Special thanks to");
1632 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1633 "Hiroyuki Imabayashi");
1634 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1636 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1638 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1640 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1642 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1644 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
1647 else if (screen_nr == 4)
1649 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1650 "Special thanks to");
1651 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1653 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1655 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1656 "Jürgen Bonhagen");
1657 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1658 "for the continuous creation");
1659 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1660 "of outstanding level sets");
1662 else if (screen_nr == 5)
1664 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1666 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1668 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1669 "for ideas and inspiration by");
1670 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1673 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
1675 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_3,
1677 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1678 "for ideas and inspiration by");
1679 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
1682 else if (screen_nr == 6)
1684 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1686 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1688 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1689 "for the new Emerald Mine engine");
1691 else if (screen_nr == 7)
1693 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1695 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
1697 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
1698 "for the initial DOS port");
1700 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
1702 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
1704 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
1705 "for some additional toons");
1707 else if (screen_nr == 8)
1709 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1710 "And not to forget:");
1711 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1713 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1714 "All those who contributed");
1715 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
1716 "levels to this game");
1717 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_3,
1725 DrawTextSCentered(ybottom, FONT_TEXT_4,
1726 "Press any key or button for next page");
1731 void DrawInfoScreen_Credits()
1733 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
1735 FadeSoundsAndMusic();
1737 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
1740 void HandleInfoScreen_Credits(int button)
1742 static int screen_nr = 0;
1744 if (button == MB_MENU_INITIALIZE)
1748 DrawInfoScreen_CreditsScreen(screen_nr);
1750 else if (button == MB_MENU_LEAVE)
1752 info_mode = INFO_MODE_MAIN;
1757 else if (button == MB_MENU_CHOICE)
1761 if (!DrawInfoScreen_CreditsScreen(screen_nr))
1763 FadeSoundsAndMusic();
1765 info_mode = INFO_MODE_MAIN;
1771 PlayMenuSoundIfLoop();
1775 void DrawInfoScreen_Program()
1777 int ystart = 150, ystep = 30;
1778 int ybottom = SYSIZE - 20;
1780 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
1785 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
1787 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
1788 "This game is Freeware!");
1789 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
1790 "If you like it, send e-mail to:");
1791 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
1792 "info@artsoft.org");
1793 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
1794 "or SnailMail to:");
1795 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
1797 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
1798 "Detmolder Strasse 189");
1799 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
1801 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
1804 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1805 "If you have created new levels,");
1806 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_2,
1807 "send them to me to include them!");
1808 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1811 DrawTextSCentered(ybottom, FONT_TEXT_4,
1812 "Press any key or button for info menu");
1815 void HandleInfoScreen_Program(int button)
1817 int button_released = !button;
1819 if (button == MB_MENU_LEAVE)
1821 info_mode = INFO_MODE_MAIN;
1827 if (button_released)
1829 FadeSoundsAndMusic();
1831 info_mode = INFO_MODE_MAIN;
1836 PlayMenuSoundIfLoop();
1840 void DrawInfoScreen_LevelSet()
1843 int ybottom = SYSIZE - 20;
1844 char *filename = getLevelSetInfoFilename();
1845 int font_nr = FONT_LEVEL_NUMBER;
1846 int font_width = getFontWidth(font_nr);
1847 int font_height = getFontHeight(font_nr);
1850 int sx = SX + pad_x;
1851 int sy = SY + pad_y;
1852 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1853 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1855 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1860 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1862 DrawTextSCentered(ybottom, FONT_TEXT_4,
1863 "Press any key or button for info menu");
1865 if (filename != NULL)
1866 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1867 max_lines_per_screen);
1869 DrawTextSCentered(ystart, FONT_TEXT_2,
1870 "No information for this level set.");
1873 void HandleInfoScreen_LevelSet(int button)
1875 int button_released = !button;
1877 if (button == MB_MENU_LEAVE)
1879 info_mode = INFO_MODE_MAIN;
1885 if (button_released)
1887 FadeSoundsAndMusic();
1889 info_mode = INFO_MODE_MAIN;
1894 PlayMenuSoundIfLoop();
1898 static void DrawInfoScreenExt(int fade_delay)
1900 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1902 if (info_mode == INFO_MODE_TITLE)
1903 DrawInfoScreen_TitleScreen();
1904 else if (info_mode == INFO_MODE_ELEMENTS)
1905 DrawInfoScreen_Elements();
1906 else if (info_mode == INFO_MODE_MUSIC)
1907 DrawInfoScreen_Music();
1908 else if (info_mode == INFO_MODE_CREDITS)
1909 DrawInfoScreen_Credits();
1910 else if (info_mode == INFO_MODE_PROGRAM)
1911 DrawInfoScreen_Program();
1912 else if (info_mode == INFO_MODE_LEVELSET)
1913 DrawInfoScreen_LevelSet();
1915 DrawInfoScreen_Main(fade_delay);
1917 if (info_mode != INFO_MODE_MAIN &&
1918 info_mode != INFO_MODE_TITLE &&
1919 info_mode != INFO_MODE_MUSIC)
1926 void DrawInfoScreen()
1928 DrawInfoScreenExt(0);
1931 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1933 if (info_mode == INFO_MODE_TITLE)
1934 HandleInfoScreen_TitleScreen(button);
1935 else if (info_mode == INFO_MODE_ELEMENTS)
1936 HandleInfoScreen_Elements(button);
1937 else if (info_mode == INFO_MODE_MUSIC)
1938 HandleInfoScreen_Music(button);
1939 else if (info_mode == INFO_MODE_CREDITS)
1940 HandleInfoScreen_Credits(button);
1941 else if (info_mode == INFO_MODE_PROGRAM)
1942 HandleInfoScreen_Program(button);
1943 else if (info_mode == INFO_MODE_LEVELSET)
1944 HandleInfoScreen_LevelSet(button);
1946 HandleInfoScreen_Main(mx, my, dx, dy, button);
1952 /* ========================================================================= */
1953 /* type name functions */
1954 /* ========================================================================= */
1956 void HandleTypeName(int newxpos, Key key)
1958 static int xpos = 0, ypos = 2;
1959 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1960 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1961 int startx = mSX + 32 + name_width;
1962 int starty = mSY + ypos * 32;
1968 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1969 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1974 if (((key >= KSYM_A && key <= KSYM_Z) ||
1975 (key >= KSYM_a && key <= KSYM_z)) &&
1976 xpos < MAX_PLAYER_NAME_LEN)
1980 if (key >= KSYM_A && key <= KSYM_Z)
1981 ascii = 'A' + (char)(key - KSYM_A);
1983 ascii = 'a' + (char)(key - KSYM_a);
1985 setup.player_name[xpos] = ascii;
1986 setup.player_name[xpos + 1] = 0;
1989 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1990 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1992 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1995 setup.player_name[xpos] = 0;
1997 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
1999 else if (key == KSYM_Return && xpos > 0)
2001 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
2002 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
2005 game_status = GAME_MODE_MAIN;
2010 /* ========================================================================= */
2011 /* tree menu functions */
2012 /* ========================================================================= */
2014 static void DrawChooseTree(TreeInfo **ti_ptr)
2018 FreeScreenGadgets();
2019 CreateScreenGadgets();
2021 CloseDoor(DOOR_CLOSE_2);
2025 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
2026 MapScreenTreeGadgets(*ti_ptr);
2032 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
2034 struct GadgetInfo *gi = screen_gadget[id];
2035 int items_max, items_visible, item_position;
2037 items_max = numTreeInfoInGroup(ti);
2038 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
2039 item_position = first_entry;
2041 if (item_position > items_max - items_visible)
2042 item_position = items_max - items_visible;
2044 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
2045 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2046 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
2049 static void drawChooseTreeList(int first_entry, int num_page_entries,
2053 char *title_string = NULL;
2055 int xoffset_sets = 16;
2057 int yoffset_sets = MENU_TITLE1_YPOS;
2059 int xoffset_setup = 16;
2061 int yoffset_setup = 16;
2064 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
2067 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
2070 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
2071 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
2073 int last_game_status = game_status; /* save current game status */
2075 title_string = ti->infotext;
2078 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
2080 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
2083 /* force LEVELS font on artwork setup screen */
2084 game_status = GAME_MODE_LEVELS;
2086 /* clear tree list area, but not title or scrollbar */
2087 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
2088 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
2089 MAX_MENU_ENTRIES_ON_SCREEN * 32);
2091 for (i = 0; i < num_page_entries; i++)
2093 TreeInfo *node, *node_first;
2094 int entry_pos = first_entry + i;
2095 int xpos = MENU_SCREEN_START_XPOS;
2096 int ypos = MENU_SCREEN_START_YPOS + i;
2097 int startx = mSX + xpos * 32;
2098 int starty = mSY + ypos * 32;
2099 int font_nr = FONT_TEXT_1;
2100 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2101 int startx_text = startx + font_xoffset;
2102 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
2103 int text_size = startx_scrollbar - startx_text;
2104 int max_buffer_len = text_size / getFontWidth(font_nr);
2105 char buffer[max_buffer_len + 1];
2107 node_first = getTreeInfoFirstGroupEntry(ti);
2108 node = getTreeInfoFromPos(node_first, entry_pos);
2110 strncpy(buffer, node->name, max_buffer_len);
2111 buffer[max_buffer_len] = '\0';
2113 DrawText(startx, starty, buffer, font_nr + node->color);
2115 if (node->parent_link)
2116 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2117 else if (node->level_group)
2118 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2120 initCursor(i, IMG_MENU_BUTTON);
2123 game_status = last_game_status; /* restore current game status */
2125 redraw_mask |= REDRAW_FIELD;
2128 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
2130 TreeInfo *node, *node_first;
2131 int x, last_redraw_mask = redraw_mask;
2133 int ypos = MENU_TITLE2_YPOS;
2138 if (ti->type != TREE_TYPE_LEVEL_DIR)
2141 node_first = getTreeInfoFirstGroupEntry(ti);
2142 node = getTreeInfoFromPos(node_first, entry_pos);
2144 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
2146 if (node->parent_link)
2147 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
2149 else if (node->level_group)
2150 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
2152 else if (ti->type == TREE_TYPE_LEVEL_DIR)
2153 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
2154 node->levels, node->class_desc);
2156 /* let BackToFront() redraw only what is needed */
2157 redraw_mask = last_redraw_mask | REDRAW_TILES;
2158 for (x = 0; x < SCR_FIELDX; x++)
2159 MarkTileDirty(x, 1);
2162 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
2165 TreeInfo *ti = *ti_ptr;
2167 int y = ti->cl_cursor;
2168 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2169 int num_entries = numTreeInfoInGroup(ti);
2170 int num_page_entries;
2171 int last_game_status = game_status; /* save current game status */
2172 boolean position_set_by_scrollbar = (dx == 999);
2174 /* force LEVELS draw offset on choose level and artwork setup screen */
2175 game_status = GAME_MODE_LEVELS;
2177 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
2178 num_page_entries = num_entries;
2180 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2182 game_status = last_game_status; /* restore current game status */
2184 if (button == MB_MENU_INITIALIZE)
2186 int num_entries = numTreeInfoInGroup(ti);
2187 int entry_pos = posTreeInfo(ti);
2189 if (ti->cl_first == -1)
2191 /* only on initialization */
2192 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2193 ti->cl_cursor = entry_pos - ti->cl_first;
2195 else if (ti->cl_cursor >= num_page_entries ||
2196 (num_entries > num_page_entries &&
2197 num_entries - ti->cl_first < num_page_entries))
2199 /* only after change of list size (by custom graphic configuration) */
2200 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2201 ti->cl_cursor = entry_pos - ti->cl_first;
2204 if (position_set_by_scrollbar)
2207 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2210 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2211 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2212 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2216 else if (button == MB_MENU_LEAVE)
2218 if (ti->node_parent)
2220 *ti_ptr = ti->node_parent;
2221 DrawChooseTree(ti_ptr);
2223 else if (game_status == GAME_MODE_SETUP)
2225 if (game_status == GAME_MODE_SETUP)
2227 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2228 execSetupGraphics();
2235 game_status = GAME_MODE_MAIN;
2242 if (mx || my) /* mouse input */
2244 int last_game_status = game_status; /* save current game status */
2246 /* force LEVELS draw offset on artwork setup screen */
2247 game_status = GAME_MODE_LEVELS;
2249 x = (mx - mSX) / 32;
2250 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2252 game_status = last_game_status; /* restore current game status */
2254 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2256 /* move cursor instead of scrolling when already at start/end of list */
2257 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
2259 else if (dy == +1 * SCROLL_LINE &&
2260 ti->cl_first + num_page_entries == num_entries)
2263 /* handle scrolling screen one line or page */
2264 if (ti->cl_cursor + dy < 0 ||
2265 ti->cl_cursor + dy > num_page_entries - 1)
2267 if (ABS(dy) == SCROLL_PAGE)
2268 step = num_page_entries - 1;
2270 if (dy < 0 && ti->cl_first > 0)
2272 /* scroll page/line up */
2274 ti->cl_first -= step;
2275 if (ti->cl_first < 0)
2278 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2279 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2280 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2281 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2284 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
2286 /* scroll page/line down */
2288 ti->cl_first += step;
2289 if (ti->cl_first + num_page_entries > num_entries)
2290 ti->cl_first = MAX(0, num_entries - num_page_entries);
2292 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2293 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2294 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2295 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2302 /* handle moving cursor one line */
2303 y = ti->cl_cursor + dy;
2308 TreeInfo *node_first, *node_cursor;
2309 int entry_pos = ti->cl_first + y;
2311 node_first = getTreeInfoFirstGroupEntry(ti);
2312 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2314 if (node_cursor->node_group)
2316 node_cursor->cl_first = ti->cl_first;
2317 node_cursor->cl_cursor = ti->cl_cursor;
2318 *ti_ptr = node_cursor->node_group;
2319 DrawChooseTree(ti_ptr);
2324 else if (dx == -1 && ti->node_parent)
2326 *ti_ptr = ti->node_parent;
2327 DrawChooseTree(ti_ptr);
2332 if (!anyScrollbarGadgetActive() &&
2333 IN_VIS_FIELD(x, y) &&
2334 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2335 y >= 0 && y < num_page_entries)
2339 if (y != ti->cl_cursor)
2341 drawChooseTreeCursor(y, FC_RED);
2342 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
2343 drawChooseTreeInfo(ti->cl_first + y, ti);
2349 TreeInfo *node_first, *node_cursor;
2350 int entry_pos = ti->cl_first + y;
2352 node_first = getTreeInfoFirstGroupEntry(ti);
2353 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2355 if (node_cursor->node_group)
2357 node_cursor->cl_first = ti->cl_first;
2358 node_cursor->cl_cursor = ti->cl_cursor;
2359 *ti_ptr = node_cursor->node_group;
2360 DrawChooseTree(ti_ptr);
2362 else if (node_cursor->parent_link)
2364 *ti_ptr = node_cursor->node_parent;
2365 DrawChooseTree(ti_ptr);
2369 node_cursor->cl_first = ti->cl_first;
2370 node_cursor->cl_cursor = ti->cl_cursor;
2371 *ti_ptr = node_cursor;
2373 if (ti->type == TREE_TYPE_LEVEL_DIR)
2375 LoadLevelSetup_SeriesInfo();
2377 SaveLevelSetup_LastSeries();
2378 SaveLevelSetup_SeriesInfo();
2382 if (game_status == GAME_MODE_SETUP)
2384 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2385 execSetupGraphics();
2391 game_status = GAME_MODE_MAIN;
2399 void DrawChooseLevel()
2401 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2403 DrawChooseTree(&leveldir_current);
2409 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2411 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2416 void DrawHallOfFame(int highlight_position)
2419 FadeSoundsAndMusic();
2420 CloseDoor(DOOR_CLOSE_2);
2422 if (highlight_position < 0)
2423 LoadScore(level_nr);
2431 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2434 static void drawHallOfFameList(int first_entry, int highlight_position)
2438 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2442 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2443 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2444 "HighScores of Level %d", level_nr);
2446 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2447 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2448 "HighScores of Level %d", level_nr);
2451 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2453 int entry = first_entry + i;
2454 boolean active = (entry == highlight_position);
2455 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2456 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2457 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2458 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2459 int dx1 = 3 * getFontWidth(font_nr1);
2460 int dx2 = dx1 + getFontWidth(font_nr1);
2461 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2462 int sy = mSY + 64 + i * 32;
2464 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2465 DrawText(mSX + dx1, sy, ".", font_nr1);
2466 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2468 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2469 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2471 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2474 redraw_mask |= REDRAW_FIELD;
2477 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2479 static int first_entry = 0;
2480 static int highlight_position = 0;
2481 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2482 int button_released = !button;
2484 if (button == MB_MENU_INITIALIZE)
2487 highlight_position = mx;
2488 drawHallOfFameList(first_entry, highlight_position);
2493 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2494 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2498 if (first_entry > 0)
2500 first_entry -= step;
2501 if (first_entry < 0)
2504 drawHallOfFameList(first_entry, highlight_position);
2509 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2511 first_entry += step;
2512 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2513 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2515 drawHallOfFameList(first_entry, highlight_position);
2518 else if (button_released)
2520 FadeSound(SND_BACKGROUND_SCORES);
2521 game_status = GAME_MODE_MAIN;
2525 if (game_status == GAME_MODE_SCORES)
2526 PlayMenuSoundIfLoop();
2532 /* ========================================================================= */
2533 /* setup screen functions */
2534 /* ========================================================================= */
2536 static struct TokenInfo *setup_info;
2537 static int num_setup_info;
2539 static char *screen_mode_text;
2540 static char *graphics_set_name;
2541 static char *sounds_set_name;
2542 static char *music_set_name;
2544 static void execSetupMain()
2546 setup_mode = SETUP_MODE_MAIN;
2550 static void execSetupGame()
2552 setup_mode = SETUP_MODE_GAME;
2556 static void execSetupEditor()
2558 setup_mode = SETUP_MODE_EDITOR;
2562 static void execSetupGraphics()
2564 if (video.fullscreen_available && screen_modes == NULL)
2568 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
2570 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
2571 char identifier[20], name[20];
2572 int x = video.fullscreen_modes[i].width;
2573 int y = video.fullscreen_modes[i].height;
2576 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
2578 ti->node_top = &screen_modes;
2579 ti->sort_priority = x * 10000 + y;
2581 sprintf(identifier, "%dx%d", x, y);
2582 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
2584 setString(&ti->identifier, identifier);
2585 setString(&ti->name, name);
2586 setString(&ti->name_sorting, name);
2587 setString(&ti->infotext, "Fullscreen Mode");
2589 pushTreeInfo(&screen_modes, ti);
2592 /* sort fullscreen modes to start with lowest available screen resolution */
2593 sortTreeInfo(&screen_modes);
2595 /* set current screen mode for fullscreen mode to configured setup value */
2596 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2597 setup.fullscreen_mode);
2599 /* if that fails, set current screen mode to reliable default value */
2600 if (screen_mode_current == NULL)
2601 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2602 DEFAULT_FULLSCREEN_MODE);
2604 /* if that also fails, set current screen mode to first available mode */
2605 if (screen_mode_current == NULL)
2606 screen_mode_current = screen_modes;
2608 if (screen_mode_current == NULL)
2609 video.fullscreen_available = FALSE;
2612 if (video.fullscreen_available)
2614 setup.fullscreen_mode = screen_mode_current->identifier;
2616 /* needed for displaying screen mode name instead of identifier */
2617 screen_mode_text = screen_mode_current->name;
2620 setup_mode = SETUP_MODE_GRAPHICS;
2624 static void execSetupChooseScreenMode()
2626 if (!video.fullscreen_available)
2629 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
2633 static void execSetupSound()
2635 setup_mode = SETUP_MODE_SOUND;
2639 static void execSetupArtwork()
2641 setup.graphics_set = artwork.gfx_current->identifier;
2642 setup.sounds_set = artwork.snd_current->identifier;
2643 setup.music_set = artwork.mus_current->identifier;
2645 /* needed if last screen (setup choice) changed graphics, sounds or music */
2646 ReloadCustomArtwork(0);
2648 /* needed for displaying artwork name instead of artwork identifier */
2649 graphics_set_name = artwork.gfx_current->name;
2650 sounds_set_name = artwork.snd_current->name;
2651 music_set_name = artwork.mus_current->name;
2653 setup_mode = SETUP_MODE_ARTWORK;
2657 static void execSetupChooseGraphics()
2659 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2663 static void execSetupChooseSounds()
2665 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2669 static void execSetupChooseMusic()
2671 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2675 static void execSetupInput()
2677 setup_mode = SETUP_MODE_INPUT;
2681 static void execSetupShortcut1()
2683 setup_mode = SETUP_MODE_SHORTCUT_1;
2687 static void execSetupShortcut2()
2689 setup_mode = SETUP_MODE_SHORTCUT_2;
2693 static void execExitSetup()
2695 game_status = GAME_MODE_MAIN;
2699 static void execSaveAndExitSetup()
2705 static struct TokenInfo setup_info_main[] =
2707 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2708 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2709 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2710 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2711 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2712 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2713 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2714 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2715 { TYPE_EMPTY, NULL, "" },
2716 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2717 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2722 static struct TokenInfo setup_info_game[] =
2724 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2725 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2726 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2727 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2728 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2729 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2730 { TYPE_EMPTY, NULL, "" },
2731 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2736 static struct TokenInfo setup_info_editor[] =
2739 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2740 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2741 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2742 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2743 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2744 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2745 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2746 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2748 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2749 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2751 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2753 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2754 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2755 { TYPE_EMPTY, NULL, "" },
2757 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
2758 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
2759 { TYPE_EMPTY, NULL, "" },
2761 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2762 { TYPE_EMPTY, NULL, "" },
2763 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2768 static struct TokenInfo setup_info_graphics[] =
2770 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2771 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
2772 { TYPE_STRING, &screen_mode_text, "" },
2773 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2775 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2776 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2777 { TYPE_SWITCH, &setup.fading, "Fading:" },
2779 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2780 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2781 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2782 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2783 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2784 { TYPE_EMPTY, NULL, "" },
2785 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2790 static struct TokenInfo setup_info_sound[] =
2792 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2793 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2794 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2795 { TYPE_EMPTY, NULL, "" },
2796 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2801 static struct TokenInfo setup_info_artwork[] =
2803 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
2804 { TYPE_STRING, &graphics_set_name, "" },
2805 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
2806 { TYPE_STRING, &sounds_set_name, "" },
2807 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
2808 { TYPE_STRING, &music_set_name, "" },
2809 { TYPE_EMPTY, NULL, "" },
2811 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2812 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2813 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2815 { TYPE_STRING, NULL, "Override Level Artwork:"},
2816 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2817 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2818 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2820 { TYPE_EMPTY, NULL, "" },
2821 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2826 static struct TokenInfo setup_info_shortcut_1[] =
2828 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2829 { TYPE_KEY, &setup.shortcut.save_game, "" },
2830 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2831 { TYPE_KEY, &setup.shortcut.load_game, "" },
2832 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2833 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2834 { TYPE_EMPTY, NULL, "" },
2835 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2836 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2837 { TYPE_EMPTY, NULL, "" },
2838 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2843 static struct TokenInfo setup_info_shortcut_2[] =
2845 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2846 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2847 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2848 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2849 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2850 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2851 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2852 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2853 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2854 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2855 { TYPE_EMPTY, NULL, "" },
2856 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2861 static Key getSetupKey()
2863 Key key = KSYM_UNDEFINED;
2864 boolean got_key_event = FALSE;
2866 while (!got_key_event)
2868 if (PendingEvent()) /* got event */
2876 case EVENT_KEYPRESS:
2878 key = GetEventKey((KeyEvent *)&event, TRUE);
2880 /* press 'Escape' or 'Enter' to keep the existing key binding */
2881 if (key == KSYM_Escape || key == KSYM_Return)
2882 key = KSYM_UNDEFINED; /* keep old value */
2884 got_key_event = TRUE;
2888 case EVENT_KEYRELEASE:
2889 key_joystick_mapping = 0;
2893 HandleOtherEvents(&event);
2901 /* don't eat all CPU time */
2908 static int getSetupTextFont(int type)
2910 if (type & (TYPE_SWITCH |
2921 static int getSetupValueFont(int type, void *value)
2923 if (type & TYPE_KEY)
2924 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2925 else if (type & TYPE_STRING)
2926 return FONT_VALUE_2;
2927 else if (type & TYPE_ECS_AGA)
2928 return FONT_VALUE_1;
2929 else if (type & TYPE_BOOLEAN_STYLE)
2930 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2932 return FONT_VALUE_1;
2935 static void drawSetupValue(int pos)
2937 boolean font_draw_xoffset_modified = FALSE;
2938 int font_draw_xoffset_old = -1;
2939 int xpos = MENU_SCREEN_VALUE_XPOS;
2940 int ypos = MENU_SCREEN_START_YPOS + pos;
2941 int startx = mSX + xpos * 32;
2942 int starty = mSY + ypos * 32;
2943 int font_nr, font_width;
2944 int type = setup_info[pos].type;
2945 void *value = setup_info[pos].value;
2946 char *value_string = getSetupValue(type, value);
2949 if (value_string == NULL)
2952 if (type & TYPE_KEY)
2955 xpos = MENU_SCREEN_START_XPOS;
2960 if (type & TYPE_QUERY)
2962 value_string = "<press key>";
2964 font_nr = FONT_INPUT_1_ACTIVE;
2968 else if (type & TYPE_STRING)
2970 int max_value_len = (SCR_FIELDX - 2) * 2;
2972 xpos = MENU_SCREEN_START_XPOS;
2974 font_nr = FONT_VALUE_2;
2977 if (strlen(value_string) > max_value_len)
2978 value_string[max_value_len] = '\0';
2980 else if (type & TYPE_ECS_AGA)
2983 font_nr = FONT_VALUE_1;
2986 else if (type & TYPE_BOOLEAN_STYLE)
2989 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2993 startx = mSX + xpos * 32;
2994 starty = mSY + ypos * 32;
2995 font_nr = getSetupValueFont(type, value);
2996 font_width = getFontWidth(font_nr);
2998 /* downward compatibility correction for Juergen Bonhagen's menu settings */
2999 if (setup_mode != SETUP_MODE_INPUT)
3001 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
3002 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3003 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
3004 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
3005 int text_font_nr = getSetupTextFont(FONT_MENU_2);
3006 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
3007 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
3008 boolean correct_font_draw_xoffset = FALSE;
3010 if (xpos == MENU_SCREEN_START_XPOS &&
3011 startx + font1_xoffset < text_startx + text_font_xoffset)
3012 correct_font_draw_xoffset = TRUE;
3014 if (xpos == MENU_SCREEN_VALUE_XPOS &&
3015 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
3016 correct_font_draw_xoffset = TRUE;
3019 printf("::: %d + %d < %d + %d + %d\n",
3020 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
3021 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
3024 /* check if setup value would overlap with setup text when printed */
3025 /* (this can happen for extreme/wrong values for font draw offset) */
3026 if (correct_font_draw_xoffset)
3028 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
3029 font_draw_xoffset_modified = TRUE;
3031 if (type & TYPE_KEY)
3032 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
3033 else if (!(type & TYPE_STRING))
3034 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
3035 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
3040 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
3041 DrawText(startx + i * font_width, starty, " ", font_nr);
3044 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
3045 DrawText(mSX + i * 32, starty, " ", font_nr);
3047 DrawText(startx, starty,
3048 (xpos == 3 ? " " : " "), font_nr);
3052 DrawText(startx, starty, value_string, font_nr);
3054 if (font_draw_xoffset_modified)
3055 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
3058 static void changeSetupValue(int pos)
3060 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
3062 *(boolean *)setup_info[pos].value ^= TRUE;
3064 else if (setup_info[pos].type & TYPE_KEY)
3068 setup_info[pos].type |= TYPE_QUERY;
3069 drawSetupValue(pos);
3070 setup_info[pos].type &= ~TYPE_QUERY;
3072 key = getSetupKey();
3073 if (key != KSYM_UNDEFINED)
3074 *(Key *)setup_info[pos].value = key;
3077 drawSetupValue(pos);
3080 static void DrawSetupScreen_Generic()
3082 char *title_string = NULL;
3086 CloseDoor(DOOR_CLOSE_2);
3090 if (setup_mode == SETUP_MODE_MAIN)
3092 setup_info = setup_info_main;
3093 title_string = "Setup";
3095 else if (setup_mode == SETUP_MODE_GAME)
3097 setup_info = setup_info_game;
3098 title_string = "Setup Game";
3100 else if (setup_mode == SETUP_MODE_EDITOR)
3102 setup_info = setup_info_editor;
3103 title_string = "Setup Editor";
3105 else if (setup_mode == SETUP_MODE_GRAPHICS)
3107 setup_info = setup_info_graphics;
3108 title_string = "Setup Graphics";
3110 else if (setup_mode == SETUP_MODE_SOUND)
3112 setup_info = setup_info_sound;
3113 title_string = "Setup Sound";
3115 else if (setup_mode == SETUP_MODE_ARTWORK)
3117 setup_info = setup_info_artwork;
3118 title_string = "Custom Artwork";
3120 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
3122 setup_info = setup_info_shortcut_1;
3123 title_string = "Setup Shortcuts";
3125 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
3127 setup_info = setup_info_shortcut_2;
3128 title_string = "Setup Shortcuts";
3132 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
3134 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
3138 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3140 void *value_ptr = setup_info[i].value;
3141 int xpos = MENU_SCREEN_START_XPOS;
3142 int ypos = MENU_SCREEN_START_YPOS + i;
3146 int font_nr = FONT_MENU_1;
3149 /* set some entries to "unchangeable" according to other variables */
3150 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
3151 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
3152 (value_ptr == &setup.sound_music && !audio.music_available) ||
3153 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
3154 (value_ptr == &screen_mode_text && !video.fullscreen_available))
3155 setup_info[i].type |= TYPE_GHOSTED;
3158 font_nr = getSetupTextFont(setup_info[i].type);
3161 if (setup_info[i].type & (TYPE_SWITCH |
3166 font_nr = FONT_MENU_2;
3168 if (setup_info[i].type & TYPE_STRING)
3169 font_nr = FONT_MENU_2;
3173 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
3175 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
3176 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3177 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
3178 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3179 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
3180 initCursor(i, IMG_MENU_BUTTON);
3182 if (setup_info[i].type & TYPE_VALUE)
3189 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3190 "Joysticks deactivated in setup menu");
3195 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
3198 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
3200 static int choice_store[MAX_SETUP_MODES];
3201 int choice = choice_store[setup_mode]; /* always starts with 0 */
3205 if (button == MB_MENU_INITIALIZE)
3207 /* advance to first valid menu entry */
3208 while (choice < num_setup_info &&
3209 setup_info[choice].type & TYPE_SKIP_ENTRY)
3211 choice_store[setup_mode] = choice;
3213 drawCursor(choice, FC_RED);
3217 else if (button == MB_MENU_LEAVE)
3219 for (y = 0; y < num_setup_info; y++)
3221 if (setup_info[y].type & TYPE_LEAVE_MENU)
3223 void (*menu_callback_function)(void) = setup_info[y].value;
3225 menu_callback_function();
3227 break; /* absolutely needed because function changes 'setup_info'! */
3234 if (mx || my) /* mouse input */
3236 x = (mx - mSX) / 32;
3237 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3239 else if (dx || dy) /* keyboard input */
3243 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
3245 if (setup_info[choice].type & menu_navigation_type ||
3246 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
3247 button = MB_MENU_CHOICE;
3252 /* jump to next non-empty menu entry (up or down) */
3253 while (y > 0 && y < num_setup_info - 1 &&
3254 setup_info[y].type & TYPE_SKIP_ENTRY)
3259 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
3263 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3265 drawCursor(y, FC_RED);
3266 drawCursor(choice, FC_BLUE);
3267 choice = choice_store[setup_mode] = y;
3270 else if (!(setup_info[y].type & TYPE_GHOSTED))
3272 /* when selecting key headline, execute function for key value change */
3273 if (setup_info[y].type & TYPE_KEYTEXT &&
3274 setup_info[y + 1].type & TYPE_KEY)
3277 /* when selecting string value, execute function for list selection */
3278 if (setup_info[y].type & TYPE_STRING && y > 0 &&
3279 setup_info[y - 1].type & TYPE_ENTER_LIST)
3282 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3284 void (*menu_callback_function)(void) = setup_info[y].value;
3286 menu_callback_function();
3290 if (setup_info[y].type & TYPE_VALUE)
3291 changeSetupValue(y);
3296 if (IN_VIS_FIELD(x, y) &&
3297 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3303 drawCursor(y, FC_RED);
3304 drawCursor(choice, FC_BLUE);
3305 choice = choice_store[setup_mode] = y;
3308 else if (!(setup_info[y].type & TYPE_GHOSTED))
3310 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3312 void (*menu_callback_function)(void) = setup_info[choice].value;
3314 menu_callback_function();
3318 if (setup_info[y].type & TYPE_KEYTEXT &&
3319 setup_info[y + 1].type & TYPE_KEY)
3322 if (setup_info[y].type & TYPE_VALUE)
3323 changeSetupValue(y);
3330 void DrawSetupScreen_Input()
3335 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
3337 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
3340 initCursor(0, IMG_MENU_BUTTON);
3341 initCursor(1, IMG_MENU_BUTTON);
3342 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
3343 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
3346 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
3347 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
3350 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
3351 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
3352 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
3355 DeactivateJoystickForCalibration();
3358 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3359 "Joysticks deactivated on this screen");
3363 /* create gadgets for setup input menu screen */
3364 FreeScreenGadgets();
3365 CreateScreenGadgets();
3367 /* map gadgets for setup input menu screen */
3368 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
3371 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
3376 static void setJoystickDeviceToNr(char *device_name, int device_nr)
3378 if (device_name == NULL)
3381 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
3384 if (strlen(device_name) > 1)
3386 char c1 = device_name[strlen(device_name) - 1];
3387 char c2 = device_name[strlen(device_name) - 2];
3389 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
3390 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
3393 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
3394 strlen(device_name));
3397 static void drawPlayerSetupInputInfo(int player_nr)
3400 static struct SetupKeyboardInfo custom_key;
3407 { &custom_key.left, "Joystick Left" },
3408 { &custom_key.right, "Joystick Right" },
3409 { &custom_key.up, "Joystick Up" },
3410 { &custom_key.down, "Joystick Down" },
3411 { &custom_key.snap, "Button 1" },
3412 { &custom_key.drop, "Button 2" }
3414 static char *joystick_name[MAX_PLAYERS] =
3424 custom_key = setup.input[player_nr].key;
3426 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
3427 FONT_INPUT_1_ACTIVE);
3429 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3431 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3432 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
3434 if (setup.input[player_nr].use_joystick)
3436 char *device_name = setup.input[player_nr].joy.device_name;
3437 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
3438 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
3440 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
3441 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
3445 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
3446 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
3449 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
3450 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
3451 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
3452 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
3453 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
3454 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
3455 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
3456 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
3457 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
3458 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
3459 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
3461 for (i = 0; i < 6; i++)
3463 int ypos = 6 + i + (i > 3 ? i-3 : 0);
3465 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3467 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3468 (setup.input[player_nr].use_joystick ?
3470 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
3474 static int input_player_nr = 0;
3476 void HandleSetupScreen_Input_Player(int step, int direction)
3478 int old_player_nr = input_player_nr;
3481 new_player_nr = old_player_nr + step * direction;
3482 if (new_player_nr < 0)
3484 if (new_player_nr > MAX_PLAYERS - 1)
3485 new_player_nr = MAX_PLAYERS - 1;
3487 if (new_player_nr != old_player_nr)
3489 input_player_nr = new_player_nr;
3491 drawPlayerSetupInputInfo(input_player_nr);
3495 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
3497 static int choice = 0;
3500 int pos_start = SETUPINPUT_SCREEN_POS_START;
3501 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
3502 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
3503 int pos_end = SETUPINPUT_SCREEN_POS_END;
3505 if (button == MB_MENU_INITIALIZE)
3507 drawPlayerSetupInputInfo(input_player_nr);
3508 drawCursor(choice, FC_RED);
3512 else if (button == MB_MENU_LEAVE)
3514 setup_mode = SETUP_MODE_MAIN;
3521 if (mx || my) /* mouse input */
3523 x = (mx - mSX) / 32;
3524 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3526 else if (dx || dy) /* keyboard input */
3528 if (dx && choice == 0)
3529 x = (dx < 0 ? 10 : 12);
3530 else if ((dx && choice == 1) ||
3531 (dx == +1 && choice == 2) ||
3532 (dx == -1 && choice == pos_end))
3533 button = MB_MENU_CHOICE;
3537 if (y >= pos_empty1 && y <= pos_empty2)
3538 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
3543 if (y == 0 && dx != 0 && button)
3545 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
3550 if (IN_VIS_FIELD(x, y) &&
3551 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
3553 static unsigned long delay = 0;
3555 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3559 (input_player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3561 drawPlayerSetupInputInfo(input_player_nr);
3566 else if (IN_VIS_FIELD(x, y) &&
3567 y >= pos_start && y <= pos_end &&
3568 !(y >= pos_empty1 && y <= pos_empty2))
3574 drawCursor(y, FC_RED);
3575 drawCursor(choice, FC_BLUE);
3583 char *device_name = setup.input[input_player_nr].joy.device_name;
3585 if (!setup.input[input_player_nr].use_joystick)
3587 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3589 setJoystickDeviceToNr(device_name, new_device_nr);
3590 setup.input[input_player_nr].use_joystick = TRUE;
3594 int device_nr = getJoystickNrFromDeviceName(device_name);
3595 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3597 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3598 setup.input[input_player_nr].use_joystick = FALSE;
3600 setJoystickDeviceToNr(device_name, new_device_nr);
3603 drawPlayerSetupInputInfo(input_player_nr);
3607 if (setup.input[input_player_nr].use_joystick)
3610 CalibrateJoystick(input_player_nr);
3613 CustomizeKeyboard(input_player_nr);
3615 else if (y == pos_end)
3619 setup_mode = SETUP_MODE_MAIN;
3626 void CustomizeKeyboard(int player_nr)
3630 boolean finished = FALSE;
3631 static struct SetupKeyboardInfo custom_key;
3636 } customize_step[] =
3638 { &custom_key.left, "Move Left" },
3639 { &custom_key.right, "Move Right" },
3640 { &custom_key.up, "Move Up" },
3641 { &custom_key.down, "Move Down" },
3642 { &custom_key.snap, "Snap Field" },
3643 { &custom_key.drop, "Drop Element" }
3646 /* read existing key bindings from player setup */
3647 custom_key = setup.input[player_nr].key;
3652 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3654 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3661 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3662 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3663 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3664 "Key:", FONT_INPUT_1_ACTIVE);
3665 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3666 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3670 if (PendingEvent()) /* got event */
3678 case EVENT_KEYPRESS:
3680 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3682 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3688 /* all keys configured -- wait for "Escape" or "Return" key */
3692 /* press 'Enter' to keep the existing key binding */
3693 if (key == KSYM_Return)
3694 key = *customize_step[step_nr].key;
3696 /* check if key already used */
3697 for (i = 0; i < step_nr; i++)
3698 if (*customize_step[i].key == key)
3703 /* got new key binding */
3704 *customize_step[step_nr].key = key;
3705 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3707 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3708 getKeyNameFromKey(key), FONT_VALUE_1);
3711 /* un-highlight last query */
3712 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3713 customize_step[step_nr - 1].text, FONT_MENU_1);
3714 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3715 "Key:", FONT_MENU_1);
3717 /* press 'Enter' to leave */
3720 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3721 "Press Enter", FONT_TITLE_1);
3725 /* query next key binding */
3726 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3727 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3728 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3729 "Key:", FONT_INPUT_1_ACTIVE);
3730 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3731 getKeyNameFromKey(*customize_step[step_nr].key),
3736 case EVENT_KEYRELEASE:
3737 key_joystick_mapping = 0;
3741 HandleOtherEvents(&event);
3749 /* don't eat all CPU time */
3753 /* write new key bindings back to player setup */
3754 setup.input[player_nr].key = custom_key;
3757 DrawSetupScreen_Input();
3760 static boolean CalibrateJoystickMain(int player_nr)
3762 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3763 int new_joystick_xright = JOYSTICK_XMIDDLE;
3764 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3765 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3766 int new_joystick_xmiddle, new_joystick_ymiddle;
3768 int joystick_fd = joystick.fd[player_nr];
3769 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3770 boolean check[3][3];
3771 int check_remaining = 3 * 3;
3776 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3779 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3784 for (y = 0; y < 3; y++)
3786 for (x = 0; x < 3; x++)
3788 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3789 check[x][y] = FALSE;
3793 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3794 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3795 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3796 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3797 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3798 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3799 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3801 joy_value = Joystick(player_nr);
3802 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3803 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3805 /* eventually uncalibrated center position (joystick could be uncentered) */
3806 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3809 new_joystick_xmiddle = joy_x;
3810 new_joystick_ymiddle = joy_y;
3812 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3815 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3820 if (PendingEvent()) /* got event */
3828 case EVENT_KEYPRESS:
3829 switch(GetEventKey((KeyEvent *)&event, TRUE))
3832 if (check_remaining == 0)
3845 case EVENT_KEYRELEASE:
3846 key_joystick_mapping = 0;
3850 HandleOtherEvents(&event);
3855 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3858 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3859 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3860 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3861 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3863 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3864 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3865 setup.input[player_nr].joy.xright = new_joystick_xright;
3866 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3867 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3868 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3870 CheckJoystickData();
3872 joy_value = Joystick(player_nr);
3874 if (joy_value & JOY_BUTTON && check_remaining == 0)
3877 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3878 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3880 if (x != last_x || y != last_y)
3882 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3883 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3888 if (check_remaining > 0 && !check[x+1][y+1])
3890 check[x+1][y+1] = TRUE;
3896 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3897 setup.input[player_nr].joy.xleft,
3898 setup.input[player_nr].joy.xmiddle,
3899 setup.input[player_nr].joy.xright);
3900 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3901 setup.input[player_nr].joy.yupper,
3902 setup.input[player_nr].joy.ymiddle,
3903 setup.input[player_nr].joy.ylower);
3912 /* don't eat all CPU time */
3916 /* calibrated center position (joystick should now be centered) */
3917 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3920 new_joystick_xmiddle = joy_x;
3921 new_joystick_ymiddle = joy_y;
3926 DrawSetupScreen_Input();
3929 /* wait until the last pressed button was released */
3930 while (Joystick(player_nr) & JOY_BUTTON)
3932 if (PendingEvent()) /* got event */
3937 HandleOtherEvents(&event);
3946 void CalibrateJoystick(int player_nr)
3948 if (!CalibrateJoystickMain(player_nr))
3950 char *device_name = setup.input[player_nr].joy.device_name;
3951 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3952 int xpos = mSX - SX;
3953 int ypos = mSY - SY;
3957 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3958 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3961 Delay(2000); /* show error message for a short time */
3967 DrawSetupScreen_Input();
3971 void DrawSetupScreen()
3973 DeactivateJoystick();
3975 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3977 if (setup_mode == SETUP_MODE_INPUT)
3978 DrawSetupScreen_Input();
3979 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3980 DrawChooseTree(&screen_mode_current);
3981 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3982 DrawChooseTree(&artwork.gfx_current);
3983 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3984 DrawChooseTree(&artwork.snd_current);
3985 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3986 DrawChooseTree(&artwork.mus_current);
3988 DrawSetupScreen_Generic();
3994 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3996 if (setup_mode == SETUP_MODE_INPUT)
3997 HandleSetupScreen_Input(mx, my, dx, dy, button);
3998 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3999 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
4000 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
4001 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
4002 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
4003 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
4004 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
4005 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
4007 HandleSetupScreen_Generic(mx, my, dx, dy, button);
4012 void HandleGameActions()
4014 if (game_status != GAME_MODE_PLAYING)
4017 GameActions(); /* main game loop */
4019 if (tape.auto_play && !tape.playing)
4020 AutoPlayTape(); /* continue automatically playing next tape */
4024 /* ---------- new screen button stuff -------------------------------------- */
4026 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
4030 case SCREEN_CTRL_ID_LAST_LEVEL:
4031 *x = mSX + TILEX * getLastLevelButtonPos();
4032 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4035 case SCREEN_CTRL_ID_NEXT_LEVEL:
4036 *x = mSX + TILEX * getNextLevelButtonPos();
4037 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4040 case SCREEN_CTRL_ID_LAST_PLAYER:
4041 *x = mSX + TILEX * 10;
4042 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4045 case SCREEN_CTRL_ID_NEXT_PLAYER:
4046 *x = mSX + TILEX * 12;
4047 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4051 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
4057 int gfx_unpressed, gfx_pressed;
4058 void (*get_gadget_position)(int *, int *, int);
4062 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
4065 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
4066 getScreenMenuButtonPos,
4067 SCREEN_CTRL_ID_LAST_LEVEL,
4072 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
4073 getScreenMenuButtonPos,
4074 SCREEN_CTRL_ID_NEXT_LEVEL,
4079 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
4080 getScreenMenuButtonPos,
4081 SCREEN_CTRL_ID_LAST_PLAYER,
4086 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
4087 getScreenMenuButtonPos,
4088 SCREEN_CTRL_ID_NEXT_PLAYER,
4096 int gfx_unpressed, gfx_pressed;
4100 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
4103 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
4104 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
4105 SCREEN_CTRL_ID_SCROLL_UP,
4109 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
4110 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
4111 SCREEN_CTRL_ID_SCROLL_DOWN,
4118 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4119 Bitmap **gfx_unpressed, **gfx_pressed;
4121 int gfx_unpressed, gfx_pressed;
4128 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
4131 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4132 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
4134 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
4136 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
4137 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
4138 GD_TYPE_SCROLLBAR_VERTICAL,
4139 SCREEN_CTRL_ID_SCROLL_VERTICAL,
4140 "scroll level series vertically"
4144 static void CreateScreenMenubuttons()
4146 struct GadgetInfo *gi;
4147 unsigned long event_mask;
4150 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4152 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4153 int gfx_unpressed, gfx_pressed;
4154 int x, y, width, height;
4155 int gd_x1, gd_x2, gd_y1, gd_y2;
4156 int id = menubutton_info[i].gadget_id;
4158 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4160 menubutton_info[i].get_gadget_position(&x, &y, id);
4162 width = SC_MENUBUTTON_XSIZE;
4163 height = SC_MENUBUTTON_YSIZE;
4165 gfx_unpressed = menubutton_info[i].gfx_unpressed;
4166 gfx_pressed = menubutton_info[i].gfx_pressed;
4167 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4168 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4169 gd_x1 = graphic_info[gfx_unpressed].src_x;
4170 gd_y1 = graphic_info[gfx_unpressed].src_y;
4171 gd_x2 = graphic_info[gfx_pressed].src_x;
4172 gd_y2 = graphic_info[gfx_pressed].src_y;
4174 gi = CreateGadget(GDI_CUSTOM_ID, id,
4175 GDI_CUSTOM_TYPE_ID, i,
4176 GDI_INFO_TEXT, menubutton_info[i].infotext,
4181 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4182 GDI_STATE, GD_BUTTON_UNPRESSED,
4183 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4184 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4185 GDI_DIRECT_DRAW, FALSE,
4186 GDI_EVENT_MASK, event_mask,
4187 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4191 Error(ERR_EXIT, "cannot create gadget");
4193 screen_gadget[id] = gi;
4197 static void CreateScreenScrollbuttons()
4199 struct GadgetInfo *gi;
4200 unsigned long event_mask;
4203 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4205 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4206 int gfx_unpressed, gfx_pressed;
4207 int x, y, width, height;
4208 int gd_x1, gd_x2, gd_y1, gd_y2;
4209 int id = scrollbutton_info[i].gadget_id;
4211 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4213 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
4214 y = mSY + scrollbutton_info[i].y;
4215 width = SC_SCROLLBUTTON_XSIZE;
4216 height = SC_SCROLLBUTTON_YSIZE;
4218 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
4219 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
4220 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
4222 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
4223 gfx_pressed = scrollbutton_info[i].gfx_pressed;
4224 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4225 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4226 gd_x1 = graphic_info[gfx_unpressed].src_x;
4227 gd_y1 = graphic_info[gfx_unpressed].src_y;
4228 gd_x2 = graphic_info[gfx_pressed].src_x;
4229 gd_y2 = graphic_info[gfx_pressed].src_y;
4231 gi = CreateGadget(GDI_CUSTOM_ID, id,
4232 GDI_CUSTOM_TYPE_ID, i,
4233 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4238 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4239 GDI_STATE, GD_BUTTON_UNPRESSED,
4240 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4241 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4242 GDI_DIRECT_DRAW, FALSE,
4243 GDI_EVENT_MASK, event_mask,
4244 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4248 Error(ERR_EXIT, "cannot create gadget");
4250 screen_gadget[id] = gi;
4254 static void CreateScreenScrollbars()
4258 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4260 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4261 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4262 int gfx_unpressed, gfx_pressed;
4264 int x, y, width, height;
4265 int gd_x1, gd_x2, gd_y1, gd_y2;
4266 struct GadgetInfo *gi;
4267 int items_max, items_visible, item_position;
4268 unsigned long event_mask;
4269 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4270 int id = scrollbar_info[i].gadget_id;
4272 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
4274 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
4275 y = mSY + scrollbar_info[i].y;
4276 width = scrollbar_info[i].width;
4277 height = scrollbar_info[i].height;
4279 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
4280 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
4282 items_max = num_page_entries;
4283 items_visible = num_page_entries;
4286 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4287 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
4288 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
4294 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
4295 gfx_pressed = scrollbar_info[i].gfx_pressed;
4296 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4297 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4298 gd_x1 = graphic_info[gfx_unpressed].src_x;
4299 gd_y1 = graphic_info[gfx_unpressed].src_y;
4300 gd_x2 = graphic_info[gfx_pressed].src_x;
4301 gd_y2 = graphic_info[gfx_pressed].src_y;
4304 gi = CreateGadget(GDI_CUSTOM_ID, id,
4305 GDI_CUSTOM_TYPE_ID, i,
4306 GDI_INFO_TEXT, scrollbar_info[i].infotext,
4311 GDI_TYPE, scrollbar_info[i].type,
4312 GDI_SCROLLBAR_ITEMS_MAX, items_max,
4313 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
4314 GDI_SCROLLBAR_ITEM_POSITION, item_position,
4315 GDI_WHEEL_AREA_X, 0,
4316 GDI_WHEEL_AREA_Y, 0,
4317 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
4318 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
4319 GDI_STATE, GD_BUTTON_UNPRESSED,
4320 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4321 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4322 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
4323 GDI_DIRECT_DRAW, FALSE,
4324 GDI_EVENT_MASK, event_mask,
4325 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4329 Error(ERR_EXIT, "cannot create gadget");
4331 screen_gadget[id] = gi;
4335 void CreateScreenGadgets()
4337 int last_game_status = game_status; /* save current game status */
4339 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4342 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4344 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
4346 /* copy pointers to clip mask and GC */
4347 scrollbar_bitmap[i]->clip_mask =
4348 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
4349 scrollbar_bitmap[i]->stored_clip_gc =
4350 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
4352 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
4353 scrollbar_bitmap[i],
4354 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
4355 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
4356 TILEX, TILEY, 0, 0);
4360 CreateScreenMenubuttons();
4362 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
4363 game_status = GAME_MODE_LEVELS;
4365 CreateScreenScrollbuttons();
4366 CreateScreenScrollbars();
4368 game_status = last_game_status; /* restore current game status */
4371 void FreeScreenGadgets()
4375 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4376 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4378 /* prevent freeing clip mask and GC twice */
4379 scrollbar_bitmap[i]->clip_mask = None;
4380 scrollbar_bitmap[i]->stored_clip_gc = None;
4382 FreeBitmap(scrollbar_bitmap[i]);
4386 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
4387 FreeGadget(screen_gadget[i]);
4390 void MapScreenMenuGadgets(int screen_mask)
4394 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4395 if (screen_mask & menubutton_info[i].screen_mask)
4396 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
4399 void MapScreenTreeGadgets(TreeInfo *ti)
4401 int num_entries = numTreeInfoInGroup(ti);
4404 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4407 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4408 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
4410 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4411 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
4414 static void HandleScreenGadgets(struct GadgetInfo *gi)
4416 int id = gi->custom_id;
4417 int button = gi->event.button;
4418 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4421 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
4427 case SCREEN_CTRL_ID_LAST_LEVEL:
4428 HandleMainMenu_SelectLevel(step, -1);
4431 case SCREEN_CTRL_ID_NEXT_LEVEL:
4432 HandleMainMenu_SelectLevel(step, +1);
4435 case SCREEN_CTRL_ID_LAST_PLAYER:
4436 HandleSetupScreen_Input_Player(step, -1);
4439 case SCREEN_CTRL_ID_NEXT_PLAYER:
4440 HandleSetupScreen_Input_Player(step, +1);
4443 case SCREEN_CTRL_ID_SCROLL_UP:
4444 if (game_status == GAME_MODE_LEVELS)
4445 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4446 else if (game_status == GAME_MODE_SETUP)
4447 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4450 case SCREEN_CTRL_ID_SCROLL_DOWN:
4451 if (game_status == GAME_MODE_LEVELS)
4452 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4453 else if (game_status == GAME_MODE_SETUP)
4454 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4457 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
4458 if (game_status == GAME_MODE_LEVELS)
4459 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
4460 else if (game_status == GAME_MODE_SETUP)
4461 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);