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);
1532 DrawMaskedBorder(REDRAW_ALL);
1535 if (redraw_mask == REDRAW_ALL)
1537 int door_state = GetDoorState();
1539 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1545 game_status = GAME_MODE_PSEUDO_PREVIEW;
1547 DrawText(20, 400, "text_3.PREVIEW", FONT_TEXT_3);
1548 DrawText(20, 420, "text_4.PREVIEW", FONT_TEXT_4);
1550 game_status = GAME_MODE_MAIN;
1552 DrawText(20, 440, "text_3.MAIN", FONT_TEXT_3);
1553 DrawText(20, 460, "text_4.MAIN", FONT_TEXT_4);
1558 FadeIn(redraw_mask);
1563 else if (fading.anim_mode == ANIM_CROSSFADE)
1564 FadeCross(redraw_mask);
1566 FadeIn(redraw_mask);
1569 FadeIn(redraw_mask);
1578 fading = title_default;
1581 SetMouseCursor(CURSOR_DEFAULT);
1585 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1588 void DrawAndFadeInMainMenu(int redraw_mask)
1590 DrawMainMenuExt(redraw_mask, TRUE);
1595 DrawMainMenuExt(REDRAW_ALL, FALSE);
1599 static void gotoTopLevelDir()
1601 /* move upwards to top level directory */
1602 while (leveldir_current->node_parent)
1604 /* write a "path" into level tree for easy navigation to last level */
1605 if (leveldir_current->node_parent->node_group->cl_first == -1)
1607 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1608 int leveldir_pos = posTreeInfo(leveldir_current);
1609 int num_page_entries;
1610 int cl_first, cl_cursor;
1612 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1613 num_page_entries = num_leveldirs;
1615 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1617 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1618 cl_cursor = leveldir_pos - cl_first;
1620 leveldir_current->node_parent->node_group->cl_first = cl_first;
1621 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1624 leveldir_current = leveldir_current->node_parent;
1629 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1631 static unsigned long title_delay = 0;
1632 static int title_screen_nr = 0;
1633 static int last_sound = -1, last_music = -1;
1634 boolean return_to_main_menu = FALSE;
1635 boolean use_fading_main_menu = TRUE;
1638 boolean use_cross_fading = FALSE;
1640 boolean use_cross_fading = !show_title_initial; /* default */
1643 struct TitleControlInfo *tci;
1644 struct TitleFadingInfo fading_default;
1645 struct TitleFadingInfo fading_last = fading;
1646 struct TitleFadingInfo fading_next;
1649 if (button == MB_MENU_INITIALIZE)
1652 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1656 int last_game_status = game_status; /* save current game status */
1660 title_screen_nr = 0;
1661 tci = &title_controls[title_screen_nr];
1663 last_sound = SND_UNDEFINED;
1664 last_music = MUS_UNDEFINED;
1667 /* determine number of title screens to display (images and messages) */
1668 InitializeTitleControls();
1671 if (game_status == GAME_MODE_INFO)
1673 if (num_title_screens == 0)
1675 DrawInfoScreen_NotAvailable("Title screen information:",
1676 "No title screen for this level set.");
1679 /* use default settings for fading, but always disable auto delay */
1680 fading = title_default;
1681 fading.auto_delay = -1;
1687 FadeSoundsAndMusic();
1690 FadeOut(REDRAW_ALL);
1695 DrawTitleScreenImage(tci->local_nr, tci->initial);
1697 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1699 fading_default = (tci->initial ? title_initial_default : title_default);
1701 fading = fading_next = getTitleFading(tci);
1705 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1706 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1708 fading.fade_mode = FADE_MODE_FADE;
1709 fading.fade_delay = fading_default.fade_delay;
1712 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1713 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1714 fading.fade_mode = FADE_MODE_FADE;
1719 sound = getTitleSound(tci);
1720 music = getTitleMusic(tci);
1722 if (sound != last_sound)
1723 PlayMenuSoundExt(sound);
1724 if (music != last_music)
1725 PlayMenuMusicExt(music);
1731 SetMouseCursor(CURSOR_NONE);
1733 // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
1739 fading = fading_next;
1741 DelayReached(&title_delay, 0); /* reset delay counter */
1747 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1748 button = MB_MENU_CHOICE;
1750 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1751 button = MB_MENU_CHOICE;
1754 if (button == MB_MENU_LEAVE)
1756 return_to_main_menu = TRUE;
1757 use_fading_main_menu = FALSE;
1759 else if (button == MB_MENU_CHOICE)
1762 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1765 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1768 FadeOut(REDRAW_FIELD);
1771 FadeSetEnterScreen();
1773 info_mode = INFO_MODE_MAIN;
1774 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1780 tci = &title_controls[title_screen_nr];
1782 if (title_screen_nr < num_title_screens)
1786 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1793 graphic_info[getTitleScreenGraphic(tci->local_nr,
1794 tci->initial)].anim_mode;
1796 anim_mode = ANIM_FADE; /* ??? */
1798 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1799 anim_mode == ANIM_CROSSFADE ? TRUE :
1803 sound = getTitleSound(tci);
1804 music = getTitleMusic(tci);
1806 if (sound == SND_UNDEFINED || sound != last_sound)
1808 if (music == MUS_UNDEFINED || music != last_music)
1812 FadeOut(REDRAW_ALL);
1816 DrawTitleScreenImage(tci->local_nr, tci->initial);
1818 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1820 fading_next = getTitleFading(tci);
1823 sound = getTitleSound(tci);
1824 music = getTitleMusic(tci);
1826 if (sound != last_sound)
1827 PlayMenuSoundExt(sound);
1828 if (music != last_music)
1829 PlayMenuMusicExt(music);
1836 printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1840 /* last screen already faded out, next screen has no animation */
1841 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1842 fading_next.fade_mode == FADE_MODE_NONE)
1843 fading = fading_next;
1845 /* last screen already faded out, next screen has no animation */
1846 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1847 fading_next.fade_mode == FADE_MODE_NONE)
1848 fading = fading_next;
1855 fading = fading_next;
1857 DelayReached(&title_delay, 0); /* reset delay counter */
1861 FadeSoundsAndMusic();
1867 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1871 FadeOut(REDRAW_ALL);
1875 FadeOut(REDRAW_ALL);
1879 return_to_main_menu = TRUE;
1883 if (return_to_main_menu)
1889 SetMouseCursor(CURSOR_DEFAULT);
1891 if (game_status == GAME_MODE_INFO)
1894 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1897 info_mode = INFO_MODE_MAIN;
1898 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1900 else /* default: return to main menu */
1903 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1906 game_status = GAME_MODE_MAIN;
1907 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1912 void HandleMainMenu_SelectLevel(int step, int direction)
1914 int old_level_nr = level_nr;
1917 new_level_nr = old_level_nr + step * direction;
1918 if (new_level_nr < leveldir_current->first_level)
1919 new_level_nr = leveldir_current->first_level;
1920 if (new_level_nr > leveldir_current->last_level)
1921 new_level_nr = leveldir_current->last_level;
1923 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1925 /* skipping levels is only allowed when trying to skip single level */
1926 if (setup.skip_levels && step == 1 &&
1927 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1929 leveldir_current->handicap_level++;
1930 SaveLevelSetup_SeriesInfo();
1933 new_level_nr = leveldir_current->handicap_level;
1936 if (new_level_nr != old_level_nr)
1938 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1940 PlaySound(SND_MENU_ITEM_SELECTING);
1942 level_nr = new_level_nr;
1945 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1946 int2str(level_nr, menu.main.text.level_number.size),
1947 mci->pos_text->font);
1949 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1952 LoadLevel(level_nr);
1953 DrawPreviewLevel(TRUE);
1957 DrawCompleteVideoDisplay();
1959 /* needed because DrawPreviewLevel() takes some time */
1967 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1969 static int choice = MAIN_CONTROL_GAME;
1973 if (button == MB_MENU_INITIALIZE)
1975 DrawCursorAndText_Main(choice, TRUE);
1980 if (mx || my) /* mouse input */
1984 for (i = 0; main_controls[i].nr != -1; i++)
1986 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1987 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1988 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1990 pos = main_controls[i].nr;
1996 else if (dx || dy) /* keyboard input */
1998 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1999 choice == MAIN_CONTROL_SETUP))
2000 button = MB_MENU_CHOICE;
2005 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
2007 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2009 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2015 PlaySound(SND_MENU_ITEM_ACTIVATING);
2017 DrawCursorAndText_Main(choice, FALSE);
2018 DrawCursorAndText_Main(pos, TRUE);
2025 PlaySound(SND_MENU_ITEM_SELECTING);
2027 if (pos == MAIN_CONTROL_NAME)
2029 game_status = GAME_MODE_PSEUDO_TYPENAME;
2031 HandleTypeName(strlen(setup.player_name), 0);
2033 else if (pos == MAIN_CONTROL_LEVELS)
2037 game_status = GAME_MODE_LEVELS;
2039 SaveLevelSetup_LastSeries();
2040 SaveLevelSetup_SeriesInfo();
2049 else if (pos == MAIN_CONTROL_SCORES)
2051 game_status = GAME_MODE_SCORES;
2055 else if (pos == MAIN_CONTROL_EDITOR)
2057 if (leveldir_current->readonly &&
2058 !strEqual(setup.player_name, "Artsoft"))
2059 Request("This level is read only !", REQ_CONFIRM);
2061 game_status = GAME_MODE_EDITOR;
2063 FadeSetEnterScreen();
2067 else if (pos == MAIN_CONTROL_INFO)
2069 game_status = GAME_MODE_INFO;
2070 info_mode = INFO_MODE_MAIN;
2073 fading = menu.navigation;
2078 else if (pos == MAIN_CONTROL_GAME)
2080 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2082 else if (pos == MAIN_CONTROL_SETUP)
2084 game_status = GAME_MODE_SETUP;
2085 setup_mode = SETUP_MODE_MAIN;
2089 else if (pos == MAIN_CONTROL_QUIT)
2091 SaveLevelSetup_LastSeries();
2092 SaveLevelSetup_SeriesInfo();
2094 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2095 game_status = GAME_MODE_QUIT;
2100 if (game_status == GAME_MODE_MAIN)
2102 DrawPreviewLevel(FALSE);
2109 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2111 static int choice = 5;
2115 if (button == MB_MENU_INITIALIZE)
2117 drawCursor(choice, TRUE);
2122 if (mx || my) /* mouse input */
2124 x = (mx - mSX) / 32;
2125 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2127 else if (dx || dy) /* keyboard input */
2129 if (dx && choice == 1)
2130 x = (dx < 0 ? 10 : 14);
2133 if (choice == 4 || choice == 6)
2134 button = MB_MENU_CHOICE;
2140 if (y == 1 && dx != 0 && button)
2142 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2144 else if (IN_VIS_FIELD(x, y) &&
2145 y >= 0 && y <= 7 && (y != 1 || x < 10))
2151 drawCursor(choice, FALSE);
2152 drawCursor(y, TRUE);
2161 game_status = GAME_MODE_PSEUDO_TYPENAME;
2162 HandleTypeName(strlen(setup.player_name), 0);
2168 game_status = GAME_MODE_LEVELS;
2170 SaveLevelSetup_LastSeries();
2171 SaveLevelSetup_SeriesInfo();
2182 game_status = GAME_MODE_SCORES;
2187 if (leveldir_current->readonly &&
2188 !strEqual(setup.player_name, "Artsoft"))
2189 Request("This level is read only !", REQ_CONFIRM);
2190 game_status = GAME_MODE_EDITOR;
2195 game_status = GAME_MODE_INFO;
2196 info_mode = INFO_MODE_MAIN;
2201 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2205 game_status = GAME_MODE_SETUP;
2206 setup_mode = SETUP_MODE_MAIN;
2212 SaveLevelSetup_LastSeries();
2213 SaveLevelSetup_SeriesInfo();
2215 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2216 game_status = GAME_MODE_QUIT;
2221 if (game_status == GAME_MODE_MAIN)
2223 DrawPreviewLevel(FALSE);
2231 /* ========================================================================= */
2232 /* info screen functions */
2233 /* ========================================================================= */
2235 static struct TokenInfo *info_info;
2236 static int num_info_info;
2238 static void execInfoTitleScreen()
2241 FadeSetEnterScreen();
2244 info_mode = INFO_MODE_TITLE;
2248 static void execInfoElements()
2251 FadeSetEnterScreen();
2254 info_mode = INFO_MODE_ELEMENTS;
2258 static void execInfoMusic()
2261 FadeSetEnterScreen();
2264 info_mode = INFO_MODE_MUSIC;
2268 static void execInfoCredits()
2271 FadeSetEnterScreen();
2274 info_mode = INFO_MODE_CREDITS;
2278 static void execInfoProgram()
2281 FadeSetEnterScreen();
2284 info_mode = INFO_MODE_PROGRAM;
2288 static void execInfoVersion()
2291 FadeSetEnterScreen();
2294 info_mode = INFO_MODE_VERSION;
2298 static void execInfoLevelSet()
2301 FadeSetEnterScreen();
2304 info_mode = INFO_MODE_LEVELSET;
2308 static void execExitInfo()
2314 game_status = GAME_MODE_MAIN;
2316 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2322 static struct TokenInfo info_info_main[] =
2324 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2325 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2326 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2327 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2328 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2329 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2330 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2331 { TYPE_EMPTY, NULL, "" },
2332 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2337 static void DrawCursorAndText_Info(int pos, boolean active)
2339 int xpos = MENU_SCREEN_START_XPOS;
2340 int ypos = MENU_SCREEN_START_YPOS + pos;
2341 int font_nr = FONT_MENU_1;
2344 font_nr = FONT_ACTIVE(font_nr);
2346 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2348 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2349 drawCursor(pos, active);
2352 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2357 CloseDoor(DOOR_CLOSE_2);
2359 /* (needed after displaying title screens which disable auto repeat) */
2360 KeyboardAutoRepeatOn();
2362 FadeSetLeaveScreen();
2365 FadeOut(redraw_mask);
2369 if (redraw_mask == REDRAW_ALL)
2372 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2378 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2380 info_info = info_info_main;
2383 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2386 int xpos = MENU_SCREEN_START_XPOS;
2387 int ypos = MENU_SCREEN_START_YPOS + i;
2388 int font_nr = FONT_MENU_1;
2391 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2392 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2393 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2394 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2395 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2396 initCursor(i, IMG_MENU_BUTTON);
2399 DrawCursorAndText_Info(i, FALSE);
2401 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2407 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2412 DrawMaskedBorder(redraw_mask);
2415 FadeIn(redraw_mask);
2420 else if (fading.anim_mode == ANIM_CROSSFADE)
2421 FadeCross(redraw_mask);
2423 FadeIn(redraw_mask);
2426 FadeIn(redraw_mask);
2435 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2437 static int choice_store[MAX_INFO_MODES];
2438 int choice = choice_store[info_mode]; /* always starts with 0 */
2442 if (button == MB_MENU_INITIALIZE)
2444 /* advance to first valid menu entry */
2445 while (choice < num_info_info &&
2446 info_info[choice].type & TYPE_SKIP_ENTRY)
2448 choice_store[info_mode] = choice;
2451 DrawCursorAndText_Info(choice, TRUE);
2453 drawCursor(choice, TRUE);
2458 else if (button == MB_MENU_LEAVE)
2460 for (y = 0; y < num_info_info; y++)
2462 if (info_info[y].type & TYPE_LEAVE_MENU)
2464 void (*menu_callback_function)(void) = info_info[y].value;
2468 menu_callback_function();
2470 break; /* absolutely needed because function changes 'info_info'! */
2477 if (mx || my) /* mouse input */
2479 x = (mx - mSX) / 32;
2480 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2482 else if (dx || dy) /* keyboard input */
2486 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2488 if (info_info[choice].type & menu_navigation_type ||
2489 info_info[choice].type & TYPE_ENTER_SCREEN ||
2490 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2491 button = MB_MENU_CHOICE;
2496 /* jump to next non-empty menu entry (up or down) */
2497 while (y > 0 && y < num_info_info - 1 &&
2498 info_info[y].type & TYPE_SKIP_ENTRY)
2502 if (IN_VIS_FIELD(x, y) &&
2503 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2509 PlaySound(SND_MENU_ITEM_ACTIVATING);
2512 DrawCursorAndText_Info(choice, FALSE);
2513 DrawCursorAndText_Info(y, TRUE);
2515 drawCursor(choice, FALSE);
2516 drawCursor(y, TRUE);
2519 choice = choice_store[info_mode] = y;
2522 else if (!(info_info[y].type & TYPE_GHOSTED))
2524 PlaySound(SND_MENU_ITEM_SELECTING);
2526 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2528 void (*menu_callback_function)(void) = info_info[choice].value;
2530 FadeSetFromType(info_info[y].type);
2532 menu_callback_function();
2538 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2541 int ystart1 = mSY - SY + 100;
2542 int ystart2 = mSY - SY + 150;
2543 int ybottom = mSY - SY + SYSIZE - 20;
2547 int ybottom = SYSIZE - 20;
2550 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2553 FadeOut(REDRAW_FIELD);
2559 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2560 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2562 DrawTextSCentered(ybottom, FONT_TEXT_4,
2563 "Press any key or button for info menu");
2566 FadeIn(REDRAW_FIELD);
2570 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2572 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2573 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2574 int xstart = mSX + 16;
2575 int ystart1 = mSY - SY + 100;
2576 int ystart2 = mSY + 64 + 2 * 32;
2577 int ybottom = mSY - SY + SYSIZE - 20;
2578 int ystep = TILEY + 4;
2579 int element, action, direction;
2587 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2588 infoscreen_step[i] = infoscreen_frame[i] = 0;
2593 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2595 DrawTextSCentered(ybottom, FONT_TEXT_4,
2596 "Press any key or button for next page");
2602 while (helpanim_info[j].element != HELPANIM_LIST_END)
2604 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2609 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2618 j += infoscreen_step[i - start];
2620 element = helpanim_info[j].element;
2621 action = helpanim_info[j].action;
2622 direction = helpanim_info[j].direction;
2625 element = EL_UNKNOWN;
2627 if (action != -1 && direction != -1)
2628 graphic = el_act_dir2img(element, action, direction);
2629 else if (action != -1)
2630 graphic = el_act2img(element, action);
2631 else if (direction != -1)
2632 graphic = el_dir2img(element, direction);
2634 graphic = el2img(element);
2636 delay = helpanim_info[j++].delay;
2641 if (infoscreen_frame[i - start] == 0)
2644 infoscreen_frame[i - start] = delay - 1;
2648 sync_frame = delay - infoscreen_frame[i - start];
2649 infoscreen_frame[i - start]--;
2652 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2654 if (!infoscreen_frame[i - start])
2655 infoscreen_step[i - start] = 0;
2659 if (!infoscreen_frame[i - start])
2660 infoscreen_step[i - start]++;
2661 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2667 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2669 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2670 graphic, sync_frame, USE_MASKING);
2673 DrawInfoScreen_HelpText(element, action, direction, i - start);
2678 redraw_mask |= REDRAW_FIELD;
2683 static char *getHelpText(int element, int action, int direction)
2685 char token[MAX_LINE_LEN];
2687 strcpy(token, element_info[element].token_name);
2690 strcat(token, element_action_info[action].suffix);
2692 if (direction != -1)
2693 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2695 return getHashEntry(helptext_info, token);
2698 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2701 int font_nr = FONT_INFO_ELEMENTS;
2703 int font_nr = FONT_LEVEL_NUMBER;
2705 int font_width = getFontWidth(font_nr);
2706 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2707 int sy = mSY + 65 + 2 * 32 + 1;
2708 int ystep = TILEY + 4;
2709 int pad_x = sx - SX;
2710 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2711 int max_lines_per_text = 2;
2714 if (action != -1 && direction != -1) /* element.action.direction */
2715 text = getHelpText(element, action, direction);
2717 if (text == NULL && action != -1) /* element.action */
2718 text = getHelpText(element, action, -1);
2720 if (text == NULL && direction != -1) /* element.direction */
2721 text = getHelpText(element, -1, direction);
2723 if (text == NULL) /* base element */
2724 text = getHelpText(element, -1, -1);
2726 if (text == NULL) /* not found */
2727 text = "No description available";
2729 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2730 sy += getFontHeight(font_nr) / 2;
2733 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2734 max_chars_per_line, -1, max_lines_per_text, -1,
2735 TRUE, FALSE, FALSE);
2737 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2738 max_chars_per_line, max_lines_per_text);
2742 void DrawInfoScreen_TitleScreen()
2747 void HandleInfoScreen_TitleScreen(int button)
2749 HandleTitleScreen(0, 0, 0, 0, button);
2752 void DrawInfoScreen_Elements()
2754 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2757 FadeOut(REDRAW_FIELD);
2763 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2766 FadeIn(REDRAW_FIELD);
2772 void HandleInfoScreen_Elements(int button)
2774 static unsigned long info_delay = 0;
2775 static int num_anims;
2776 static int num_pages;
2778 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2781 if (button == MB_MENU_INITIALIZE)
2783 boolean new_element = TRUE;
2787 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2789 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2791 else if (new_element)
2794 new_element = FALSE;
2798 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2802 if (button == MB_MENU_LEAVE)
2804 PlaySound(SND_MENU_ITEM_SELECTING);
2806 info_mode = INFO_MODE_MAIN;
2811 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2813 if (button != MB_MENU_INITIALIZE)
2815 PlaySound(SND_MENU_ITEM_SELECTING);
2820 if (page >= num_pages)
2822 FadeSoundsAndMusic();
2825 FadeOut(REDRAW_FIELD);
2828 info_mode = INFO_MODE_MAIN;
2829 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2834 if (button != MB_MENU_INITIALIZE)
2835 FadeCrossSaveBackbuffer();
2837 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2839 if (button != MB_MENU_INITIALIZE)
2840 FadeCross(REDRAW_FIELD);
2844 if (DelayReached(&info_delay, GameFrameDelay))
2845 if (page < num_pages)
2846 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2848 PlayMenuSoundIfLoop();
2852 void DrawInfoScreen_Music()
2854 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2857 FadeOut(REDRAW_FIELD);
2865 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2868 FadeIn(REDRAW_FIELD);
2872 void HandleInfoScreen_Music(int button)
2874 static struct MusicFileInfo *list = NULL;
2875 int ystart1 = mSY - SY + 100;
2876 int ystart2 = mSY - SY + 150;
2877 int ybottom = mSY - SY + SYSIZE - 20;
2880 if (button == MB_MENU_INITIALIZE)
2882 list = music_file_info;
2886 FadeSoundsAndMusic();
2891 DrawTextSCentered(ystart1, FONT_TEXT_1,
2892 "No music info for this level set.");
2894 DrawTextSCentered(ybottom, FONT_TEXT_4,
2895 "Press any key or button for info menu");
2901 if (button == MB_MENU_LEAVE)
2903 PlaySound(SND_MENU_ITEM_SELECTING);
2905 FadeSoundsAndMusic();
2907 info_mode = INFO_MODE_MAIN;
2912 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2916 if (button != MB_MENU_INITIALIZE)
2918 PlaySound(SND_MENU_ITEM_SELECTING);
2926 FadeSoundsAndMusic();
2929 FadeOut(REDRAW_FIELD);
2932 info_mode = INFO_MODE_MAIN;
2933 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2938 FadeSoundsAndMusic();
2940 if (button != MB_MENU_INITIALIZE)
2941 FadeCrossSaveBackbuffer();
2948 int sound = list->music;
2950 if (sound_info[sound].loop)
2951 PlaySoundLoop(sound);
2955 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2959 PlayMusic(list->music);
2961 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2964 if (!strEqual(list->title, UNKNOWN_NAME))
2966 if (!strEqual(list->title_header, UNKNOWN_NAME))
2967 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2969 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2972 if (!strEqual(list->artist, UNKNOWN_NAME))
2974 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2975 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2977 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2979 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2982 if (!strEqual(list->album, UNKNOWN_NAME))
2984 if (!strEqual(list->album_header, UNKNOWN_NAME))
2985 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2987 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2989 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2992 if (!strEqual(list->year, UNKNOWN_NAME))
2994 if (!strEqual(list->year_header, UNKNOWN_NAME))
2995 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2997 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2999 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
3002 DrawTextSCentered(ybottom, FONT_TEXT_4,
3003 "Press any key or button for next page");
3005 if (button != MB_MENU_INITIALIZE)
3006 FadeCross(REDRAW_FIELD);
3009 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3010 PlaySoundLoop(list->music);
3013 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
3015 int ystart1 = mSY - SY + 100;
3016 int ystart2 = mSY - SY + 150;
3017 int ybottom = mSY - SY + SYSIZE - 20;
3026 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
3030 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3031 "Special thanks to");
3032 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3034 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3036 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3037 "\"Boulder Dash\"");
3038 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3040 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3042 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3044 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3045 "First Star Software");
3047 else if (screen_nr == 1)
3049 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3050 "Special thanks to");
3051 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3052 "Klaus Heinz & Volker Wertich");
3053 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3055 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3056 "\"Emerald Mine\"");
3057 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3059 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3061 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3063 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3066 else if (screen_nr == 2)
3068 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3069 "Special thanks to");
3070 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3071 "Michael Stopp & Philip Jespersen");
3072 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3074 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3076 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3078 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3080 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3082 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3083 "Digital Integration");
3085 else if (screen_nr == 3)
3087 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3088 "Special thanks to");
3089 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3090 "Hiroyuki Imabayashi");
3091 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3093 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3095 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3097 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3099 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3101 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3104 else if (screen_nr == 4)
3106 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3107 "Special thanks to");
3108 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3110 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3112 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3113 "Jürgen Bonhagen");
3114 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3115 "for the continuous creation");
3116 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3117 "of outstanding level sets");
3119 else if (screen_nr == 5)
3121 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3123 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3125 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3126 "for ideas and inspiration by");
3127 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3130 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3132 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3134 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3135 "for ideas and inspiration by");
3136 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3139 else if (screen_nr == 6)
3141 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3143 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3145 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3146 "for the new Emerald Mine engine");
3148 else if (screen_nr == 7)
3150 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3152 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3154 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3155 "for the initial DOS port");
3157 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3159 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3161 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3162 "for some additional toons");
3164 else if (screen_nr == 8)
3166 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3167 "And not to forget:");
3168 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3170 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3171 "All those who contributed");
3172 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3173 "levels to this game");
3174 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3184 DrawTextSCentered(ybottom, FONT_TEXT_4,
3185 "Press any key or button for next page");
3190 void DrawInfoScreen_Credits()
3192 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3194 FadeSoundsAndMusic();
3197 FadeOut(REDRAW_FIELD);
3200 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3203 FadeIn(REDRAW_FIELD);
3207 void HandleInfoScreen_Credits(int button)
3209 static int screen_nr = 0;
3211 if (button == MB_MENU_INITIALIZE)
3215 DrawInfoScreen_CreditsScreen(screen_nr);
3217 else if (button == MB_MENU_LEAVE)
3219 PlaySound(SND_MENU_ITEM_SELECTING);
3221 info_mode = INFO_MODE_MAIN;
3226 else if (button == MB_MENU_CHOICE)
3228 boolean show_screen;
3230 PlaySound(SND_MENU_ITEM_SELECTING);
3234 FadeCrossSaveBackbuffer();
3236 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3240 FadeCross(REDRAW_FIELD);
3244 FadeSoundsAndMusic();
3247 FadeOut(REDRAW_FIELD);
3250 info_mode = INFO_MODE_MAIN;
3251 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3256 PlayMenuSoundIfLoop();
3260 void DrawInfoScreen_Program()
3262 int ystart1 = mSY - SY + 100;
3263 int ystart2 = mSY - SY + 150;
3264 int ybottom = mSY - SY + SYSIZE - 20;
3267 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3270 FadeOut(REDRAW_FIELD);
3276 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3278 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3279 "This game is Freeware!");
3280 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3281 "If you like it, send e-mail to:");
3282 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3283 PROGRAM_EMAIL_STRING);
3284 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3285 "or SnailMail to:");
3286 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3288 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3289 "Detmolder Strasse 189");
3290 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3292 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3294 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3295 "More information and levels:");
3296 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3297 PROGRAM_WEBSITE_STRING);
3298 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3299 "If you have created new levels,");
3300 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3301 "send them to me to include them!");
3302 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3305 DrawTextSCentered(ybottom, FONT_TEXT_4,
3306 "Press any key or button for info menu");
3309 FadeIn(REDRAW_FIELD);
3313 void HandleInfoScreen_Program(int button)
3315 if (button == MB_MENU_LEAVE)
3317 PlaySound(SND_MENU_ITEM_SELECTING);
3319 info_mode = INFO_MODE_MAIN;
3324 else if (button == MB_MENU_CHOICE)
3326 PlaySound(SND_MENU_ITEM_SELECTING);
3328 FadeSoundsAndMusic();
3331 FadeOut(REDRAW_FIELD);
3334 info_mode = INFO_MODE_MAIN;
3335 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3339 PlayMenuSoundIfLoop();
3343 void DrawInfoScreen_Version()
3345 int font_header = FONT_TEXT_3;
3346 int font_text = FONT_TEXT_2;
3347 int xstep = getFontWidth(font_text);
3348 int ystep = getFontHeight(font_text);
3349 int ystart1 = mSY - SY + 100;
3350 int ystart2 = mSY - SY + 150;
3351 int ybottom = mSY - SY + SYSIZE - 20;
3352 int xstart1 = mSX + 2 * xstep;
3353 int xstart2 = mSX + 19 * xstep;
3354 #if defined(TARGET_SDL)
3355 int xstart3 = mSX + 29 * xstep;
3356 SDL_version sdl_version_compiled;
3357 const SDL_version *sdl_version_linked;
3358 int driver_name_len = 8;
3359 char driver_name[driver_name_len];
3362 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3365 FadeOut(REDRAW_FIELD);
3371 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3373 DrawTextF(xstart1, ystart2, font_header, "Name");
3374 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3377 DrawTextF(xstart1, ystart2, font_header, "Version");
3378 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3381 DrawTextF(xstart1, ystart2, font_header, "Platform");
3382 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3385 DrawTextF(xstart1, ystart2, font_header, "Target");
3386 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3389 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3390 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3392 #if defined(TARGET_SDL)
3393 ystart2 += 3 * ystep;
3394 DrawTextF(xstart1, ystart2, font_header, "Library");
3395 DrawTextF(xstart2, ystart2, font_header, "compiled");
3396 DrawTextF(xstart3, ystart2, font_header, "linked");
3398 SDL_VERSION(&sdl_version_compiled);
3399 sdl_version_linked = SDL_Linked_Version();
3401 ystart2 += 2 * ystep;
3402 DrawTextF(xstart1, ystart2, font_text, "SDL");
3403 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3404 sdl_version_compiled.major,
3405 sdl_version_compiled.minor,
3406 sdl_version_compiled.patch);
3407 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3408 sdl_version_linked->major,
3409 sdl_version_linked->minor,
3410 sdl_version_linked->patch);
3412 SDL_IMAGE_VERSION(&sdl_version_compiled);
3413 sdl_version_linked = IMG_Linked_Version();
3416 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3417 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3418 sdl_version_compiled.major,
3419 sdl_version_compiled.minor,
3420 sdl_version_compiled.patch);
3421 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3422 sdl_version_linked->major,
3423 sdl_version_linked->minor,
3424 sdl_version_linked->patch);
3426 SDL_MIXER_VERSION(&sdl_version_compiled);
3427 sdl_version_linked = Mix_Linked_Version();
3430 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3431 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3432 sdl_version_compiled.major,
3433 sdl_version_compiled.minor,
3434 sdl_version_compiled.patch);
3435 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3436 sdl_version_linked->major,
3437 sdl_version_linked->minor,
3438 sdl_version_linked->patch);
3440 SDL_NET_VERSION(&sdl_version_compiled);
3441 sdl_version_linked = SDLNet_Linked_Version();
3444 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3445 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3446 sdl_version_compiled.major,
3447 sdl_version_compiled.minor,
3448 sdl_version_compiled.patch);
3449 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3450 sdl_version_linked->major,
3451 sdl_version_linked->minor,
3452 sdl_version_linked->patch);
3454 ystart2 += 3 * ystep;
3455 DrawTextF(xstart1, ystart2, font_header, "Driver");
3456 DrawTextF(xstart2, ystart2, font_header, "Requested");
3457 DrawTextF(xstart3, ystart2, font_header, "Used");
3459 SDL_VideoDriverName(driver_name, driver_name_len);
3461 ystart2 += 2 * ystep;
3462 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3463 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3464 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3466 SDL_AudioDriverName(driver_name, driver_name_len);
3469 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3470 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3471 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3474 DrawTextSCentered(ybottom, FONT_TEXT_4,
3475 "Press any key or button for info menu");
3478 FadeIn(REDRAW_FIELD);
3482 void HandleInfoScreen_Version(int button)
3484 if (button == MB_MENU_LEAVE)
3486 PlaySound(SND_MENU_ITEM_SELECTING);
3488 info_mode = INFO_MODE_MAIN;
3493 else if (button == MB_MENU_CHOICE)
3495 PlaySound(SND_MENU_ITEM_SELECTING);
3497 FadeSoundsAndMusic();
3500 FadeOut(REDRAW_FIELD);
3503 info_mode = INFO_MODE_MAIN;
3504 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3508 PlayMenuSoundIfLoop();
3512 void DrawInfoScreen_LevelSet()
3514 struct TitleMessageInfo *tmi = &readme;
3515 char *filename = getLevelSetInfoFilename();
3517 /* if chars set to "-1", automatically determine by text and font width */
3518 if (tmi->chars == -1)
3519 tmi->chars = tmi->width / getFontWidth(tmi->font);
3521 tmi->width = tmi->chars * getFontWidth(tmi->font);
3523 /* if lines set to "-1", automatically determine by text and font height */
3524 if (tmi->lines == -1)
3525 tmi->lines = tmi->height / getFontHeight(tmi->font);
3527 tmi->height = tmi->lines * getFontHeight(tmi->font);
3529 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3532 FadeOut(REDRAW_FIELD);
3538 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3540 if (filename != NULL)
3541 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3542 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3543 tmi->autowrap, tmi->centered, tmi->parse_comments);
3545 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3546 "No information for this level set.");
3548 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3549 "Press any key or button for info menu");
3552 FadeIn(REDRAW_FIELD);
3556 void HandleInfoScreen_LevelSet(int button)
3558 if (button == MB_MENU_LEAVE)
3560 PlaySound(SND_MENU_ITEM_SELECTING);
3562 info_mode = INFO_MODE_MAIN;
3567 else if (button == MB_MENU_CHOICE)
3569 PlaySound(SND_MENU_ITEM_SELECTING);
3571 FadeSoundsAndMusic();
3574 FadeOut(REDRAW_FIELD);
3577 info_mode = INFO_MODE_MAIN;
3578 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3582 PlayMenuSoundIfLoop();
3586 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3588 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3590 if (info_mode == INFO_MODE_TITLE)
3591 DrawInfoScreen_TitleScreen();
3592 else if (info_mode == INFO_MODE_ELEMENTS)
3593 DrawInfoScreen_Elements();
3594 else if (info_mode == INFO_MODE_MUSIC)
3595 DrawInfoScreen_Music();
3596 else if (info_mode == INFO_MODE_CREDITS)
3597 DrawInfoScreen_Credits();
3598 else if (info_mode == INFO_MODE_PROGRAM)
3599 DrawInfoScreen_Program();
3600 else if (info_mode == INFO_MODE_VERSION)
3601 DrawInfoScreen_Version();
3602 else if (info_mode == INFO_MODE_LEVELSET)
3603 DrawInfoScreen_LevelSet();
3605 DrawInfoScreen_Main(redraw_mask, do_fading);
3607 if (info_mode != INFO_MODE_MAIN &&
3608 info_mode != INFO_MODE_TITLE &&
3609 info_mode != INFO_MODE_MUSIC)
3616 void DrawAndFadeInInfoScreen(int redraw_mask)
3618 DrawInfoScreenExt(redraw_mask, TRUE);
3621 void DrawInfoScreen()
3623 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3626 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3628 if (info_mode == INFO_MODE_TITLE)
3629 HandleInfoScreen_TitleScreen(button);
3630 else if (info_mode == INFO_MODE_ELEMENTS)
3631 HandleInfoScreen_Elements(button);
3632 else if (info_mode == INFO_MODE_MUSIC)
3633 HandleInfoScreen_Music(button);
3634 else if (info_mode == INFO_MODE_CREDITS)
3635 HandleInfoScreen_Credits(button);
3636 else if (info_mode == INFO_MODE_PROGRAM)
3637 HandleInfoScreen_Program(button);
3638 else if (info_mode == INFO_MODE_VERSION)
3639 HandleInfoScreen_Version(button);
3640 else if (info_mode == INFO_MODE_LEVELSET)
3641 HandleInfoScreen_LevelSet(button);
3643 HandleInfoScreen_Main(mx, my, dx, dy, button);
3649 /* ========================================================================= */
3650 /* type name functions */
3651 /* ========================================================================= */
3653 void HandleTypeName(int newxpos, Key key)
3655 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3656 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3658 struct TextPosInfo *pos = mci->pos_input;
3659 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3660 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3663 static int xpos = 0;
3665 static int xpos = 0, ypos = 2;
3667 int font_nr = pos->font;
3668 int font_active_nr = FONT_ACTIVE(font_nr);
3669 int font_width = getFontWidth(font_active_nr);
3672 int startx = mSX + mci->pos_input->x;
3673 int starty = mSY + mci->pos_input->y;
3676 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3677 int startx = mSX + 32 + name_width;
3678 int starty = mSY + ypos * 32;
3680 char key_char = getValidConfigValueChar(getCharFromKey(key));
3681 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3682 boolean is_active = TRUE;
3684 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3688 strcpy(last_player_name, setup.player_name);
3693 /* add one character width for added cursor character */
3694 pos->width += font_width;
3695 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3697 DrawText(startx, starty, setup.player_name, font_active_nr);
3698 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3701 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3703 setup.player_name[xpos] = key_char;
3704 setup.player_name[xpos + 1] = 0;
3709 /* add one character width for added name text character */
3710 pos->width += font_width;
3711 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3713 DrawText(startx, starty, setup.player_name, font_active_nr);
3714 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3717 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3721 setup.player_name[xpos] = 0;
3724 /* remove one character width for removed name text character */
3725 pos->width -= font_width;
3726 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3728 DrawText(startx, starty, setup.player_name, font_active_nr);
3729 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3732 else if (key == KSYM_Return && xpos > 0)
3735 /* remove one character width for removed cursor text character */
3736 pos->width -= font_width;
3737 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3739 DrawText(startx, starty, setup.player_name, font_nr);
3740 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3747 game_status = GAME_MODE_MAIN;
3749 else if (key == KSYM_Escape)
3751 strcpy(setup.player_name, last_player_name);
3755 game_status = GAME_MODE_MAIN;
3760 pos->width = (strlen(setup.player_name) + 1) * font_width;
3761 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3763 DrawText(startx, starty, setup.player_name, font_active_nr);
3764 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3768 pos->width = strlen(setup.player_name) * font_width;
3769 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3771 DrawText(startx, starty, setup.player_name, font_nr);
3776 /* ========================================================================= */
3777 /* tree menu functions */
3778 /* ========================================================================= */
3780 static void DrawChooseTree(TreeInfo **ti_ptr)
3784 FreeScreenGadgets();
3785 CreateScreenGadgets();
3787 CloseDoor(DOOR_CLOSE_2);
3790 FadeOut(REDRAW_FIELD);
3795 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3796 MapScreenTreeGadgets(*ti_ptr);
3799 FadeIn(REDRAW_FIELD);
3805 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3807 struct GadgetInfo *gi = screen_gadget[id];
3808 int items_max, items_visible, item_position;
3810 items_max = numTreeInfoInGroup(ti);
3811 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3812 item_position = first_entry;
3814 if (item_position > items_max - items_visible)
3815 item_position = items_max - items_visible;
3817 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3818 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3819 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3822 static void drawChooseTreeList(int first_entry, int num_page_entries,
3826 char *title_string = NULL;
3827 int yoffset_sets = MENU_TITLE1_YPOS;
3828 int yoffset_setup = 16;
3829 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3831 int last_game_status = game_status; /* save current game status */
3833 title_string = ti->infotext;
3835 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3838 /* force LEVELS font on artwork setup screen */
3839 game_status = GAME_MODE_LEVELS;
3843 /* clear tree list area, but not title or scrollbar */
3844 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3845 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3846 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3848 /* clear tree list area, but not title or scrollbar */
3849 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3850 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3851 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3854 for (i = 0; i < num_page_entries; i++)
3856 TreeInfo *node, *node_first;
3857 int entry_pos = first_entry + i;
3858 int xpos = MENU_SCREEN_START_XPOS;
3859 int ypos = MENU_SCREEN_START_YPOS + i;
3860 int startx = mSX + xpos * 32;
3861 int starty = mSY + ypos * 32;
3862 int font_nr = FONT_TEXT_1;
3863 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3864 int startx_text = startx + font_xoffset;
3865 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3866 int text_size = startx_scrollbar - startx_text;
3867 int max_buffer_len = text_size / getFontWidth(font_nr);
3868 char buffer[max_buffer_len + 1];
3870 node_first = getTreeInfoFirstGroupEntry(ti);
3871 node = getTreeInfoFromPos(node_first, entry_pos);
3873 strncpy(buffer, node->name, max_buffer_len);
3874 buffer[max_buffer_len] = '\0';
3876 DrawText(startx, starty, buffer, font_nr + node->color);
3878 if (node->parent_link)
3879 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3880 else if (node->level_group)
3881 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3883 initCursor(i, IMG_MENU_BUTTON);
3886 game_status = last_game_status; /* restore current game status */
3888 redraw_mask |= REDRAW_FIELD;
3891 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3893 TreeInfo *node, *node_first;
3894 int x, last_redraw_mask = redraw_mask;
3895 int ypos = MENU_TITLE2_YPOS;
3896 int font_nr = FONT_TITLE_2;
3898 if (ti->type != TREE_TYPE_LEVEL_DIR)
3901 node_first = getTreeInfoFirstGroupEntry(ti);
3902 node = getTreeInfoFromPos(node_first, entry_pos);
3904 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3906 if (node->parent_link)
3907 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3909 else if (node->level_group)
3910 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3912 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3913 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3914 node->levels, node->class_desc);
3916 /* let BackToFront() redraw only what is needed */
3917 redraw_mask = last_redraw_mask | REDRAW_TILES;
3918 for (x = 0; x < SCR_FIELDX; x++)
3919 MarkTileDirty(x, 1);
3922 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3925 TreeInfo *ti = *ti_ptr;
3927 int y = ti->cl_cursor;
3928 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3929 int num_entries = numTreeInfoInGroup(ti);
3930 int num_page_entries;
3931 int last_game_status = game_status; /* save current game status */
3932 boolean position_set_by_scrollbar = (dx == 999);
3935 /* force LEVELS draw offset on choose level and artwork setup screen */
3936 game_status = GAME_MODE_LEVELS;
3939 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3940 num_page_entries = num_entries;
3942 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3944 game_status = last_game_status; /* restore current game status */
3946 if (button == MB_MENU_INITIALIZE)
3948 int num_entries = numTreeInfoInGroup(ti);
3949 int entry_pos = posTreeInfo(ti);
3951 if (ti->cl_first == -1)
3953 /* only on initialization */
3954 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3955 ti->cl_cursor = entry_pos - ti->cl_first;
3957 else if (ti->cl_cursor >= num_page_entries ||
3958 (num_entries > num_page_entries &&
3959 num_entries - ti->cl_first < num_page_entries))
3961 /* only after change of list size (by custom graphic configuration) */
3962 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3963 ti->cl_cursor = entry_pos - ti->cl_first;
3966 if (position_set_by_scrollbar)
3969 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3972 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3973 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3974 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3978 else if (button == MB_MENU_LEAVE)
3982 PlaySound(SND_MENU_ITEM_SELECTING);
3984 if (ti->node_parent)
3986 *ti_ptr = ti->node_parent;
3987 DrawChooseTree(ti_ptr);
3989 else if (game_status == GAME_MODE_SETUP)
3991 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3993 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3994 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3995 execSetupGraphics();
4001 game_status = GAME_MODE_MAIN;
4003 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4012 if (mx || my) /* mouse input */
4014 int last_game_status = game_status; /* save current game status */
4017 /* force LEVELS draw offset on artwork setup screen */
4018 game_status = GAME_MODE_LEVELS;
4021 x = (mx - mSX) / 32;
4022 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4024 game_status = last_game_status; /* restore current game status */
4026 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4028 /* move cursor instead of scrolling when already at start/end of list */
4029 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4031 else if (dy == +1 * SCROLL_LINE &&
4032 ti->cl_first + num_page_entries == num_entries)
4035 /* handle scrolling screen one line or page */
4036 if (ti->cl_cursor + dy < 0 ||
4037 ti->cl_cursor + dy > num_page_entries - 1)
4039 if (ABS(dy) == SCROLL_PAGE)
4040 step = num_page_entries - 1;
4042 if (dy < 0 && ti->cl_first > 0)
4044 /* scroll page/line up */
4046 ti->cl_first -= step;
4047 if (ti->cl_first < 0)
4050 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4051 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4052 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4054 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4057 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4059 /* scroll page/line down */
4061 ti->cl_first += step;
4062 if (ti->cl_first + num_page_entries > num_entries)
4063 ti->cl_first = MAX(0, num_entries - num_page_entries);
4065 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4066 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4067 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4069 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4076 /* handle moving cursor one line */
4077 y = ti->cl_cursor + dy;
4082 TreeInfo *node_first, *node_cursor;
4083 int entry_pos = ti->cl_first + y;
4085 node_first = getTreeInfoFirstGroupEntry(ti);
4086 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4088 if (node_cursor->node_group)
4092 PlaySound(SND_MENU_ITEM_SELECTING);
4094 node_cursor->cl_first = ti->cl_first;
4095 node_cursor->cl_cursor = ti->cl_cursor;
4096 *ti_ptr = node_cursor->node_group;
4097 DrawChooseTree(ti_ptr);
4102 else if (dx == -1 && ti->node_parent)
4106 PlaySound(SND_MENU_ITEM_SELECTING);
4108 *ti_ptr = ti->node_parent;
4109 DrawChooseTree(ti_ptr);
4114 if (!anyScrollbarGadgetActive() &&
4115 IN_VIS_FIELD(x, y) &&
4116 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4117 y >= 0 && y < num_page_entries)
4121 if (y != ti->cl_cursor)
4123 PlaySound(SND_MENU_ITEM_ACTIVATING);
4125 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4126 drawChooseTreeCursor(y, TRUE);
4127 drawChooseTreeInfo(ti->cl_first + y, ti);
4134 TreeInfo *node_first, *node_cursor;
4135 int entry_pos = ti->cl_first + y;
4137 PlaySound(SND_MENU_ITEM_SELECTING);
4139 node_first = getTreeInfoFirstGroupEntry(ti);
4140 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4142 if (node_cursor->node_group)
4146 node_cursor->cl_first = ti->cl_first;
4147 node_cursor->cl_cursor = ti->cl_cursor;
4148 *ti_ptr = node_cursor->node_group;
4149 DrawChooseTree(ti_ptr);
4151 else if (node_cursor->parent_link)
4155 *ti_ptr = node_cursor->node_parent;
4156 DrawChooseTree(ti_ptr);
4160 FadeSetEnterScreen();
4162 node_cursor->cl_first = ti->cl_first;
4163 node_cursor->cl_cursor = ti->cl_cursor;
4164 *ti_ptr = node_cursor;
4166 if (ti->type == TREE_TYPE_LEVEL_DIR)
4168 LoadLevelSetup_SeriesInfo();
4170 SaveLevelSetup_LastSeries();
4171 SaveLevelSetup_SeriesInfo();
4175 if (game_status == GAME_MODE_SETUP)
4177 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4179 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4180 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4181 execSetupGraphics();
4187 game_status = GAME_MODE_MAIN;
4195 void DrawChooseLevel()
4197 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4199 DrawChooseTree(&leveldir_current);
4205 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4207 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4212 void DrawHallOfFame(int highlight_position)
4215 FadeSoundsAndMusic();
4217 /* (this is needed when called from GameEnd() after winning a game) */
4218 KeyboardAutoRepeatOn();
4221 /* (this is needed when called from GameEnd() after winning a game) */
4222 SetDrawDeactivationMask(REDRAW_NONE);
4223 SetDrawBackgroundMask(REDRAW_FIELD);
4225 CloseDoor(DOOR_CLOSE_2);
4227 if (highlight_position < 0)
4228 LoadScore(level_nr);
4230 FadeSetEnterScreen();
4232 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4235 FadeOut(REDRAW_FIELD);
4243 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4246 FadeIn(REDRAW_FIELD);
4250 static void drawHallOfFameList(int first_entry, int highlight_position)
4254 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4257 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4258 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4259 "HighScores of Level %d", level_nr);
4261 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4263 int entry = first_entry + i;
4264 boolean active = (entry == highlight_position);
4265 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4266 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4267 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4268 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4269 int dx1 = 3 * getFontWidth(font_nr1);
4270 int dx2 = dx1 + getFontWidth(font_nr1);
4271 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4272 int sy = mSY + 64 + i * 32;
4274 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4275 DrawText(mSX + dx1, sy, ".", font_nr1);
4276 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4278 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4279 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4281 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4284 redraw_mask |= REDRAW_FIELD;
4287 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4289 static int first_entry = 0;
4290 static int highlight_position = 0;
4291 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4293 if (button == MB_MENU_INITIALIZE)
4296 highlight_position = mx;
4297 drawHallOfFameList(first_entry, highlight_position);
4302 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4303 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4307 if (first_entry > 0)
4309 first_entry -= step;
4310 if (first_entry < 0)
4313 drawHallOfFameList(first_entry, highlight_position);
4318 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4320 first_entry += step;
4321 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4322 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4324 drawHallOfFameList(first_entry, highlight_position);
4327 else if (button == MB_MENU_LEAVE)
4329 PlaySound(SND_MENU_ITEM_SELECTING);
4331 FadeSound(SND_BACKGROUND_SCORES);
4333 game_status = GAME_MODE_MAIN;
4337 else if (button == MB_MENU_CHOICE)
4339 PlaySound(SND_MENU_ITEM_SELECTING);
4341 FadeSound(SND_BACKGROUND_SCORES);
4344 FadeOut(REDRAW_FIELD);
4347 game_status = GAME_MODE_MAIN;
4349 DrawAndFadeInMainMenu(REDRAW_FIELD);
4352 if (game_status == GAME_MODE_SCORES)
4353 PlayMenuSoundIfLoop();
4359 /* ========================================================================= */
4360 /* setup screen functions */
4361 /* ========================================================================= */
4363 static struct TokenInfo *setup_info;
4364 static int num_setup_info;
4366 static char *screen_mode_text;
4367 static char *scroll_delay_text;
4368 static char *game_speed_text;
4369 static char *graphics_set_name;
4370 static char *sounds_set_name;
4371 static char *music_set_name;
4373 static void execSetupMain()
4379 setup_mode = SETUP_MODE_MAIN;
4383 static void execSetupGame()
4389 if (game_speeds == NULL)
4393 for (i = 0; game_speeds_list[i].value != -1; i++)
4395 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4396 char identifier[32], name[32];
4397 int value = game_speeds_list[i].value;
4398 char *text = game_speeds_list[i].text;
4400 ti->node_top = &game_speeds;
4401 ti->sort_priority = 10000 - value;
4403 sprintf(identifier, "%d", value);
4404 sprintf(name, "%s", text);
4406 setString(&ti->identifier, identifier);
4407 setString(&ti->name, name);
4408 setString(&ti->name_sorting, name);
4409 setString(&ti->infotext, "Game Speed");
4411 pushTreeInfo(&game_speeds, ti);
4414 /* sort game speed values to start with slowest game speed */
4415 sortTreeInfo(&game_speeds);
4417 /* set current game speed to configured game speed value */
4418 game_speed_current =
4419 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4421 /* if that fails, set current game speed to reliable default value */
4422 if (game_speed_current == NULL)
4423 game_speed_current =
4424 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4426 /* if that also fails, set current game speed to first available speed */
4427 if (game_speed_current == NULL)
4428 game_speed_current = game_speeds;
4431 setup.game_frame_delay = atoi(game_speed_current->identifier);
4433 /* needed for displaying game speed text instead of identifier */
4434 game_speed_text = game_speed_current->name;
4436 setup_mode = SETUP_MODE_GAME;
4440 static void execSetupChooseGameSpeed()
4446 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4450 static void execSetupEditor()
4456 setup_mode = SETUP_MODE_EDITOR;
4460 static void execSetupGraphics()
4466 if (video.fullscreen_available && screen_modes == NULL)
4470 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4472 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4473 char identifier[32], name[32];
4474 int x = video.fullscreen_modes[i].width;
4475 int y = video.fullscreen_modes[i].height;
4478 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4480 ti->node_top = &screen_modes;
4481 ti->sort_priority = x * 10000 + y;
4483 sprintf(identifier, "%dx%d", x, y);
4484 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4486 setString(&ti->identifier, identifier);
4487 setString(&ti->name, name);
4488 setString(&ti->name_sorting, name);
4489 setString(&ti->infotext, "Fullscreen Mode");
4491 pushTreeInfo(&screen_modes, ti);
4494 /* sort fullscreen modes to start with lowest available screen resolution */
4495 sortTreeInfo(&screen_modes);
4497 /* set current screen mode for fullscreen mode to configured setup value */
4498 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4499 setup.fullscreen_mode);
4501 /* if that fails, set current screen mode to reliable default value */
4502 if (screen_mode_current == NULL)
4503 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4504 DEFAULT_FULLSCREEN_MODE);
4506 /* if that also fails, set current screen mode to first available mode */
4507 if (screen_mode_current == NULL)
4508 screen_mode_current = screen_modes;
4510 if (screen_mode_current == NULL)
4511 video.fullscreen_available = FALSE;
4514 if (video.fullscreen_available)
4516 setup.fullscreen_mode = screen_mode_current->identifier;
4518 /* needed for displaying screen mode name instead of identifier */
4519 screen_mode_text = screen_mode_current->name;
4523 if (scroll_delays == NULL)
4527 for (i = 0; scroll_delays_list[i].value != -1; i++)
4529 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4530 char identifier[32], name[32];
4531 int value = scroll_delays_list[i].value;
4532 char *text = scroll_delays_list[i].text;
4534 ti->node_top = &scroll_delays;
4535 ti->sort_priority = value;
4537 sprintf(identifier, "%d", value);
4538 sprintf(name, "%s", text);
4540 setString(&ti->identifier, identifier);
4541 setString(&ti->name, name);
4542 setString(&ti->name_sorting, name);
4543 setString(&ti->infotext, "Scroll Delay");
4545 pushTreeInfo(&scroll_delays, ti);
4548 /* sort scroll delay values to start with lowest scroll delay value */
4549 sortTreeInfo(&scroll_delays);
4551 /* set current scroll delay value to configured scroll delay value */
4552 scroll_delay_current =
4553 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4555 /* if that fails, set current scroll delay to reliable default value */
4556 if (scroll_delay_current == NULL)
4557 scroll_delay_current =
4558 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4560 /* if that also fails, set current scroll delay to first available value */
4561 if (scroll_delay_current == NULL)
4562 scroll_delay_current = scroll_delays;
4565 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4567 /* needed for displaying scroll delay text instead of identifier */
4568 scroll_delay_text = scroll_delay_current->name;
4571 setup_mode = SETUP_MODE_GRAPHICS;
4575 static void execSetupChooseScreenMode()
4581 if (!video.fullscreen_available)
4584 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4588 static void execSetupChooseScrollDelay()
4594 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4598 static void execSetupSound()
4604 setup_mode = SETUP_MODE_SOUND;
4608 static void execSetupArtwork()
4614 setup.graphics_set = artwork.gfx_current->identifier;
4615 setup.sounds_set = artwork.snd_current->identifier;
4616 setup.music_set = artwork.mus_current->identifier;
4618 /* needed if last screen (setup choice) changed graphics, sounds or music */
4619 ReloadCustomArtwork(0);
4621 /* needed for displaying artwork name instead of artwork identifier */
4622 graphics_set_name = artwork.gfx_current->name;
4623 sounds_set_name = artwork.snd_current->name;
4624 music_set_name = artwork.mus_current->name;
4626 setup_mode = SETUP_MODE_ARTWORK;
4630 static void execSetupChooseGraphics()
4636 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4640 static void execSetupChooseSounds()
4646 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4650 static void execSetupChooseMusic()
4656 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4660 static void execSetupInput()
4666 setup_mode = SETUP_MODE_INPUT;
4670 static void execSetupShortcuts1()
4676 setup_mode = SETUP_MODE_SHORTCUTS_1;
4680 static void execSetupShortcuts2()
4686 setup_mode = SETUP_MODE_SHORTCUTS_2;
4690 static void execExitSetup()
4696 game_status = GAME_MODE_MAIN;
4698 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4704 static void execSaveAndExitSetup()
4710 static struct TokenInfo setup_info_main[] =
4712 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4713 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4714 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4715 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4716 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4717 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4718 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4719 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4720 { TYPE_EMPTY, NULL, "" },
4721 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4722 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4727 static struct TokenInfo setup_info_game[] =
4729 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4730 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4731 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4732 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4733 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4734 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4735 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4736 { TYPE_STRING, &game_speed_text, "" },
4737 { TYPE_EMPTY, NULL, "" },
4738 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4743 static struct TokenInfo setup_info_editor[] =
4746 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4747 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4748 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4749 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4750 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4751 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4752 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4753 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4755 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4756 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4757 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4759 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4761 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4762 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4763 { TYPE_EMPTY, NULL, "" },
4765 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4766 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4767 { TYPE_EMPTY, NULL, "" },
4769 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4770 { TYPE_EMPTY, NULL, "" },
4771 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4776 static struct TokenInfo setup_info_graphics[] =
4778 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4779 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4780 { TYPE_STRING, &screen_mode_text, "" },
4782 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4784 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4785 { TYPE_STRING, &scroll_delay_text, "" },
4787 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4788 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4790 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4791 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4792 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4793 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4794 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4795 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4796 { TYPE_EMPTY, NULL, "" },
4797 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4802 static struct TokenInfo setup_info_sound[] =
4804 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4805 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4806 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4807 { TYPE_EMPTY, NULL, "" },
4808 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4813 static struct TokenInfo setup_info_artwork[] =
4815 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4816 { TYPE_STRING, &graphics_set_name, "" },
4817 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4818 { TYPE_STRING, &sounds_set_name, "" },
4819 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4820 { TYPE_STRING, &music_set_name, "" },
4821 { TYPE_EMPTY, NULL, "" },
4823 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4824 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4825 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4827 { TYPE_STRING, NULL, "Override Level Artwork:"},
4828 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4829 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4830 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4832 { TYPE_EMPTY, NULL, "" },
4833 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4838 static struct TokenInfo setup_info_input[] =
4840 { TYPE_SWITCH, NULL, "Player:" },
4841 { TYPE_SWITCH, NULL, "Device:" },
4842 { TYPE_ENTER_MENU, NULL, "" },
4843 { TYPE_EMPTY, NULL, "" },
4844 { TYPE_EMPTY, 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_LEAVE_MENU, execSetupMain, "Back" },
4858 static struct TokenInfo setup_info_shortcuts_1[] =
4860 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4861 { TYPE_KEY, &setup.shortcut.save_game, "" },
4862 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4863 { TYPE_KEY, &setup.shortcut.load_game, "" },
4864 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4865 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4866 { TYPE_EMPTY, NULL, "" },
4867 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4868 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4869 { TYPE_EMPTY, NULL, "" },
4870 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4875 static struct TokenInfo setup_info_shortcuts_2[] =
4877 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4878 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4879 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4880 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4881 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4882 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4883 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4884 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4885 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4886 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4887 { TYPE_EMPTY, NULL, "" },
4888 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4893 static Key getSetupKey()
4895 Key key = KSYM_UNDEFINED;
4896 boolean got_key_event = FALSE;
4898 while (!got_key_event)
4900 if (PendingEvent()) /* got event */
4908 case EVENT_KEYPRESS:
4910 key = GetEventKey((KeyEvent *)&event, TRUE);
4912 /* press 'Escape' or 'Enter' to keep the existing key binding */
4913 if (key == KSYM_Escape || key == KSYM_Return)
4914 key = KSYM_UNDEFINED; /* keep old value */
4916 got_key_event = TRUE;
4920 case EVENT_KEYRELEASE:
4921 key_joystick_mapping = 0;
4925 HandleOtherEvents(&event);
4933 /* don't eat all CPU time */
4940 static int getSetupTextFont(int type)
4942 if (type & (TYPE_SWITCH |
4953 static int getSetupValueFont(int type, void *value)
4955 if (type & TYPE_KEY)
4956 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4957 else if (type & TYPE_STRING)
4958 return FONT_VALUE_2;
4959 else if (type & TYPE_ECS_AGA)
4960 return FONT_VALUE_1;
4961 else if (type & TYPE_BOOLEAN_STYLE)
4962 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4964 return FONT_VALUE_1;
4967 static void drawSetupValue(int pos)
4969 boolean font_draw_xoffset_modified = FALSE;
4970 int font_draw_xoffset_old = -1;
4971 int xpos = MENU_SCREEN_VALUE_XPOS;
4972 int ypos = MENU_SCREEN_START_YPOS + pos;
4973 int startx = mSX + xpos * 32;
4974 int starty = mSY + ypos * 32;
4975 int font_nr, font_width;
4976 int type = setup_info[pos].type;
4977 void *value = setup_info[pos].value;
4978 char *value_string = getSetupValue(type, value);
4981 if (value_string == NULL)
4984 if (type & TYPE_KEY)
4986 xpos = MENU_SCREEN_START_XPOS;
4988 if (type & TYPE_QUERY)
4990 value_string = "<press key>";
4993 else if (type & TYPE_STRING)
4995 int max_value_len = (SCR_FIELDX - 2) * 2;
4997 xpos = MENU_SCREEN_START_XPOS;
4999 if (strlen(value_string) > max_value_len)
5000 value_string[max_value_len] = '\0';
5003 startx = mSX + xpos * 32;
5004 starty = mSY + ypos * 32;
5005 font_nr = getSetupValueFont(type, value);
5006 font_width = getFontWidth(font_nr);
5008 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5009 if (setup_mode != SETUP_MODE_INPUT)
5011 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5012 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5013 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5014 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5015 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5016 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5017 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5018 boolean correct_font_draw_xoffset = FALSE;
5020 if (xpos == MENU_SCREEN_START_XPOS &&
5021 startx + font1_xoffset < text_startx + text_font_xoffset)
5022 correct_font_draw_xoffset = TRUE;
5024 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5025 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5026 correct_font_draw_xoffset = TRUE;
5028 /* check if setup value would overlap with setup text when printed */
5029 /* (this can happen for extreme/wrong values for font draw offset) */
5030 if (correct_font_draw_xoffset)
5032 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5033 font_draw_xoffset_modified = TRUE;
5035 if (type & TYPE_KEY)
5036 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5037 else if (!(type & TYPE_STRING))
5038 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5039 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5043 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5044 DrawText(startx + i * font_width, starty, " ", font_nr);
5046 DrawText(startx, starty, value_string, font_nr);
5048 if (font_draw_xoffset_modified)
5049 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5052 static void changeSetupValue(int pos)
5054 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5056 *(boolean *)setup_info[pos].value ^= TRUE;
5058 else if (setup_info[pos].type & TYPE_KEY)
5062 setup_info[pos].type |= TYPE_QUERY;
5063 drawSetupValue(pos);
5064 setup_info[pos].type &= ~TYPE_QUERY;
5066 key = getSetupKey();
5067 if (key != KSYM_UNDEFINED)
5068 *(Key *)setup_info[pos].value = key;
5071 drawSetupValue(pos);
5074 static void DrawCursorAndText_Setup(int pos, boolean active)
5076 int xpos = MENU_SCREEN_START_XPOS;
5077 int ypos = MENU_SCREEN_START_YPOS + pos;
5078 int font_nr = getSetupTextFont(setup_info[pos].type);
5080 if (setup_info == setup_info_input)
5081 font_nr = FONT_MENU_1;
5084 font_nr = FONT_ACTIVE(font_nr);
5086 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5088 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5089 drawCursor(pos, active);
5092 static void DrawSetupScreen_Generic()
5094 char *title_string = NULL;
5098 CloseDoor(DOOR_CLOSE_2);
5101 FadeOut(REDRAW_FIELD);
5106 if (setup_mode == SETUP_MODE_MAIN)
5108 setup_info = setup_info_main;
5109 title_string = "Setup";
5111 else if (setup_mode == SETUP_MODE_GAME)
5113 setup_info = setup_info_game;
5114 title_string = "Setup Game";
5116 else if (setup_mode == SETUP_MODE_EDITOR)
5118 setup_info = setup_info_editor;
5119 title_string = "Setup Editor";
5121 else if (setup_mode == SETUP_MODE_GRAPHICS)
5123 setup_info = setup_info_graphics;
5124 title_string = "Setup Graphics";
5126 else if (setup_mode == SETUP_MODE_SOUND)
5128 setup_info = setup_info_sound;
5129 title_string = "Setup Sound";
5131 else if (setup_mode == SETUP_MODE_ARTWORK)
5133 setup_info = setup_info_artwork;
5134 title_string = "Custom Artwork";
5136 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5138 setup_info = setup_info_shortcuts_1;
5139 title_string = "Setup Shortcuts";
5141 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5143 setup_info = setup_info_shortcuts_2;
5144 title_string = "Setup Shortcuts";
5147 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5150 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5152 void *value_ptr = setup_info[i].value;
5155 int xpos = MENU_SCREEN_START_XPOS;
5156 int ypos = MENU_SCREEN_START_YPOS + i;
5160 /* set some entries to "unchangeable" according to other variables */
5161 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5162 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5163 (value_ptr == &setup.sound_music && !audio.music_available) ||
5164 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5165 (value_ptr == &screen_mode_text && !video.fullscreen_available))
5166 setup_info[i].type |= TYPE_GHOSTED;
5168 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5169 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5170 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5171 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5172 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5173 initCursor(i, IMG_MENU_BUTTON);
5176 DrawCursorAndText_Setup(i, FALSE);
5178 font_nr = getSetupTextFont(setup_info[i].type);
5180 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5183 if (setup_info[i].type & TYPE_VALUE)
5190 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5191 "Joysticks deactivated in setup menu");
5195 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5199 FadeIn(REDRAW_FIELD);
5204 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5208 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5210 static int choice_store[MAX_SETUP_MODES];
5211 int choice = choice_store[setup_mode]; /* always starts with 0 */
5215 if (button == MB_MENU_INITIALIZE)
5217 /* advance to first valid menu entry */
5218 while (choice < num_setup_info &&
5219 setup_info[choice].type & TYPE_SKIP_ENTRY)
5221 choice_store[setup_mode] = choice;
5224 DrawCursorAndText_Setup(choice, TRUE);
5226 drawCursor(choice, TRUE);
5231 else if (button == MB_MENU_LEAVE)
5233 PlaySound(SND_MENU_ITEM_SELECTING);
5235 for (y = 0; y < num_setup_info; y++)
5237 if (setup_info[y].type & TYPE_LEAVE_MENU)
5239 void (*menu_callback_function)(void) = setup_info[y].value;
5243 menu_callback_function();
5245 break; /* absolutely needed because function changes 'setup_info'! */
5252 if (mx || my) /* mouse input */
5254 x = (mx - mSX) / 32;
5255 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5257 else if (dx || dy) /* keyboard input */
5261 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5263 if (setup_info[choice].type & menu_navigation_type ||
5264 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5265 button = MB_MENU_CHOICE;
5270 /* jump to next non-empty menu entry (up or down) */
5271 while (y > 0 && y < num_setup_info - 1 &&
5272 setup_info[y].type & TYPE_SKIP_ENTRY)
5276 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5280 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5282 PlaySound(SND_MENU_ITEM_ACTIVATING);
5285 DrawCursorAndText_Setup(choice, FALSE);
5286 DrawCursorAndText_Setup(y, TRUE);
5288 drawCursor(choice, FALSE);
5289 drawCursor(y, TRUE);
5292 choice = choice_store[setup_mode] = y;
5295 else if (!(setup_info[y].type & TYPE_GHOSTED))
5297 PlaySound(SND_MENU_ITEM_SELECTING);
5299 /* when selecting key headline, execute function for key value change */
5300 if (setup_info[y].type & TYPE_KEYTEXT &&
5301 setup_info[y + 1].type & TYPE_KEY)
5304 /* when selecting string value, execute function for list selection */
5305 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5306 setup_info[y - 1].type & TYPE_ENTER_LIST)
5309 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5311 void (*menu_callback_function)(void) = setup_info[y].value;
5313 FadeSetFromType(setup_info[y].type);
5315 menu_callback_function();
5319 if (setup_info[y].type & TYPE_VALUE)
5320 changeSetupValue(y);
5326 void DrawSetupScreen_Input()
5333 FadeOut(REDRAW_FIELD);
5339 setup_info = setup_info_input;
5342 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5345 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5347 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5348 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5349 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5350 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5351 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5352 initCursor(i, IMG_MENU_BUTTON);
5354 DrawCursorAndText_Setup(i, FALSE);
5357 initCursor(0, IMG_MENU_BUTTON);
5358 initCursor(1, IMG_MENU_BUTTON);
5359 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
5360 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5362 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
5363 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
5364 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
5368 DeactivateJoystickForCalibration();
5371 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5372 "Joysticks deactivated on this screen");
5375 /* create gadgets for setup input menu screen */
5376 FreeScreenGadgets();
5377 CreateScreenGadgets();
5379 /* map gadgets for setup input menu screen */
5380 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5382 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5385 FadeIn(REDRAW_FIELD);
5391 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5393 if (device_name == NULL)
5396 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5399 if (strlen(device_name) > 1)
5401 char c1 = device_name[strlen(device_name) - 1];
5402 char c2 = device_name[strlen(device_name) - 2];
5404 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5405 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5408 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5409 strlen(device_name));
5412 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5415 static struct SetupKeyboardInfo custom_key;
5422 { &custom_key.left, "Joystick Left" },
5423 { &custom_key.right, "Joystick Right" },
5424 { &custom_key.up, "Joystick Up" },
5425 { &custom_key.down, "Joystick Down" },
5426 { &custom_key.snap, "Button 1" },
5427 { &custom_key.drop, "Button 2" }
5429 static char *joystick_name[MAX_PLAYERS] =
5436 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5440 custom_key = setup.input[player_nr].key;
5442 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5443 FONT_INPUT_1_ACTIVE);
5445 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5447 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5448 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5450 if (setup.input[player_nr].use_joystick)
5452 char *device_name = setup.input[player_nr].joy.device_name;
5453 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5454 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5456 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5457 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5461 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5462 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5465 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5467 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5468 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5469 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5470 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5472 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5473 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5474 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5475 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5476 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5477 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5479 for (i = 0; i < 6; i++)
5481 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5483 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5485 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5486 (setup.input[player_nr].use_joystick ?
5488 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5492 static int input_player_nr = 0;
5494 void HandleSetupScreen_Input_Player(int step, int direction)
5496 int old_player_nr = input_player_nr;
5499 new_player_nr = old_player_nr + step * direction;
5500 if (new_player_nr < 0)
5502 if (new_player_nr > MAX_PLAYERS - 1)
5503 new_player_nr = MAX_PLAYERS - 1;
5505 if (new_player_nr != old_player_nr)
5507 input_player_nr = new_player_nr;
5509 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5513 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5515 static int choice = 0;
5518 int pos_start = SETUPINPUT_SCREEN_POS_START;
5519 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5520 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5521 int pos_end = SETUPINPUT_SCREEN_POS_END;
5523 if (button == MB_MENU_INITIALIZE)
5525 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5528 DrawCursorAndText_Setup(choice, TRUE);
5530 drawCursor(choice, TRUE);
5535 else if (button == MB_MENU_LEAVE)
5537 setup_mode = SETUP_MODE_MAIN;
5544 if (mx || my) /* mouse input */
5546 x = (mx - mSX) / 32;
5547 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5549 else if (dx || dy) /* keyboard input */
5551 if (dx && choice == 0)
5552 x = (dx < 0 ? 10 : 12);
5553 else if ((dx && choice == 1) ||
5554 (dx == +1 && choice == 2) ||
5555 (dx == -1 && choice == pos_end))
5556 button = MB_MENU_CHOICE;
5560 if (y >= pos_empty1 && y <= pos_empty2)
5561 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5564 if (y == 0 && dx != 0 && button)
5566 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5568 else if (IN_VIS_FIELD(x, y) &&
5569 y >= pos_start && y <= pos_end &&
5570 !(y >= pos_empty1 && y <= pos_empty2))
5577 DrawCursorAndText_Setup(choice, FALSE);
5578 DrawCursorAndText_Setup(y, TRUE);
5580 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5582 drawCursor(choice, FALSE);
5583 drawCursor(y, TRUE);
5593 char *device_name = setup.input[input_player_nr].joy.device_name;
5595 if (!setup.input[input_player_nr].use_joystick)
5597 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5599 setJoystickDeviceToNr(device_name, new_device_nr);
5600 setup.input[input_player_nr].use_joystick = TRUE;
5604 int device_nr = getJoystickNrFromDeviceName(device_name);
5605 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5607 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5608 setup.input[input_player_nr].use_joystick = FALSE;
5610 setJoystickDeviceToNr(device_name, new_device_nr);
5613 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5617 if (setup.input[input_player_nr].use_joystick)
5620 CalibrateJoystick(input_player_nr);
5623 CustomizeKeyboard(input_player_nr);
5625 else if (y == pos_end)
5631 setup_mode = SETUP_MODE_MAIN;
5638 void CustomizeKeyboard(int player_nr)
5642 boolean finished = FALSE;
5643 static struct SetupKeyboardInfo custom_key;
5648 } customize_step[] =
5650 { &custom_key.left, "Move Left" },
5651 { &custom_key.right, "Move Right" },
5652 { &custom_key.up, "Move Up" },
5653 { &custom_key.down, "Move Down" },
5654 { &custom_key.snap, "Snap Field" },
5655 { &custom_key.drop, "Drop Element" }
5658 /* read existing key bindings from player setup */
5659 custom_key = setup.input[player_nr].key;
5662 FadeOut(REDRAW_FIELD);
5666 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5674 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5675 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5676 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5677 "Key:", FONT_INPUT_1_ACTIVE);
5678 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5679 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5682 FadeIn(REDRAW_FIELD);
5689 if (PendingEvent()) /* got event */
5697 case EVENT_KEYPRESS:
5699 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5701 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5703 if (key == KSYM_Escape)
5704 FadeSkipNextFadeIn();
5710 /* all keys configured -- wait for "Escape" or "Return" key */
5714 /* press 'Enter' to keep the existing key binding */
5715 if (key == KSYM_Return)
5716 key = *customize_step[step_nr].key;
5718 /* check if key already used */
5719 for (i = 0; i < step_nr; i++)
5720 if (*customize_step[i].key == key)
5725 /* got new key binding */
5726 *customize_step[step_nr].key = key;
5727 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5729 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5730 getKeyNameFromKey(key), FONT_VALUE_1);
5733 /* un-highlight last query */
5734 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5735 customize_step[step_nr - 1].text, FONT_MENU_1);
5736 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5737 "Key:", FONT_MENU_1);
5739 /* press 'Enter' to leave */
5742 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5743 "Press Enter", FONT_TITLE_1);
5747 /* query next key binding */
5748 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5749 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5750 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5751 "Key:", FONT_INPUT_1_ACTIVE);
5752 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5753 getKeyNameFromKey(*customize_step[step_nr].key),
5758 case EVENT_KEYRELEASE:
5759 key_joystick_mapping = 0;
5763 HandleOtherEvents(&event);
5771 /* don't eat all CPU time */
5775 /* write new key bindings back to player setup */
5776 setup.input[player_nr].key = custom_key;
5779 DrawSetupScreen_Input();
5782 static boolean CalibrateJoystickMain(int player_nr)
5784 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5785 int new_joystick_xright = JOYSTICK_XMIDDLE;
5786 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5787 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5788 int new_joystick_xmiddle, new_joystick_ymiddle;
5790 int joystick_fd = joystick.fd[player_nr];
5791 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5792 boolean check[3][3];
5793 int check_remaining = 3 * 3;
5798 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5801 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5805 FadeOut(REDRAW_FIELD);
5809 for (y = 0; y < 3; y++)
5811 for (x = 0; x < 3; x++)
5813 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5814 check[x][y] = FALSE;
5818 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5819 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5820 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5821 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5822 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5823 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5824 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5826 joy_value = Joystick(player_nr);
5827 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5828 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5830 /* eventually uncalibrated center position (joystick could be uncentered) */
5831 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5834 new_joystick_xmiddle = joy_x;
5835 new_joystick_ymiddle = joy_y;
5837 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5840 FadeIn(REDRAW_FIELD);
5845 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5850 if (PendingEvent()) /* got event */
5858 case EVENT_KEYPRESS:
5859 switch (GetEventKey((KeyEvent *)&event, TRUE))
5862 if (check_remaining == 0)
5867 FadeSkipNextFadeIn();
5876 case EVENT_KEYRELEASE:
5877 key_joystick_mapping = 0;
5881 HandleOtherEvents(&event);
5886 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5889 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5890 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5891 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5892 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5894 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5895 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5896 setup.input[player_nr].joy.xright = new_joystick_xright;
5897 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5898 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5899 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5901 CheckJoystickData();
5903 joy_value = Joystick(player_nr);
5905 if (joy_value & JOY_BUTTON && check_remaining == 0)
5908 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5909 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5911 if (x != last_x || y != last_y)
5913 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5914 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5919 if (check_remaining > 0 && !check[x+1][y+1])
5921 check[x+1][y+1] = TRUE;
5927 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5928 setup.input[player_nr].joy.xleft,
5929 setup.input[player_nr].joy.xmiddle,
5930 setup.input[player_nr].joy.xright);
5931 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5932 setup.input[player_nr].joy.yupper,
5933 setup.input[player_nr].joy.ymiddle,
5934 setup.input[player_nr].joy.ylower);
5943 /* don't eat all CPU time */
5947 /* calibrated center position (joystick should now be centered) */
5948 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5951 new_joystick_xmiddle = joy_x;
5952 new_joystick_ymiddle = joy_y;
5957 DrawSetupScreen_Input();
5960 /* wait until the last pressed button was released */
5961 while (Joystick(player_nr) & JOY_BUTTON)
5963 if (PendingEvent()) /* got event */
5968 HandleOtherEvents(&event);
5977 void CalibrateJoystick(int player_nr)
5979 if (!CalibrateJoystickMain(player_nr))
5981 char *device_name = setup.input[player_nr].joy.device_name;
5982 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5983 int xpos = mSX - SX;
5984 int ypos = mSY - SY;
5988 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5989 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5992 Delay(2000); /* show error message for a short time */
5998 DrawSetupScreen_Input();
6002 void DrawSetupScreen()
6004 DeactivateJoystick();
6006 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6008 if (setup_mode == SETUP_MODE_INPUT)
6009 DrawSetupScreen_Input();
6010 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6011 DrawChooseTree(&game_speed_current);
6012 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6013 DrawChooseTree(&screen_mode_current);
6014 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6015 DrawChooseTree(&scroll_delay_current);
6016 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6017 DrawChooseTree(&artwork.gfx_current);
6018 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6019 DrawChooseTree(&artwork.snd_current);
6020 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6021 DrawChooseTree(&artwork.mus_current);
6023 DrawSetupScreen_Generic();
6029 void RedrawSetupScreenAfterFullscreenToggle()
6031 if (setup_mode == SETUP_MODE_GRAPHICS)
6035 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6037 if (setup_mode == SETUP_MODE_INPUT)
6038 HandleSetupScreen_Input(mx, my, dx, dy, button);
6039 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6040 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6041 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6042 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6043 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6044 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6045 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6046 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6047 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6048 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6049 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6050 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6052 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6057 void HandleGameActions()
6059 if (game_status != GAME_MODE_PLAYING)
6062 GameActions(); /* main game loop */
6064 if (tape.auto_play && !tape.playing)
6065 AutoPlayTape(); /* continue automatically playing next tape */
6069 void ChangeGameStatus(int new_game_status)
6071 /* for fading out last screen, use the last game status */
6072 global.border_status = game_status;
6073 global.fading_status = game_status;
6077 /* for fading in next screen, use the new game status */
6078 global.border_status = new_game_status;
6079 global.fading_status = new_game_status;
6084 /* ---------- new screen button stuff -------------------------------------- */
6086 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6091 case SCREEN_CTRL_ID_PREV_LEVEL:
6092 *x = mSX + menu.main.button.prev_level.x;
6093 *y = mSY + menu.main.button.prev_level.y;
6096 case SCREEN_CTRL_ID_NEXT_LEVEL:
6097 *x = mSX + menu.main.button.next_level.x;
6098 *y = mSY + menu.main.button.next_level.y;
6101 case SCREEN_CTRL_ID_PREV_LEVEL:
6102 *x = mSX + TILEX * getPrevlevelButtonPos();
6103 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6106 case SCREEN_CTRL_ID_NEXT_LEVEL:
6107 *x = mSX + TILEX * getNextLevelButtonPos();
6108 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6112 case SCREEN_CTRL_ID_PREV_PLAYER:
6113 *x = mSX + TILEX * 10;
6114 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6117 case SCREEN_CTRL_ID_NEXT_PLAYER:
6118 *x = mSX + TILEX * 12;
6119 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6123 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6129 int gfx_unpressed, gfx_pressed;
6130 void (*get_gadget_position)(int *, int *, int);
6134 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6137 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6138 getScreenMenuButtonPos,
6139 SCREEN_CTRL_ID_PREV_LEVEL,
6144 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6145 getScreenMenuButtonPos,
6146 SCREEN_CTRL_ID_NEXT_LEVEL,
6151 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6152 getScreenMenuButtonPos,
6153 SCREEN_CTRL_ID_PREV_PLAYER,
6158 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6159 getScreenMenuButtonPos,
6160 SCREEN_CTRL_ID_NEXT_PLAYER,
6168 int gfx_unpressed, gfx_pressed;
6172 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6175 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6176 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6177 SCREEN_CTRL_ID_SCROLL_UP,
6181 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6182 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6183 SCREEN_CTRL_ID_SCROLL_DOWN,
6190 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6191 Bitmap **gfx_unpressed, **gfx_pressed;
6193 int gfx_unpressed, gfx_pressed;
6200 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6203 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6204 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6206 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6208 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6209 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6210 GD_TYPE_SCROLLBAR_VERTICAL,
6211 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6212 "scroll level series vertically"
6216 static void CreateScreenMenubuttons()
6218 struct GadgetInfo *gi;
6219 unsigned long event_mask;
6222 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6224 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6225 int gfx_unpressed, gfx_pressed;
6226 int x, y, width, height;
6227 int gd_x1, gd_x2, gd_y1, gd_y2;
6228 int id = menubutton_info[i].gadget_id;
6230 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6232 menubutton_info[i].get_gadget_position(&x, &y, id);
6234 width = SC_MENUBUTTON_XSIZE;
6235 height = SC_MENUBUTTON_YSIZE;
6237 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6238 gfx_pressed = menubutton_info[i].gfx_pressed;
6239 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6240 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6241 gd_x1 = graphic_info[gfx_unpressed].src_x;
6242 gd_y1 = graphic_info[gfx_unpressed].src_y;
6243 gd_x2 = graphic_info[gfx_pressed].src_x;
6244 gd_y2 = graphic_info[gfx_pressed].src_y;
6246 gi = CreateGadget(GDI_CUSTOM_ID, id,
6247 GDI_CUSTOM_TYPE_ID, i,
6248 GDI_INFO_TEXT, menubutton_info[i].infotext,
6253 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6254 GDI_STATE, GD_BUTTON_UNPRESSED,
6255 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6256 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6257 GDI_DIRECT_DRAW, FALSE,
6258 GDI_EVENT_MASK, event_mask,
6259 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6263 Error(ERR_EXIT, "cannot create gadget");
6265 screen_gadget[id] = gi;
6269 static void CreateScreenScrollbuttons()
6271 struct GadgetInfo *gi;
6272 unsigned long event_mask;
6275 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6277 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6278 int gfx_unpressed, gfx_pressed;
6279 int x, y, width, height;
6280 int gd_x1, gd_x2, gd_y1, gd_y2;
6281 int id = scrollbutton_info[i].gadget_id;
6283 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6285 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6286 y = mSY + scrollbutton_info[i].y;
6287 width = SC_SCROLLBUTTON_XSIZE;
6288 height = SC_SCROLLBUTTON_YSIZE;
6290 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6291 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6292 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6294 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6295 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6296 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6297 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6298 gd_x1 = graphic_info[gfx_unpressed].src_x;
6299 gd_y1 = graphic_info[gfx_unpressed].src_y;
6300 gd_x2 = graphic_info[gfx_pressed].src_x;
6301 gd_y2 = graphic_info[gfx_pressed].src_y;
6303 gi = CreateGadget(GDI_CUSTOM_ID, id,
6304 GDI_CUSTOM_TYPE_ID, i,
6305 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6310 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6311 GDI_STATE, GD_BUTTON_UNPRESSED,
6312 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6313 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6314 GDI_DIRECT_DRAW, FALSE,
6315 GDI_EVENT_MASK, event_mask,
6316 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6320 Error(ERR_EXIT, "cannot create gadget");
6322 screen_gadget[id] = gi;
6326 static void CreateScreenScrollbars()
6330 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6332 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6333 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6334 int gfx_unpressed, gfx_pressed;
6336 int x, y, width, height;
6337 int gd_x1, gd_x2, gd_y1, gd_y2;
6338 struct GadgetInfo *gi;
6339 int items_max, items_visible, item_position;
6340 unsigned long event_mask;
6341 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6342 int id = scrollbar_info[i].gadget_id;
6344 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6346 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6347 y = mSY + scrollbar_info[i].y;
6348 width = scrollbar_info[i].width;
6349 height = scrollbar_info[i].height;
6351 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6352 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6354 items_max = num_page_entries;
6355 items_visible = num_page_entries;
6358 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6359 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6360 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6366 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6367 gfx_pressed = scrollbar_info[i].gfx_pressed;
6368 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6369 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6370 gd_x1 = graphic_info[gfx_unpressed].src_x;
6371 gd_y1 = graphic_info[gfx_unpressed].src_y;
6372 gd_x2 = graphic_info[gfx_pressed].src_x;
6373 gd_y2 = graphic_info[gfx_pressed].src_y;
6376 gi = CreateGadget(GDI_CUSTOM_ID, id,
6377 GDI_CUSTOM_TYPE_ID, i,
6378 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6383 GDI_TYPE, scrollbar_info[i].type,
6384 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6385 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6386 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6388 GDI_WHEEL_AREA_X, SX,
6389 GDI_WHEEL_AREA_Y, SY,
6390 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6391 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6393 GDI_WHEEL_AREA_X, 0,
6394 GDI_WHEEL_AREA_Y, 0,
6395 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6396 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6398 GDI_STATE, GD_BUTTON_UNPRESSED,
6399 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6400 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6401 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6402 GDI_DIRECT_DRAW, FALSE,
6403 GDI_EVENT_MASK, event_mask,
6404 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6408 Error(ERR_EXIT, "cannot create gadget");
6410 screen_gadget[id] = gi;
6414 void CreateScreenGadgets()
6416 int last_game_status = game_status; /* save current game status */
6418 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6421 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6423 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6425 /* copy pointers to clip mask and GC */
6426 scrollbar_bitmap[i]->clip_mask =
6427 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6428 scrollbar_bitmap[i]->stored_clip_gc =
6429 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6431 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6432 scrollbar_bitmap[i],
6433 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6434 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6435 TILEX, TILEY, 0, 0);
6439 CreateScreenMenubuttons();
6442 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6443 game_status = GAME_MODE_LEVELS;
6446 CreateScreenScrollbuttons();
6447 CreateScreenScrollbars();
6449 game_status = last_game_status; /* restore current game status */
6452 void FreeScreenGadgets()
6456 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6457 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6459 /* prevent freeing clip mask and GC twice */
6460 scrollbar_bitmap[i]->clip_mask = None;
6461 scrollbar_bitmap[i]->stored_clip_gc = None;
6463 FreeBitmap(scrollbar_bitmap[i]);
6467 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6468 FreeGadget(screen_gadget[i]);
6471 void MapScreenMenuGadgets(int screen_mask)
6475 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6476 if (screen_mask & menubutton_info[i].screen_mask)
6477 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6480 void MapScreenTreeGadgets(TreeInfo *ti)
6482 int num_entries = numTreeInfoInGroup(ti);
6485 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6488 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6489 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6491 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6492 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6495 static void HandleScreenGadgets(struct GadgetInfo *gi)
6497 int id = gi->custom_id;
6498 int button = gi->event.button;
6499 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6503 case SCREEN_CTRL_ID_PREV_LEVEL:
6504 HandleMainMenu_SelectLevel(step, -1);
6507 case SCREEN_CTRL_ID_NEXT_LEVEL:
6508 HandleMainMenu_SelectLevel(step, +1);
6511 case SCREEN_CTRL_ID_PREV_PLAYER:
6512 HandleSetupScreen_Input_Player(step, -1);
6515 case SCREEN_CTRL_ID_NEXT_PLAYER:
6516 HandleSetupScreen_Input_Player(step, +1);
6519 case SCREEN_CTRL_ID_SCROLL_UP:
6520 if (game_status == GAME_MODE_LEVELS)
6521 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6522 else if (game_status == GAME_MODE_SETUP)
6523 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6526 case SCREEN_CTRL_ID_SCROLL_DOWN:
6527 if (game_status == GAME_MODE_LEVELS)
6528 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6529 else if (game_status == GAME_MODE_SETUP)
6530 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6533 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6534 if (game_status == GAME_MODE_LEVELS)
6535 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6536 else if (game_status == GAME_MODE_SETUP)
6537 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);