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();
1320 FadeOut(redraw_mask);
1324 FadeSoundsAndMusic();
1326 KeyboardAutoRepeatOn();
1329 SetDrawDeactivationMask(REDRAW_NONE);
1330 SetDrawBackgroundMask(REDRAW_FIELD);
1332 audio.sound_deactivated = FALSE;
1336 /* needed if last screen was the playing screen, invoked from level editor */
1337 if (level_editor_test_game)
1339 game_status = GAME_MODE_EDITOR;
1345 /* needed if last screen was the editor screen */
1346 UndrawSpecialEditorDoor();
1348 /* needed if last screen was the setup screen and fullscreen state changed */
1349 ToggleFullscreenIfNeeded();
1351 /* leveldir_current may be invalid (level group, parent link) */
1352 if (!validLevelSeries(leveldir_current))
1353 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1355 if (leveldir_current != leveldir_last_valid)
1356 levelset_has_changed = TRUE;
1358 /* store valid level series information */
1359 leveldir_last_valid = leveldir_current;
1361 /* needed if last screen (level choice) changed graphics, sounds or music */
1362 ReloadCustomArtwork(0);
1364 #if defined(TARGET_SDL)
1365 SetDrawtoField(DRAW_BACKBUFFER);
1369 if (levelset_has_changed)
1370 fading = title_default;
1374 if (CheckTitleScreen(levelset_has_changed))
1376 game_status = GAME_MODE_TITLE;
1385 if (setup.show_titlescreen &&
1386 ((levelset_has_changed &&
1387 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1388 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1389 (show_title_initial &&
1390 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1391 getLevelSetMessageFilename(1, TRUE) != NULL))))
1393 game_status = GAME_MODE_TITLE;
1401 /* level_nr may have been set to value over handicap with level editor */
1402 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1403 level_nr = leveldir_current->handicap_level;
1405 LoadLevel(level_nr);
1407 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1410 FadeOut(redraw_mask);
1414 if (redraw_mask == REDRAW_ALL)
1417 int door_state = GetDoorState();
1422 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1426 OpenDoor(DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1428 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1437 InitializeMainControls();
1440 DrawCursorAndText_Main(-1, FALSE);
1442 for (i = 0; main_controls[i].nr != -1; i++)
1444 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1445 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1446 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1447 char *text = main_controls[i].text;
1448 char *input = main_controls[i].input;
1449 int button_graphic = main_controls[i].button_graphic;
1450 int font_text = main_controls[i].font_text;
1451 int font_input = main_controls[i].font_input;
1453 if (pos_button != NULL)
1454 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1457 if (pos_text != NULL && text != NULL)
1458 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1460 if (pos_input != NULL && input != NULL)
1461 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1469 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1470 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1471 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1472 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1473 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1474 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1475 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1476 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1478 /* calculated after (possible) reload of custom artwork */
1479 name_width = getTextWidth(name_text, FONT_MENU_1);
1480 level_width = 9 * 32;
1482 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1485 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1486 int2str(level_nr, 3), FONT_VALUE_1);
1489 int text_height = getFontHeight(FONT_TEXT_3);
1490 int xpos = getLevelRangeTextPos() * 32 + 8;
1491 int ypos2 = 3 * 32 + 16;
1492 int ypos1 = ypos2 - text_height;
1494 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1495 "%03d", leveldir_current->first_level);
1496 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1497 "%03d", leveldir_current->last_level);
1500 for (i = 0; i < 8; i++)
1501 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1504 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1507 DrawPreviewLevel(TRUE);
1509 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1512 if (TAPE_IS_EMPTY(tape))
1514 DrawCompleteVideoDisplay();
1519 /* create gadgets for main menu screen */
1520 FreeScreenGadgets();
1521 CreateScreenGadgets();
1524 BlitBitmap(drawto, window, VX, VY, VXSIZE, VYSIZE, VX, VY);
1528 /* map gadgets for main menu screen */
1530 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1533 DrawMaskedBorder(REDRAW_ALL);
1537 if (redraw_mask == REDRAW_ALL)
1539 int door_state = GetDoorState();
1541 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1547 game_status = GAME_MODE_PSEUDO_PREVIEW;
1549 DrawText(20, 400, "text_3.PREVIEW", FONT_TEXT_3);
1550 DrawText(20, 420, "text_4.PREVIEW", FONT_TEXT_4);
1552 game_status = GAME_MODE_MAIN;
1554 DrawText(20, 440, "text_3.MAIN", FONT_TEXT_3);
1555 DrawText(20, 460, "text_4.MAIN", FONT_TEXT_4);
1560 FadeIn(redraw_mask);
1565 else if (fading.anim_mode == ANIM_CROSSFADE)
1566 FadeCross(redraw_mask);
1568 FadeIn(redraw_mask);
1571 FadeIn(redraw_mask);
1580 fading = title_default;
1583 SetMouseCursor(CURSOR_DEFAULT);
1587 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1590 void DrawAndFadeInMainMenu(int redraw_mask)
1592 DrawMainMenuExt(redraw_mask, TRUE);
1597 DrawMainMenuExt(REDRAW_ALL, FALSE);
1601 static void gotoTopLevelDir()
1603 /* move upwards to top level directory */
1604 while (leveldir_current->node_parent)
1606 /* write a "path" into level tree for easy navigation to last level */
1607 if (leveldir_current->node_parent->node_group->cl_first == -1)
1609 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1610 int leveldir_pos = posTreeInfo(leveldir_current);
1611 int num_page_entries;
1612 int cl_first, cl_cursor;
1614 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1615 num_page_entries = num_leveldirs;
1617 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1619 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1620 cl_cursor = leveldir_pos - cl_first;
1622 leveldir_current->node_parent->node_group->cl_first = cl_first;
1623 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1626 leveldir_current = leveldir_current->node_parent;
1631 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1633 static unsigned long title_delay = 0;
1634 static int title_screen_nr = 0;
1635 static int last_sound = -1, last_music = -1;
1636 boolean return_to_main_menu = FALSE;
1637 boolean use_fading_main_menu = TRUE;
1640 boolean use_cross_fading = FALSE;
1642 boolean use_cross_fading = !show_title_initial; /* default */
1645 struct TitleControlInfo *tci;
1646 struct TitleFadingInfo fading_default;
1647 struct TitleFadingInfo fading_last = fading;
1648 struct TitleFadingInfo fading_next;
1651 if (button == MB_MENU_INITIALIZE)
1654 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1658 int last_game_status = game_status; /* save current game status */
1662 title_screen_nr = 0;
1663 tci = &title_controls[title_screen_nr];
1665 last_sound = SND_UNDEFINED;
1666 last_music = MUS_UNDEFINED;
1669 /* determine number of title screens to display (images and messages) */
1670 InitializeTitleControls();
1673 if (game_status == GAME_MODE_INFO)
1675 if (num_title_screens == 0)
1677 DrawInfoScreen_NotAvailable("Title screen information:",
1678 "No title screen for this level set.");
1681 /* use default settings for fading, but always disable auto delay */
1682 fading = title_default;
1683 fading.auto_delay = -1;
1689 FadeSoundsAndMusic();
1692 FadeOut(REDRAW_ALL);
1697 DrawTitleScreenImage(tci->local_nr, tci->initial);
1699 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1701 fading_default = (tci->initial ? title_initial_default : title_default);
1703 fading = fading_next = getTitleFading(tci);
1707 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1708 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1710 fading.fade_mode = FADE_MODE_FADE;
1711 fading.fade_delay = fading_default.fade_delay;
1714 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1715 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1716 fading.fade_mode = FADE_MODE_FADE;
1721 sound = getTitleSound(tci);
1722 music = getTitleMusic(tci);
1724 if (sound != last_sound)
1725 PlayMenuSoundExt(sound);
1726 if (music != last_music)
1727 PlayMenuMusicExt(music);
1733 SetMouseCursor(CURSOR_NONE);
1735 // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
1741 fading = fading_next;
1743 DelayReached(&title_delay, 0); /* reset delay counter */
1749 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1750 button = MB_MENU_CHOICE;
1752 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1753 button = MB_MENU_CHOICE;
1756 if (button == MB_MENU_LEAVE)
1758 return_to_main_menu = TRUE;
1759 use_fading_main_menu = FALSE;
1761 else if (button == MB_MENU_CHOICE)
1764 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1767 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1770 FadeOut(REDRAW_FIELD);
1773 FadeSetEnterScreen();
1775 info_mode = INFO_MODE_MAIN;
1776 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1782 tci = &title_controls[title_screen_nr];
1784 if (title_screen_nr < num_title_screens)
1788 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1795 graphic_info[getTitleScreenGraphic(tci->local_nr,
1796 tci->initial)].anim_mode;
1798 anim_mode = ANIM_FADE; /* ??? */
1800 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1801 anim_mode == ANIM_CROSSFADE ? TRUE :
1805 sound = getTitleSound(tci);
1806 music = getTitleMusic(tci);
1808 if (sound == SND_UNDEFINED || sound != last_sound)
1810 if (music == MUS_UNDEFINED || music != last_music)
1814 FadeOut(REDRAW_ALL);
1818 DrawTitleScreenImage(tci->local_nr, tci->initial);
1820 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1822 fading_next = getTitleFading(tci);
1825 sound = getTitleSound(tci);
1826 music = getTitleMusic(tci);
1828 if (sound != last_sound)
1829 PlayMenuSoundExt(sound);
1830 if (music != last_music)
1831 PlayMenuMusicExt(music);
1838 printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1842 /* last screen already faded out, next screen has no animation */
1843 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1844 fading_next.fade_mode == FADE_MODE_NONE)
1845 fading = fading_next;
1847 /* last screen already faded out, next screen has no animation */
1848 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1849 fading_next.fade_mode == FADE_MODE_NONE)
1850 fading = fading_next;
1857 fading = fading_next;
1859 DelayReached(&title_delay, 0); /* reset delay counter */
1863 FadeSoundsAndMusic();
1869 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1873 FadeOut(REDRAW_ALL);
1877 FadeOut(REDRAW_ALL);
1881 return_to_main_menu = TRUE;
1885 if (return_to_main_menu)
1891 SetMouseCursor(CURSOR_DEFAULT);
1893 if (game_status == GAME_MODE_INFO)
1896 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1899 info_mode = INFO_MODE_MAIN;
1900 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1902 else /* default: return to main menu */
1905 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1908 game_status = GAME_MODE_MAIN;
1909 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1914 void HandleMainMenu_SelectLevel(int step, int direction)
1916 int old_level_nr = level_nr;
1919 new_level_nr = old_level_nr + step * direction;
1920 if (new_level_nr < leveldir_current->first_level)
1921 new_level_nr = leveldir_current->first_level;
1922 if (new_level_nr > leveldir_current->last_level)
1923 new_level_nr = leveldir_current->last_level;
1925 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1927 /* skipping levels is only allowed when trying to skip single level */
1928 if (setup.skip_levels && step == 1 &&
1929 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1931 leveldir_current->handicap_level++;
1932 SaveLevelSetup_SeriesInfo();
1935 new_level_nr = leveldir_current->handicap_level;
1938 if (new_level_nr != old_level_nr)
1940 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1942 PlaySound(SND_MENU_ITEM_SELECTING);
1944 level_nr = new_level_nr;
1947 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1948 int2str(level_nr, menu.main.text.level_number.size),
1949 mci->pos_text->font);
1951 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1954 LoadLevel(level_nr);
1955 DrawPreviewLevel(TRUE);
1959 DrawCompleteVideoDisplay();
1961 /* needed because DrawPreviewLevel() takes some time */
1969 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1971 static int choice = MAIN_CONTROL_GAME;
1975 if (button == MB_MENU_INITIALIZE)
1977 DrawCursorAndText_Main(choice, TRUE);
1982 if (mx || my) /* mouse input */
1986 for (i = 0; main_controls[i].nr != -1; i++)
1988 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1989 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1990 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1992 pos = main_controls[i].nr;
1998 else if (dx || dy) /* keyboard input */
2000 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2001 choice == MAIN_CONTROL_SETUP))
2002 button = MB_MENU_CHOICE;
2007 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
2009 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2011 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2017 PlaySound(SND_MENU_ITEM_ACTIVATING);
2019 DrawCursorAndText_Main(choice, FALSE);
2020 DrawCursorAndText_Main(pos, TRUE);
2027 PlaySound(SND_MENU_ITEM_SELECTING);
2029 if (pos == MAIN_CONTROL_NAME)
2031 game_status = GAME_MODE_PSEUDO_TYPENAME;
2033 HandleTypeName(strlen(setup.player_name), 0);
2035 else if (pos == MAIN_CONTROL_LEVELS)
2039 game_status = GAME_MODE_LEVELS;
2041 SaveLevelSetup_LastSeries();
2042 SaveLevelSetup_SeriesInfo();
2051 else if (pos == MAIN_CONTROL_SCORES)
2053 game_status = GAME_MODE_SCORES;
2057 else if (pos == MAIN_CONTROL_EDITOR)
2059 if (leveldir_current->readonly &&
2060 !strEqual(setup.player_name, "Artsoft"))
2061 Request("This level is read only !", REQ_CONFIRM);
2063 game_status = GAME_MODE_EDITOR;
2065 FadeSetEnterScreen();
2069 else if (pos == MAIN_CONTROL_INFO)
2071 game_status = GAME_MODE_INFO;
2072 info_mode = INFO_MODE_MAIN;
2075 fading = menu.navigation;
2080 else if (pos == MAIN_CONTROL_GAME)
2082 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2084 else if (pos == MAIN_CONTROL_SETUP)
2086 game_status = GAME_MODE_SETUP;
2087 setup_mode = SETUP_MODE_MAIN;
2091 else if (pos == MAIN_CONTROL_QUIT)
2093 SaveLevelSetup_LastSeries();
2094 SaveLevelSetup_SeriesInfo();
2096 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2097 game_status = GAME_MODE_QUIT;
2102 if (game_status == GAME_MODE_MAIN)
2104 DrawPreviewLevel(FALSE);
2111 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2113 static int choice = 5;
2117 if (button == MB_MENU_INITIALIZE)
2119 drawCursor(choice, TRUE);
2124 if (mx || my) /* mouse input */
2126 x = (mx - mSX) / 32;
2127 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2129 else if (dx || dy) /* keyboard input */
2131 if (dx && choice == 1)
2132 x = (dx < 0 ? 10 : 14);
2135 if (choice == 4 || choice == 6)
2136 button = MB_MENU_CHOICE;
2142 if (y == 1 && dx != 0 && button)
2144 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2146 else if (IN_VIS_FIELD(x, y) &&
2147 y >= 0 && y <= 7 && (y != 1 || x < 10))
2153 drawCursor(choice, FALSE);
2154 drawCursor(y, TRUE);
2163 game_status = GAME_MODE_PSEUDO_TYPENAME;
2164 HandleTypeName(strlen(setup.player_name), 0);
2170 game_status = GAME_MODE_LEVELS;
2172 SaveLevelSetup_LastSeries();
2173 SaveLevelSetup_SeriesInfo();
2184 game_status = GAME_MODE_SCORES;
2189 if (leveldir_current->readonly &&
2190 !strEqual(setup.player_name, "Artsoft"))
2191 Request("This level is read only !", REQ_CONFIRM);
2192 game_status = GAME_MODE_EDITOR;
2197 game_status = GAME_MODE_INFO;
2198 info_mode = INFO_MODE_MAIN;
2203 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2207 game_status = GAME_MODE_SETUP;
2208 setup_mode = SETUP_MODE_MAIN;
2214 SaveLevelSetup_LastSeries();
2215 SaveLevelSetup_SeriesInfo();
2217 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2218 game_status = GAME_MODE_QUIT;
2223 if (game_status == GAME_MODE_MAIN)
2225 DrawPreviewLevel(FALSE);
2233 /* ========================================================================= */
2234 /* info screen functions */
2235 /* ========================================================================= */
2237 static struct TokenInfo *info_info;
2238 static int num_info_info;
2240 static void execInfoTitleScreen()
2243 FadeSetEnterScreen();
2246 info_mode = INFO_MODE_TITLE;
2250 static void execInfoElements()
2253 FadeSetEnterScreen();
2256 info_mode = INFO_MODE_ELEMENTS;
2260 static void execInfoMusic()
2263 FadeSetEnterScreen();
2266 info_mode = INFO_MODE_MUSIC;
2270 static void execInfoCredits()
2273 FadeSetEnterScreen();
2276 info_mode = INFO_MODE_CREDITS;
2280 static void execInfoProgram()
2283 FadeSetEnterScreen();
2286 info_mode = INFO_MODE_PROGRAM;
2290 static void execInfoVersion()
2293 FadeSetEnterScreen();
2296 info_mode = INFO_MODE_VERSION;
2300 static void execInfoLevelSet()
2303 FadeSetEnterScreen();
2306 info_mode = INFO_MODE_LEVELSET;
2310 static void execExitInfo()
2316 game_status = GAME_MODE_MAIN;
2318 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2324 static struct TokenInfo info_info_main[] =
2326 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2327 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2328 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2329 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2330 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2331 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2332 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2333 { TYPE_EMPTY, NULL, "" },
2334 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2339 static void DrawCursorAndText_Info(int pos, boolean active)
2341 int xpos = MENU_SCREEN_START_XPOS;
2342 int ypos = MENU_SCREEN_START_YPOS + pos;
2343 int font_nr = FONT_MENU_1;
2346 font_nr = FONT_ACTIVE(font_nr);
2348 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2350 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2351 drawCursor(pos, active);
2354 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2359 CloseDoor(DOOR_CLOSE_2);
2361 /* (needed after displaying title screens which disable auto repeat) */
2362 KeyboardAutoRepeatOn();
2364 FadeSetLeaveScreen();
2367 FadeOut(redraw_mask);
2371 if (redraw_mask == REDRAW_ALL)
2374 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2380 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2382 info_info = info_info_main;
2385 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2388 int xpos = MENU_SCREEN_START_XPOS;
2389 int ypos = MENU_SCREEN_START_YPOS + i;
2390 int font_nr = FONT_MENU_1;
2393 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2394 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2395 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2396 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2397 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2398 initCursor(i, IMG_MENU_BUTTON);
2401 DrawCursorAndText_Info(i, FALSE);
2403 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2409 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2414 DrawMaskedBorder(redraw_mask);
2417 FadeIn(redraw_mask);
2422 else if (fading.anim_mode == ANIM_CROSSFADE)
2423 FadeCross(redraw_mask);
2425 FadeIn(redraw_mask);
2428 FadeIn(redraw_mask);
2437 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2439 static int choice_store[MAX_INFO_MODES];
2440 int choice = choice_store[info_mode]; /* always starts with 0 */
2444 if (button == MB_MENU_INITIALIZE)
2446 /* advance to first valid menu entry */
2447 while (choice < num_info_info &&
2448 info_info[choice].type & TYPE_SKIP_ENTRY)
2450 choice_store[info_mode] = choice;
2453 DrawCursorAndText_Info(choice, TRUE);
2455 drawCursor(choice, TRUE);
2460 else if (button == MB_MENU_LEAVE)
2462 for (y = 0; y < num_info_info; y++)
2464 if (info_info[y].type & TYPE_LEAVE_MENU)
2466 void (*menu_callback_function)(void) = info_info[y].value;
2470 menu_callback_function();
2472 break; /* absolutely needed because function changes 'info_info'! */
2479 if (mx || my) /* mouse input */
2481 x = (mx - mSX) / 32;
2482 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2484 else if (dx || dy) /* keyboard input */
2488 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2490 if (info_info[choice].type & menu_navigation_type ||
2491 info_info[choice].type & TYPE_ENTER_SCREEN ||
2492 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2493 button = MB_MENU_CHOICE;
2498 /* jump to next non-empty menu entry (up or down) */
2499 while (y > 0 && y < num_info_info - 1 &&
2500 info_info[y].type & TYPE_SKIP_ENTRY)
2504 if (IN_VIS_FIELD(x, y) &&
2505 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2511 PlaySound(SND_MENU_ITEM_ACTIVATING);
2514 DrawCursorAndText_Info(choice, FALSE);
2515 DrawCursorAndText_Info(y, TRUE);
2517 drawCursor(choice, FALSE);
2518 drawCursor(y, TRUE);
2521 choice = choice_store[info_mode] = y;
2524 else if (!(info_info[y].type & TYPE_GHOSTED))
2526 PlaySound(SND_MENU_ITEM_SELECTING);
2528 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2530 void (*menu_callback_function)(void) = info_info[choice].value;
2532 FadeSetFromType(info_info[y].type);
2534 menu_callback_function();
2540 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2543 int ystart1 = mSY - SY + 100;
2544 int ystart2 = mSY - SY + 150;
2545 int ybottom = mSY - SY + SYSIZE - 20;
2549 int ybottom = SYSIZE - 20;
2552 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2555 FadeOut(REDRAW_FIELD);
2561 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2562 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2564 DrawTextSCentered(ybottom, FONT_TEXT_4,
2565 "Press any key or button for info menu");
2568 FadeIn(REDRAW_FIELD);
2572 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2574 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2575 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2576 int xstart = mSX + 16;
2577 int ystart1 = mSY - SY + 100;
2578 int ystart2 = mSY + 64 + 2 * 32;
2579 int ybottom = mSY - SY + SYSIZE - 20;
2580 int ystep = TILEY + 4;
2581 int element, action, direction;
2589 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2590 infoscreen_step[i] = infoscreen_frame[i] = 0;
2595 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2597 DrawTextSCentered(ybottom, FONT_TEXT_4,
2598 "Press any key or button for next page");
2604 while (helpanim_info[j].element != HELPANIM_LIST_END)
2606 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2611 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2620 j += infoscreen_step[i - start];
2622 element = helpanim_info[j].element;
2623 action = helpanim_info[j].action;
2624 direction = helpanim_info[j].direction;
2627 element = EL_UNKNOWN;
2629 if (action != -1 && direction != -1)
2630 graphic = el_act_dir2img(element, action, direction);
2631 else if (action != -1)
2632 graphic = el_act2img(element, action);
2633 else if (direction != -1)
2634 graphic = el_dir2img(element, direction);
2636 graphic = el2img(element);
2638 delay = helpanim_info[j++].delay;
2643 if (infoscreen_frame[i - start] == 0)
2646 infoscreen_frame[i - start] = delay - 1;
2650 sync_frame = delay - infoscreen_frame[i - start];
2651 infoscreen_frame[i - start]--;
2654 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2656 if (!infoscreen_frame[i - start])
2657 infoscreen_step[i - start] = 0;
2661 if (!infoscreen_frame[i - start])
2662 infoscreen_step[i - start]++;
2663 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2669 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2671 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2672 graphic, sync_frame, USE_MASKING);
2675 DrawInfoScreen_HelpText(element, action, direction, i - start);
2680 redraw_mask |= REDRAW_FIELD;
2685 static char *getHelpText(int element, int action, int direction)
2687 char token[MAX_LINE_LEN];
2689 strcpy(token, element_info[element].token_name);
2692 strcat(token, element_action_info[action].suffix);
2694 if (direction != -1)
2695 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2697 return getHashEntry(helptext_info, token);
2700 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2703 int font_nr = FONT_INFO_ELEMENTS;
2705 int font_nr = FONT_LEVEL_NUMBER;
2707 int font_width = getFontWidth(font_nr);
2708 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2709 int sy = mSY + 65 + 2 * 32 + 1;
2710 int ystep = TILEY + 4;
2711 int pad_x = sx - SX;
2712 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2713 int max_lines_per_text = 2;
2716 if (action != -1 && direction != -1) /* element.action.direction */
2717 text = getHelpText(element, action, direction);
2719 if (text == NULL && action != -1) /* element.action */
2720 text = getHelpText(element, action, -1);
2722 if (text == NULL && direction != -1) /* element.direction */
2723 text = getHelpText(element, -1, direction);
2725 if (text == NULL) /* base element */
2726 text = getHelpText(element, -1, -1);
2728 if (text == NULL) /* not found */
2729 text = "No description available";
2731 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2732 sy += getFontHeight(font_nr) / 2;
2735 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2736 max_chars_per_line, -1, max_lines_per_text, -1,
2737 TRUE, FALSE, FALSE);
2739 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2740 max_chars_per_line, max_lines_per_text);
2744 void DrawInfoScreen_TitleScreen()
2749 void HandleInfoScreen_TitleScreen(int button)
2751 HandleTitleScreen(0, 0, 0, 0, button);
2754 void DrawInfoScreen_Elements()
2756 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2759 FadeOut(REDRAW_FIELD);
2765 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2768 FadeIn(REDRAW_FIELD);
2774 void HandleInfoScreen_Elements(int button)
2776 static unsigned long info_delay = 0;
2777 static int num_anims;
2778 static int num_pages;
2780 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2783 if (button == MB_MENU_INITIALIZE)
2785 boolean new_element = TRUE;
2789 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2791 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2793 else if (new_element)
2796 new_element = FALSE;
2800 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2804 if (button == MB_MENU_LEAVE)
2806 PlaySound(SND_MENU_ITEM_SELECTING);
2808 info_mode = INFO_MODE_MAIN;
2813 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2815 if (button != MB_MENU_INITIALIZE)
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2822 if (page >= num_pages)
2824 FadeSoundsAndMusic();
2827 FadeOut(REDRAW_FIELD);
2830 info_mode = INFO_MODE_MAIN;
2831 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2836 if (button != MB_MENU_INITIALIZE)
2837 FadeCrossSaveBackbuffer();
2839 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2841 if (button != MB_MENU_INITIALIZE)
2842 FadeCross(REDRAW_FIELD);
2846 if (DelayReached(&info_delay, GameFrameDelay))
2847 if (page < num_pages)
2848 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2850 PlayMenuSoundIfLoop();
2854 void DrawInfoScreen_Music()
2856 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2859 FadeOut(REDRAW_FIELD);
2867 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2870 FadeIn(REDRAW_FIELD);
2874 void HandleInfoScreen_Music(int button)
2876 static struct MusicFileInfo *list = NULL;
2877 int ystart1 = mSY - SY + 100;
2878 int ystart2 = mSY - SY + 150;
2879 int ybottom = mSY - SY + SYSIZE - 20;
2882 if (button == MB_MENU_INITIALIZE)
2884 list = music_file_info;
2888 FadeSoundsAndMusic();
2893 DrawTextSCentered(ystart1, FONT_TEXT_1,
2894 "No music info for this level set.");
2896 DrawTextSCentered(ybottom, FONT_TEXT_4,
2897 "Press any key or button for info menu");
2903 if (button == MB_MENU_LEAVE)
2905 PlaySound(SND_MENU_ITEM_SELECTING);
2907 FadeSoundsAndMusic();
2909 info_mode = INFO_MODE_MAIN;
2914 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2918 if (button != MB_MENU_INITIALIZE)
2920 PlaySound(SND_MENU_ITEM_SELECTING);
2928 FadeSoundsAndMusic();
2931 FadeOut(REDRAW_FIELD);
2934 info_mode = INFO_MODE_MAIN;
2935 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2940 FadeSoundsAndMusic();
2942 if (button != MB_MENU_INITIALIZE)
2943 FadeCrossSaveBackbuffer();
2950 int sound = list->music;
2952 if (sound_info[sound].loop)
2953 PlaySoundLoop(sound);
2957 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2961 PlayMusic(list->music);
2963 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2966 if (!strEqual(list->title, UNKNOWN_NAME))
2968 if (!strEqual(list->title_header, UNKNOWN_NAME))
2969 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2971 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2974 if (!strEqual(list->artist, UNKNOWN_NAME))
2976 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2977 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2979 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2981 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2984 if (!strEqual(list->album, UNKNOWN_NAME))
2986 if (!strEqual(list->album_header, UNKNOWN_NAME))
2987 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2989 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2991 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2994 if (!strEqual(list->year, UNKNOWN_NAME))
2996 if (!strEqual(list->year_header, UNKNOWN_NAME))
2997 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2999 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
3001 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
3004 DrawTextSCentered(ybottom, FONT_TEXT_4,
3005 "Press any key or button for next page");
3007 if (button != MB_MENU_INITIALIZE)
3008 FadeCross(REDRAW_FIELD);
3011 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3012 PlaySoundLoop(list->music);
3015 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
3017 int ystart1 = mSY - SY + 100;
3018 int ystart2 = mSY - SY + 150;
3019 int ybottom = mSY - SY + SYSIZE - 20;
3028 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
3032 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3033 "Special thanks to");
3034 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3036 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3038 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3039 "\"Boulder Dash\"");
3040 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3042 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3044 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3046 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3047 "First Star Software");
3049 else if (screen_nr == 1)
3051 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3052 "Special thanks to");
3053 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3054 "Klaus Heinz & Volker Wertich");
3055 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3057 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3058 "\"Emerald Mine\"");
3059 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3061 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3063 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3065 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3068 else if (screen_nr == 2)
3070 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3071 "Special thanks to");
3072 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3073 "Michael Stopp & Philip Jespersen");
3074 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3076 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3078 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3080 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3082 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3084 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3085 "Digital Integration");
3087 else if (screen_nr == 3)
3089 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3090 "Special thanks to");
3091 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3092 "Hiroyuki Imabayashi");
3093 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3095 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3097 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3099 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3101 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3103 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3106 else if (screen_nr == 4)
3108 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3109 "Special thanks to");
3110 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3112 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3114 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3115 "Jürgen Bonhagen");
3116 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3117 "for the continuous creation");
3118 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3119 "of outstanding level sets");
3121 else if (screen_nr == 5)
3123 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3125 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3127 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3128 "for ideas and inspiration by");
3129 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3132 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3134 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3136 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3137 "for ideas and inspiration by");
3138 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3141 else if (screen_nr == 6)
3143 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3145 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3147 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3148 "for the new Emerald Mine engine");
3150 else if (screen_nr == 7)
3152 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3154 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3156 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3157 "for the initial DOS port");
3159 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3161 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3163 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3164 "for some additional toons");
3166 else if (screen_nr == 8)
3168 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3169 "And not to forget:");
3170 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3172 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3173 "All those who contributed");
3174 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3175 "levels to this game");
3176 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3186 DrawTextSCentered(ybottom, FONT_TEXT_4,
3187 "Press any key or button for next page");
3192 void DrawInfoScreen_Credits()
3194 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3196 FadeSoundsAndMusic();
3199 FadeOut(REDRAW_FIELD);
3202 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3205 FadeIn(REDRAW_FIELD);
3209 void HandleInfoScreen_Credits(int button)
3211 static int screen_nr = 0;
3213 if (button == MB_MENU_INITIALIZE)
3217 DrawInfoScreen_CreditsScreen(screen_nr);
3219 else if (button == MB_MENU_LEAVE)
3221 PlaySound(SND_MENU_ITEM_SELECTING);
3223 info_mode = INFO_MODE_MAIN;
3228 else if (button == MB_MENU_CHOICE)
3230 boolean show_screen;
3232 PlaySound(SND_MENU_ITEM_SELECTING);
3236 FadeCrossSaveBackbuffer();
3238 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3242 FadeCross(REDRAW_FIELD);
3246 FadeSoundsAndMusic();
3249 FadeOut(REDRAW_FIELD);
3252 info_mode = INFO_MODE_MAIN;
3253 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3258 PlayMenuSoundIfLoop();
3262 void DrawInfoScreen_Program()
3264 int ystart1 = mSY - SY + 100;
3265 int ystart2 = mSY - SY + 150;
3266 int ybottom = mSY - SY + SYSIZE - 20;
3269 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3272 FadeOut(REDRAW_FIELD);
3278 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3280 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3281 "This game is Freeware!");
3282 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3283 "If you like it, send e-mail to:");
3284 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3285 PROGRAM_EMAIL_STRING);
3286 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3287 "or SnailMail to:");
3288 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3290 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3291 "Detmolder Strasse 189");
3292 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3294 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3296 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3297 "More information and levels:");
3298 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3299 PROGRAM_WEBSITE_STRING);
3300 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3301 "If you have created new levels,");
3302 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3303 "send them to me to include them!");
3304 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3307 DrawTextSCentered(ybottom, FONT_TEXT_4,
3308 "Press any key or button for info menu");
3311 FadeIn(REDRAW_FIELD);
3315 void HandleInfoScreen_Program(int button)
3317 if (button == MB_MENU_LEAVE)
3319 PlaySound(SND_MENU_ITEM_SELECTING);
3321 info_mode = INFO_MODE_MAIN;
3326 else if (button == MB_MENU_CHOICE)
3328 PlaySound(SND_MENU_ITEM_SELECTING);
3330 FadeSoundsAndMusic();
3333 FadeOut(REDRAW_FIELD);
3336 info_mode = INFO_MODE_MAIN;
3337 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3341 PlayMenuSoundIfLoop();
3345 void DrawInfoScreen_Version()
3347 int font_header = FONT_TEXT_3;
3348 int font_text = FONT_TEXT_2;
3349 int xstep = getFontWidth(font_text);
3350 int ystep = getFontHeight(font_text);
3351 int ystart1 = mSY - SY + 100;
3352 int ystart2 = mSY - SY + 150;
3353 int ybottom = mSY - SY + SYSIZE - 20;
3354 int xstart1 = mSX + 2 * xstep;
3355 int xstart2 = mSX + 19 * xstep;
3356 #if defined(TARGET_SDL)
3357 int xstart3 = mSX + 29 * xstep;
3358 SDL_version sdl_version_compiled;
3359 const SDL_version *sdl_version_linked;
3360 int driver_name_len = 8;
3361 char driver_name[driver_name_len];
3364 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3367 FadeOut(REDRAW_FIELD);
3373 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3375 DrawTextF(xstart1, ystart2, font_header, "Name");
3376 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3379 DrawTextF(xstart1, ystart2, font_header, "Version");
3380 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3383 DrawTextF(xstart1, ystart2, font_header, "Platform");
3384 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3387 DrawTextF(xstart1, ystart2, font_header, "Target");
3388 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3391 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3392 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3394 #if defined(TARGET_SDL)
3395 ystart2 += 3 * ystep;
3396 DrawTextF(xstart1, ystart2, font_header, "Library");
3397 DrawTextF(xstart2, ystart2, font_header, "compiled");
3398 DrawTextF(xstart3, ystart2, font_header, "linked");
3400 SDL_VERSION(&sdl_version_compiled);
3401 sdl_version_linked = SDL_Linked_Version();
3403 ystart2 += 2 * ystep;
3404 DrawTextF(xstart1, ystart2, font_text, "SDL");
3405 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3406 sdl_version_compiled.major,
3407 sdl_version_compiled.minor,
3408 sdl_version_compiled.patch);
3409 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3410 sdl_version_linked->major,
3411 sdl_version_linked->minor,
3412 sdl_version_linked->patch);
3414 SDL_IMAGE_VERSION(&sdl_version_compiled);
3415 sdl_version_linked = IMG_Linked_Version();
3418 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3419 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3420 sdl_version_compiled.major,
3421 sdl_version_compiled.minor,
3422 sdl_version_compiled.patch);
3423 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3424 sdl_version_linked->major,
3425 sdl_version_linked->minor,
3426 sdl_version_linked->patch);
3428 SDL_MIXER_VERSION(&sdl_version_compiled);
3429 sdl_version_linked = Mix_Linked_Version();
3432 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3433 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3434 sdl_version_compiled.major,
3435 sdl_version_compiled.minor,
3436 sdl_version_compiled.patch);
3437 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3438 sdl_version_linked->major,
3439 sdl_version_linked->minor,
3440 sdl_version_linked->patch);
3442 SDL_NET_VERSION(&sdl_version_compiled);
3443 sdl_version_linked = SDLNet_Linked_Version();
3446 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3447 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3448 sdl_version_compiled.major,
3449 sdl_version_compiled.minor,
3450 sdl_version_compiled.patch);
3451 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3452 sdl_version_linked->major,
3453 sdl_version_linked->minor,
3454 sdl_version_linked->patch);
3456 ystart2 += 3 * ystep;
3457 DrawTextF(xstart1, ystart2, font_header, "Driver");
3458 DrawTextF(xstart2, ystart2, font_header, "Requested");
3459 DrawTextF(xstart3, ystart2, font_header, "Used");
3461 SDL_VideoDriverName(driver_name, driver_name_len);
3463 ystart2 += 2 * ystep;
3464 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3465 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3466 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3468 SDL_AudioDriverName(driver_name, driver_name_len);
3471 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3472 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3473 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3476 DrawTextSCentered(ybottom, FONT_TEXT_4,
3477 "Press any key or button for info menu");
3480 FadeIn(REDRAW_FIELD);
3484 void HandleInfoScreen_Version(int button)
3486 if (button == MB_MENU_LEAVE)
3488 PlaySound(SND_MENU_ITEM_SELECTING);
3490 info_mode = INFO_MODE_MAIN;
3495 else if (button == MB_MENU_CHOICE)
3497 PlaySound(SND_MENU_ITEM_SELECTING);
3499 FadeSoundsAndMusic();
3502 FadeOut(REDRAW_FIELD);
3505 info_mode = INFO_MODE_MAIN;
3506 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3510 PlayMenuSoundIfLoop();
3514 void DrawInfoScreen_LevelSet()
3516 struct TitleMessageInfo *tmi = &readme;
3517 char *filename = getLevelSetInfoFilename();
3519 /* if chars set to "-1", automatically determine by text and font width */
3520 if (tmi->chars == -1)
3521 tmi->chars = tmi->width / getFontWidth(tmi->font);
3523 tmi->width = tmi->chars * getFontWidth(tmi->font);
3525 /* if lines set to "-1", automatically determine by text and font height */
3526 if (tmi->lines == -1)
3527 tmi->lines = tmi->height / getFontHeight(tmi->font);
3529 tmi->height = tmi->lines * getFontHeight(tmi->font);
3531 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3534 FadeOut(REDRAW_FIELD);
3540 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3542 if (filename != NULL)
3543 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3544 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3545 tmi->autowrap, tmi->centered, tmi->parse_comments);
3547 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3548 "No information for this level set.");
3550 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3551 "Press any key or button for info menu");
3554 FadeIn(REDRAW_FIELD);
3558 void HandleInfoScreen_LevelSet(int button)
3560 if (button == MB_MENU_LEAVE)
3562 PlaySound(SND_MENU_ITEM_SELECTING);
3564 info_mode = INFO_MODE_MAIN;
3569 else if (button == MB_MENU_CHOICE)
3571 PlaySound(SND_MENU_ITEM_SELECTING);
3573 FadeSoundsAndMusic();
3576 FadeOut(REDRAW_FIELD);
3579 info_mode = INFO_MODE_MAIN;
3580 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3584 PlayMenuSoundIfLoop();
3588 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3590 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3592 if (info_mode == INFO_MODE_TITLE)
3593 DrawInfoScreen_TitleScreen();
3594 else if (info_mode == INFO_MODE_ELEMENTS)
3595 DrawInfoScreen_Elements();
3596 else if (info_mode == INFO_MODE_MUSIC)
3597 DrawInfoScreen_Music();
3598 else if (info_mode == INFO_MODE_CREDITS)
3599 DrawInfoScreen_Credits();
3600 else if (info_mode == INFO_MODE_PROGRAM)
3601 DrawInfoScreen_Program();
3602 else if (info_mode == INFO_MODE_VERSION)
3603 DrawInfoScreen_Version();
3604 else if (info_mode == INFO_MODE_LEVELSET)
3605 DrawInfoScreen_LevelSet();
3607 DrawInfoScreen_Main(redraw_mask, do_fading);
3609 if (info_mode != INFO_MODE_MAIN &&
3610 info_mode != INFO_MODE_TITLE &&
3611 info_mode != INFO_MODE_MUSIC)
3618 void DrawAndFadeInInfoScreen(int redraw_mask)
3620 DrawInfoScreenExt(redraw_mask, TRUE);
3623 void DrawInfoScreen()
3625 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3628 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3630 if (info_mode == INFO_MODE_TITLE)
3631 HandleInfoScreen_TitleScreen(button);
3632 else if (info_mode == INFO_MODE_ELEMENTS)
3633 HandleInfoScreen_Elements(button);
3634 else if (info_mode == INFO_MODE_MUSIC)
3635 HandleInfoScreen_Music(button);
3636 else if (info_mode == INFO_MODE_CREDITS)
3637 HandleInfoScreen_Credits(button);
3638 else if (info_mode == INFO_MODE_PROGRAM)
3639 HandleInfoScreen_Program(button);
3640 else if (info_mode == INFO_MODE_VERSION)
3641 HandleInfoScreen_Version(button);
3642 else if (info_mode == INFO_MODE_LEVELSET)
3643 HandleInfoScreen_LevelSet(button);
3645 HandleInfoScreen_Main(mx, my, dx, dy, button);
3651 /* ========================================================================= */
3652 /* type name functions */
3653 /* ========================================================================= */
3655 void HandleTypeName(int newxpos, Key key)
3657 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3658 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3660 struct TextPosInfo *pos = mci->pos_input;
3661 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3662 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3665 static int xpos = 0;
3667 static int xpos = 0, ypos = 2;
3669 int font_nr = pos->font;
3670 int font_active_nr = FONT_ACTIVE(font_nr);
3671 int font_width = getFontWidth(font_active_nr);
3674 int startx = mSX + mci->pos_input->x;
3675 int starty = mSY + mci->pos_input->y;
3678 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3679 int startx = mSX + 32 + name_width;
3680 int starty = mSY + ypos * 32;
3682 char key_char = getValidConfigValueChar(getCharFromKey(key));
3683 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3684 boolean is_active = TRUE;
3686 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3690 strcpy(last_player_name, setup.player_name);
3695 /* add one character width for added cursor character */
3696 pos->width += font_width;
3697 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3699 DrawText(startx, starty, setup.player_name, font_active_nr);
3700 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3703 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3705 setup.player_name[xpos] = key_char;
3706 setup.player_name[xpos + 1] = 0;
3711 /* add one character width for added name text character */
3712 pos->width += font_width;
3713 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3715 DrawText(startx, starty, setup.player_name, font_active_nr);
3716 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3719 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3723 setup.player_name[xpos] = 0;
3726 /* remove one character width for removed name text character */
3727 pos->width -= font_width;
3728 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3730 DrawText(startx, starty, setup.player_name, font_active_nr);
3731 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3734 else if (key == KSYM_Return && xpos > 0)
3737 /* remove one character width for removed cursor text character */
3738 pos->width -= font_width;
3739 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3741 DrawText(startx, starty, setup.player_name, font_nr);
3742 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3749 game_status = GAME_MODE_MAIN;
3751 else if (key == KSYM_Escape)
3753 strcpy(setup.player_name, last_player_name);
3757 game_status = GAME_MODE_MAIN;
3762 pos->width = (strlen(setup.player_name) + 1) * font_width;
3763 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3765 DrawText(startx, starty, setup.player_name, font_active_nr);
3766 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3770 pos->width = strlen(setup.player_name) * font_width;
3771 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3773 DrawText(startx, starty, setup.player_name, font_nr);
3778 /* ========================================================================= */
3779 /* tree menu functions */
3780 /* ========================================================================= */
3782 static void DrawChooseTree(TreeInfo **ti_ptr)
3786 FreeScreenGadgets();
3787 CreateScreenGadgets();
3789 CloseDoor(DOOR_CLOSE_2);
3792 FadeOut(REDRAW_FIELD);
3797 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3798 MapScreenTreeGadgets(*ti_ptr);
3801 FadeIn(REDRAW_FIELD);
3807 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3809 struct GadgetInfo *gi = screen_gadget[id];
3810 int items_max, items_visible, item_position;
3812 items_max = numTreeInfoInGroup(ti);
3813 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3814 item_position = first_entry;
3816 if (item_position > items_max - items_visible)
3817 item_position = items_max - items_visible;
3819 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3820 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3821 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3824 static void drawChooseTreeList(int first_entry, int num_page_entries,
3828 char *title_string = NULL;
3829 int yoffset_sets = MENU_TITLE1_YPOS;
3830 int yoffset_setup = 16;
3831 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3833 int last_game_status = game_status; /* save current game status */
3835 title_string = ti->infotext;
3837 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3840 /* force LEVELS font on artwork setup screen */
3841 game_status = GAME_MODE_LEVELS;
3845 /* clear tree list area, but not title or scrollbar */
3846 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3847 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3848 NUM_MENU_ENTRIES_ON_SCREEN * 32);
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 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3856 for (i = 0; i < num_page_entries; i++)
3858 TreeInfo *node, *node_first;
3859 int entry_pos = first_entry + i;
3860 int xpos = MENU_SCREEN_START_XPOS;
3861 int ypos = MENU_SCREEN_START_YPOS + i;
3862 int startx = mSX + xpos * 32;
3863 int starty = mSY + ypos * 32;
3864 int font_nr = FONT_TEXT_1;
3865 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3866 int startx_text = startx + font_xoffset;
3867 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3868 int text_size = startx_scrollbar - startx_text;
3869 int max_buffer_len = text_size / getFontWidth(font_nr);
3870 char buffer[max_buffer_len + 1];
3872 node_first = getTreeInfoFirstGroupEntry(ti);
3873 node = getTreeInfoFromPos(node_first, entry_pos);
3875 strncpy(buffer, node->name, max_buffer_len);
3876 buffer[max_buffer_len] = '\0';
3878 DrawText(startx, starty, buffer, font_nr + node->color);
3880 if (node->parent_link)
3881 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3882 else if (node->level_group)
3883 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3885 initCursor(i, IMG_MENU_BUTTON);
3888 game_status = last_game_status; /* restore current game status */
3890 redraw_mask |= REDRAW_FIELD;
3893 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3895 TreeInfo *node, *node_first;
3896 int x, last_redraw_mask = redraw_mask;
3897 int ypos = MENU_TITLE2_YPOS;
3898 int font_nr = FONT_TITLE_2;
3900 if (ti->type != TREE_TYPE_LEVEL_DIR)
3903 node_first = getTreeInfoFirstGroupEntry(ti);
3904 node = getTreeInfoFromPos(node_first, entry_pos);
3906 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3908 if (node->parent_link)
3909 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3911 else if (node->level_group)
3912 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3914 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3915 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3916 node->levels, node->class_desc);
3918 /* let BackToFront() redraw only what is needed */
3919 redraw_mask = last_redraw_mask | REDRAW_TILES;
3920 for (x = 0; x < SCR_FIELDX; x++)
3921 MarkTileDirty(x, 1);
3924 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3927 TreeInfo *ti = *ti_ptr;
3929 int y = ti->cl_cursor;
3930 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3931 int num_entries = numTreeInfoInGroup(ti);
3932 int num_page_entries;
3933 int last_game_status = game_status; /* save current game status */
3934 boolean position_set_by_scrollbar = (dx == 999);
3937 /* force LEVELS draw offset on choose level and artwork setup screen */
3938 game_status = GAME_MODE_LEVELS;
3941 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3942 num_page_entries = num_entries;
3944 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3946 game_status = last_game_status; /* restore current game status */
3948 if (button == MB_MENU_INITIALIZE)
3950 int num_entries = numTreeInfoInGroup(ti);
3951 int entry_pos = posTreeInfo(ti);
3953 if (ti->cl_first == -1)
3955 /* only on initialization */
3956 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3957 ti->cl_cursor = entry_pos - ti->cl_first;
3959 else if (ti->cl_cursor >= num_page_entries ||
3960 (num_entries > num_page_entries &&
3961 num_entries - ti->cl_first < num_page_entries))
3963 /* only after change of list size (by custom graphic configuration) */
3964 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3965 ti->cl_cursor = entry_pos - ti->cl_first;
3968 if (position_set_by_scrollbar)
3971 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3974 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3975 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3976 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3980 else if (button == MB_MENU_LEAVE)
3984 PlaySound(SND_MENU_ITEM_SELECTING);
3986 if (ti->node_parent)
3988 *ti_ptr = ti->node_parent;
3989 DrawChooseTree(ti_ptr);
3991 else if (game_status == GAME_MODE_SETUP)
3993 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3995 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3996 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3997 execSetupGraphics();
4003 game_status = GAME_MODE_MAIN;
4005 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4014 if (mx || my) /* mouse input */
4016 int last_game_status = game_status; /* save current game status */
4019 /* force LEVELS draw offset on artwork setup screen */
4020 game_status = GAME_MODE_LEVELS;
4023 x = (mx - mSX) / 32;
4024 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4026 game_status = last_game_status; /* restore current game status */
4028 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4030 /* move cursor instead of scrolling when already at start/end of list */
4031 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4033 else if (dy == +1 * SCROLL_LINE &&
4034 ti->cl_first + num_page_entries == num_entries)
4037 /* handle scrolling screen one line or page */
4038 if (ti->cl_cursor + dy < 0 ||
4039 ti->cl_cursor + dy > num_page_entries - 1)
4041 if (ABS(dy) == SCROLL_PAGE)
4042 step = num_page_entries - 1;
4044 if (dy < 0 && ti->cl_first > 0)
4046 /* scroll page/line up */
4048 ti->cl_first -= step;
4049 if (ti->cl_first < 0)
4052 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4053 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4054 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4056 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4059 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4061 /* scroll page/line down */
4063 ti->cl_first += step;
4064 if (ti->cl_first + num_page_entries > num_entries)
4065 ti->cl_first = MAX(0, num_entries - num_page_entries);
4067 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4068 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4069 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4071 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4078 /* handle moving cursor one line */
4079 y = ti->cl_cursor + dy;
4084 TreeInfo *node_first, *node_cursor;
4085 int entry_pos = ti->cl_first + y;
4087 node_first = getTreeInfoFirstGroupEntry(ti);
4088 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4090 if (node_cursor->node_group)
4094 PlaySound(SND_MENU_ITEM_SELECTING);
4096 node_cursor->cl_first = ti->cl_first;
4097 node_cursor->cl_cursor = ti->cl_cursor;
4098 *ti_ptr = node_cursor->node_group;
4099 DrawChooseTree(ti_ptr);
4104 else if (dx == -1 && ti->node_parent)
4108 PlaySound(SND_MENU_ITEM_SELECTING);
4110 *ti_ptr = ti->node_parent;
4111 DrawChooseTree(ti_ptr);
4116 if (!anyScrollbarGadgetActive() &&
4117 IN_VIS_FIELD(x, y) &&
4118 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4119 y >= 0 && y < num_page_entries)
4123 if (y != ti->cl_cursor)
4125 PlaySound(SND_MENU_ITEM_ACTIVATING);
4127 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4128 drawChooseTreeCursor(y, TRUE);
4129 drawChooseTreeInfo(ti->cl_first + y, ti);
4136 TreeInfo *node_first, *node_cursor;
4137 int entry_pos = ti->cl_first + y;
4139 PlaySound(SND_MENU_ITEM_SELECTING);
4141 node_first = getTreeInfoFirstGroupEntry(ti);
4142 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4144 if (node_cursor->node_group)
4148 node_cursor->cl_first = ti->cl_first;
4149 node_cursor->cl_cursor = ti->cl_cursor;
4150 *ti_ptr = node_cursor->node_group;
4151 DrawChooseTree(ti_ptr);
4153 else if (node_cursor->parent_link)
4157 *ti_ptr = node_cursor->node_parent;
4158 DrawChooseTree(ti_ptr);
4162 FadeSetEnterScreen();
4164 node_cursor->cl_first = ti->cl_first;
4165 node_cursor->cl_cursor = ti->cl_cursor;
4166 *ti_ptr = node_cursor;
4168 if (ti->type == TREE_TYPE_LEVEL_DIR)
4170 LoadLevelSetup_SeriesInfo();
4172 SaveLevelSetup_LastSeries();
4173 SaveLevelSetup_SeriesInfo();
4177 if (game_status == GAME_MODE_SETUP)
4179 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4181 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4182 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4183 execSetupGraphics();
4189 game_status = GAME_MODE_MAIN;
4197 void DrawChooseLevel()
4199 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4201 DrawChooseTree(&leveldir_current);
4207 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4209 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4214 void DrawHallOfFame(int highlight_position)
4217 FadeSoundsAndMusic();
4219 /* (this is needed when called from GameEnd() after winning a game) */
4220 KeyboardAutoRepeatOn();
4223 /* (this is needed when called from GameEnd() after winning a game) */
4224 SetDrawDeactivationMask(REDRAW_NONE);
4225 SetDrawBackgroundMask(REDRAW_FIELD);
4227 CloseDoor(DOOR_CLOSE_2);
4229 if (highlight_position < 0)
4230 LoadScore(level_nr);
4232 FadeSetEnterScreen();
4234 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4237 FadeOut(REDRAW_FIELD);
4245 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4248 FadeIn(REDRAW_FIELD);
4252 static void drawHallOfFameList(int first_entry, int highlight_position)
4256 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4259 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4260 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4261 "HighScores of Level %d", level_nr);
4263 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4265 int entry = first_entry + i;
4266 boolean active = (entry == highlight_position);
4267 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4268 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4269 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4270 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4271 int dx1 = 3 * getFontWidth(font_nr1);
4272 int dx2 = dx1 + getFontWidth(font_nr1);
4273 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4274 int sy = mSY + 64 + i * 32;
4276 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4277 DrawText(mSX + dx1, sy, ".", font_nr1);
4278 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4280 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4281 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4283 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4286 redraw_mask |= REDRAW_FIELD;
4289 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4291 static int first_entry = 0;
4292 static int highlight_position = 0;
4293 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4295 if (button == MB_MENU_INITIALIZE)
4298 highlight_position = mx;
4299 drawHallOfFameList(first_entry, highlight_position);
4304 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4305 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4309 if (first_entry > 0)
4311 first_entry -= step;
4312 if (first_entry < 0)
4315 drawHallOfFameList(first_entry, highlight_position);
4320 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4322 first_entry += step;
4323 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4324 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4326 drawHallOfFameList(first_entry, highlight_position);
4329 else if (button == MB_MENU_LEAVE)
4331 PlaySound(SND_MENU_ITEM_SELECTING);
4333 FadeSound(SND_BACKGROUND_SCORES);
4335 game_status = GAME_MODE_MAIN;
4339 else if (button == MB_MENU_CHOICE)
4341 PlaySound(SND_MENU_ITEM_SELECTING);
4343 FadeSound(SND_BACKGROUND_SCORES);
4346 FadeOut(REDRAW_FIELD);
4349 game_status = GAME_MODE_MAIN;
4351 DrawAndFadeInMainMenu(REDRAW_FIELD);
4354 if (game_status == GAME_MODE_SCORES)
4355 PlayMenuSoundIfLoop();
4361 /* ========================================================================= */
4362 /* setup screen functions */
4363 /* ========================================================================= */
4365 static struct TokenInfo *setup_info;
4366 static int num_setup_info;
4368 static char *screen_mode_text;
4369 static char *scroll_delay_text;
4370 static char *game_speed_text;
4371 static char *graphics_set_name;
4372 static char *sounds_set_name;
4373 static char *music_set_name;
4375 static void execSetupMain()
4381 setup_mode = SETUP_MODE_MAIN;
4385 static void execSetupGame()
4391 if (game_speeds == NULL)
4395 for (i = 0; game_speeds_list[i].value != -1; i++)
4397 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4398 char identifier[32], name[32];
4399 int value = game_speeds_list[i].value;
4400 char *text = game_speeds_list[i].text;
4402 ti->node_top = &game_speeds;
4403 ti->sort_priority = 10000 - value;
4405 sprintf(identifier, "%d", value);
4406 sprintf(name, "%s", text);
4408 setString(&ti->identifier, identifier);
4409 setString(&ti->name, name);
4410 setString(&ti->name_sorting, name);
4411 setString(&ti->infotext, "Game Speed");
4413 pushTreeInfo(&game_speeds, ti);
4416 /* sort game speed values to start with slowest game speed */
4417 sortTreeInfo(&game_speeds);
4419 /* set current game speed to configured game speed value */
4420 game_speed_current =
4421 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4423 /* if that fails, set current game speed to reliable default value */
4424 if (game_speed_current == NULL)
4425 game_speed_current =
4426 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4428 /* if that also fails, set current game speed to first available speed */
4429 if (game_speed_current == NULL)
4430 game_speed_current = game_speeds;
4433 setup.game_frame_delay = atoi(game_speed_current->identifier);
4435 /* needed for displaying game speed text instead of identifier */
4436 game_speed_text = game_speed_current->name;
4438 setup_mode = SETUP_MODE_GAME;
4442 static void execSetupChooseGameSpeed()
4448 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4452 static void execSetupEditor()
4458 setup_mode = SETUP_MODE_EDITOR;
4462 static void execSetupGraphics()
4468 if (video.fullscreen_available && screen_modes == NULL)
4472 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4474 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4475 char identifier[32], name[32];
4476 int x = video.fullscreen_modes[i].width;
4477 int y = video.fullscreen_modes[i].height;
4480 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4482 ti->node_top = &screen_modes;
4483 ti->sort_priority = x * 10000 + y;
4485 sprintf(identifier, "%dx%d", x, y);
4486 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4488 setString(&ti->identifier, identifier);
4489 setString(&ti->name, name);
4490 setString(&ti->name_sorting, name);
4491 setString(&ti->infotext, "Fullscreen Mode");
4493 pushTreeInfo(&screen_modes, ti);
4496 /* sort fullscreen modes to start with lowest available screen resolution */
4497 sortTreeInfo(&screen_modes);
4499 /* set current screen mode for fullscreen mode to configured setup value */
4500 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4501 setup.fullscreen_mode);
4503 /* if that fails, set current screen mode to reliable default value */
4504 if (screen_mode_current == NULL)
4505 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4506 DEFAULT_FULLSCREEN_MODE);
4508 /* if that also fails, set current screen mode to first available mode */
4509 if (screen_mode_current == NULL)
4510 screen_mode_current = screen_modes;
4512 if (screen_mode_current == NULL)
4513 video.fullscreen_available = FALSE;
4516 if (video.fullscreen_available)
4518 setup.fullscreen_mode = screen_mode_current->identifier;
4520 /* needed for displaying screen mode name instead of identifier */
4521 screen_mode_text = screen_mode_current->name;
4525 if (scroll_delays == NULL)
4529 for (i = 0; scroll_delays_list[i].value != -1; i++)
4531 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4532 char identifier[32], name[32];
4533 int value = scroll_delays_list[i].value;
4534 char *text = scroll_delays_list[i].text;
4536 ti->node_top = &scroll_delays;
4537 ti->sort_priority = value;
4539 sprintf(identifier, "%d", value);
4540 sprintf(name, "%s", text);
4542 setString(&ti->identifier, identifier);
4543 setString(&ti->name, name);
4544 setString(&ti->name_sorting, name);
4545 setString(&ti->infotext, "Scroll Delay");
4547 pushTreeInfo(&scroll_delays, ti);
4550 /* sort scroll delay values to start with lowest scroll delay value */
4551 sortTreeInfo(&scroll_delays);
4553 /* set current scroll delay value to configured scroll delay value */
4554 scroll_delay_current =
4555 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4557 /* if that fails, set current scroll delay to reliable default value */
4558 if (scroll_delay_current == NULL)
4559 scroll_delay_current =
4560 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4562 /* if that also fails, set current scroll delay to first available value */
4563 if (scroll_delay_current == NULL)
4564 scroll_delay_current = scroll_delays;
4567 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4569 /* needed for displaying scroll delay text instead of identifier */
4570 scroll_delay_text = scroll_delay_current->name;
4573 setup_mode = SETUP_MODE_GRAPHICS;
4577 static void execSetupChooseScreenMode()
4583 if (!video.fullscreen_available)
4586 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4590 static void execSetupChooseScrollDelay()
4596 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4600 static void execSetupSound()
4606 setup_mode = SETUP_MODE_SOUND;
4610 static void execSetupArtwork()
4616 setup.graphics_set = artwork.gfx_current->identifier;
4617 setup.sounds_set = artwork.snd_current->identifier;
4618 setup.music_set = artwork.mus_current->identifier;
4620 /* needed if last screen (setup choice) changed graphics, sounds or music */
4621 ReloadCustomArtwork(0);
4623 /* needed for displaying artwork name instead of artwork identifier */
4624 graphics_set_name = artwork.gfx_current->name;
4625 sounds_set_name = artwork.snd_current->name;
4626 music_set_name = artwork.mus_current->name;
4628 setup_mode = SETUP_MODE_ARTWORK;
4632 static void execSetupChooseGraphics()
4638 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4642 static void execSetupChooseSounds()
4648 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4652 static void execSetupChooseMusic()
4658 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4662 static void execSetupInput()
4668 setup_mode = SETUP_MODE_INPUT;
4672 static void execSetupShortcuts1()
4678 setup_mode = SETUP_MODE_SHORTCUTS_1;
4682 static void execSetupShortcuts2()
4688 setup_mode = SETUP_MODE_SHORTCUTS_2;
4692 static void execExitSetup()
4698 game_status = GAME_MODE_MAIN;
4700 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4706 static void execSaveAndExitSetup()
4712 static struct TokenInfo setup_info_main[] =
4714 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4715 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4716 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4717 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4718 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4719 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4720 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4721 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4722 { TYPE_EMPTY, NULL, "" },
4723 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4724 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4729 static struct TokenInfo setup_info_game[] =
4731 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4732 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4733 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4734 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4735 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4736 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4737 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4738 { TYPE_STRING, &game_speed_text, "" },
4739 { TYPE_EMPTY, NULL, "" },
4740 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4745 static struct TokenInfo setup_info_editor[] =
4748 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4749 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4750 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4751 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4752 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4753 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4754 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4755 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4757 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4758 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4759 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4761 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4763 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4764 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4765 { TYPE_EMPTY, NULL, "" },
4767 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4768 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4769 { TYPE_EMPTY, NULL, "" },
4771 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4772 { TYPE_EMPTY, NULL, "" },
4773 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4778 static struct TokenInfo setup_info_graphics[] =
4780 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4781 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4782 { TYPE_STRING, &screen_mode_text, "" },
4784 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4786 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4787 { TYPE_STRING, &scroll_delay_text, "" },
4789 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4790 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4792 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4793 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4794 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4795 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4796 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4797 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4798 { TYPE_EMPTY, NULL, "" },
4799 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4804 static struct TokenInfo setup_info_sound[] =
4806 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4807 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4808 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4809 { TYPE_EMPTY, NULL, "" },
4810 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4815 static struct TokenInfo setup_info_artwork[] =
4817 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4818 { TYPE_STRING, &graphics_set_name, "" },
4819 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4820 { TYPE_STRING, &sounds_set_name, "" },
4821 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4822 { TYPE_STRING, &music_set_name, "" },
4823 { TYPE_EMPTY, NULL, "" },
4825 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4826 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4827 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4829 { TYPE_STRING, NULL, "Override Level Artwork:"},
4830 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4831 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4832 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4834 { TYPE_EMPTY, NULL, "" },
4835 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4840 static struct TokenInfo setup_info_input[] =
4842 { TYPE_SWITCH, NULL, "Player:" },
4843 { TYPE_SWITCH, NULL, "Device:" },
4844 { TYPE_ENTER_MENU, NULL, "" },
4845 { TYPE_EMPTY, NULL, "" },
4846 { TYPE_EMPTY, NULL, "" },
4847 { TYPE_EMPTY, NULL, "" },
4848 { TYPE_EMPTY, NULL, "" },
4849 { TYPE_EMPTY, NULL, "" },
4850 { TYPE_EMPTY, NULL, "" },
4851 { TYPE_EMPTY, NULL, "" },
4852 { TYPE_EMPTY, NULL, "" },
4853 { TYPE_EMPTY, NULL, "" },
4854 { TYPE_EMPTY, NULL, "" },
4855 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4860 static struct TokenInfo setup_info_shortcuts_1[] =
4862 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4863 { TYPE_KEY, &setup.shortcut.save_game, "" },
4864 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4865 { TYPE_KEY, &setup.shortcut.load_game, "" },
4866 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4867 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4868 { TYPE_EMPTY, NULL, "" },
4869 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4870 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4871 { TYPE_EMPTY, NULL, "" },
4872 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4877 static struct TokenInfo setup_info_shortcuts_2[] =
4879 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4880 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4881 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4882 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4883 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4884 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4885 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4886 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4887 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4888 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4889 { TYPE_EMPTY, NULL, "" },
4890 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4895 static Key getSetupKey()
4897 Key key = KSYM_UNDEFINED;
4898 boolean got_key_event = FALSE;
4900 while (!got_key_event)
4902 if (PendingEvent()) /* got event */
4910 case EVENT_KEYPRESS:
4912 key = GetEventKey((KeyEvent *)&event, TRUE);
4914 /* press 'Escape' or 'Enter' to keep the existing key binding */
4915 if (key == KSYM_Escape || key == KSYM_Return)
4916 key = KSYM_UNDEFINED; /* keep old value */
4918 got_key_event = TRUE;
4922 case EVENT_KEYRELEASE:
4923 key_joystick_mapping = 0;
4927 HandleOtherEvents(&event);
4935 /* don't eat all CPU time */
4942 static int getSetupTextFont(int type)
4944 if (type & (TYPE_SWITCH |
4955 static int getSetupValueFont(int type, void *value)
4957 if (type & TYPE_KEY)
4958 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4959 else if (type & TYPE_STRING)
4960 return FONT_VALUE_2;
4961 else if (type & TYPE_ECS_AGA)
4962 return FONT_VALUE_1;
4963 else if (type & TYPE_BOOLEAN_STYLE)
4964 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4966 return FONT_VALUE_1;
4969 static void drawSetupValue(int pos)
4971 boolean font_draw_xoffset_modified = FALSE;
4972 int font_draw_xoffset_old = -1;
4973 int xpos = MENU_SCREEN_VALUE_XPOS;
4974 int ypos = MENU_SCREEN_START_YPOS + pos;
4975 int startx = mSX + xpos * 32;
4976 int starty = mSY + ypos * 32;
4977 int font_nr, font_width;
4978 int type = setup_info[pos].type;
4979 void *value = setup_info[pos].value;
4980 char *value_string = getSetupValue(type, value);
4983 if (value_string == NULL)
4986 if (type & TYPE_KEY)
4988 xpos = MENU_SCREEN_START_XPOS;
4990 if (type & TYPE_QUERY)
4992 value_string = "<press key>";
4995 else if (type & TYPE_STRING)
4997 int max_value_len = (SCR_FIELDX - 2) * 2;
4999 xpos = MENU_SCREEN_START_XPOS;
5001 if (strlen(value_string) > max_value_len)
5002 value_string[max_value_len] = '\0';
5005 startx = mSX + xpos * 32;
5006 starty = mSY + ypos * 32;
5007 font_nr = getSetupValueFont(type, value);
5008 font_width = getFontWidth(font_nr);
5010 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5011 if (setup_mode != SETUP_MODE_INPUT)
5013 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5014 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5015 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5016 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5017 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5018 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5019 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5020 boolean correct_font_draw_xoffset = FALSE;
5022 if (xpos == MENU_SCREEN_START_XPOS &&
5023 startx + font1_xoffset < text_startx + text_font_xoffset)
5024 correct_font_draw_xoffset = TRUE;
5026 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5027 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5028 correct_font_draw_xoffset = TRUE;
5030 /* check if setup value would overlap with setup text when printed */
5031 /* (this can happen for extreme/wrong values for font draw offset) */
5032 if (correct_font_draw_xoffset)
5034 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5035 font_draw_xoffset_modified = TRUE;
5037 if (type & TYPE_KEY)
5038 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5039 else if (!(type & TYPE_STRING))
5040 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5041 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5045 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5046 DrawText(startx + i * font_width, starty, " ", font_nr);
5048 DrawText(startx, starty, value_string, font_nr);
5050 if (font_draw_xoffset_modified)
5051 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5054 static void changeSetupValue(int pos)
5056 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5058 *(boolean *)setup_info[pos].value ^= TRUE;
5060 else if (setup_info[pos].type & TYPE_KEY)
5064 setup_info[pos].type |= TYPE_QUERY;
5065 drawSetupValue(pos);
5066 setup_info[pos].type &= ~TYPE_QUERY;
5068 key = getSetupKey();
5069 if (key != KSYM_UNDEFINED)
5070 *(Key *)setup_info[pos].value = key;
5073 drawSetupValue(pos);
5076 static void DrawCursorAndText_Setup(int pos, boolean active)
5078 int xpos = MENU_SCREEN_START_XPOS;
5079 int ypos = MENU_SCREEN_START_YPOS + pos;
5080 int font_nr = getSetupTextFont(setup_info[pos].type);
5082 if (setup_info == setup_info_input)
5083 font_nr = FONT_MENU_1;
5086 font_nr = FONT_ACTIVE(font_nr);
5088 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5090 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5091 drawCursor(pos, active);
5094 static void DrawSetupScreen_Generic()
5096 char *title_string = NULL;
5100 CloseDoor(DOOR_CLOSE_2);
5103 FadeOut(REDRAW_FIELD);
5108 if (setup_mode == SETUP_MODE_MAIN)
5110 setup_info = setup_info_main;
5111 title_string = "Setup";
5113 else if (setup_mode == SETUP_MODE_GAME)
5115 setup_info = setup_info_game;
5116 title_string = "Setup Game";
5118 else if (setup_mode == SETUP_MODE_EDITOR)
5120 setup_info = setup_info_editor;
5121 title_string = "Setup Editor";
5123 else if (setup_mode == SETUP_MODE_GRAPHICS)
5125 setup_info = setup_info_graphics;
5126 title_string = "Setup Graphics";
5128 else if (setup_mode == SETUP_MODE_SOUND)
5130 setup_info = setup_info_sound;
5131 title_string = "Setup Sound";
5133 else if (setup_mode == SETUP_MODE_ARTWORK)
5135 setup_info = setup_info_artwork;
5136 title_string = "Custom Artwork";
5138 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5140 setup_info = setup_info_shortcuts_1;
5141 title_string = "Setup Shortcuts";
5143 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5145 setup_info = setup_info_shortcuts_2;
5146 title_string = "Setup Shortcuts";
5149 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5152 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5154 void *value_ptr = setup_info[i].value;
5157 int xpos = MENU_SCREEN_START_XPOS;
5158 int ypos = MENU_SCREEN_START_YPOS + i;
5162 /* set some entries to "unchangeable" according to other variables */
5163 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5164 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5165 (value_ptr == &setup.sound_music && !audio.music_available) ||
5166 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5167 (value_ptr == &screen_mode_text && !video.fullscreen_available))
5168 setup_info[i].type |= TYPE_GHOSTED;
5170 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5171 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5172 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5173 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5174 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5175 initCursor(i, IMG_MENU_BUTTON);
5178 DrawCursorAndText_Setup(i, FALSE);
5180 font_nr = getSetupTextFont(setup_info[i].type);
5182 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5185 if (setup_info[i].type & TYPE_VALUE)
5192 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5193 "Joysticks deactivated in setup menu");
5197 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5201 FadeIn(REDRAW_FIELD);
5206 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5210 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5212 static int choice_store[MAX_SETUP_MODES];
5213 int choice = choice_store[setup_mode]; /* always starts with 0 */
5217 if (button == MB_MENU_INITIALIZE)
5219 /* advance to first valid menu entry */
5220 while (choice < num_setup_info &&
5221 setup_info[choice].type & TYPE_SKIP_ENTRY)
5223 choice_store[setup_mode] = choice;
5226 DrawCursorAndText_Setup(choice, TRUE);
5228 drawCursor(choice, TRUE);
5233 else if (button == MB_MENU_LEAVE)
5235 PlaySound(SND_MENU_ITEM_SELECTING);
5237 for (y = 0; y < num_setup_info; y++)
5239 if (setup_info[y].type & TYPE_LEAVE_MENU)
5241 void (*menu_callback_function)(void) = setup_info[y].value;
5245 menu_callback_function();
5247 break; /* absolutely needed because function changes 'setup_info'! */
5254 if (mx || my) /* mouse input */
5256 x = (mx - mSX) / 32;
5257 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5259 else if (dx || dy) /* keyboard input */
5263 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5265 if (setup_info[choice].type & menu_navigation_type ||
5266 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5267 button = MB_MENU_CHOICE;
5272 /* jump to next non-empty menu entry (up or down) */
5273 while (y > 0 && y < num_setup_info - 1 &&
5274 setup_info[y].type & TYPE_SKIP_ENTRY)
5278 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5282 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5284 PlaySound(SND_MENU_ITEM_ACTIVATING);
5287 DrawCursorAndText_Setup(choice, FALSE);
5288 DrawCursorAndText_Setup(y, TRUE);
5290 drawCursor(choice, FALSE);
5291 drawCursor(y, TRUE);
5294 choice = choice_store[setup_mode] = y;
5297 else if (!(setup_info[y].type & TYPE_GHOSTED))
5299 PlaySound(SND_MENU_ITEM_SELECTING);
5301 /* when selecting key headline, execute function for key value change */
5302 if (setup_info[y].type & TYPE_KEYTEXT &&
5303 setup_info[y + 1].type & TYPE_KEY)
5306 /* when selecting string value, execute function for list selection */
5307 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5308 setup_info[y - 1].type & TYPE_ENTER_LIST)
5311 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5313 void (*menu_callback_function)(void) = setup_info[y].value;
5315 FadeSetFromType(setup_info[y].type);
5317 menu_callback_function();
5321 if (setup_info[y].type & TYPE_VALUE)
5322 changeSetupValue(y);
5328 void DrawSetupScreen_Input()
5335 FadeOut(REDRAW_FIELD);
5341 setup_info = setup_info_input;
5344 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5347 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5349 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5350 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5351 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5352 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5353 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5354 initCursor(i, IMG_MENU_BUTTON);
5356 DrawCursorAndText_Setup(i, FALSE);
5359 initCursor(0, IMG_MENU_BUTTON);
5360 initCursor(1, IMG_MENU_BUTTON);
5361 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
5362 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5364 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
5365 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
5366 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
5370 DeactivateJoystickForCalibration();
5373 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5374 "Joysticks deactivated on this screen");
5377 /* create gadgets for setup input menu screen */
5378 FreeScreenGadgets();
5379 CreateScreenGadgets();
5381 /* map gadgets for setup input menu screen */
5382 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5384 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5387 FadeIn(REDRAW_FIELD);
5393 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5395 if (device_name == NULL)
5398 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5401 if (strlen(device_name) > 1)
5403 char c1 = device_name[strlen(device_name) - 1];
5404 char c2 = device_name[strlen(device_name) - 2];
5406 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5407 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5410 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5411 strlen(device_name));
5414 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5417 static struct SetupKeyboardInfo custom_key;
5424 { &custom_key.left, "Joystick Left" },
5425 { &custom_key.right, "Joystick Right" },
5426 { &custom_key.up, "Joystick Up" },
5427 { &custom_key.down, "Joystick Down" },
5428 { &custom_key.snap, "Button 1" },
5429 { &custom_key.drop, "Button 2" }
5431 static char *joystick_name[MAX_PLAYERS] =
5438 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5442 custom_key = setup.input[player_nr].key;
5444 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5445 FONT_INPUT_1_ACTIVE);
5447 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5449 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5450 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5452 if (setup.input[player_nr].use_joystick)
5454 char *device_name = setup.input[player_nr].joy.device_name;
5455 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5456 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5458 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5459 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5463 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5464 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5467 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5469 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5470 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5471 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5472 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5474 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5475 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5476 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5477 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5478 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5479 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5481 for (i = 0; i < 6; i++)
5483 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5485 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5487 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5488 (setup.input[player_nr].use_joystick ?
5490 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5494 static int input_player_nr = 0;
5496 void HandleSetupScreen_Input_Player(int step, int direction)
5498 int old_player_nr = input_player_nr;
5501 new_player_nr = old_player_nr + step * direction;
5502 if (new_player_nr < 0)
5504 if (new_player_nr > MAX_PLAYERS - 1)
5505 new_player_nr = MAX_PLAYERS - 1;
5507 if (new_player_nr != old_player_nr)
5509 input_player_nr = new_player_nr;
5511 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5515 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5517 static int choice = 0;
5520 int pos_start = SETUPINPUT_SCREEN_POS_START;
5521 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5522 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5523 int pos_end = SETUPINPUT_SCREEN_POS_END;
5525 if (button == MB_MENU_INITIALIZE)
5527 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5530 DrawCursorAndText_Setup(choice, TRUE);
5532 drawCursor(choice, TRUE);
5537 else if (button == MB_MENU_LEAVE)
5539 setup_mode = SETUP_MODE_MAIN;
5546 if (mx || my) /* mouse input */
5548 x = (mx - mSX) / 32;
5549 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5551 else if (dx || dy) /* keyboard input */
5553 if (dx && choice == 0)
5554 x = (dx < 0 ? 10 : 12);
5555 else if ((dx && choice == 1) ||
5556 (dx == +1 && choice == 2) ||
5557 (dx == -1 && choice == pos_end))
5558 button = MB_MENU_CHOICE;
5562 if (y >= pos_empty1 && y <= pos_empty2)
5563 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5566 if (y == 0 && dx != 0 && button)
5568 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5570 else if (IN_VIS_FIELD(x, y) &&
5571 y >= pos_start && y <= pos_end &&
5572 !(y >= pos_empty1 && y <= pos_empty2))
5579 DrawCursorAndText_Setup(choice, FALSE);
5580 DrawCursorAndText_Setup(y, TRUE);
5582 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5584 drawCursor(choice, FALSE);
5585 drawCursor(y, TRUE);
5595 char *device_name = setup.input[input_player_nr].joy.device_name;
5597 if (!setup.input[input_player_nr].use_joystick)
5599 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5601 setJoystickDeviceToNr(device_name, new_device_nr);
5602 setup.input[input_player_nr].use_joystick = TRUE;
5606 int device_nr = getJoystickNrFromDeviceName(device_name);
5607 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5609 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5610 setup.input[input_player_nr].use_joystick = FALSE;
5612 setJoystickDeviceToNr(device_name, new_device_nr);
5615 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5619 if (setup.input[input_player_nr].use_joystick)
5622 CalibrateJoystick(input_player_nr);
5625 CustomizeKeyboard(input_player_nr);
5627 else if (y == pos_end)
5633 setup_mode = SETUP_MODE_MAIN;
5640 void CustomizeKeyboard(int player_nr)
5644 boolean finished = FALSE;
5645 static struct SetupKeyboardInfo custom_key;
5650 } customize_step[] =
5652 { &custom_key.left, "Move Left" },
5653 { &custom_key.right, "Move Right" },
5654 { &custom_key.up, "Move Up" },
5655 { &custom_key.down, "Move Down" },
5656 { &custom_key.snap, "Snap Field" },
5657 { &custom_key.drop, "Drop Element" }
5660 /* read existing key bindings from player setup */
5661 custom_key = setup.input[player_nr].key;
5664 FadeOut(REDRAW_FIELD);
5668 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5676 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5677 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5678 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5679 "Key:", FONT_INPUT_1_ACTIVE);
5680 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5681 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5684 FadeIn(REDRAW_FIELD);
5691 if (PendingEvent()) /* got event */
5699 case EVENT_KEYPRESS:
5701 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5703 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5705 if (key == KSYM_Escape)
5706 FadeSkipNextFadeIn();
5712 /* all keys configured -- wait for "Escape" or "Return" key */
5716 /* press 'Enter' to keep the existing key binding */
5717 if (key == KSYM_Return)
5718 key = *customize_step[step_nr].key;
5720 /* check if key already used */
5721 for (i = 0; i < step_nr; i++)
5722 if (*customize_step[i].key == key)
5727 /* got new key binding */
5728 *customize_step[step_nr].key = key;
5729 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5731 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5732 getKeyNameFromKey(key), FONT_VALUE_1);
5735 /* un-highlight last query */
5736 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5737 customize_step[step_nr - 1].text, FONT_MENU_1);
5738 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5739 "Key:", FONT_MENU_1);
5741 /* press 'Enter' to leave */
5744 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5745 "Press Enter", FONT_TITLE_1);
5749 /* query next key binding */
5750 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5751 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5752 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5753 "Key:", FONT_INPUT_1_ACTIVE);
5754 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5755 getKeyNameFromKey(*customize_step[step_nr].key),
5760 case EVENT_KEYRELEASE:
5761 key_joystick_mapping = 0;
5765 HandleOtherEvents(&event);
5773 /* don't eat all CPU time */
5777 /* write new key bindings back to player setup */
5778 setup.input[player_nr].key = custom_key;
5781 DrawSetupScreen_Input();
5784 static boolean CalibrateJoystickMain(int player_nr)
5786 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5787 int new_joystick_xright = JOYSTICK_XMIDDLE;
5788 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5789 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5790 int new_joystick_xmiddle, new_joystick_ymiddle;
5792 int joystick_fd = joystick.fd[player_nr];
5793 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5794 boolean check[3][3];
5795 int check_remaining = 3 * 3;
5800 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5803 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5807 FadeOut(REDRAW_FIELD);
5811 for (y = 0; y < 3; y++)
5813 for (x = 0; x < 3; x++)
5815 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5816 check[x][y] = FALSE;
5820 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5821 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5822 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5823 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5824 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5825 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5826 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5828 joy_value = Joystick(player_nr);
5829 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5830 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5832 /* eventually uncalibrated center position (joystick could be uncentered) */
5833 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5836 new_joystick_xmiddle = joy_x;
5837 new_joystick_ymiddle = joy_y;
5839 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5842 FadeIn(REDRAW_FIELD);
5847 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5852 if (PendingEvent()) /* got event */
5860 case EVENT_KEYPRESS:
5861 switch (GetEventKey((KeyEvent *)&event, TRUE))
5864 if (check_remaining == 0)
5869 FadeSkipNextFadeIn();
5878 case EVENT_KEYRELEASE:
5879 key_joystick_mapping = 0;
5883 HandleOtherEvents(&event);
5888 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5891 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5892 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5893 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5894 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5896 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5897 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5898 setup.input[player_nr].joy.xright = new_joystick_xright;
5899 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5900 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5901 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5903 CheckJoystickData();
5905 joy_value = Joystick(player_nr);
5907 if (joy_value & JOY_BUTTON && check_remaining == 0)
5910 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5911 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5913 if (x != last_x || y != last_y)
5915 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5916 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5921 if (check_remaining > 0 && !check[x+1][y+1])
5923 check[x+1][y+1] = TRUE;
5929 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5930 setup.input[player_nr].joy.xleft,
5931 setup.input[player_nr].joy.xmiddle,
5932 setup.input[player_nr].joy.xright);
5933 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5934 setup.input[player_nr].joy.yupper,
5935 setup.input[player_nr].joy.ymiddle,
5936 setup.input[player_nr].joy.ylower);
5945 /* don't eat all CPU time */
5949 /* calibrated center position (joystick should now be centered) */
5950 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5953 new_joystick_xmiddle = joy_x;
5954 new_joystick_ymiddle = joy_y;
5959 DrawSetupScreen_Input();
5962 /* wait until the last pressed button was released */
5963 while (Joystick(player_nr) & JOY_BUTTON)
5965 if (PendingEvent()) /* got event */
5970 HandleOtherEvents(&event);
5979 void CalibrateJoystick(int player_nr)
5981 if (!CalibrateJoystickMain(player_nr))
5983 char *device_name = setup.input[player_nr].joy.device_name;
5984 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5985 int xpos = mSX - SX;
5986 int ypos = mSY - SY;
5990 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5991 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5994 Delay(2000); /* show error message for a short time */
6000 DrawSetupScreen_Input();
6004 void DrawSetupScreen()
6006 DeactivateJoystick();
6008 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6010 if (setup_mode == SETUP_MODE_INPUT)
6011 DrawSetupScreen_Input();
6012 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6013 DrawChooseTree(&game_speed_current);
6014 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6015 DrawChooseTree(&screen_mode_current);
6016 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6017 DrawChooseTree(&scroll_delay_current);
6018 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6019 DrawChooseTree(&artwork.gfx_current);
6020 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6021 DrawChooseTree(&artwork.snd_current);
6022 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6023 DrawChooseTree(&artwork.mus_current);
6025 DrawSetupScreen_Generic();
6031 void RedrawSetupScreenAfterFullscreenToggle()
6033 if (setup_mode == SETUP_MODE_GRAPHICS)
6037 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6039 if (setup_mode == SETUP_MODE_INPUT)
6040 HandleSetupScreen_Input(mx, my, dx, dy, button);
6041 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6042 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6043 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6044 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6045 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6046 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6047 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6048 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6049 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6050 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6051 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6052 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6054 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6059 void HandleGameActions()
6061 if (game_status != GAME_MODE_PLAYING)
6064 GameActions(); /* main game loop */
6066 if (tape.auto_play && !tape.playing)
6067 AutoPlayTape(); /* continue automatically playing next tape */
6071 /* ---------- new screen button stuff -------------------------------------- */
6073 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6078 case SCREEN_CTRL_ID_PREV_LEVEL:
6079 *x = mSX + menu.main.button.prev_level.x;
6080 *y = mSY + menu.main.button.prev_level.y;
6083 case SCREEN_CTRL_ID_NEXT_LEVEL:
6084 *x = mSX + menu.main.button.next_level.x;
6085 *y = mSY + menu.main.button.next_level.y;
6088 case SCREEN_CTRL_ID_PREV_LEVEL:
6089 *x = mSX + TILEX * getPrevlevelButtonPos();
6090 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6093 case SCREEN_CTRL_ID_NEXT_LEVEL:
6094 *x = mSX + TILEX * getNextLevelButtonPos();
6095 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6099 case SCREEN_CTRL_ID_PREV_PLAYER:
6100 *x = mSX + TILEX * 10;
6101 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6104 case SCREEN_CTRL_ID_NEXT_PLAYER:
6105 *x = mSX + TILEX * 12;
6106 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6110 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6116 int gfx_unpressed, gfx_pressed;
6117 void (*get_gadget_position)(int *, int *, int);
6121 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6124 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6125 getScreenMenuButtonPos,
6126 SCREEN_CTRL_ID_PREV_LEVEL,
6131 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6132 getScreenMenuButtonPos,
6133 SCREEN_CTRL_ID_NEXT_LEVEL,
6138 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6139 getScreenMenuButtonPos,
6140 SCREEN_CTRL_ID_PREV_PLAYER,
6145 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6146 getScreenMenuButtonPos,
6147 SCREEN_CTRL_ID_NEXT_PLAYER,
6155 int gfx_unpressed, gfx_pressed;
6159 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6162 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6163 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6164 SCREEN_CTRL_ID_SCROLL_UP,
6168 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6169 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6170 SCREEN_CTRL_ID_SCROLL_DOWN,
6177 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6178 Bitmap **gfx_unpressed, **gfx_pressed;
6180 int gfx_unpressed, gfx_pressed;
6187 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6190 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6191 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6193 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6195 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6196 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6197 GD_TYPE_SCROLLBAR_VERTICAL,
6198 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6199 "scroll level series vertically"
6203 static void CreateScreenMenubuttons()
6205 struct GadgetInfo *gi;
6206 unsigned long event_mask;
6209 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6211 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6212 int gfx_unpressed, gfx_pressed;
6213 int x, y, width, height;
6214 int gd_x1, gd_x2, gd_y1, gd_y2;
6215 int id = menubutton_info[i].gadget_id;
6217 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6219 menubutton_info[i].get_gadget_position(&x, &y, id);
6221 width = SC_MENUBUTTON_XSIZE;
6222 height = SC_MENUBUTTON_YSIZE;
6224 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6225 gfx_pressed = menubutton_info[i].gfx_pressed;
6226 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6227 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6228 gd_x1 = graphic_info[gfx_unpressed].src_x;
6229 gd_y1 = graphic_info[gfx_unpressed].src_y;
6230 gd_x2 = graphic_info[gfx_pressed].src_x;
6231 gd_y2 = graphic_info[gfx_pressed].src_y;
6233 gi = CreateGadget(GDI_CUSTOM_ID, id,
6234 GDI_CUSTOM_TYPE_ID, i,
6235 GDI_INFO_TEXT, menubutton_info[i].infotext,
6240 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6241 GDI_STATE, GD_BUTTON_UNPRESSED,
6242 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6243 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6244 GDI_DIRECT_DRAW, FALSE,
6245 GDI_EVENT_MASK, event_mask,
6246 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6250 Error(ERR_EXIT, "cannot create gadget");
6252 screen_gadget[id] = gi;
6256 static void CreateScreenScrollbuttons()
6258 struct GadgetInfo *gi;
6259 unsigned long event_mask;
6262 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6264 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6265 int gfx_unpressed, gfx_pressed;
6266 int x, y, width, height;
6267 int gd_x1, gd_x2, gd_y1, gd_y2;
6268 int id = scrollbutton_info[i].gadget_id;
6270 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6272 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6273 y = mSY + scrollbutton_info[i].y;
6274 width = SC_SCROLLBUTTON_XSIZE;
6275 height = SC_SCROLLBUTTON_YSIZE;
6277 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6278 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6279 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6281 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6282 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6283 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6284 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6285 gd_x1 = graphic_info[gfx_unpressed].src_x;
6286 gd_y1 = graphic_info[gfx_unpressed].src_y;
6287 gd_x2 = graphic_info[gfx_pressed].src_x;
6288 gd_y2 = graphic_info[gfx_pressed].src_y;
6290 gi = CreateGadget(GDI_CUSTOM_ID, id,
6291 GDI_CUSTOM_TYPE_ID, i,
6292 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6297 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6298 GDI_STATE, GD_BUTTON_UNPRESSED,
6299 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6300 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6301 GDI_DIRECT_DRAW, FALSE,
6302 GDI_EVENT_MASK, event_mask,
6303 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6307 Error(ERR_EXIT, "cannot create gadget");
6309 screen_gadget[id] = gi;
6313 static void CreateScreenScrollbars()
6317 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6319 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6320 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6321 int gfx_unpressed, gfx_pressed;
6323 int x, y, width, height;
6324 int gd_x1, gd_x2, gd_y1, gd_y2;
6325 struct GadgetInfo *gi;
6326 int items_max, items_visible, item_position;
6327 unsigned long event_mask;
6328 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6329 int id = scrollbar_info[i].gadget_id;
6331 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6333 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6334 y = mSY + scrollbar_info[i].y;
6335 width = scrollbar_info[i].width;
6336 height = scrollbar_info[i].height;
6338 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6339 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6341 items_max = num_page_entries;
6342 items_visible = num_page_entries;
6345 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6346 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6347 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6353 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6354 gfx_pressed = scrollbar_info[i].gfx_pressed;
6355 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6356 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6357 gd_x1 = graphic_info[gfx_unpressed].src_x;
6358 gd_y1 = graphic_info[gfx_unpressed].src_y;
6359 gd_x2 = graphic_info[gfx_pressed].src_x;
6360 gd_y2 = graphic_info[gfx_pressed].src_y;
6363 gi = CreateGadget(GDI_CUSTOM_ID, id,
6364 GDI_CUSTOM_TYPE_ID, i,
6365 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6370 GDI_TYPE, scrollbar_info[i].type,
6371 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6372 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6373 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6375 GDI_WHEEL_AREA_X, SX,
6376 GDI_WHEEL_AREA_Y, SY,
6377 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6378 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6380 GDI_WHEEL_AREA_X, 0,
6381 GDI_WHEEL_AREA_Y, 0,
6382 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6383 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6385 GDI_STATE, GD_BUTTON_UNPRESSED,
6386 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6387 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6388 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6389 GDI_DIRECT_DRAW, FALSE,
6390 GDI_EVENT_MASK, event_mask,
6391 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6395 Error(ERR_EXIT, "cannot create gadget");
6397 screen_gadget[id] = gi;
6401 void CreateScreenGadgets()
6403 int last_game_status = game_status; /* save current game status */
6405 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6408 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6410 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6412 /* copy pointers to clip mask and GC */
6413 scrollbar_bitmap[i]->clip_mask =
6414 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6415 scrollbar_bitmap[i]->stored_clip_gc =
6416 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6418 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6419 scrollbar_bitmap[i],
6420 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6421 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6422 TILEX, TILEY, 0, 0);
6426 CreateScreenMenubuttons();
6429 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6430 game_status = GAME_MODE_LEVELS;
6433 CreateScreenScrollbuttons();
6434 CreateScreenScrollbars();
6436 game_status = last_game_status; /* restore current game status */
6439 void FreeScreenGadgets()
6443 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6444 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6446 /* prevent freeing clip mask and GC twice */
6447 scrollbar_bitmap[i]->clip_mask = None;
6448 scrollbar_bitmap[i]->stored_clip_gc = None;
6450 FreeBitmap(scrollbar_bitmap[i]);
6454 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6455 FreeGadget(screen_gadget[i]);
6458 void MapScreenMenuGadgets(int screen_mask)
6462 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6463 if (screen_mask & menubutton_info[i].screen_mask)
6464 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6467 void MapScreenTreeGadgets(TreeInfo *ti)
6469 int num_entries = numTreeInfoInGroup(ti);
6472 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6475 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6476 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6478 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6479 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6482 static void HandleScreenGadgets(struct GadgetInfo *gi)
6484 int id = gi->custom_id;
6485 int button = gi->event.button;
6486 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6490 case SCREEN_CTRL_ID_PREV_LEVEL:
6491 HandleMainMenu_SelectLevel(step, -1);
6494 case SCREEN_CTRL_ID_NEXT_LEVEL:
6495 HandleMainMenu_SelectLevel(step, +1);
6498 case SCREEN_CTRL_ID_PREV_PLAYER:
6499 HandleSetupScreen_Input_Player(step, -1);
6502 case SCREEN_CTRL_ID_NEXT_PLAYER:
6503 HandleSetupScreen_Input_Player(step, +1);
6506 case SCREEN_CTRL_ID_SCROLL_UP:
6507 if (game_status == GAME_MODE_LEVELS)
6508 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6509 else if (game_status == GAME_MODE_SETUP)
6510 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6513 case SCREEN_CTRL_ID_SCROLL_DOWN:
6514 if (game_status == GAME_MODE_LEVELS)
6515 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6516 else if (game_status == GAME_MODE_SETUP)
6517 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6520 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6521 if (game_status == GAME_MODE_LEVELS)
6522 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6523 else if (game_status == GAME_MODE_SETUP)
6524 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);