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 PROGRAM_EMAIL_STRING);
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,
1803 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
1804 "More information and levels:");
1805 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
1806 PROGRAM_WEBSITE_STRING);
1807 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
1808 "If you have created new levels,");
1809 DrawTextSCentered(ystart + 10 * ystep, FONT_TEXT_2,
1810 "send them to me to include them!");
1811 DrawTextSCentered(ystart + 11 * ystep, FONT_TEXT_2,
1814 DrawTextSCentered(ybottom, FONT_TEXT_4,
1815 "Press any key or button for info menu");
1818 void HandleInfoScreen_Program(int button)
1820 int button_released = !button;
1822 if (button == MB_MENU_LEAVE)
1824 info_mode = INFO_MODE_MAIN;
1830 if (button_released)
1832 FadeSoundsAndMusic();
1834 info_mode = INFO_MODE_MAIN;
1839 PlayMenuSoundIfLoop();
1843 void DrawInfoScreen_LevelSet()
1846 int ybottom = SYSIZE - 20;
1847 char *filename = getLevelSetInfoFilename();
1848 int font_nr = FONT_LEVEL_NUMBER;
1849 int font_width = getFontWidth(font_nr);
1850 int font_height = getFontHeight(font_nr);
1853 int sx = SX + pad_x;
1854 int sy = SY + pad_y;
1855 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
1856 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
1858 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1863 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
1865 DrawTextSCentered(ybottom, FONT_TEXT_4,
1866 "Press any key or button for info menu");
1868 if (filename != NULL)
1869 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
1870 max_lines_per_screen);
1872 DrawTextSCentered(ystart, FONT_TEXT_2,
1873 "No information for this level set.");
1876 void HandleInfoScreen_LevelSet(int button)
1878 int button_released = !button;
1880 if (button == MB_MENU_LEAVE)
1882 info_mode = INFO_MODE_MAIN;
1888 if (button_released)
1890 FadeSoundsAndMusic();
1892 info_mode = INFO_MODE_MAIN;
1897 PlayMenuSoundIfLoop();
1901 static void DrawInfoScreenExt(int fade_delay)
1903 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
1905 if (info_mode == INFO_MODE_TITLE)
1906 DrawInfoScreen_TitleScreen();
1907 else if (info_mode == INFO_MODE_ELEMENTS)
1908 DrawInfoScreen_Elements();
1909 else if (info_mode == INFO_MODE_MUSIC)
1910 DrawInfoScreen_Music();
1911 else if (info_mode == INFO_MODE_CREDITS)
1912 DrawInfoScreen_Credits();
1913 else if (info_mode == INFO_MODE_PROGRAM)
1914 DrawInfoScreen_Program();
1915 else if (info_mode == INFO_MODE_LEVELSET)
1916 DrawInfoScreen_LevelSet();
1918 DrawInfoScreen_Main(fade_delay);
1920 if (info_mode != INFO_MODE_MAIN &&
1921 info_mode != INFO_MODE_TITLE &&
1922 info_mode != INFO_MODE_MUSIC)
1929 void DrawInfoScreen()
1931 DrawInfoScreenExt(0);
1934 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
1936 if (info_mode == INFO_MODE_TITLE)
1937 HandleInfoScreen_TitleScreen(button);
1938 else if (info_mode == INFO_MODE_ELEMENTS)
1939 HandleInfoScreen_Elements(button);
1940 else if (info_mode == INFO_MODE_MUSIC)
1941 HandleInfoScreen_Music(button);
1942 else if (info_mode == INFO_MODE_CREDITS)
1943 HandleInfoScreen_Credits(button);
1944 else if (info_mode == INFO_MODE_PROGRAM)
1945 HandleInfoScreen_Program(button);
1946 else if (info_mode == INFO_MODE_LEVELSET)
1947 HandleInfoScreen_LevelSet(button);
1949 HandleInfoScreen_Main(mx, my, dx, dy, button);
1955 /* ========================================================================= */
1956 /* type name functions */
1957 /* ========================================================================= */
1959 void HandleTypeName(int newxpos, Key key)
1961 static int xpos = 0, ypos = 2;
1962 int font_width = getFontWidth(FONT_INPUT_1_ACTIVE);
1963 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
1964 int startx = mSX + 32 + name_width;
1965 int starty = mSY + ypos * 32;
1971 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1972 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1977 if (((key >= KSYM_A && key <= KSYM_Z) ||
1978 (key >= KSYM_a && key <= KSYM_z)) &&
1979 xpos < MAX_PLAYER_NAME_LEN)
1983 if (key >= KSYM_A && key <= KSYM_Z)
1984 ascii = 'A' + (char)(key - KSYM_A);
1986 ascii = 'a' + (char)(key - KSYM_a);
1988 setup.player_name[xpos] = ascii;
1989 setup.player_name[xpos + 1] = 0;
1992 DrawText(startx, starty, setup.player_name, FONT_INPUT_1_ACTIVE);
1993 DrawText(startx + xpos * font_width, starty, "_", FONT_INPUT_1_ACTIVE);
1995 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
1998 setup.player_name[xpos] = 0;
2000 DrawText(startx + xpos * font_width, starty, "_ ", FONT_INPUT_1_ACTIVE);
2002 else if (key == KSYM_Return && xpos > 0)
2004 DrawText(startx, starty, setup.player_name, FONT_INPUT_1);
2005 DrawText(startx + xpos * font_width, starty, " ", FONT_INPUT_1_ACTIVE);
2008 game_status = GAME_MODE_MAIN;
2013 /* ========================================================================= */
2014 /* tree menu functions */
2015 /* ========================================================================= */
2017 static void DrawChooseTree(TreeInfo **ti_ptr)
2021 FreeScreenGadgets();
2022 CreateScreenGadgets();
2024 CloseDoor(DOOR_CLOSE_2);
2028 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
2029 MapScreenTreeGadgets(*ti_ptr);
2035 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
2037 struct GadgetInfo *gi = screen_gadget[id];
2038 int items_max, items_visible, item_position;
2040 items_max = numTreeInfoInGroup(ti);
2041 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
2042 item_position = first_entry;
2044 if (item_position > items_max - items_visible)
2045 item_position = items_max - items_visible;
2047 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
2048 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2049 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
2052 static void drawChooseTreeList(int first_entry, int num_page_entries,
2056 char *title_string = NULL;
2058 int xoffset_sets = 16;
2060 int yoffset_sets = MENU_TITLE1_YPOS;
2062 int xoffset_setup = 16;
2064 int yoffset_setup = 16;
2067 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? xoffset_sets :
2070 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
2073 int xoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : xoffset_setup);
2074 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? 0 : yoffset_setup);
2076 int last_game_status = game_status; /* save current game status */
2078 title_string = ti->infotext;
2081 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
2083 DrawText(SX + xoffset, SY + yoffset, title_string, FONT_TITLE_1);
2086 /* force LEVELS font on artwork setup screen */
2087 game_status = GAME_MODE_LEVELS;
2089 /* clear tree list area, but not title or scrollbar */
2090 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
2091 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
2092 MAX_MENU_ENTRIES_ON_SCREEN * 32);
2094 for (i = 0; i < num_page_entries; i++)
2096 TreeInfo *node, *node_first;
2097 int entry_pos = first_entry + i;
2098 int xpos = MENU_SCREEN_START_XPOS;
2099 int ypos = MENU_SCREEN_START_YPOS + i;
2100 int startx = mSX + xpos * 32;
2101 int starty = mSY + ypos * 32;
2102 int font_nr = FONT_TEXT_1;
2103 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2104 int startx_text = startx + font_xoffset;
2105 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
2106 int text_size = startx_scrollbar - startx_text;
2107 int max_buffer_len = text_size / getFontWidth(font_nr);
2108 char buffer[max_buffer_len + 1];
2110 node_first = getTreeInfoFirstGroupEntry(ti);
2111 node = getTreeInfoFromPos(node_first, entry_pos);
2113 strncpy(buffer, node->name, max_buffer_len);
2114 buffer[max_buffer_len] = '\0';
2116 DrawText(startx, starty, buffer, font_nr + node->color);
2118 if (node->parent_link)
2119 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2120 else if (node->level_group)
2121 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2123 initCursor(i, IMG_MENU_BUTTON);
2126 game_status = last_game_status; /* restore current game status */
2128 redraw_mask |= REDRAW_FIELD;
2131 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
2133 TreeInfo *node, *node_first;
2134 int x, last_redraw_mask = redraw_mask;
2136 int ypos = MENU_TITLE2_YPOS;
2141 if (ti->type != TREE_TYPE_LEVEL_DIR)
2144 node_first = getTreeInfoFirstGroupEntry(ti);
2145 node = getTreeInfoFromPos(node_first, entry_pos);
2147 DrawBackground(SX, SY + ypos, SXSIZE, getFontHeight(FONT_TITLE_2));
2149 if (node->parent_link)
2150 DrawTextFCentered(ypos, FONT_TITLE_2, "leave group \"%s\"",
2152 else if (node->level_group)
2153 DrawTextFCentered(ypos, FONT_TITLE_2, "enter group \"%s\"",
2155 else if (ti->type == TREE_TYPE_LEVEL_DIR)
2156 DrawTextFCentered(ypos, FONT_TITLE_2, "%3d levels (%s)",
2157 node->levels, node->class_desc);
2159 /* let BackToFront() redraw only what is needed */
2160 redraw_mask = last_redraw_mask | REDRAW_TILES;
2161 for (x = 0; x < SCR_FIELDX; x++)
2162 MarkTileDirty(x, 1);
2165 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
2168 TreeInfo *ti = *ti_ptr;
2170 int y = ti->cl_cursor;
2171 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2172 int num_entries = numTreeInfoInGroup(ti);
2173 int num_page_entries;
2174 int last_game_status = game_status; /* save current game status */
2175 boolean position_set_by_scrollbar = (dx == 999);
2177 /* force LEVELS draw offset on choose level and artwork setup screen */
2178 game_status = GAME_MODE_LEVELS;
2180 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
2181 num_page_entries = num_entries;
2183 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2185 game_status = last_game_status; /* restore current game status */
2187 if (button == MB_MENU_INITIALIZE)
2189 int num_entries = numTreeInfoInGroup(ti);
2190 int entry_pos = posTreeInfo(ti);
2192 if (ti->cl_first == -1)
2194 /* only on initialization */
2195 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2196 ti->cl_cursor = entry_pos - ti->cl_first;
2198 else if (ti->cl_cursor >= num_page_entries ||
2199 (num_entries > num_page_entries &&
2200 num_entries - ti->cl_first < num_page_entries))
2202 /* only after change of list size (by custom graphic configuration) */
2203 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2204 ti->cl_cursor = entry_pos - ti->cl_first;
2207 if (position_set_by_scrollbar)
2210 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2213 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2214 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2215 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2219 else if (button == MB_MENU_LEAVE)
2221 if (ti->node_parent)
2223 *ti_ptr = ti->node_parent;
2224 DrawChooseTree(ti_ptr);
2226 else if (game_status == GAME_MODE_SETUP)
2228 if (game_status == GAME_MODE_SETUP)
2230 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2231 execSetupGraphics();
2238 game_status = GAME_MODE_MAIN;
2245 if (mx || my) /* mouse input */
2247 int last_game_status = game_status; /* save current game status */
2249 /* force LEVELS draw offset on artwork setup screen */
2250 game_status = GAME_MODE_LEVELS;
2252 x = (mx - mSX) / 32;
2253 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2255 game_status = last_game_status; /* restore current game status */
2257 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2259 /* move cursor instead of scrolling when already at start/end of list */
2260 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
2262 else if (dy == +1 * SCROLL_LINE &&
2263 ti->cl_first + num_page_entries == num_entries)
2266 /* handle scrolling screen one line or page */
2267 if (ti->cl_cursor + dy < 0 ||
2268 ti->cl_cursor + dy > num_page_entries - 1)
2270 if (ABS(dy) == SCROLL_PAGE)
2271 step = num_page_entries - 1;
2273 if (dy < 0 && ti->cl_first > 0)
2275 /* scroll page/line up */
2277 ti->cl_first -= step;
2278 if (ti->cl_first < 0)
2281 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2282 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2283 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2284 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2287 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
2289 /* scroll page/line down */
2291 ti->cl_first += step;
2292 if (ti->cl_first + num_page_entries > num_entries)
2293 ti->cl_first = MAX(0, num_entries - num_page_entries);
2295 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2296 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2297 drawChooseTreeCursor(ti->cl_cursor, FC_RED);
2298 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2305 /* handle moving cursor one line */
2306 y = ti->cl_cursor + dy;
2311 TreeInfo *node_first, *node_cursor;
2312 int entry_pos = ti->cl_first + y;
2314 node_first = getTreeInfoFirstGroupEntry(ti);
2315 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2317 if (node_cursor->node_group)
2319 node_cursor->cl_first = ti->cl_first;
2320 node_cursor->cl_cursor = ti->cl_cursor;
2321 *ti_ptr = node_cursor->node_group;
2322 DrawChooseTree(ti_ptr);
2327 else if (dx == -1 && ti->node_parent)
2329 *ti_ptr = ti->node_parent;
2330 DrawChooseTree(ti_ptr);
2335 if (!anyScrollbarGadgetActive() &&
2336 IN_VIS_FIELD(x, y) &&
2337 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2338 y >= 0 && y < num_page_entries)
2342 if (y != ti->cl_cursor)
2344 drawChooseTreeCursor(y, FC_RED);
2345 drawChooseTreeCursor(ti->cl_cursor, FC_BLUE);
2346 drawChooseTreeInfo(ti->cl_first + y, ti);
2352 TreeInfo *node_first, *node_cursor;
2353 int entry_pos = ti->cl_first + y;
2355 node_first = getTreeInfoFirstGroupEntry(ti);
2356 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2358 if (node_cursor->node_group)
2360 node_cursor->cl_first = ti->cl_first;
2361 node_cursor->cl_cursor = ti->cl_cursor;
2362 *ti_ptr = node_cursor->node_group;
2363 DrawChooseTree(ti_ptr);
2365 else if (node_cursor->parent_link)
2367 *ti_ptr = node_cursor->node_parent;
2368 DrawChooseTree(ti_ptr);
2372 node_cursor->cl_first = ti->cl_first;
2373 node_cursor->cl_cursor = ti->cl_cursor;
2374 *ti_ptr = node_cursor;
2376 if (ti->type == TREE_TYPE_LEVEL_DIR)
2378 LoadLevelSetup_SeriesInfo();
2380 SaveLevelSetup_LastSeries();
2381 SaveLevelSetup_SeriesInfo();
2385 if (game_status == GAME_MODE_SETUP)
2387 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2388 execSetupGraphics();
2394 game_status = GAME_MODE_MAIN;
2402 void DrawChooseLevel()
2404 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2406 DrawChooseTree(&leveldir_current);
2412 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2414 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2419 void DrawHallOfFame(int highlight_position)
2422 FadeSoundsAndMusic();
2423 CloseDoor(DOOR_CLOSE_2);
2425 if (highlight_position < 0)
2426 LoadScore(level_nr);
2434 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
2437 static void drawHallOfFameList(int first_entry, int highlight_position)
2441 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
2445 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
2446 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2447 "HighScores of Level %d", level_nr);
2449 DrawText(mSX + 80, mSY + MENU_TITLE1_YPOS, "Hall Of Fame", FONT_TITLE_1);
2450 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
2451 "HighScores of Level %d", level_nr);
2454 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2456 int entry = first_entry + i;
2457 boolean active = (entry == highlight_position);
2458 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
2459 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
2460 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
2461 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
2462 int dx1 = 3 * getFontWidth(font_nr1);
2463 int dx2 = dx1 + getFontWidth(font_nr1);
2464 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
2465 int sy = mSY + 64 + i * 32;
2467 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
2468 DrawText(mSX + dx1, sy, ".", font_nr1);
2469 DrawText(mSX + dx2, sy, ".........................", font_nr3);
2471 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
2472 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
2474 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
2477 redraw_mask |= REDRAW_FIELD;
2480 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
2482 static int first_entry = 0;
2483 static int highlight_position = 0;
2484 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2485 int button_released = !button;
2487 if (button == MB_MENU_INITIALIZE)
2490 highlight_position = mx;
2491 drawHallOfFameList(first_entry, highlight_position);
2496 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
2497 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
2501 if (first_entry > 0)
2503 first_entry -= step;
2504 if (first_entry < 0)
2507 drawHallOfFameList(first_entry, highlight_position);
2512 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
2514 first_entry += step;
2515 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
2516 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
2518 drawHallOfFameList(first_entry, highlight_position);
2521 else if (button_released)
2523 FadeSound(SND_BACKGROUND_SCORES);
2524 game_status = GAME_MODE_MAIN;
2528 if (game_status == GAME_MODE_SCORES)
2529 PlayMenuSoundIfLoop();
2535 /* ========================================================================= */
2536 /* setup screen functions */
2537 /* ========================================================================= */
2539 static struct TokenInfo *setup_info;
2540 static int num_setup_info;
2542 static char *screen_mode_text;
2543 static char *graphics_set_name;
2544 static char *sounds_set_name;
2545 static char *music_set_name;
2547 static void execSetupMain()
2549 setup_mode = SETUP_MODE_MAIN;
2553 static void execSetupGame()
2555 setup_mode = SETUP_MODE_GAME;
2559 static void execSetupEditor()
2561 setup_mode = SETUP_MODE_EDITOR;
2565 static void execSetupGraphics()
2567 if (video.fullscreen_available && screen_modes == NULL)
2571 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
2573 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
2574 char identifier[32], name[32];
2575 int x = video.fullscreen_modes[i].width;
2576 int y = video.fullscreen_modes[i].height;
2579 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
2581 ti->node_top = &screen_modes;
2582 ti->sort_priority = x * 10000 + y;
2584 sprintf(identifier, "%dx%d", x, y);
2585 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
2587 setString(&ti->identifier, identifier);
2588 setString(&ti->name, name);
2589 setString(&ti->name_sorting, name);
2590 setString(&ti->infotext, "Fullscreen Mode");
2592 pushTreeInfo(&screen_modes, ti);
2595 /* sort fullscreen modes to start with lowest available screen resolution */
2596 sortTreeInfo(&screen_modes);
2598 /* set current screen mode for fullscreen mode to configured setup value */
2599 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2600 setup.fullscreen_mode);
2602 /* if that fails, set current screen mode to reliable default value */
2603 if (screen_mode_current == NULL)
2604 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
2605 DEFAULT_FULLSCREEN_MODE);
2607 /* if that also fails, set current screen mode to first available mode */
2608 if (screen_mode_current == NULL)
2609 screen_mode_current = screen_modes;
2611 if (screen_mode_current == NULL)
2612 video.fullscreen_available = FALSE;
2615 if (video.fullscreen_available)
2617 setup.fullscreen_mode = screen_mode_current->identifier;
2619 /* needed for displaying screen mode name instead of identifier */
2620 screen_mode_text = screen_mode_current->name;
2623 setup_mode = SETUP_MODE_GRAPHICS;
2627 static void execSetupChooseScreenMode()
2629 if (!video.fullscreen_available)
2632 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
2636 static void execSetupSound()
2638 setup_mode = SETUP_MODE_SOUND;
2642 static void execSetupArtwork()
2644 setup.graphics_set = artwork.gfx_current->identifier;
2645 setup.sounds_set = artwork.snd_current->identifier;
2646 setup.music_set = artwork.mus_current->identifier;
2648 /* needed if last screen (setup choice) changed graphics, sounds or music */
2649 ReloadCustomArtwork(0);
2651 /* needed for displaying artwork name instead of artwork identifier */
2652 graphics_set_name = artwork.gfx_current->name;
2653 sounds_set_name = artwork.snd_current->name;
2654 music_set_name = artwork.mus_current->name;
2656 setup_mode = SETUP_MODE_ARTWORK;
2660 static void execSetupChooseGraphics()
2662 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
2666 static void execSetupChooseSounds()
2668 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
2672 static void execSetupChooseMusic()
2674 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
2678 static void execSetupInput()
2680 setup_mode = SETUP_MODE_INPUT;
2684 static void execSetupShortcut1()
2686 setup_mode = SETUP_MODE_SHORTCUT_1;
2690 static void execSetupShortcut2()
2692 setup_mode = SETUP_MODE_SHORTCUT_2;
2696 static void execExitSetup()
2698 game_status = GAME_MODE_MAIN;
2702 static void execSaveAndExitSetup()
2708 static struct TokenInfo setup_info_main[] =
2710 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
2711 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
2712 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
2713 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
2714 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
2715 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
2716 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
2717 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
2718 { TYPE_EMPTY, NULL, "" },
2719 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
2720 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
2725 static struct TokenInfo setup_info_game[] =
2727 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
2728 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
2729 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
2730 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
2731 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
2732 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
2733 { TYPE_EMPTY, NULL, "" },
2734 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2739 static struct TokenInfo setup_info_editor[] =
2742 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
2743 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
2744 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
2745 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
2746 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
2747 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
2748 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
2749 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
2751 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
2752 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
2754 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
2756 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
2757 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
2758 { TYPE_EMPTY, NULL, "" },
2760 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
2761 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
2762 { TYPE_EMPTY, NULL, "" },
2764 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
2765 { TYPE_EMPTY, NULL, "" },
2766 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2771 static struct TokenInfo setup_info_graphics[] =
2773 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
2774 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
2775 { TYPE_STRING, &screen_mode_text, "" },
2776 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
2778 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
2779 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
2780 { TYPE_SWITCH, &setup.fading, "Fading:" },
2782 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
2783 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
2784 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
2785 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
2786 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
2787 { TYPE_EMPTY, NULL, "" },
2788 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2793 static struct TokenInfo setup_info_sound[] =
2795 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
2796 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
2797 { TYPE_SWITCH, &setup.sound_music, "Music:" },
2798 { TYPE_EMPTY, NULL, "" },
2799 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2804 static struct TokenInfo setup_info_artwork[] =
2806 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
2807 { TYPE_STRING, &graphics_set_name, "" },
2808 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
2809 { TYPE_STRING, &sounds_set_name, "" },
2810 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
2811 { TYPE_STRING, &music_set_name, "" },
2812 { TYPE_EMPTY, NULL, "" },
2814 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
2815 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
2816 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
2818 { TYPE_STRING, NULL, "Override Level Artwork:"},
2819 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
2820 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
2821 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
2823 { TYPE_EMPTY, NULL, "" },
2824 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2829 static struct TokenInfo setup_info_shortcut_1[] =
2831 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
2832 { TYPE_KEY, &setup.shortcut.save_game, "" },
2833 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
2834 { TYPE_KEY, &setup.shortcut.load_game, "" },
2835 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
2836 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
2837 { TYPE_EMPTY, NULL, "" },
2838 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
2839 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
2840 { TYPE_EMPTY, NULL, "" },
2841 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2846 static struct TokenInfo setup_info_shortcut_2[] =
2848 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
2849 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
2850 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
2851 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
2852 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
2853 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
2854 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
2855 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
2856 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
2857 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
2858 { TYPE_EMPTY, NULL, "" },
2859 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
2864 static Key getSetupKey()
2866 Key key = KSYM_UNDEFINED;
2867 boolean got_key_event = FALSE;
2869 while (!got_key_event)
2871 if (PendingEvent()) /* got event */
2879 case EVENT_KEYPRESS:
2881 key = GetEventKey((KeyEvent *)&event, TRUE);
2883 /* press 'Escape' or 'Enter' to keep the existing key binding */
2884 if (key == KSYM_Escape || key == KSYM_Return)
2885 key = KSYM_UNDEFINED; /* keep old value */
2887 got_key_event = TRUE;
2891 case EVENT_KEYRELEASE:
2892 key_joystick_mapping = 0;
2896 HandleOtherEvents(&event);
2904 /* don't eat all CPU time */
2911 static int getSetupTextFont(int type)
2913 if (type & (TYPE_SWITCH |
2924 static int getSetupValueFont(int type, void *value)
2926 if (type & TYPE_KEY)
2927 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
2928 else if (type & TYPE_STRING)
2929 return FONT_VALUE_2;
2930 else if (type & TYPE_ECS_AGA)
2931 return FONT_VALUE_1;
2932 else if (type & TYPE_BOOLEAN_STYLE)
2933 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2935 return FONT_VALUE_1;
2938 static void drawSetupValue(int pos)
2940 boolean font_draw_xoffset_modified = FALSE;
2941 int font_draw_xoffset_old = -1;
2942 int xpos = MENU_SCREEN_VALUE_XPOS;
2943 int ypos = MENU_SCREEN_START_YPOS + pos;
2944 int startx = mSX + xpos * 32;
2945 int starty = mSY + ypos * 32;
2946 int font_nr, font_width;
2947 int type = setup_info[pos].type;
2948 void *value = setup_info[pos].value;
2949 char *value_string = getSetupValue(type, value);
2952 if (value_string == NULL)
2955 if (type & TYPE_KEY)
2958 xpos = MENU_SCREEN_START_XPOS;
2963 if (type & TYPE_QUERY)
2965 value_string = "<press key>";
2967 font_nr = FONT_INPUT_1_ACTIVE;
2971 else if (type & TYPE_STRING)
2973 int max_value_len = (SCR_FIELDX - 2) * 2;
2975 xpos = MENU_SCREEN_START_XPOS;
2977 font_nr = FONT_VALUE_2;
2980 if (strlen(value_string) > max_value_len)
2981 value_string[max_value_len] = '\0';
2983 else if (type & TYPE_ECS_AGA)
2986 font_nr = FONT_VALUE_1;
2989 else if (type & TYPE_BOOLEAN_STYLE)
2992 font_nr = (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
2996 startx = mSX + xpos * 32;
2997 starty = mSY + ypos * 32;
2998 font_nr = getSetupValueFont(type, value);
2999 font_width = getFontWidth(font_nr);
3001 /* downward compatibility correction for Juergen Bonhagen's menu settings */
3002 if (setup_mode != SETUP_MODE_INPUT)
3004 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
3005 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3006 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
3007 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
3008 int text_font_nr = getSetupTextFont(FONT_MENU_2);
3009 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
3010 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
3011 boolean correct_font_draw_xoffset = FALSE;
3013 if (xpos == MENU_SCREEN_START_XPOS &&
3014 startx + font1_xoffset < text_startx + text_font_xoffset)
3015 correct_font_draw_xoffset = TRUE;
3017 if (xpos == MENU_SCREEN_VALUE_XPOS &&
3018 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
3019 correct_font_draw_xoffset = TRUE;
3022 printf("::: %d + %d < %d + %d + %d\n",
3023 startx, font_xoffset, text_startx, text_width, text_font_xoffset);
3024 printf("::: => need correction == %d\n", correct_font_draw_xoffset);
3027 /* check if setup value would overlap with setup text when printed */
3028 /* (this can happen for extreme/wrong values for font draw offset) */
3029 if (correct_font_draw_xoffset)
3031 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
3032 font_draw_xoffset_modified = TRUE;
3034 if (type & TYPE_KEY)
3035 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
3036 else if (!(type & TYPE_STRING))
3037 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
3038 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
3043 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
3044 DrawText(startx + i * font_width, starty, " ", font_nr);
3047 for (i = xpos; i <= MENU_SCREEN_MAX_XPOS; i++)
3048 DrawText(mSX + i * 32, starty, " ", font_nr);
3050 DrawText(startx, starty,
3051 (xpos == 3 ? " " : " "), font_nr);
3055 DrawText(startx, starty, value_string, font_nr);
3057 if (font_draw_xoffset_modified)
3058 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
3061 static void changeSetupValue(int pos)
3063 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
3065 *(boolean *)setup_info[pos].value ^= TRUE;
3067 else if (setup_info[pos].type & TYPE_KEY)
3071 setup_info[pos].type |= TYPE_QUERY;
3072 drawSetupValue(pos);
3073 setup_info[pos].type &= ~TYPE_QUERY;
3075 key = getSetupKey();
3076 if (key != KSYM_UNDEFINED)
3077 *(Key *)setup_info[pos].value = key;
3080 drawSetupValue(pos);
3083 static void DrawSetupScreen_Generic()
3085 char *title_string = NULL;
3089 CloseDoor(DOOR_CLOSE_2);
3093 if (setup_mode == SETUP_MODE_MAIN)
3095 setup_info = setup_info_main;
3096 title_string = "Setup";
3098 else if (setup_mode == SETUP_MODE_GAME)
3100 setup_info = setup_info_game;
3101 title_string = "Setup Game";
3103 else if (setup_mode == SETUP_MODE_EDITOR)
3105 setup_info = setup_info_editor;
3106 title_string = "Setup Editor";
3108 else if (setup_mode == SETUP_MODE_GRAPHICS)
3110 setup_info = setup_info_graphics;
3111 title_string = "Setup Graphics";
3113 else if (setup_mode == SETUP_MODE_SOUND)
3115 setup_info = setup_info_sound;
3116 title_string = "Setup Sound";
3118 else if (setup_mode == SETUP_MODE_ARTWORK)
3120 setup_info = setup_info_artwork;
3121 title_string = "Custom Artwork";
3123 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
3125 setup_info = setup_info_shortcut_1;
3126 title_string = "Setup Shortcuts";
3128 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
3130 setup_info = setup_info_shortcut_2;
3131 title_string = "Setup Shortcuts";
3135 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
3137 DrawText(mSX + 16, mSY + 16, title_string, FONT_TITLE_1);
3141 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3143 void *value_ptr = setup_info[i].value;
3144 int xpos = MENU_SCREEN_START_XPOS;
3145 int ypos = MENU_SCREEN_START_YPOS + i;
3149 int font_nr = FONT_MENU_1;
3152 /* set some entries to "unchangeable" according to other variables */
3153 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
3154 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
3155 (value_ptr == &setup.sound_music && !audio.music_available) ||
3156 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
3157 (value_ptr == &screen_mode_text && !video.fullscreen_available))
3158 setup_info[i].type |= TYPE_GHOSTED;
3161 font_nr = getSetupTextFont(setup_info[i].type);
3164 if (setup_info[i].type & (TYPE_SWITCH |
3169 font_nr = FONT_MENU_2;
3171 if (setup_info[i].type & TYPE_STRING)
3172 font_nr = FONT_MENU_2;
3176 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
3178 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
3179 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3180 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
3181 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3182 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
3183 initCursor(i, IMG_MENU_BUTTON);
3185 if (setup_info[i].type & TYPE_VALUE)
3192 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3193 "Joysticks deactivated in setup menu");
3198 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
3201 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
3203 static int choice_store[MAX_SETUP_MODES];
3204 int choice = choice_store[setup_mode]; /* always starts with 0 */
3208 if (button == MB_MENU_INITIALIZE)
3210 /* advance to first valid menu entry */
3211 while (choice < num_setup_info &&
3212 setup_info[choice].type & TYPE_SKIP_ENTRY)
3214 choice_store[setup_mode] = choice;
3216 drawCursor(choice, FC_RED);
3220 else if (button == MB_MENU_LEAVE)
3222 for (y = 0; y < num_setup_info; y++)
3224 if (setup_info[y].type & TYPE_LEAVE_MENU)
3226 void (*menu_callback_function)(void) = setup_info[y].value;
3228 menu_callback_function();
3230 break; /* absolutely needed because function changes 'setup_info'! */
3237 if (mx || my) /* mouse input */
3239 x = (mx - mSX) / 32;
3240 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3242 else if (dx || dy) /* keyboard input */
3246 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
3248 if (setup_info[choice].type & menu_navigation_type ||
3249 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
3250 button = MB_MENU_CHOICE;
3255 /* jump to next non-empty menu entry (up or down) */
3256 while (y > 0 && y < num_setup_info - 1 &&
3257 setup_info[y].type & TYPE_SKIP_ENTRY)
3262 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
3266 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3268 drawCursor(y, FC_RED);
3269 drawCursor(choice, FC_BLUE);
3270 choice = choice_store[setup_mode] = y;
3273 else if (!(setup_info[y].type & TYPE_GHOSTED))
3275 /* when selecting key headline, execute function for key value change */
3276 if (setup_info[y].type & TYPE_KEYTEXT &&
3277 setup_info[y + 1].type & TYPE_KEY)
3280 /* when selecting string value, execute function for list selection */
3281 if (setup_info[y].type & TYPE_STRING && y > 0 &&
3282 setup_info[y - 1].type & TYPE_ENTER_LIST)
3285 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3287 void (*menu_callback_function)(void) = setup_info[y].value;
3289 menu_callback_function();
3293 if (setup_info[y].type & TYPE_VALUE)
3294 changeSetupValue(y);
3299 if (IN_VIS_FIELD(x, y) &&
3300 y >= 0 && y < num_setup_info && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3306 drawCursor(y, FC_RED);
3307 drawCursor(choice, FC_BLUE);
3308 choice = choice_store[setup_mode] = y;
3311 else if (!(setup_info[y].type & TYPE_GHOSTED))
3313 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3315 void (*menu_callback_function)(void) = setup_info[choice].value;
3317 menu_callback_function();
3321 if (setup_info[y].type & TYPE_KEYTEXT &&
3322 setup_info[y + 1].type & TYPE_KEY)
3325 if (setup_info[y].type & TYPE_VALUE)
3326 changeSetupValue(y);
3333 void DrawSetupScreen_Input()
3338 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
3340 DrawText(mSX + 16, mSY + 16, "Setup Input", FONT_TITLE_1);
3343 initCursor(0, IMG_MENU_BUTTON);
3344 initCursor(1, IMG_MENU_BUTTON);
3345 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
3346 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
3349 drawCursorXY(10, 0, IMG_MENU_BUTTON_LEFT);
3350 drawCursorXY(12, 0, IMG_MENU_BUTTON_RIGHT);
3353 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
3354 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
3355 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
3358 DeactivateJoystickForCalibration();
3361 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3362 "Joysticks deactivated on this screen");
3366 /* create gadgets for setup input menu screen */
3367 FreeScreenGadgets();
3368 CreateScreenGadgets();
3370 /* map gadgets for setup input menu screen */
3371 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
3374 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
3379 static void setJoystickDeviceToNr(char *device_name, int device_nr)
3381 if (device_name == NULL)
3384 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
3387 if (strlen(device_name) > 1)
3389 char c1 = device_name[strlen(device_name) - 1];
3390 char c2 = device_name[strlen(device_name) - 2];
3392 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
3393 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
3396 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
3397 strlen(device_name));
3400 static void drawPlayerSetupInputInfo(int player_nr)
3403 static struct SetupKeyboardInfo custom_key;
3410 { &custom_key.left, "Joystick Left" },
3411 { &custom_key.right, "Joystick Right" },
3412 { &custom_key.up, "Joystick Up" },
3413 { &custom_key.down, "Joystick Down" },
3414 { &custom_key.snap, "Button 1" },
3415 { &custom_key.drop, "Button 2" }
3417 static char *joystick_name[MAX_PLAYERS] =
3427 custom_key = setup.input[player_nr].key;
3429 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
3430 FONT_INPUT_1_ACTIVE);
3432 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3434 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
3435 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
3437 if (setup.input[player_nr].use_joystick)
3439 char *device_name = setup.input[player_nr].joy.device_name;
3440 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
3441 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
3443 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
3444 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", FONT_MENU_1);
3448 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
3449 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", FONT_MENU_1);
3452 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
3453 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
3454 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
3455 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
3456 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
3457 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
3458 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
3459 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
3460 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
3461 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
3462 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
3464 for (i = 0; i < 6; i++)
3466 int ypos = 6 + i + (i > 3 ? i-3 : 0);
3468 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3470 DrawText(mSX + 3 * 32, mSY + ypos * 32,
3471 (setup.input[player_nr].use_joystick ?
3473 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
3477 static int input_player_nr = 0;
3479 void HandleSetupScreen_Input_Player(int step, int direction)
3481 int old_player_nr = input_player_nr;
3484 new_player_nr = old_player_nr + step * direction;
3485 if (new_player_nr < 0)
3487 if (new_player_nr > MAX_PLAYERS - 1)
3488 new_player_nr = MAX_PLAYERS - 1;
3490 if (new_player_nr != old_player_nr)
3492 input_player_nr = new_player_nr;
3494 drawPlayerSetupInputInfo(input_player_nr);
3498 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
3500 static int choice = 0;
3503 int pos_start = SETUPINPUT_SCREEN_POS_START;
3504 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
3505 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
3506 int pos_end = SETUPINPUT_SCREEN_POS_END;
3508 if (button == MB_MENU_INITIALIZE)
3510 drawPlayerSetupInputInfo(input_player_nr);
3511 drawCursor(choice, FC_RED);
3515 else if (button == MB_MENU_LEAVE)
3517 setup_mode = SETUP_MODE_MAIN;
3524 if (mx || my) /* mouse input */
3526 x = (mx - mSX) / 32;
3527 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3529 else if (dx || dy) /* keyboard input */
3531 if (dx && choice == 0)
3532 x = (dx < 0 ? 10 : 12);
3533 else if ((dx && choice == 1) ||
3534 (dx == +1 && choice == 2) ||
3535 (dx == -1 && choice == pos_end))
3536 button = MB_MENU_CHOICE;
3540 if (y >= pos_empty1 && y <= pos_empty2)
3541 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
3546 if (y == 0 && dx != 0 && button)
3548 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
3553 if (IN_VIS_FIELD(x, y) &&
3554 y == 0 && ((x < 10 && !button) || ((x == 10 || x == 12) && button)))
3556 static unsigned long delay = 0;
3558 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
3562 (input_player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
3564 drawPlayerSetupInputInfo(input_player_nr);
3569 else if (IN_VIS_FIELD(x, y) &&
3570 y >= pos_start && y <= pos_end &&
3571 !(y >= pos_empty1 && y <= pos_empty2))
3577 drawCursor(y, FC_RED);
3578 drawCursor(choice, FC_BLUE);
3586 char *device_name = setup.input[input_player_nr].joy.device_name;
3588 if (!setup.input[input_player_nr].use_joystick)
3590 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
3592 setJoystickDeviceToNr(device_name, new_device_nr);
3593 setup.input[input_player_nr].use_joystick = TRUE;
3597 int device_nr = getJoystickNrFromDeviceName(device_name);
3598 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
3600 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
3601 setup.input[input_player_nr].use_joystick = FALSE;
3603 setJoystickDeviceToNr(device_name, new_device_nr);
3606 drawPlayerSetupInputInfo(input_player_nr);
3610 if (setup.input[input_player_nr].use_joystick)
3613 CalibrateJoystick(input_player_nr);
3616 CustomizeKeyboard(input_player_nr);
3618 else if (y == pos_end)
3622 setup_mode = SETUP_MODE_MAIN;
3629 void CustomizeKeyboard(int player_nr)
3633 boolean finished = FALSE;
3634 static struct SetupKeyboardInfo custom_key;
3639 } customize_step[] =
3641 { &custom_key.left, "Move Left" },
3642 { &custom_key.right, "Move Right" },
3643 { &custom_key.up, "Move Up" },
3644 { &custom_key.down, "Move Down" },
3645 { &custom_key.snap, "Snap Field" },
3646 { &custom_key.drop, "Drop Element" }
3649 /* read existing key bindings from player setup */
3650 custom_key = setup.input[player_nr].key;
3655 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
3657 DrawText(mSX + 16, mSY + 16, "Keyboard Input", FONT_TITLE_1);
3664 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3665 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3666 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3667 "Key:", FONT_INPUT_1_ACTIVE);
3668 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3669 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
3673 if (PendingEvent()) /* got event */
3681 case EVENT_KEYPRESS:
3683 Key key = GetEventKey((KeyEvent *)&event, FALSE);
3685 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
3691 /* all keys configured -- wait for "Escape" or "Return" key */
3695 /* press 'Enter' to keep the existing key binding */
3696 if (key == KSYM_Return)
3697 key = *customize_step[step_nr].key;
3699 /* check if key already used */
3700 for (i = 0; i < step_nr; i++)
3701 if (*customize_step[i].key == key)
3706 /* got new key binding */
3707 *customize_step[step_nr].key = key;
3708 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3710 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3711 getKeyNameFromKey(key), FONT_VALUE_1);
3714 /* un-highlight last query */
3715 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
3716 customize_step[step_nr - 1].text, FONT_MENU_1);
3717 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
3718 "Key:", FONT_MENU_1);
3720 /* press 'Enter' to leave */
3723 DrawText(mSX + 16, mSY + 15 * 32 + 16,
3724 "Press Enter", FONT_TITLE_1);
3728 /* query next key binding */
3729 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
3730 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
3731 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
3732 "Key:", FONT_INPUT_1_ACTIVE);
3733 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
3734 getKeyNameFromKey(*customize_step[step_nr].key),
3739 case EVENT_KEYRELEASE:
3740 key_joystick_mapping = 0;
3744 HandleOtherEvents(&event);
3752 /* don't eat all CPU time */
3756 /* write new key bindings back to player setup */
3757 setup.input[player_nr].key = custom_key;
3760 DrawSetupScreen_Input();
3763 static boolean CalibrateJoystickMain(int player_nr)
3765 int new_joystick_xleft = JOYSTICK_XMIDDLE;
3766 int new_joystick_xright = JOYSTICK_XMIDDLE;
3767 int new_joystick_yupper = JOYSTICK_YMIDDLE;
3768 int new_joystick_ylower = JOYSTICK_YMIDDLE;
3769 int new_joystick_xmiddle, new_joystick_ymiddle;
3771 int joystick_fd = joystick.fd[player_nr];
3772 int x, y, last_x, last_y, xpos = 8, ypos = 3;
3773 boolean check[3][3];
3774 int check_remaining = 3 * 3;
3779 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
3782 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
3787 for (y = 0; y < 3; y++)
3789 for (x = 0; x < 3; x++)
3791 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
3792 check[x][y] = FALSE;
3796 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
3797 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
3798 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
3799 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
3800 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
3801 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
3802 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
3804 joy_value = Joystick(player_nr);
3805 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3806 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3808 /* eventually uncalibrated center position (joystick could be uncentered) */
3809 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3812 new_joystick_xmiddle = joy_x;
3813 new_joystick_ymiddle = joy_y;
3815 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
3818 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
3823 if (PendingEvent()) /* got event */
3831 case EVENT_KEYPRESS:
3832 switch(GetEventKey((KeyEvent *)&event, TRUE))
3835 if (check_remaining == 0)
3848 case EVENT_KEYRELEASE:
3849 key_joystick_mapping = 0;
3853 HandleOtherEvents(&event);
3858 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3861 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
3862 new_joystick_xright = MAX(new_joystick_xright, joy_x);
3863 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
3864 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
3866 setup.input[player_nr].joy.xleft = new_joystick_xleft;
3867 setup.input[player_nr].joy.yupper = new_joystick_yupper;
3868 setup.input[player_nr].joy.xright = new_joystick_xright;
3869 setup.input[player_nr].joy.ylower = new_joystick_ylower;
3870 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
3871 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
3873 CheckJoystickData();
3875 joy_value = Joystick(player_nr);
3877 if (joy_value & JOY_BUTTON && check_remaining == 0)
3880 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
3881 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
3883 if (x != last_x || y != last_y)
3885 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
3886 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
3891 if (check_remaining > 0 && !check[x+1][y+1])
3893 check[x+1][y+1] = TRUE;
3899 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
3900 setup.input[player_nr].joy.xleft,
3901 setup.input[player_nr].joy.xmiddle,
3902 setup.input[player_nr].joy.xright);
3903 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
3904 setup.input[player_nr].joy.yupper,
3905 setup.input[player_nr].joy.ymiddle,
3906 setup.input[player_nr].joy.ylower);
3915 /* don't eat all CPU time */
3919 /* calibrated center position (joystick should now be centered) */
3920 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
3923 new_joystick_xmiddle = joy_x;
3924 new_joystick_ymiddle = joy_y;
3929 DrawSetupScreen_Input();
3932 /* wait until the last pressed button was released */
3933 while (Joystick(player_nr) & JOY_BUTTON)
3935 if (PendingEvent()) /* got event */
3940 HandleOtherEvents(&event);
3949 void CalibrateJoystick(int player_nr)
3951 if (!CalibrateJoystickMain(player_nr))
3953 char *device_name = setup.input[player_nr].joy.device_name;
3954 int nr = getJoystickNrFromDeviceName(device_name) + 1;
3955 int xpos = mSX - SX;
3956 int ypos = mSY - SY;
3960 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
3961 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
3964 Delay(2000); /* show error message for a short time */
3970 DrawSetupScreen_Input();
3974 void DrawSetupScreen()
3976 DeactivateJoystick();
3978 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
3980 if (setup_mode == SETUP_MODE_INPUT)
3981 DrawSetupScreen_Input();
3982 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3983 DrawChooseTree(&screen_mode_current);
3984 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
3985 DrawChooseTree(&artwork.gfx_current);
3986 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
3987 DrawChooseTree(&artwork.snd_current);
3988 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
3989 DrawChooseTree(&artwork.mus_current);
3991 DrawSetupScreen_Generic();
3997 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
3999 if (setup_mode == SETUP_MODE_INPUT)
4000 HandleSetupScreen_Input(mx, my, dx, dy, button);
4001 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
4002 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
4003 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
4004 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
4005 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
4006 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
4007 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
4008 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
4010 HandleSetupScreen_Generic(mx, my, dx, dy, button);
4015 void HandleGameActions()
4017 if (game_status != GAME_MODE_PLAYING)
4020 GameActions(); /* main game loop */
4022 if (tape.auto_play && !tape.playing)
4023 AutoPlayTape(); /* continue automatically playing next tape */
4027 /* ---------- new screen button stuff -------------------------------------- */
4029 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
4033 case SCREEN_CTRL_ID_LAST_LEVEL:
4034 *x = mSX + TILEX * getLastLevelButtonPos();
4035 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4038 case SCREEN_CTRL_ID_NEXT_LEVEL:
4039 *x = mSX + TILEX * getNextLevelButtonPos();
4040 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4043 case SCREEN_CTRL_ID_LAST_PLAYER:
4044 *x = mSX + TILEX * 10;
4045 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4048 case SCREEN_CTRL_ID_NEXT_PLAYER:
4049 *x = mSX + TILEX * 12;
4050 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4054 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
4060 int gfx_unpressed, gfx_pressed;
4061 void (*get_gadget_position)(int *, int *, int);
4065 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
4068 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
4069 getScreenMenuButtonPos,
4070 SCREEN_CTRL_ID_LAST_LEVEL,
4075 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
4076 getScreenMenuButtonPos,
4077 SCREEN_CTRL_ID_NEXT_LEVEL,
4082 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
4083 getScreenMenuButtonPos,
4084 SCREEN_CTRL_ID_LAST_PLAYER,
4089 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
4090 getScreenMenuButtonPos,
4091 SCREEN_CTRL_ID_NEXT_PLAYER,
4099 int gfx_unpressed, gfx_pressed;
4103 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
4106 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
4107 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
4108 SCREEN_CTRL_ID_SCROLL_UP,
4112 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
4113 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
4114 SCREEN_CTRL_ID_SCROLL_DOWN,
4121 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4122 Bitmap **gfx_unpressed, **gfx_pressed;
4124 int gfx_unpressed, gfx_pressed;
4131 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
4134 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4135 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
4137 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
4139 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
4140 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
4141 GD_TYPE_SCROLLBAR_VERTICAL,
4142 SCREEN_CTRL_ID_SCROLL_VERTICAL,
4143 "scroll level series vertically"
4147 static void CreateScreenMenubuttons()
4149 struct GadgetInfo *gi;
4150 unsigned long event_mask;
4153 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4155 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4156 int gfx_unpressed, gfx_pressed;
4157 int x, y, width, height;
4158 int gd_x1, gd_x2, gd_y1, gd_y2;
4159 int id = menubutton_info[i].gadget_id;
4161 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4163 menubutton_info[i].get_gadget_position(&x, &y, id);
4165 width = SC_MENUBUTTON_XSIZE;
4166 height = SC_MENUBUTTON_YSIZE;
4168 gfx_unpressed = menubutton_info[i].gfx_unpressed;
4169 gfx_pressed = menubutton_info[i].gfx_pressed;
4170 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4171 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4172 gd_x1 = graphic_info[gfx_unpressed].src_x;
4173 gd_y1 = graphic_info[gfx_unpressed].src_y;
4174 gd_x2 = graphic_info[gfx_pressed].src_x;
4175 gd_y2 = graphic_info[gfx_pressed].src_y;
4177 gi = CreateGadget(GDI_CUSTOM_ID, id,
4178 GDI_CUSTOM_TYPE_ID, i,
4179 GDI_INFO_TEXT, menubutton_info[i].infotext,
4184 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4185 GDI_STATE, GD_BUTTON_UNPRESSED,
4186 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4187 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4188 GDI_DIRECT_DRAW, FALSE,
4189 GDI_EVENT_MASK, event_mask,
4190 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4194 Error(ERR_EXIT, "cannot create gadget");
4196 screen_gadget[id] = gi;
4200 static void CreateScreenScrollbuttons()
4202 struct GadgetInfo *gi;
4203 unsigned long event_mask;
4206 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4208 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4209 int gfx_unpressed, gfx_pressed;
4210 int x, y, width, height;
4211 int gd_x1, gd_x2, gd_y1, gd_y2;
4212 int id = scrollbutton_info[i].gadget_id;
4214 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4216 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
4217 y = mSY + scrollbutton_info[i].y;
4218 width = SC_SCROLLBUTTON_XSIZE;
4219 height = SC_SCROLLBUTTON_YSIZE;
4221 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
4222 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
4223 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
4225 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
4226 gfx_pressed = scrollbutton_info[i].gfx_pressed;
4227 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4228 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4229 gd_x1 = graphic_info[gfx_unpressed].src_x;
4230 gd_y1 = graphic_info[gfx_unpressed].src_y;
4231 gd_x2 = graphic_info[gfx_pressed].src_x;
4232 gd_y2 = graphic_info[gfx_pressed].src_y;
4234 gi = CreateGadget(GDI_CUSTOM_ID, id,
4235 GDI_CUSTOM_TYPE_ID, i,
4236 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4241 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4242 GDI_STATE, GD_BUTTON_UNPRESSED,
4243 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4244 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4245 GDI_DIRECT_DRAW, FALSE,
4246 GDI_EVENT_MASK, event_mask,
4247 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4251 Error(ERR_EXIT, "cannot create gadget");
4253 screen_gadget[id] = gi;
4257 static void CreateScreenScrollbars()
4261 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4263 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4264 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4265 int gfx_unpressed, gfx_pressed;
4267 int x, y, width, height;
4268 int gd_x1, gd_x2, gd_y1, gd_y2;
4269 struct GadgetInfo *gi;
4270 int items_max, items_visible, item_position;
4271 unsigned long event_mask;
4272 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4273 int id = scrollbar_info[i].gadget_id;
4275 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
4277 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
4278 y = mSY + scrollbar_info[i].y;
4279 width = scrollbar_info[i].width;
4280 height = scrollbar_info[i].height;
4282 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
4283 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
4285 items_max = num_page_entries;
4286 items_visible = num_page_entries;
4289 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4290 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
4291 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
4297 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
4298 gfx_pressed = scrollbar_info[i].gfx_pressed;
4299 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4300 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4301 gd_x1 = graphic_info[gfx_unpressed].src_x;
4302 gd_y1 = graphic_info[gfx_unpressed].src_y;
4303 gd_x2 = graphic_info[gfx_pressed].src_x;
4304 gd_y2 = graphic_info[gfx_pressed].src_y;
4307 gi = CreateGadget(GDI_CUSTOM_ID, id,
4308 GDI_CUSTOM_TYPE_ID, i,
4309 GDI_INFO_TEXT, scrollbar_info[i].infotext,
4314 GDI_TYPE, scrollbar_info[i].type,
4315 GDI_SCROLLBAR_ITEMS_MAX, items_max,
4316 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
4317 GDI_SCROLLBAR_ITEM_POSITION, item_position,
4318 GDI_WHEEL_AREA_X, 0,
4319 GDI_WHEEL_AREA_Y, 0,
4320 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
4321 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
4322 GDI_STATE, GD_BUTTON_UNPRESSED,
4323 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4324 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4325 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
4326 GDI_DIRECT_DRAW, FALSE,
4327 GDI_EVENT_MASK, event_mask,
4328 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4332 Error(ERR_EXIT, "cannot create gadget");
4334 screen_gadget[id] = gi;
4338 void CreateScreenGadgets()
4340 int last_game_status = game_status; /* save current game status */
4342 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4345 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4347 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
4349 /* copy pointers to clip mask and GC */
4350 scrollbar_bitmap[i]->clip_mask =
4351 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
4352 scrollbar_bitmap[i]->stored_clip_gc =
4353 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
4355 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
4356 scrollbar_bitmap[i],
4357 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
4358 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
4359 TILEX, TILEY, 0, 0);
4363 CreateScreenMenubuttons();
4365 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
4366 game_status = GAME_MODE_LEVELS;
4368 CreateScreenScrollbuttons();
4369 CreateScreenScrollbars();
4371 game_status = last_game_status; /* restore current game status */
4374 void FreeScreenGadgets()
4378 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4379 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4381 /* prevent freeing clip mask and GC twice */
4382 scrollbar_bitmap[i]->clip_mask = None;
4383 scrollbar_bitmap[i]->stored_clip_gc = None;
4385 FreeBitmap(scrollbar_bitmap[i]);
4389 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
4390 FreeGadget(screen_gadget[i]);
4393 void MapScreenMenuGadgets(int screen_mask)
4397 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4398 if (screen_mask & menubutton_info[i].screen_mask)
4399 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
4402 void MapScreenTreeGadgets(TreeInfo *ti)
4404 int num_entries = numTreeInfoInGroup(ti);
4407 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4410 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4411 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
4413 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4414 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
4417 static void HandleScreenGadgets(struct GadgetInfo *gi)
4419 int id = gi->custom_id;
4420 int button = gi->event.button;
4421 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4424 if (game_status != GAME_MODE_LEVELS && game_status != GAME_MODE_SETUP)
4430 case SCREEN_CTRL_ID_LAST_LEVEL:
4431 HandleMainMenu_SelectLevel(step, -1);
4434 case SCREEN_CTRL_ID_NEXT_LEVEL:
4435 HandleMainMenu_SelectLevel(step, +1);
4438 case SCREEN_CTRL_ID_LAST_PLAYER:
4439 HandleSetupScreen_Input_Player(step, -1);
4442 case SCREEN_CTRL_ID_NEXT_PLAYER:
4443 HandleSetupScreen_Input_Player(step, +1);
4446 case SCREEN_CTRL_ID_SCROLL_UP:
4447 if (game_status == GAME_MODE_LEVELS)
4448 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4449 else if (game_status == GAME_MODE_SETUP)
4450 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
4453 case SCREEN_CTRL_ID_SCROLL_DOWN:
4454 if (game_status == GAME_MODE_LEVELS)
4455 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4456 else if (game_status == GAME_MODE_SETUP)
4457 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
4460 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
4461 if (game_status == GAME_MODE_LEVELS)
4462 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
4463 else if (game_status == GAME_MODE_SETUP)
4464 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);