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 /* forward declarations of internal functions */
130 static void HandleScreenGadgets(struct GadgetInfo *);
131 static void HandleSetupScreen_Generic(int, int, int, int, int);
132 static void HandleSetupScreen_Input(int, int, int, int, int);
133 static void CustomizeKeyboard(int);
134 static void CalibrateJoystick(int);
135 static void execSetupGame(void);
136 static void execSetupGraphics(void);
137 static void execSetupArtwork(void);
138 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
140 static void DrawChooseLevel(void);
141 static void DrawInfoScreen(void);
142 static void DrawAndFadeInInfoScreen(int);
143 static void DrawSetupScreen(void);
145 static void DrawInfoScreenExt(int, int);
146 static void DrawInfoScreen_NotAvailable(char *, char *);
147 static void DrawInfoScreen_HelpAnim(int, int, boolean);
148 static void DrawInfoScreen_HelpText(int, int, int, int);
149 static void HandleInfoScreen_Main(int, int, int, int, int);
150 static void HandleInfoScreen_TitleScreen(int);
151 static void HandleInfoScreen_Elements(int);
152 static void HandleInfoScreen_Music(int);
153 static void HandleInfoScreen_Credits(int);
154 static void HandleInfoScreen_Program(int);
155 static void HandleInfoScreen_Version(int);
157 static void MapScreenMenuGadgets(int);
158 static void MapScreenTreeGadgets(TreeInfo *);
160 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
162 static int info_mode = INFO_MODE_MAIN;
163 static int setup_mode = SETUP_MODE_MAIN;
165 static TreeInfo *screen_modes = NULL;
166 static TreeInfo *screen_mode_current = NULL;
168 static TreeInfo *scroll_delays = NULL;
169 static TreeInfo *scroll_delay_current = NULL;
171 static TreeInfo *game_speeds = NULL;
172 static TreeInfo *game_speed_current = NULL;
178 } game_speeds_list[] =
187 { 1000, "1/1s (Extremely Slow)" },
192 { 29, "1/35s (Original Supaplex)" },
194 { 20, "1/50s (Normal Speed)" },
195 { 14, "1/70s (Maximum Supaplex)" },
199 { 1, "1/1000s (Extremely Fast)" },
209 } scroll_delays_list[] =
211 { 0, "0 Tiles (No Scroll Delay)" },
214 { 3, "3 Tiles (Default)" },
219 { 8, "8 Tiles (Maximum Scroll Delay)"},
224 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
225 (s) <= GAME_MODE_SETUP ? (s) : \
226 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
227 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
229 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
230 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
231 (i) <= INFO_MODE_LEVELSET ? (i) : \
234 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
235 (i) <= SETUP_MODE_SHORTCUTS_2 ? (i) : \
236 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
237 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
238 SETUP_MODE_CHOOSE_ARTWORK : \
239 SETUP_MODE_CHOOSE_OTHER)
241 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
242 menu.draw_xoffset[GAME_MODE_INFO] : \
243 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
244 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
245 menu.draw_yoffset[GAME_MODE_INFO] : \
246 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
248 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
249 menu.draw_xoffset[GAME_MODE_SETUP] : \
250 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
251 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
252 menu.draw_yoffset[GAME_MODE_SETUP] : \
253 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
255 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
256 DRAW_XOFFSET_INFO(info_mode) : \
257 (s) == GAME_MODE_SETUP ? \
258 DRAW_XOFFSET_SETUP(setup_mode) : \
259 menu.draw_xoffset[DRAW_MODE(s)])
260 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
261 DRAW_YOFFSET_INFO(info_mode) : \
262 (s) == GAME_MODE_SETUP ? \
263 DRAW_YOFFSET_SETUP(setup_mode) : \
264 menu.draw_yoffset[DRAW_MODE(s)])
266 #define mSX (SX + DRAW_XOFFSET(game_status))
267 #define mSY (SY + DRAW_YOFFSET(game_status))
269 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
270 menu.list_size[game_status] : \
271 MAX_MENU_ENTRIES_ON_SCREEN)
273 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
274 #define NUM_SCROLLBAR_BITMAPS 2
275 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
279 /* title display and control definitions */
281 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
282 2 * MAX_NUM_TITLE_MESSAGES)
284 static int num_title_screens = 0;
286 struct TitleControlInfo
294 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
296 /* main menu display and control definitions */
298 #define MAIN_CONTROL_NAME 0
299 #define MAIN_CONTROL_LEVELS 1
300 #define MAIN_CONTROL_SCORES 2
301 #define MAIN_CONTROL_EDITOR 3
302 #define MAIN_CONTROL_INFO 4
303 #define MAIN_CONTROL_GAME 5
304 #define MAIN_CONTROL_SETUP 6
305 #define MAIN_CONTROL_QUIT 7
306 #define MAIN_CONTROL_PREV_LEVEL 8
307 #define MAIN_CONTROL_NEXT_LEVEL 9
308 #define MAIN_CONTROL_FIRST_LEVEL 10
309 #define MAIN_CONTROL_LAST_LEVEL 11
310 #define MAIN_CONTROL_LEVEL_NUMBER 12
311 #define MAIN_CONTROL_LEVEL_INFO_1 13
312 #define MAIN_CONTROL_LEVEL_INFO_2 14
313 #define MAIN_CONTROL_LEVEL_NAME 15
314 #define MAIN_CONTROL_LEVEL_AUTHOR 16
315 #define MAIN_CONTROL_LEVEL_YEAR 17
316 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
317 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
318 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
319 #define MAIN_CONTROL_TITLE_1 21
320 #define MAIN_CONTROL_TITLE_2 22
321 #define MAIN_CONTROL_TITLE_3 23
323 static char str_main_text_name[10];
324 static char str_main_text_first_level[10];
325 static char str_main_text_last_level[10];
326 static char str_main_text_level_number[10];
328 static char *main_text_name = str_main_text_name;
329 static char *main_text_first_level = str_main_text_first_level;
330 static char *main_text_last_level = str_main_text_last_level;
331 static char *main_text_level_number = str_main_text_level_number;
332 static char *main_text_levels = "Levelset";
333 static char *main_text_scores = "Hall Of Fame";
334 static char *main_text_editor = "Level Creator";
335 static char *main_text_info = "Info Screen";
336 static char *main_text_game = "Start Game";
337 static char *main_text_setup = "Setup";
338 static char *main_text_quit = "Quit";
339 static char *main_text_level_name = level.name;
340 static char *main_text_level_author = level.author;
341 static char *main_text_level_year = NULL;
342 static char *main_text_level_imported_from = NULL;
343 static char *main_text_level_imported_by = NULL;
344 static char *main_text_level_tested_by = NULL;
345 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
346 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
347 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
349 struct MainControlInfo
353 struct MenuPosInfo *pos_button;
356 struct TextPosInfo *pos_text;
359 struct TextPosInfo *pos_input;
363 static struct MainControlInfo main_controls[] =
367 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
368 &menu.main.text.name, &main_text_name,
369 &menu.main.input.name, &setup.player_name,
373 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
374 &menu.main.text.levels, &main_text_levels,
379 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
380 &menu.main.text.scores, &main_text_scores,
385 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
386 &menu.main.text.editor, &main_text_editor,
391 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
392 &menu.main.text.info, &main_text_info,
397 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
398 &menu.main.text.game, &main_text_game,
403 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
404 &menu.main.text.setup, &main_text_setup,
409 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
410 &menu.main.text.quit, &main_text_quit,
414 /* (these two buttons are real gadgets) */
416 MAIN_CONTROL_PREV_LEVEL,
417 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
422 MAIN_CONTROL_NEXT_LEVEL,
423 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
429 MAIN_CONTROL_FIRST_LEVEL,
431 &menu.main.text.first_level, &main_text_first_level,
435 MAIN_CONTROL_LAST_LEVEL,
437 &menu.main.text.last_level, &main_text_last_level,
441 MAIN_CONTROL_LEVEL_NUMBER,
443 &menu.main.text.level_number, &main_text_level_number,
447 MAIN_CONTROL_LEVEL_INFO_1,
449 &menu.main.text.level_info_1, NULL,
453 MAIN_CONTROL_LEVEL_INFO_2,
455 &menu.main.text.level_info_2, NULL,
459 MAIN_CONTROL_LEVEL_NAME,
461 &menu.main.text.level_name, &main_text_level_name,
465 MAIN_CONTROL_LEVEL_AUTHOR,
467 &menu.main.text.level_author, &main_text_level_author,
471 MAIN_CONTROL_LEVEL_YEAR,
473 &menu.main.text.level_year, &main_text_level_year,
477 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
479 &menu.main.text.level_imported_from, &main_text_level_imported_from,
483 MAIN_CONTROL_LEVEL_IMPORTED_BY,
485 &menu.main.text.level_imported_by, &main_text_level_imported_by,
489 MAIN_CONTROL_LEVEL_TESTED_BY,
491 &menu.main.text.level_tested_by, &main_text_level_tested_by,
495 MAIN_CONTROL_TITLE_1,
497 &menu.main.text.title_1, &main_text_title_1,
501 MAIN_CONTROL_TITLE_2,
503 &menu.main.text.title_2, &main_text_title_2,
507 MAIN_CONTROL_TITLE_3,
509 &menu.main.text.title_3, &main_text_title_3,
522 static int getTitleScreenGraphic(int nr, boolean initial)
524 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
527 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
529 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
533 static int getTitleScreenGameMode(boolean initial)
535 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
539 static int getTitleMessageGameMode(boolean initial)
541 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
545 static int getTitleScreenBackground(boolean initial)
547 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
552 static int getTitleMessageBackground(int nr, boolean initial)
554 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
558 static int getTitleBackground(int nr, boolean initial, boolean is_image)
560 int base = (is_image ?
561 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
562 IMG_BACKGROUND_TITLESCREEN_1) :
563 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
564 IMG_BACKGROUND_TITLEMESSAGE_1));
565 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
566 IMG_BACKGROUND_TITLE);
567 int graphic_local = base + nr;
569 if (graphic_info[graphic_local].bitmap != NULL)
570 return graphic_local;
572 if (graphic_info[graphic_global].bitmap != NULL)
573 return graphic_global;
575 return IMG_UNDEFINED;
578 static int getTitleSound(struct TitleControlInfo *tci)
580 boolean is_image = tci->is_image;
581 int initial = tci->initial;
582 int nr = tci->local_nr;
583 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
584 int base = (is_image ?
585 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
586 SND_BACKGROUND_TITLESCREEN_1) :
587 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
588 SND_BACKGROUND_TITLEMESSAGE_1));
589 int sound_global = menu.sound[mode];
590 int sound_local = base + nr;
593 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
594 nr, initial, is_image,
595 sound_global, getSoundListEntry(sound_global)->filename,
596 sound_local, getSoundListEntry(sound_local)->filename);
599 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
602 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
605 return SND_UNDEFINED;
608 static int getTitleMusic(struct TitleControlInfo *tci)
610 boolean is_image = tci->is_image;
611 int initial = tci->initial;
612 int nr = tci->local_nr;
613 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
614 int base = (is_image ?
615 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
616 MUS_BACKGROUND_TITLESCREEN_1) :
617 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
618 MUS_BACKGROUND_TITLEMESSAGE_1));
619 int music_global = menu.music[mode];
620 int music_local = base + nr;
623 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
624 nr, initial, is_image,
625 music_global, getMusicListEntry(music_global)->filename,
626 music_local, getMusicListEntry(music_local)->filename);
629 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
632 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
635 return MUS_UNDEFINED;
638 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
640 boolean is_image = tci->is_image;
641 int initial = tci->initial;
642 int nr = tci->local_nr;
643 struct TitleFadingInfo ti;
647 int graphic = getTitleScreenGraphic(nr, initial);
649 /* initialize fading control values to default title config settings */
650 ti = (initial ? title_initial_default : title_default);
652 /* override default settings with image config settings, if defined */
653 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
654 ti.fade_mode = graphic_info[graphic].fade_mode;
655 if (graphic_info[graphic].fade_delay > -1)
656 ti.fade_delay = graphic_info[graphic].fade_delay;
657 if (graphic_info[graphic].post_delay > -1)
658 ti.post_delay = graphic_info[graphic].post_delay;
659 if (graphic_info[graphic].auto_delay > -1)
660 ti.auto_delay = graphic_info[graphic].auto_delay;
666 ti.fade_mode = titlemessage_initial[nr].fade_mode;
667 ti.fade_delay = titlemessage_initial[nr].fade_delay;
668 ti.post_delay = titlemessage_initial[nr].post_delay;
669 ti.auto_delay = titlemessage_initial[nr].auto_delay;
673 ti.fade_mode = titlemessage[nr].fade_mode;
674 ti.fade_delay = titlemessage[nr].fade_delay;
675 ti.post_delay = titlemessage[nr].post_delay;
676 ti.auto_delay = titlemessage[nr].auto_delay;
681 if (ti.anim_mode == ANIM_NONE)
682 ti.fade_delay = ti.post_delay = 0;
688 static int compareTitleControlInfo(const void *object1, const void *object2)
690 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
691 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
694 if (tci1->initial != tci2->initial)
695 compare_result = (tci1->initial ? -1 : +1);
696 else if (tci1->sort_priority != tci2->sort_priority)
697 compare_result = tci1->sort_priority - tci2->sort_priority;
698 else if (tci1->is_image != tci2->is_image)
699 compare_result = (tci1->is_image ? -1 : +1);
701 compare_result = tci1->local_nr - tci2->local_nr;
703 return compare_result;
706 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
708 int nr, int sort_priority)
710 title_controls[num_title_screens].is_image = is_image;
711 title_controls[num_title_screens].initial = initial;
712 title_controls[num_title_screens].local_nr = nr;
713 title_controls[num_title_screens].sort_priority = sort_priority;
718 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
722 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
724 int graphic = getTitleScreenGraphic(i, initial);
725 Bitmap *bitmap = graphic_info[graphic].bitmap;
726 int sort_priority = graphic_info[graphic].sort_priority;
729 /* skip images and messages (fonts!) when using forced custom graphics */
730 if (setup.override_level_graphics && !initial)
735 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
738 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
740 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
741 char *filename = getLevelSetTitleMessageFilename(i, initial);
742 int sort_priority = tmi->sort_priority;
745 /* skip images and messages (fonts!) when using forced custom graphics */
746 if (setup.override_level_graphics)
750 if (filename != NULL)
751 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
755 static void InitializeTitleControls(boolean show_title_initial)
757 num_title_screens = 0;
760 if (show_title_initial)
761 InitializeTitleControls_CheckTitleInfo(TRUE);
764 InitializeTitleControls_CheckTitleInfo(FALSE);
766 /* sort title screens according to sort_priority and title number */
767 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
768 compareTitleControlInfo);
771 static boolean visibleMenuPos(struct MenuPosInfo *pos)
773 return (pos != NULL && pos->x != -1 && pos->y != -1);
776 static boolean visibleTextPos(struct TextPosInfo *pos)
778 return (pos != NULL && pos->x != -1 && pos->y != -1);
781 static void InitializeMainControls()
783 boolean local_team_mode = (!options.network && setup.team_mode);
786 /* set main control text values to dynamically determined values */
787 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
789 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
790 menu.main.text.first_level.size));
791 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
792 menu.main.text.last_level.size));
793 strcpy(main_text_level_number, int2str(level_nr,
794 menu.main.text.level_number.size));
796 main_text_level_year = leveldir_current->year;
797 main_text_level_imported_from = leveldir_current->imported_from;
798 main_text_level_imported_by = leveldir_current->imported_by;
799 main_text_level_tested_by = leveldir_current->tested_by;
801 /* set main control screen positions to dynamically determined values */
802 for (i = 0; main_controls[i].nr != -1; i++)
804 struct MainControlInfo *mci = &main_controls[i];
806 struct MenuPosInfo *pos_button = mci->pos_button;
807 struct TextPosInfo *pos_text = mci->pos_text;
808 struct TextPosInfo *pos_input = mci->pos_input;
809 char *text = (mci->text ? *mci->text : NULL);
810 char *input = (mci->input ? *mci->input : NULL);
811 int button_graphic = mci->button_graphic;
813 int font_text = (pos_text ? pos_text->font : -1);
814 int font_input = (pos_input ? pos_input->font : -1);
816 int font_text = mci->font_text;
817 int font_input = mci->font_input;
820 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
821 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
822 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
823 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
824 int text_chars = (text != NULL ? strlen(text) : 0);
825 int input_chars = (input != NULL ? strlen(input) : 0);
828 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
830 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
831 int text_width = font_text_width * text_chars;
832 int text_height = font_text_height;
833 int input_width = font_input_width * input_chars;
834 int input_height = font_input_height;
836 if (nr == MAIN_CONTROL_NAME)
839 if (menu.main.input.name.x == -1)
840 menu.main.input.name.x = menu.main.text.name.x + text_width;
841 if (menu.main.input.name.y == -1)
842 menu.main.input.name.y = menu.main.text.name.y;
846 menu.main.input.name.width = input_width;
847 menu.main.input.name.height = input_height;
849 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
850 menu.main.input.name.height = font_input_height;
854 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
856 if (pos_button->width == 0)
857 pos_button->width = button_width;
858 if (pos_button->height == 0)
859 pos_button->height = button_height;
862 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
864 /* calculate width for non-clickable text -- needed for text alignment */
865 boolean calculate_text_width = (pos_button == NULL && text != NULL);
867 if (visibleMenuPos(pos_button))
869 if (pos_text->x == -1)
870 pos_text->x = pos_button->x + pos_button->width;
871 if (pos_text->y == -1)
872 pos_text->y = pos_button->y;
875 if (pos_text->width == -1 || calculate_text_width)
876 pos_text->width = text_width;
877 if (pos_text->height == -1)
878 pos_text->height = text_height;
881 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
883 if (visibleTextPos(pos_text))
885 if (pos_input->x == -1)
886 pos_input->x = pos_text->x + pos_text->width;
887 if (pos_input->y == -1)
888 pos_input->y = pos_text->y;
891 if (pos_input->width == -1)
892 pos_input->width = input_width;
893 if (pos_input->height == -1)
894 pos_input->height = input_height;
899 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
900 boolean active_input)
904 for (i = 0; main_controls[i].nr != -1; i++)
906 struct MainControlInfo *mci = &main_controls[i];
908 if (mci->nr == nr || nr == -1)
910 struct MenuPosInfo *pos_button = mci->pos_button;
911 struct TextPosInfo *pos_text = mci->pos_text;
912 struct TextPosInfo *pos_input = mci->pos_input;
913 char *text = (mci->text ? *mci->text : NULL);
914 char *input = (mci->input ? *mci->input : NULL);
915 int button_graphic = mci->button_graphic;
917 int font_text = (pos_text ? pos_text->font : -1);
918 int font_input = (pos_input ? pos_input->font : -1);
920 int font_text = mci->font_text;
921 int font_input = mci->font_input;
926 button_graphic = BUTTON_ACTIVE(button_graphic);
927 font_text = FONT_ACTIVE(font_text);
932 font_input = FONT_ACTIVE(font_input);
935 if (visibleMenuPos(pos_button))
937 struct MenuPosInfo *pos = pos_button;
938 int x = mSX + pos->x;
939 int y = mSY + pos->y;
941 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
942 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
945 if (visibleTextPos(pos_text) && text != NULL)
947 struct TextPosInfo *pos = pos_text;
948 int x = mSX + ALIGNED_TEXT_XPOS(pos);
949 int y = mSY + ALIGNED_TEXT_YPOS(pos);
952 /* (check why/if this is needed) */
953 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
955 DrawText(x, y, text, font_text);
958 if (visibleTextPos(pos_input) && input != NULL)
960 struct TextPosInfo *pos = pos_input;
961 int x = mSX + ALIGNED_TEXT_XPOS(pos);
962 int y = mSY + ALIGNED_TEXT_YPOS(pos);
965 /* (check why/if this is needed) */
966 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
968 DrawText(x, y, input, font_input);
974 static void DrawCursorAndText_Main(int nr, boolean active_text)
976 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
980 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
982 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
986 static struct MainControlInfo *getMainControlInfo(int nr)
990 for (i = 0; main_controls[i].nr != -1; i++)
991 if (main_controls[i].nr == nr)
992 return &main_controls[i];
997 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1002 int rect_x = ALIGNED_TEXT_XPOS(rect);
1003 int rect_y = ALIGNED_TEXT_YPOS(rect);
1005 return (x >= rect_x && x < rect_x + rect->width &&
1006 y >= rect_y && y < rect_y + rect->height);
1009 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1014 int rect_x = ALIGNED_TEXT_XPOS(rect);
1015 int rect_y = ALIGNED_TEXT_YPOS(rect);
1017 return (x >= rect_x && x < rect_x + rect->width &&
1018 y >= rect_y && y < rect_y + rect->height);
1021 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1023 static int cursor_array[SCR_FIELDY];
1024 int x = mSX + TILEX * xpos;
1025 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1030 cursor_array[ypos] = graphic;
1032 graphic = cursor_array[ypos];
1036 graphic = BUTTON_ACTIVE(graphic);
1038 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1039 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1042 static void initCursor(int ypos, int graphic)
1044 drawCursorExt(0, ypos, FALSE, graphic);
1047 static void drawCursor(int ypos, boolean active)
1049 drawCursorExt(0, ypos, active, -1);
1052 static void drawCursorXY(int xpos, int ypos, int graphic)
1054 drawCursorExt(xpos, ypos, FALSE, graphic);
1057 static void drawChooseTreeCursor(int ypos, boolean active)
1059 int last_game_status = game_status; /* save current game status */
1062 /* force LEVELS draw offset on artwork setup screen */
1063 game_status = GAME_MODE_LEVELS;
1066 drawCursorExt(0, ypos, active, -1);
1068 game_status = last_game_status; /* restore current game status */
1073 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1074 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1078 static int getPrevlevelButtonPos()
1083 static int getCurrentLevelTextPos()
1085 return (getPrevlevelButtonPos() + 1);
1088 static int getNextLevelButtonPos()
1090 return getPrevlevelButtonPos() + 3 + 1;
1093 static int getLevelRangeTextPos()
1095 return getNextLevelButtonPos() + 1;
1099 int effectiveGameStatus()
1101 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1102 return GAME_MODE_TITLE;
1107 void DrawTitleScreenImage(int nr, boolean initial)
1109 int graphic = getTitleScreenGraphic(nr, initial);
1110 Bitmap *bitmap = graphic_info[graphic].bitmap;
1111 int width = graphic_info[graphic].width;
1112 int height = graphic_info[graphic].height;
1113 int src_x = graphic_info[graphic].src_x;
1114 int src_y = graphic_info[graphic].src_y;
1120 if (width > WIN_XSIZE)
1122 /* image width too large for window => center image horizontally */
1123 src_x = (width - WIN_XSIZE) / 2;
1127 if (height > WIN_YSIZE)
1129 /* image height too large for window => center image vertically */
1130 src_y = (height - WIN_YSIZE) / 2;
1134 /* always display title screens centered */
1135 dst_x = (WIN_XSIZE - width) / 2;
1136 dst_y = (WIN_YSIZE - height) / 2;
1138 SetDrawBackgroundMask(REDRAW_ALL);
1139 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1141 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1143 if (DrawingOnBackground(dst_x, dst_y))
1144 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1146 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1148 redraw_mask = REDRAW_ALL;
1151 void DrawTitleScreenMessage(int nr, boolean initial)
1153 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1154 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1155 int last_game_status = game_status; /* save current game status */
1157 if (filename == NULL)
1160 /* force TITLE font on title message screen */
1161 game_status = getTitleMessageGameMode(initial);
1163 /* if chars set to "-1", automatically determine by text and font width */
1164 if (tmi->chars == -1)
1165 tmi->chars = tmi->width / getFontWidth(tmi->font);
1167 tmi->width = tmi->chars * getFontWidth(tmi->font);
1169 /* if lines set to "-1", automatically determine by text and font height */
1170 if (tmi->lines == -1)
1171 tmi->lines = tmi->height / getFontHeight(tmi->font);
1173 tmi->height = tmi->lines * getFontHeight(tmi->font);
1175 SetDrawBackgroundMask(REDRAW_ALL);
1176 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1178 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1180 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1181 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1182 tmi->autowrap, tmi->centered, tmi->parse_comments);
1184 game_status = last_game_status; /* restore current game status */
1187 void DrawTitleScreen()
1189 KeyboardAutoRepeatOff();
1192 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1195 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1200 boolean CheckTitleScreen(boolean levelset_has_changed)
1202 static boolean show_title_initial = TRUE;
1203 boolean show_titlescreen = FALSE;
1205 /* needed to be able to skip title screen, if no image or message defined */
1206 InitializeTitleControls(show_title_initial);
1208 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1209 show_titlescreen = TRUE;
1211 /* show initial title images and messages only once at program start */
1212 show_title_initial = FALSE;
1214 return (show_titlescreen && num_title_screens > 0);
1217 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1219 static LevelDirTree *leveldir_last_valid = NULL;
1220 boolean levelset_has_changed = FALSE;
1222 FadeSetLeaveScreen();
1224 /* do not fade out here -- function may continue and fade on editor screen */
1227 FadeSoundsAndMusic();
1229 KeyboardAutoRepeatOn();
1232 SetDrawDeactivationMask(REDRAW_NONE);
1233 SetDrawBackgroundMask(REDRAW_FIELD);
1235 audio.sound_deactivated = FALSE;
1239 /* needed if last screen was the playing screen, invoked from level editor */
1240 if (level_editor_test_game)
1242 game_status = GAME_MODE_EDITOR;
1248 /* needed if last screen was the setup screen and fullscreen state changed */
1249 ToggleFullscreenIfNeeded();
1251 /* leveldir_current may be invalid (level group, parent link) */
1252 if (!validLevelSeries(leveldir_current))
1253 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1255 if (leveldir_current != leveldir_last_valid)
1256 levelset_has_changed = TRUE;
1258 /* store valid level series information */
1259 leveldir_last_valid = leveldir_current;
1261 /* needed if last screen (level choice) changed graphics, sounds or music */
1262 ReloadCustomArtwork(0);
1264 if (redraw_mask & REDRAW_ALL)
1265 fade_mask = REDRAW_ALL;
1270 /* needed if last screen was the editor screen */
1271 UndrawSpecialEditorDoor();
1274 #if defined(TARGET_SDL)
1275 SetDrawtoField(DRAW_BACKBUFFER);
1278 if (CheckTitleScreen(levelset_has_changed))
1280 game_status = GAME_MODE_TITLE;
1287 /* level_nr may have been set to value over handicap with level editor */
1288 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1289 level_nr = leveldir_current->handicap_level;
1291 LoadLevel(level_nr);
1293 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1296 if (fade_mask == REDRAW_ALL)
1298 // int door_state = GetDoorState();
1302 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1308 InitializeMainControls();
1310 DrawCursorAndText_Main(-1, FALSE);
1311 DrawPreviewLevel(TRUE);
1313 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1316 if (TAPE_IS_EMPTY(tape))
1318 DrawCompleteVideoDisplay();
1323 /* create gadgets for main menu screen */
1324 FreeScreenGadgets();
1325 CreateScreenGadgets();
1327 /* map gadgets for main menu screen */
1329 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1332 if (fade_mask == REDRAW_ALL)
1334 int door_state = GetDoorState();
1336 // RedrawBackground();
1338 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1342 DrawMaskedBorder(REDRAW_ALL);
1347 SetMouseCursor(CURSOR_DEFAULT);
1351 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1354 void DrawAndFadeInMainMenu(int fade_mask)
1356 DrawMainMenuExt(fade_mask, TRUE);
1361 DrawMainMenuExt(REDRAW_ALL, FALSE);
1365 static void gotoTopLevelDir()
1367 /* move upwards to top level directory */
1368 while (leveldir_current->node_parent)
1370 /* write a "path" into level tree for easy navigation to last level */
1371 if (leveldir_current->node_parent->node_group->cl_first == -1)
1373 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1374 int leveldir_pos = posTreeInfo(leveldir_current);
1375 int num_page_entries;
1376 int cl_first, cl_cursor;
1378 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1379 num_page_entries = num_leveldirs;
1381 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1383 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1384 cl_cursor = leveldir_pos - cl_first;
1386 leveldir_current->node_parent->node_group->cl_first = cl_first;
1387 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1390 leveldir_current = leveldir_current->node_parent;
1395 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1397 static unsigned long title_delay = 0;
1398 static int title_screen_nr = 0;
1399 static int last_sound = -1, last_music = -1;
1400 boolean return_to_main_menu = FALSE;
1401 boolean use_fading_main_menu = TRUE;
1402 struct TitleControlInfo *tci;
1403 struct TitleFadingInfo fading_default;
1404 struct TitleFadingInfo fading_last = fading;
1405 struct TitleFadingInfo fading_next;
1408 if (button == MB_MENU_INITIALIZE)
1411 title_screen_nr = 0;
1412 tci = &title_controls[title_screen_nr];
1414 last_sound = SND_UNDEFINED;
1415 last_music = MUS_UNDEFINED;
1417 if (game_status == GAME_MODE_INFO)
1419 if (num_title_screens == 0)
1421 DrawInfoScreen_NotAvailable("Title screen information:",
1422 "No title screen for this level set.");
1427 FadeSoundsAndMusic();
1430 FadeOut(REDRAW_ALL);
1435 DrawTitleScreenImage(tci->local_nr, tci->initial);
1437 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1439 fading_default = (tci->initial ? title_initial_default : title_default);
1441 fading = fading_next = getTitleFading(tci);
1445 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1446 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1448 fading.fade_mode = FADE_MODE_FADE;
1449 fading.fade_delay = fading_default.fade_delay;
1452 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1453 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1454 fading.fade_mode = FADE_MODE_FADE;
1459 sound = getTitleSound(tci);
1460 music = getTitleMusic(tci);
1462 if (sound != last_sound)
1463 PlayMenuSoundExt(sound);
1464 if (music != last_music)
1465 PlayMenuMusicExt(music);
1471 SetMouseCursor(CURSOR_NONE);
1477 fading = fading_next;
1479 DelayReached(&title_delay, 0); /* reset delay counter */
1485 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1486 button = MB_MENU_CHOICE;
1488 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1489 button = MB_MENU_CHOICE;
1492 if (button == MB_MENU_LEAVE)
1494 return_to_main_menu = TRUE;
1495 use_fading_main_menu = FALSE;
1497 else if (button == MB_MENU_CHOICE)
1499 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1502 FadeOut(REDRAW_FIELD);
1505 FadeSetEnterScreen();
1507 info_mode = INFO_MODE_MAIN;
1508 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1514 tci = &title_controls[title_screen_nr];
1516 if (title_screen_nr < num_title_screens)
1518 sound = getTitleSound(tci);
1519 music = getTitleMusic(tci);
1521 if (sound == SND_UNDEFINED || sound != last_sound)
1523 if (music == MUS_UNDEFINED || music != last_music)
1527 FadeOut(REDRAW_ALL);
1531 DrawTitleScreenImage(tci->local_nr, tci->initial);
1533 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1535 fading_next = getTitleFading(tci);
1538 sound = getTitleSound(tci);
1539 music = getTitleMusic(tci);
1541 if (sound != last_sound)
1542 PlayMenuSoundExt(sound);
1543 if (music != last_music)
1544 PlayMenuMusicExt(music);
1551 /* last screen already faded out, next screen has no animation */
1552 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1553 fading_next.fade_mode == FADE_MODE_NONE)
1554 fading = fading_next;
1556 /* last screen already faded out, next screen has no animation */
1557 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1558 fading_next.fade_mode == FADE_MODE_NONE)
1559 fading = fading_next;
1566 fading = fading_next;
1568 DelayReached(&title_delay, 0); /* reset delay counter */
1572 FadeSoundsAndMusic();
1574 return_to_main_menu = TRUE;
1578 if (return_to_main_menu)
1584 SetMouseCursor(CURSOR_DEFAULT);
1586 if (game_status == GAME_MODE_INFO)
1589 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1592 info_mode = INFO_MODE_MAIN;
1593 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1595 else /* default: return to main menu */
1598 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1601 game_status = GAME_MODE_MAIN;
1602 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1607 void HandleMainMenu_SelectLevel(int step, int direction)
1609 int old_level_nr = level_nr;
1612 new_level_nr = old_level_nr + step * direction;
1613 if (new_level_nr < leveldir_current->first_level)
1614 new_level_nr = leveldir_current->first_level;
1615 if (new_level_nr > leveldir_current->last_level)
1616 new_level_nr = leveldir_current->last_level;
1618 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1620 /* skipping levels is only allowed when trying to skip single level */
1621 if (setup.skip_levels && step == 1 &&
1622 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1624 leveldir_current->handicap_level++;
1625 SaveLevelSetup_SeriesInfo();
1628 new_level_nr = leveldir_current->handicap_level;
1631 if (new_level_nr != old_level_nr)
1633 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1635 PlaySound(SND_MENU_ITEM_SELECTING);
1637 level_nr = new_level_nr;
1639 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1640 int2str(level_nr, menu.main.text.level_number.size),
1641 mci->pos_text->font);
1643 LoadLevel(level_nr);
1644 DrawPreviewLevel(TRUE);
1648 DrawCompleteVideoDisplay();
1650 /* needed because DrawPreviewLevel() takes some time */
1656 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1658 static int choice = MAIN_CONTROL_GAME;
1662 if (button == MB_MENU_INITIALIZE)
1664 DrawCursorAndText_Main(choice, TRUE);
1669 if (mx || my) /* mouse input */
1673 for (i = 0; main_controls[i].nr != -1; i++)
1675 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1676 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1677 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1679 pos = main_controls[i].nr;
1685 else if (dx || dy) /* keyboard input */
1687 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1688 choice == MAIN_CONTROL_SETUP))
1689 button = MB_MENU_CHOICE;
1694 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1696 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1698 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1704 PlaySound(SND_MENU_ITEM_ACTIVATING);
1706 DrawCursorAndText_Main(choice, FALSE);
1707 DrawCursorAndText_Main(pos, TRUE);
1714 PlaySound(SND_MENU_ITEM_SELECTING);
1716 if (pos == MAIN_CONTROL_NAME)
1718 game_status = GAME_MODE_PSEUDO_TYPENAME;
1720 HandleTypeName(strlen(setup.player_name), 0);
1722 else if (pos == MAIN_CONTROL_LEVELS)
1726 game_status = GAME_MODE_LEVELS;
1728 SaveLevelSetup_LastSeries();
1729 SaveLevelSetup_SeriesInfo();
1738 else if (pos == MAIN_CONTROL_SCORES)
1740 game_status = GAME_MODE_SCORES;
1744 else if (pos == MAIN_CONTROL_EDITOR)
1746 if (leveldir_current->readonly &&
1747 !strEqual(setup.player_name, "Artsoft"))
1748 Request("This level is read only !", REQ_CONFIRM);
1750 game_status = GAME_MODE_EDITOR;
1752 FadeSetEnterScreen();
1756 else if (pos == MAIN_CONTROL_INFO)
1758 game_status = GAME_MODE_INFO;
1759 info_mode = INFO_MODE_MAIN;
1763 else if (pos == MAIN_CONTROL_GAME)
1765 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1767 else if (pos == MAIN_CONTROL_SETUP)
1769 game_status = GAME_MODE_SETUP;
1770 setup_mode = SETUP_MODE_MAIN;
1774 else if (pos == MAIN_CONTROL_QUIT)
1776 SaveLevelSetup_LastSeries();
1777 SaveLevelSetup_SeriesInfo();
1779 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1780 game_status = GAME_MODE_QUIT;
1785 if (game_status == GAME_MODE_MAIN)
1787 DrawPreviewLevel(FALSE);
1793 /* ========================================================================= */
1794 /* info screen functions */
1795 /* ========================================================================= */
1797 static struct TokenInfo *info_info;
1798 static int num_info_info;
1800 static void execInfoTitleScreen()
1802 info_mode = INFO_MODE_TITLE;
1807 static void execInfoElements()
1809 info_mode = INFO_MODE_ELEMENTS;
1814 static void execInfoMusic()
1816 info_mode = INFO_MODE_MUSIC;
1821 static void execInfoCredits()
1823 info_mode = INFO_MODE_CREDITS;
1828 static void execInfoProgram()
1830 info_mode = INFO_MODE_PROGRAM;
1835 static void execInfoVersion()
1837 info_mode = INFO_MODE_VERSION;
1842 static void execInfoLevelSet()
1844 info_mode = INFO_MODE_LEVELSET;
1849 static void execExitInfo()
1851 game_status = GAME_MODE_MAIN;
1853 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1856 static struct TokenInfo info_info_main[] =
1858 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1859 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1860 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1861 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1862 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1863 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1864 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1865 { TYPE_EMPTY, NULL, "" },
1866 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1871 static void DrawCursorAndText_Info(int pos, boolean active)
1873 int xpos = MENU_SCREEN_START_XPOS;
1874 int ypos = MENU_SCREEN_START_YPOS + pos;
1875 int font_nr = FONT_MENU_1;
1878 font_nr = FONT_ACTIVE(font_nr);
1880 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1882 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1883 drawCursor(pos, active);
1886 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1891 CloseDoor(DOOR_CLOSE_2);
1893 /* (needed after displaying title screens which disable auto repeat) */
1894 KeyboardAutoRepeatOn();
1896 FadeSetLeaveScreen();
1903 if (fade_mask == REDRAW_ALL)
1907 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1913 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1915 info_info = info_info_main;
1919 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1921 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1924 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1925 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1926 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1927 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1928 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1929 initCursor(i, IMG_MENU_BUTTON);
1931 DrawCursorAndText_Info(i, FALSE);
1936 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1941 DrawMaskedBorder(fade_mask);
1948 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1950 static int choice_store[MAX_INFO_MODES];
1951 int choice = choice_store[info_mode]; /* always starts with 0 */
1955 if (button == MB_MENU_INITIALIZE)
1957 /* advance to first valid menu entry */
1958 while (choice < num_info_info &&
1959 info_info[choice].type & TYPE_SKIP_ENTRY)
1961 choice_store[info_mode] = choice;
1963 DrawCursorAndText_Info(choice, TRUE);
1967 else if (button == MB_MENU_LEAVE)
1969 for (y = 0; y < num_info_info; y++)
1971 if (info_info[y].type & TYPE_LEAVE_MENU)
1973 void (*menu_callback_function)(void) = info_info[y].value;
1977 menu_callback_function();
1979 break; /* absolutely needed because function changes 'info_info'! */
1986 if (mx || my) /* mouse input */
1988 x = (mx - mSX) / 32;
1989 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1991 else if (dx || dy) /* keyboard input */
1995 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
1997 if (info_info[choice].type & menu_navigation_type ||
1998 info_info[choice].type & TYPE_ENTER_SCREEN ||
1999 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2000 button = MB_MENU_CHOICE;
2005 /* jump to next non-empty menu entry (up or down) */
2006 while (y > 0 && y < num_info_info - 1 &&
2007 info_info[y].type & TYPE_SKIP_ENTRY)
2011 if (IN_VIS_FIELD(x, y) &&
2012 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2018 PlaySound(SND_MENU_ITEM_ACTIVATING);
2020 DrawCursorAndText_Info(choice, FALSE);
2021 DrawCursorAndText_Info(y, TRUE);
2023 choice = choice_store[info_mode] = y;
2026 else if (!(info_info[y].type & TYPE_GHOSTED))
2028 PlaySound(SND_MENU_ITEM_SELECTING);
2030 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2032 void (*menu_callback_function)(void) = info_info[choice].value;
2034 FadeSetFromType(info_info[y].type);
2036 menu_callback_function();
2042 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2044 int ystart1 = mSY - SY + 100;
2045 int ystart2 = mSY - SY + 150;
2046 int ybottom = mSY - SY + SYSIZE - 20;
2048 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2050 FadeOut(REDRAW_FIELD);
2055 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2056 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2058 DrawTextSCentered(ybottom, FONT_TEXT_4,
2059 "Press any key or button for info menu");
2061 FadeIn(REDRAW_FIELD);
2064 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2066 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2067 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2068 int xstart = mSX + 16;
2069 int ystart1 = mSY - SY + 100;
2070 int ystart2 = mSY + 64 + 2 * 32;
2071 int ybottom = mSY - SY + SYSIZE - 20;
2072 int ystep = TILEY + 4;
2073 int element, action, direction;
2081 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2082 infoscreen_step[i] = infoscreen_frame[i] = 0;
2087 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2089 DrawTextSCentered(ybottom, FONT_TEXT_4,
2090 "Press any key or button for next page");
2096 while (helpanim_info[j].element != HELPANIM_LIST_END)
2098 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2103 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2112 j += infoscreen_step[i - start];
2114 element = helpanim_info[j].element;
2115 action = helpanim_info[j].action;
2116 direction = helpanim_info[j].direction;
2119 element = EL_UNKNOWN;
2121 if (action != -1 && direction != -1)
2122 graphic = el_act_dir2img(element, action, direction);
2123 else if (action != -1)
2124 graphic = el_act2img(element, action);
2125 else if (direction != -1)
2126 graphic = el_dir2img(element, direction);
2128 graphic = el2img(element);
2130 delay = helpanim_info[j++].delay;
2135 if (infoscreen_frame[i - start] == 0)
2138 infoscreen_frame[i - start] = delay - 1;
2142 sync_frame = delay - infoscreen_frame[i - start];
2143 infoscreen_frame[i - start]--;
2146 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2148 if (!infoscreen_frame[i - start])
2149 infoscreen_step[i - start] = 0;
2153 if (!infoscreen_frame[i - start])
2154 infoscreen_step[i - start]++;
2155 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2161 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2163 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2164 graphic, sync_frame, USE_MASKING);
2167 DrawInfoScreen_HelpText(element, action, direction, i - start);
2172 redraw_mask |= REDRAW_FIELD;
2177 static char *getHelpText(int element, int action, int direction)
2179 char token[MAX_LINE_LEN];
2181 strcpy(token, element_info[element].token_name);
2184 strcat(token, element_action_info[action].suffix);
2186 if (direction != -1)
2187 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2189 return getHashEntry(helptext_info, token);
2192 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2194 int font_nr = FONT_INFO_ELEMENTS;
2195 int font_width = getFontWidth(font_nr);
2196 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2197 int sy = mSY + 65 + 2 * 32 + 1;
2198 int ystep = TILEY + 4;
2199 int pad_x = sx - SX;
2200 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2201 int max_lines_per_text = 2;
2204 if (action != -1 && direction != -1) /* element.action.direction */
2205 text = getHelpText(element, action, direction);
2207 if (text == NULL && action != -1) /* element.action */
2208 text = getHelpText(element, action, -1);
2210 if (text == NULL && direction != -1) /* element.direction */
2211 text = getHelpText(element, -1, direction);
2213 if (text == NULL) /* base element */
2214 text = getHelpText(element, -1, -1);
2216 if (text == NULL) /* not found */
2217 text = "No description available";
2219 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2220 sy += getFontHeight(font_nr) / 2;
2222 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2223 max_chars_per_line, -1, max_lines_per_text, -1,
2224 TRUE, FALSE, FALSE);
2227 void DrawInfoScreen_TitleScreen()
2232 void HandleInfoScreen_TitleScreen(int button)
2234 HandleTitleScreen(0, 0, 0, 0, button);
2237 void DrawInfoScreen_Elements()
2239 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2241 FadeOut(REDRAW_FIELD);
2246 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2248 FadeIn(REDRAW_FIELD);
2253 void HandleInfoScreen_Elements(int button)
2255 static unsigned long info_delay = 0;
2256 static int num_anims;
2257 static int num_pages;
2259 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2262 if (button == MB_MENU_INITIALIZE)
2264 boolean new_element = TRUE;
2268 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2270 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2272 else if (new_element)
2275 new_element = FALSE;
2279 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2283 if (button == MB_MENU_LEAVE)
2285 PlaySound(SND_MENU_ITEM_SELECTING);
2287 info_mode = INFO_MODE_MAIN;
2292 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2294 if (button != MB_MENU_INITIALIZE)
2296 PlaySound(SND_MENU_ITEM_SELECTING);
2301 if (page >= num_pages)
2303 FadeSoundsAndMusic();
2305 info_mode = INFO_MODE_MAIN;
2306 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2313 FadeSetNextScreen();
2316 if (button != MB_MENU_INITIALIZE)
2317 FadeOut(REDRAW_FIELD);
2319 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2321 if (button != MB_MENU_INITIALIZE)
2322 FadeIn(REDRAW_FIELD);
2326 if (DelayReached(&info_delay, GameFrameDelay))
2327 if (page < num_pages)
2328 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2330 PlayMenuSoundIfLoop();
2334 void DrawInfoScreen_Music()
2336 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2339 FadeOut(REDRAW_FIELD);
2347 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2350 FadeIn(REDRAW_FIELD);
2354 void HandleInfoScreen_Music(int button)
2356 static struct MusicFileInfo *list = NULL;
2357 int ystart1 = mSY - SY + 100;
2358 int ystart2 = mSY - SY + 150;
2359 int ybottom = mSY - SY + SYSIZE - 20;
2362 if (button == MB_MENU_INITIALIZE)
2364 list = music_file_info;
2368 FadeSoundsAndMusic();
2373 DrawTextSCentered(ystart1, FONT_TEXT_1,
2374 "No music info for this level set.");
2376 DrawTextSCentered(ybottom, FONT_TEXT_4,
2377 "Press any key or button for info menu");
2383 if (button == MB_MENU_LEAVE)
2385 PlaySound(SND_MENU_ITEM_SELECTING);
2387 FadeSoundsAndMusic();
2389 info_mode = INFO_MODE_MAIN;
2394 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2398 if (button != MB_MENU_INITIALIZE)
2400 PlaySound(SND_MENU_ITEM_SELECTING);
2408 FadeSoundsAndMusic();
2410 info_mode = INFO_MODE_MAIN;
2411 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2416 FadeSoundsAndMusic();
2419 if (list != music_file_info)
2420 FadeSetNextScreen();
2423 if (button != MB_MENU_INITIALIZE)
2424 FadeOut(REDRAW_FIELD);
2431 int sound = list->music;
2433 if (sound_info[sound].loop)
2434 PlaySoundLoop(sound);
2438 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2442 PlayMusic(list->music);
2444 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2447 if (!strEqual(list->title, UNKNOWN_NAME))
2449 if (!strEqual(list->title_header, UNKNOWN_NAME))
2450 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2452 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2455 if (!strEqual(list->artist, UNKNOWN_NAME))
2457 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2458 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2460 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2462 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2465 if (!strEqual(list->album, UNKNOWN_NAME))
2467 if (!strEqual(list->album_header, UNKNOWN_NAME))
2468 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2470 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2472 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2475 if (!strEqual(list->year, UNKNOWN_NAME))
2477 if (!strEqual(list->year_header, UNKNOWN_NAME))
2478 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2480 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2482 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2485 DrawTextSCentered(ybottom, FONT_TEXT_4,
2486 "Press any key or button for next page");
2488 if (button != MB_MENU_INITIALIZE)
2489 FadeIn(REDRAW_FIELD);
2492 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2493 PlaySoundLoop(list->music);
2496 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2498 int ystart1 = mSY - SY + 100;
2499 int ystart2 = mSY - SY + 150;
2500 int ybottom = mSY - SY + SYSIZE - 20;
2506 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2510 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2511 "Special thanks to");
2512 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2514 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2516 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2517 "\"Boulder Dash\"");
2518 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2520 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2522 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2524 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2525 "First Star Software");
2527 else if (screen_nr == 1)
2529 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2530 "Special thanks to");
2531 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2532 "Klaus Heinz & Volker Wertich");
2533 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2535 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2536 "\"Emerald Mine\"");
2537 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2539 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2541 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2543 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2546 else if (screen_nr == 2)
2548 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2549 "Special thanks to");
2550 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2551 "Michael Stopp & Philip Jespersen");
2552 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2554 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2556 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2558 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2560 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2562 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2563 "Digital Integration");
2565 else if (screen_nr == 3)
2567 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2568 "Special thanks to");
2569 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2570 "Hiroyuki Imabayashi");
2571 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2573 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2575 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2577 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2579 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2581 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2584 else if (screen_nr == 4)
2586 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2587 "Special thanks to");
2588 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2590 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2592 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2593 "Jürgen Bonhagen");
2594 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2595 "for the continuous creation");
2596 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2597 "of outstanding level sets");
2599 else if (screen_nr == 5)
2601 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2603 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2605 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2606 "for ideas and inspiration by");
2607 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2610 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2612 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2614 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2615 "for ideas and inspiration by");
2616 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2619 else if (screen_nr == 6)
2621 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2623 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2625 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2626 "for the new Emerald Mine engine");
2628 else if (screen_nr == 7)
2630 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2632 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2634 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2635 "for the initial DOS port");
2637 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2639 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2641 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2642 "for some additional toons");
2644 else if (screen_nr == 8)
2646 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2647 "And not to forget:");
2648 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2650 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2651 "All those who contributed");
2652 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2653 "levels to this game");
2654 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2658 DrawTextSCentered(ybottom, FONT_TEXT_4,
2659 "Press any key or button for next page");
2662 void DrawInfoScreen_Credits()
2664 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2666 FadeSoundsAndMusic();
2669 FadeOut(REDRAW_FIELD);
2672 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2675 FadeIn(REDRAW_FIELD);
2679 void HandleInfoScreen_Credits(int button)
2681 static int screen_nr = 0;
2682 int num_screens = 9;
2684 if (button == MB_MENU_INITIALIZE)
2688 // DrawInfoScreen_CreditsScreen(screen_nr);
2691 if (button == MB_MENU_LEAVE)
2693 PlaySound(SND_MENU_ITEM_SELECTING);
2695 info_mode = INFO_MODE_MAIN;
2700 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2702 if (button != MB_MENU_INITIALIZE)
2704 PlaySound(SND_MENU_ITEM_SELECTING);
2709 if (screen_nr >= num_screens)
2711 FadeSoundsAndMusic();
2713 info_mode = INFO_MODE_MAIN;
2714 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2721 FadeSetNextScreen();
2724 if (button != MB_MENU_INITIALIZE)
2725 FadeOut(REDRAW_FIELD);
2727 DrawInfoScreen_CreditsScreen(screen_nr);
2729 if (button != MB_MENU_INITIALIZE)
2730 FadeIn(REDRAW_FIELD);
2734 PlayMenuSoundIfLoop();
2738 void DrawInfoScreen_Program()
2740 int ystart1 = mSY - SY + 100;
2741 int ystart2 = mSY - SY + 150;
2742 int ybottom = mSY - SY + SYSIZE - 20;
2745 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2748 FadeOut(REDRAW_FIELD);
2754 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2756 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2757 "This game is Freeware!");
2758 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2759 "If you like it, send e-mail to:");
2760 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2761 PROGRAM_EMAIL_STRING);
2762 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2763 "or SnailMail to:");
2764 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2766 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2767 "Detmolder Strasse 189");
2768 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2770 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2772 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2773 "More information and levels:");
2774 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2775 PROGRAM_WEBSITE_STRING);
2776 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2777 "If you have created new levels,");
2778 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2779 "send them to me to include them!");
2780 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2783 DrawTextSCentered(ybottom, FONT_TEXT_4,
2784 "Press any key or button for info menu");
2787 FadeIn(REDRAW_FIELD);
2791 void HandleInfoScreen_Program(int button)
2793 if (button == MB_MENU_LEAVE)
2795 PlaySound(SND_MENU_ITEM_SELECTING);
2797 info_mode = INFO_MODE_MAIN;
2802 else if (button == MB_MENU_CHOICE)
2804 PlaySound(SND_MENU_ITEM_SELECTING);
2806 FadeSoundsAndMusic();
2809 FadeOut(REDRAW_FIELD);
2812 info_mode = INFO_MODE_MAIN;
2813 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2817 PlayMenuSoundIfLoop();
2821 void DrawInfoScreen_Version()
2823 int font_header = FONT_TEXT_3;
2824 int font_text = FONT_TEXT_2;
2825 int xstep = getFontWidth(font_text);
2826 int ystep = getFontHeight(font_text);
2827 int ystart1 = mSY - SY + 100;
2828 int ystart2 = mSY - SY + 150;
2829 int ybottom = mSY - SY + SYSIZE - 20;
2830 int xstart1 = mSX + 2 * xstep;
2831 int xstart2 = mSX + 19 * xstep;
2832 #if defined(TARGET_SDL)
2833 int xstart3 = mSX + 29 * xstep;
2834 SDL_version sdl_version_compiled;
2835 const SDL_version *sdl_version_linked;
2836 int driver_name_len = 8;
2837 char driver_name[driver_name_len];
2840 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2843 FadeOut(REDRAW_FIELD);
2849 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2851 DrawTextF(xstart1, ystart2, font_header, "Name");
2852 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2855 DrawTextF(xstart1, ystart2, font_header, "Version");
2856 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2859 DrawTextF(xstart1, ystart2, font_header, "Platform");
2860 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2863 DrawTextF(xstart1, ystart2, font_header, "Target");
2864 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2867 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2868 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2870 #if defined(TARGET_SDL)
2871 ystart2 += 3 * ystep;
2872 DrawTextF(xstart1, ystart2, font_header, "Library");
2873 DrawTextF(xstart2, ystart2, font_header, "compiled");
2874 DrawTextF(xstart3, ystart2, font_header, "linked");
2876 SDL_VERSION(&sdl_version_compiled);
2877 sdl_version_linked = SDL_Linked_Version();
2879 ystart2 += 2 * ystep;
2880 DrawTextF(xstart1, ystart2, font_text, "SDL");
2881 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2882 sdl_version_compiled.major,
2883 sdl_version_compiled.minor,
2884 sdl_version_compiled.patch);
2885 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2886 sdl_version_linked->major,
2887 sdl_version_linked->minor,
2888 sdl_version_linked->patch);
2890 SDL_IMAGE_VERSION(&sdl_version_compiled);
2891 sdl_version_linked = IMG_Linked_Version();
2894 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2895 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2896 sdl_version_compiled.major,
2897 sdl_version_compiled.minor,
2898 sdl_version_compiled.patch);
2899 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2900 sdl_version_linked->major,
2901 sdl_version_linked->minor,
2902 sdl_version_linked->patch);
2904 SDL_MIXER_VERSION(&sdl_version_compiled);
2905 sdl_version_linked = Mix_Linked_Version();
2908 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2909 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2910 sdl_version_compiled.major,
2911 sdl_version_compiled.minor,
2912 sdl_version_compiled.patch);
2913 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2914 sdl_version_linked->major,
2915 sdl_version_linked->minor,
2916 sdl_version_linked->patch);
2918 SDL_NET_VERSION(&sdl_version_compiled);
2919 sdl_version_linked = SDLNet_Linked_Version();
2922 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2923 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2924 sdl_version_compiled.major,
2925 sdl_version_compiled.minor,
2926 sdl_version_compiled.patch);
2927 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2928 sdl_version_linked->major,
2929 sdl_version_linked->minor,
2930 sdl_version_linked->patch);
2932 ystart2 += 3 * ystep;
2933 DrawTextF(xstart1, ystart2, font_header, "Driver");
2934 DrawTextF(xstart2, ystart2, font_header, "Requested");
2935 DrawTextF(xstart3, ystart2, font_header, "Used");
2937 SDL_VideoDriverName(driver_name, driver_name_len);
2939 ystart2 += 2 * ystep;
2940 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2941 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2942 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2944 SDL_AudioDriverName(driver_name, driver_name_len);
2947 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2948 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2949 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2952 DrawTextSCentered(ybottom, FONT_TEXT_4,
2953 "Press any key or button for info menu");
2956 FadeIn(REDRAW_FIELD);
2960 void HandleInfoScreen_Version(int button)
2962 if (button == MB_MENU_LEAVE)
2964 PlaySound(SND_MENU_ITEM_SELECTING);
2966 info_mode = INFO_MODE_MAIN;
2971 else if (button == MB_MENU_CHOICE)
2973 PlaySound(SND_MENU_ITEM_SELECTING);
2975 FadeSoundsAndMusic();
2978 FadeOut(REDRAW_FIELD);
2981 info_mode = INFO_MODE_MAIN;
2982 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2986 PlayMenuSoundIfLoop();
2990 void DrawInfoScreen_LevelSet()
2992 struct TitleMessageInfo *tmi = &readme;
2993 char *filename = getLevelSetInfoFilename();
2995 /* if chars set to "-1", automatically determine by text and font width */
2996 if (tmi->chars == -1)
2997 tmi->chars = tmi->width / getFontWidth(tmi->font);
2999 tmi->width = tmi->chars * getFontWidth(tmi->font);
3001 /* if lines set to "-1", automatically determine by text and font height */
3002 if (tmi->lines == -1)
3003 tmi->lines = tmi->height / getFontHeight(tmi->font);
3005 tmi->height = tmi->lines * getFontHeight(tmi->font);
3007 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3010 FadeOut(REDRAW_FIELD);
3016 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3018 if (filename != NULL)
3019 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3020 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3021 tmi->autowrap, tmi->centered, tmi->parse_comments);
3023 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3024 "No information for this level set.");
3026 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3027 "Press any key or button for info menu");
3030 FadeIn(REDRAW_FIELD);
3034 void HandleInfoScreen_LevelSet(int button)
3036 if (button == MB_MENU_LEAVE)
3038 PlaySound(SND_MENU_ITEM_SELECTING);
3040 info_mode = INFO_MODE_MAIN;
3045 else if (button == MB_MENU_CHOICE)
3047 PlaySound(SND_MENU_ITEM_SELECTING);
3049 FadeSoundsAndMusic();
3052 FadeOut(REDRAW_FIELD);
3055 info_mode = INFO_MODE_MAIN;
3056 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3060 PlayMenuSoundIfLoop();
3064 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3066 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3068 if (info_mode == INFO_MODE_TITLE)
3069 DrawInfoScreen_TitleScreen();
3070 else if (info_mode == INFO_MODE_ELEMENTS)
3071 DrawInfoScreen_Elements();
3072 else if (info_mode == INFO_MODE_MUSIC)
3073 DrawInfoScreen_Music();
3074 else if (info_mode == INFO_MODE_CREDITS)
3075 DrawInfoScreen_Credits();
3076 else if (info_mode == INFO_MODE_PROGRAM)
3077 DrawInfoScreen_Program();
3078 else if (info_mode == INFO_MODE_VERSION)
3079 DrawInfoScreen_Version();
3080 else if (info_mode == INFO_MODE_LEVELSET)
3081 DrawInfoScreen_LevelSet();
3083 DrawInfoScreen_Main(fade_mask, do_fading);
3085 if (info_mode != INFO_MODE_MAIN &&
3086 info_mode != INFO_MODE_TITLE &&
3087 info_mode != INFO_MODE_MUSIC)
3094 void DrawAndFadeInInfoScreen(int fade_mask)
3096 DrawInfoScreenExt(fade_mask, TRUE);
3099 void DrawInfoScreen()
3101 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3104 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3106 if (info_mode == INFO_MODE_TITLE)
3107 HandleInfoScreen_TitleScreen(button);
3108 else if (info_mode == INFO_MODE_ELEMENTS)
3109 HandleInfoScreen_Elements(button);
3110 else if (info_mode == INFO_MODE_MUSIC)
3111 HandleInfoScreen_Music(button);
3112 else if (info_mode == INFO_MODE_CREDITS)
3113 HandleInfoScreen_Credits(button);
3114 else if (info_mode == INFO_MODE_PROGRAM)
3115 HandleInfoScreen_Program(button);
3116 else if (info_mode == INFO_MODE_VERSION)
3117 HandleInfoScreen_Version(button);
3118 else if (info_mode == INFO_MODE_LEVELSET)
3119 HandleInfoScreen_LevelSet(button);
3121 HandleInfoScreen_Main(mx, my, dx, dy, button);
3127 /* ========================================================================= */
3128 /* type name functions */
3129 /* ========================================================================= */
3131 void HandleTypeName(int newxpos, Key key)
3133 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3134 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3135 struct TextPosInfo *pos = mci->pos_input;
3136 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3137 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3138 static int xpos = 0;
3139 int font_nr = pos->font;
3140 int font_active_nr = FONT_ACTIVE(font_nr);
3141 int font_width = getFontWidth(font_active_nr);
3142 char key_char = getValidConfigValueChar(getCharFromKey(key));
3143 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3144 boolean is_active = TRUE;
3146 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3150 strcpy(last_player_name, setup.player_name);
3154 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3156 setup.player_name[xpos] = key_char;
3157 setup.player_name[xpos + 1] = 0;
3161 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3165 setup.player_name[xpos] = 0;
3167 else if (key == KSYM_Return && xpos > 0)
3173 game_status = GAME_MODE_MAIN;
3175 else if (key == KSYM_Escape)
3177 strcpy(setup.player_name, last_player_name);
3181 game_status = GAME_MODE_MAIN;
3186 pos->width = (strlen(setup.player_name) + 1) * font_width;
3187 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3189 DrawText(startx, starty, setup.player_name, font_active_nr);
3190 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3194 pos->width = strlen(setup.player_name) * font_width;
3195 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3197 DrawText(startx, starty, setup.player_name, font_nr);
3202 /* ========================================================================= */
3203 /* tree menu functions */
3204 /* ========================================================================= */
3206 static void DrawChooseTree(TreeInfo **ti_ptr)
3210 FreeScreenGadgets();
3211 CreateScreenGadgets();
3213 CloseDoor(DOOR_CLOSE_2);
3216 FadeOut(REDRAW_FIELD);
3221 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3222 MapScreenTreeGadgets(*ti_ptr);
3225 FadeIn(REDRAW_FIELD);
3231 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3233 struct GadgetInfo *gi = screen_gadget[id];
3234 int items_max, items_visible, item_position;
3236 items_max = numTreeInfoInGroup(ti);
3237 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3238 item_position = first_entry;
3240 if (item_position > items_max - items_visible)
3241 item_position = items_max - items_visible;
3243 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3244 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3245 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3248 static void drawChooseTreeList(int first_entry, int num_page_entries,
3252 char *title_string = NULL;
3253 int yoffset_sets = MENU_TITLE1_YPOS;
3254 int yoffset_setup = 16;
3255 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3257 int last_game_status = game_status; /* save current game status */
3259 title_string = ti->infotext;
3261 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3264 /* force LEVELS font on artwork setup screen */
3265 game_status = GAME_MODE_LEVELS;
3269 /* clear tree list area, but not title or scrollbar */
3270 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3271 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3272 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3274 /* clear tree list area, but not title or scrollbar */
3275 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3276 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3277 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3280 for (i = 0; i < num_page_entries; i++)
3282 TreeInfo *node, *node_first;
3283 int entry_pos = first_entry + i;
3284 int xpos = MENU_SCREEN_START_XPOS;
3285 int ypos = MENU_SCREEN_START_YPOS + i;
3286 int startx = mSX + xpos * 32;
3287 int starty = mSY + ypos * 32;
3288 int font_nr = FONT_TEXT_1;
3289 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3290 int startx_text = startx + font_xoffset;
3291 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3292 int text_size = startx_scrollbar - startx_text;
3293 int max_buffer_len = text_size / getFontWidth(font_nr);
3294 char buffer[max_buffer_len + 1];
3296 node_first = getTreeInfoFirstGroupEntry(ti);
3297 node = getTreeInfoFromPos(node_first, entry_pos);
3299 strncpy(buffer, node->name, max_buffer_len);
3300 buffer[max_buffer_len] = '\0';
3302 DrawText(startx, starty, buffer, font_nr + node->color);
3304 if (node->parent_link)
3305 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3306 else if (node->level_group)
3307 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3309 initCursor(i, IMG_MENU_BUTTON);
3312 game_status = last_game_status; /* restore current game status */
3314 redraw_mask |= REDRAW_FIELD;
3317 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3319 TreeInfo *node, *node_first;
3320 int x, last_redraw_mask = redraw_mask;
3321 int ypos = MENU_TITLE2_YPOS;
3322 int font_nr = FONT_TITLE_2;
3324 if (ti->type != TREE_TYPE_LEVEL_DIR)
3327 node_first = getTreeInfoFirstGroupEntry(ti);
3328 node = getTreeInfoFromPos(node_first, entry_pos);
3330 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3332 if (node->parent_link)
3333 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3335 else if (node->level_group)
3336 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3338 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3339 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3340 node->levels, node->class_desc);
3342 /* let BackToFront() redraw only what is needed */
3343 redraw_mask = last_redraw_mask | REDRAW_TILES;
3344 for (x = 0; x < SCR_FIELDX; x++)
3345 MarkTileDirty(x, 1);
3348 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3351 TreeInfo *ti = *ti_ptr;
3353 int y = ti->cl_cursor;
3354 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3355 int num_entries = numTreeInfoInGroup(ti);
3356 int num_page_entries;
3357 int last_game_status = game_status; /* save current game status */
3358 boolean position_set_by_scrollbar = (dx == 999);
3361 /* force LEVELS draw offset on choose level and artwork setup screen */
3362 game_status = GAME_MODE_LEVELS;
3365 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3366 num_page_entries = num_entries;
3368 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3370 game_status = last_game_status; /* restore current game status */
3372 if (button == MB_MENU_INITIALIZE)
3374 int num_entries = numTreeInfoInGroup(ti);
3375 int entry_pos = posTreeInfo(ti);
3377 if (ti->cl_first == -1)
3379 /* only on initialization */
3380 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3381 ti->cl_cursor = entry_pos - ti->cl_first;
3383 else if (ti->cl_cursor >= num_page_entries ||
3384 (num_entries > num_page_entries &&
3385 num_entries - ti->cl_first < num_page_entries))
3387 /* only after change of list size (by custom graphic configuration) */
3388 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3389 ti->cl_cursor = entry_pos - ti->cl_first;
3392 if (position_set_by_scrollbar)
3395 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3398 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3399 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3400 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3404 else if (button == MB_MENU_LEAVE)
3408 PlaySound(SND_MENU_ITEM_SELECTING);
3410 if (ti->node_parent)
3412 *ti_ptr = ti->node_parent;
3413 DrawChooseTree(ti_ptr);
3415 else if (game_status == GAME_MODE_SETUP)
3417 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3419 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3420 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3421 execSetupGraphics();
3427 game_status = GAME_MODE_MAIN;
3429 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3435 if (mx || my) /* mouse input */
3437 int last_game_status = game_status; /* save current game status */
3440 /* force LEVELS draw offset on artwork setup screen */
3441 game_status = GAME_MODE_LEVELS;
3444 x = (mx - mSX) / 32;
3445 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3447 game_status = last_game_status; /* restore current game status */
3449 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3451 /* move cursor instead of scrolling when already at start/end of list */
3452 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3454 else if (dy == +1 * SCROLL_LINE &&
3455 ti->cl_first + num_page_entries == num_entries)
3458 /* handle scrolling screen one line or page */
3459 if (ti->cl_cursor + dy < 0 ||
3460 ti->cl_cursor + dy > num_page_entries - 1)
3462 if (ABS(dy) == SCROLL_PAGE)
3463 step = num_page_entries - 1;
3465 if (dy < 0 && ti->cl_first > 0)
3467 /* scroll page/line up */
3469 ti->cl_first -= step;
3470 if (ti->cl_first < 0)
3473 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3474 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3475 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3477 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3480 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3482 /* scroll page/line down */
3484 ti->cl_first += step;
3485 if (ti->cl_first + num_page_entries > num_entries)
3486 ti->cl_first = MAX(0, num_entries - num_page_entries);
3488 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3489 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3490 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3492 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3499 /* handle moving cursor one line */
3500 y = ti->cl_cursor + dy;
3505 TreeInfo *node_first, *node_cursor;
3506 int entry_pos = ti->cl_first + y;
3508 node_first = getTreeInfoFirstGroupEntry(ti);
3509 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3511 if (node_cursor->node_group)
3515 PlaySound(SND_MENU_ITEM_SELECTING);
3517 node_cursor->cl_first = ti->cl_first;
3518 node_cursor->cl_cursor = ti->cl_cursor;
3519 *ti_ptr = node_cursor->node_group;
3520 DrawChooseTree(ti_ptr);
3525 else if (dx == -1 && ti->node_parent)
3529 PlaySound(SND_MENU_ITEM_SELECTING);
3531 *ti_ptr = ti->node_parent;
3532 DrawChooseTree(ti_ptr);
3537 if (!anyScrollbarGadgetActive() &&
3538 IN_VIS_FIELD(x, y) &&
3539 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3540 y >= 0 && y < num_page_entries)
3544 if (y != ti->cl_cursor)
3546 PlaySound(SND_MENU_ITEM_ACTIVATING);
3548 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3549 drawChooseTreeCursor(y, TRUE);
3550 drawChooseTreeInfo(ti->cl_first + y, ti);
3557 TreeInfo *node_first, *node_cursor;
3558 int entry_pos = ti->cl_first + y;
3560 PlaySound(SND_MENU_ITEM_SELECTING);
3562 node_first = getTreeInfoFirstGroupEntry(ti);
3563 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3565 if (node_cursor->node_group)
3569 node_cursor->cl_first = ti->cl_first;
3570 node_cursor->cl_cursor = ti->cl_cursor;
3571 *ti_ptr = node_cursor->node_group;
3572 DrawChooseTree(ti_ptr);
3574 else if (node_cursor->parent_link)
3578 *ti_ptr = node_cursor->node_parent;
3579 DrawChooseTree(ti_ptr);
3583 FadeSetEnterScreen();
3585 node_cursor->cl_first = ti->cl_first;
3586 node_cursor->cl_cursor = ti->cl_cursor;
3587 *ti_ptr = node_cursor;
3589 if (ti->type == TREE_TYPE_LEVEL_DIR)
3591 LoadLevelSetup_SeriesInfo();
3593 SaveLevelSetup_LastSeries();
3594 SaveLevelSetup_SeriesInfo();
3598 if (game_status == GAME_MODE_SETUP)
3600 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3602 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3603 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3604 execSetupGraphics();
3610 game_status = GAME_MODE_MAIN;
3618 void DrawChooseLevel()
3620 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3622 DrawChooseTree(&leveldir_current);
3628 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3630 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3635 void DrawHallOfFame(int highlight_position)
3638 FadeSoundsAndMusic();
3640 /* (this is needed when called from GameEnd() after winning a game) */
3641 KeyboardAutoRepeatOn();
3644 /* (this is needed when called from GameEnd() after winning a game) */
3645 SetDrawDeactivationMask(REDRAW_NONE);
3646 SetDrawBackgroundMask(REDRAW_FIELD);
3648 CloseDoor(DOOR_CLOSE_2);
3650 if (highlight_position < 0)
3651 LoadScore(level_nr);
3653 FadeSetEnterScreen();
3655 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3658 FadeOut(REDRAW_FIELD);
3666 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3669 FadeIn(REDRAW_FIELD);
3673 static void drawHallOfFameList(int first_entry, int highlight_position)
3677 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3680 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3681 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3682 "HighScores of Level %d", level_nr);
3684 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3686 int entry = first_entry + i;
3687 boolean active = (entry == highlight_position);
3688 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3689 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3690 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3691 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3692 int dx1 = 3 * getFontWidth(font_nr1);
3693 int dx2 = dx1 + getFontWidth(font_nr1);
3694 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3695 int sy = mSY + 64 + i * 32;
3697 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3698 DrawText(mSX + dx1, sy, ".", font_nr1);
3699 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3701 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3702 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3704 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3707 redraw_mask |= REDRAW_FIELD;
3710 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3712 static int first_entry = 0;
3713 static int highlight_position = 0;
3714 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3716 if (button == MB_MENU_INITIALIZE)
3719 highlight_position = mx;
3720 drawHallOfFameList(first_entry, highlight_position);
3725 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3726 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3730 if (first_entry > 0)
3732 first_entry -= step;
3733 if (first_entry < 0)
3736 drawHallOfFameList(first_entry, highlight_position);
3741 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3743 first_entry += step;
3744 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3745 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3747 drawHallOfFameList(first_entry, highlight_position);
3750 else if (button == MB_MENU_LEAVE)
3752 PlaySound(SND_MENU_ITEM_SELECTING);
3754 FadeSound(SND_BACKGROUND_SCORES);
3756 game_status = GAME_MODE_MAIN;
3760 else if (button == MB_MENU_CHOICE)
3762 PlaySound(SND_MENU_ITEM_SELECTING);
3764 FadeSound(SND_BACKGROUND_SCORES);
3767 FadeOut(REDRAW_FIELD);
3770 game_status = GAME_MODE_MAIN;
3772 DrawAndFadeInMainMenu(REDRAW_FIELD);
3775 if (game_status == GAME_MODE_SCORES)
3776 PlayMenuSoundIfLoop();
3782 /* ========================================================================= */
3783 /* setup screen functions */
3784 /* ========================================================================= */
3786 static struct TokenInfo *setup_info;
3787 static int num_setup_info;
3789 static char *screen_mode_text;
3790 static char *scroll_delay_text;
3791 static char *game_speed_text;
3792 static char *graphics_set_name;
3793 static char *sounds_set_name;
3794 static char *music_set_name;
3796 static void execSetupMain()
3798 setup_mode = SETUP_MODE_MAIN;
3803 static void execSetupGame()
3805 if (game_speeds == NULL)
3809 for (i = 0; game_speeds_list[i].value != -1; i++)
3811 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3812 char identifier[32], name[32];
3813 int value = game_speeds_list[i].value;
3814 char *text = game_speeds_list[i].text;
3816 ti->node_top = &game_speeds;
3817 ti->sort_priority = 10000 - value;
3819 sprintf(identifier, "%d", value);
3820 sprintf(name, "%s", text);
3822 setString(&ti->identifier, identifier);
3823 setString(&ti->name, name);
3824 setString(&ti->name_sorting, name);
3825 setString(&ti->infotext, "Game Speed");
3827 pushTreeInfo(&game_speeds, ti);
3830 /* sort game speed values to start with slowest game speed */
3831 sortTreeInfo(&game_speeds);
3833 /* set current game speed to configured game speed value */
3834 game_speed_current =
3835 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3837 /* if that fails, set current game speed to reliable default value */
3838 if (game_speed_current == NULL)
3839 game_speed_current =
3840 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3842 /* if that also fails, set current game speed to first available speed */
3843 if (game_speed_current == NULL)
3844 game_speed_current = game_speeds;
3847 setup.game_frame_delay = atoi(game_speed_current->identifier);
3849 /* needed for displaying game speed text instead of identifier */
3850 game_speed_text = game_speed_current->name;
3852 setup_mode = SETUP_MODE_GAME;
3857 static void execSetupChooseGameSpeed()
3859 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3864 static void execSetupEditor()
3866 setup_mode = SETUP_MODE_EDITOR;
3871 static void execSetupGraphics()
3873 if (video.fullscreen_available && screen_modes == NULL)
3877 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3879 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3880 char identifier[32], name[32];
3881 int x = video.fullscreen_modes[i].width;
3882 int y = video.fullscreen_modes[i].height;
3885 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3887 ti->node_top = &screen_modes;
3888 ti->sort_priority = x * 10000 + y;
3890 sprintf(identifier, "%dx%d", x, y);
3891 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3893 setString(&ti->identifier, identifier);
3894 setString(&ti->name, name);
3895 setString(&ti->name_sorting, name);
3896 setString(&ti->infotext, "Fullscreen Mode");
3898 pushTreeInfo(&screen_modes, ti);
3901 /* sort fullscreen modes to start with lowest available screen resolution */
3902 sortTreeInfo(&screen_modes);
3904 /* set current screen mode for fullscreen mode to configured setup value */
3905 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3906 setup.fullscreen_mode);
3908 /* if that fails, set current screen mode to reliable default value */
3909 if (screen_mode_current == NULL)
3910 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3911 DEFAULT_FULLSCREEN_MODE);
3913 /* if that also fails, set current screen mode to first available mode */
3914 if (screen_mode_current == NULL)
3915 screen_mode_current = screen_modes;
3917 if (screen_mode_current == NULL)
3918 video.fullscreen_available = FALSE;
3921 if (video.fullscreen_available)
3923 setup.fullscreen_mode = screen_mode_current->identifier;
3925 /* needed for displaying screen mode name instead of identifier */
3926 screen_mode_text = screen_mode_current->name;
3930 if (scroll_delays == NULL)
3934 for (i = 0; scroll_delays_list[i].value != -1; i++)
3936 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3937 char identifier[32], name[32];
3938 int value = scroll_delays_list[i].value;
3939 char *text = scroll_delays_list[i].text;
3941 ti->node_top = &scroll_delays;
3942 ti->sort_priority = value;
3944 sprintf(identifier, "%d", value);
3945 sprintf(name, "%s", text);
3947 setString(&ti->identifier, identifier);
3948 setString(&ti->name, name);
3949 setString(&ti->name_sorting, name);
3950 setString(&ti->infotext, "Scroll Delay");
3952 pushTreeInfo(&scroll_delays, ti);
3955 /* sort scroll delay values to start with lowest scroll delay value */
3956 sortTreeInfo(&scroll_delays);
3958 /* set current scroll delay value to configured scroll delay value */
3959 scroll_delay_current =
3960 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
3962 /* if that fails, set current scroll delay to reliable default value */
3963 if (scroll_delay_current == NULL)
3964 scroll_delay_current =
3965 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
3967 /* if that also fails, set current scroll delay to first available value */
3968 if (scroll_delay_current == NULL)
3969 scroll_delay_current = scroll_delays;
3972 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
3974 /* needed for displaying scroll delay text instead of identifier */
3975 scroll_delay_text = scroll_delay_current->name;
3978 setup_mode = SETUP_MODE_GRAPHICS;
3982 static void execSetupChooseScreenMode()
3984 if (!video.fullscreen_available)
3987 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
3992 static void execSetupChooseScrollDelay()
3994 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
3999 static void execSetupSound()
4001 setup_mode = SETUP_MODE_SOUND;
4006 static void execSetupArtwork()
4008 setup.graphics_set = artwork.gfx_current->identifier;
4009 setup.sounds_set = artwork.snd_current->identifier;
4010 setup.music_set = artwork.mus_current->identifier;
4012 /* needed if last screen (setup choice) changed graphics, sounds or music */
4013 ReloadCustomArtwork(0);
4015 /* needed for displaying artwork name instead of artwork identifier */
4016 graphics_set_name = artwork.gfx_current->name;
4017 sounds_set_name = artwork.snd_current->name;
4018 music_set_name = artwork.mus_current->name;
4020 setup_mode = SETUP_MODE_ARTWORK;
4025 static void execSetupChooseGraphics()
4027 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4032 static void execSetupChooseSounds()
4034 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4039 static void execSetupChooseMusic()
4041 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4046 static void execSetupInput()
4048 setup_mode = SETUP_MODE_INPUT;
4053 static void execSetupShortcuts1()
4055 setup_mode = SETUP_MODE_SHORTCUTS_1;
4060 static void execSetupShortcuts2()
4062 setup_mode = SETUP_MODE_SHORTCUTS_2;
4067 static void execExitSetup()
4069 game_status = GAME_MODE_MAIN;
4071 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4074 static void execSaveAndExitSetup()
4080 static struct TokenInfo setup_info_main[] =
4082 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4083 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4084 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4085 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4086 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4087 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4088 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4089 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4090 { TYPE_EMPTY, NULL, "" },
4091 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4092 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4097 static struct TokenInfo setup_info_game[] =
4099 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4100 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4101 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4102 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4103 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4104 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4105 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4106 { TYPE_STRING, &game_speed_text, "" },
4107 { TYPE_EMPTY, NULL, "" },
4108 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4113 static struct TokenInfo setup_info_editor[] =
4116 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4117 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4118 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4119 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4120 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4121 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4122 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4123 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4125 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4126 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4127 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4129 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4131 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4132 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4133 { TYPE_EMPTY, NULL, "" },
4135 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4136 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4137 { TYPE_EMPTY, NULL, "" },
4139 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4140 { TYPE_EMPTY, NULL, "" },
4141 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4146 static struct TokenInfo setup_info_graphics[] =
4148 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4149 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4150 { TYPE_STRING, &screen_mode_text, "" },
4152 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4154 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4155 { TYPE_STRING, &scroll_delay_text, "" },
4157 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4159 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4160 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4161 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4162 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4163 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4164 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4165 { TYPE_EMPTY, NULL, "" },
4166 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4171 static struct TokenInfo setup_info_sound[] =
4173 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4174 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4175 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4176 { TYPE_EMPTY, NULL, "" },
4177 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4182 static struct TokenInfo setup_info_artwork[] =
4184 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4185 { TYPE_STRING, &graphics_set_name, "" },
4186 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4187 { TYPE_STRING, &sounds_set_name, "" },
4188 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4189 { TYPE_STRING, &music_set_name, "" },
4190 { TYPE_EMPTY, NULL, "" },
4192 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4193 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4194 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4196 { TYPE_STRING, NULL, "Override Level Artwork:"},
4197 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4198 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4199 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4201 { TYPE_EMPTY, NULL, "" },
4202 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4207 static struct TokenInfo setup_info_input[] =
4209 { TYPE_SWITCH, NULL, "Player:" },
4210 { TYPE_SWITCH, NULL, "Device:" },
4211 { TYPE_ENTER_MENU, NULL, "" },
4212 { TYPE_EMPTY, NULL, "" },
4213 { TYPE_EMPTY, NULL, "" },
4214 { TYPE_EMPTY, NULL, "" },
4215 { TYPE_EMPTY, NULL, "" },
4216 { TYPE_EMPTY, NULL, "" },
4217 { TYPE_EMPTY, NULL, "" },
4218 { TYPE_EMPTY, NULL, "" },
4219 { TYPE_EMPTY, NULL, "" },
4220 { TYPE_EMPTY, NULL, "" },
4221 { TYPE_EMPTY, NULL, "" },
4222 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4227 static struct TokenInfo setup_info_shortcuts_1[] =
4229 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4230 { TYPE_KEY, &setup.shortcut.save_game, "" },
4231 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4232 { TYPE_KEY, &setup.shortcut.load_game, "" },
4233 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4234 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4235 { TYPE_EMPTY, NULL, "" },
4236 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4237 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4238 { TYPE_EMPTY, NULL, "" },
4239 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4244 static struct TokenInfo setup_info_shortcuts_2[] =
4246 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4247 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4248 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4249 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4250 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4251 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4252 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4253 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4254 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4255 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4256 { TYPE_EMPTY, NULL, "" },
4257 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4262 static Key getSetupKey()
4264 Key key = KSYM_UNDEFINED;
4265 boolean got_key_event = FALSE;
4267 while (!got_key_event)
4269 if (PendingEvent()) /* got event */
4277 case EVENT_KEYPRESS:
4279 key = GetEventKey((KeyEvent *)&event, TRUE);
4281 /* press 'Escape' or 'Enter' to keep the existing key binding */
4282 if (key == KSYM_Escape || key == KSYM_Return)
4283 key = KSYM_UNDEFINED; /* keep old value */
4285 got_key_event = TRUE;
4289 case EVENT_KEYRELEASE:
4290 key_joystick_mapping = 0;
4294 HandleOtherEvents(&event);
4302 /* don't eat all CPU time */
4309 static int getSetupTextFont(int type)
4311 if (type & (TYPE_SWITCH |
4322 static int getSetupValueFont(int type, void *value)
4324 if (type & TYPE_KEY)
4325 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4326 else if (type & TYPE_STRING)
4327 return FONT_VALUE_2;
4328 else if (type & TYPE_ECS_AGA)
4329 return FONT_VALUE_1;
4330 else if (type & TYPE_BOOLEAN_STYLE)
4331 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4333 return FONT_VALUE_1;
4336 static void drawSetupValue(int pos)
4338 boolean font_draw_xoffset_modified = FALSE;
4339 int font_draw_xoffset_old = -1;
4340 int xpos = MENU_SCREEN_VALUE_XPOS;
4341 int ypos = MENU_SCREEN_START_YPOS + pos;
4342 int startx = mSX + xpos * 32;
4343 int starty = mSY + ypos * 32;
4344 int font_nr, font_width;
4345 int type = setup_info[pos].type;
4346 void *value = setup_info[pos].value;
4347 char *value_string = getSetupValue(type, value);
4350 if (value_string == NULL)
4353 if (type & TYPE_KEY)
4355 xpos = MENU_SCREEN_START_XPOS;
4357 if (type & TYPE_QUERY)
4359 value_string = "<press key>";
4362 else if (type & TYPE_STRING)
4364 int max_value_len = (SCR_FIELDX - 2) * 2;
4366 xpos = MENU_SCREEN_START_XPOS;
4368 if (strlen(value_string) > max_value_len)
4369 value_string[max_value_len] = '\0';
4372 startx = mSX + xpos * 32;
4373 starty = mSY + ypos * 32;
4374 font_nr = getSetupValueFont(type, value);
4375 font_width = getFontWidth(font_nr);
4377 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4378 if (setup_mode != SETUP_MODE_INPUT)
4380 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4381 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4382 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4383 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4384 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4385 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4386 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4387 boolean correct_font_draw_xoffset = FALSE;
4389 if (xpos == MENU_SCREEN_START_XPOS &&
4390 startx + font1_xoffset < text_startx + text_font_xoffset)
4391 correct_font_draw_xoffset = TRUE;
4393 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4394 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4395 correct_font_draw_xoffset = TRUE;
4397 /* check if setup value would overlap with setup text when printed */
4398 /* (this can happen for extreme/wrong values for font draw offset) */
4399 if (correct_font_draw_xoffset)
4401 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4402 font_draw_xoffset_modified = TRUE;
4404 if (type & TYPE_KEY)
4405 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4406 else if (!(type & TYPE_STRING))
4407 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4408 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4412 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4413 DrawText(startx + i * font_width, starty, " ", font_nr);
4415 DrawText(startx, starty, value_string, font_nr);
4417 if (font_draw_xoffset_modified)
4418 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4421 static void changeSetupValue(int pos)
4423 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4425 *(boolean *)setup_info[pos].value ^= TRUE;
4427 else if (setup_info[pos].type & TYPE_KEY)
4431 setup_info[pos].type |= TYPE_QUERY;
4432 drawSetupValue(pos);
4433 setup_info[pos].type &= ~TYPE_QUERY;
4435 key = getSetupKey();
4436 if (key != KSYM_UNDEFINED)
4437 *(Key *)setup_info[pos].value = key;
4440 drawSetupValue(pos);
4443 static void DrawCursorAndText_Setup(int pos, boolean active)
4445 int xpos = MENU_SCREEN_START_XPOS;
4446 int ypos = MENU_SCREEN_START_YPOS + pos;
4447 int font_nr = getSetupTextFont(setup_info[pos].type);
4449 if (setup_info == setup_info_input)
4450 font_nr = FONT_MENU_1;
4453 font_nr = FONT_ACTIVE(font_nr);
4455 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4457 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4458 drawCursor(pos, active);
4461 static void DrawSetupScreen_Generic()
4463 boolean redraw_all = FALSE;
4464 char *title_string = NULL;
4468 CloseDoor(DOOR_CLOSE_2);
4470 if (redraw_mask & REDRAW_ALL)
4474 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4475 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4476 int2str(0, redraw_mask)));
4480 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4481 FadeOut(redraw_mask);
4483 FadeOut(REDRAW_FIELD);
4488 if (setup_mode == SETUP_MODE_MAIN)
4490 setup_info = setup_info_main;
4491 title_string = "Setup";
4493 else if (setup_mode == SETUP_MODE_GAME)
4495 setup_info = setup_info_game;
4496 title_string = "Setup Game";
4498 else if (setup_mode == SETUP_MODE_EDITOR)
4500 setup_info = setup_info_editor;
4501 title_string = "Setup Editor";
4503 else if (setup_mode == SETUP_MODE_GRAPHICS)
4505 setup_info = setup_info_graphics;
4506 title_string = "Setup Graphics";
4508 else if (setup_mode == SETUP_MODE_SOUND)
4510 setup_info = setup_info_sound;
4511 title_string = "Setup Sound";
4513 else if (setup_mode == SETUP_MODE_ARTWORK)
4515 setup_info = setup_info_artwork;
4516 title_string = "Custom Artwork";
4518 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4520 setup_info = setup_info_shortcuts_1;
4521 title_string = "Setup Shortcuts";
4523 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4525 setup_info = setup_info_shortcuts_2;
4526 title_string = "Setup Shortcuts";
4529 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4533 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4535 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4538 void *value_ptr = setup_info[i].value;
4540 /* set some entries to "unchangeable" according to other variables */
4541 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4542 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4543 (value_ptr == &setup.sound_music && !audio.music_available) ||
4544 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4545 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4546 setup_info[i].type |= TYPE_GHOSTED;
4548 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4549 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4550 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4551 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4552 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4553 initCursor(i, IMG_MENU_BUTTON);
4555 DrawCursorAndText_Setup(i, FALSE);
4557 if (setup_info[i].type & TYPE_VALUE)
4564 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4565 "Joysticks deactivated in setup menu");
4569 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4573 redraw_mask = REDRAW_ALL;
4576 FadeIn(redraw_mask);
4578 FadeIn(REDRAW_FIELD);
4583 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4587 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4589 static int choice_store[MAX_SETUP_MODES];
4590 int choice = choice_store[setup_mode]; /* always starts with 0 */
4594 if (button == MB_MENU_INITIALIZE)
4596 /* advance to first valid menu entry */
4597 while (choice < num_setup_info &&
4598 setup_info[choice].type & TYPE_SKIP_ENTRY)
4600 choice_store[setup_mode] = choice;
4602 DrawCursorAndText_Setup(choice, TRUE);
4606 else if (button == MB_MENU_LEAVE)
4608 PlaySound(SND_MENU_ITEM_SELECTING);
4610 for (y = 0; y < num_setup_info; y++)
4612 if (setup_info[y].type & TYPE_LEAVE_MENU)
4614 void (*menu_callback_function)(void) = setup_info[y].value;
4618 menu_callback_function();
4620 break; /* absolutely needed because function changes 'setup_info'! */
4627 if (mx || my) /* mouse input */
4629 x = (mx - mSX) / 32;
4630 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4632 else if (dx || dy) /* keyboard input */
4636 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4638 if (setup_info[choice].type & menu_navigation_type ||
4639 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
4640 button = MB_MENU_CHOICE;
4645 /* jump to next non-empty menu entry (up or down) */
4646 while (y > 0 && y < num_setup_info - 1 &&
4647 setup_info[y].type & TYPE_SKIP_ENTRY)
4651 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4655 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4657 PlaySound(SND_MENU_ITEM_ACTIVATING);
4659 DrawCursorAndText_Setup(choice, FALSE);
4660 DrawCursorAndText_Setup(y, TRUE);
4662 choice = choice_store[setup_mode] = y;
4665 else if (!(setup_info[y].type & TYPE_GHOSTED))
4667 PlaySound(SND_MENU_ITEM_SELECTING);
4669 /* when selecting key headline, execute function for key value change */
4670 if (setup_info[y].type & TYPE_KEYTEXT &&
4671 setup_info[y + 1].type & TYPE_KEY)
4674 /* when selecting string value, execute function for list selection */
4675 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4676 setup_info[y - 1].type & TYPE_ENTER_LIST)
4679 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4681 void (*menu_callback_function)(void) = setup_info[y].value;
4683 FadeSetFromType(setup_info[y].type);
4685 menu_callback_function();
4689 if (setup_info[y].type & TYPE_VALUE)
4690 changeSetupValue(y);
4696 void DrawSetupScreen_Input()
4701 FadeOut(REDRAW_FIELD);
4707 setup_info = setup_info_input;
4710 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4714 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4715 "Joysticks deactivated on this screen");
4717 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4718 "Joysticks deactivated on this screen");
4723 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4725 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4728 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4729 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4730 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4731 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4732 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4733 initCursor(i, IMG_MENU_BUTTON);
4735 DrawCursorAndText_Setup(i, FALSE);
4739 DeactivateJoystickForCalibration();
4744 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4745 "Joysticks deactivated on this screen");
4747 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4748 "Joysticks deactivated on this screen");
4752 /* create gadgets for setup input menu screen */
4753 FreeScreenGadgets();
4754 CreateScreenGadgets();
4756 /* map gadgets for setup input menu screen */
4757 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4759 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4762 FadeIn(REDRAW_FIELD);
4768 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4770 if (device_name == NULL)
4773 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4776 if (strlen(device_name) > 1)
4778 char c1 = device_name[strlen(device_name) - 1];
4779 char c2 = device_name[strlen(device_name) - 2];
4781 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4782 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4785 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4786 strlen(device_name));
4789 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4792 static struct SetupKeyboardInfo custom_key;
4799 { &custom_key.left, "Joystick Left" },
4800 { &custom_key.right, "Joystick Right" },
4801 { &custom_key.up, "Joystick Up" },
4802 { &custom_key.down, "Joystick Down" },
4803 { &custom_key.snap, "Button 1" },
4804 { &custom_key.drop, "Button 2" }
4806 static char *joystick_name[MAX_PLAYERS] =
4813 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4817 custom_key = setup.input[player_nr].key;
4819 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4820 FONT_INPUT_1_ACTIVE);
4822 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4824 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4825 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4827 if (setup.input[player_nr].use_joystick)
4829 char *device_name = setup.input[player_nr].joy.device_name;
4830 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4831 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4833 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4834 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4838 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4839 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4842 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4844 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4845 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4846 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4847 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4849 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4850 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4851 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4852 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4853 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4854 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4856 for (i = 0; i < 6; i++)
4858 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4860 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4862 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4863 (setup.input[player_nr].use_joystick ?
4865 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4869 static int input_player_nr = 0;
4871 void HandleSetupScreen_Input_Player(int step, int direction)
4873 int old_player_nr = input_player_nr;
4876 new_player_nr = old_player_nr + step * direction;
4877 if (new_player_nr < 0)
4879 if (new_player_nr > MAX_PLAYERS - 1)
4880 new_player_nr = MAX_PLAYERS - 1;
4882 if (new_player_nr != old_player_nr)
4884 input_player_nr = new_player_nr;
4886 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4890 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
4892 static int choice = 0;
4895 int pos_start = SETUPINPUT_SCREEN_POS_START;
4896 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
4897 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
4898 int pos_end = SETUPINPUT_SCREEN_POS_END;
4900 if (button == MB_MENU_INITIALIZE)
4902 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
4904 DrawCursorAndText_Setup(choice, TRUE);
4908 else if (button == MB_MENU_LEAVE)
4910 setup_mode = SETUP_MODE_MAIN;
4917 if (mx || my) /* mouse input */
4919 x = (mx - mSX) / 32;
4920 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4922 else if (dx || dy) /* keyboard input */
4924 if (dx && choice == 0)
4925 x = (dx < 0 ? 10 : 12);
4926 else if ((dx && choice == 1) ||
4927 (dx == +1 && choice == 2) ||
4928 (dx == -1 && choice == pos_end))
4929 button = MB_MENU_CHOICE;
4933 if (y >= pos_empty1 && y <= pos_empty2)
4934 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
4937 if (y == 0 && dx != 0 && button)
4939 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
4941 else if (IN_VIS_FIELD(x, y) &&
4942 y >= pos_start && y <= pos_end &&
4943 !(y >= pos_empty1 && y <= pos_empty2))
4949 DrawCursorAndText_Setup(choice, FALSE);
4950 DrawCursorAndText_Setup(y, TRUE);
4952 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
4961 char *device_name = setup.input[input_player_nr].joy.device_name;
4963 if (!setup.input[input_player_nr].use_joystick)
4965 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
4967 setJoystickDeviceToNr(device_name, new_device_nr);
4968 setup.input[input_player_nr].use_joystick = TRUE;
4972 int device_nr = getJoystickNrFromDeviceName(device_name);
4973 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
4975 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
4976 setup.input[input_player_nr].use_joystick = FALSE;
4978 setJoystickDeviceToNr(device_name, new_device_nr);
4981 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4985 if (setup.input[input_player_nr].use_joystick)
4988 CalibrateJoystick(input_player_nr);
4991 CustomizeKeyboard(input_player_nr);
4993 else if (y == pos_end)
4999 setup_mode = SETUP_MODE_MAIN;
5006 void CustomizeKeyboard(int player_nr)
5010 boolean finished = FALSE;
5011 static struct SetupKeyboardInfo custom_key;
5016 } customize_step[] =
5018 { &custom_key.left, "Move Left" },
5019 { &custom_key.right, "Move Right" },
5020 { &custom_key.up, "Move Up" },
5021 { &custom_key.down, "Move Down" },
5022 { &custom_key.snap, "Snap Field" },
5023 { &custom_key.drop, "Drop Element" }
5026 /* read existing key bindings from player setup */
5027 custom_key = setup.input[player_nr].key;
5030 FadeOut(REDRAW_FIELD);
5034 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5042 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5043 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5044 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5045 "Key:", FONT_INPUT_1_ACTIVE);
5046 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5047 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5050 FadeIn(REDRAW_FIELD);
5057 if (PendingEvent()) /* got event */
5065 case EVENT_KEYPRESS:
5067 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5069 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5071 if (key == KSYM_Escape)
5072 FadeSkipNextFadeIn();
5078 /* all keys configured -- wait for "Escape" or "Return" key */
5082 /* press 'Enter' to keep the existing key binding */
5083 if (key == KSYM_Return)
5084 key = *customize_step[step_nr].key;
5086 /* check if key already used */
5087 for (i = 0; i < step_nr; i++)
5088 if (*customize_step[i].key == key)
5093 /* got new key binding */
5094 *customize_step[step_nr].key = key;
5095 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5097 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5098 getKeyNameFromKey(key), FONT_VALUE_1);
5101 /* un-highlight last query */
5102 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5103 customize_step[step_nr - 1].text, FONT_MENU_1);
5104 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5105 "Key:", FONT_MENU_1);
5107 /* press 'Enter' to leave */
5110 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5111 "Press Enter", FONT_TITLE_1);
5115 /* query next key binding */
5116 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5117 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5118 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5119 "Key:", FONT_INPUT_1_ACTIVE);
5120 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5121 getKeyNameFromKey(*customize_step[step_nr].key),
5126 case EVENT_KEYRELEASE:
5127 key_joystick_mapping = 0;
5131 HandleOtherEvents(&event);
5139 /* don't eat all CPU time */
5143 /* write new key bindings back to player setup */
5144 setup.input[player_nr].key = custom_key;
5147 DrawSetupScreen_Input();
5150 static boolean CalibrateJoystickMain(int player_nr)
5152 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5153 int new_joystick_xright = JOYSTICK_XMIDDLE;
5154 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5155 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5156 int new_joystick_xmiddle, new_joystick_ymiddle;
5158 int joystick_fd = joystick.fd[player_nr];
5159 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5160 boolean check[3][3];
5161 int check_remaining = 3 * 3;
5166 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5169 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5173 FadeOut(REDRAW_FIELD);
5177 for (y = 0; y < 3; y++)
5179 for (x = 0; x < 3; x++)
5181 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5182 check[x][y] = FALSE;
5186 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5187 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5188 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5189 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5190 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5191 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5192 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5194 joy_value = Joystick(player_nr);
5195 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5196 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5198 /* eventually uncalibrated center position (joystick could be uncentered) */
5199 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5202 new_joystick_xmiddle = joy_x;
5203 new_joystick_ymiddle = joy_y;
5205 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5207 FadeIn(REDRAW_FIELD);
5209 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5214 if (PendingEvent()) /* got event */
5222 case EVENT_KEYPRESS:
5223 switch (GetEventKey((KeyEvent *)&event, TRUE))
5226 if (check_remaining == 0)
5231 FadeSkipNextFadeIn();
5240 case EVENT_KEYRELEASE:
5241 key_joystick_mapping = 0;
5245 HandleOtherEvents(&event);
5250 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5253 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5254 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5255 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5256 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5258 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5259 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5260 setup.input[player_nr].joy.xright = new_joystick_xright;
5261 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5262 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5263 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5265 CheckJoystickData();
5267 joy_value = Joystick(player_nr);
5269 if (joy_value & JOY_BUTTON && check_remaining == 0)
5272 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5273 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5275 if (x != last_x || y != last_y)
5277 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5278 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5283 if (check_remaining > 0 && !check[x+1][y+1])
5285 check[x+1][y+1] = TRUE;
5291 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5292 setup.input[player_nr].joy.xleft,
5293 setup.input[player_nr].joy.xmiddle,
5294 setup.input[player_nr].joy.xright);
5295 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5296 setup.input[player_nr].joy.yupper,
5297 setup.input[player_nr].joy.ymiddle,
5298 setup.input[player_nr].joy.ylower);
5307 /* don't eat all CPU time */
5311 /* calibrated center position (joystick should now be centered) */
5312 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5315 new_joystick_xmiddle = joy_x;
5316 new_joystick_ymiddle = joy_y;
5321 DrawSetupScreen_Input();
5324 /* wait until the last pressed button was released */
5325 while (Joystick(player_nr) & JOY_BUTTON)
5327 if (PendingEvent()) /* got event */
5332 HandleOtherEvents(&event);
5341 void CalibrateJoystick(int player_nr)
5343 if (!CalibrateJoystickMain(player_nr))
5345 char *device_name = setup.input[player_nr].joy.device_name;
5346 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5347 int xpos = mSX - SX;
5348 int ypos = mSY - SY;
5352 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5353 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5356 Delay(2000); /* show error message for a short time */
5362 DrawSetupScreen_Input();
5366 void DrawSetupScreen()
5368 DeactivateJoystick();
5370 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5372 if (setup_mode == SETUP_MODE_INPUT)
5373 DrawSetupScreen_Input();
5374 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5375 DrawChooseTree(&game_speed_current);
5376 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5377 DrawChooseTree(&screen_mode_current);
5378 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5379 DrawChooseTree(&scroll_delay_current);
5380 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5381 DrawChooseTree(&artwork.gfx_current);
5382 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5383 DrawChooseTree(&artwork.snd_current);
5384 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5385 DrawChooseTree(&artwork.mus_current);
5387 DrawSetupScreen_Generic();
5393 void RedrawSetupScreenAfterFullscreenToggle()
5395 if (setup_mode == SETUP_MODE_GRAPHICS)
5399 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5401 if (setup_mode == SETUP_MODE_INPUT)
5402 HandleSetupScreen_Input(mx, my, dx, dy, button);
5403 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5404 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5405 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5406 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5407 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5408 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5409 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5410 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5411 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5412 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5413 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5414 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5416 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5421 void HandleGameActions()
5423 if (game_status != GAME_MODE_PLAYING)
5426 GameActions(); /* main game loop */
5428 if (tape.auto_play && !tape.playing)
5429 AutoPlayTape(); /* continue automatically playing next tape */
5433 /* ---------- new screen button stuff -------------------------------------- */
5435 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5440 case SCREEN_CTRL_ID_PREV_LEVEL:
5441 *x = mSX + menu.main.button.prev_level.x;
5442 *y = mSY + menu.main.button.prev_level.y;
5445 case SCREEN_CTRL_ID_NEXT_LEVEL:
5446 *x = mSX + menu.main.button.next_level.x;
5447 *y = mSY + menu.main.button.next_level.y;
5450 case SCREEN_CTRL_ID_PREV_LEVEL:
5451 *x = mSX + TILEX * getPrevlevelButtonPos();
5452 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5455 case SCREEN_CTRL_ID_NEXT_LEVEL:
5456 *x = mSX + TILEX * getNextLevelButtonPos();
5457 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5461 case SCREEN_CTRL_ID_PREV_PLAYER:
5462 *x = mSX + TILEX * 10;
5463 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5466 case SCREEN_CTRL_ID_NEXT_PLAYER:
5467 *x = mSX + TILEX * 12;
5468 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5472 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5478 int gfx_unpressed, gfx_pressed;
5479 void (*get_gadget_position)(int *, int *, int);
5483 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5486 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5487 getScreenMenuButtonPos,
5488 SCREEN_CTRL_ID_PREV_LEVEL,
5493 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5494 getScreenMenuButtonPos,
5495 SCREEN_CTRL_ID_NEXT_LEVEL,
5500 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5501 getScreenMenuButtonPos,
5502 SCREEN_CTRL_ID_PREV_PLAYER,
5507 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5508 getScreenMenuButtonPos,
5509 SCREEN_CTRL_ID_NEXT_PLAYER,
5517 int gfx_unpressed, gfx_pressed;
5521 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5524 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5525 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5526 SCREEN_CTRL_ID_SCROLL_UP,
5530 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5531 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5532 SCREEN_CTRL_ID_SCROLL_DOWN,
5539 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5540 Bitmap **gfx_unpressed, **gfx_pressed;
5542 int gfx_unpressed, gfx_pressed;
5549 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5552 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5553 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5555 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5557 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5558 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5559 GD_TYPE_SCROLLBAR_VERTICAL,
5560 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5561 "scroll level series vertically"
5565 static void CreateScreenMenubuttons()
5567 struct GadgetInfo *gi;
5568 unsigned long event_mask;
5571 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5573 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5574 int gfx_unpressed, gfx_pressed;
5575 int x, y, width, height;
5576 int gd_x1, gd_x2, gd_y1, gd_y2;
5577 int id = menubutton_info[i].gadget_id;
5579 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5581 menubutton_info[i].get_gadget_position(&x, &y, id);
5583 width = SC_MENUBUTTON_XSIZE;
5584 height = SC_MENUBUTTON_YSIZE;
5586 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5587 gfx_pressed = menubutton_info[i].gfx_pressed;
5588 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5589 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5590 gd_x1 = graphic_info[gfx_unpressed].src_x;
5591 gd_y1 = graphic_info[gfx_unpressed].src_y;
5592 gd_x2 = graphic_info[gfx_pressed].src_x;
5593 gd_y2 = graphic_info[gfx_pressed].src_y;
5595 gi = CreateGadget(GDI_CUSTOM_ID, id,
5596 GDI_CUSTOM_TYPE_ID, i,
5597 GDI_INFO_TEXT, menubutton_info[i].infotext,
5602 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5603 GDI_STATE, GD_BUTTON_UNPRESSED,
5604 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5605 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5606 GDI_DIRECT_DRAW, FALSE,
5607 GDI_EVENT_MASK, event_mask,
5608 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5612 Error(ERR_EXIT, "cannot create gadget");
5614 screen_gadget[id] = gi;
5618 static void CreateScreenScrollbuttons()
5620 struct GadgetInfo *gi;
5621 unsigned long event_mask;
5624 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5626 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5627 int gfx_unpressed, gfx_pressed;
5628 int x, y, width, height;
5629 int gd_x1, gd_x2, gd_y1, gd_y2;
5630 int id = scrollbutton_info[i].gadget_id;
5632 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5634 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5635 y = mSY + scrollbutton_info[i].y;
5636 width = SC_SCROLLBUTTON_XSIZE;
5637 height = SC_SCROLLBUTTON_YSIZE;
5639 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5640 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5641 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5643 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5644 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5645 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5646 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5647 gd_x1 = graphic_info[gfx_unpressed].src_x;
5648 gd_y1 = graphic_info[gfx_unpressed].src_y;
5649 gd_x2 = graphic_info[gfx_pressed].src_x;
5650 gd_y2 = graphic_info[gfx_pressed].src_y;
5652 gi = CreateGadget(GDI_CUSTOM_ID, id,
5653 GDI_CUSTOM_TYPE_ID, i,
5654 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5659 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5660 GDI_STATE, GD_BUTTON_UNPRESSED,
5661 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5662 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5663 GDI_DIRECT_DRAW, FALSE,
5664 GDI_EVENT_MASK, event_mask,
5665 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5669 Error(ERR_EXIT, "cannot create gadget");
5671 screen_gadget[id] = gi;
5675 static void CreateScreenScrollbars()
5679 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5681 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5682 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5683 int gfx_unpressed, gfx_pressed;
5685 int x, y, width, height;
5686 int gd_x1, gd_x2, gd_y1, gd_y2;
5687 struct GadgetInfo *gi;
5688 int items_max, items_visible, item_position;
5689 unsigned long event_mask;
5690 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5691 int id = scrollbar_info[i].gadget_id;
5693 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5695 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5696 y = mSY + scrollbar_info[i].y;
5697 width = scrollbar_info[i].width;
5698 height = scrollbar_info[i].height;
5700 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5701 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5703 items_max = num_page_entries;
5704 items_visible = num_page_entries;
5707 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5708 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5709 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5715 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5716 gfx_pressed = scrollbar_info[i].gfx_pressed;
5717 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5718 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5719 gd_x1 = graphic_info[gfx_unpressed].src_x;
5720 gd_y1 = graphic_info[gfx_unpressed].src_y;
5721 gd_x2 = graphic_info[gfx_pressed].src_x;
5722 gd_y2 = graphic_info[gfx_pressed].src_y;
5725 gi = CreateGadget(GDI_CUSTOM_ID, id,
5726 GDI_CUSTOM_TYPE_ID, i,
5727 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5732 GDI_TYPE, scrollbar_info[i].type,
5733 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5734 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5735 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5737 GDI_WHEEL_AREA_X, SX,
5738 GDI_WHEEL_AREA_Y, SY,
5739 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5740 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5742 GDI_WHEEL_AREA_X, 0,
5743 GDI_WHEEL_AREA_Y, 0,
5744 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5745 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5747 GDI_STATE, GD_BUTTON_UNPRESSED,
5748 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5749 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5750 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5751 GDI_DIRECT_DRAW, FALSE,
5752 GDI_EVENT_MASK, event_mask,
5753 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5757 Error(ERR_EXIT, "cannot create gadget");
5759 screen_gadget[id] = gi;
5763 void CreateScreenGadgets()
5765 int last_game_status = game_status; /* save current game status */
5767 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5770 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5772 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5774 /* copy pointers to clip mask and GC */
5775 scrollbar_bitmap[i]->clip_mask =
5776 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5777 scrollbar_bitmap[i]->stored_clip_gc =
5778 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5780 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5781 scrollbar_bitmap[i],
5782 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5783 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5784 TILEX, TILEY, 0, 0);
5788 CreateScreenMenubuttons();
5791 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5792 game_status = GAME_MODE_LEVELS;
5795 CreateScreenScrollbuttons();
5796 CreateScreenScrollbars();
5798 game_status = last_game_status; /* restore current game status */
5801 void FreeScreenGadgets()
5805 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5806 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5808 /* prevent freeing clip mask and GC twice */
5809 scrollbar_bitmap[i]->clip_mask = None;
5810 scrollbar_bitmap[i]->stored_clip_gc = None;
5812 FreeBitmap(scrollbar_bitmap[i]);
5816 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5817 FreeGadget(screen_gadget[i]);
5820 void MapScreenMenuGadgets(int screen_mask)
5824 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5825 if (screen_mask & menubutton_info[i].screen_mask)
5826 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5829 void MapScreenTreeGadgets(TreeInfo *ti)
5831 int num_entries = numTreeInfoInGroup(ti);
5834 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5837 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5838 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5840 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5841 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5844 static void HandleScreenGadgets(struct GadgetInfo *gi)
5846 int id = gi->custom_id;
5847 int button = gi->event.button;
5848 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5852 case SCREEN_CTRL_ID_PREV_LEVEL:
5853 HandleMainMenu_SelectLevel(step, -1);
5856 case SCREEN_CTRL_ID_NEXT_LEVEL:
5857 HandleMainMenu_SelectLevel(step, +1);
5860 case SCREEN_CTRL_ID_PREV_PLAYER:
5861 HandleSetupScreen_Input_Player(step, -1);
5864 case SCREEN_CTRL_ID_NEXT_PLAYER:
5865 HandleSetupScreen_Input_Player(step, +1);
5868 case SCREEN_CTRL_ID_SCROLL_UP:
5869 if (game_status == GAME_MODE_LEVELS)
5870 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5871 else if (game_status == GAME_MODE_SETUP)
5872 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5875 case SCREEN_CTRL_ID_SCROLL_DOWN:
5876 if (game_status == GAME_MODE_LEVELS)
5877 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5878 else if (game_status == GAME_MODE_SETUP)
5879 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5882 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5883 if (game_status == GAME_MODE_LEVELS)
5884 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5885 else if (game_status == GAME_MODE_SETUP)
5886 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);