1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 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_PREV_LEVEL 0
76 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
77 #define SCREEN_CTRL_ID_PREV_PLAYER 2
78 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
79 #define SCREEN_CTRL_ID_SCROLL_UP 4
80 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
81 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
83 #define NUM_SCREEN_GADGETS 7
85 #define NUM_SCREEN_MENUBUTTONS 4
86 #define NUM_SCREEN_SCROLLBUTTONS 2
87 #define NUM_SCREEN_SCROLLBARS 1
89 #define SCREEN_MASK_MAIN (1 << 0)
90 #define SCREEN_MASK_INPUT (1 << 1)
92 /* graphic position and size values for buttons and scrollbars */
93 #define SC_MENUBUTTON_XSIZE TILEX
94 #define SC_MENUBUTTON_YSIZE TILEY
96 #define SC_SCROLLBUTTON_XSIZE TILEX
97 #define SC_SCROLLBUTTON_YSIZE TILEY
99 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
101 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
102 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
103 SC_SCROLLBUTTON_YSIZE)
105 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
106 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
108 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
109 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
110 SC_SCROLLBUTTON_YSIZE)
112 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
113 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
114 SC_SCROLL_VERTICAL_YSIZE)
116 #define SC_BORDER_SIZE 14
118 /* other useful macro definitions */
119 #define BUTTON_GRAPHIC_ACTIVE(g) \
120 (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE : \
121 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE : \
122 g == IMG_MENU_BUTTON_UP ? IMG_MENU_BUTTON_UP_ACTIVE : \
123 g == IMG_MENU_BUTTON_DOWN ? IMG_MENU_BUTTON_DOWN_ACTIVE : \
124 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE : \
125 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE : \
126 g == IMG_MENU_BUTTON_PREV_LEVEL ? IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE : \
127 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE : \
128 IMG_MENU_BUTTON_ACTIVE)
131 /* forward declarations of internal functions */
132 static void HandleScreenGadgets(struct GadgetInfo *);
133 static void HandleSetupScreen_Generic(int, int, int, int, int);
134 static void HandleSetupScreen_Input(int, int, int, int, int);
135 static void CustomizeKeyboard(int);
136 static void CalibrateJoystick(int);
137 static void execSetupGraphics(void);
138 static void execSetupArtwork(void);
139 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
141 static void DrawChooseLevel(void);
142 static void DrawInfoScreen(void);
143 static void DrawAndFadeInInfoScreen(int);
144 static void DrawSetupScreen(void);
146 static void DrawInfoScreenExt(int, int);
147 static void DrawInfoScreen_NotAvailable(char *, char *);
148 static void DrawInfoScreen_HelpAnim(int, int, boolean);
149 static void DrawInfoScreen_HelpText(int, int, int, int);
150 static void HandleInfoScreen_Main(int, int, int, int, int);
151 static void HandleInfoScreen_TitleScreen(int);
152 static void HandleInfoScreen_Elements(int);
153 static void HandleInfoScreen_Music(int);
154 static void HandleInfoScreen_Credits(int);
155 static void HandleInfoScreen_Program(int);
157 static void MapScreenMenuGadgets(int);
158 static void MapScreenTreeGadgets(TreeInfo *);
160 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
162 static boolean show_titlescreen_initial = TRUE;
164 static int setup_mode = SETUP_MODE_MAIN;
165 static int info_mode = INFO_MODE_MAIN;
167 static TreeInfo *screen_modes = NULL;
168 static TreeInfo *screen_mode_current = NULL;
170 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
171 (s) <= GAME_MODE_SETUP ? (s) : \
172 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
173 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
175 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
176 (i) <= INFO_MODE_LEVELSET ? (i) : \
179 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
180 menu.draw_xoffset[GAME_MODE_INFO] : \
181 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
182 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
183 menu.draw_yoffset[GAME_MODE_INFO] : \
184 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
186 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
187 DRAW_XOFFSET_INFO(info_mode) : \
188 menu.draw_xoffset[DRAW_MODE(s)])
189 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
190 DRAW_YOFFSET_INFO(info_mode) : \
191 menu.draw_yoffset[DRAW_MODE(s)])
193 #define mSX (SX + DRAW_XOFFSET(game_status))
194 #define mSY (SY + DRAW_YOFFSET(game_status))
196 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
197 menu.list_size[game_status] : \
198 MAX_MENU_ENTRIES_ON_SCREEN)
200 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
201 #define NUM_SCROLLBAR_BITMAPS 2
202 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
206 #define MAIN_CONTROL_NAME 0
207 #define MAIN_CONTROL_LEVELS 1
208 #define MAIN_CONTROL_SCORES 2
209 #define MAIN_CONTROL_EDITOR 3
210 #define MAIN_CONTROL_INFO 4
211 #define MAIN_CONTROL_GAME 5
212 #define MAIN_CONTROL_SETUP 6
213 #define MAIN_CONTROL_QUIT 7
214 #define MAIN_CONTROL_PREV_LEVEL 8
215 #define MAIN_CONTROL_NEXT_LEVEL 9
216 #define MAIN_CONTROL_CURRENT_LEVEL 10
217 #define MAIN_CONTROL_FIRST_LEVEL 11
218 #define MAIN_CONTROL_LAST_LEVEL 12
219 #define MAIN_CONTROL_LEVEL_INFO_1 13
220 #define MAIN_CONTROL_LEVEL_INFO_2 14
221 #define MAIN_CONTROL_TITLE_1 15
222 #define MAIN_CONTROL_TITLE_2 16
223 #define MAIN_CONTROL_TITLE_3 17
225 static char main_text_name[10];
226 static char main_text_current_level[10];
227 static char main_text_first_level[10];
228 static char main_text_last_level[10];
229 static char main_input_name[MAX_PLAYER_NAME_LEN + 1];
231 struct MainControlInfo
235 struct MenuPosInfo *pos_button;
238 struct MenuPosInfo *pos_text;
242 struct MenuPosInfo *pos_input;
247 static struct MainControlInfo main_controls[] =
251 &menu.main.button.name, IMG_MENU_BUTTON,
252 &menu.main.text.name, main_text_name, FONT_MENU_1,
253 &menu.main.input.name, main_input_name, FONT_INPUT_1,
257 &menu.main.button.levels, IMG_MENU_BUTTON_ENTER_MENU,
258 &menu.main.text.levels, "Levelset", FONT_MENU_1,
263 &menu.main.button.scores, IMG_MENU_BUTTON,
264 &menu.main.text.scores, "Hall Of Fame", FONT_MENU_1,
269 &menu.main.button.editor, IMG_MENU_BUTTON,
270 &menu.main.text.editor, "Level Creator", FONT_MENU_1,
275 &menu.main.button.info, IMG_MENU_BUTTON_ENTER_MENU,
276 &menu.main.text.info, "Info Screen", FONT_MENU_1,
281 &menu.main.button.game, IMG_MENU_BUTTON,
282 &menu.main.text.game, "Start Game", FONT_MENU_1,
287 &menu.main.button.setup, IMG_MENU_BUTTON_ENTER_MENU,
288 &menu.main.text.setup, "Setup", FONT_MENU_1,
293 &menu.main.button.quit, IMG_MENU_BUTTON,
294 &menu.main.text.quit, "Quit", FONT_MENU_1,
298 /* (these two buttons are real gadgets) */
300 MAIN_CONTROL_PREV_LEVEL,
301 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
306 MAIN_CONTROL_NEXT_LEVEL,
307 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
313 MAIN_CONTROL_CURRENT_LEVEL,
315 &menu.main.text.current_level, main_text_current_level,FONT_VALUE_1,
319 MAIN_CONTROL_FIRST_LEVEL,
321 &menu.main.text.first_level, main_text_first_level, FONT_TEXT_3,
325 MAIN_CONTROL_LAST_LEVEL,
327 &menu.main.text.last_level, main_text_last_level, FONT_TEXT_3,
331 MAIN_CONTROL_LEVEL_INFO_1,
333 &menu.main.text.level_info_1, NULL, -1,
337 MAIN_CONTROL_LEVEL_INFO_2,
339 &menu.main.text.level_info_2, NULL, -1,
343 MAIN_CONTROL_TITLE_1,
345 &menu.main.text.title_1, PROGRAM_TITLE_STRING, FONT_TITLE_1,
349 MAIN_CONTROL_TITLE_2,
351 &menu.main.text.title_2, PROGRAM_COPYRIGHT_STRING, FONT_TITLE_2,
355 MAIN_CONTROL_TITLE_3,
357 &menu.main.text.title_3, PROGRAM_GAME_BY_STRING, FONT_TITLE_2,
370 static void InitializeMainControls()
372 boolean local_team_mode = (!options.network && setup.team_mode);
375 /* set main control text values to dynamically determined values */
376 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
377 sprintf(main_text_current_level, "%s", int2str(level_nr, 3));
378 sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
379 sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
380 sprintf(main_input_name, "%s", setup.player_name);
382 /* set main control screen positions to dynamically determined values */
383 for (i = 0; main_controls[i].nr != -1; i++)
385 struct MainControlInfo *mci = &main_controls[i];
387 struct MenuPosInfo *pos_button = mci->pos_button;
388 struct MenuPosInfo *pos_text = mci->pos_text;
389 struct MenuPosInfo *pos_input = mci->pos_input;
390 char *text = mci->text;
391 char *input = mci->input;
392 int button_graphic = mci->button_graphic;
393 int font_text = mci->font_text;
394 int font_input = mci->font_input;
396 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
397 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
398 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
399 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
400 int text_chars = (text != NULL ? strlen(text) : 0);
401 int input_chars = (input != NULL ? strlen(input) : 0);
404 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
406 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
407 int text_width = font_text_width * text_chars;
408 int text_height = font_text_height;
409 int input_width = font_input_width * input_chars;
410 int input_height = font_input_height;
412 if (nr == MAIN_CONTROL_NAME)
415 if (menu.main.input.name.x == -1)
416 menu.main.input.name.x = menu.main.text.name.x + text_width;
417 if (menu.main.input.name.y == -1)
418 menu.main.input.name.y = menu.main.text.name.y;
421 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
422 menu.main.input.name.height = font_input_height;
425 if (pos_button != NULL)
427 if (pos_button->width == 0)
428 pos_button->width = button_width;
429 if (pos_button->height == 0)
430 pos_button->height = button_height;
433 if (pos_text != NULL)
435 /* calculate width for non-clickable text -- needed for text alignment */
436 boolean calculate_text_width = (pos_button == NULL && text != NULL);
438 if (pos_text->x == -1 && pos_button != NULL)
439 pos_text->x = pos_button->x + pos_button->width;
440 if (pos_text->y == -1 && pos_button != NULL)
441 pos_text->y = pos_button->y;
443 if (pos_text->width == -1 || calculate_text_width)
444 pos_text->width = text_width;
445 if (pos_text->height == -1)
446 pos_text->height = text_height;
449 if (pos_input != NULL)
451 if (pos_input->x == -1 && pos_text != NULL)
452 pos_input->x = pos_text->x + pos_text->width;
453 if (pos_input->y == -1 && pos_text != NULL)
454 pos_input->y = pos_text->y;
456 if (pos_input->width == -1)
457 pos_input->width = input_width;
458 if (pos_input->height == -1)
459 pos_input->height = input_height;
464 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
465 boolean active_input)
469 for (i = 0; main_controls[i].nr != -1; i++)
471 struct MainControlInfo *mci = &main_controls[i];
473 if (mci->nr == nr || nr == -1)
475 struct MenuPosInfo *pos_button = mci->pos_button;
476 struct MenuPosInfo *pos_text = mci->pos_text;
477 struct MenuPosInfo *pos_input = mci->pos_input;
478 char *text = mci->text;
479 char *input = mci->input;
480 int button_graphic = mci->button_graphic;
481 int font_text = mci->font_text;
482 int font_input = mci->font_input;
486 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
487 font_text = FONT_ACTIVE(font_text);
492 font_input = FONT_ACTIVE(font_input);
495 if (pos_button != NULL)
497 struct MenuPosInfo *pos = pos_button;
498 int x = mSX + pos->x;
499 int y = mSY + pos->y;
501 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
502 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
505 if (pos_text != NULL && text != NULL)
507 struct MenuPosInfo *pos = pos_text;
508 int x = mSX + ALIGNED_XPOS(pos->x, pos->width, pos->align);
509 int y = mSY + pos->y;
511 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
512 DrawText(x, y, text, font_text);
515 if (pos_input != NULL && input != NULL)
517 struct MenuPosInfo *pos = pos_input;
518 int x = mSX + ALIGNED_XPOS(pos->x, pos->width, pos->align);
519 int y = mSY + pos->y;
521 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
522 DrawText(x, y, input, font_input);
528 static void DrawCursorAndText_Main(int nr, boolean active_text)
530 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
534 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
536 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
540 static struct MainControlInfo *getMainControlInfo(int nr)
544 for (i = 0; main_controls[i].nr != -1; i++)
545 if (main_controls[i].nr == nr)
546 return &main_controls[i];
551 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
556 int rect_x = ALIGNED_XPOS(rect->x, rect->width, rect->align);
557 int rect_y = rect->y;
559 return (x >= rect_x && x < rect_x + rect->width &&
560 y >= rect_y && y < rect_y + rect->height);
563 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
565 static int cursor_array[SCR_FIELDY];
566 int x = mSX + TILEX * xpos;
567 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
572 cursor_array[ypos] = graphic;
574 graphic = cursor_array[ypos];
578 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
580 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
581 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
584 static void initCursor(int ypos, int graphic)
586 drawCursorExt(0, ypos, FALSE, graphic);
589 static void drawCursor(int ypos, boolean active)
591 drawCursorExt(0, ypos, active, -1);
594 static void drawCursorXY(int xpos, int ypos, int graphic)
596 drawCursorExt(xpos, ypos, FALSE, graphic);
599 static void drawChooseTreeCursor(int ypos, boolean active)
601 int last_game_status = game_status; /* save current game status */
603 /* force LEVELS draw offset on artwork setup screen */
604 game_status = GAME_MODE_LEVELS;
606 drawCursorExt(0, ypos, active, -1);
608 game_status = last_game_status; /* restore current game status */
613 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
614 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
618 static int getPrevlevelButtonPos()
623 static int getCurrentLevelTextPos()
625 return (getPrevlevelButtonPos() + 1);
628 static int getNextLevelButtonPos()
630 return getPrevlevelButtonPos() + 3 + 1;
633 static int getLevelRangeTextPos()
635 return getNextLevelButtonPos() + 1;
639 static int getTitleScreenGraphic()
641 return (show_titlescreen_initial ? IMG_TITLESCREEN_INITIAL_1 :
645 int effectiveGameStatus()
647 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
648 return GAME_MODE_TITLE;
653 void DrawTitleScreenImage(int nr)
655 int graphic = getTitleScreenGraphic() + nr;
656 Bitmap *bitmap = graphic_info[graphic].bitmap;
658 int width = graphic_info[graphic].width;
659 int height = graphic_info[graphic].height;
660 int src_x = graphic_info[graphic].src_x;
661 int src_y = graphic_info[graphic].src_y;
663 int width = graphic_info[graphic].src_image_width;
664 int height = graphic_info[graphic].src_image_height;
665 int src_x = 0, src_y = 0;
672 if (width > WIN_XSIZE)
674 /* image width too large for window => center image horizontally */
675 src_x = (width - WIN_XSIZE) / 2;
679 if (height > WIN_YSIZE)
681 /* image height too large for window => center image vertically */
682 src_y = (height - WIN_YSIZE) / 2;
686 dst_x = (WIN_XSIZE - width) / 2;
687 dst_y = (WIN_YSIZE - height) / 2;
689 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
691 if (DrawingOnBackground(dst_x, dst_y))
692 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
694 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
696 redraw_mask = REDRAW_ALL;
698 /* reset fading control values to default config settings */
699 title.fade_delay_final = title.fade_delay;
700 title.post_delay_final = title.post_delay;
701 title.auto_delay_final = title.auto_delay;
703 /* override default settings with image config settings, if defined */
704 if (graphic_info[graphic].fade_delay > -1)
705 title.fade_delay_final = graphic_info[graphic].fade_delay;
706 if (graphic_info[graphic].post_delay > -1)
707 title.post_delay_final = graphic_info[graphic].post_delay;
708 if (graphic_info[graphic].auto_delay > -1)
709 title.auto_delay_final = graphic_info[graphic].auto_delay;
712 void DrawTitleScreen()
714 KeyboardAutoRepeatOff();
716 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
718 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
723 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
725 static LevelDirTree *leveldir_last_valid = NULL;
726 boolean levelset_has_changed = FALSE;
728 boolean local_team_mode = (!options.network && setup.team_mode);
729 char *name_text = (local_team_mode ? "Team:" : "Name:");
730 int name_width, level_width;
737 FadeSoundsAndMusic();
739 KeyboardAutoRepeatOn();
742 SetDrawDeactivationMask(REDRAW_NONE);
743 SetDrawBackgroundMask(REDRAW_FIELD);
745 audio.sound_deactivated = FALSE;
749 /* needed if last screen was the playing screen, invoked from level editor */
750 if (level_editor_test_game)
752 game_status = GAME_MODE_EDITOR;
758 /* needed if last screen was the editor screen */
759 UndrawSpecialEditorDoor();
761 /* needed if last screen was the setup screen and fullscreen state changed */
762 ToggleFullscreenIfNeeded();
764 /* leveldir_current may be invalid (level group, parent link) */
765 if (!validLevelSeries(leveldir_current))
766 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
768 if (leveldir_current != leveldir_last_valid)
769 levelset_has_changed = TRUE;
771 /* store valid level series information */
772 leveldir_last_valid = leveldir_current;
774 /* needed if last screen (level choice) changed graphics, sounds or music */
775 ReloadCustomArtwork(0);
778 SetDrawtoField(DRAW_BACKBUFFER);
781 if (setup.show_titlescreen &&
782 ((levelset_has_changed &&
783 graphic_info[IMG_TITLESCREEN_1].bitmap != NULL) ||
784 (show_titlescreen_initial &&
785 graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL)))
787 game_status = GAME_MODE_TITLE;
794 /* level_nr may have been set to value over handicap with level editor */
795 if (setup.handicap && level_nr > leveldir_current->handicap_level)
796 level_nr = leveldir_current->handicap_level;
800 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
804 InitializeMainControls();
807 DrawCursorAndText_Main(-1, FALSE);
809 for (i = 0; main_controls[i].nr != -1; i++)
811 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
812 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
813 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
814 char *text = main_controls[i].text;
815 char *input = main_controls[i].input;
816 int button_graphic = main_controls[i].button_graphic;
817 int font_text = main_controls[i].font_text;
818 int font_input = main_controls[i].font_input;
820 if (pos_button != NULL)
821 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
824 if (pos_text != NULL && text != NULL)
825 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
827 if (pos_input != NULL && input != NULL)
828 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
836 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
837 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
838 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
839 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
840 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
841 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
842 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
843 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
845 /* calculated after (possible) reload of custom artwork */
846 name_width = getTextWidth(name_text, FONT_MENU_1);
847 level_width = 9 * 32;
849 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
852 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
853 int2str(level_nr, 3), FONT_VALUE_1);
856 int text_height = getFontHeight(FONT_TEXT_3);
857 int xpos = getLevelRangeTextPos() * 32 + 8;
858 int ypos2 = 3 * 32 + 16;
859 int ypos1 = ypos2 - text_height;
861 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
862 "%03d", leveldir_current->first_level);
863 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
864 "%03d", leveldir_current->last_level);
867 for (i = 0; i < 8; i++)
868 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
871 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
874 DrawPreviewLevel(TRUE);
876 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
879 if (TAPE_IS_EMPTY(tape))
881 DrawCompleteVideoDisplay();
886 /* create gadgets for main menu screen */
888 CreateScreenGadgets();
890 /* map gadgets for main menu screen */
892 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
894 DrawMaskedBorder(REDRAW_ALL);
903 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
906 void DrawAndFadeInMainMenu(int redraw_mask)
908 DrawMainMenuExt(redraw_mask, TRUE);
913 DrawMainMenuExt(REDRAW_ALL, FALSE);
917 static void gotoTopLevelDir()
919 /* move upwards to top level directory */
920 while (leveldir_current->node_parent)
922 /* write a "path" into level tree for easy navigation to last level */
923 if (leveldir_current->node_parent->node_group->cl_first == -1)
925 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
926 int leveldir_pos = posTreeInfo(leveldir_current);
927 int num_page_entries;
928 int cl_first, cl_cursor;
930 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
931 num_page_entries = num_leveldirs;
933 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
935 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
936 cl_cursor = leveldir_pos - cl_first;
938 leveldir_current->node_parent->node_group->cl_first = cl_first;
939 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
942 leveldir_current = leveldir_current->node_parent;
947 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
949 static unsigned long title_delay = 0;
950 static int title_nr = 0;
951 boolean return_to_main_menu = FALSE;
952 boolean use_fading_main_menu = TRUE;
953 boolean use_cross_fading = !show_titlescreen_initial; /* default */
955 if (button == MB_MENU_INITIALIZE)
957 int last_game_status = game_status; /* save current game status */
962 if (show_titlescreen_initial &&
963 graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap == NULL)
964 show_titlescreen_initial = FALSE;
966 if (game_status == GAME_MODE_INFO)
968 if (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
970 DrawInfoScreen_NotAvailable("Title screen information:",
971 "No title screen for this level set.");
973 title.auto_delay_final = -1;
978 FadeSoundsAndMusic();
983 /* force TITLE music on title info screen */
984 game_status = GAME_MODE_TITLE;
989 game_status = last_game_status; /* restore current game status */
991 DrawTitleScreenImage(title_nr);
995 DelayReached(&title_delay, 0); /* reset delay counter */
1000 if (title.auto_delay_final > -1 &&
1001 DelayReached(&title_delay, title.auto_delay_final))
1002 button = MB_MENU_CHOICE;
1004 if (button == MB_MENU_LEAVE)
1006 return_to_main_menu = TRUE;
1007 use_fading_main_menu = FALSE;
1009 else if (button == MB_MENU_CHOICE)
1013 if (game_status == GAME_MODE_INFO &&
1014 graphic_info[IMG_TITLESCREEN_1].bitmap == NULL)
1016 FadeOut(REDRAW_FIELD);
1018 info_mode = INFO_MODE_MAIN;
1019 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1026 if (show_titlescreen_initial &&
1027 (title_nr >= MAX_NUM_TITLE_SCREENS ||
1028 graphic_info[IMG_TITLESCREEN_INITIAL_1 + title_nr].bitmap == NULL))
1030 show_titlescreen_initial = FALSE;
1032 title_nr = 0; /* restart with title screens for current level set */
1035 anim_mode = graphic_info[getTitleScreenGraphic() + title_nr].anim_mode;
1037 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1038 anim_mode == ANIM_CROSSFADE ? TRUE :
1041 if (!use_cross_fading)
1042 FadeOut(REDRAW_ALL);
1044 if (title_nr < MAX_NUM_TITLE_SCREENS &&
1045 graphic_info[getTitleScreenGraphic() + title_nr].bitmap != NULL)
1047 if (use_cross_fading)
1048 FadeCrossSaveBackbuffer();
1050 DrawTitleScreenImage(title_nr);
1052 if (use_cross_fading)
1053 FadeCross(REDRAW_ALL);
1057 DelayReached(&title_delay, 0); /* reset delay counter */
1061 FadeSoundsAndMusic();
1063 FadeOut(REDRAW_ALL);
1065 return_to_main_menu = TRUE;
1069 if (return_to_main_menu)
1071 show_titlescreen_initial = FALSE;
1075 if (game_status == GAME_MODE_INFO)
1077 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1079 info_mode = INFO_MODE_MAIN;
1080 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1082 else /* default: return to main menu */
1084 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1086 game_status = GAME_MODE_MAIN;
1087 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1092 void HandleMainMenu_SelectLevel(int step, int direction)
1094 int old_level_nr = level_nr;
1097 new_level_nr = old_level_nr + step * direction;
1098 if (new_level_nr < leveldir_current->first_level)
1099 new_level_nr = leveldir_current->first_level;
1100 if (new_level_nr > leveldir_current->last_level)
1101 new_level_nr = leveldir_current->last_level;
1103 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1105 /* skipping levels is only allowed when trying to skip single level */
1106 if (setup.skip_levels && step == 1 &&
1107 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1109 leveldir_current->handicap_level++;
1110 SaveLevelSetup_SeriesInfo();
1113 new_level_nr = leveldir_current->handicap_level;
1116 if (new_level_nr != old_level_nr)
1118 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_CURRENT_LEVEL);
1120 PlaySound(SND_MENU_ITEM_SELECTING);
1122 level_nr = new_level_nr;
1125 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1126 int2str(level_nr, 3), mci->font_text);
1128 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1131 LoadLevel(level_nr);
1132 DrawPreviewLevel(TRUE);
1136 DrawCompleteVideoDisplay();
1138 /* needed because DrawPreviewLevel() takes some time */
1146 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1148 static int choice = MAIN_CONTROL_GAME;
1152 if (button == MB_MENU_INITIALIZE)
1154 DrawCursorAndText_Main(choice, TRUE);
1159 if (mx || my) /* mouse input */
1163 for (i = 0; main_controls[i].nr != -1; i++)
1165 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1166 insideMenuPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1167 insideMenuPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1169 pos = main_controls[i].nr;
1175 else if (dx || dy) /* keyboard input */
1177 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1178 choice == MAIN_CONTROL_SETUP))
1179 button = MB_MENU_CHOICE;
1184 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1186 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1188 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1194 PlaySound(SND_MENU_ITEM_ACTIVATING);
1196 DrawCursorAndText_Main(choice, FALSE);
1197 DrawCursorAndText_Main(pos, TRUE);
1204 PlaySound(SND_MENU_ITEM_SELECTING);
1206 if (pos == MAIN_CONTROL_NAME)
1208 game_status = GAME_MODE_PSEUDO_TYPENAME;
1210 HandleTypeName(strlen(setup.player_name), 0);
1212 else if (pos == MAIN_CONTROL_LEVELS)
1216 game_status = GAME_MODE_LEVELS;
1218 SaveLevelSetup_LastSeries();
1219 SaveLevelSetup_SeriesInfo();
1228 else if (pos == MAIN_CONTROL_SCORES)
1230 game_status = GAME_MODE_SCORES;
1234 else if (pos == MAIN_CONTROL_EDITOR)
1236 if (leveldir_current->readonly &&
1237 !strEqual(setup.player_name, "Artsoft"))
1238 Request("This level is read only !", REQ_CONFIRM);
1240 game_status = GAME_MODE_EDITOR;
1244 else if (pos == MAIN_CONTROL_INFO)
1246 game_status = GAME_MODE_INFO;
1247 info_mode = INFO_MODE_MAIN;
1251 else if (pos == MAIN_CONTROL_GAME)
1253 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1255 else if (pos == MAIN_CONTROL_SETUP)
1257 game_status = GAME_MODE_SETUP;
1258 setup_mode = SETUP_MODE_MAIN;
1262 else if (pos == MAIN_CONTROL_QUIT)
1264 SaveLevelSetup_LastSeries();
1265 SaveLevelSetup_SeriesInfo();
1267 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1268 game_status = GAME_MODE_QUIT;
1273 if (game_status == GAME_MODE_MAIN)
1275 DrawPreviewLevel(FALSE);
1282 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1284 static int choice = 5;
1288 if (button == MB_MENU_INITIALIZE)
1290 drawCursor(choice, TRUE);
1295 if (mx || my) /* mouse input */
1297 x = (mx - mSX) / 32;
1298 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1300 else if (dx || dy) /* keyboard input */
1302 if (dx && choice == 1)
1303 x = (dx < 0 ? 10 : 14);
1306 if (choice == 4 || choice == 6)
1307 button = MB_MENU_CHOICE;
1313 if (y == 1 && dx != 0 && button)
1315 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1317 else if (IN_VIS_FIELD(x, y) &&
1318 y >= 0 && y <= 7 && (y != 1 || x < 10))
1324 drawCursor(choice, FALSE);
1325 drawCursor(y, TRUE);
1334 game_status = GAME_MODE_PSEUDO_TYPENAME;
1335 HandleTypeName(strlen(setup.player_name), 0);
1341 game_status = GAME_MODE_LEVELS;
1342 SaveLevelSetup_LastSeries();
1343 SaveLevelSetup_SeriesInfo();
1354 game_status = GAME_MODE_SCORES;
1359 if (leveldir_current->readonly &&
1360 !strEqual(setup.player_name, "Artsoft"))
1361 Request("This level is read only !", REQ_CONFIRM);
1362 game_status = GAME_MODE_EDITOR;
1367 game_status = GAME_MODE_INFO;
1368 info_mode = INFO_MODE_MAIN;
1373 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1377 game_status = GAME_MODE_SETUP;
1378 setup_mode = SETUP_MODE_MAIN;
1384 SaveLevelSetup_LastSeries();
1385 SaveLevelSetup_SeriesInfo();
1387 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1388 game_status = GAME_MODE_QUIT;
1393 if (game_status == GAME_MODE_MAIN)
1395 DrawPreviewLevel(FALSE);
1403 /* ========================================================================= */
1404 /* info screen functions */
1405 /* ========================================================================= */
1407 static struct TokenInfo *info_info;
1408 static int num_info_info;
1410 static void execInfoTitleScreen()
1412 info_mode = INFO_MODE_TITLE;
1416 static void execInfoElements()
1418 info_mode = INFO_MODE_ELEMENTS;
1422 static void execInfoMusic()
1424 info_mode = INFO_MODE_MUSIC;
1428 static void execInfoCredits()
1430 info_mode = INFO_MODE_CREDITS;
1434 static void execInfoProgram()
1436 info_mode = INFO_MODE_PROGRAM;
1440 static void execInfoLevelSet()
1442 info_mode = INFO_MODE_LEVELSET;
1446 static void execExitInfo()
1448 game_status = GAME_MODE_MAIN;
1452 static struct TokenInfo info_info_main[] =
1454 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1455 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1456 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1457 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1458 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1459 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1460 { TYPE_EMPTY, NULL, "" },
1461 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1466 static void DrawCursorAndText_Info(int pos, boolean active)
1468 int xpos = MENU_SCREEN_START_XPOS;
1469 int ypos = MENU_SCREEN_START_YPOS + pos;
1470 int font_nr = FONT_MENU_1;
1473 font_nr = FONT_ACTIVE(font_nr);
1475 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1477 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1478 drawCursor(pos, active);
1481 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
1486 CloseDoor(DOOR_CLOSE_2);
1490 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1492 info_info = info_info_main;
1495 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1498 int xpos = MENU_SCREEN_START_XPOS;
1499 int ypos = MENU_SCREEN_START_YPOS + i;
1500 int font_nr = FONT_MENU_1;
1503 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1504 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1505 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1506 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1507 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1508 initCursor(i, IMG_MENU_BUTTON);
1511 DrawCursorAndText_Info(i, FALSE);
1513 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
1519 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1524 DrawMaskedBorder(REDRAW_ALL);
1527 FadeIn(redraw_mask);
1534 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1536 static int choice_store[MAX_INFO_MODES];
1537 int choice = choice_store[info_mode]; /* always starts with 0 */
1541 if (button == MB_MENU_INITIALIZE)
1543 /* advance to first valid menu entry */
1544 while (choice < num_info_info &&
1545 info_info[choice].type & TYPE_SKIP_ENTRY)
1547 choice_store[info_mode] = choice;
1550 DrawCursorAndText_Info(choice, TRUE);
1552 drawCursor(choice, TRUE);
1557 else if (button == MB_MENU_LEAVE)
1559 for (y = 0; y < num_info_info; y++)
1561 if (info_info[y].type & TYPE_LEAVE_MENU)
1563 void (*menu_callback_function)(void) = info_info[y].value;
1565 menu_callback_function();
1567 break; /* absolutely needed because function changes 'info_info'! */
1574 if (mx || my) /* mouse input */
1576 x = (mx - mSX) / 32;
1577 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1579 else if (dx || dy) /* keyboard input */
1583 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
1585 if (info_info[choice].type & menu_navigation_type ||
1586 info_info[choice].type & TYPE_ENTER_SCREEN ||
1587 info_info[choice].type & TYPE_BOOLEAN_STYLE)
1588 button = MB_MENU_CHOICE;
1593 /* jump to next non-empty menu entry (up or down) */
1594 while (y > 0 && y < num_info_info - 1 &&
1595 info_info[y].type & TYPE_SKIP_ENTRY)
1599 if (IN_VIS_FIELD(x, y) &&
1600 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
1606 PlaySound(SND_MENU_ITEM_ACTIVATING);
1609 DrawCursorAndText_Info(choice, FALSE);
1610 DrawCursorAndText_Info(y, TRUE);
1612 drawCursor(choice, FALSE);
1613 drawCursor(y, TRUE);
1616 choice = choice_store[info_mode] = y;
1619 else if (!(info_info[y].type & TYPE_GHOSTED))
1621 PlaySound(SND_MENU_ITEM_SELECTING);
1623 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
1625 void (*menu_callback_function)(void) = info_info[choice].value;
1627 menu_callback_function();
1633 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
1637 int ybottom = SYSIZE - 20;
1639 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
1641 FadeOut(REDRAW_FIELD);
1646 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
1647 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
1649 DrawTextSCentered(ybottom, FONT_TEXT_4,
1650 "Press any key or button for info menu");
1652 FadeIn(REDRAW_FIELD);
1655 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
1657 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
1658 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
1659 int xstart = mSX + 16;
1660 int ystart = mSY + 64 + 2 * 32;
1661 int ystep = TILEY + 4;
1662 int element, action, direction;
1670 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
1671 infoscreen_step[i] = infoscreen_frame[i] = 0;
1676 DrawTextSCentered(100, FONT_TEXT_1, "The Game Elements:");
1678 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
1679 "Press any key or button for next page");
1685 while (helpanim_info[j].element != HELPANIM_LIST_END)
1687 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
1692 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1701 j += infoscreen_step[i - start];
1703 element = helpanim_info[j].element;
1704 action = helpanim_info[j].action;
1705 direction = helpanim_info[j].direction;
1708 element = EL_UNKNOWN;
1710 if (action != -1 && direction != -1)
1711 graphic = el_act_dir2img(element, action, direction);
1712 else if (action != -1)
1713 graphic = el_act2img(element, action);
1714 else if (direction != -1)
1715 graphic = el_dir2img(element, direction);
1717 graphic = el2img(element);
1719 delay = helpanim_info[j++].delay;
1724 if (infoscreen_frame[i - start] == 0)
1727 infoscreen_frame[i - start] = delay - 1;
1731 sync_frame = delay - infoscreen_frame[i - start];
1732 infoscreen_frame[i - start]--;
1735 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
1737 if (!infoscreen_frame[i - start])
1738 infoscreen_step[i - start] = 0;
1742 if (!infoscreen_frame[i - start])
1743 infoscreen_step[i - start]++;
1744 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
1750 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
1752 DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
1753 graphic, sync_frame, USE_MASKING);
1756 DrawInfoScreen_HelpText(element, action, direction, i - start);
1761 redraw_mask |= REDRAW_FIELD;
1766 static char *getHelpText(int element, int action, int direction)
1768 char token[MAX_LINE_LEN];
1770 strcpy(token, element_info[element].token_name);
1773 strcat(token, element_action_info[action].suffix);
1775 if (direction != -1)
1776 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
1778 return getHashEntry(helptext_info, token);
1781 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
1783 int font_nr = FONT_LEVEL_NUMBER;
1784 int font_width = getFontWidth(font_nr);
1785 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
1786 int sy = mSY + 65 + 2 * 32 + 1;
1787 int ystep = TILEY + 4;
1788 int pad_x = sx - SX;
1789 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
1790 int max_lines_per_text = 2;
1793 if (action != -1 && direction != -1) /* element.action.direction */
1794 text = getHelpText(element, action, direction);
1796 if (text == NULL && action != -1) /* element.action */
1797 text = getHelpText(element, action, -1);
1799 if (text == NULL && direction != -1) /* element.direction */
1800 text = getHelpText(element, -1, direction);
1802 if (text == NULL) /* base element */
1803 text = getHelpText(element, -1, -1);
1805 if (text == NULL) /* not found */
1806 text = "No description available";
1808 if (strlen(text) <= max_chars_per_line) /* only one line of text */
1809 sy += getFontHeight(font_nr) / 2;
1811 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
1812 max_chars_per_line, max_lines_per_text);
1815 void DrawInfoScreen_TitleScreen()
1820 void HandleInfoScreen_TitleScreen(int button)
1822 HandleTitleScreen(0, 0, 0, 0, button);
1825 void DrawInfoScreen_Elements()
1827 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
1829 FadeOut(REDRAW_FIELD);
1834 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
1836 FadeIn(REDRAW_FIELD);
1841 void HandleInfoScreen_Elements(int button)
1843 static unsigned long info_delay = 0;
1844 static int num_anims;
1845 static int num_pages;
1847 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
1850 if (button == MB_MENU_INITIALIZE)
1852 boolean new_element = TRUE;
1856 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
1858 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
1860 else if (new_element)
1863 new_element = FALSE;
1867 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
1871 if (button == MB_MENU_LEAVE)
1873 PlaySound(SND_MENU_ITEM_SELECTING);
1875 info_mode = INFO_MODE_MAIN;
1880 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
1882 if (button != MB_MENU_INITIALIZE)
1884 PlaySound(SND_MENU_ITEM_SELECTING);
1889 if (page >= num_pages)
1891 FadeSoundsAndMusic();
1892 FadeOut(REDRAW_FIELD);
1894 info_mode = INFO_MODE_MAIN;
1895 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1900 if (button != MB_MENU_INITIALIZE)
1901 FadeCrossSaveBackbuffer();
1903 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
1905 if (button != MB_MENU_INITIALIZE)
1906 FadeCross(REDRAW_FIELD);
1910 if (DelayReached(&info_delay, GameFrameDelay))
1911 if (page < num_pages)
1912 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
1914 PlayMenuSoundIfLoop();
1918 void DrawInfoScreen_Music()
1920 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
1922 FadeOut(REDRAW_FIELD);
1929 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
1931 FadeIn(REDRAW_FIELD);
1934 void HandleInfoScreen_Music(int button)
1936 static struct MusicFileInfo *list = NULL;
1937 int ystart = 150, dy = 30;
1938 int ybottom = SYSIZE - 20;
1940 if (button == MB_MENU_INITIALIZE)
1942 list = music_file_info;
1946 FadeSoundsAndMusic();
1951 DrawTextSCentered(100, FONT_TEXT_1, "No music info for this level set.");
1953 DrawTextSCentered(ybottom, FONT_TEXT_4,
1954 "Press any key or button for info menu");
1960 if (button == MB_MENU_LEAVE)
1962 PlaySound(SND_MENU_ITEM_SELECTING);
1964 FadeSoundsAndMusic();
1966 info_mode = INFO_MODE_MAIN;
1971 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
1975 if (button != MB_MENU_INITIALIZE)
1977 PlaySound(SND_MENU_ITEM_SELECTING);
1985 FadeSoundsAndMusic();
1986 FadeOut(REDRAW_FIELD);
1988 info_mode = INFO_MODE_MAIN;
1989 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1994 FadeSoundsAndMusic();
1996 if (button != MB_MENU_INITIALIZE)
1997 FadeCrossSaveBackbuffer();
2004 int sound = list->music;
2006 if (sound_info[sound].loop)
2007 PlaySoundLoop(sound);
2011 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Sounds:");
2015 PlayMusic(list->music);
2017 DrawTextSCentered(100, FONT_TEXT_1, "The Game Background Music:");
2020 if (!strEqual(list->title, UNKNOWN_NAME))
2022 if (!strEqual(list->title_header, UNKNOWN_NAME))
2023 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->title_header);
2025 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2028 if (!strEqual(list->artist, UNKNOWN_NAME))
2030 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2031 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->artist_header);
2033 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "by");
2035 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2038 if (!strEqual(list->album, UNKNOWN_NAME))
2040 if (!strEqual(list->album_header, UNKNOWN_NAME))
2041 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->album_header);
2043 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the album");
2045 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2048 if (!strEqual(list->year, UNKNOWN_NAME))
2050 if (!strEqual(list->year_header, UNKNOWN_NAME))
2051 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, list->year_header);
2053 DrawTextSCentered(ystart + y++ * dy, FONT_TEXT_2, "from the year");
2055 DrawTextFCentered(ystart + y++ * dy, FONT_TEXT_3, "%s", list->year);
2058 DrawTextSCentered(ybottom, FONT_TEXT_4,
2059 "Press any key or button for next page");
2061 if (button != MB_MENU_INITIALIZE)
2062 FadeCross(REDRAW_FIELD);
2065 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2066 PlaySoundLoop(list->music);
2069 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2071 int ystart = 150, ystep = 30;
2072 int ybottom = SYSIZE - 20;
2080 DrawTextSCentered(100, FONT_TEXT_1, "Credits:");
2084 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2085 "Special thanks to");
2086 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2088 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2090 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2091 "\"Boulder Dash\"");
2092 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
2094 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
2096 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
2098 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
2099 "First Star Software");
2101 else if (screen_nr == 1)
2103 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2104 "Special thanks to");
2105 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2106 "Klaus Heinz & Volker Wertich");
2107 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2109 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2110 "\"Emerald Mine\"");
2111 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
2113 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
2115 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
2117 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
2120 else if (screen_nr == 2)
2122 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2123 "Special thanks to");
2124 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2125 "Michael Stopp & Philip Jespersen");
2126 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2128 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2130 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
2132 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
2134 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
2136 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
2137 "Digital Integration");
2139 else if (screen_nr == 3)
2141 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2142 "Special thanks to");
2143 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2144 "Hiroyuki Imabayashi");
2145 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2147 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2149 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
2151 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
2153 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
2155 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_3,
2158 else if (screen_nr == 4)
2160 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2161 "Special thanks to");
2162 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2164 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2166 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2167 "Jürgen Bonhagen");
2168 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
2169 "for the continuous creation");
2170 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
2171 "of outstanding level sets");
2173 else if (screen_nr == 5)
2175 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2177 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2179 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2180 "for ideas and inspiration by");
2181 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2184 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_2,
2186 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_3,
2188 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
2189 "for ideas and inspiration by");
2190 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
2193 else if (screen_nr == 6)
2195 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2197 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2199 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2200 "for the new Emerald Mine engine");
2202 else if (screen_nr == 7)
2204 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2206 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_3,
2208 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_2,
2209 "for the initial DOS port");
2211 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_2,
2213 DrawTextSCentered(ystart + 5 * ystep, FONT_TEXT_3,
2215 DrawTextSCentered(ystart + 6 * ystep, FONT_TEXT_2,
2216 "for some additional toons");
2218 else if (screen_nr == 8)
2220 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2221 "And not to forget:");
2222 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
2224 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
2225 "All those who contributed");
2226 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_3,
2227 "levels to this game");
2228 DrawTextSCentered(ystart + 4 * ystep, FONT_TEXT_3,
2238 DrawTextSCentered(ybottom, FONT_TEXT_4,
2239 "Press any key or button for next page");
2244 void DrawInfoScreen_Credits()
2246 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2248 FadeSoundsAndMusic();
2250 FadeOut(REDRAW_FIELD);
2252 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2254 FadeIn(REDRAW_FIELD);
2257 void HandleInfoScreen_Credits(int button)
2259 static int screen_nr = 0;
2261 if (button == MB_MENU_INITIALIZE)
2265 DrawInfoScreen_CreditsScreen(screen_nr);
2267 else if (button == MB_MENU_LEAVE)
2269 PlaySound(SND_MENU_ITEM_SELECTING);
2271 info_mode = INFO_MODE_MAIN;
2276 else if (button == MB_MENU_CHOICE)
2278 boolean show_screen;
2280 PlaySound(SND_MENU_ITEM_SELECTING);
2284 FadeCrossSaveBackbuffer();
2286 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
2290 FadeCross(REDRAW_FIELD);
2294 FadeSoundsAndMusic();
2295 FadeOut(REDRAW_FIELD);
2297 info_mode = INFO_MODE_MAIN;
2298 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2303 PlayMenuSoundIfLoop();
2307 void DrawInfoScreen_Program()
2309 int ystart = 150, ystep = 30;
2310 int ybottom = SYSIZE - 20;
2312 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2314 FadeOut(REDRAW_FIELD);
2319 DrawTextSCentered(100, FONT_TEXT_1, "Program Information:");
2321 DrawTextSCentered(ystart + 0 * ystep, FONT_TEXT_2,
2322 "This game is Freeware!");
2323 DrawTextSCentered(ystart + 1 * ystep, FONT_TEXT_2,
2324 "If you like it, send e-mail to:");
2325 DrawTextSCentered(ystart + 2 * ystep, FONT_TEXT_3,
2326 PROGRAM_EMAIL_STRING);
2327 DrawTextSCentered(ystart + 3 * ystep, FONT_TEXT_2,
2328 "or SnailMail to:");
2329 DrawTextSCentered(ystart + 4 * ystep + 0, FONT_TEXT_3,
2331 DrawTextSCentered(ystart + 4 * ystep + 20, FONT_TEXT_3,
2332 "Detmolder Strasse 189");
2333 DrawTextSCentered(ystart + 4 * ystep + 40, FONT_TEXT_3,
2335 DrawTextSCentered(ystart + 4 * ystep + 60, FONT_TEXT_3,
2337 DrawTextSCentered(ystart + 7 * ystep, FONT_TEXT_2,
2338 "More information and levels:");
2339 DrawTextSCentered(ystart + 8 * ystep, FONT_TEXT_3,
2340 PROGRAM_WEBSITE_STRING);
2341 DrawTextSCentered(ystart + 9 * ystep, FONT_TEXT_2,
2342 "If you have created new levels,");
2343 DrawTextSCentered(ystart + 10 * ystep, FONT_TEXT_2,
2344 "send them to me to include them!");
2345 DrawTextSCentered(ystart + 11 * ystep, FONT_TEXT_2,
2348 DrawTextSCentered(ybottom, FONT_TEXT_4,
2349 "Press any key or button for info menu");
2351 FadeIn(REDRAW_FIELD);
2354 void HandleInfoScreen_Program(int button)
2356 if (button == MB_MENU_LEAVE)
2358 PlaySound(SND_MENU_ITEM_SELECTING);
2360 info_mode = INFO_MODE_MAIN;
2365 else if (button == MB_MENU_CHOICE)
2367 PlaySound(SND_MENU_ITEM_SELECTING);
2369 FadeSoundsAndMusic();
2370 FadeOut(REDRAW_FIELD);
2372 info_mode = INFO_MODE_MAIN;
2373 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2377 PlayMenuSoundIfLoop();
2381 void DrawInfoScreen_LevelSet()
2384 int ybottom = SYSIZE - 20;
2385 char *filename = getLevelSetInfoFilename();
2386 int font_nr = FONT_LEVEL_NUMBER;
2387 int font_width = getFontWidth(font_nr);
2388 int font_height = getFontHeight(font_nr);
2391 int sx = SX + pad_x;
2392 int sy = SY + pad_y;
2393 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
2394 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
2396 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2398 FadeOut(REDRAW_FIELD);
2403 DrawTextSCentered(100, FONT_TEXT_1, "Level Set Information:");
2405 DrawTextSCentered(ybottom, FONT_TEXT_4,
2406 "Press any key or button for info menu");
2408 if (filename != NULL)
2409 DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
2410 max_lines_per_screen);
2412 DrawTextSCentered(ystart, FONT_TEXT_2,
2413 "No information for this level set.");
2415 FadeIn(REDRAW_FIELD);
2418 void HandleInfoScreen_LevelSet(int button)
2420 if (button == MB_MENU_LEAVE)
2422 PlaySound(SND_MENU_ITEM_SELECTING);
2424 info_mode = INFO_MODE_MAIN;
2429 else if (button == MB_MENU_CHOICE)
2431 PlaySound(SND_MENU_ITEM_SELECTING);
2433 FadeSoundsAndMusic();
2434 FadeOut(REDRAW_FIELD);
2436 info_mode = INFO_MODE_MAIN;
2437 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2441 PlayMenuSoundIfLoop();
2445 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
2447 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2449 if (info_mode == INFO_MODE_TITLE)
2450 DrawInfoScreen_TitleScreen();
2451 else if (info_mode == INFO_MODE_ELEMENTS)
2452 DrawInfoScreen_Elements();
2453 else if (info_mode == INFO_MODE_MUSIC)
2454 DrawInfoScreen_Music();
2455 else if (info_mode == INFO_MODE_CREDITS)
2456 DrawInfoScreen_Credits();
2457 else if (info_mode == INFO_MODE_PROGRAM)
2458 DrawInfoScreen_Program();
2459 else if (info_mode == INFO_MODE_LEVELSET)
2460 DrawInfoScreen_LevelSet();
2462 DrawInfoScreen_Main(redraw_mask, do_fading);
2464 if (info_mode != INFO_MODE_MAIN &&
2465 info_mode != INFO_MODE_TITLE &&
2466 info_mode != INFO_MODE_MUSIC)
2473 void DrawAndFadeInInfoScreen(int redraw_mask)
2475 DrawInfoScreenExt(redraw_mask, TRUE);
2478 void DrawInfoScreen()
2480 DrawInfoScreenExt(REDRAW_ALL, FALSE);
2483 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
2485 if (info_mode == INFO_MODE_TITLE)
2486 HandleInfoScreen_TitleScreen(button);
2487 else if (info_mode == INFO_MODE_ELEMENTS)
2488 HandleInfoScreen_Elements(button);
2489 else if (info_mode == INFO_MODE_MUSIC)
2490 HandleInfoScreen_Music(button);
2491 else if (info_mode == INFO_MODE_CREDITS)
2492 HandleInfoScreen_Credits(button);
2493 else if (info_mode == INFO_MODE_PROGRAM)
2494 HandleInfoScreen_Program(button);
2495 else if (info_mode == INFO_MODE_LEVELSET)
2496 HandleInfoScreen_LevelSet(button);
2498 HandleInfoScreen_Main(mx, my, dx, dy, button);
2504 /* ========================================================================= */
2505 /* type name functions */
2506 /* ========================================================================= */
2508 void HandleTypeName(int newxpos, Key key)
2510 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
2512 struct MenuPosInfo *pos = mci->pos_input;
2513 int startx = mSX + ALIGNED_XPOS(pos->x, pos->width, pos->align);
2514 int starty = mSY + pos->y;
2517 static int xpos = 0;
2519 static int xpos = 0, ypos = 2;
2521 int font_nr = mci->font_input;
2522 int font_active_nr = FONT_ACTIVE(font_nr);
2523 int font_width = getFontWidth(font_active_nr);
2526 int startx = mSX + mci->pos_input->x;
2527 int starty = mSY + mci->pos_input->y;
2530 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
2531 int startx = mSX + 32 + name_width;
2532 int starty = mSY + ypos * 32;
2539 DrawText(startx, starty, setup.player_name, font_active_nr);
2540 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
2545 if (((key >= KSYM_A && key <= KSYM_Z) ||
2546 (key >= KSYM_a && key <= KSYM_z)) &&
2547 xpos < MAX_PLAYER_NAME_LEN)
2551 if (key >= KSYM_A && key <= KSYM_Z)
2552 ascii = 'A' + (char)(key - KSYM_A);
2554 ascii = 'a' + (char)(key - KSYM_a);
2556 setup.player_name[xpos] = ascii;
2557 setup.player_name[xpos + 1] = 0;
2561 DrawText(startx, starty, setup.player_name, font_active_nr);
2562 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
2564 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
2568 setup.player_name[xpos] = 0;
2570 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
2572 else if (key == KSYM_Return && xpos > 0)
2574 DrawText(startx, starty, setup.player_name, font_nr);
2575 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
2579 game_status = GAME_MODE_MAIN;
2584 /* ========================================================================= */
2585 /* tree menu functions */
2586 /* ========================================================================= */
2588 static void DrawChooseTree(TreeInfo **ti_ptr)
2592 FreeScreenGadgets();
2593 CreateScreenGadgets();
2595 CloseDoor(DOOR_CLOSE_2);
2599 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
2600 MapScreenTreeGadgets(*ti_ptr);
2606 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
2608 struct GadgetInfo *gi = screen_gadget[id];
2609 int items_max, items_visible, item_position;
2611 items_max = numTreeInfoInGroup(ti);
2612 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
2613 item_position = first_entry;
2615 if (item_position > items_max - items_visible)
2616 item_position = items_max - items_visible;
2618 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
2619 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
2620 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
2623 static void drawChooseTreeList(int first_entry, int num_page_entries,
2627 char *title_string = NULL;
2628 int yoffset_sets = MENU_TITLE1_YPOS;
2629 int yoffset_setup = 16;
2630 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
2632 int last_game_status = game_status; /* save current game status */
2634 title_string = ti->infotext;
2636 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
2638 /* force LEVELS font on artwork setup screen */
2639 game_status = GAME_MODE_LEVELS;
2642 /* clear tree list area, but not title or scrollbar */
2643 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
2644 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
2645 NUM_MENU_ENTRIES_ON_SCREEN * 32);
2647 /* clear tree list area, but not title or scrollbar */
2648 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
2649 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
2650 MAX_MENU_ENTRIES_ON_SCREEN * 32);
2653 for (i = 0; i < num_page_entries; i++)
2655 TreeInfo *node, *node_first;
2656 int entry_pos = first_entry + i;
2657 int xpos = MENU_SCREEN_START_XPOS;
2658 int ypos = MENU_SCREEN_START_YPOS + i;
2659 int startx = mSX + xpos * 32;
2660 int starty = mSY + ypos * 32;
2661 int font_nr = FONT_TEXT_1;
2662 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
2663 int startx_text = startx + font_xoffset;
2664 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
2665 int text_size = startx_scrollbar - startx_text;
2666 int max_buffer_len = text_size / getFontWidth(font_nr);
2667 char buffer[max_buffer_len + 1];
2669 node_first = getTreeInfoFirstGroupEntry(ti);
2670 node = getTreeInfoFromPos(node_first, entry_pos);
2672 strncpy(buffer, node->name, max_buffer_len);
2673 buffer[max_buffer_len] = '\0';
2675 DrawText(startx, starty, buffer, font_nr + node->color);
2677 if (node->parent_link)
2678 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2679 else if (node->level_group)
2680 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2682 initCursor(i, IMG_MENU_BUTTON);
2685 game_status = last_game_status; /* restore current game status */
2687 redraw_mask |= REDRAW_FIELD;
2690 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
2692 TreeInfo *node, *node_first;
2693 int x, last_redraw_mask = redraw_mask;
2694 int ypos = MENU_TITLE2_YPOS;
2695 int font_nr = FONT_TITLE_2;
2697 if (ti->type != TREE_TYPE_LEVEL_DIR)
2700 node_first = getTreeInfoFirstGroupEntry(ti);
2701 node = getTreeInfoFromPos(node_first, entry_pos);
2703 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
2705 if (node->parent_link)
2706 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
2708 else if (node->level_group)
2709 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
2711 else if (ti->type == TREE_TYPE_LEVEL_DIR)
2712 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
2713 node->levels, node->class_desc);
2715 /* let BackToFront() redraw only what is needed */
2716 redraw_mask = last_redraw_mask | REDRAW_TILES;
2717 for (x = 0; x < SCR_FIELDX; x++)
2718 MarkTileDirty(x, 1);
2721 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
2724 TreeInfo *ti = *ti_ptr;
2726 int y = ti->cl_cursor;
2727 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2728 int num_entries = numTreeInfoInGroup(ti);
2729 int num_page_entries;
2730 int last_game_status = game_status; /* save current game status */
2731 boolean position_set_by_scrollbar = (dx == 999);
2733 /* force LEVELS draw offset on choose level and artwork setup screen */
2734 game_status = GAME_MODE_LEVELS;
2736 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
2737 num_page_entries = num_entries;
2739 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2741 game_status = last_game_status; /* restore current game status */
2743 if (button == MB_MENU_INITIALIZE)
2745 int num_entries = numTreeInfoInGroup(ti);
2746 int entry_pos = posTreeInfo(ti);
2748 if (ti->cl_first == -1)
2750 /* only on initialization */
2751 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2752 ti->cl_cursor = entry_pos - ti->cl_first;
2754 else if (ti->cl_cursor >= num_page_entries ||
2755 (num_entries > num_page_entries &&
2756 num_entries - ti->cl_first < num_page_entries))
2758 /* only after change of list size (by custom graphic configuration) */
2759 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
2760 ti->cl_cursor = entry_pos - ti->cl_first;
2763 if (position_set_by_scrollbar)
2766 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2769 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2770 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2771 drawChooseTreeCursor(ti->cl_cursor, TRUE);
2775 else if (button == MB_MENU_LEAVE)
2777 PlaySound(SND_MENU_ITEM_SELECTING);
2779 if (ti->node_parent)
2781 *ti_ptr = ti->node_parent;
2782 DrawChooseTree(ti_ptr);
2784 else if (game_status == GAME_MODE_SETUP)
2786 if (game_status == GAME_MODE_SETUP)
2788 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2789 execSetupGraphics();
2796 game_status = GAME_MODE_MAIN;
2803 if (mx || my) /* mouse input */
2805 int last_game_status = game_status; /* save current game status */
2807 /* force LEVELS draw offset on artwork setup screen */
2808 game_status = GAME_MODE_LEVELS;
2810 x = (mx - mSX) / 32;
2811 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2813 game_status = last_game_status; /* restore current game status */
2815 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2817 /* move cursor instead of scrolling when already at start/end of list */
2818 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
2820 else if (dy == +1 * SCROLL_LINE &&
2821 ti->cl_first + num_page_entries == num_entries)
2824 /* handle scrolling screen one line or page */
2825 if (ti->cl_cursor + dy < 0 ||
2826 ti->cl_cursor + dy > num_page_entries - 1)
2828 if (ABS(dy) == SCROLL_PAGE)
2829 step = num_page_entries - 1;
2831 if (dy < 0 && ti->cl_first > 0)
2833 /* scroll page/line up */
2835 ti->cl_first -= step;
2836 if (ti->cl_first < 0)
2839 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2840 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2841 drawChooseTreeCursor(ti->cl_cursor, TRUE);
2843 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2846 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
2848 /* scroll page/line down */
2850 ti->cl_first += step;
2851 if (ti->cl_first + num_page_entries > num_entries)
2852 ti->cl_first = MAX(0, num_entries - num_page_entries);
2854 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
2855 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
2856 drawChooseTreeCursor(ti->cl_cursor, TRUE);
2858 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
2865 /* handle moving cursor one line */
2866 y = ti->cl_cursor + dy;
2871 TreeInfo *node_first, *node_cursor;
2872 int entry_pos = ti->cl_first + y;
2874 node_first = getTreeInfoFirstGroupEntry(ti);
2875 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2877 if (node_cursor->node_group)
2879 PlaySound(SND_MENU_ITEM_SELECTING);
2881 node_cursor->cl_first = ti->cl_first;
2882 node_cursor->cl_cursor = ti->cl_cursor;
2883 *ti_ptr = node_cursor->node_group;
2884 DrawChooseTree(ti_ptr);
2889 else if (dx == -1 && ti->node_parent)
2891 PlaySound(SND_MENU_ITEM_SELECTING);
2893 *ti_ptr = ti->node_parent;
2894 DrawChooseTree(ti_ptr);
2899 if (!anyScrollbarGadgetActive() &&
2900 IN_VIS_FIELD(x, y) &&
2901 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2902 y >= 0 && y < num_page_entries)
2906 if (y != ti->cl_cursor)
2908 PlaySound(SND_MENU_ITEM_ACTIVATING);
2910 drawChooseTreeCursor(ti->cl_cursor, FALSE);
2911 drawChooseTreeCursor(y, TRUE);
2912 drawChooseTreeInfo(ti->cl_first + y, ti);
2919 TreeInfo *node_first, *node_cursor;
2920 int entry_pos = ti->cl_first + y;
2922 PlaySound(SND_MENU_ITEM_SELECTING);
2924 node_first = getTreeInfoFirstGroupEntry(ti);
2925 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
2927 if (node_cursor->node_group)
2929 node_cursor->cl_first = ti->cl_first;
2930 node_cursor->cl_cursor = ti->cl_cursor;
2931 *ti_ptr = node_cursor->node_group;
2932 DrawChooseTree(ti_ptr);
2934 else if (node_cursor->parent_link)
2936 *ti_ptr = node_cursor->node_parent;
2937 DrawChooseTree(ti_ptr);
2941 node_cursor->cl_first = ti->cl_first;
2942 node_cursor->cl_cursor = ti->cl_cursor;
2943 *ti_ptr = node_cursor;
2945 if (ti->type == TREE_TYPE_LEVEL_DIR)
2947 LoadLevelSetup_SeriesInfo();
2949 SaveLevelSetup_LastSeries();
2950 SaveLevelSetup_SeriesInfo();
2954 if (game_status == GAME_MODE_SETUP)
2956 if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
2957 execSetupGraphics();
2963 game_status = GAME_MODE_MAIN;
2971 void DrawChooseLevel()
2973 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
2975 DrawChooseTree(&leveldir_current);
2981 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
2983 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
2988 void DrawHallOfFame(int highlight_position)
2991 FadeSoundsAndMusic();
2993 /* (this is needed when called from GameEnd() after winning a game) */
2994 KeyboardAutoRepeatOn();
2997 /* (this is needed when called from GameEnd() after winning a game) */
2998 SetDrawDeactivationMask(REDRAW_NONE);
2999 SetDrawBackgroundMask(REDRAW_FIELD);
3001 CloseDoor(DOOR_CLOSE_2);
3003 if (highlight_position < 0)
3004 LoadScore(level_nr);
3006 FadeOut(REDRAW_FIELD);
3013 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3015 FadeIn(REDRAW_FIELD);
3018 static void drawHallOfFameList(int first_entry, int highlight_position)
3022 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3025 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3026 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3027 "HighScores of Level %d", level_nr);
3029 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3031 int entry = first_entry + i;
3032 boolean active = (entry == highlight_position);
3033 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3034 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3035 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3036 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3037 int dx1 = 3 * getFontWidth(font_nr1);
3038 int dx2 = dx1 + getFontWidth(font_nr1);
3039 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3040 int sy = mSY + 64 + i * 32;
3042 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3043 DrawText(mSX + dx1, sy, ".", font_nr1);
3044 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3046 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3047 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3049 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3052 redraw_mask |= REDRAW_FIELD;
3055 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3057 static int first_entry = 0;
3058 static int highlight_position = 0;
3059 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3061 if (button == MB_MENU_INITIALIZE)
3064 highlight_position = mx;
3065 drawHallOfFameList(first_entry, highlight_position);
3070 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3071 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3075 if (first_entry > 0)
3077 first_entry -= step;
3078 if (first_entry < 0)
3081 drawHallOfFameList(first_entry, highlight_position);
3086 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3088 first_entry += step;
3089 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3090 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3092 drawHallOfFameList(first_entry, highlight_position);
3095 else if (button == MB_MENU_LEAVE)
3097 PlaySound(SND_MENU_ITEM_SELECTING);
3099 FadeSound(SND_BACKGROUND_SCORES);
3101 game_status = GAME_MODE_MAIN;
3105 else if (button == MB_MENU_CHOICE)
3107 PlaySound(SND_MENU_ITEM_SELECTING);
3109 FadeSound(SND_BACKGROUND_SCORES);
3110 FadeOut(REDRAW_FIELD);
3112 game_status = GAME_MODE_MAIN;
3114 DrawAndFadeInMainMenu(REDRAW_FIELD);
3117 if (game_status == GAME_MODE_SCORES)
3118 PlayMenuSoundIfLoop();
3124 /* ========================================================================= */
3125 /* setup screen functions */
3126 /* ========================================================================= */
3128 static struct TokenInfo *setup_info;
3129 static int num_setup_info;
3131 static char *screen_mode_text;
3132 static char *graphics_set_name;
3133 static char *sounds_set_name;
3134 static char *music_set_name;
3136 static void execSetupMain()
3138 setup_mode = SETUP_MODE_MAIN;
3142 static void execSetupGame()
3144 setup_mode = SETUP_MODE_GAME;
3148 static void execSetupEditor()
3150 setup_mode = SETUP_MODE_EDITOR;
3154 static void execSetupGraphics()
3156 if (video.fullscreen_available && screen_modes == NULL)
3160 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3162 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3163 char identifier[32], name[32];
3164 int x = video.fullscreen_modes[i].width;
3165 int y = video.fullscreen_modes[i].height;
3168 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3170 ti->node_top = &screen_modes;
3171 ti->sort_priority = x * 10000 + y;
3173 sprintf(identifier, "%dx%d", x, y);
3174 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3176 setString(&ti->identifier, identifier);
3177 setString(&ti->name, name);
3178 setString(&ti->name_sorting, name);
3179 setString(&ti->infotext, "Fullscreen Mode");
3181 pushTreeInfo(&screen_modes, ti);
3184 /* sort fullscreen modes to start with lowest available screen resolution */
3185 sortTreeInfo(&screen_modes);
3187 /* set current screen mode for fullscreen mode to configured setup value */
3188 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3189 setup.fullscreen_mode);
3191 /* if that fails, set current screen mode to reliable default value */
3192 if (screen_mode_current == NULL)
3193 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3194 DEFAULT_FULLSCREEN_MODE);
3196 /* if that also fails, set current screen mode to first available mode */
3197 if (screen_mode_current == NULL)
3198 screen_mode_current = screen_modes;
3200 if (screen_mode_current == NULL)
3201 video.fullscreen_available = FALSE;
3204 if (video.fullscreen_available)
3206 setup.fullscreen_mode = screen_mode_current->identifier;
3208 /* needed for displaying screen mode name instead of identifier */
3209 screen_mode_text = screen_mode_current->name;
3212 setup_mode = SETUP_MODE_GRAPHICS;
3216 static void execSetupChooseScreenMode()
3218 if (!video.fullscreen_available)
3221 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
3225 static void execSetupSound()
3227 setup_mode = SETUP_MODE_SOUND;
3231 static void execSetupArtwork()
3233 setup.graphics_set = artwork.gfx_current->identifier;
3234 setup.sounds_set = artwork.snd_current->identifier;
3235 setup.music_set = artwork.mus_current->identifier;
3237 /* needed if last screen (setup choice) changed graphics, sounds or music */
3238 ReloadCustomArtwork(0);
3240 /* needed for displaying artwork name instead of artwork identifier */
3241 graphics_set_name = artwork.gfx_current->name;
3242 sounds_set_name = artwork.snd_current->name;
3243 music_set_name = artwork.mus_current->name;
3245 setup_mode = SETUP_MODE_ARTWORK;
3249 static void execSetupChooseGraphics()
3251 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
3255 static void execSetupChooseSounds()
3257 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
3261 static void execSetupChooseMusic()
3263 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
3267 static void execSetupInput()
3269 setup_mode = SETUP_MODE_INPUT;
3273 static void execSetupShortcut1()
3275 setup_mode = SETUP_MODE_SHORTCUT_1;
3279 static void execSetupShortcut2()
3281 setup_mode = SETUP_MODE_SHORTCUT_2;
3285 static void execExitSetup()
3287 game_status = GAME_MODE_MAIN;
3291 static void execSaveAndExitSetup()
3297 static struct TokenInfo setup_info_main[] =
3299 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
3300 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
3301 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
3302 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
3303 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
3304 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
3305 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
3306 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
3307 { TYPE_EMPTY, NULL, "" },
3308 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
3309 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
3314 static struct TokenInfo setup_info_game[] =
3316 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
3317 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
3318 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
3319 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
3320 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
3321 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
3322 { TYPE_EMPTY, NULL, "" },
3323 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3328 static struct TokenInfo setup_info_editor[] =
3331 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
3332 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
3333 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
3334 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
3335 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
3336 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
3337 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
3338 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
3340 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
3341 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
3343 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
3345 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
3346 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
3347 { TYPE_EMPTY, NULL, "" },
3349 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
3350 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
3351 { TYPE_EMPTY, NULL, "" },
3353 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
3354 { TYPE_EMPTY, NULL, "" },
3355 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3360 static struct TokenInfo setup_info_graphics[] =
3362 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
3363 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
3364 { TYPE_STRING, &screen_mode_text, "" },
3365 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
3367 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
3368 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
3370 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
3371 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
3372 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
3373 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
3374 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
3375 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
3376 { TYPE_EMPTY, NULL, "" },
3377 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3382 static struct TokenInfo setup_info_sound[] =
3384 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
3385 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
3386 { TYPE_SWITCH, &setup.sound_music, "Music:" },
3387 { TYPE_EMPTY, NULL, "" },
3388 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3393 static struct TokenInfo setup_info_artwork[] =
3395 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
3396 { TYPE_STRING, &graphics_set_name, "" },
3397 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
3398 { TYPE_STRING, &sounds_set_name, "" },
3399 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
3400 { TYPE_STRING, &music_set_name, "" },
3401 { TYPE_EMPTY, NULL, "" },
3403 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
3404 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
3405 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
3407 { TYPE_STRING, NULL, "Override Level Artwork:"},
3408 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
3409 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
3410 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
3412 { TYPE_EMPTY, NULL, "" },
3413 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3418 static struct TokenInfo setup_info_input[] =
3420 { TYPE_SWITCH, NULL, "Player:" },
3421 { TYPE_SWITCH, NULL, "Device:" },
3422 { TYPE_ENTER_MENU, NULL, "" },
3423 { TYPE_EMPTY, NULL, "" },
3424 { TYPE_EMPTY, NULL, "" },
3425 { TYPE_EMPTY, NULL, "" },
3426 { TYPE_EMPTY, NULL, "" },
3427 { TYPE_EMPTY, NULL, "" },
3428 { TYPE_EMPTY, NULL, "" },
3429 { TYPE_EMPTY, NULL, "" },
3430 { TYPE_EMPTY, NULL, "" },
3431 { TYPE_EMPTY, NULL, "" },
3432 { TYPE_EMPTY, NULL, "" },
3433 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3438 static struct TokenInfo setup_info_shortcut_1[] =
3440 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
3441 { TYPE_KEY, &setup.shortcut.save_game, "" },
3442 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
3443 { TYPE_KEY, &setup.shortcut.load_game, "" },
3444 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
3445 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
3446 { TYPE_EMPTY, NULL, "" },
3447 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
3448 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
3449 { TYPE_EMPTY, NULL, "" },
3450 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3455 static struct TokenInfo setup_info_shortcut_2[] =
3457 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
3458 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
3459 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
3460 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
3461 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
3462 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
3463 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
3464 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
3465 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
3466 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
3467 { TYPE_EMPTY, NULL, "" },
3468 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
3473 static Key getSetupKey()
3475 Key key = KSYM_UNDEFINED;
3476 boolean got_key_event = FALSE;
3478 while (!got_key_event)
3480 if (PendingEvent()) /* got event */
3488 case EVENT_KEYPRESS:
3490 key = GetEventKey((KeyEvent *)&event, TRUE);
3492 /* press 'Escape' or 'Enter' to keep the existing key binding */
3493 if (key == KSYM_Escape || key == KSYM_Return)
3494 key = KSYM_UNDEFINED; /* keep old value */
3496 got_key_event = TRUE;
3500 case EVENT_KEYRELEASE:
3501 key_joystick_mapping = 0;
3505 HandleOtherEvents(&event);
3513 /* don't eat all CPU time */
3520 static int getSetupTextFont(int type)
3522 if (type & (TYPE_SWITCH |
3533 static int getSetupValueFont(int type, void *value)
3535 if (type & TYPE_KEY)
3536 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
3537 else if (type & TYPE_STRING)
3538 return FONT_VALUE_2;
3539 else if (type & TYPE_ECS_AGA)
3540 return FONT_VALUE_1;
3541 else if (type & TYPE_BOOLEAN_STYLE)
3542 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
3544 return FONT_VALUE_1;
3547 static void drawSetupValue(int pos)
3549 boolean font_draw_xoffset_modified = FALSE;
3550 int font_draw_xoffset_old = -1;
3551 int xpos = MENU_SCREEN_VALUE_XPOS;
3552 int ypos = MENU_SCREEN_START_YPOS + pos;
3553 int startx = mSX + xpos * 32;
3554 int starty = mSY + ypos * 32;
3555 int font_nr, font_width;
3556 int type = setup_info[pos].type;
3557 void *value = setup_info[pos].value;
3558 char *value_string = getSetupValue(type, value);
3561 if (value_string == NULL)
3564 if (type & TYPE_KEY)
3566 xpos = MENU_SCREEN_START_XPOS;
3568 if (type & TYPE_QUERY)
3570 value_string = "<press key>";
3573 else if (type & TYPE_STRING)
3575 int max_value_len = (SCR_FIELDX - 2) * 2;
3577 xpos = MENU_SCREEN_START_XPOS;
3579 if (strlen(value_string) > max_value_len)
3580 value_string[max_value_len] = '\0';
3583 startx = mSX + xpos * 32;
3584 starty = mSY + ypos * 32;
3585 font_nr = getSetupValueFont(type, value);
3586 font_width = getFontWidth(font_nr);
3588 /* downward compatibility correction for Juergen Bonhagen's menu settings */
3589 if (setup_mode != SETUP_MODE_INPUT)
3591 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
3592 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3593 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
3594 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
3595 int text_font_nr = getSetupTextFont(FONT_MENU_2);
3596 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
3597 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
3598 boolean correct_font_draw_xoffset = FALSE;
3600 if (xpos == MENU_SCREEN_START_XPOS &&
3601 startx + font1_xoffset < text_startx + text_font_xoffset)
3602 correct_font_draw_xoffset = TRUE;
3604 if (xpos == MENU_SCREEN_VALUE_XPOS &&
3605 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
3606 correct_font_draw_xoffset = TRUE;
3608 /* check if setup value would overlap with setup text when printed */
3609 /* (this can happen for extreme/wrong values for font draw offset) */
3610 if (correct_font_draw_xoffset)
3612 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
3613 font_draw_xoffset_modified = TRUE;
3615 if (type & TYPE_KEY)
3616 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
3617 else if (!(type & TYPE_STRING))
3618 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
3619 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
3623 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
3624 DrawText(startx + i * font_width, starty, " ", font_nr);
3626 DrawText(startx, starty, value_string, font_nr);
3628 if (font_draw_xoffset_modified)
3629 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
3632 static void changeSetupValue(int pos)
3634 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
3636 *(boolean *)setup_info[pos].value ^= TRUE;
3638 else if (setup_info[pos].type & TYPE_KEY)
3642 setup_info[pos].type |= TYPE_QUERY;
3643 drawSetupValue(pos);
3644 setup_info[pos].type &= ~TYPE_QUERY;
3646 key = getSetupKey();
3647 if (key != KSYM_UNDEFINED)
3648 *(Key *)setup_info[pos].value = key;
3651 drawSetupValue(pos);
3654 static void DrawCursorAndText_Setup(int pos, boolean active)
3656 int xpos = MENU_SCREEN_START_XPOS;
3657 int ypos = MENU_SCREEN_START_YPOS + pos;
3658 int font_nr = getSetupTextFont(setup_info[pos].type);
3660 if (setup_info == setup_info_input)
3661 font_nr = FONT_MENU_1;
3664 font_nr = FONT_ACTIVE(font_nr);
3666 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
3668 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
3669 drawCursor(pos, active);
3672 static void DrawSetupScreen_Generic()
3674 char *title_string = NULL;
3678 CloseDoor(DOOR_CLOSE_2);
3682 if (setup_mode == SETUP_MODE_MAIN)
3684 setup_info = setup_info_main;
3685 title_string = "Setup";
3687 else if (setup_mode == SETUP_MODE_GAME)
3689 setup_info = setup_info_game;
3690 title_string = "Setup Game";
3692 else if (setup_mode == SETUP_MODE_EDITOR)
3694 setup_info = setup_info_editor;
3695 title_string = "Setup Editor";
3697 else if (setup_mode == SETUP_MODE_GRAPHICS)
3699 setup_info = setup_info_graphics;
3700 title_string = "Setup Graphics";
3702 else if (setup_mode == SETUP_MODE_SOUND)
3704 setup_info = setup_info_sound;
3705 title_string = "Setup Sound";
3707 else if (setup_mode == SETUP_MODE_ARTWORK)
3709 setup_info = setup_info_artwork;
3710 title_string = "Custom Artwork";
3712 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
3714 setup_info = setup_info_shortcut_1;
3715 title_string = "Setup Shortcuts";
3717 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
3719 setup_info = setup_info_shortcut_2;
3720 title_string = "Setup Shortcuts";
3723 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
3726 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3728 void *value_ptr = setup_info[i].value;
3731 int xpos = MENU_SCREEN_START_XPOS;
3732 int ypos = MENU_SCREEN_START_YPOS + i;
3736 /* set some entries to "unchangeable" according to other variables */
3737 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
3738 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
3739 (value_ptr == &setup.sound_music && !audio.music_available) ||
3740 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
3741 (value_ptr == &screen_mode_text && !video.fullscreen_available))
3742 setup_info[i].type |= TYPE_GHOSTED;
3744 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
3745 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3746 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
3747 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3748 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
3749 initCursor(i, IMG_MENU_BUTTON);
3752 DrawCursorAndText_Setup(i, FALSE);
3754 font_nr = getSetupTextFont(setup_info[i].type);
3756 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
3759 if (setup_info[i].type & TYPE_VALUE)
3766 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3767 "Joysticks deactivated in setup menu");
3772 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
3775 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
3777 static int choice_store[MAX_SETUP_MODES];
3778 int choice = choice_store[setup_mode]; /* always starts with 0 */
3782 if (button == MB_MENU_INITIALIZE)
3784 /* advance to first valid menu entry */
3785 while (choice < num_setup_info &&
3786 setup_info[choice].type & TYPE_SKIP_ENTRY)
3788 choice_store[setup_mode] = choice;
3791 DrawCursorAndText_Setup(choice, TRUE);
3793 drawCursor(choice, TRUE);
3798 else if (button == MB_MENU_LEAVE)
3800 PlaySound(SND_MENU_ITEM_SELECTING);
3802 for (y = 0; y < num_setup_info; y++)
3804 if (setup_info[y].type & TYPE_LEAVE_MENU)
3806 void (*menu_callback_function)(void) = setup_info[y].value;
3808 menu_callback_function();
3810 break; /* absolutely needed because function changes 'setup_info'! */
3817 if (mx || my) /* mouse input */
3819 x = (mx - mSX) / 32;
3820 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3822 else if (dx || dy) /* keyboard input */
3826 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
3828 if (setup_info[choice].type & menu_navigation_type ||
3829 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
3830 button = MB_MENU_CHOICE;
3835 /* jump to next non-empty menu entry (up or down) */
3836 while (y > 0 && y < num_setup_info - 1 &&
3837 setup_info[y].type & TYPE_SKIP_ENTRY)
3841 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
3845 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
3847 PlaySound(SND_MENU_ITEM_ACTIVATING);
3850 DrawCursorAndText_Setup(choice, FALSE);
3851 DrawCursorAndText_Setup(y, TRUE);
3853 drawCursor(choice, FALSE);
3854 drawCursor(y, TRUE);
3857 choice = choice_store[setup_mode] = y;
3860 else if (!(setup_info[y].type & TYPE_GHOSTED))
3862 PlaySound(SND_MENU_ITEM_SELECTING);
3864 /* when selecting key headline, execute function for key value change */
3865 if (setup_info[y].type & TYPE_KEYTEXT &&
3866 setup_info[y + 1].type & TYPE_KEY)
3869 /* when selecting string value, execute function for list selection */
3870 if (setup_info[y].type & TYPE_STRING && y > 0 &&
3871 setup_info[y - 1].type & TYPE_ENTER_LIST)
3874 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
3876 void (*menu_callback_function)(void) = setup_info[y].value;
3878 menu_callback_function();
3882 if (setup_info[y].type & TYPE_VALUE)
3883 changeSetupValue(y);
3889 void DrawSetupScreen_Input()
3898 setup_info = setup_info_input;
3901 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
3904 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3906 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
3907 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3908 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
3909 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3910 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
3911 initCursor(i, IMG_MENU_BUTTON);
3913 DrawCursorAndText_Setup(i, FALSE);
3916 initCursor(0, IMG_MENU_BUTTON);
3917 initCursor(1, IMG_MENU_BUTTON);
3918 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
3919 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
3921 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
3922 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
3923 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
3927 DeactivateJoystickForCalibration();
3930 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
3931 "Joysticks deactivated on this screen");
3934 /* create gadgets for setup input menu screen */
3935 FreeScreenGadgets();
3936 CreateScreenGadgets();
3938 /* map gadgets for setup input menu screen */
3939 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
3941 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
3946 static void setJoystickDeviceToNr(char *device_name, int device_nr)
3948 if (device_name == NULL)
3951 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
3954 if (strlen(device_name) > 1)
3956 char c1 = device_name[strlen(device_name) - 1];
3957 char c2 = device_name[strlen(device_name) - 2];
3959 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
3960 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
3963 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
3964 strlen(device_name));
3967 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
3970 static struct SetupKeyboardInfo custom_key;
3977 { &custom_key.left, "Joystick Left" },
3978 { &custom_key.right, "Joystick Right" },
3979 { &custom_key.up, "Joystick Up" },
3980 { &custom_key.down, "Joystick Down" },
3981 { &custom_key.snap, "Button 1" },
3982 { &custom_key.drop, "Button 2" }
3984 static char *joystick_name[MAX_PLAYERS] =
3991 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
3995 custom_key = setup.input[player_nr].key;
3997 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
3998 FONT_INPUT_1_ACTIVE);
4000 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4002 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4003 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4005 if (setup.input[player_nr].use_joystick)
4007 char *device_name = setup.input[player_nr].joy.device_name;
4008 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4009 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4011 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4012 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4016 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4017 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4020 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4022 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4023 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4024 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4025 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4027 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4028 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4029 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4030 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4031 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4032 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4034 for (i = 0; i < 6; i++)
4036 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4038 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4040 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4041 (setup.input[player_nr].use_joystick ?
4043 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4047 static int input_player_nr = 0;
4049 void HandleSetupScreen_Input_Player(int step, int direction)
4051 int old_player_nr = input_player_nr;
4054 new_player_nr = old_player_nr + step * direction;
4055 if (new_player_nr < 0)
4057 if (new_player_nr > MAX_PLAYERS - 1)
4058 new_player_nr = MAX_PLAYERS - 1;
4060 if (new_player_nr != old_player_nr)
4062 input_player_nr = new_player_nr;
4064 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4068 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
4070 static int choice = 0;
4073 int pos_start = SETUPINPUT_SCREEN_POS_START;
4074 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
4075 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
4076 int pos_end = SETUPINPUT_SCREEN_POS_END;
4078 if (button == MB_MENU_INITIALIZE)
4080 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
4083 DrawCursorAndText_Setup(choice, TRUE);
4085 drawCursor(choice, TRUE);
4090 else if (button == MB_MENU_LEAVE)
4092 setup_mode = SETUP_MODE_MAIN;
4099 if (mx || my) /* mouse input */
4101 x = (mx - mSX) / 32;
4102 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4104 else if (dx || dy) /* keyboard input */
4106 if (dx && choice == 0)
4107 x = (dx < 0 ? 10 : 12);
4108 else if ((dx && choice == 1) ||
4109 (dx == +1 && choice == 2) ||
4110 (dx == -1 && choice == pos_end))
4111 button = MB_MENU_CHOICE;
4115 if (y >= pos_empty1 && y <= pos_empty2)
4116 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
4119 if (y == 0 && dx != 0 && button)
4121 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
4123 else if (IN_VIS_FIELD(x, y) &&
4124 y >= pos_start && y <= pos_end &&
4125 !(y >= pos_empty1 && y <= pos_empty2))
4132 DrawCursorAndText_Setup(choice, FALSE);
4133 DrawCursorAndText_Setup(y, TRUE);
4135 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
4137 drawCursor(choice, FALSE);
4138 drawCursor(y, TRUE);
4148 char *device_name = setup.input[input_player_nr].joy.device_name;
4150 if (!setup.input[input_player_nr].use_joystick)
4152 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
4154 setJoystickDeviceToNr(device_name, new_device_nr);
4155 setup.input[input_player_nr].use_joystick = TRUE;
4159 int device_nr = getJoystickNrFromDeviceName(device_name);
4160 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
4162 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
4163 setup.input[input_player_nr].use_joystick = FALSE;
4165 setJoystickDeviceToNr(device_name, new_device_nr);
4168 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4172 if (setup.input[input_player_nr].use_joystick)
4175 CalibrateJoystick(input_player_nr);
4178 CustomizeKeyboard(input_player_nr);
4180 else if (y == pos_end)
4184 setup_mode = SETUP_MODE_MAIN;
4191 void CustomizeKeyboard(int player_nr)
4195 boolean finished = FALSE;
4196 static struct SetupKeyboardInfo custom_key;
4201 } customize_step[] =
4203 { &custom_key.left, "Move Left" },
4204 { &custom_key.right, "Move Right" },
4205 { &custom_key.up, "Move Up" },
4206 { &custom_key.down, "Move Down" },
4207 { &custom_key.snap, "Snap Field" },
4208 { &custom_key.drop, "Drop Element" }
4211 /* read existing key bindings from player setup */
4212 custom_key = setup.input[player_nr].key;
4216 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
4222 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
4223 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
4224 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
4225 "Key:", FONT_INPUT_1_ACTIVE);
4226 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
4227 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
4231 if (PendingEvent()) /* got event */
4239 case EVENT_KEYPRESS:
4241 Key key = GetEventKey((KeyEvent *)&event, FALSE);
4243 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
4249 /* all keys configured -- wait for "Escape" or "Return" key */
4253 /* press 'Enter' to keep the existing key binding */
4254 if (key == KSYM_Return)
4255 key = *customize_step[step_nr].key;
4257 /* check if key already used */
4258 for (i = 0; i < step_nr; i++)
4259 if (*customize_step[i].key == key)
4264 /* got new key binding */
4265 *customize_step[step_nr].key = key;
4266 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
4268 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
4269 getKeyNameFromKey(key), FONT_VALUE_1);
4272 /* un-highlight last query */
4273 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
4274 customize_step[step_nr - 1].text, FONT_MENU_1);
4275 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
4276 "Key:", FONT_MENU_1);
4278 /* press 'Enter' to leave */
4281 DrawText(mSX + 16, mSY + 15 * 32 + 16,
4282 "Press Enter", FONT_TITLE_1);
4286 /* query next key binding */
4287 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
4288 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
4289 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
4290 "Key:", FONT_INPUT_1_ACTIVE);
4291 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
4292 getKeyNameFromKey(*customize_step[step_nr].key),
4297 case EVENT_KEYRELEASE:
4298 key_joystick_mapping = 0;
4302 HandleOtherEvents(&event);
4310 /* don't eat all CPU time */
4314 /* write new key bindings back to player setup */
4315 setup.input[player_nr].key = custom_key;
4318 DrawSetupScreen_Input();
4321 static boolean CalibrateJoystickMain(int player_nr)
4323 int new_joystick_xleft = JOYSTICK_XMIDDLE;
4324 int new_joystick_xright = JOYSTICK_XMIDDLE;
4325 int new_joystick_yupper = JOYSTICK_YMIDDLE;
4326 int new_joystick_ylower = JOYSTICK_YMIDDLE;
4327 int new_joystick_xmiddle, new_joystick_ymiddle;
4329 int joystick_fd = joystick.fd[player_nr];
4330 int x, y, last_x, last_y, xpos = 8, ypos = 3;
4331 boolean check[3][3];
4332 int check_remaining = 3 * 3;
4337 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
4340 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
4345 for (y = 0; y < 3; y++)
4347 for (x = 0; x < 3; x++)
4349 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
4350 check[x][y] = FALSE;
4354 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
4355 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
4356 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
4357 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
4358 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
4359 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
4360 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
4362 joy_value = Joystick(player_nr);
4363 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
4364 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
4366 /* eventually uncalibrated center position (joystick could be uncentered) */
4367 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
4370 new_joystick_xmiddle = joy_x;
4371 new_joystick_ymiddle = joy_y;
4373 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
4376 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
4381 if (PendingEvent()) /* got event */
4389 case EVENT_KEYPRESS:
4390 switch (GetEventKey((KeyEvent *)&event, TRUE))
4393 if (check_remaining == 0)
4406 case EVENT_KEYRELEASE:
4407 key_joystick_mapping = 0;
4411 HandleOtherEvents(&event);
4416 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
4419 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
4420 new_joystick_xright = MAX(new_joystick_xright, joy_x);
4421 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
4422 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
4424 setup.input[player_nr].joy.xleft = new_joystick_xleft;
4425 setup.input[player_nr].joy.yupper = new_joystick_yupper;
4426 setup.input[player_nr].joy.xright = new_joystick_xright;
4427 setup.input[player_nr].joy.ylower = new_joystick_ylower;
4428 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
4429 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
4431 CheckJoystickData();
4433 joy_value = Joystick(player_nr);
4435 if (joy_value & JOY_BUTTON && check_remaining == 0)
4438 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
4439 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
4441 if (x != last_x || y != last_y)
4443 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
4444 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
4449 if (check_remaining > 0 && !check[x+1][y+1])
4451 check[x+1][y+1] = TRUE;
4457 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
4458 setup.input[player_nr].joy.xleft,
4459 setup.input[player_nr].joy.xmiddle,
4460 setup.input[player_nr].joy.xright);
4461 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
4462 setup.input[player_nr].joy.yupper,
4463 setup.input[player_nr].joy.ymiddle,
4464 setup.input[player_nr].joy.ylower);
4473 /* don't eat all CPU time */
4477 /* calibrated center position (joystick should now be centered) */
4478 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
4481 new_joystick_xmiddle = joy_x;
4482 new_joystick_ymiddle = joy_y;
4487 DrawSetupScreen_Input();
4490 /* wait until the last pressed button was released */
4491 while (Joystick(player_nr) & JOY_BUTTON)
4493 if (PendingEvent()) /* got event */
4498 HandleOtherEvents(&event);
4507 void CalibrateJoystick(int player_nr)
4509 if (!CalibrateJoystickMain(player_nr))
4511 char *device_name = setup.input[player_nr].joy.device_name;
4512 int nr = getJoystickNrFromDeviceName(device_name) + 1;
4513 int xpos = mSX - SX;
4514 int ypos = mSY - SY;
4518 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
4519 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
4522 Delay(2000); /* show error message for a short time */
4528 DrawSetupScreen_Input();
4532 void DrawSetupScreen()
4534 DeactivateJoystick();
4536 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
4538 if (setup_mode == SETUP_MODE_INPUT)
4539 DrawSetupScreen_Input();
4540 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
4541 DrawChooseTree(&screen_mode_current);
4542 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
4543 DrawChooseTree(&artwork.gfx_current);
4544 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
4545 DrawChooseTree(&artwork.snd_current);
4546 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
4547 DrawChooseTree(&artwork.mus_current);
4549 DrawSetupScreen_Generic();
4555 void RedrawSetupScreenAfterFullscreenToggle()
4557 if (setup_mode == SETUP_MODE_GRAPHICS)
4561 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
4563 if (setup_mode == SETUP_MODE_INPUT)
4564 HandleSetupScreen_Input(mx, my, dx, dy, button);
4565 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
4566 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
4567 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
4568 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
4569 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
4570 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
4571 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
4572 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
4574 HandleSetupScreen_Generic(mx, my, dx, dy, button);
4579 void HandleGameActions()
4581 if (game_status != GAME_MODE_PLAYING)
4584 GameActions(); /* main game loop */
4586 if (tape.auto_play && !tape.playing)
4587 AutoPlayTape(); /* continue automatically playing next tape */
4591 /* ---------- new screen button stuff -------------------------------------- */
4593 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
4598 case SCREEN_CTRL_ID_PREV_LEVEL:
4599 *x = mSX + menu.main.button.prev_level.x;
4600 *y = mSY + menu.main.button.prev_level.y;
4603 case SCREEN_CTRL_ID_NEXT_LEVEL:
4604 *x = mSX + menu.main.button.next_level.x;
4605 *y = mSY + menu.main.button.next_level.y;
4608 case SCREEN_CTRL_ID_PREV_LEVEL:
4609 *x = mSX + TILEX * getPrevlevelButtonPos();
4610 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4613 case SCREEN_CTRL_ID_NEXT_LEVEL:
4614 *x = mSX + TILEX * getNextLevelButtonPos();
4615 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
4619 case SCREEN_CTRL_ID_PREV_PLAYER:
4620 *x = mSX + TILEX * 10;
4621 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4624 case SCREEN_CTRL_ID_NEXT_PLAYER:
4625 *x = mSX + TILEX * 12;
4626 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
4630 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
4636 int gfx_unpressed, gfx_pressed;
4637 void (*get_gadget_position)(int *, int *, int);
4641 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
4644 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
4645 getScreenMenuButtonPos,
4646 SCREEN_CTRL_ID_PREV_LEVEL,
4651 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
4652 getScreenMenuButtonPos,
4653 SCREEN_CTRL_ID_NEXT_LEVEL,
4658 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
4659 getScreenMenuButtonPos,
4660 SCREEN_CTRL_ID_PREV_PLAYER,
4665 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
4666 getScreenMenuButtonPos,
4667 SCREEN_CTRL_ID_NEXT_PLAYER,
4675 int gfx_unpressed, gfx_pressed;
4679 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
4682 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
4683 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
4684 SCREEN_CTRL_ID_SCROLL_UP,
4688 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
4689 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
4690 SCREEN_CTRL_ID_SCROLL_DOWN,
4697 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4698 Bitmap **gfx_unpressed, **gfx_pressed;
4700 int gfx_unpressed, gfx_pressed;
4707 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
4710 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4711 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
4713 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
4715 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
4716 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
4717 GD_TYPE_SCROLLBAR_VERTICAL,
4718 SCREEN_CTRL_ID_SCROLL_VERTICAL,
4719 "scroll level series vertically"
4723 static void CreateScreenMenubuttons()
4725 struct GadgetInfo *gi;
4726 unsigned long event_mask;
4729 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4731 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4732 int gfx_unpressed, gfx_pressed;
4733 int x, y, width, height;
4734 int gd_x1, gd_x2, gd_y1, gd_y2;
4735 int id = menubutton_info[i].gadget_id;
4737 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4739 menubutton_info[i].get_gadget_position(&x, &y, id);
4741 width = SC_MENUBUTTON_XSIZE;
4742 height = SC_MENUBUTTON_YSIZE;
4744 gfx_unpressed = menubutton_info[i].gfx_unpressed;
4745 gfx_pressed = menubutton_info[i].gfx_pressed;
4746 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4747 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4748 gd_x1 = graphic_info[gfx_unpressed].src_x;
4749 gd_y1 = graphic_info[gfx_unpressed].src_y;
4750 gd_x2 = graphic_info[gfx_pressed].src_x;
4751 gd_y2 = graphic_info[gfx_pressed].src_y;
4753 gi = CreateGadget(GDI_CUSTOM_ID, id,
4754 GDI_CUSTOM_TYPE_ID, i,
4755 GDI_INFO_TEXT, menubutton_info[i].infotext,
4760 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4761 GDI_STATE, GD_BUTTON_UNPRESSED,
4762 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4763 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4764 GDI_DIRECT_DRAW, FALSE,
4765 GDI_EVENT_MASK, event_mask,
4766 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4770 Error(ERR_EXIT, "cannot create gadget");
4772 screen_gadget[id] = gi;
4776 static void CreateScreenScrollbuttons()
4778 struct GadgetInfo *gi;
4779 unsigned long event_mask;
4782 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4784 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4785 int gfx_unpressed, gfx_pressed;
4786 int x, y, width, height;
4787 int gd_x1, gd_x2, gd_y1, gd_y2;
4788 int id = scrollbutton_info[i].gadget_id;
4790 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4792 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
4793 y = mSY + scrollbutton_info[i].y;
4794 width = SC_SCROLLBUTTON_XSIZE;
4795 height = SC_SCROLLBUTTON_YSIZE;
4797 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
4798 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
4799 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
4801 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
4802 gfx_pressed = scrollbutton_info[i].gfx_pressed;
4803 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4804 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4805 gd_x1 = graphic_info[gfx_unpressed].src_x;
4806 gd_y1 = graphic_info[gfx_unpressed].src_y;
4807 gd_x2 = graphic_info[gfx_pressed].src_x;
4808 gd_y2 = graphic_info[gfx_pressed].src_y;
4810 gi = CreateGadget(GDI_CUSTOM_ID, id,
4811 GDI_CUSTOM_TYPE_ID, i,
4812 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4817 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4818 GDI_STATE, GD_BUTTON_UNPRESSED,
4819 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4820 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4821 GDI_DIRECT_DRAW, FALSE,
4822 GDI_EVENT_MASK, event_mask,
4823 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4827 Error(ERR_EXIT, "cannot create gadget");
4829 screen_gadget[id] = gi;
4833 static void CreateScreenScrollbars()
4837 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4839 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
4840 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4841 int gfx_unpressed, gfx_pressed;
4843 int x, y, width, height;
4844 int gd_x1, gd_x2, gd_y1, gd_y2;
4845 struct GadgetInfo *gi;
4846 int items_max, items_visible, item_position;
4847 unsigned long event_mask;
4848 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4849 int id = scrollbar_info[i].gadget_id;
4851 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
4853 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
4854 y = mSY + scrollbar_info[i].y;
4855 width = scrollbar_info[i].width;
4856 height = scrollbar_info[i].height;
4858 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
4859 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
4861 items_max = num_page_entries;
4862 items_visible = num_page_entries;
4865 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4866 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
4867 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
4873 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
4874 gfx_pressed = scrollbar_info[i].gfx_pressed;
4875 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
4876 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
4877 gd_x1 = graphic_info[gfx_unpressed].src_x;
4878 gd_y1 = graphic_info[gfx_unpressed].src_y;
4879 gd_x2 = graphic_info[gfx_pressed].src_x;
4880 gd_y2 = graphic_info[gfx_pressed].src_y;
4883 gi = CreateGadget(GDI_CUSTOM_ID, id,
4884 GDI_CUSTOM_TYPE_ID, i,
4885 GDI_INFO_TEXT, scrollbar_info[i].infotext,
4890 GDI_TYPE, scrollbar_info[i].type,
4891 GDI_SCROLLBAR_ITEMS_MAX, items_max,
4892 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
4893 GDI_SCROLLBAR_ITEM_POSITION, item_position,
4895 GDI_WHEEL_AREA_X, SX,
4896 GDI_WHEEL_AREA_Y, SY,
4897 GDI_WHEEL_AREA_WIDTH, SXSIZE,
4898 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
4900 GDI_WHEEL_AREA_X, 0,
4901 GDI_WHEEL_AREA_Y, 0,
4902 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
4903 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
4905 GDI_STATE, GD_BUTTON_UNPRESSED,
4906 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
4907 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
4908 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
4909 GDI_DIRECT_DRAW, FALSE,
4910 GDI_EVENT_MASK, event_mask,
4911 GDI_CALLBACK_ACTION, HandleScreenGadgets,
4915 Error(ERR_EXIT, "cannot create gadget");
4917 screen_gadget[id] = gi;
4921 void CreateScreenGadgets()
4923 int last_game_status = game_status; /* save current game status */
4925 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4928 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4930 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
4932 /* copy pointers to clip mask and GC */
4933 scrollbar_bitmap[i]->clip_mask =
4934 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
4935 scrollbar_bitmap[i]->stored_clip_gc =
4936 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
4938 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
4939 scrollbar_bitmap[i],
4940 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
4941 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
4942 TILEX, TILEY, 0, 0);
4946 CreateScreenMenubuttons();
4948 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
4949 game_status = GAME_MODE_LEVELS;
4951 CreateScreenScrollbuttons();
4952 CreateScreenScrollbars();
4954 game_status = last_game_status; /* restore current game status */
4957 void FreeScreenGadgets()
4961 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
4962 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
4964 /* prevent freeing clip mask and GC twice */
4965 scrollbar_bitmap[i]->clip_mask = None;
4966 scrollbar_bitmap[i]->stored_clip_gc = None;
4968 FreeBitmap(scrollbar_bitmap[i]);
4972 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
4973 FreeGadget(screen_gadget[i]);
4976 void MapScreenMenuGadgets(int screen_mask)
4980 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
4981 if (screen_mask & menubutton_info[i].screen_mask)
4982 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
4985 void MapScreenTreeGadgets(TreeInfo *ti)
4987 int num_entries = numTreeInfoInGroup(ti);
4990 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4993 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
4994 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
4996 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
4997 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5000 static void HandleScreenGadgets(struct GadgetInfo *gi)
5002 int id = gi->custom_id;
5003 int button = gi->event.button;
5004 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5008 case SCREEN_CTRL_ID_PREV_LEVEL:
5009 HandleMainMenu_SelectLevel(step, -1);
5012 case SCREEN_CTRL_ID_NEXT_LEVEL:
5013 HandleMainMenu_SelectLevel(step, +1);
5016 case SCREEN_CTRL_ID_PREV_PLAYER:
5017 HandleSetupScreen_Input_Player(step, -1);
5020 case SCREEN_CTRL_ID_NEXT_PLAYER:
5021 HandleSetupScreen_Input_Player(step, +1);
5024 case SCREEN_CTRL_ID_SCROLL_UP:
5025 if (game_status == GAME_MODE_LEVELS)
5026 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5027 else if (game_status == GAME_MODE_SETUP)
5028 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5031 case SCREEN_CTRL_ID_SCROLL_DOWN:
5032 if (game_status == GAME_MODE_LEVELS)
5033 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5034 else if (game_status == GAME_MODE_SETUP)
5035 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5038 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5039 if (game_status == GAME_MODE_LEVELS)
5040 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5041 else if (game_status == GAME_MODE_SETUP)
5042 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);