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"
28 /* screens on the info screen */
29 #define INFO_MODE_MAIN 0
30 #define INFO_MODE_TITLE 1
31 #define INFO_MODE_ELEMENTS 2
32 #define INFO_MODE_MUSIC 3
33 #define INFO_MODE_CREDITS 4
34 #define INFO_MODE_PROGRAM 5
35 #define INFO_MODE_VERSION 6
36 #define INFO_MODE_LEVELSET 7
38 #define MAX_INFO_MODES 8
40 /* screens on the setup screen */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_SHORTCUTS_1 7
49 #define SETUP_MODE_SHORTCUTS_2 8
51 /* sub-screens on the setup screen (generic) */
52 #define SETUP_MODE_CHOOSE_ARTWORK 9
53 #define SETUP_MODE_CHOOSE_OTHER 10
55 /* sub-screens on the setup screen (specific) */
56 #define SETUP_MODE_CHOOSE_GAME_SPEED 11
57 #define SETUP_MODE_CHOOSE_SCREEN_MODE 12
58 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 13
59 #define SETUP_MODE_CHOOSE_GRAPHICS 14
60 #define SETUP_MODE_CHOOSE_SOUNDS 15
61 #define SETUP_MODE_CHOOSE_MUSIC 16
63 #define MAX_SETUP_MODES 17
65 /* for input setup functions */
66 #define SETUPINPUT_SCREEN_POS_START 0
67 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
68 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
69 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
71 /* for various menu stuff */
72 #define MENU_SCREEN_START_XPOS 1
73 #define MENU_SCREEN_START_YPOS 2
74 #define MENU_SCREEN_VALUE_XPOS 14
75 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
76 #define MENU_TITLE1_YPOS 8
77 #define MENU_TITLE2_YPOS 46
78 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
79 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
80 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
81 MENU_SCREEN_START_XPOS)
82 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
84 /* buttons and scrollbars identifiers */
85 #define SCREEN_CTRL_ID_PREV_LEVEL 0
86 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
87 #define SCREEN_CTRL_ID_PREV_PLAYER 2
88 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
89 #define SCREEN_CTRL_ID_SCROLL_UP 4
90 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
91 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
93 #define NUM_SCREEN_GADGETS 7
95 #define NUM_SCREEN_MENUBUTTONS 4
96 #define NUM_SCREEN_SCROLLBUTTONS 2
97 #define NUM_SCREEN_SCROLLBARS 1
99 #define SCREEN_MASK_MAIN (1 << 0)
100 #define SCREEN_MASK_INPUT (1 << 1)
102 /* graphic position and size values for buttons and scrollbars */
103 #define SC_MENUBUTTON_XSIZE TILEX
104 #define SC_MENUBUTTON_YSIZE TILEY
106 #define SC_SCROLLBUTTON_XSIZE TILEX
107 #define SC_SCROLLBUTTON_YSIZE TILEY
109 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
111 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
112 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
113 SC_SCROLLBUTTON_YSIZE)
115 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
118 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
119 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
120 SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
124 SC_SCROLL_VERTICAL_YSIZE)
126 #define SC_BORDER_SIZE 14
129 /* other useful macro definitions */
130 #define BUTTON_GRAPHIC_ACTIVE(g) \
131 (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE : \
132 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE : \
133 g == IMG_MENU_BUTTON_UP ? IMG_MENU_BUTTON_UP_ACTIVE : \
134 g == IMG_MENU_BUTTON_DOWN ? IMG_MENU_BUTTON_DOWN_ACTIVE : \
135 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE : \
136 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE : \
137 g == IMG_MENU_BUTTON_PREV_LEVEL ? IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE : \
138 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE : \
139 g == IMG_MENU_BUTTON_NAME ? IMG_MENU_BUTTON_NAME_ACTIVE : \
140 g == IMG_MENU_BUTTON_LEVELS ? IMG_MENU_BUTTON_LEVELS_ACTIVE : \
141 g == IMG_MENU_BUTTON_SCORES ? IMG_MENU_BUTTON_SCORES_ACTIVE : \
142 g == IMG_MENU_BUTTON_EDITOR ? IMG_MENU_BUTTON_EDITOR_ACTIVE : \
143 g == IMG_MENU_BUTTON_INFO ? IMG_MENU_BUTTON_INFO_ACTIVE : \
144 g == IMG_MENU_BUTTON_GAME ? IMG_MENU_BUTTON_GAME_ACTIVE : \
145 g == IMG_MENU_BUTTON_SETUP ? IMG_MENU_BUTTON_SETUP_ACTIVE : \
146 g == IMG_MENU_BUTTON_QUIT ? IMG_MENU_BUTTON_QUIT_ACTIVE : \
147 IMG_MENU_BUTTON_ACTIVE)
151 /* forward declarations of internal functions */
152 static void HandleScreenGadgets(struct GadgetInfo *);
153 static void HandleSetupScreen_Generic(int, int, int, int, int);
154 static void HandleSetupScreen_Input(int, int, int, int, int);
155 static void CustomizeKeyboard(int);
156 static void CalibrateJoystick(int);
157 static void execSetupGame(void);
158 static void execSetupGraphics(void);
159 static void execSetupArtwork(void);
160 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
162 static void DrawChooseLevel(void);
163 static void DrawInfoScreen(void);
164 static void DrawAndFadeInInfoScreen(int);
165 static void DrawSetupScreen(void);
167 static void DrawInfoScreenExt(int, int);
168 static void DrawInfoScreen_NotAvailable(char *, char *);
169 static void DrawInfoScreen_HelpAnim(int, int, boolean);
170 static void DrawInfoScreen_HelpText(int, int, int, int);
171 static void HandleInfoScreen_Main(int, int, int, int, int);
172 static void HandleInfoScreen_TitleScreen(int);
173 static void HandleInfoScreen_Elements(int);
174 static void HandleInfoScreen_Music(int);
175 static void HandleInfoScreen_Credits(int);
176 static void HandleInfoScreen_Program(int);
177 static void HandleInfoScreen_Version(int);
179 static void MapScreenMenuGadgets(int);
180 static void MapScreenTreeGadgets(TreeInfo *);
182 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
184 static int info_mode = INFO_MODE_MAIN;
185 static int setup_mode = SETUP_MODE_MAIN;
187 static TreeInfo *screen_modes = NULL;
188 static TreeInfo *screen_mode_current = NULL;
190 static TreeInfo *scroll_delays = NULL;
191 static TreeInfo *scroll_delay_current = NULL;
193 static TreeInfo *game_speeds = NULL;
194 static TreeInfo *game_speed_current = NULL;
200 } game_speeds_list[] =
209 { 1000, "1/1s (Extremely Slow)" },
214 { 29, "1/35s (Original Supaplex)" },
216 { 20, "1/50s (Normal Speed)" },
217 { 14, "1/70s (Maximum Supaplex)" },
221 { 1, "1/1000s (Extremely Fast)" },
231 } scroll_delays_list[] =
233 { 0, "0 Tiles (No Scroll Delay)" },
236 { 3, "3 Tiles (Default)" },
241 { 8, "8 Tiles (Maximum Scroll Delay)"},
246 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
247 (s) <= GAME_MODE_SETUP ? (s) : \
248 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
249 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
251 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
252 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
253 (i) <= INFO_MODE_LEVELSET ? (i) : \
256 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
257 (i) <= SETUP_MODE_SHORTCUTS_2 ? (i) : \
258 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
259 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
260 SETUP_MODE_CHOOSE_ARTWORK : \
261 SETUP_MODE_CHOOSE_OTHER)
263 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
264 menu.draw_xoffset[GAME_MODE_INFO] : \
265 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
266 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
267 menu.draw_yoffset[GAME_MODE_INFO] : \
268 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
270 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
271 menu.draw_xoffset[GAME_MODE_SETUP] : \
272 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
273 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
274 menu.draw_yoffset[GAME_MODE_SETUP] : \
275 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
277 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
278 DRAW_XOFFSET_INFO(info_mode) : \
279 (s) == GAME_MODE_SETUP ? \
280 DRAW_XOFFSET_SETUP(setup_mode) : \
281 menu.draw_xoffset[DRAW_MODE(s)])
282 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
283 DRAW_YOFFSET_INFO(info_mode) : \
284 (s) == GAME_MODE_SETUP ? \
285 DRAW_YOFFSET_SETUP(setup_mode) : \
286 menu.draw_yoffset[DRAW_MODE(s)])
288 #define mSX (SX + DRAW_XOFFSET(game_status))
289 #define mSY (SY + DRAW_YOFFSET(game_status))
291 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
292 menu.list_size[game_status] : \
293 MAX_MENU_ENTRIES_ON_SCREEN)
295 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
296 #define NUM_SCROLLBAR_BITMAPS 2
297 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
301 /* title display and control definitions */
303 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
304 2 * MAX_NUM_TITLE_MESSAGES)
306 static int num_title_screens = 0;
308 struct TitleControlInfo
316 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
318 /* main menu display and control definitions */
320 #define MAIN_CONTROL_NAME 0
321 #define MAIN_CONTROL_LEVELS 1
322 #define MAIN_CONTROL_SCORES 2
323 #define MAIN_CONTROL_EDITOR 3
324 #define MAIN_CONTROL_INFO 4
325 #define MAIN_CONTROL_GAME 5
326 #define MAIN_CONTROL_SETUP 6
327 #define MAIN_CONTROL_QUIT 7
328 #define MAIN_CONTROL_PREV_LEVEL 8
329 #define MAIN_CONTROL_NEXT_LEVEL 9
330 #define MAIN_CONTROL_FIRST_LEVEL 10
331 #define MAIN_CONTROL_LAST_LEVEL 11
332 #define MAIN_CONTROL_LEVEL_NUMBER 12
333 #define MAIN_CONTROL_LEVEL_INFO_1 13
334 #define MAIN_CONTROL_LEVEL_INFO_2 14
335 #define MAIN_CONTROL_LEVEL_NAME 15
336 #define MAIN_CONTROL_LEVEL_AUTHOR 16
337 #define MAIN_CONTROL_LEVEL_YEAR 17
338 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
339 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
340 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
341 #define MAIN_CONTROL_TITLE_1 21
342 #define MAIN_CONTROL_TITLE_2 22
343 #define MAIN_CONTROL_TITLE_3 23
345 static char str_main_text_name[10];
346 static char str_main_text_first_level[10];
347 static char str_main_text_last_level[10];
348 static char str_main_text_level_number[10];
350 static char *main_text_name = str_main_text_name;
351 static char *main_text_first_level = str_main_text_first_level;
352 static char *main_text_last_level = str_main_text_last_level;
353 static char *main_text_level_number = str_main_text_level_number;
354 static char *main_text_levels = "Levelset";
355 static char *main_text_scores = "Hall Of Fame";
356 static char *main_text_editor = "Level Creator";
357 static char *main_text_info = "Info Screen";
358 static char *main_text_game = "Start Game";
359 static char *main_text_setup = "Setup";
360 static char *main_text_quit = "Quit";
361 static char *main_text_level_name = level.name;
362 static char *main_text_level_author = level.author;
363 static char *main_text_level_year = NULL;
364 static char *main_text_level_imported_from = NULL;
365 static char *main_text_level_imported_by = NULL;
366 static char *main_text_level_tested_by = NULL;
367 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
368 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
369 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
371 struct MainControlInfo
375 struct MenuPosInfo *pos_button;
378 struct TextPosInfo *pos_text;
381 struct TextPosInfo *pos_input;
385 static struct MainControlInfo main_controls[] =
389 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
390 &menu.main.text.name, &main_text_name,
391 &menu.main.input.name, &setup.player_name,
395 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
396 &menu.main.text.levels, &main_text_levels,
401 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
402 &menu.main.text.scores, &main_text_scores,
407 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
408 &menu.main.text.editor, &main_text_editor,
413 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
414 &menu.main.text.info, &main_text_info,
419 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
420 &menu.main.text.game, &main_text_game,
425 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
426 &menu.main.text.setup, &main_text_setup,
431 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
432 &menu.main.text.quit, &main_text_quit,
436 /* (these two buttons are real gadgets) */
438 MAIN_CONTROL_PREV_LEVEL,
439 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
444 MAIN_CONTROL_NEXT_LEVEL,
445 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
451 MAIN_CONTROL_FIRST_LEVEL,
453 &menu.main.text.first_level, &main_text_first_level,
457 MAIN_CONTROL_LAST_LEVEL,
459 &menu.main.text.last_level, &main_text_last_level,
463 MAIN_CONTROL_LEVEL_NUMBER,
465 &menu.main.text.level_number, &main_text_level_number,
469 MAIN_CONTROL_LEVEL_INFO_1,
471 &menu.main.text.level_info_1, NULL,
475 MAIN_CONTROL_LEVEL_INFO_2,
477 &menu.main.text.level_info_2, NULL,
481 MAIN_CONTROL_LEVEL_NAME,
483 &menu.main.text.level_name, &main_text_level_name,
487 MAIN_CONTROL_LEVEL_AUTHOR,
489 &menu.main.text.level_author, &main_text_level_author,
493 MAIN_CONTROL_LEVEL_YEAR,
495 &menu.main.text.level_year, &main_text_level_year,
499 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
501 &menu.main.text.level_imported_from, &main_text_level_imported_from,
505 MAIN_CONTROL_LEVEL_IMPORTED_BY,
507 &menu.main.text.level_imported_by, &main_text_level_imported_by,
511 MAIN_CONTROL_LEVEL_TESTED_BY,
513 &menu.main.text.level_tested_by, &main_text_level_tested_by,
517 MAIN_CONTROL_TITLE_1,
519 &menu.main.text.title_1, &main_text_title_1,
523 MAIN_CONTROL_TITLE_2,
525 &menu.main.text.title_2, &main_text_title_2,
529 MAIN_CONTROL_TITLE_3,
531 &menu.main.text.title_3, &main_text_title_3,
544 static int getTitleScreenGraphic(int nr, boolean initial)
546 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
549 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
551 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
555 static int getTitleScreenGameMode(boolean initial)
557 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
561 static int getTitleMessageGameMode(boolean initial)
563 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
567 static int getTitleScreenBackground(boolean initial)
569 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
574 static int getTitleMessageBackground(int nr, boolean initial)
576 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
580 static int getTitleBackground(int nr, boolean initial, boolean is_image)
582 int base = (is_image ?
583 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
584 IMG_BACKGROUND_TITLESCREEN_1) :
585 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
586 IMG_BACKGROUND_TITLEMESSAGE_1));
587 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
588 IMG_BACKGROUND_TITLE);
589 int graphic_local = base + nr;
591 if (graphic_info[graphic_local].bitmap != NULL)
592 return graphic_local;
594 if (graphic_info[graphic_global].bitmap != NULL)
595 return graphic_global;
597 return IMG_UNDEFINED;
600 static int getTitleSound(struct TitleControlInfo *tci)
602 boolean is_image = tci->is_image;
603 int initial = tci->initial;
604 int nr = tci->local_nr;
605 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
606 int base = (is_image ?
607 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
608 SND_BACKGROUND_TITLESCREEN_1) :
609 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
610 SND_BACKGROUND_TITLEMESSAGE_1));
611 int sound_global = menu.sound[mode];
612 int sound_local = base + nr;
615 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
616 nr, initial, is_image,
617 sound_global, getSoundListEntry(sound_global)->filename,
618 sound_local, getSoundListEntry(sound_local)->filename);
621 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
624 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
627 return SND_UNDEFINED;
630 static int getTitleMusic(struct TitleControlInfo *tci)
632 boolean is_image = tci->is_image;
633 int initial = tci->initial;
634 int nr = tci->local_nr;
635 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
636 int base = (is_image ?
637 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
638 MUS_BACKGROUND_TITLESCREEN_1) :
639 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
640 MUS_BACKGROUND_TITLEMESSAGE_1));
641 int music_global = menu.music[mode];
642 int music_local = base + nr;
645 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
646 nr, initial, is_image,
647 music_global, getMusicListEntry(music_global)->filename,
648 music_local, getMusicListEntry(music_local)->filename);
651 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
654 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
657 return MUS_UNDEFINED;
660 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
662 boolean is_image = tci->is_image;
663 int initial = tci->initial;
664 int nr = tci->local_nr;
665 struct TitleFadingInfo ti;
669 int graphic = getTitleScreenGraphic(nr, initial);
671 /* initialize fading control values to default title config settings */
672 ti = (initial ? title_initial_default : title_default);
674 /* override default settings with image config settings, if defined */
675 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
676 ti.fade_mode = graphic_info[graphic].fade_mode;
677 if (graphic_info[graphic].fade_delay > -1)
678 ti.fade_delay = graphic_info[graphic].fade_delay;
679 if (graphic_info[graphic].post_delay > -1)
680 ti.post_delay = graphic_info[graphic].post_delay;
681 if (graphic_info[graphic].auto_delay > -1)
682 ti.auto_delay = graphic_info[graphic].auto_delay;
688 ti.fade_mode = titlemessage_initial[nr].fade_mode;
689 ti.fade_delay = titlemessage_initial[nr].fade_delay;
690 ti.post_delay = titlemessage_initial[nr].post_delay;
691 ti.auto_delay = titlemessage_initial[nr].auto_delay;
695 ti.fade_mode = titlemessage[nr].fade_mode;
696 ti.fade_delay = titlemessage[nr].fade_delay;
697 ti.post_delay = titlemessage[nr].post_delay;
698 ti.auto_delay = titlemessage[nr].auto_delay;
703 if (ti.anim_mode == ANIM_NONE)
704 ti.fade_delay = ti.post_delay = 0;
710 static int compareTitleControlInfo(const void *object1, const void *object2)
712 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
713 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
716 if (tci1->initial != tci2->initial)
717 compare_result = (tci1->initial ? -1 : +1);
718 else if (tci1->sort_priority != tci2->sort_priority)
719 compare_result = tci1->sort_priority - tci2->sort_priority;
720 else if (tci1->is_image != tci2->is_image)
721 compare_result = (tci1->is_image ? -1 : +1);
723 compare_result = tci1->local_nr - tci2->local_nr;
725 return compare_result;
728 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
730 int nr, int sort_priority)
732 title_controls[num_title_screens].is_image = is_image;
733 title_controls[num_title_screens].initial = initial;
734 title_controls[num_title_screens].local_nr = nr;
735 title_controls[num_title_screens].sort_priority = sort_priority;
740 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
744 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
746 int graphic = getTitleScreenGraphic(i, initial);
747 Bitmap *bitmap = graphic_info[graphic].bitmap;
748 int sort_priority = graphic_info[graphic].sort_priority;
751 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
754 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
756 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
757 char *filename = getLevelSetTitleMessageFilename(i, initial);
758 int sort_priority = tmi->sort_priority;
760 if (filename != NULL)
761 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
765 static void InitializeTitleControls(boolean show_title_initial)
767 num_title_screens = 0;
769 if (show_title_initial)
770 InitializeTitleControls_CheckTitleInfo(TRUE);
772 InitializeTitleControls_CheckTitleInfo(FALSE);
774 /* sort title screens according to sort_priority and title number */
775 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
776 compareTitleControlInfo);
779 static boolean visibleMenuPos(struct MenuPosInfo *pos)
781 return (pos != NULL && pos->x != -1 && pos->y != -1);
784 static boolean visibleTextPos(struct TextPosInfo *pos)
786 return (pos != NULL && pos->x != -1 && pos->y != -1);
789 static void InitializeMainControls()
791 boolean local_team_mode = (!options.network && setup.team_mode);
794 /* set main control text values to dynamically determined values */
795 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
797 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
798 menu.main.text.first_level.size));
799 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
800 menu.main.text.last_level.size));
801 strcpy(main_text_level_number, int2str(level_nr,
802 menu.main.text.level_number.size));
804 main_text_level_year = leveldir_current->year;
805 main_text_level_imported_from = leveldir_current->imported_from;
806 main_text_level_imported_by = leveldir_current->imported_by;
807 main_text_level_tested_by = leveldir_current->tested_by;
809 /* set main control screen positions to dynamically determined values */
810 for (i = 0; main_controls[i].nr != -1; i++)
812 struct MainControlInfo *mci = &main_controls[i];
814 struct MenuPosInfo *pos_button = mci->pos_button;
815 struct TextPosInfo *pos_text = mci->pos_text;
816 struct TextPosInfo *pos_input = mci->pos_input;
817 char *text = (mci->text ? *mci->text : NULL);
818 char *input = (mci->input ? *mci->input : NULL);
819 int button_graphic = mci->button_graphic;
821 int font_text = (pos_text ? pos_text->font : -1);
822 int font_input = (pos_input ? pos_input->font : -1);
824 int font_text = mci->font_text;
825 int font_input = mci->font_input;
828 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
829 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
830 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
831 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
832 int text_chars = (text != NULL ? strlen(text) : 0);
833 int input_chars = (input != NULL ? strlen(input) : 0);
836 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
838 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
839 int text_width = font_text_width * text_chars;
840 int text_height = font_text_height;
841 int input_width = font_input_width * input_chars;
842 int input_height = font_input_height;
844 if (nr == MAIN_CONTROL_NAME)
847 if (menu.main.input.name.x == -1)
848 menu.main.input.name.x = menu.main.text.name.x + text_width;
849 if (menu.main.input.name.y == -1)
850 menu.main.input.name.y = menu.main.text.name.y;
854 menu.main.input.name.width = input_width;
855 menu.main.input.name.height = input_height;
857 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
858 menu.main.input.name.height = font_input_height;
862 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
864 if (pos_button->width == 0)
865 pos_button->width = button_width;
866 if (pos_button->height == 0)
867 pos_button->height = button_height;
870 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
872 /* calculate width for non-clickable text -- needed for text alignment */
873 boolean calculate_text_width = (pos_button == NULL && text != NULL);
875 if (visibleMenuPos(pos_button))
877 if (pos_text->x == -1)
878 pos_text->x = pos_button->x + pos_button->width;
879 if (pos_text->y == -1)
880 pos_text->y = pos_button->y;
883 if (pos_text->width == -1 || calculate_text_width)
884 pos_text->width = text_width;
885 if (pos_text->height == -1)
886 pos_text->height = text_height;
889 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
891 if (visibleTextPos(pos_text))
893 if (pos_input->x == -1)
894 pos_input->x = pos_text->x + pos_text->width;
895 if (pos_input->y == -1)
896 pos_input->y = pos_text->y;
899 if (pos_input->width == -1)
900 pos_input->width = input_width;
901 if (pos_input->height == -1)
902 pos_input->height = input_height;
907 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
908 boolean active_input)
912 for (i = 0; main_controls[i].nr != -1; i++)
914 struct MainControlInfo *mci = &main_controls[i];
916 if (mci->nr == nr || nr == -1)
918 struct MenuPosInfo *pos_button = mci->pos_button;
919 struct TextPosInfo *pos_text = mci->pos_text;
920 struct TextPosInfo *pos_input = mci->pos_input;
921 char *text = (mci->text ? *mci->text : NULL);
922 char *input = (mci->input ? *mci->input : NULL);
923 int button_graphic = mci->button_graphic;
925 int font_text = (pos_text ? pos_text->font : -1);
926 int font_input = (pos_input ? pos_input->font : -1);
928 int font_text = mci->font_text;
929 int font_input = mci->font_input;
934 button_graphic = BUTTON_ACTIVE(button_graphic);
935 font_text = FONT_ACTIVE(font_text);
940 font_input = FONT_ACTIVE(font_input);
943 if (visibleMenuPos(pos_button))
945 struct MenuPosInfo *pos = pos_button;
946 int x = mSX + pos->x;
947 int y = mSY + pos->y;
949 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
950 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
953 if (visibleTextPos(pos_text) && text != NULL)
955 struct TextPosInfo *pos = pos_text;
956 int x = mSX + ALIGNED_TEXT_XPOS(pos);
957 int y = mSY + ALIGNED_TEXT_YPOS(pos);
960 /* (check why/if this is needed) */
961 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
963 DrawText(x, y, text, font_text);
966 if (visibleTextPos(pos_input) && input != NULL)
968 struct TextPosInfo *pos = pos_input;
969 int x = mSX + ALIGNED_TEXT_XPOS(pos);
970 int y = mSY + ALIGNED_TEXT_YPOS(pos);
973 /* (check why/if this is needed) */
974 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
976 DrawText(x, y, input, font_input);
982 static void DrawCursorAndText_Main(int nr, boolean active_text)
984 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
988 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
990 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
994 static struct MainControlInfo *getMainControlInfo(int nr)
998 for (i = 0; main_controls[i].nr != -1; i++)
999 if (main_controls[i].nr == nr)
1000 return &main_controls[i];
1005 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1010 int rect_x = ALIGNED_TEXT_XPOS(rect);
1011 int rect_y = ALIGNED_TEXT_YPOS(rect);
1013 return (x >= rect_x && x < rect_x + rect->width &&
1014 y >= rect_y && y < rect_y + rect->height);
1017 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1022 int rect_x = ALIGNED_TEXT_XPOS(rect);
1023 int rect_y = ALIGNED_TEXT_YPOS(rect);
1025 return (x >= rect_x && x < rect_x + rect->width &&
1026 y >= rect_y && y < rect_y + rect->height);
1029 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1031 static int cursor_array[SCR_FIELDY];
1032 int x = mSX + TILEX * xpos;
1033 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1038 cursor_array[ypos] = graphic;
1040 graphic = cursor_array[ypos];
1044 graphic = BUTTON_ACTIVE(graphic);
1046 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1047 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1050 static void initCursor(int ypos, int graphic)
1052 drawCursorExt(0, ypos, FALSE, graphic);
1055 static void drawCursor(int ypos, boolean active)
1057 drawCursorExt(0, ypos, active, -1);
1060 static void drawCursorXY(int xpos, int ypos, int graphic)
1062 drawCursorExt(xpos, ypos, FALSE, graphic);
1065 static void drawChooseTreeCursor(int ypos, boolean active)
1067 int last_game_status = game_status; /* save current game status */
1070 /* force LEVELS draw offset on artwork setup screen */
1071 game_status = GAME_MODE_LEVELS;
1074 drawCursorExt(0, ypos, active, -1);
1076 game_status = last_game_status; /* restore current game status */
1081 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1082 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1086 static int getPrevlevelButtonPos()
1091 static int getCurrentLevelTextPos()
1093 return (getPrevlevelButtonPos() + 1);
1096 static int getNextLevelButtonPos()
1098 return getPrevlevelButtonPos() + 3 + 1;
1101 static int getLevelRangeTextPos()
1103 return getNextLevelButtonPos() + 1;
1107 int effectiveGameStatus()
1109 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1110 return GAME_MODE_TITLE;
1115 void DrawTitleScreenImage(int nr, boolean initial)
1117 int graphic = getTitleScreenGraphic(nr, initial);
1118 Bitmap *bitmap = graphic_info[graphic].bitmap;
1120 int width = graphic_info[graphic].width;
1121 int height = graphic_info[graphic].height;
1122 int src_x = graphic_info[graphic].src_x;
1123 int src_y = graphic_info[graphic].src_y;
1125 int width = graphic_info[graphic].src_image_width;
1126 int height = graphic_info[graphic].src_image_height;
1127 int src_x = 0, src_y = 0;
1134 if (width > WIN_XSIZE)
1136 /* image width too large for window => center image horizontally */
1137 src_x = (width - WIN_XSIZE) / 2;
1141 if (height > WIN_YSIZE)
1143 /* image height too large for window => center image vertically */
1144 src_y = (height - WIN_YSIZE) / 2;
1148 /* always display title screens centered */
1149 dst_x = (WIN_XSIZE - width) / 2;
1150 dst_y = (WIN_YSIZE - height) / 2;
1152 SetDrawBackgroundMask(REDRAW_ALL);
1153 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1155 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1157 if (DrawingOnBackground(dst_x, dst_y))
1158 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1160 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1162 redraw_mask = REDRAW_ALL;
1164 /* reset fading control values to default config settings */
1168 title = getTitleFading(nr, initial, TRUE);
1173 title.fade_delay_final = title.fade_delay;
1174 title.post_delay_final = title.post_delay;
1175 title.auto_delay_final = title.auto_delay;
1177 /* override default settings with image config settings, if defined */
1178 if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
1179 title.anim_mode = graphic_info[graphic].anim_mode;
1180 if (graphic_info[graphic].fade_delay > -1)
1181 title.fade_delay = graphic_info[graphic].fade_delay;
1182 if (graphic_info[graphic].post_delay > -1)
1183 title.post_delay = graphic_info[graphic].post_delay;
1184 if (graphic_info[graphic].auto_delay > -1)
1185 title.auto_delay = graphic_info[graphic].auto_delay;
1189 void DrawTitleScreenMessage(int nr, boolean initial)
1191 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1192 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1194 int font_nr = FONT_TEXT_1;
1198 int pad_y = 32 + 14;
1201 int max_chars_per_line;
1202 int max_lines_per_screen;
1204 int last_game_status = game_status; /* save current game status */
1206 if (filename == NULL)
1209 /* force TITLE font on title message screen */
1210 game_status = getTitleMessageGameMode(initial);
1212 /* if chars set to "-1", automatically determine by text and font width */
1213 if (tmi->chars == -1)
1214 tmi->chars = tmi->width / getFontWidth(tmi->font);
1216 tmi->width = tmi->chars * getFontWidth(tmi->font);
1218 /* if lines set to "-1", automatically determine by text and font height */
1219 if (tmi->lines == -1)
1220 tmi->lines = tmi->height / getFontHeight(tmi->font);
1222 tmi->height = tmi->lines * getFontHeight(tmi->font);
1224 SetDrawBackgroundMask(REDRAW_ALL);
1225 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1227 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1230 font_width = getFontWidth(font_nr);
1231 font_height = getFontHeight(font_nr);
1232 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1233 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1237 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1238 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1239 tmi->autowrap, tmi->centered, tmi->parse_comments);
1241 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1242 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1243 tmi->parse_comments);
1246 game_status = last_game_status; /* restore current game status */
1249 void DrawTitleScreen()
1251 KeyboardAutoRepeatOff();
1254 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1257 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1262 boolean CheckTitleScreen(boolean levelset_has_changed)
1264 static boolean show_title_initial = TRUE;
1265 boolean show_titlescreen = FALSE;
1267 /* needed to be able to skip title screen, if no image or message defined */
1268 InitializeTitleControls(show_title_initial);
1270 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1271 show_titlescreen = TRUE;
1273 /* show initial title images and messages only once at program start */
1274 show_title_initial = FALSE;
1276 return (show_titlescreen && num_title_screens > 0);
1279 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1281 static LevelDirTree *leveldir_last_valid = NULL;
1282 boolean levelset_has_changed = FALSE;
1284 boolean local_team_mode = (!options.network && setup.team_mode);
1285 char *name_text = (local_team_mode ? "Team:" : "Name:");
1286 int name_width, level_width;
1293 /* !!! CHANGE THIS !!! */
1294 title = title_default;
1299 int graphicA = element_info[EL_EM_DYNAMITE_ACTIVE].special_graphic[GFX_SPECIAL_ARG_EDITOR];
1300 int graphicB = element_info[EL_EM_DYNAMITE_ACTIVE].special_graphic[GFX_SPECIAL_ARG_PANEL];
1301 int graphic1 = element_info[EL_CONVEYOR_BELT_1_MIDDLE].special_graphic[GFX_SPECIAL_ARG_EDITOR];
1302 int graphic2 = element_info[EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE].special_graphic[GFX_SPECIAL_ARG_EDITOR];
1304 printf("::: %d [%d] -> %d, %d [%d, %d]\n",
1306 graphic_info[graphicA].src_x,
1307 graphic_info[graphicA].src_y,
1308 graphic1, graphic2);
1313 printf("::: %d, %d\n", fading.anim_mode == ANIM_CROSSFADE,
1314 redraw_mask == REDRAW_ALL);
1317 FadeSetLeaveScreen();
1319 /* (does not work well when changing to editor, which fades out itself) */
1321 FadeOut(redraw_mask);
1325 FadeSoundsAndMusic();
1327 KeyboardAutoRepeatOn();
1330 SetDrawDeactivationMask(REDRAW_NONE);
1331 SetDrawBackgroundMask(REDRAW_FIELD);
1333 audio.sound_deactivated = FALSE;
1337 /* needed if last screen was the playing screen, invoked from level editor */
1338 if (level_editor_test_game)
1340 game_status = GAME_MODE_EDITOR;
1347 FadeOut(redraw_mask);
1350 /* needed if last screen was the editor screen */
1351 UndrawSpecialEditorDoor();
1353 /* needed if last screen was the setup screen and fullscreen state changed */
1354 ToggleFullscreenIfNeeded();
1356 /* leveldir_current may be invalid (level group, parent link) */
1357 if (!validLevelSeries(leveldir_current))
1358 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1360 if (leveldir_current != leveldir_last_valid)
1361 levelset_has_changed = TRUE;
1363 /* store valid level series information */
1364 leveldir_last_valid = leveldir_current;
1366 /* needed if last screen (level choice) changed graphics, sounds or music */
1367 ReloadCustomArtwork(0);
1369 #if defined(TARGET_SDL)
1370 SetDrawtoField(DRAW_BACKBUFFER);
1374 if (levelset_has_changed)
1375 fading = title_default;
1379 if (CheckTitleScreen(levelset_has_changed))
1381 game_status = GAME_MODE_TITLE;
1390 if (setup.show_titlescreen &&
1391 ((levelset_has_changed &&
1392 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1393 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1394 (show_title_initial &&
1395 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1396 getLevelSetMessageFilename(1, TRUE) != NULL))))
1398 game_status = GAME_MODE_TITLE;
1406 /* level_nr may have been set to value over handicap with level editor */
1407 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1408 level_nr = leveldir_current->handicap_level;
1410 LoadLevel(level_nr);
1412 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1415 FadeOut(redraw_mask);
1419 if (redraw_mask == REDRAW_ALL)
1422 int door_state = GetDoorState();
1427 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1431 OpenDoor(DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1433 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1442 InitializeMainControls();
1445 DrawCursorAndText_Main(-1, FALSE);
1447 for (i = 0; main_controls[i].nr != -1; i++)
1449 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1450 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1451 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1452 char *text = main_controls[i].text;
1453 char *input = main_controls[i].input;
1454 int button_graphic = main_controls[i].button_graphic;
1455 int font_text = main_controls[i].font_text;
1456 int font_input = main_controls[i].font_input;
1458 if (pos_button != NULL)
1459 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1462 if (pos_text != NULL && text != NULL)
1463 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1465 if (pos_input != NULL && input != NULL)
1466 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1474 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1475 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1476 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1477 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1478 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1479 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1480 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1481 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1483 /* calculated after (possible) reload of custom artwork */
1484 name_width = getTextWidth(name_text, FONT_MENU_1);
1485 level_width = 9 * 32;
1487 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1490 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1491 int2str(level_nr, 3), FONT_VALUE_1);
1494 int text_height = getFontHeight(FONT_TEXT_3);
1495 int xpos = getLevelRangeTextPos() * 32 + 8;
1496 int ypos2 = 3 * 32 + 16;
1497 int ypos1 = ypos2 - text_height;
1499 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1500 "%03d", leveldir_current->first_level);
1501 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1502 "%03d", leveldir_current->last_level);
1505 for (i = 0; i < 8; i++)
1506 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1509 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1512 DrawPreviewLevel(TRUE);
1514 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1517 if (TAPE_IS_EMPTY(tape))
1519 DrawCompleteVideoDisplay();
1524 /* create gadgets for main menu screen */
1525 FreeScreenGadgets();
1526 CreateScreenGadgets();
1529 BlitBitmap(drawto, window, VX, VY, VXSIZE, VYSIZE, VX, VY);
1533 /* map gadgets for main menu screen */
1535 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1538 DrawMaskedBorder(REDRAW_ALL);
1542 if (redraw_mask == REDRAW_ALL)
1544 int door_state = GetDoorState();
1546 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1552 game_status = GAME_MODE_PSEUDO_PREVIEW;
1554 DrawText(20, 400, "text_3.PREVIEW", FONT_TEXT_3);
1555 DrawText(20, 420, "text_4.PREVIEW", FONT_TEXT_4);
1557 game_status = GAME_MODE_MAIN;
1559 DrawText(20, 440, "text_3.MAIN", FONT_TEXT_3);
1560 DrawText(20, 460, "text_4.MAIN", FONT_TEXT_4);
1565 FadeIn(redraw_mask);
1570 else if (fading.anim_mode == ANIM_CROSSFADE)
1571 FadeCross(redraw_mask);
1573 FadeIn(redraw_mask);
1576 FadeIn(redraw_mask);
1585 fading = title_default;
1588 SetMouseCursor(CURSOR_DEFAULT);
1592 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1595 void DrawAndFadeInMainMenu(int redraw_mask)
1597 DrawMainMenuExt(redraw_mask, TRUE);
1602 DrawMainMenuExt(REDRAW_ALL, FALSE);
1606 static void gotoTopLevelDir()
1608 /* move upwards to top level directory */
1609 while (leveldir_current->node_parent)
1611 /* write a "path" into level tree for easy navigation to last level */
1612 if (leveldir_current->node_parent->node_group->cl_first == -1)
1614 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1615 int leveldir_pos = posTreeInfo(leveldir_current);
1616 int num_page_entries;
1617 int cl_first, cl_cursor;
1619 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1620 num_page_entries = num_leveldirs;
1622 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1624 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1625 cl_cursor = leveldir_pos - cl_first;
1627 leveldir_current->node_parent->node_group->cl_first = cl_first;
1628 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1631 leveldir_current = leveldir_current->node_parent;
1636 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1638 static unsigned long title_delay = 0;
1639 static int title_screen_nr = 0;
1640 static int last_sound = -1, last_music = -1;
1641 boolean return_to_main_menu = FALSE;
1642 boolean use_fading_main_menu = TRUE;
1645 boolean use_cross_fading = FALSE;
1647 boolean use_cross_fading = !show_title_initial; /* default */
1650 struct TitleControlInfo *tci;
1651 struct TitleFadingInfo fading_default;
1652 struct TitleFadingInfo fading_last = fading;
1653 struct TitleFadingInfo fading_next;
1656 if (button == MB_MENU_INITIALIZE)
1659 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1663 int last_game_status = game_status; /* save current game status */
1667 title_screen_nr = 0;
1668 tci = &title_controls[title_screen_nr];
1670 last_sound = SND_UNDEFINED;
1671 last_music = MUS_UNDEFINED;
1674 /* determine number of title screens to display (images and messages) */
1675 InitializeTitleControls();
1678 if (game_status == GAME_MODE_INFO)
1680 if (num_title_screens == 0)
1682 DrawInfoScreen_NotAvailable("Title screen information:",
1683 "No title screen for this level set.");
1686 /* use default settings for fading, but always disable auto delay */
1687 fading = title_default;
1688 fading.auto_delay = -1;
1694 FadeSoundsAndMusic();
1697 FadeOut(REDRAW_ALL);
1702 DrawTitleScreenImage(tci->local_nr, tci->initial);
1704 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1706 fading_default = (tci->initial ? title_initial_default : title_default);
1708 fading = fading_next = getTitleFading(tci);
1712 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1713 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1715 fading.fade_mode = FADE_MODE_FADE;
1716 fading.fade_delay = fading_default.fade_delay;
1719 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1720 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1721 fading.fade_mode = FADE_MODE_FADE;
1726 sound = getTitleSound(tci);
1727 music = getTitleMusic(tci);
1729 if (sound != last_sound)
1730 PlayMenuSoundExt(sound);
1731 if (music != last_music)
1732 PlayMenuMusicExt(music);
1738 SetMouseCursor(CURSOR_NONE);
1740 // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
1746 fading = fading_next;
1748 DelayReached(&title_delay, 0); /* reset delay counter */
1754 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1755 button = MB_MENU_CHOICE;
1757 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1758 button = MB_MENU_CHOICE;
1761 if (button == MB_MENU_LEAVE)
1763 return_to_main_menu = TRUE;
1764 use_fading_main_menu = FALSE;
1766 else if (button == MB_MENU_CHOICE)
1769 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1772 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1775 FadeOut(REDRAW_FIELD);
1778 FadeSetEnterScreen();
1780 info_mode = INFO_MODE_MAIN;
1781 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1787 tci = &title_controls[title_screen_nr];
1789 if (title_screen_nr < num_title_screens)
1793 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1800 graphic_info[getTitleScreenGraphic(tci->local_nr,
1801 tci->initial)].anim_mode;
1803 anim_mode = ANIM_FADE; /* ??? */
1805 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1806 anim_mode == ANIM_CROSSFADE ? TRUE :
1810 sound = getTitleSound(tci);
1811 music = getTitleMusic(tci);
1813 if (sound == SND_UNDEFINED || sound != last_sound)
1815 if (music == MUS_UNDEFINED || music != last_music)
1819 FadeOut(REDRAW_ALL);
1823 DrawTitleScreenImage(tci->local_nr, tci->initial);
1825 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1827 fading_next = getTitleFading(tci);
1830 sound = getTitleSound(tci);
1831 music = getTitleMusic(tci);
1833 if (sound != last_sound)
1834 PlayMenuSoundExt(sound);
1835 if (music != last_music)
1836 PlayMenuMusicExt(music);
1843 printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1847 /* last screen already faded out, next screen has no animation */
1848 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1849 fading_next.fade_mode == FADE_MODE_NONE)
1850 fading = fading_next;
1852 /* last screen already faded out, next screen has no animation */
1853 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1854 fading_next.fade_mode == FADE_MODE_NONE)
1855 fading = fading_next;
1862 fading = fading_next;
1864 DelayReached(&title_delay, 0); /* reset delay counter */
1868 FadeSoundsAndMusic();
1874 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1878 FadeOut(REDRAW_ALL);
1882 FadeOut(REDRAW_ALL);
1886 return_to_main_menu = TRUE;
1890 if (return_to_main_menu)
1896 SetMouseCursor(CURSOR_DEFAULT);
1898 if (game_status == GAME_MODE_INFO)
1901 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1904 info_mode = INFO_MODE_MAIN;
1905 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1907 else /* default: return to main menu */
1910 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1913 game_status = GAME_MODE_MAIN;
1914 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1919 void HandleMainMenu_SelectLevel(int step, int direction)
1921 int old_level_nr = level_nr;
1924 new_level_nr = old_level_nr + step * direction;
1925 if (new_level_nr < leveldir_current->first_level)
1926 new_level_nr = leveldir_current->first_level;
1927 if (new_level_nr > leveldir_current->last_level)
1928 new_level_nr = leveldir_current->last_level;
1930 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1932 /* skipping levels is only allowed when trying to skip single level */
1933 if (setup.skip_levels && step == 1 &&
1934 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1936 leveldir_current->handicap_level++;
1937 SaveLevelSetup_SeriesInfo();
1940 new_level_nr = leveldir_current->handicap_level;
1943 if (new_level_nr != old_level_nr)
1945 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1947 PlaySound(SND_MENU_ITEM_SELECTING);
1949 level_nr = new_level_nr;
1952 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1953 int2str(level_nr, menu.main.text.level_number.size),
1954 mci->pos_text->font);
1956 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1959 LoadLevel(level_nr);
1960 DrawPreviewLevel(TRUE);
1964 DrawCompleteVideoDisplay();
1966 /* needed because DrawPreviewLevel() takes some time */
1974 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1976 static int choice = MAIN_CONTROL_GAME;
1980 if (button == MB_MENU_INITIALIZE)
1982 DrawCursorAndText_Main(choice, TRUE);
1987 if (mx || my) /* mouse input */
1991 for (i = 0; main_controls[i].nr != -1; i++)
1993 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1994 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1995 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1997 pos = main_controls[i].nr;
2003 else if (dx || dy) /* keyboard input */
2005 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2006 choice == MAIN_CONTROL_SETUP))
2007 button = MB_MENU_CHOICE;
2012 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
2014 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2016 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2022 PlaySound(SND_MENU_ITEM_ACTIVATING);
2024 DrawCursorAndText_Main(choice, FALSE);
2025 DrawCursorAndText_Main(pos, TRUE);
2032 PlaySound(SND_MENU_ITEM_SELECTING);
2034 if (pos == MAIN_CONTROL_NAME)
2036 game_status = GAME_MODE_PSEUDO_TYPENAME;
2038 HandleTypeName(strlen(setup.player_name), 0);
2040 else if (pos == MAIN_CONTROL_LEVELS)
2044 game_status = GAME_MODE_LEVELS;
2046 SaveLevelSetup_LastSeries();
2047 SaveLevelSetup_SeriesInfo();
2056 else if (pos == MAIN_CONTROL_SCORES)
2058 game_status = GAME_MODE_SCORES;
2062 else if (pos == MAIN_CONTROL_EDITOR)
2064 if (leveldir_current->readonly &&
2065 !strEqual(setup.player_name, "Artsoft"))
2066 Request("This level is read only !", REQ_CONFIRM);
2068 game_status = GAME_MODE_EDITOR;
2070 FadeSetEnterScreen();
2074 else if (pos == MAIN_CONTROL_INFO)
2076 game_status = GAME_MODE_INFO;
2077 info_mode = INFO_MODE_MAIN;
2080 fading = menu.navigation;
2085 else if (pos == MAIN_CONTROL_GAME)
2087 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2089 else if (pos == MAIN_CONTROL_SETUP)
2091 game_status = GAME_MODE_SETUP;
2092 setup_mode = SETUP_MODE_MAIN;
2096 else if (pos == MAIN_CONTROL_QUIT)
2098 SaveLevelSetup_LastSeries();
2099 SaveLevelSetup_SeriesInfo();
2101 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2102 game_status = GAME_MODE_QUIT;
2107 if (game_status == GAME_MODE_MAIN)
2109 DrawPreviewLevel(FALSE);
2116 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2118 static int choice = 5;
2122 if (button == MB_MENU_INITIALIZE)
2124 drawCursor(choice, TRUE);
2129 if (mx || my) /* mouse input */
2131 x = (mx - mSX) / 32;
2132 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2134 else if (dx || dy) /* keyboard input */
2136 if (dx && choice == 1)
2137 x = (dx < 0 ? 10 : 14);
2140 if (choice == 4 || choice == 6)
2141 button = MB_MENU_CHOICE;
2147 if (y == 1 && dx != 0 && button)
2149 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2151 else if (IN_VIS_FIELD(x, y) &&
2152 y >= 0 && y <= 7 && (y != 1 || x < 10))
2158 drawCursor(choice, FALSE);
2159 drawCursor(y, TRUE);
2168 game_status = GAME_MODE_PSEUDO_TYPENAME;
2169 HandleTypeName(strlen(setup.player_name), 0);
2175 game_status = GAME_MODE_LEVELS;
2177 SaveLevelSetup_LastSeries();
2178 SaveLevelSetup_SeriesInfo();
2189 game_status = GAME_MODE_SCORES;
2194 if (leveldir_current->readonly &&
2195 !strEqual(setup.player_name, "Artsoft"))
2196 Request("This level is read only !", REQ_CONFIRM);
2197 game_status = GAME_MODE_EDITOR;
2202 game_status = GAME_MODE_INFO;
2203 info_mode = INFO_MODE_MAIN;
2208 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2212 game_status = GAME_MODE_SETUP;
2213 setup_mode = SETUP_MODE_MAIN;
2219 SaveLevelSetup_LastSeries();
2220 SaveLevelSetup_SeriesInfo();
2222 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2223 game_status = GAME_MODE_QUIT;
2228 if (game_status == GAME_MODE_MAIN)
2230 DrawPreviewLevel(FALSE);
2238 /* ========================================================================= */
2239 /* info screen functions */
2240 /* ========================================================================= */
2242 static struct TokenInfo *info_info;
2243 static int num_info_info;
2245 static void execInfoTitleScreen()
2248 FadeSetEnterScreen();
2251 info_mode = INFO_MODE_TITLE;
2255 static void execInfoElements()
2258 FadeSetEnterScreen();
2261 info_mode = INFO_MODE_ELEMENTS;
2265 static void execInfoMusic()
2268 FadeSetEnterScreen();
2271 info_mode = INFO_MODE_MUSIC;
2275 static void execInfoCredits()
2278 FadeSetEnterScreen();
2281 info_mode = INFO_MODE_CREDITS;
2285 static void execInfoProgram()
2288 FadeSetEnterScreen();
2291 info_mode = INFO_MODE_PROGRAM;
2295 static void execInfoVersion()
2298 FadeSetEnterScreen();
2301 info_mode = INFO_MODE_VERSION;
2305 static void execInfoLevelSet()
2308 FadeSetEnterScreen();
2311 info_mode = INFO_MODE_LEVELSET;
2315 static void execExitInfo()
2321 game_status = GAME_MODE_MAIN;
2323 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2329 static struct TokenInfo info_info_main[] =
2331 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2332 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2333 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2334 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2335 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2336 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2337 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2338 { TYPE_EMPTY, NULL, "" },
2339 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2344 static void DrawCursorAndText_Info(int pos, boolean active)
2346 int xpos = MENU_SCREEN_START_XPOS;
2347 int ypos = MENU_SCREEN_START_YPOS + pos;
2348 int font_nr = FONT_MENU_1;
2351 font_nr = FONT_ACTIVE(font_nr);
2353 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2355 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2356 drawCursor(pos, active);
2359 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2364 CloseDoor(DOOR_CLOSE_2);
2366 /* (needed after displaying title screens which disable auto repeat) */
2367 KeyboardAutoRepeatOn();
2369 FadeSetLeaveScreen();
2372 FadeOut(redraw_mask);
2376 if (redraw_mask == REDRAW_ALL)
2379 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2385 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2387 info_info = info_info_main;
2390 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2393 int xpos = MENU_SCREEN_START_XPOS;
2394 int ypos = MENU_SCREEN_START_YPOS + i;
2395 int font_nr = FONT_MENU_1;
2398 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2399 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2400 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2401 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2402 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2403 initCursor(i, IMG_MENU_BUTTON);
2406 DrawCursorAndText_Info(i, FALSE);
2408 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2414 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2419 DrawMaskedBorder(redraw_mask);
2422 FadeIn(redraw_mask);
2427 else if (fading.anim_mode == ANIM_CROSSFADE)
2428 FadeCross(redraw_mask);
2430 FadeIn(redraw_mask);
2433 FadeIn(redraw_mask);
2442 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2444 static int choice_store[MAX_INFO_MODES];
2445 int choice = choice_store[info_mode]; /* always starts with 0 */
2449 if (button == MB_MENU_INITIALIZE)
2451 /* advance to first valid menu entry */
2452 while (choice < num_info_info &&
2453 info_info[choice].type & TYPE_SKIP_ENTRY)
2455 choice_store[info_mode] = choice;
2458 DrawCursorAndText_Info(choice, TRUE);
2460 drawCursor(choice, TRUE);
2465 else if (button == MB_MENU_LEAVE)
2467 for (y = 0; y < num_info_info; y++)
2469 if (info_info[y].type & TYPE_LEAVE_MENU)
2471 void (*menu_callback_function)(void) = info_info[y].value;
2475 menu_callback_function();
2477 break; /* absolutely needed because function changes 'info_info'! */
2484 if (mx || my) /* mouse input */
2486 x = (mx - mSX) / 32;
2487 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2489 else if (dx || dy) /* keyboard input */
2493 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2495 if (info_info[choice].type & menu_navigation_type ||
2496 info_info[choice].type & TYPE_ENTER_SCREEN ||
2497 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2498 button = MB_MENU_CHOICE;
2503 /* jump to next non-empty menu entry (up or down) */
2504 while (y > 0 && y < num_info_info - 1 &&
2505 info_info[y].type & TYPE_SKIP_ENTRY)
2509 if (IN_VIS_FIELD(x, y) &&
2510 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2516 PlaySound(SND_MENU_ITEM_ACTIVATING);
2519 DrawCursorAndText_Info(choice, FALSE);
2520 DrawCursorAndText_Info(y, TRUE);
2522 drawCursor(choice, FALSE);
2523 drawCursor(y, TRUE);
2526 choice = choice_store[info_mode] = y;
2529 else if (!(info_info[y].type & TYPE_GHOSTED))
2531 PlaySound(SND_MENU_ITEM_SELECTING);
2533 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2535 void (*menu_callback_function)(void) = info_info[choice].value;
2537 FadeSetFromType(info_info[y].type);
2539 menu_callback_function();
2545 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2548 int ystart1 = mSY - SY + 100;
2549 int ystart2 = mSY - SY + 150;
2550 int ybottom = mSY - SY + SYSIZE - 20;
2554 int ybottom = SYSIZE - 20;
2557 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2560 FadeOut(REDRAW_FIELD);
2566 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2567 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2569 DrawTextSCentered(ybottom, FONT_TEXT_4,
2570 "Press any key or button for info menu");
2573 FadeIn(REDRAW_FIELD);
2577 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2579 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2580 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2581 int xstart = mSX + 16;
2582 int ystart1 = mSY - SY + 100;
2583 int ystart2 = mSY + 64 + 2 * 32;
2584 int ybottom = mSY - SY + SYSIZE - 20;
2585 int ystep = TILEY + 4;
2586 int element, action, direction;
2594 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2595 infoscreen_step[i] = infoscreen_frame[i] = 0;
2600 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2602 DrawTextSCentered(ybottom, FONT_TEXT_4,
2603 "Press any key or button for next page");
2609 while (helpanim_info[j].element != HELPANIM_LIST_END)
2611 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2616 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2625 j += infoscreen_step[i - start];
2627 element = helpanim_info[j].element;
2628 action = helpanim_info[j].action;
2629 direction = helpanim_info[j].direction;
2632 element = EL_UNKNOWN;
2634 if (action != -1 && direction != -1)
2635 graphic = el_act_dir2img(element, action, direction);
2636 else if (action != -1)
2637 graphic = el_act2img(element, action);
2638 else if (direction != -1)
2639 graphic = el_dir2img(element, direction);
2641 graphic = el2img(element);
2643 delay = helpanim_info[j++].delay;
2648 if (infoscreen_frame[i - start] == 0)
2651 infoscreen_frame[i - start] = delay - 1;
2655 sync_frame = delay - infoscreen_frame[i - start];
2656 infoscreen_frame[i - start]--;
2659 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2661 if (!infoscreen_frame[i - start])
2662 infoscreen_step[i - start] = 0;
2666 if (!infoscreen_frame[i - start])
2667 infoscreen_step[i - start]++;
2668 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2674 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2676 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2677 graphic, sync_frame, USE_MASKING);
2680 DrawInfoScreen_HelpText(element, action, direction, i - start);
2685 redraw_mask |= REDRAW_FIELD;
2690 static char *getHelpText(int element, int action, int direction)
2692 char token[MAX_LINE_LEN];
2694 strcpy(token, element_info[element].token_name);
2697 strcat(token, element_action_info[action].suffix);
2699 if (direction != -1)
2700 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2702 return getHashEntry(helptext_info, token);
2705 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2708 int font_nr = FONT_INFO_ELEMENTS;
2710 int font_nr = FONT_LEVEL_NUMBER;
2712 int font_width = getFontWidth(font_nr);
2713 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2714 int sy = mSY + 65 + 2 * 32 + 1;
2715 int ystep = TILEY + 4;
2716 int pad_x = sx - SX;
2717 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2718 int max_lines_per_text = 2;
2721 if (action != -1 && direction != -1) /* element.action.direction */
2722 text = getHelpText(element, action, direction);
2724 if (text == NULL && action != -1) /* element.action */
2725 text = getHelpText(element, action, -1);
2727 if (text == NULL && direction != -1) /* element.direction */
2728 text = getHelpText(element, -1, direction);
2730 if (text == NULL) /* base element */
2731 text = getHelpText(element, -1, -1);
2733 if (text == NULL) /* not found */
2734 text = "No description available";
2736 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2737 sy += getFontHeight(font_nr) / 2;
2740 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2741 max_chars_per_line, -1, max_lines_per_text, -1,
2742 TRUE, FALSE, FALSE);
2744 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2745 max_chars_per_line, max_lines_per_text);
2749 void DrawInfoScreen_TitleScreen()
2754 void HandleInfoScreen_TitleScreen(int button)
2756 HandleTitleScreen(0, 0, 0, 0, button);
2759 void DrawInfoScreen_Elements()
2761 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2764 FadeOut(REDRAW_FIELD);
2770 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2773 FadeIn(REDRAW_FIELD);
2779 void HandleInfoScreen_Elements(int button)
2781 static unsigned long info_delay = 0;
2782 static int num_anims;
2783 static int num_pages;
2785 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2788 if (button == MB_MENU_INITIALIZE)
2790 boolean new_element = TRUE;
2794 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2796 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2798 else if (new_element)
2801 new_element = FALSE;
2805 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2809 if (button == MB_MENU_LEAVE)
2811 PlaySound(SND_MENU_ITEM_SELECTING);
2813 info_mode = INFO_MODE_MAIN;
2818 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2820 if (button != MB_MENU_INITIALIZE)
2822 PlaySound(SND_MENU_ITEM_SELECTING);
2827 if (page >= num_pages)
2829 FadeSoundsAndMusic();
2832 FadeOut(REDRAW_FIELD);
2835 info_mode = INFO_MODE_MAIN;
2836 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2841 if (button != MB_MENU_INITIALIZE)
2842 FadeCrossSaveBackbuffer();
2844 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2846 if (button != MB_MENU_INITIALIZE)
2847 FadeCross(REDRAW_FIELD);
2851 if (DelayReached(&info_delay, GameFrameDelay))
2852 if (page < num_pages)
2853 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2855 PlayMenuSoundIfLoop();
2859 void DrawInfoScreen_Music()
2861 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2864 FadeOut(REDRAW_FIELD);
2872 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2875 FadeIn(REDRAW_FIELD);
2879 void HandleInfoScreen_Music(int button)
2881 static struct MusicFileInfo *list = NULL;
2882 int ystart1 = mSY - SY + 100;
2883 int ystart2 = mSY - SY + 150;
2884 int ybottom = mSY - SY + SYSIZE - 20;
2887 if (button == MB_MENU_INITIALIZE)
2889 list = music_file_info;
2893 FadeSoundsAndMusic();
2898 DrawTextSCentered(ystart1, FONT_TEXT_1,
2899 "No music info for this level set.");
2901 DrawTextSCentered(ybottom, FONT_TEXT_4,
2902 "Press any key or button for info menu");
2908 if (button == MB_MENU_LEAVE)
2910 PlaySound(SND_MENU_ITEM_SELECTING);
2912 FadeSoundsAndMusic();
2914 info_mode = INFO_MODE_MAIN;
2919 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2923 if (button != MB_MENU_INITIALIZE)
2925 PlaySound(SND_MENU_ITEM_SELECTING);
2933 FadeSoundsAndMusic();
2936 FadeOut(REDRAW_FIELD);
2939 info_mode = INFO_MODE_MAIN;
2940 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2945 FadeSoundsAndMusic();
2947 if (button != MB_MENU_INITIALIZE)
2948 FadeCrossSaveBackbuffer();
2955 int sound = list->music;
2957 if (sound_info[sound].loop)
2958 PlaySoundLoop(sound);
2962 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2966 PlayMusic(list->music);
2968 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2971 if (!strEqual(list->title, UNKNOWN_NAME))
2973 if (!strEqual(list->title_header, UNKNOWN_NAME))
2974 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2976 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2979 if (!strEqual(list->artist, UNKNOWN_NAME))
2981 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2982 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2984 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2986 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2989 if (!strEqual(list->album, UNKNOWN_NAME))
2991 if (!strEqual(list->album_header, UNKNOWN_NAME))
2992 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2994 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2996 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2999 if (!strEqual(list->year, UNKNOWN_NAME))
3001 if (!strEqual(list->year_header, UNKNOWN_NAME))
3002 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
3004 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
3006 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
3009 DrawTextSCentered(ybottom, FONT_TEXT_4,
3010 "Press any key or button for next page");
3012 if (button != MB_MENU_INITIALIZE)
3013 FadeCross(REDRAW_FIELD);
3016 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3017 PlaySoundLoop(list->music);
3020 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
3022 int ystart1 = mSY - SY + 100;
3023 int ystart2 = mSY - SY + 150;
3024 int ybottom = mSY - SY + SYSIZE - 20;
3033 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
3037 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3038 "Special thanks to");
3039 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3041 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3043 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3044 "\"Boulder Dash\"");
3045 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3047 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3049 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3051 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3052 "First Star Software");
3054 else if (screen_nr == 1)
3056 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3057 "Special thanks to");
3058 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3059 "Klaus Heinz & Volker Wertich");
3060 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3062 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3063 "\"Emerald Mine\"");
3064 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3066 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3068 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3070 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3073 else if (screen_nr == 2)
3075 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3076 "Special thanks to");
3077 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3078 "Michael Stopp & Philip Jespersen");
3079 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3081 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3083 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3085 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3087 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3089 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3090 "Digital Integration");
3092 else if (screen_nr == 3)
3094 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3095 "Special thanks to");
3096 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3097 "Hiroyuki Imabayashi");
3098 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3100 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3102 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3104 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3106 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3108 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3111 else if (screen_nr == 4)
3113 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3114 "Special thanks to");
3115 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3117 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3119 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3120 "Jürgen Bonhagen");
3121 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3122 "for the continuous creation");
3123 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3124 "of outstanding level sets");
3126 else if (screen_nr == 5)
3128 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3130 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3132 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3133 "for ideas and inspiration by");
3134 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3137 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3139 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3141 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3142 "for ideas and inspiration by");
3143 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3146 else if (screen_nr == 6)
3148 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3150 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3152 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3153 "for the new Emerald Mine engine");
3155 else if (screen_nr == 7)
3157 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3159 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3161 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3162 "for the initial DOS port");
3164 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3166 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3168 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3169 "for some additional toons");
3171 else if (screen_nr == 8)
3173 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3174 "And not to forget:");
3175 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3177 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3178 "All those who contributed");
3179 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3180 "levels to this game");
3181 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3191 DrawTextSCentered(ybottom, FONT_TEXT_4,
3192 "Press any key or button for next page");
3197 void DrawInfoScreen_Credits()
3199 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3201 FadeSoundsAndMusic();
3204 FadeOut(REDRAW_FIELD);
3207 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3210 FadeIn(REDRAW_FIELD);
3214 void HandleInfoScreen_Credits(int button)
3216 static int screen_nr = 0;
3218 if (button == MB_MENU_INITIALIZE)
3222 DrawInfoScreen_CreditsScreen(screen_nr);
3224 else if (button == MB_MENU_LEAVE)
3226 PlaySound(SND_MENU_ITEM_SELECTING);
3228 info_mode = INFO_MODE_MAIN;
3233 else if (button == MB_MENU_CHOICE)
3235 boolean show_screen;
3237 PlaySound(SND_MENU_ITEM_SELECTING);
3241 FadeCrossSaveBackbuffer();
3243 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3247 FadeCross(REDRAW_FIELD);
3251 FadeSoundsAndMusic();
3254 FadeOut(REDRAW_FIELD);
3257 info_mode = INFO_MODE_MAIN;
3258 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3263 PlayMenuSoundIfLoop();
3267 void DrawInfoScreen_Program()
3269 int ystart1 = mSY - SY + 100;
3270 int ystart2 = mSY - SY + 150;
3271 int ybottom = mSY - SY + SYSIZE - 20;
3274 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3277 FadeOut(REDRAW_FIELD);
3283 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3285 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3286 "This game is Freeware!");
3287 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3288 "If you like it, send e-mail to:");
3289 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3290 PROGRAM_EMAIL_STRING);
3291 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3292 "or SnailMail to:");
3293 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3295 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3296 "Detmolder Strasse 189");
3297 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3299 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3301 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3302 "More information and levels:");
3303 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3304 PROGRAM_WEBSITE_STRING);
3305 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3306 "If you have created new levels,");
3307 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3308 "send them to me to include them!");
3309 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3312 DrawTextSCentered(ybottom, FONT_TEXT_4,
3313 "Press any key or button for info menu");
3316 FadeIn(REDRAW_FIELD);
3320 void HandleInfoScreen_Program(int button)
3322 if (button == MB_MENU_LEAVE)
3324 PlaySound(SND_MENU_ITEM_SELECTING);
3326 info_mode = INFO_MODE_MAIN;
3331 else if (button == MB_MENU_CHOICE)
3333 PlaySound(SND_MENU_ITEM_SELECTING);
3335 FadeSoundsAndMusic();
3338 FadeOut(REDRAW_FIELD);
3341 info_mode = INFO_MODE_MAIN;
3342 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3346 PlayMenuSoundIfLoop();
3350 void DrawInfoScreen_Version()
3352 int font_header = FONT_TEXT_3;
3353 int font_text = FONT_TEXT_2;
3354 int xstep = getFontWidth(font_text);
3355 int ystep = getFontHeight(font_text);
3356 int ystart1 = mSY - SY + 100;
3357 int ystart2 = mSY - SY + 150;
3358 int ybottom = mSY - SY + SYSIZE - 20;
3359 int xstart1 = mSX + 2 * xstep;
3360 int xstart2 = mSX + 19 * xstep;
3361 #if defined(TARGET_SDL)
3362 int xstart3 = mSX + 29 * xstep;
3363 SDL_version sdl_version_compiled;
3364 const SDL_version *sdl_version_linked;
3365 int driver_name_len = 8;
3366 char driver_name[driver_name_len];
3369 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3372 FadeOut(REDRAW_FIELD);
3378 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3380 DrawTextF(xstart1, ystart2, font_header, "Name");
3381 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3384 DrawTextF(xstart1, ystart2, font_header, "Version");
3385 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3388 DrawTextF(xstart1, ystart2, font_header, "Platform");
3389 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3392 DrawTextF(xstart1, ystart2, font_header, "Target");
3393 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3396 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3397 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3399 #if defined(TARGET_SDL)
3400 ystart2 += 3 * ystep;
3401 DrawTextF(xstart1, ystart2, font_header, "Library");
3402 DrawTextF(xstart2, ystart2, font_header, "compiled");
3403 DrawTextF(xstart3, ystart2, font_header, "linked");
3405 SDL_VERSION(&sdl_version_compiled);
3406 sdl_version_linked = SDL_Linked_Version();
3408 ystart2 += 2 * ystep;
3409 DrawTextF(xstart1, ystart2, font_text, "SDL");
3410 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3411 sdl_version_compiled.major,
3412 sdl_version_compiled.minor,
3413 sdl_version_compiled.patch);
3414 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3415 sdl_version_linked->major,
3416 sdl_version_linked->minor,
3417 sdl_version_linked->patch);
3419 SDL_IMAGE_VERSION(&sdl_version_compiled);
3420 sdl_version_linked = IMG_Linked_Version();
3423 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3424 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3425 sdl_version_compiled.major,
3426 sdl_version_compiled.minor,
3427 sdl_version_compiled.patch);
3428 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3429 sdl_version_linked->major,
3430 sdl_version_linked->minor,
3431 sdl_version_linked->patch);
3433 SDL_MIXER_VERSION(&sdl_version_compiled);
3434 sdl_version_linked = Mix_Linked_Version();
3437 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3438 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3439 sdl_version_compiled.major,
3440 sdl_version_compiled.minor,
3441 sdl_version_compiled.patch);
3442 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3443 sdl_version_linked->major,
3444 sdl_version_linked->minor,
3445 sdl_version_linked->patch);
3447 SDL_NET_VERSION(&sdl_version_compiled);
3448 sdl_version_linked = SDLNet_Linked_Version();
3451 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3452 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3453 sdl_version_compiled.major,
3454 sdl_version_compiled.minor,
3455 sdl_version_compiled.patch);
3456 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3457 sdl_version_linked->major,
3458 sdl_version_linked->minor,
3459 sdl_version_linked->patch);
3461 ystart2 += 3 * ystep;
3462 DrawTextF(xstart1, ystart2, font_header, "Driver");
3463 DrawTextF(xstart2, ystart2, font_header, "Requested");
3464 DrawTextF(xstart3, ystart2, font_header, "Used");
3466 SDL_VideoDriverName(driver_name, driver_name_len);
3468 ystart2 += 2 * ystep;
3469 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3470 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3471 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3473 SDL_AudioDriverName(driver_name, driver_name_len);
3476 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3477 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3478 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3481 DrawTextSCentered(ybottom, FONT_TEXT_4,
3482 "Press any key or button for info menu");
3485 FadeIn(REDRAW_FIELD);
3489 void HandleInfoScreen_Version(int button)
3491 if (button == MB_MENU_LEAVE)
3493 PlaySound(SND_MENU_ITEM_SELECTING);
3495 info_mode = INFO_MODE_MAIN;
3500 else if (button == MB_MENU_CHOICE)
3502 PlaySound(SND_MENU_ITEM_SELECTING);
3504 FadeSoundsAndMusic();
3507 FadeOut(REDRAW_FIELD);
3510 info_mode = INFO_MODE_MAIN;
3511 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3515 PlayMenuSoundIfLoop();
3519 void DrawInfoScreen_LevelSet()
3521 struct TitleMessageInfo *tmi = &readme;
3522 char *filename = getLevelSetInfoFilename();
3524 /* if chars set to "-1", automatically determine by text and font width */
3525 if (tmi->chars == -1)
3526 tmi->chars = tmi->width / getFontWidth(tmi->font);
3528 tmi->width = tmi->chars * getFontWidth(tmi->font);
3530 /* if lines set to "-1", automatically determine by text and font height */
3531 if (tmi->lines == -1)
3532 tmi->lines = tmi->height / getFontHeight(tmi->font);
3534 tmi->height = tmi->lines * getFontHeight(tmi->font);
3536 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3539 FadeOut(REDRAW_FIELD);
3545 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3547 if (filename != NULL)
3548 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3549 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3550 tmi->autowrap, tmi->centered, tmi->parse_comments);
3552 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3553 "No information for this level set.");
3555 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3556 "Press any key or button for info menu");
3559 FadeIn(REDRAW_FIELD);
3563 void HandleInfoScreen_LevelSet(int button)
3565 if (button == MB_MENU_LEAVE)
3567 PlaySound(SND_MENU_ITEM_SELECTING);
3569 info_mode = INFO_MODE_MAIN;
3574 else if (button == MB_MENU_CHOICE)
3576 PlaySound(SND_MENU_ITEM_SELECTING);
3578 FadeSoundsAndMusic();
3581 FadeOut(REDRAW_FIELD);
3584 info_mode = INFO_MODE_MAIN;
3585 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3589 PlayMenuSoundIfLoop();
3593 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3595 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3597 if (info_mode == INFO_MODE_TITLE)
3598 DrawInfoScreen_TitleScreen();
3599 else if (info_mode == INFO_MODE_ELEMENTS)
3600 DrawInfoScreen_Elements();
3601 else if (info_mode == INFO_MODE_MUSIC)
3602 DrawInfoScreen_Music();
3603 else if (info_mode == INFO_MODE_CREDITS)
3604 DrawInfoScreen_Credits();
3605 else if (info_mode == INFO_MODE_PROGRAM)
3606 DrawInfoScreen_Program();
3607 else if (info_mode == INFO_MODE_VERSION)
3608 DrawInfoScreen_Version();
3609 else if (info_mode == INFO_MODE_LEVELSET)
3610 DrawInfoScreen_LevelSet();
3612 DrawInfoScreen_Main(redraw_mask, do_fading);
3614 if (info_mode != INFO_MODE_MAIN &&
3615 info_mode != INFO_MODE_TITLE &&
3616 info_mode != INFO_MODE_MUSIC)
3623 void DrawAndFadeInInfoScreen(int redraw_mask)
3625 DrawInfoScreenExt(redraw_mask, TRUE);
3628 void DrawInfoScreen()
3630 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3633 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3635 if (info_mode == INFO_MODE_TITLE)
3636 HandleInfoScreen_TitleScreen(button);
3637 else if (info_mode == INFO_MODE_ELEMENTS)
3638 HandleInfoScreen_Elements(button);
3639 else if (info_mode == INFO_MODE_MUSIC)
3640 HandleInfoScreen_Music(button);
3641 else if (info_mode == INFO_MODE_CREDITS)
3642 HandleInfoScreen_Credits(button);
3643 else if (info_mode == INFO_MODE_PROGRAM)
3644 HandleInfoScreen_Program(button);
3645 else if (info_mode == INFO_MODE_VERSION)
3646 HandleInfoScreen_Version(button);
3647 else if (info_mode == INFO_MODE_LEVELSET)
3648 HandleInfoScreen_LevelSet(button);
3650 HandleInfoScreen_Main(mx, my, dx, dy, button);
3656 /* ========================================================================= */
3657 /* type name functions */
3658 /* ========================================================================= */
3660 void HandleTypeName(int newxpos, Key key)
3662 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3663 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3665 struct TextPosInfo *pos = mci->pos_input;
3666 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3667 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3670 static int xpos = 0;
3672 static int xpos = 0, ypos = 2;
3674 int font_nr = pos->font;
3675 int font_active_nr = FONT_ACTIVE(font_nr);
3676 int font_width = getFontWidth(font_active_nr);
3679 int startx = mSX + mci->pos_input->x;
3680 int starty = mSY + mci->pos_input->y;
3683 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3684 int startx = mSX + 32 + name_width;
3685 int starty = mSY + ypos * 32;
3687 char key_char = getValidConfigValueChar(getCharFromKey(key));
3688 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3689 boolean is_active = TRUE;
3691 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3695 strcpy(last_player_name, setup.player_name);
3700 /* add one character width for added cursor character */
3701 pos->width += font_width;
3702 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3704 DrawText(startx, starty, setup.player_name, font_active_nr);
3705 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3708 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3710 setup.player_name[xpos] = key_char;
3711 setup.player_name[xpos + 1] = 0;
3716 /* add one character width for added name text character */
3717 pos->width += font_width;
3718 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3720 DrawText(startx, starty, setup.player_name, font_active_nr);
3721 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3724 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3728 setup.player_name[xpos] = 0;
3731 /* remove one character width for removed name text character */
3732 pos->width -= font_width;
3733 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3735 DrawText(startx, starty, setup.player_name, font_active_nr);
3736 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3739 else if (key == KSYM_Return && xpos > 0)
3742 /* remove one character width for removed cursor text character */
3743 pos->width -= font_width;
3744 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3746 DrawText(startx, starty, setup.player_name, font_nr);
3747 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3754 game_status = GAME_MODE_MAIN;
3756 else if (key == KSYM_Escape)
3758 strcpy(setup.player_name, last_player_name);
3762 game_status = GAME_MODE_MAIN;
3767 pos->width = (strlen(setup.player_name) + 1) * font_width;
3768 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3770 DrawText(startx, starty, setup.player_name, font_active_nr);
3771 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3775 pos->width = strlen(setup.player_name) * font_width;
3776 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3778 DrawText(startx, starty, setup.player_name, font_nr);
3783 /* ========================================================================= */
3784 /* tree menu functions */
3785 /* ========================================================================= */
3787 static void DrawChooseTree(TreeInfo **ti_ptr)
3791 FreeScreenGadgets();
3792 CreateScreenGadgets();
3794 CloseDoor(DOOR_CLOSE_2);
3797 FadeOut(REDRAW_FIELD);
3802 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3803 MapScreenTreeGadgets(*ti_ptr);
3806 FadeIn(REDRAW_FIELD);
3812 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3814 struct GadgetInfo *gi = screen_gadget[id];
3815 int items_max, items_visible, item_position;
3817 items_max = numTreeInfoInGroup(ti);
3818 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3819 item_position = first_entry;
3821 if (item_position > items_max - items_visible)
3822 item_position = items_max - items_visible;
3824 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3825 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3826 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3829 static void drawChooseTreeList(int first_entry, int num_page_entries,
3833 char *title_string = NULL;
3834 int yoffset_sets = MENU_TITLE1_YPOS;
3835 int yoffset_setup = 16;
3836 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3838 int last_game_status = game_status; /* save current game status */
3840 title_string = ti->infotext;
3842 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3845 /* force LEVELS font on artwork setup screen */
3846 game_status = GAME_MODE_LEVELS;
3850 /* clear tree list area, but not title or scrollbar */
3851 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3852 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3853 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3855 /* clear tree list area, but not title or scrollbar */
3856 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3857 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3858 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3861 for (i = 0; i < num_page_entries; i++)
3863 TreeInfo *node, *node_first;
3864 int entry_pos = first_entry + i;
3865 int xpos = MENU_SCREEN_START_XPOS;
3866 int ypos = MENU_SCREEN_START_YPOS + i;
3867 int startx = mSX + xpos * 32;
3868 int starty = mSY + ypos * 32;
3869 int font_nr = FONT_TEXT_1;
3870 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3871 int startx_text = startx + font_xoffset;
3872 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3873 int text_size = startx_scrollbar - startx_text;
3874 int max_buffer_len = text_size / getFontWidth(font_nr);
3875 char buffer[max_buffer_len + 1];
3877 node_first = getTreeInfoFirstGroupEntry(ti);
3878 node = getTreeInfoFromPos(node_first, entry_pos);
3880 strncpy(buffer, node->name, max_buffer_len);
3881 buffer[max_buffer_len] = '\0';
3883 DrawText(startx, starty, buffer, font_nr + node->color);
3885 if (node->parent_link)
3886 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3887 else if (node->level_group)
3888 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3890 initCursor(i, IMG_MENU_BUTTON);
3893 game_status = last_game_status; /* restore current game status */
3895 redraw_mask |= REDRAW_FIELD;
3898 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3900 TreeInfo *node, *node_first;
3901 int x, last_redraw_mask = redraw_mask;
3902 int ypos = MENU_TITLE2_YPOS;
3903 int font_nr = FONT_TITLE_2;
3905 if (ti->type != TREE_TYPE_LEVEL_DIR)
3908 node_first = getTreeInfoFirstGroupEntry(ti);
3909 node = getTreeInfoFromPos(node_first, entry_pos);
3911 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3913 if (node->parent_link)
3914 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3916 else if (node->level_group)
3917 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3919 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3920 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3921 node->levels, node->class_desc);
3923 /* let BackToFront() redraw only what is needed */
3924 redraw_mask = last_redraw_mask | REDRAW_TILES;
3925 for (x = 0; x < SCR_FIELDX; x++)
3926 MarkTileDirty(x, 1);
3929 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3932 TreeInfo *ti = *ti_ptr;
3934 int y = ti->cl_cursor;
3935 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3936 int num_entries = numTreeInfoInGroup(ti);
3937 int num_page_entries;
3938 int last_game_status = game_status; /* save current game status */
3939 boolean position_set_by_scrollbar = (dx == 999);
3942 /* force LEVELS draw offset on choose level and artwork setup screen */
3943 game_status = GAME_MODE_LEVELS;
3946 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3947 num_page_entries = num_entries;
3949 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3951 game_status = last_game_status; /* restore current game status */
3953 if (button == MB_MENU_INITIALIZE)
3955 int num_entries = numTreeInfoInGroup(ti);
3956 int entry_pos = posTreeInfo(ti);
3958 if (ti->cl_first == -1)
3960 /* only on initialization */
3961 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3962 ti->cl_cursor = entry_pos - ti->cl_first;
3964 else if (ti->cl_cursor >= num_page_entries ||
3965 (num_entries > num_page_entries &&
3966 num_entries - ti->cl_first < num_page_entries))
3968 /* only after change of list size (by custom graphic configuration) */
3969 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3970 ti->cl_cursor = entry_pos - ti->cl_first;
3973 if (position_set_by_scrollbar)
3976 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3979 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3980 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3981 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3985 else if (button == MB_MENU_LEAVE)
3989 PlaySound(SND_MENU_ITEM_SELECTING);
3991 if (ti->node_parent)
3993 *ti_ptr = ti->node_parent;
3994 DrawChooseTree(ti_ptr);
3996 else if (game_status == GAME_MODE_SETUP)
3998 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4000 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4001 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4002 execSetupGraphics();
4008 game_status = GAME_MODE_MAIN;
4010 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4019 if (mx || my) /* mouse input */
4021 int last_game_status = game_status; /* save current game status */
4024 /* force LEVELS draw offset on artwork setup screen */
4025 game_status = GAME_MODE_LEVELS;
4028 x = (mx - mSX) / 32;
4029 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4031 game_status = last_game_status; /* restore current game status */
4033 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4035 /* move cursor instead of scrolling when already at start/end of list */
4036 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4038 else if (dy == +1 * SCROLL_LINE &&
4039 ti->cl_first + num_page_entries == num_entries)
4042 /* handle scrolling screen one line or page */
4043 if (ti->cl_cursor + dy < 0 ||
4044 ti->cl_cursor + dy > num_page_entries - 1)
4046 if (ABS(dy) == SCROLL_PAGE)
4047 step = num_page_entries - 1;
4049 if (dy < 0 && ti->cl_first > 0)
4051 /* scroll page/line up */
4053 ti->cl_first -= step;
4054 if (ti->cl_first < 0)
4057 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4058 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4059 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4061 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4064 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4066 /* scroll page/line down */
4068 ti->cl_first += step;
4069 if (ti->cl_first + num_page_entries > num_entries)
4070 ti->cl_first = MAX(0, num_entries - num_page_entries);
4072 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4073 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4074 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4076 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4083 /* handle moving cursor one line */
4084 y = ti->cl_cursor + dy;
4089 TreeInfo *node_first, *node_cursor;
4090 int entry_pos = ti->cl_first + y;
4092 node_first = getTreeInfoFirstGroupEntry(ti);
4093 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4095 if (node_cursor->node_group)
4099 PlaySound(SND_MENU_ITEM_SELECTING);
4101 node_cursor->cl_first = ti->cl_first;
4102 node_cursor->cl_cursor = ti->cl_cursor;
4103 *ti_ptr = node_cursor->node_group;
4104 DrawChooseTree(ti_ptr);
4109 else if (dx == -1 && ti->node_parent)
4113 PlaySound(SND_MENU_ITEM_SELECTING);
4115 *ti_ptr = ti->node_parent;
4116 DrawChooseTree(ti_ptr);
4121 if (!anyScrollbarGadgetActive() &&
4122 IN_VIS_FIELD(x, y) &&
4123 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4124 y >= 0 && y < num_page_entries)
4128 if (y != ti->cl_cursor)
4130 PlaySound(SND_MENU_ITEM_ACTIVATING);
4132 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4133 drawChooseTreeCursor(y, TRUE);
4134 drawChooseTreeInfo(ti->cl_first + y, ti);
4141 TreeInfo *node_first, *node_cursor;
4142 int entry_pos = ti->cl_first + y;
4144 PlaySound(SND_MENU_ITEM_SELECTING);
4146 node_first = getTreeInfoFirstGroupEntry(ti);
4147 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4149 if (node_cursor->node_group)
4153 node_cursor->cl_first = ti->cl_first;
4154 node_cursor->cl_cursor = ti->cl_cursor;
4155 *ti_ptr = node_cursor->node_group;
4156 DrawChooseTree(ti_ptr);
4158 else if (node_cursor->parent_link)
4162 *ti_ptr = node_cursor->node_parent;
4163 DrawChooseTree(ti_ptr);
4167 FadeSetEnterScreen();
4169 node_cursor->cl_first = ti->cl_first;
4170 node_cursor->cl_cursor = ti->cl_cursor;
4171 *ti_ptr = node_cursor;
4173 if (ti->type == TREE_TYPE_LEVEL_DIR)
4175 LoadLevelSetup_SeriesInfo();
4177 SaveLevelSetup_LastSeries();
4178 SaveLevelSetup_SeriesInfo();
4182 if (game_status == GAME_MODE_SETUP)
4184 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4186 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4187 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4188 execSetupGraphics();
4194 game_status = GAME_MODE_MAIN;
4202 void DrawChooseLevel()
4204 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4206 DrawChooseTree(&leveldir_current);
4212 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4214 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4219 void DrawHallOfFame(int highlight_position)
4222 FadeSoundsAndMusic();
4224 /* (this is needed when called from GameEnd() after winning a game) */
4225 KeyboardAutoRepeatOn();
4228 /* (this is needed when called from GameEnd() after winning a game) */
4229 SetDrawDeactivationMask(REDRAW_NONE);
4230 SetDrawBackgroundMask(REDRAW_FIELD);
4232 CloseDoor(DOOR_CLOSE_2);
4234 if (highlight_position < 0)
4235 LoadScore(level_nr);
4237 FadeSetEnterScreen();
4239 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4242 FadeOut(REDRAW_FIELD);
4250 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4253 FadeIn(REDRAW_FIELD);
4257 static void drawHallOfFameList(int first_entry, int highlight_position)
4261 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4264 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4265 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4266 "HighScores of Level %d", level_nr);
4268 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4270 int entry = first_entry + i;
4271 boolean active = (entry == highlight_position);
4272 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4273 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4274 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4275 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4276 int dx1 = 3 * getFontWidth(font_nr1);
4277 int dx2 = dx1 + getFontWidth(font_nr1);
4278 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4279 int sy = mSY + 64 + i * 32;
4281 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4282 DrawText(mSX + dx1, sy, ".", font_nr1);
4283 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4285 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4286 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4288 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4291 redraw_mask |= REDRAW_FIELD;
4294 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4296 static int first_entry = 0;
4297 static int highlight_position = 0;
4298 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4300 if (button == MB_MENU_INITIALIZE)
4303 highlight_position = mx;
4304 drawHallOfFameList(first_entry, highlight_position);
4309 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4310 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4314 if (first_entry > 0)
4316 first_entry -= step;
4317 if (first_entry < 0)
4320 drawHallOfFameList(first_entry, highlight_position);
4325 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4327 first_entry += step;
4328 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4329 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4331 drawHallOfFameList(first_entry, highlight_position);
4334 else if (button == MB_MENU_LEAVE)
4336 PlaySound(SND_MENU_ITEM_SELECTING);
4338 FadeSound(SND_BACKGROUND_SCORES);
4340 game_status = GAME_MODE_MAIN;
4344 else if (button == MB_MENU_CHOICE)
4346 PlaySound(SND_MENU_ITEM_SELECTING);
4348 FadeSound(SND_BACKGROUND_SCORES);
4351 FadeOut(REDRAW_FIELD);
4354 game_status = GAME_MODE_MAIN;
4356 DrawAndFadeInMainMenu(REDRAW_FIELD);
4359 if (game_status == GAME_MODE_SCORES)
4360 PlayMenuSoundIfLoop();
4366 /* ========================================================================= */
4367 /* setup screen functions */
4368 /* ========================================================================= */
4370 static struct TokenInfo *setup_info;
4371 static int num_setup_info;
4373 static char *screen_mode_text;
4374 static char *scroll_delay_text;
4375 static char *game_speed_text;
4376 static char *graphics_set_name;
4377 static char *sounds_set_name;
4378 static char *music_set_name;
4380 static void execSetupMain()
4386 setup_mode = SETUP_MODE_MAIN;
4390 static void execSetupGame()
4396 if (game_speeds == NULL)
4400 for (i = 0; game_speeds_list[i].value != -1; i++)
4402 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4403 char identifier[32], name[32];
4404 int value = game_speeds_list[i].value;
4405 char *text = game_speeds_list[i].text;
4407 ti->node_top = &game_speeds;
4408 ti->sort_priority = 10000 - value;
4410 sprintf(identifier, "%d", value);
4411 sprintf(name, "%s", text);
4413 setString(&ti->identifier, identifier);
4414 setString(&ti->name, name);
4415 setString(&ti->name_sorting, name);
4416 setString(&ti->infotext, "Game Speed");
4418 pushTreeInfo(&game_speeds, ti);
4421 /* sort game speed values to start with slowest game speed */
4422 sortTreeInfo(&game_speeds);
4424 /* set current game speed to configured game speed value */
4425 game_speed_current =
4426 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4428 /* if that fails, set current game speed to reliable default value */
4429 if (game_speed_current == NULL)
4430 game_speed_current =
4431 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4433 /* if that also fails, set current game speed to first available speed */
4434 if (game_speed_current == NULL)
4435 game_speed_current = game_speeds;
4438 setup.game_frame_delay = atoi(game_speed_current->identifier);
4440 /* needed for displaying game speed text instead of identifier */
4441 game_speed_text = game_speed_current->name;
4443 setup_mode = SETUP_MODE_GAME;
4447 static void execSetupChooseGameSpeed()
4453 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4457 static void execSetupEditor()
4463 setup_mode = SETUP_MODE_EDITOR;
4467 static void execSetupGraphics()
4473 if (video.fullscreen_available && screen_modes == NULL)
4477 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4479 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4480 char identifier[32], name[32];
4481 int x = video.fullscreen_modes[i].width;
4482 int y = video.fullscreen_modes[i].height;
4485 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4487 ti->node_top = &screen_modes;
4488 ti->sort_priority = x * 10000 + y;
4490 sprintf(identifier, "%dx%d", x, y);
4491 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4493 setString(&ti->identifier, identifier);
4494 setString(&ti->name, name);
4495 setString(&ti->name_sorting, name);
4496 setString(&ti->infotext, "Fullscreen Mode");
4498 pushTreeInfo(&screen_modes, ti);
4501 /* sort fullscreen modes to start with lowest available screen resolution */
4502 sortTreeInfo(&screen_modes);
4504 /* set current screen mode for fullscreen mode to configured setup value */
4505 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4506 setup.fullscreen_mode);
4508 /* if that fails, set current screen mode to reliable default value */
4509 if (screen_mode_current == NULL)
4510 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4511 DEFAULT_FULLSCREEN_MODE);
4513 /* if that also fails, set current screen mode to first available mode */
4514 if (screen_mode_current == NULL)
4515 screen_mode_current = screen_modes;
4517 if (screen_mode_current == NULL)
4518 video.fullscreen_available = FALSE;
4521 if (video.fullscreen_available)
4523 setup.fullscreen_mode = screen_mode_current->identifier;
4525 /* needed for displaying screen mode name instead of identifier */
4526 screen_mode_text = screen_mode_current->name;
4530 if (scroll_delays == NULL)
4534 for (i = 0; scroll_delays_list[i].value != -1; i++)
4536 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4537 char identifier[32], name[32];
4538 int value = scroll_delays_list[i].value;
4539 char *text = scroll_delays_list[i].text;
4541 ti->node_top = &scroll_delays;
4542 ti->sort_priority = value;
4544 sprintf(identifier, "%d", value);
4545 sprintf(name, "%s", text);
4547 setString(&ti->identifier, identifier);
4548 setString(&ti->name, name);
4549 setString(&ti->name_sorting, name);
4550 setString(&ti->infotext, "Scroll Delay");
4552 pushTreeInfo(&scroll_delays, ti);
4555 /* sort scroll delay values to start with lowest scroll delay value */
4556 sortTreeInfo(&scroll_delays);
4558 /* set current scroll delay value to configured scroll delay value */
4559 scroll_delay_current =
4560 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4562 /* if that fails, set current scroll delay to reliable default value */
4563 if (scroll_delay_current == NULL)
4564 scroll_delay_current =
4565 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4567 /* if that also fails, set current scroll delay to first available value */
4568 if (scroll_delay_current == NULL)
4569 scroll_delay_current = scroll_delays;
4572 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4574 /* needed for displaying scroll delay text instead of identifier */
4575 scroll_delay_text = scroll_delay_current->name;
4578 setup_mode = SETUP_MODE_GRAPHICS;
4582 static void execSetupChooseScreenMode()
4588 if (!video.fullscreen_available)
4591 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4595 static void execSetupChooseScrollDelay()
4601 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4605 static void execSetupSound()
4611 setup_mode = SETUP_MODE_SOUND;
4615 static void execSetupArtwork()
4621 setup.graphics_set = artwork.gfx_current->identifier;
4622 setup.sounds_set = artwork.snd_current->identifier;
4623 setup.music_set = artwork.mus_current->identifier;
4625 /* needed if last screen (setup choice) changed graphics, sounds or music */
4626 ReloadCustomArtwork(0);
4628 /* needed for displaying artwork name instead of artwork identifier */
4629 graphics_set_name = artwork.gfx_current->name;
4630 sounds_set_name = artwork.snd_current->name;
4631 music_set_name = artwork.mus_current->name;
4633 setup_mode = SETUP_MODE_ARTWORK;
4637 static void execSetupChooseGraphics()
4643 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4647 static void execSetupChooseSounds()
4653 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4657 static void execSetupChooseMusic()
4663 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4667 static void execSetupInput()
4673 setup_mode = SETUP_MODE_INPUT;
4677 static void execSetupShortcuts1()
4683 setup_mode = SETUP_MODE_SHORTCUTS_1;
4687 static void execSetupShortcuts2()
4693 setup_mode = SETUP_MODE_SHORTCUTS_2;
4697 static void execExitSetup()
4703 game_status = GAME_MODE_MAIN;
4705 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4711 static void execSaveAndExitSetup()
4717 static struct TokenInfo setup_info_main[] =
4719 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4720 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4721 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4722 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4723 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4724 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4725 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4726 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4727 { TYPE_EMPTY, NULL, "" },
4728 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4729 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4734 static struct TokenInfo setup_info_game[] =
4736 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4737 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4738 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4739 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4740 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4741 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4742 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4743 { TYPE_STRING, &game_speed_text, "" },
4744 { TYPE_EMPTY, NULL, "" },
4745 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4750 static struct TokenInfo setup_info_editor[] =
4753 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4754 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4755 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4756 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4757 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4758 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4759 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4760 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4762 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4763 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4764 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4766 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4768 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4769 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4770 { TYPE_EMPTY, NULL, "" },
4772 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4773 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4774 { TYPE_EMPTY, NULL, "" },
4776 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4777 { TYPE_EMPTY, NULL, "" },
4778 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4783 static struct TokenInfo setup_info_graphics[] =
4785 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4786 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4787 { TYPE_STRING, &screen_mode_text, "" },
4789 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4791 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4792 { TYPE_STRING, &scroll_delay_text, "" },
4794 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4795 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4797 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4798 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4799 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4800 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4801 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4802 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4803 { TYPE_EMPTY, NULL, "" },
4804 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4809 static struct TokenInfo setup_info_sound[] =
4811 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4812 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4813 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4814 { TYPE_EMPTY, NULL, "" },
4815 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4820 static struct TokenInfo setup_info_artwork[] =
4822 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4823 { TYPE_STRING, &graphics_set_name, "" },
4824 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4825 { TYPE_STRING, &sounds_set_name, "" },
4826 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4827 { TYPE_STRING, &music_set_name, "" },
4828 { TYPE_EMPTY, NULL, "" },
4830 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4831 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4832 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4834 { TYPE_STRING, NULL, "Override Level Artwork:"},
4835 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4836 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4837 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4839 { TYPE_EMPTY, NULL, "" },
4840 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4845 static struct TokenInfo setup_info_input[] =
4847 { TYPE_SWITCH, NULL, "Player:" },
4848 { TYPE_SWITCH, NULL, "Device:" },
4849 { TYPE_ENTER_MENU, NULL, "" },
4850 { TYPE_EMPTY, NULL, "" },
4851 { TYPE_EMPTY, NULL, "" },
4852 { TYPE_EMPTY, NULL, "" },
4853 { TYPE_EMPTY, NULL, "" },
4854 { TYPE_EMPTY, NULL, "" },
4855 { TYPE_EMPTY, NULL, "" },
4856 { TYPE_EMPTY, NULL, "" },
4857 { TYPE_EMPTY, NULL, "" },
4858 { TYPE_EMPTY, NULL, "" },
4859 { TYPE_EMPTY, NULL, "" },
4860 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4865 static struct TokenInfo setup_info_shortcuts_1[] =
4867 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4868 { TYPE_KEY, &setup.shortcut.save_game, "" },
4869 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4870 { TYPE_KEY, &setup.shortcut.load_game, "" },
4871 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4872 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4873 { TYPE_EMPTY, NULL, "" },
4874 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4875 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4876 { TYPE_EMPTY, NULL, "" },
4877 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4882 static struct TokenInfo setup_info_shortcuts_2[] =
4884 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4885 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4886 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4887 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4888 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4889 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4890 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4891 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4892 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4893 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4894 { TYPE_EMPTY, NULL, "" },
4895 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4900 static Key getSetupKey()
4902 Key key = KSYM_UNDEFINED;
4903 boolean got_key_event = FALSE;
4905 while (!got_key_event)
4907 if (PendingEvent()) /* got event */
4915 case EVENT_KEYPRESS:
4917 key = GetEventKey((KeyEvent *)&event, TRUE);
4919 /* press 'Escape' or 'Enter' to keep the existing key binding */
4920 if (key == KSYM_Escape || key == KSYM_Return)
4921 key = KSYM_UNDEFINED; /* keep old value */
4923 got_key_event = TRUE;
4927 case EVENT_KEYRELEASE:
4928 key_joystick_mapping = 0;
4932 HandleOtherEvents(&event);
4940 /* don't eat all CPU time */
4947 static int getSetupTextFont(int type)
4949 if (type & (TYPE_SWITCH |
4960 static int getSetupValueFont(int type, void *value)
4962 if (type & TYPE_KEY)
4963 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4964 else if (type & TYPE_STRING)
4965 return FONT_VALUE_2;
4966 else if (type & TYPE_ECS_AGA)
4967 return FONT_VALUE_1;
4968 else if (type & TYPE_BOOLEAN_STYLE)
4969 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4971 return FONT_VALUE_1;
4974 static void drawSetupValue(int pos)
4976 boolean font_draw_xoffset_modified = FALSE;
4977 int font_draw_xoffset_old = -1;
4978 int xpos = MENU_SCREEN_VALUE_XPOS;
4979 int ypos = MENU_SCREEN_START_YPOS + pos;
4980 int startx = mSX + xpos * 32;
4981 int starty = mSY + ypos * 32;
4982 int font_nr, font_width;
4983 int type = setup_info[pos].type;
4984 void *value = setup_info[pos].value;
4985 char *value_string = getSetupValue(type, value);
4988 if (value_string == NULL)
4991 if (type & TYPE_KEY)
4993 xpos = MENU_SCREEN_START_XPOS;
4995 if (type & TYPE_QUERY)
4997 value_string = "<press key>";
5000 else if (type & TYPE_STRING)
5002 int max_value_len = (SCR_FIELDX - 2) * 2;
5004 xpos = MENU_SCREEN_START_XPOS;
5006 if (strlen(value_string) > max_value_len)
5007 value_string[max_value_len] = '\0';
5010 startx = mSX + xpos * 32;
5011 starty = mSY + ypos * 32;
5012 font_nr = getSetupValueFont(type, value);
5013 font_width = getFontWidth(font_nr);
5015 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5016 if (setup_mode != SETUP_MODE_INPUT)
5018 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5019 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5020 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5021 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5022 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5023 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5024 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5025 boolean correct_font_draw_xoffset = FALSE;
5027 if (xpos == MENU_SCREEN_START_XPOS &&
5028 startx + font1_xoffset < text_startx + text_font_xoffset)
5029 correct_font_draw_xoffset = TRUE;
5031 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5032 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5033 correct_font_draw_xoffset = TRUE;
5035 /* check if setup value would overlap with setup text when printed */
5036 /* (this can happen for extreme/wrong values for font draw offset) */
5037 if (correct_font_draw_xoffset)
5039 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5040 font_draw_xoffset_modified = TRUE;
5042 if (type & TYPE_KEY)
5043 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5044 else if (!(type & TYPE_STRING))
5045 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5046 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5050 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5051 DrawText(startx + i * font_width, starty, " ", font_nr);
5053 DrawText(startx, starty, value_string, font_nr);
5055 if (font_draw_xoffset_modified)
5056 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5059 static void changeSetupValue(int pos)
5061 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5063 *(boolean *)setup_info[pos].value ^= TRUE;
5065 else if (setup_info[pos].type & TYPE_KEY)
5069 setup_info[pos].type |= TYPE_QUERY;
5070 drawSetupValue(pos);
5071 setup_info[pos].type &= ~TYPE_QUERY;
5073 key = getSetupKey();
5074 if (key != KSYM_UNDEFINED)
5075 *(Key *)setup_info[pos].value = key;
5078 drawSetupValue(pos);
5081 static void DrawCursorAndText_Setup(int pos, boolean active)
5083 int xpos = MENU_SCREEN_START_XPOS;
5084 int ypos = MENU_SCREEN_START_YPOS + pos;
5085 int font_nr = getSetupTextFont(setup_info[pos].type);
5087 if (setup_info == setup_info_input)
5088 font_nr = FONT_MENU_1;
5091 font_nr = FONT_ACTIVE(font_nr);
5093 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5095 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5096 drawCursor(pos, active);
5099 static void DrawSetupScreen_Generic()
5101 char *title_string = NULL;
5105 CloseDoor(DOOR_CLOSE_2);
5108 FadeOut(REDRAW_FIELD);
5113 if (setup_mode == SETUP_MODE_MAIN)
5115 setup_info = setup_info_main;
5116 title_string = "Setup";
5118 else if (setup_mode == SETUP_MODE_GAME)
5120 setup_info = setup_info_game;
5121 title_string = "Setup Game";
5123 else if (setup_mode == SETUP_MODE_EDITOR)
5125 setup_info = setup_info_editor;
5126 title_string = "Setup Editor";
5128 else if (setup_mode == SETUP_MODE_GRAPHICS)
5130 setup_info = setup_info_graphics;
5131 title_string = "Setup Graphics";
5133 else if (setup_mode == SETUP_MODE_SOUND)
5135 setup_info = setup_info_sound;
5136 title_string = "Setup Sound";
5138 else if (setup_mode == SETUP_MODE_ARTWORK)
5140 setup_info = setup_info_artwork;
5141 title_string = "Custom Artwork";
5143 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5145 setup_info = setup_info_shortcuts_1;
5146 title_string = "Setup Shortcuts";
5148 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5150 setup_info = setup_info_shortcuts_2;
5151 title_string = "Setup Shortcuts";
5154 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5157 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5159 void *value_ptr = setup_info[i].value;
5162 int xpos = MENU_SCREEN_START_XPOS;
5163 int ypos = MENU_SCREEN_START_YPOS + i;
5167 /* set some entries to "unchangeable" according to other variables */
5168 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5169 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5170 (value_ptr == &setup.sound_music && !audio.music_available) ||
5171 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5172 (value_ptr == &screen_mode_text && !video.fullscreen_available))
5173 setup_info[i].type |= TYPE_GHOSTED;
5175 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5176 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5177 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5178 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5179 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5180 initCursor(i, IMG_MENU_BUTTON);
5183 DrawCursorAndText_Setup(i, FALSE);
5185 font_nr = getSetupTextFont(setup_info[i].type);
5187 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5190 if (setup_info[i].type & TYPE_VALUE)
5197 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5198 "Joysticks deactivated in setup menu");
5202 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5206 FadeIn(REDRAW_FIELD);
5211 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5215 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5217 static int choice_store[MAX_SETUP_MODES];
5218 int choice = choice_store[setup_mode]; /* always starts with 0 */
5222 if (button == MB_MENU_INITIALIZE)
5224 /* advance to first valid menu entry */
5225 while (choice < num_setup_info &&
5226 setup_info[choice].type & TYPE_SKIP_ENTRY)
5228 choice_store[setup_mode] = choice;
5231 DrawCursorAndText_Setup(choice, TRUE);
5233 drawCursor(choice, TRUE);
5238 else if (button == MB_MENU_LEAVE)
5240 PlaySound(SND_MENU_ITEM_SELECTING);
5242 for (y = 0; y < num_setup_info; y++)
5244 if (setup_info[y].type & TYPE_LEAVE_MENU)
5246 void (*menu_callback_function)(void) = setup_info[y].value;
5250 menu_callback_function();
5252 break; /* absolutely needed because function changes 'setup_info'! */
5259 if (mx || my) /* mouse input */
5261 x = (mx - mSX) / 32;
5262 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5264 else if (dx || dy) /* keyboard input */
5268 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5270 if (setup_info[choice].type & menu_navigation_type ||
5271 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5272 button = MB_MENU_CHOICE;
5277 /* jump to next non-empty menu entry (up or down) */
5278 while (y > 0 && y < num_setup_info - 1 &&
5279 setup_info[y].type & TYPE_SKIP_ENTRY)
5283 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5287 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5289 PlaySound(SND_MENU_ITEM_ACTIVATING);
5292 DrawCursorAndText_Setup(choice, FALSE);
5293 DrawCursorAndText_Setup(y, TRUE);
5295 drawCursor(choice, FALSE);
5296 drawCursor(y, TRUE);
5299 choice = choice_store[setup_mode] = y;
5302 else if (!(setup_info[y].type & TYPE_GHOSTED))
5304 PlaySound(SND_MENU_ITEM_SELECTING);
5306 /* when selecting key headline, execute function for key value change */
5307 if (setup_info[y].type & TYPE_KEYTEXT &&
5308 setup_info[y + 1].type & TYPE_KEY)
5311 /* when selecting string value, execute function for list selection */
5312 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5313 setup_info[y - 1].type & TYPE_ENTER_LIST)
5316 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5318 void (*menu_callback_function)(void) = setup_info[y].value;
5320 FadeSetFromType(setup_info[y].type);
5322 menu_callback_function();
5326 if (setup_info[y].type & TYPE_VALUE)
5327 changeSetupValue(y);
5333 void DrawSetupScreen_Input()
5340 FadeOut(REDRAW_FIELD);
5346 setup_info = setup_info_input;
5349 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5352 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5354 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5355 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5356 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5357 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5358 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5359 initCursor(i, IMG_MENU_BUTTON);
5361 DrawCursorAndText_Setup(i, FALSE);
5364 initCursor(0, IMG_MENU_BUTTON);
5365 initCursor(1, IMG_MENU_BUTTON);
5366 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
5367 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5369 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
5370 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
5371 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
5375 DeactivateJoystickForCalibration();
5378 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5379 "Joysticks deactivated on this screen");
5382 /* create gadgets for setup input menu screen */
5383 FreeScreenGadgets();
5384 CreateScreenGadgets();
5386 /* map gadgets for setup input menu screen */
5387 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5389 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5392 FadeIn(REDRAW_FIELD);
5398 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5400 if (device_name == NULL)
5403 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5406 if (strlen(device_name) > 1)
5408 char c1 = device_name[strlen(device_name) - 1];
5409 char c2 = device_name[strlen(device_name) - 2];
5411 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5412 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5415 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5416 strlen(device_name));
5419 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5422 static struct SetupKeyboardInfo custom_key;
5429 { &custom_key.left, "Joystick Left" },
5430 { &custom_key.right, "Joystick Right" },
5431 { &custom_key.up, "Joystick Up" },
5432 { &custom_key.down, "Joystick Down" },
5433 { &custom_key.snap, "Button 1" },
5434 { &custom_key.drop, "Button 2" }
5436 static char *joystick_name[MAX_PLAYERS] =
5443 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5447 custom_key = setup.input[player_nr].key;
5449 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5450 FONT_INPUT_1_ACTIVE);
5452 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5454 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5455 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5457 if (setup.input[player_nr].use_joystick)
5459 char *device_name = setup.input[player_nr].joy.device_name;
5460 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5461 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5463 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5464 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5468 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5469 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5472 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5474 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5475 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5476 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5477 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5479 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5480 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5481 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5482 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5483 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5484 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5486 for (i = 0; i < 6; i++)
5488 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5490 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5492 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5493 (setup.input[player_nr].use_joystick ?
5495 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5499 static int input_player_nr = 0;
5501 void HandleSetupScreen_Input_Player(int step, int direction)
5503 int old_player_nr = input_player_nr;
5506 new_player_nr = old_player_nr + step * direction;
5507 if (new_player_nr < 0)
5509 if (new_player_nr > MAX_PLAYERS - 1)
5510 new_player_nr = MAX_PLAYERS - 1;
5512 if (new_player_nr != old_player_nr)
5514 input_player_nr = new_player_nr;
5516 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5520 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5522 static int choice = 0;
5525 int pos_start = SETUPINPUT_SCREEN_POS_START;
5526 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5527 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5528 int pos_end = SETUPINPUT_SCREEN_POS_END;
5530 if (button == MB_MENU_INITIALIZE)
5532 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5535 DrawCursorAndText_Setup(choice, TRUE);
5537 drawCursor(choice, TRUE);
5542 else if (button == MB_MENU_LEAVE)
5544 setup_mode = SETUP_MODE_MAIN;
5551 if (mx || my) /* mouse input */
5553 x = (mx - mSX) / 32;
5554 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5556 else if (dx || dy) /* keyboard input */
5558 if (dx && choice == 0)
5559 x = (dx < 0 ? 10 : 12);
5560 else if ((dx && choice == 1) ||
5561 (dx == +1 && choice == 2) ||
5562 (dx == -1 && choice == pos_end))
5563 button = MB_MENU_CHOICE;
5567 if (y >= pos_empty1 && y <= pos_empty2)
5568 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5571 if (y == 0 && dx != 0 && button)
5573 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5575 else if (IN_VIS_FIELD(x, y) &&
5576 y >= pos_start && y <= pos_end &&
5577 !(y >= pos_empty1 && y <= pos_empty2))
5584 DrawCursorAndText_Setup(choice, FALSE);
5585 DrawCursorAndText_Setup(y, TRUE);
5587 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5589 drawCursor(choice, FALSE);
5590 drawCursor(y, TRUE);
5600 char *device_name = setup.input[input_player_nr].joy.device_name;
5602 if (!setup.input[input_player_nr].use_joystick)
5604 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5606 setJoystickDeviceToNr(device_name, new_device_nr);
5607 setup.input[input_player_nr].use_joystick = TRUE;
5611 int device_nr = getJoystickNrFromDeviceName(device_name);
5612 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5614 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5615 setup.input[input_player_nr].use_joystick = FALSE;
5617 setJoystickDeviceToNr(device_name, new_device_nr);
5620 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5624 if (setup.input[input_player_nr].use_joystick)
5627 CalibrateJoystick(input_player_nr);
5630 CustomizeKeyboard(input_player_nr);
5632 else if (y == pos_end)
5638 setup_mode = SETUP_MODE_MAIN;
5645 void CustomizeKeyboard(int player_nr)
5649 boolean finished = FALSE;
5650 static struct SetupKeyboardInfo custom_key;
5655 } customize_step[] =
5657 { &custom_key.left, "Move Left" },
5658 { &custom_key.right, "Move Right" },
5659 { &custom_key.up, "Move Up" },
5660 { &custom_key.down, "Move Down" },
5661 { &custom_key.snap, "Snap Field" },
5662 { &custom_key.drop, "Drop Element" }
5665 /* read existing key bindings from player setup */
5666 custom_key = setup.input[player_nr].key;
5669 FadeOut(REDRAW_FIELD);
5673 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5681 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5682 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5683 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5684 "Key:", FONT_INPUT_1_ACTIVE);
5685 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5686 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5689 FadeIn(REDRAW_FIELD);
5696 if (PendingEvent()) /* got event */
5704 case EVENT_KEYPRESS:
5706 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5708 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5710 if (key == KSYM_Escape)
5711 FadeSkipNextFadeIn();
5717 /* all keys configured -- wait for "Escape" or "Return" key */
5721 /* press 'Enter' to keep the existing key binding */
5722 if (key == KSYM_Return)
5723 key = *customize_step[step_nr].key;
5725 /* check if key already used */
5726 for (i = 0; i < step_nr; i++)
5727 if (*customize_step[i].key == key)
5732 /* got new key binding */
5733 *customize_step[step_nr].key = key;
5734 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5736 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5737 getKeyNameFromKey(key), FONT_VALUE_1);
5740 /* un-highlight last query */
5741 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5742 customize_step[step_nr - 1].text, FONT_MENU_1);
5743 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5744 "Key:", FONT_MENU_1);
5746 /* press 'Enter' to leave */
5749 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5750 "Press Enter", FONT_TITLE_1);
5754 /* query next key binding */
5755 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5756 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5757 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5758 "Key:", FONT_INPUT_1_ACTIVE);
5759 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5760 getKeyNameFromKey(*customize_step[step_nr].key),
5765 case EVENT_KEYRELEASE:
5766 key_joystick_mapping = 0;
5770 HandleOtherEvents(&event);
5778 /* don't eat all CPU time */
5782 /* write new key bindings back to player setup */
5783 setup.input[player_nr].key = custom_key;
5786 DrawSetupScreen_Input();
5789 static boolean CalibrateJoystickMain(int player_nr)
5791 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5792 int new_joystick_xright = JOYSTICK_XMIDDLE;
5793 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5794 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5795 int new_joystick_xmiddle, new_joystick_ymiddle;
5797 int joystick_fd = joystick.fd[player_nr];
5798 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5799 boolean check[3][3];
5800 int check_remaining = 3 * 3;
5805 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5808 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5812 FadeOut(REDRAW_FIELD);
5816 for (y = 0; y < 3; y++)
5818 for (x = 0; x < 3; x++)
5820 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5821 check[x][y] = FALSE;
5825 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5826 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5827 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5828 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5829 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5830 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5831 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5833 joy_value = Joystick(player_nr);
5834 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5835 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5837 /* eventually uncalibrated center position (joystick could be uncentered) */
5838 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5841 new_joystick_xmiddle = joy_x;
5842 new_joystick_ymiddle = joy_y;
5844 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5847 FadeIn(REDRAW_FIELD);
5852 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5857 if (PendingEvent()) /* got event */
5865 case EVENT_KEYPRESS:
5866 switch (GetEventKey((KeyEvent *)&event, TRUE))
5869 if (check_remaining == 0)
5874 FadeSkipNextFadeIn();
5883 case EVENT_KEYRELEASE:
5884 key_joystick_mapping = 0;
5888 HandleOtherEvents(&event);
5893 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5896 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5897 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5898 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5899 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5901 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5902 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5903 setup.input[player_nr].joy.xright = new_joystick_xright;
5904 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5905 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5906 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5908 CheckJoystickData();
5910 joy_value = Joystick(player_nr);
5912 if (joy_value & JOY_BUTTON && check_remaining == 0)
5915 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5916 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5918 if (x != last_x || y != last_y)
5920 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5921 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5926 if (check_remaining > 0 && !check[x+1][y+1])
5928 check[x+1][y+1] = TRUE;
5934 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5935 setup.input[player_nr].joy.xleft,
5936 setup.input[player_nr].joy.xmiddle,
5937 setup.input[player_nr].joy.xright);
5938 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5939 setup.input[player_nr].joy.yupper,
5940 setup.input[player_nr].joy.ymiddle,
5941 setup.input[player_nr].joy.ylower);
5950 /* don't eat all CPU time */
5954 /* calibrated center position (joystick should now be centered) */
5955 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5958 new_joystick_xmiddle = joy_x;
5959 new_joystick_ymiddle = joy_y;
5964 DrawSetupScreen_Input();
5967 /* wait until the last pressed button was released */
5968 while (Joystick(player_nr) & JOY_BUTTON)
5970 if (PendingEvent()) /* got event */
5975 HandleOtherEvents(&event);
5984 void CalibrateJoystick(int player_nr)
5986 if (!CalibrateJoystickMain(player_nr))
5988 char *device_name = setup.input[player_nr].joy.device_name;
5989 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5990 int xpos = mSX - SX;
5991 int ypos = mSY - SY;
5995 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5996 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5999 Delay(2000); /* show error message for a short time */
6005 DrawSetupScreen_Input();
6009 void DrawSetupScreen()
6011 DeactivateJoystick();
6013 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6015 if (setup_mode == SETUP_MODE_INPUT)
6016 DrawSetupScreen_Input();
6017 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6018 DrawChooseTree(&game_speed_current);
6019 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6020 DrawChooseTree(&screen_mode_current);
6021 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6022 DrawChooseTree(&scroll_delay_current);
6023 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6024 DrawChooseTree(&artwork.gfx_current);
6025 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6026 DrawChooseTree(&artwork.snd_current);
6027 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6028 DrawChooseTree(&artwork.mus_current);
6030 DrawSetupScreen_Generic();
6036 void RedrawSetupScreenAfterFullscreenToggle()
6038 if (setup_mode == SETUP_MODE_GRAPHICS)
6042 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6044 if (setup_mode == SETUP_MODE_INPUT)
6045 HandleSetupScreen_Input(mx, my, dx, dy, button);
6046 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6047 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6048 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6049 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6050 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6051 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6052 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6053 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6054 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6055 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6056 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6057 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6059 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6064 void HandleGameActions()
6066 if (game_status != GAME_MODE_PLAYING)
6069 GameActions(); /* main game loop */
6071 if (tape.auto_play && !tape.playing)
6072 AutoPlayTape(); /* continue automatically playing next tape */
6076 /* ---------- new screen button stuff -------------------------------------- */
6078 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6083 case SCREEN_CTRL_ID_PREV_LEVEL:
6084 *x = mSX + menu.main.button.prev_level.x;
6085 *y = mSY + menu.main.button.prev_level.y;
6088 case SCREEN_CTRL_ID_NEXT_LEVEL:
6089 *x = mSX + menu.main.button.next_level.x;
6090 *y = mSY + menu.main.button.next_level.y;
6093 case SCREEN_CTRL_ID_PREV_LEVEL:
6094 *x = mSX + TILEX * getPrevlevelButtonPos();
6095 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6098 case SCREEN_CTRL_ID_NEXT_LEVEL:
6099 *x = mSX + TILEX * getNextLevelButtonPos();
6100 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6104 case SCREEN_CTRL_ID_PREV_PLAYER:
6105 *x = mSX + TILEX * 10;
6106 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6109 case SCREEN_CTRL_ID_NEXT_PLAYER:
6110 *x = mSX + TILEX * 12;
6111 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6115 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6121 int gfx_unpressed, gfx_pressed;
6122 void (*get_gadget_position)(int *, int *, int);
6126 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6129 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6130 getScreenMenuButtonPos,
6131 SCREEN_CTRL_ID_PREV_LEVEL,
6136 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6137 getScreenMenuButtonPos,
6138 SCREEN_CTRL_ID_NEXT_LEVEL,
6143 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6144 getScreenMenuButtonPos,
6145 SCREEN_CTRL_ID_PREV_PLAYER,
6150 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6151 getScreenMenuButtonPos,
6152 SCREEN_CTRL_ID_NEXT_PLAYER,
6160 int gfx_unpressed, gfx_pressed;
6164 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6167 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6168 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6169 SCREEN_CTRL_ID_SCROLL_UP,
6173 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6174 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6175 SCREEN_CTRL_ID_SCROLL_DOWN,
6182 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6183 Bitmap **gfx_unpressed, **gfx_pressed;
6185 int gfx_unpressed, gfx_pressed;
6192 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6195 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6196 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6198 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6200 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6201 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6202 GD_TYPE_SCROLLBAR_VERTICAL,
6203 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6204 "scroll level series vertically"
6208 static void CreateScreenMenubuttons()
6210 struct GadgetInfo *gi;
6211 unsigned long event_mask;
6214 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6216 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6217 int gfx_unpressed, gfx_pressed;
6218 int x, y, width, height;
6219 int gd_x1, gd_x2, gd_y1, gd_y2;
6220 int id = menubutton_info[i].gadget_id;
6222 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6224 menubutton_info[i].get_gadget_position(&x, &y, id);
6226 width = SC_MENUBUTTON_XSIZE;
6227 height = SC_MENUBUTTON_YSIZE;
6229 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6230 gfx_pressed = menubutton_info[i].gfx_pressed;
6231 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6232 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6233 gd_x1 = graphic_info[gfx_unpressed].src_x;
6234 gd_y1 = graphic_info[gfx_unpressed].src_y;
6235 gd_x2 = graphic_info[gfx_pressed].src_x;
6236 gd_y2 = graphic_info[gfx_pressed].src_y;
6238 gi = CreateGadget(GDI_CUSTOM_ID, id,
6239 GDI_CUSTOM_TYPE_ID, i,
6240 GDI_INFO_TEXT, menubutton_info[i].infotext,
6245 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6246 GDI_STATE, GD_BUTTON_UNPRESSED,
6247 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6248 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6249 GDI_DIRECT_DRAW, FALSE,
6250 GDI_EVENT_MASK, event_mask,
6251 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6255 Error(ERR_EXIT, "cannot create gadget");
6257 screen_gadget[id] = gi;
6261 static void CreateScreenScrollbuttons()
6263 struct GadgetInfo *gi;
6264 unsigned long event_mask;
6267 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6269 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6270 int gfx_unpressed, gfx_pressed;
6271 int x, y, width, height;
6272 int gd_x1, gd_x2, gd_y1, gd_y2;
6273 int id = scrollbutton_info[i].gadget_id;
6275 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6277 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6278 y = mSY + scrollbutton_info[i].y;
6279 width = SC_SCROLLBUTTON_XSIZE;
6280 height = SC_SCROLLBUTTON_YSIZE;
6282 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6283 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6284 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6286 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6287 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6288 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6289 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6290 gd_x1 = graphic_info[gfx_unpressed].src_x;
6291 gd_y1 = graphic_info[gfx_unpressed].src_y;
6292 gd_x2 = graphic_info[gfx_pressed].src_x;
6293 gd_y2 = graphic_info[gfx_pressed].src_y;
6295 gi = CreateGadget(GDI_CUSTOM_ID, id,
6296 GDI_CUSTOM_TYPE_ID, i,
6297 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6302 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6303 GDI_STATE, GD_BUTTON_UNPRESSED,
6304 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6305 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6306 GDI_DIRECT_DRAW, FALSE,
6307 GDI_EVENT_MASK, event_mask,
6308 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6312 Error(ERR_EXIT, "cannot create gadget");
6314 screen_gadget[id] = gi;
6318 static void CreateScreenScrollbars()
6322 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6324 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6325 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6326 int gfx_unpressed, gfx_pressed;
6328 int x, y, width, height;
6329 int gd_x1, gd_x2, gd_y1, gd_y2;
6330 struct GadgetInfo *gi;
6331 int items_max, items_visible, item_position;
6332 unsigned long event_mask;
6333 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6334 int id = scrollbar_info[i].gadget_id;
6336 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6338 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6339 y = mSY + scrollbar_info[i].y;
6340 width = scrollbar_info[i].width;
6341 height = scrollbar_info[i].height;
6343 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6344 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6346 items_max = num_page_entries;
6347 items_visible = num_page_entries;
6350 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6351 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6352 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6358 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6359 gfx_pressed = scrollbar_info[i].gfx_pressed;
6360 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6361 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6362 gd_x1 = graphic_info[gfx_unpressed].src_x;
6363 gd_y1 = graphic_info[gfx_unpressed].src_y;
6364 gd_x2 = graphic_info[gfx_pressed].src_x;
6365 gd_y2 = graphic_info[gfx_pressed].src_y;
6368 gi = CreateGadget(GDI_CUSTOM_ID, id,
6369 GDI_CUSTOM_TYPE_ID, i,
6370 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6375 GDI_TYPE, scrollbar_info[i].type,
6376 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6377 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6378 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6380 GDI_WHEEL_AREA_X, SX,
6381 GDI_WHEEL_AREA_Y, SY,
6382 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6383 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6385 GDI_WHEEL_AREA_X, 0,
6386 GDI_WHEEL_AREA_Y, 0,
6387 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6388 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6390 GDI_STATE, GD_BUTTON_UNPRESSED,
6391 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6392 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6393 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6394 GDI_DIRECT_DRAW, FALSE,
6395 GDI_EVENT_MASK, event_mask,
6396 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6400 Error(ERR_EXIT, "cannot create gadget");
6402 screen_gadget[id] = gi;
6406 void CreateScreenGadgets()
6408 int last_game_status = game_status; /* save current game status */
6410 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6413 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6415 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6417 /* copy pointers to clip mask and GC */
6418 scrollbar_bitmap[i]->clip_mask =
6419 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6420 scrollbar_bitmap[i]->stored_clip_gc =
6421 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6423 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6424 scrollbar_bitmap[i],
6425 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6426 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6427 TILEX, TILEY, 0, 0);
6431 CreateScreenMenubuttons();
6434 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6435 game_status = GAME_MODE_LEVELS;
6438 CreateScreenScrollbuttons();
6439 CreateScreenScrollbars();
6441 game_status = last_game_status; /* restore current game status */
6444 void FreeScreenGadgets()
6448 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6449 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6451 /* prevent freeing clip mask and GC twice */
6452 scrollbar_bitmap[i]->clip_mask = None;
6453 scrollbar_bitmap[i]->stored_clip_gc = None;
6455 FreeBitmap(scrollbar_bitmap[i]);
6459 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6460 FreeGadget(screen_gadget[i]);
6463 void MapScreenMenuGadgets(int screen_mask)
6467 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6468 if (screen_mask & menubutton_info[i].screen_mask)
6469 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6472 void MapScreenTreeGadgets(TreeInfo *ti)
6474 int num_entries = numTreeInfoInGroup(ti);
6477 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6480 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6481 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6483 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6484 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6487 static void HandleScreenGadgets(struct GadgetInfo *gi)
6489 int id = gi->custom_id;
6490 int button = gi->event.button;
6491 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6495 case SCREEN_CTRL_ID_PREV_LEVEL:
6496 HandleMainMenu_SelectLevel(step, -1);
6499 case SCREEN_CTRL_ID_NEXT_LEVEL:
6500 HandleMainMenu_SelectLevel(step, +1);
6503 case SCREEN_CTRL_ID_PREV_PLAYER:
6504 HandleSetupScreen_Input_Player(step, -1);
6507 case SCREEN_CTRL_ID_NEXT_PLAYER:
6508 HandleSetupScreen_Input_Player(step, +1);
6511 case SCREEN_CTRL_ID_SCROLL_UP:
6512 if (game_status == GAME_MODE_LEVELS)
6513 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6514 else if (game_status == GAME_MODE_SETUP)
6515 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6518 case SCREEN_CTRL_ID_SCROLL_DOWN:
6519 if (game_status == GAME_MODE_LEVELS)
6520 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6521 else if (game_status == GAME_MODE_SETUP)
6522 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6525 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6526 if (game_status == GAME_MODE_LEVELS)
6527 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6528 else if (game_status == GAME_MODE_SETUP)
6529 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);