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))
1145 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1146 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1149 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1151 redraw_mask = REDRAW_ALL;
1154 void DrawTitleScreenMessage(int nr, boolean initial)
1156 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1157 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1158 int last_game_status = game_status; /* save current game status */
1160 if (filename == NULL)
1163 /* force TITLE font on title message screen */
1164 game_status = getTitleMessageGameMode(initial);
1166 /* if chars set to "-1", automatically determine by text and font width */
1167 if (tmi->chars == -1)
1168 tmi->chars = tmi->width / getFontWidth(tmi->font);
1170 tmi->width = tmi->chars * getFontWidth(tmi->font);
1172 /* if lines set to "-1", automatically determine by text and font height */
1173 if (tmi->lines == -1)
1174 tmi->lines = tmi->height / getFontHeight(tmi->font);
1176 tmi->height = tmi->lines * getFontHeight(tmi->font);
1178 SetDrawBackgroundMask(REDRAW_ALL);
1179 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1181 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1183 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1184 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1185 tmi->autowrap, tmi->centered, tmi->parse_comments);
1187 game_status = last_game_status; /* restore current game status */
1190 void DrawTitleScreen()
1192 KeyboardAutoRepeatOff();
1195 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1198 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1203 boolean CheckTitleScreen(boolean levelset_has_changed)
1205 static boolean show_title_initial = TRUE;
1206 boolean show_titlescreen = FALSE;
1208 /* needed to be able to skip title screen, if no image or message defined */
1209 InitializeTitleControls(show_title_initial);
1211 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1212 show_titlescreen = TRUE;
1214 /* show initial title images and messages only once at program start */
1215 show_title_initial = FALSE;
1217 return (show_titlescreen && num_title_screens > 0);
1220 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1222 static LevelDirTree *leveldir_last_valid = NULL;
1223 boolean levelset_has_changed = FALSE;
1225 FadeSetLeaveScreen();
1227 /* do not fade out here -- function may continue and fade on editor screen */
1230 FadeSoundsAndMusic();
1232 KeyboardAutoRepeatOn();
1235 SetDrawDeactivationMask(REDRAW_NONE);
1236 SetDrawBackgroundMask(REDRAW_FIELD);
1238 audio.sound_deactivated = FALSE;
1242 /* needed if last screen was the playing screen, invoked from level editor */
1243 if (level_editor_test_game)
1245 game_status = GAME_MODE_EDITOR;
1251 /* needed if last screen was the setup screen and fullscreen state changed */
1252 ToggleFullscreenIfNeeded();
1254 /* leveldir_current may be invalid (level group, parent link) */
1255 if (!validLevelSeries(leveldir_current))
1256 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1258 if (leveldir_current != leveldir_last_valid)
1259 levelset_has_changed = TRUE;
1261 /* store valid level series information */
1262 leveldir_last_valid = leveldir_current;
1264 /* needed if last screen (level choice) changed graphics, sounds or music */
1265 ReloadCustomArtwork(0);
1267 if (redraw_mask & REDRAW_ALL)
1268 fade_mask = REDRAW_ALL;
1273 /* needed if last screen was the editor screen */
1274 UndrawSpecialEditorDoor();
1276 if (fade_mask == REDRAW_FIELD)
1281 #if defined(TARGET_SDL)
1282 SetDrawtoField(DRAW_BACKBUFFER);
1285 if (CheckTitleScreen(levelset_has_changed))
1287 game_status = GAME_MODE_TITLE;
1294 /* level_nr may have been set to value over handicap with level editor */
1295 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1296 level_nr = leveldir_current->handicap_level;
1298 LoadLevel(level_nr);
1299 LoadScore(level_nr);
1301 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1304 if (fade_mask == REDRAW_ALL)
1306 // int door_state = GetDoorState();
1310 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1316 InitializeMainControls();
1318 DrawCursorAndText_Main(-1, FALSE);
1319 DrawPreviewLevel(TRUE);
1321 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1324 if (TAPE_IS_EMPTY(tape))
1326 DrawCompleteVideoDisplay();
1331 /* create gadgets for main menu screen */
1332 FreeScreenGadgets();
1333 CreateScreenGadgets();
1335 /* map gadgets for main menu screen */
1337 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1340 if (fade_mask == REDRAW_ALL)
1342 int door_state = GetDoorState();
1344 // RedrawBackground();
1346 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1350 DrawMaskedBorder(REDRAW_ALL);
1356 /* update screen area with special editor door */
1357 redraw_mask |= REDRAW_ALL;
1361 SetMouseCursor(CURSOR_DEFAULT);
1365 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1368 void DrawAndFadeInMainMenu(int fade_mask)
1370 DrawMainMenuExt(fade_mask, TRUE);
1375 DrawMainMenuExt(REDRAW_ALL, FALSE);
1379 static void gotoTopLevelDir()
1381 /* move upwards to top level directory */
1382 while (leveldir_current->node_parent)
1384 /* write a "path" into level tree for easy navigation to last level */
1385 if (leveldir_current->node_parent->node_group->cl_first == -1)
1387 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1388 int leveldir_pos = posTreeInfo(leveldir_current);
1389 int num_page_entries;
1390 int cl_first, cl_cursor;
1392 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1393 num_page_entries = num_leveldirs;
1395 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1397 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1398 cl_cursor = leveldir_pos - cl_first;
1400 leveldir_current->node_parent->node_group->cl_first = cl_first;
1401 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1404 leveldir_current = leveldir_current->node_parent;
1409 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1411 static unsigned long title_delay = 0;
1412 static int title_screen_nr = 0;
1413 static int last_sound = -1, last_music = -1;
1414 boolean return_to_main_menu = FALSE;
1415 boolean use_fading_main_menu = TRUE;
1416 struct TitleControlInfo *tci;
1417 struct TitleFadingInfo fading_default;
1418 struct TitleFadingInfo fading_last = fading;
1419 struct TitleFadingInfo fading_next;
1422 if (button == MB_MENU_INITIALIZE)
1425 title_screen_nr = 0;
1426 tci = &title_controls[title_screen_nr];
1428 last_sound = SND_UNDEFINED;
1429 last_music = MUS_UNDEFINED;
1431 if (game_status == GAME_MODE_INFO)
1433 if (num_title_screens == 0)
1435 DrawInfoScreen_NotAvailable("Title screen information:",
1436 "No title screen for this level set.");
1441 FadeSoundsAndMusic();
1444 FadeOut(REDRAW_ALL);
1449 DrawTitleScreenImage(tci->local_nr, tci->initial);
1451 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1453 fading_default = (tci->initial ? title_initial_default : title_default);
1455 fading = fading_next = getTitleFading(tci);
1459 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1460 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1462 fading.fade_mode = FADE_MODE_FADE;
1463 fading.fade_delay = fading_default.fade_delay;
1466 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1467 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1468 fading.fade_mode = FADE_MODE_FADE;
1473 sound = getTitleSound(tci);
1474 music = getTitleMusic(tci);
1476 if (sound != last_sound)
1477 PlayMenuSoundExt(sound);
1478 if (music != last_music)
1479 PlayMenuMusicExt(music);
1485 SetMouseCursor(CURSOR_NONE);
1491 fading = fading_next;
1493 DelayReached(&title_delay, 0); /* reset delay counter */
1499 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1500 button = MB_MENU_CHOICE;
1502 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1503 button = MB_MENU_CHOICE;
1506 if (button == MB_MENU_LEAVE)
1508 return_to_main_menu = TRUE;
1509 use_fading_main_menu = FALSE;
1511 else if (button == MB_MENU_CHOICE)
1513 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1516 FadeOut(REDRAW_FIELD);
1519 FadeSetEnterScreen();
1521 info_mode = INFO_MODE_MAIN;
1522 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1528 tci = &title_controls[title_screen_nr];
1530 if (title_screen_nr < num_title_screens)
1532 sound = getTitleSound(tci);
1533 music = getTitleMusic(tci);
1535 if (sound == SND_UNDEFINED || sound != last_sound)
1537 if (music == MUS_UNDEFINED || music != last_music)
1541 FadeOut(REDRAW_ALL);
1545 DrawTitleScreenImage(tci->local_nr, tci->initial);
1547 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1549 fading_next = getTitleFading(tci);
1552 sound = getTitleSound(tci);
1553 music = getTitleMusic(tci);
1555 if (sound != last_sound)
1556 PlayMenuSoundExt(sound);
1557 if (music != last_music)
1558 PlayMenuMusicExt(music);
1565 /* last screen already faded out, next screen has no animation */
1566 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1567 fading_next.fade_mode == FADE_MODE_NONE)
1568 fading = fading_next;
1570 /* last screen already faded out, next screen has no animation */
1571 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1572 fading_next.fade_mode == FADE_MODE_NONE)
1573 fading = fading_next;
1580 fading = fading_next;
1582 DelayReached(&title_delay, 0); /* reset delay counter */
1586 FadeSoundsAndMusic();
1588 return_to_main_menu = TRUE;
1592 if (return_to_main_menu)
1598 SetMouseCursor(CURSOR_DEFAULT);
1600 if (game_status == GAME_MODE_INFO)
1603 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1606 info_mode = INFO_MODE_MAIN;
1607 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1609 else /* default: return to main menu */
1612 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1615 game_status = GAME_MODE_MAIN;
1616 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1621 void HandleMainMenu_SelectLevel(int step, int direction)
1623 int old_level_nr = level_nr;
1626 new_level_nr = old_level_nr + step * direction;
1627 if (new_level_nr < leveldir_current->first_level)
1628 new_level_nr = leveldir_current->first_level;
1629 if (new_level_nr > leveldir_current->last_level)
1630 new_level_nr = leveldir_current->last_level;
1632 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1634 /* skipping levels is only allowed when trying to skip single level */
1635 if (setup.skip_levels && step == 1 &&
1636 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1638 leveldir_current->handicap_level++;
1639 SaveLevelSetup_SeriesInfo();
1642 new_level_nr = leveldir_current->handicap_level;
1645 if (new_level_nr != old_level_nr)
1647 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1649 PlaySound(SND_MENU_ITEM_SELECTING);
1651 level_nr = new_level_nr;
1653 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1654 int2str(level_nr, menu.main.text.level_number.size),
1655 mci->pos_text->font);
1657 LoadLevel(level_nr);
1658 DrawPreviewLevel(TRUE);
1662 DrawCompleteVideoDisplay();
1664 /* needed because DrawPreviewLevel() takes some time */
1670 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1672 static int choice = MAIN_CONTROL_GAME;
1676 if (button == MB_MENU_INITIALIZE)
1678 DrawCursorAndText_Main(choice, TRUE);
1683 if (mx || my) /* mouse input */
1687 for (i = 0; main_controls[i].nr != -1; i++)
1689 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1690 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1691 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1693 pos = main_controls[i].nr;
1699 else if (dx || dy) /* keyboard input */
1701 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1702 choice == MAIN_CONTROL_SETUP))
1703 button = MB_MENU_CHOICE;
1708 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1710 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1712 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1718 PlaySound(SND_MENU_ITEM_ACTIVATING);
1720 DrawCursorAndText_Main(choice, FALSE);
1721 DrawCursorAndText_Main(pos, TRUE);
1728 PlaySound(SND_MENU_ITEM_SELECTING);
1730 if (pos == MAIN_CONTROL_NAME)
1732 game_status = GAME_MODE_PSEUDO_TYPENAME;
1734 HandleTypeName(strlen(setup.player_name), 0);
1736 else if (pos == MAIN_CONTROL_LEVELS)
1740 game_status = GAME_MODE_LEVELS;
1742 SaveLevelSetup_LastSeries();
1743 SaveLevelSetup_SeriesInfo();
1752 else if (pos == MAIN_CONTROL_SCORES)
1754 game_status = GAME_MODE_SCORES;
1758 else if (pos == MAIN_CONTROL_EDITOR)
1760 if (leveldir_current->readonly &&
1761 !strEqual(setup.player_name, "Artsoft"))
1762 Request("This level is read only !", REQ_CONFIRM);
1764 game_status = GAME_MODE_EDITOR;
1766 FadeSetEnterScreen();
1770 else if (pos == MAIN_CONTROL_INFO)
1772 game_status = GAME_MODE_INFO;
1773 info_mode = INFO_MODE_MAIN;
1777 else if (pos == MAIN_CONTROL_GAME)
1779 StartGameActions(options.network, setup.autorecord, level.random_seed);
1781 else if (pos == MAIN_CONTROL_SETUP)
1783 game_status = GAME_MODE_SETUP;
1784 setup_mode = SETUP_MODE_MAIN;
1788 else if (pos == MAIN_CONTROL_QUIT)
1790 SaveLevelSetup_LastSeries();
1791 SaveLevelSetup_SeriesInfo();
1793 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1794 game_status = GAME_MODE_QUIT;
1799 if (game_status == GAME_MODE_MAIN)
1801 DrawPreviewLevel(FALSE);
1807 /* ========================================================================= */
1808 /* info screen functions */
1809 /* ========================================================================= */
1811 static struct TokenInfo *info_info;
1812 static int num_info_info;
1814 static void execInfoTitleScreen()
1816 info_mode = INFO_MODE_TITLE;
1821 static void execInfoElements()
1823 info_mode = INFO_MODE_ELEMENTS;
1828 static void execInfoMusic()
1830 info_mode = INFO_MODE_MUSIC;
1835 static void execInfoCredits()
1837 info_mode = INFO_MODE_CREDITS;
1842 static void execInfoProgram()
1844 info_mode = INFO_MODE_PROGRAM;
1849 static void execInfoVersion()
1851 info_mode = INFO_MODE_VERSION;
1856 static void execInfoLevelSet()
1858 info_mode = INFO_MODE_LEVELSET;
1863 static void execExitInfo()
1865 game_status = GAME_MODE_MAIN;
1867 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1870 static struct TokenInfo info_info_main[] =
1872 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1873 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1874 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1875 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1876 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1877 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1878 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1879 { TYPE_EMPTY, NULL, "" },
1880 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1885 static void DrawCursorAndText_Info(int pos, boolean active)
1887 int xpos = MENU_SCREEN_START_XPOS;
1888 int ypos = MENU_SCREEN_START_YPOS + pos;
1889 int font_nr = FONT_MENU_1;
1892 font_nr = FONT_ACTIVE(font_nr);
1894 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1896 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1897 drawCursor(pos, active);
1900 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1905 CloseDoor(DOOR_CLOSE_2);
1907 /* (needed after displaying title screens which disable auto repeat) */
1908 KeyboardAutoRepeatOn();
1910 FadeSetLeaveScreen();
1917 if (fade_mask == REDRAW_ALL)
1921 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1927 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1929 info_info = info_info_main;
1933 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1935 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1938 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1939 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1940 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1941 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1942 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1943 initCursor(i, IMG_MENU_BUTTON);
1945 DrawCursorAndText_Info(i, FALSE);
1950 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1955 DrawMaskedBorder(fade_mask);
1962 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1964 static int choice_store[MAX_INFO_MODES];
1965 int choice = choice_store[info_mode]; /* always starts with 0 */
1969 if (button == MB_MENU_INITIALIZE)
1971 /* advance to first valid menu entry */
1972 while (choice < num_info_info &&
1973 info_info[choice].type & TYPE_SKIP_ENTRY)
1975 choice_store[info_mode] = choice;
1977 DrawCursorAndText_Info(choice, TRUE);
1981 else if (button == MB_MENU_LEAVE)
1983 for (y = 0; y < num_info_info; y++)
1985 if (info_info[y].type & TYPE_LEAVE_MENU)
1987 void (*menu_callback_function)(void) = info_info[y].value;
1991 menu_callback_function();
1993 break; /* absolutely needed because function changes 'info_info'! */
2000 if (mx || my) /* mouse input */
2002 x = (mx - mSX) / 32;
2003 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2005 else if (dx || dy) /* keyboard input */
2009 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2011 if (info_info[choice].type & menu_navigation_type ||
2012 info_info[choice].type & TYPE_ENTER_SCREEN ||
2013 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2014 info_info[choice].type & TYPE_YES_NO_AUTO)
2015 button = MB_MENU_CHOICE;
2020 /* jump to next non-empty menu entry (up or down) */
2021 while (y > 0 && y < num_info_info - 1 &&
2022 info_info[y].type & TYPE_SKIP_ENTRY)
2026 if (IN_VIS_FIELD(x, y) &&
2027 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2033 PlaySound(SND_MENU_ITEM_ACTIVATING);
2035 DrawCursorAndText_Info(choice, FALSE);
2036 DrawCursorAndText_Info(y, TRUE);
2038 choice = choice_store[info_mode] = y;
2041 else if (!(info_info[y].type & TYPE_GHOSTED))
2043 PlaySound(SND_MENU_ITEM_SELECTING);
2045 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2047 void (*menu_callback_function)(void) = info_info[choice].value;
2049 FadeSetFromType(info_info[y].type);
2051 menu_callback_function();
2057 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2059 int ystart1 = mSY - SY + 100;
2060 int ystart2 = mSY - SY + 150;
2061 int ybottom = mSY - SY + SYSIZE - 20;
2063 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2065 FadeOut(REDRAW_FIELD);
2070 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2071 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2073 DrawTextSCentered(ybottom, FONT_TEXT_4,
2074 "Press any key or button for info menu");
2076 FadeIn(REDRAW_FIELD);
2079 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2081 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2082 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2083 int xstart = mSX + 16;
2084 int ystart1 = mSY - SY + 100;
2085 int ystart2 = mSY + 64 + 2 * 32;
2086 int ybottom = mSY - SY + SYSIZE - 20;
2087 int ystep = TILEY + 4;
2088 int element, action, direction;
2096 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2097 infoscreen_step[i] = infoscreen_frame[i] = 0;
2102 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2104 DrawTextSCentered(ybottom, FONT_TEXT_4,
2105 "Press any key or button for next page");
2111 while (helpanim_info[j].element != HELPANIM_LIST_END)
2113 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2118 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2127 j += infoscreen_step[i - start];
2129 element = helpanim_info[j].element;
2130 action = helpanim_info[j].action;
2131 direction = helpanim_info[j].direction;
2134 element = EL_UNKNOWN;
2136 if (action != -1 && direction != -1)
2137 graphic = el_act_dir2img(element, action, direction);
2138 else if (action != -1)
2139 graphic = el_act2img(element, action);
2140 else if (direction != -1)
2141 graphic = el_dir2img(element, direction);
2143 graphic = el2img(element);
2145 delay = helpanim_info[j++].delay;
2150 if (infoscreen_frame[i - start] == 0)
2153 infoscreen_frame[i - start] = delay - 1;
2157 sync_frame = delay - infoscreen_frame[i - start];
2158 infoscreen_frame[i - start]--;
2161 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2163 if (!infoscreen_frame[i - start])
2164 infoscreen_step[i - start] = 0;
2168 if (!infoscreen_frame[i - start])
2169 infoscreen_step[i - start]++;
2170 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2176 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2178 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2179 graphic, sync_frame, USE_MASKING);
2182 DrawInfoScreen_HelpText(element, action, direction, i - start);
2187 redraw_mask |= REDRAW_FIELD;
2192 static char *getHelpText(int element, int action, int direction)
2194 char token[MAX_LINE_LEN];
2196 strcpy(token, element_info[element].token_name);
2199 strcat(token, element_action_info[action].suffix);
2201 if (direction != -1)
2202 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2204 return getHashEntry(helptext_info, token);
2207 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2209 int font_nr = FONT_INFO_ELEMENTS;
2210 int font_width = getFontWidth(font_nr);
2211 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2212 int sy = mSY + 65 + 2 * 32 + 1;
2213 int ystep = TILEY + 4;
2214 int pad_x = sx - SX;
2215 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2216 int max_lines_per_text = 2;
2219 if (action != -1 && direction != -1) /* element.action.direction */
2220 text = getHelpText(element, action, direction);
2222 if (text == NULL && action != -1) /* element.action */
2223 text = getHelpText(element, action, -1);
2225 if (text == NULL && direction != -1) /* element.direction */
2226 text = getHelpText(element, -1, direction);
2228 if (text == NULL) /* base element */
2229 text = getHelpText(element, -1, -1);
2231 if (text == NULL) /* not found */
2232 text = "No description available";
2234 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2235 sy += getFontHeight(font_nr) / 2;
2237 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2238 max_chars_per_line, -1, max_lines_per_text, -1,
2239 TRUE, FALSE, FALSE);
2242 void DrawInfoScreen_TitleScreen()
2247 void HandleInfoScreen_TitleScreen(int button)
2249 HandleTitleScreen(0, 0, 0, 0, button);
2252 void DrawInfoScreen_Elements()
2254 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2256 FadeOut(REDRAW_FIELD);
2261 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2263 FadeIn(REDRAW_FIELD);
2268 void HandleInfoScreen_Elements(int button)
2270 static unsigned long info_delay = 0;
2271 static int num_anims;
2272 static int num_pages;
2274 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2277 if (button == MB_MENU_INITIALIZE)
2279 boolean new_element = TRUE;
2283 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2285 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2287 else if (new_element)
2290 new_element = FALSE;
2294 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2298 if (button == MB_MENU_LEAVE)
2300 PlaySound(SND_MENU_ITEM_SELECTING);
2302 info_mode = INFO_MODE_MAIN;
2307 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2309 if (button != MB_MENU_INITIALIZE)
2311 PlaySound(SND_MENU_ITEM_SELECTING);
2316 if (page >= num_pages)
2318 FadeSoundsAndMusic();
2320 info_mode = INFO_MODE_MAIN;
2321 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2328 FadeSetNextScreen();
2331 if (button != MB_MENU_INITIALIZE)
2332 FadeOut(REDRAW_FIELD);
2334 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2336 if (button != MB_MENU_INITIALIZE)
2337 FadeIn(REDRAW_FIELD);
2341 if (DelayReached(&info_delay, GameFrameDelay))
2342 if (page < num_pages)
2343 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2345 PlayMenuSoundIfLoop();
2349 void DrawInfoScreen_Music()
2351 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2354 FadeOut(REDRAW_FIELD);
2362 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2365 FadeIn(REDRAW_FIELD);
2369 void HandleInfoScreen_Music(int button)
2371 static struct MusicFileInfo *list = NULL;
2372 int ystart1 = mSY - SY + 100;
2373 int ystart2 = mSY - SY + 150;
2374 int ybottom = mSY - SY + SYSIZE - 20;
2377 if (button == MB_MENU_INITIALIZE)
2379 list = music_file_info;
2383 FadeSoundsAndMusic();
2388 DrawTextSCentered(ystart1, FONT_TEXT_1,
2389 "No music info for this level set.");
2391 DrawTextSCentered(ybottom, FONT_TEXT_4,
2392 "Press any key or button for info menu");
2398 if (button == MB_MENU_LEAVE)
2400 PlaySound(SND_MENU_ITEM_SELECTING);
2402 FadeSoundsAndMusic();
2404 info_mode = INFO_MODE_MAIN;
2409 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2413 if (button != MB_MENU_INITIALIZE)
2415 PlaySound(SND_MENU_ITEM_SELECTING);
2423 FadeSoundsAndMusic();
2425 info_mode = INFO_MODE_MAIN;
2426 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2431 FadeSoundsAndMusic();
2434 if (list != music_file_info)
2435 FadeSetNextScreen();
2438 if (button != MB_MENU_INITIALIZE)
2439 FadeOut(REDRAW_FIELD);
2446 int sound = list->music;
2448 if (sound_info[sound].loop)
2449 PlaySoundLoop(sound);
2453 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2457 PlayMusic(list->music);
2459 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2462 if (!strEqual(list->title, UNKNOWN_NAME))
2464 if (!strEqual(list->title_header, UNKNOWN_NAME))
2465 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2467 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2470 if (!strEqual(list->artist, UNKNOWN_NAME))
2472 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2473 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2475 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2477 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2480 if (!strEqual(list->album, UNKNOWN_NAME))
2482 if (!strEqual(list->album_header, UNKNOWN_NAME))
2483 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2485 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2487 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2490 if (!strEqual(list->year, UNKNOWN_NAME))
2492 if (!strEqual(list->year_header, UNKNOWN_NAME))
2493 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2495 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2497 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2500 DrawTextSCentered(ybottom, FONT_TEXT_4,
2501 "Press any key or button for next page");
2503 if (button != MB_MENU_INITIALIZE)
2504 FadeIn(REDRAW_FIELD);
2507 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2508 PlaySoundLoop(list->music);
2511 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2513 int ystart1 = mSY - SY + 100;
2514 int ystart2 = mSY - SY + 150;
2515 int ybottom = mSY - SY + SYSIZE - 20;
2521 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2525 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2526 "Special thanks to");
2527 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2529 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2531 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2532 "\"Boulder Dash\"");
2533 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2535 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2537 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2539 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2540 "First Star Software");
2542 else if (screen_nr == 1)
2544 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2545 "Special thanks to");
2546 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2547 "Klaus Heinz & Volker Wertich");
2548 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2550 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2551 "\"Emerald Mine\"");
2552 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2554 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2556 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2558 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2561 else if (screen_nr == 2)
2563 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2564 "Special thanks to");
2565 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2566 "Michael Stopp & Philip Jespersen");
2567 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2569 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2571 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2573 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2575 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2577 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2578 "Digital Integration");
2580 else if (screen_nr == 3)
2582 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2583 "Special thanks to");
2584 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2585 "Hiroyuki Imabayashi");
2586 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2588 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2590 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2592 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2594 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2596 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2599 else if (screen_nr == 4)
2601 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2602 "Special thanks to");
2603 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2605 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2607 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2608 "Jürgen Bonhagen");
2609 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2610 "for the continuous creation");
2611 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2612 "of outstanding level sets");
2614 else if (screen_nr == 5)
2616 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2618 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2620 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2621 "for ideas and inspiration by");
2622 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2625 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2627 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2629 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2630 "for ideas and inspiration by");
2631 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2634 else if (screen_nr == 6)
2636 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2638 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2641 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2642 "for the code base used for the");
2643 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2644 "native Emerald Mine engine");
2646 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2647 "for the new Emerald Mine engine");
2650 else if (screen_nr == 7)
2652 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2654 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2656 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2657 "for the initial DOS port");
2659 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2661 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2663 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2664 "for some additional toons");
2666 else if (screen_nr == 8)
2668 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2669 "And not to forget:");
2670 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2672 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2673 "All those who contributed");
2674 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2675 "levels to this game");
2676 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2680 DrawTextSCentered(ybottom, FONT_TEXT_4,
2681 "Press any key or button for next page");
2684 void DrawInfoScreen_Credits()
2686 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2688 FadeSoundsAndMusic();
2691 FadeOut(REDRAW_FIELD);
2694 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2697 FadeIn(REDRAW_FIELD);
2701 void HandleInfoScreen_Credits(int button)
2703 static int screen_nr = 0;
2704 int num_screens = 9;
2706 if (button == MB_MENU_INITIALIZE)
2710 // DrawInfoScreen_CreditsScreen(screen_nr);
2713 if (button == MB_MENU_LEAVE)
2715 PlaySound(SND_MENU_ITEM_SELECTING);
2717 info_mode = INFO_MODE_MAIN;
2722 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2724 if (button != MB_MENU_INITIALIZE)
2726 PlaySound(SND_MENU_ITEM_SELECTING);
2731 if (screen_nr >= num_screens)
2733 FadeSoundsAndMusic();
2735 info_mode = INFO_MODE_MAIN;
2736 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2743 FadeSetNextScreen();
2746 if (button != MB_MENU_INITIALIZE)
2747 FadeOut(REDRAW_FIELD);
2749 DrawInfoScreen_CreditsScreen(screen_nr);
2751 if (button != MB_MENU_INITIALIZE)
2752 FadeIn(REDRAW_FIELD);
2756 PlayMenuSoundIfLoop();
2760 void DrawInfoScreen_Program()
2762 int ystart1 = mSY - SY + 100;
2763 int ystart2 = mSY - SY + 150;
2764 int ybottom = mSY - SY + SYSIZE - 20;
2767 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2770 FadeOut(REDRAW_FIELD);
2776 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2778 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2779 "This game is Freeware!");
2780 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2781 "If you like it, send e-mail to:");
2782 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2783 PROGRAM_EMAIL_STRING);
2784 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2785 "or SnailMail to:");
2786 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2788 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2789 "Detmolder Strasse 189");
2790 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2792 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2794 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2795 "More information and levels:");
2796 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2797 PROGRAM_WEBSITE_STRING);
2798 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2799 "If you have created new levels,");
2800 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2801 "send them to me to include them!");
2802 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2805 DrawTextSCentered(ybottom, FONT_TEXT_4,
2806 "Press any key or button for info menu");
2809 FadeIn(REDRAW_FIELD);
2813 void HandleInfoScreen_Program(int button)
2815 if (button == MB_MENU_LEAVE)
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2819 info_mode = INFO_MODE_MAIN;
2824 else if (button == MB_MENU_CHOICE)
2826 PlaySound(SND_MENU_ITEM_SELECTING);
2828 FadeSoundsAndMusic();
2831 FadeOut(REDRAW_FIELD);
2834 info_mode = INFO_MODE_MAIN;
2835 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2839 PlayMenuSoundIfLoop();
2843 void DrawInfoScreen_Version()
2845 int font_header = FONT_TEXT_3;
2846 int font_text = FONT_TEXT_2;
2847 int xstep = getFontWidth(font_text);
2848 int ystep = getFontHeight(font_text);
2849 int ystart1 = mSY - SY + 100;
2850 int ystart2 = mSY - SY + 150;
2851 int ybottom = mSY - SY + SYSIZE - 20;
2852 int xstart1 = mSX + 2 * xstep;
2853 int xstart2 = mSX + 19 * xstep;
2854 #if defined(TARGET_SDL)
2855 int xstart3 = mSX + 29 * xstep;
2856 SDL_version sdl_version_compiled;
2857 const SDL_version *sdl_version_linked;
2858 int driver_name_len = 8;
2859 char driver_name[driver_name_len];
2862 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2865 FadeOut(REDRAW_FIELD);
2871 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2873 DrawTextF(xstart1, ystart2, font_header, "Name");
2874 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2877 DrawTextF(xstart1, ystart2, font_header, "Version");
2878 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2881 DrawTextF(xstart1, ystart2, font_header, "Platform");
2882 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2885 DrawTextF(xstart1, ystart2, font_header, "Target");
2886 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2889 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2890 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2892 #if defined(TARGET_SDL)
2893 ystart2 += 3 * ystep;
2894 DrawTextF(xstart1, ystart2, font_header, "Library");
2895 DrawTextF(xstart2, ystart2, font_header, "compiled");
2896 DrawTextF(xstart3, ystart2, font_header, "linked");
2898 SDL_VERSION(&sdl_version_compiled);
2899 sdl_version_linked = SDL_Linked_Version();
2901 ystart2 += 2 * ystep;
2902 DrawTextF(xstart1, ystart2, font_text, "SDL");
2903 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2904 sdl_version_compiled.major,
2905 sdl_version_compiled.minor,
2906 sdl_version_compiled.patch);
2907 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2908 sdl_version_linked->major,
2909 sdl_version_linked->minor,
2910 sdl_version_linked->patch);
2912 SDL_IMAGE_VERSION(&sdl_version_compiled);
2913 sdl_version_linked = IMG_Linked_Version();
2916 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2917 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2918 sdl_version_compiled.major,
2919 sdl_version_compiled.minor,
2920 sdl_version_compiled.patch);
2921 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2922 sdl_version_linked->major,
2923 sdl_version_linked->minor,
2924 sdl_version_linked->patch);
2926 SDL_MIXER_VERSION(&sdl_version_compiled);
2927 sdl_version_linked = Mix_Linked_Version();
2930 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2931 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2932 sdl_version_compiled.major,
2933 sdl_version_compiled.minor,
2934 sdl_version_compiled.patch);
2935 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2936 sdl_version_linked->major,
2937 sdl_version_linked->minor,
2938 sdl_version_linked->patch);
2940 SDL_NET_VERSION(&sdl_version_compiled);
2941 sdl_version_linked = SDLNet_Linked_Version();
2944 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2945 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2946 sdl_version_compiled.major,
2947 sdl_version_compiled.minor,
2948 sdl_version_compiled.patch);
2949 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2950 sdl_version_linked->major,
2951 sdl_version_linked->minor,
2952 sdl_version_linked->patch);
2954 ystart2 += 3 * ystep;
2955 DrawTextF(xstart1, ystart2, font_header, "Driver");
2956 DrawTextF(xstart2, ystart2, font_header, "Requested");
2957 DrawTextF(xstart3, ystart2, font_header, "Used");
2959 SDL_VideoDriverName(driver_name, driver_name_len);
2961 ystart2 += 2 * ystep;
2962 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2963 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2964 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2966 SDL_AudioDriverName(driver_name, driver_name_len);
2969 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2970 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2971 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2974 DrawTextSCentered(ybottom, FONT_TEXT_4,
2975 "Press any key or button for info menu");
2978 FadeIn(REDRAW_FIELD);
2982 void HandleInfoScreen_Version(int button)
2984 if (button == MB_MENU_LEAVE)
2986 PlaySound(SND_MENU_ITEM_SELECTING);
2988 info_mode = INFO_MODE_MAIN;
2993 else if (button == MB_MENU_CHOICE)
2995 PlaySound(SND_MENU_ITEM_SELECTING);
2997 FadeSoundsAndMusic();
3000 FadeOut(REDRAW_FIELD);
3003 info_mode = INFO_MODE_MAIN;
3004 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3008 PlayMenuSoundIfLoop();
3012 void DrawInfoScreen_LevelSet()
3014 struct TitleMessageInfo *tmi = &readme;
3015 char *filename = getLevelSetInfoFilename();
3017 /* if chars set to "-1", automatically determine by text and font width */
3018 if (tmi->chars == -1)
3019 tmi->chars = tmi->width / getFontWidth(tmi->font);
3021 tmi->width = tmi->chars * getFontWidth(tmi->font);
3023 /* if lines set to "-1", automatically determine by text and font height */
3024 if (tmi->lines == -1)
3025 tmi->lines = tmi->height / getFontHeight(tmi->font);
3027 tmi->height = tmi->lines * getFontHeight(tmi->font);
3029 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3032 FadeOut(REDRAW_FIELD);
3038 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3040 if (filename != NULL)
3041 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3042 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3043 tmi->autowrap, tmi->centered, tmi->parse_comments);
3045 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3046 "No information for this level set.");
3048 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3049 "Press any key or button for info menu");
3052 FadeIn(REDRAW_FIELD);
3056 void HandleInfoScreen_LevelSet(int button)
3058 if (button == MB_MENU_LEAVE)
3060 PlaySound(SND_MENU_ITEM_SELECTING);
3062 info_mode = INFO_MODE_MAIN;
3067 else if (button == MB_MENU_CHOICE)
3069 PlaySound(SND_MENU_ITEM_SELECTING);
3071 FadeSoundsAndMusic();
3074 FadeOut(REDRAW_FIELD);
3077 info_mode = INFO_MODE_MAIN;
3078 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3082 PlayMenuSoundIfLoop();
3086 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3088 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3090 if (info_mode == INFO_MODE_TITLE)
3091 DrawInfoScreen_TitleScreen();
3092 else if (info_mode == INFO_MODE_ELEMENTS)
3093 DrawInfoScreen_Elements();
3094 else if (info_mode == INFO_MODE_MUSIC)
3095 DrawInfoScreen_Music();
3096 else if (info_mode == INFO_MODE_CREDITS)
3097 DrawInfoScreen_Credits();
3098 else if (info_mode == INFO_MODE_PROGRAM)
3099 DrawInfoScreen_Program();
3100 else if (info_mode == INFO_MODE_VERSION)
3101 DrawInfoScreen_Version();
3102 else if (info_mode == INFO_MODE_LEVELSET)
3103 DrawInfoScreen_LevelSet();
3105 DrawInfoScreen_Main(fade_mask, do_fading);
3107 if (info_mode != INFO_MODE_MAIN &&
3108 info_mode != INFO_MODE_TITLE &&
3109 info_mode != INFO_MODE_MUSIC)
3116 void DrawAndFadeInInfoScreen(int fade_mask)
3118 DrawInfoScreenExt(fade_mask, TRUE);
3121 void DrawInfoScreen()
3123 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3126 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3128 if (info_mode == INFO_MODE_TITLE)
3129 HandleInfoScreen_TitleScreen(button);
3130 else if (info_mode == INFO_MODE_ELEMENTS)
3131 HandleInfoScreen_Elements(button);
3132 else if (info_mode == INFO_MODE_MUSIC)
3133 HandleInfoScreen_Music(button);
3134 else if (info_mode == INFO_MODE_CREDITS)
3135 HandleInfoScreen_Credits(button);
3136 else if (info_mode == INFO_MODE_PROGRAM)
3137 HandleInfoScreen_Program(button);
3138 else if (info_mode == INFO_MODE_VERSION)
3139 HandleInfoScreen_Version(button);
3140 else if (info_mode == INFO_MODE_LEVELSET)
3141 HandleInfoScreen_LevelSet(button);
3143 HandleInfoScreen_Main(mx, my, dx, dy, button);
3149 /* ========================================================================= */
3150 /* type name functions */
3151 /* ========================================================================= */
3153 void HandleTypeName(int newxpos, Key key)
3155 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3156 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3157 struct TextPosInfo *pos = mci->pos_input;
3158 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3159 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3160 static int xpos = 0;
3161 int font_nr = pos->font;
3162 int font_active_nr = FONT_ACTIVE(font_nr);
3163 int font_width = getFontWidth(font_active_nr);
3164 char key_char = getValidConfigValueChar(getCharFromKey(key));
3165 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3166 boolean is_active = TRUE;
3168 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3172 strcpy(last_player_name, setup.player_name);
3176 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3178 setup.player_name[xpos] = key_char;
3179 setup.player_name[xpos + 1] = 0;
3183 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3187 setup.player_name[xpos] = 0;
3189 else if (key == KSYM_Return && xpos > 0)
3195 game_status = GAME_MODE_MAIN;
3197 else if (key == KSYM_Escape)
3199 strcpy(setup.player_name, last_player_name);
3203 game_status = GAME_MODE_MAIN;
3208 pos->width = (strlen(setup.player_name) + 1) * font_width;
3209 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3211 DrawText(startx, starty, setup.player_name, font_active_nr);
3212 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3216 pos->width = strlen(setup.player_name) * font_width;
3217 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3219 DrawText(startx, starty, setup.player_name, font_nr);
3224 /* ========================================================================= */
3225 /* tree menu functions */
3226 /* ========================================================================= */
3228 static void DrawChooseTree(TreeInfo **ti_ptr)
3232 FreeScreenGadgets();
3233 CreateScreenGadgets();
3235 CloseDoor(DOOR_CLOSE_2);
3238 FadeOut(REDRAW_FIELD);
3243 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3244 MapScreenTreeGadgets(*ti_ptr);
3247 FadeIn(REDRAW_FIELD);
3253 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3255 struct GadgetInfo *gi = screen_gadget[id];
3256 int items_max, items_visible, item_position;
3258 items_max = numTreeInfoInGroup(ti);
3259 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3260 item_position = first_entry;
3262 if (item_position > items_max - items_visible)
3263 item_position = items_max - items_visible;
3265 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3266 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3267 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3270 static void drawChooseTreeList(int first_entry, int num_page_entries,
3274 char *title_string = NULL;
3275 int yoffset_sets = MENU_TITLE1_YPOS;
3276 int yoffset_setup = 16;
3277 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3279 int last_game_status = game_status; /* save current game status */
3281 title_string = ti->infotext;
3283 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3286 /* force LEVELS font on artwork setup screen */
3287 game_status = GAME_MODE_LEVELS;
3291 /* clear tree list area, but not title or scrollbar */
3292 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3293 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3294 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3296 /* clear tree list area, but not title or scrollbar */
3297 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3298 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3299 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3302 for (i = 0; i < num_page_entries; i++)
3304 TreeInfo *node, *node_first;
3305 int entry_pos = first_entry + i;
3306 int xpos = MENU_SCREEN_START_XPOS;
3307 int ypos = MENU_SCREEN_START_YPOS + i;
3308 int startx = mSX + xpos * 32;
3309 int starty = mSY + ypos * 32;
3310 int font_nr = FONT_TEXT_1;
3311 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3312 int startx_text = startx + font_xoffset;
3313 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3314 int text_size = startx_scrollbar - startx_text;
3315 int max_buffer_len = text_size / getFontWidth(font_nr);
3316 char buffer[max_buffer_len + 1];
3318 node_first = getTreeInfoFirstGroupEntry(ti);
3319 node = getTreeInfoFromPos(node_first, entry_pos);
3321 strncpy(buffer, node->name, max_buffer_len);
3322 buffer[max_buffer_len] = '\0';
3324 DrawText(startx, starty, buffer, font_nr + node->color);
3326 if (node->parent_link)
3327 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3328 else if (node->level_group)
3329 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3331 initCursor(i, IMG_MENU_BUTTON);
3334 game_status = last_game_status; /* restore current game status */
3336 redraw_mask |= REDRAW_FIELD;
3339 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3341 TreeInfo *node, *node_first;
3342 int x, last_redraw_mask = redraw_mask;
3343 int ypos = MENU_TITLE2_YPOS;
3344 int font_nr = FONT_TITLE_2;
3346 if (ti->type != TREE_TYPE_LEVEL_DIR)
3349 node_first = getTreeInfoFirstGroupEntry(ti);
3350 node = getTreeInfoFromPos(node_first, entry_pos);
3352 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3354 if (node->parent_link)
3355 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3357 else if (node->level_group)
3358 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3360 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3361 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3362 node->levels, node->class_desc);
3364 /* let BackToFront() redraw only what is needed */
3365 redraw_mask = last_redraw_mask | REDRAW_TILES;
3366 for (x = 0; x < SCR_FIELDX; x++)
3367 MarkTileDirty(x, 1);
3370 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3373 TreeInfo *ti = *ti_ptr;
3375 int y = ti->cl_cursor;
3376 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3377 int num_entries = numTreeInfoInGroup(ti);
3378 int num_page_entries;
3379 int last_game_status = game_status; /* save current game status */
3380 boolean position_set_by_scrollbar = (dx == 999);
3383 /* force LEVELS draw offset on choose level and artwork setup screen */
3384 game_status = GAME_MODE_LEVELS;
3387 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3388 num_page_entries = num_entries;
3390 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3392 game_status = last_game_status; /* restore current game status */
3394 if (button == MB_MENU_INITIALIZE)
3396 int num_entries = numTreeInfoInGroup(ti);
3397 int entry_pos = posTreeInfo(ti);
3399 if (ti->cl_first == -1)
3401 /* only on initialization */
3402 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3403 ti->cl_cursor = entry_pos - ti->cl_first;
3405 else if (ti->cl_cursor >= num_page_entries ||
3406 (num_entries > num_page_entries &&
3407 num_entries - ti->cl_first < num_page_entries))
3409 /* only after change of list size (by custom graphic configuration) */
3410 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3411 ti->cl_cursor = entry_pos - ti->cl_first;
3414 if (position_set_by_scrollbar)
3417 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3420 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3421 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3422 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3426 else if (button == MB_MENU_LEAVE)
3430 PlaySound(SND_MENU_ITEM_SELECTING);
3432 if (ti->node_parent)
3434 *ti_ptr = ti->node_parent;
3435 DrawChooseTree(ti_ptr);
3437 else if (game_status == GAME_MODE_SETUP)
3439 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3441 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3442 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3443 execSetupGraphics();
3449 game_status = GAME_MODE_MAIN;
3451 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3457 if (mx || my) /* mouse input */
3459 int last_game_status = game_status; /* save current game status */
3462 /* force LEVELS draw offset on artwork setup screen */
3463 game_status = GAME_MODE_LEVELS;
3466 x = (mx - mSX) / 32;
3467 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3469 game_status = last_game_status; /* restore current game status */
3471 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3473 /* move cursor instead of scrolling when already at start/end of list */
3474 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3476 else if (dy == +1 * SCROLL_LINE &&
3477 ti->cl_first + num_page_entries == num_entries)
3480 /* handle scrolling screen one line or page */
3481 if (ti->cl_cursor + dy < 0 ||
3482 ti->cl_cursor + dy > num_page_entries - 1)
3484 if (ABS(dy) == SCROLL_PAGE)
3485 step = num_page_entries - 1;
3487 if (dy < 0 && ti->cl_first > 0)
3489 /* scroll page/line up */
3491 ti->cl_first -= step;
3492 if (ti->cl_first < 0)
3495 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3496 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3497 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3499 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3502 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3504 /* scroll page/line down */
3506 ti->cl_first += step;
3507 if (ti->cl_first + num_page_entries > num_entries)
3508 ti->cl_first = MAX(0, num_entries - num_page_entries);
3510 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3511 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3512 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3514 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3521 /* handle moving cursor one line */
3522 y = ti->cl_cursor + dy;
3527 TreeInfo *node_first, *node_cursor;
3528 int entry_pos = ti->cl_first + y;
3530 node_first = getTreeInfoFirstGroupEntry(ti);
3531 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3533 if (node_cursor->node_group)
3537 PlaySound(SND_MENU_ITEM_SELECTING);
3539 node_cursor->cl_first = ti->cl_first;
3540 node_cursor->cl_cursor = ti->cl_cursor;
3541 *ti_ptr = node_cursor->node_group;
3542 DrawChooseTree(ti_ptr);
3547 else if (dx == -1 && ti->node_parent)
3551 PlaySound(SND_MENU_ITEM_SELECTING);
3553 *ti_ptr = ti->node_parent;
3554 DrawChooseTree(ti_ptr);
3559 if (!anyScrollbarGadgetActive() &&
3560 IN_VIS_FIELD(x, y) &&
3561 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3562 y >= 0 && y < num_page_entries)
3566 if (y != ti->cl_cursor)
3568 PlaySound(SND_MENU_ITEM_ACTIVATING);
3570 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3571 drawChooseTreeCursor(y, TRUE);
3572 drawChooseTreeInfo(ti->cl_first + y, ti);
3579 TreeInfo *node_first, *node_cursor;
3580 int entry_pos = ti->cl_first + y;
3582 PlaySound(SND_MENU_ITEM_SELECTING);
3584 node_first = getTreeInfoFirstGroupEntry(ti);
3585 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3587 if (node_cursor->node_group)
3591 node_cursor->cl_first = ti->cl_first;
3592 node_cursor->cl_cursor = ti->cl_cursor;
3593 *ti_ptr = node_cursor->node_group;
3594 DrawChooseTree(ti_ptr);
3596 else if (node_cursor->parent_link)
3600 *ti_ptr = node_cursor->node_parent;
3601 DrawChooseTree(ti_ptr);
3605 FadeSetEnterScreen();
3607 node_cursor->cl_first = ti->cl_first;
3608 node_cursor->cl_cursor = ti->cl_cursor;
3609 *ti_ptr = node_cursor;
3611 if (ti->type == TREE_TYPE_LEVEL_DIR)
3613 LoadLevelSetup_SeriesInfo();
3615 SaveLevelSetup_LastSeries();
3616 SaveLevelSetup_SeriesInfo();
3620 if (game_status == GAME_MODE_SETUP)
3622 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3624 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3625 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3626 execSetupGraphics();
3632 game_status = GAME_MODE_MAIN;
3640 void DrawChooseLevel()
3642 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3644 DrawChooseTree(&leveldir_current);
3650 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3652 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3657 void DrawHallOfFame(int highlight_position)
3660 FadeSoundsAndMusic();
3662 /* (this is needed when called from GameEnd() after winning a game) */
3663 KeyboardAutoRepeatOn();
3666 /* (this is needed when called from GameEnd() after winning a game) */
3667 SetDrawDeactivationMask(REDRAW_NONE);
3668 SetDrawBackgroundMask(REDRAW_FIELD);
3670 CloseDoor(DOOR_CLOSE_2);
3672 if (highlight_position < 0)
3673 LoadScore(level_nr);
3675 FadeSetEnterScreen();
3677 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3680 FadeOut(REDRAW_FIELD);
3688 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3691 FadeIn(REDRAW_FIELD);
3695 static void drawHallOfFameList(int first_entry, int highlight_position)
3699 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3702 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3703 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3704 "HighScores of Level %d", level_nr);
3706 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3708 int entry = first_entry + i;
3709 boolean active = (entry == highlight_position);
3710 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3711 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3712 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3713 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3714 int dx1 = 3 * getFontWidth(font_nr1);
3715 int dx2 = dx1 + getFontWidth(font_nr1);
3716 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3717 int sy = mSY + 64 + i * 32;
3719 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3720 DrawText(mSX + dx1, sy, ".", font_nr1);
3721 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3723 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3724 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3726 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3729 redraw_mask |= REDRAW_FIELD;
3732 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3734 static int first_entry = 0;
3735 static int highlight_position = 0;
3736 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3738 if (button == MB_MENU_INITIALIZE)
3741 highlight_position = mx;
3742 drawHallOfFameList(first_entry, highlight_position);
3747 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3748 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3752 if (first_entry > 0)
3754 first_entry -= step;
3755 if (first_entry < 0)
3758 drawHallOfFameList(first_entry, highlight_position);
3763 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3765 first_entry += step;
3766 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3767 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3769 drawHallOfFameList(first_entry, highlight_position);
3772 else if (button == MB_MENU_LEAVE)
3774 PlaySound(SND_MENU_ITEM_SELECTING);
3776 FadeSound(SND_BACKGROUND_SCORES);
3778 game_status = GAME_MODE_MAIN;
3782 else if (button == MB_MENU_CHOICE)
3784 PlaySound(SND_MENU_ITEM_SELECTING);
3786 FadeSound(SND_BACKGROUND_SCORES);
3789 FadeOut(REDRAW_FIELD);
3792 game_status = GAME_MODE_MAIN;
3794 DrawAndFadeInMainMenu(REDRAW_FIELD);
3797 if (game_status == GAME_MODE_SCORES)
3798 PlayMenuSoundIfLoop();
3804 /* ========================================================================= */
3805 /* setup screen functions */
3806 /* ========================================================================= */
3808 static struct TokenInfo *setup_info;
3809 static int num_setup_info;
3811 static char *screen_mode_text;
3812 static char *scroll_delay_text;
3813 static char *game_speed_text;
3814 static char *graphics_set_name;
3815 static char *sounds_set_name;
3816 static char *music_set_name;
3818 static void execSetupMain()
3820 setup_mode = SETUP_MODE_MAIN;
3825 static void execSetupGame()
3827 if (game_speeds == NULL)
3831 for (i = 0; game_speeds_list[i].value != -1; i++)
3833 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3834 char identifier[32], name[32];
3835 int value = game_speeds_list[i].value;
3836 char *text = game_speeds_list[i].text;
3838 ti->node_top = &game_speeds;
3839 ti->sort_priority = 10000 - value;
3841 sprintf(identifier, "%d", value);
3842 sprintf(name, "%s", text);
3844 setString(&ti->identifier, identifier);
3845 setString(&ti->name, name);
3846 setString(&ti->name_sorting, name);
3847 setString(&ti->infotext, "Game Speed");
3849 pushTreeInfo(&game_speeds, ti);
3852 /* sort game speed values to start with slowest game speed */
3853 sortTreeInfo(&game_speeds);
3855 /* set current game speed to configured game speed value */
3856 game_speed_current =
3857 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3859 /* if that fails, set current game speed to reliable default value */
3860 if (game_speed_current == NULL)
3861 game_speed_current =
3862 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3864 /* if that also fails, set current game speed to first available speed */
3865 if (game_speed_current == NULL)
3866 game_speed_current = game_speeds;
3869 setup.game_frame_delay = atoi(game_speed_current->identifier);
3871 /* needed for displaying game speed text instead of identifier */
3872 game_speed_text = game_speed_current->name;
3874 setup_mode = SETUP_MODE_GAME;
3879 static void execSetupChooseGameSpeed()
3881 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3886 static void execSetupEditor()
3888 setup_mode = SETUP_MODE_EDITOR;
3893 static void execSetupGraphics()
3895 if (video.fullscreen_available && screen_modes == NULL)
3899 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3901 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3902 char identifier[32], name[32];
3903 int x = video.fullscreen_modes[i].width;
3904 int y = video.fullscreen_modes[i].height;
3907 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3909 ti->node_top = &screen_modes;
3910 ti->sort_priority = x * 10000 + y;
3912 sprintf(identifier, "%dx%d", x, y);
3913 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3915 setString(&ti->identifier, identifier);
3916 setString(&ti->name, name);
3917 setString(&ti->name_sorting, name);
3918 setString(&ti->infotext, "Fullscreen Mode");
3920 pushTreeInfo(&screen_modes, ti);
3923 /* sort fullscreen modes to start with lowest available screen resolution */
3924 sortTreeInfo(&screen_modes);
3926 /* set current screen mode for fullscreen mode to configured setup value */
3927 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3928 setup.fullscreen_mode);
3930 /* if that fails, set current screen mode to reliable default value */
3931 if (screen_mode_current == NULL)
3932 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3933 DEFAULT_FULLSCREEN_MODE);
3935 /* if that also fails, set current screen mode to first available mode */
3936 if (screen_mode_current == NULL)
3937 screen_mode_current = screen_modes;
3939 if (screen_mode_current == NULL)
3940 video.fullscreen_available = FALSE;
3943 if (video.fullscreen_available)
3945 setup.fullscreen_mode = screen_mode_current->identifier;
3947 /* needed for displaying screen mode name instead of identifier */
3948 screen_mode_text = screen_mode_current->name;
3952 if (scroll_delays == NULL)
3956 for (i = 0; scroll_delays_list[i].value != -1; i++)
3958 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3959 char identifier[32], name[32];
3960 int value = scroll_delays_list[i].value;
3961 char *text = scroll_delays_list[i].text;
3963 ti->node_top = &scroll_delays;
3964 ti->sort_priority = value;
3966 sprintf(identifier, "%d", value);
3967 sprintf(name, "%s", text);
3969 setString(&ti->identifier, identifier);
3970 setString(&ti->name, name);
3971 setString(&ti->name_sorting, name);
3972 setString(&ti->infotext, "Scroll Delay");
3974 pushTreeInfo(&scroll_delays, ti);
3977 /* sort scroll delay values to start with lowest scroll delay value */
3978 sortTreeInfo(&scroll_delays);
3980 /* set current scroll delay value to configured scroll delay value */
3981 scroll_delay_current =
3982 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
3984 /* if that fails, set current scroll delay to reliable default value */
3985 if (scroll_delay_current == NULL)
3986 scroll_delay_current =
3987 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
3989 /* if that also fails, set current scroll delay to first available value */
3990 if (scroll_delay_current == NULL)
3991 scroll_delay_current = scroll_delays;
3994 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
3996 /* needed for displaying scroll delay text instead of identifier */
3997 scroll_delay_text = scroll_delay_current->name;
4000 setup_mode = SETUP_MODE_GRAPHICS;
4004 static void execSetupChooseScreenMode()
4006 if (!video.fullscreen_available)
4009 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4014 static void execSetupChooseScrollDelay()
4016 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4021 static void execSetupSound()
4023 setup_mode = SETUP_MODE_SOUND;
4028 static void execSetupArtwork()
4031 printf("::: '%s', '%s', '%s'\n",
4032 artwork.gfx_current->subdir,
4033 artwork.gfx_current->fullpath,
4034 artwork.gfx_current->basepath);
4037 setup.graphics_set = artwork.gfx_current->identifier;
4038 setup.sounds_set = artwork.snd_current->identifier;
4039 setup.music_set = artwork.mus_current->identifier;
4041 /* needed if last screen (setup choice) changed graphics, sounds or music */
4042 ReloadCustomArtwork(0);
4044 /* needed for displaying artwork name instead of artwork identifier */
4045 graphics_set_name = artwork.gfx_current->name;
4046 sounds_set_name = artwork.snd_current->name;
4047 music_set_name = artwork.mus_current->name;
4049 setup_mode = SETUP_MODE_ARTWORK;
4054 static void execSetupChooseGraphics()
4056 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4061 static void execSetupChooseSounds()
4063 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4068 static void execSetupChooseMusic()
4070 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4075 static void execSetupInput()
4077 setup_mode = SETUP_MODE_INPUT;
4082 static void execSetupShortcuts1()
4084 setup_mode = SETUP_MODE_SHORTCUTS_1;
4089 static void execSetupShortcuts2()
4091 setup_mode = SETUP_MODE_SHORTCUTS_2;
4096 static void execExitSetup()
4098 game_status = GAME_MODE_MAIN;
4100 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4103 static void execSaveAndExitSetup()
4109 static struct TokenInfo setup_info_main[] =
4111 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4112 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4113 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4114 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4115 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4116 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4117 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4118 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4119 { TYPE_EMPTY, NULL, "" },
4120 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4121 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4126 static struct TokenInfo setup_info_game[] =
4128 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4129 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4130 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4131 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4132 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4133 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4134 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4135 { TYPE_STRING, &game_speed_text, "" },
4136 { TYPE_EMPTY, NULL, "" },
4137 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4142 static struct TokenInfo setup_info_editor[] =
4145 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4146 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4147 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4148 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4149 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4150 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4151 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4152 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4154 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4155 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4156 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4158 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4160 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4161 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4162 { TYPE_EMPTY, NULL, "" },
4164 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4165 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4166 { TYPE_EMPTY, NULL, "" },
4168 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4169 { TYPE_EMPTY, NULL, "" },
4170 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4175 static struct TokenInfo setup_info_graphics[] =
4177 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4178 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4179 { TYPE_STRING, &screen_mode_text, "" },
4181 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4183 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4184 { TYPE_STRING, &scroll_delay_text, "" },
4186 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4188 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4189 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4190 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4191 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4192 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4193 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4194 { TYPE_EMPTY, NULL, "" },
4195 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4200 static struct TokenInfo setup_info_sound[] =
4202 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4203 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4204 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4205 { TYPE_EMPTY, NULL, "" },
4206 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4211 static struct TokenInfo setup_info_artwork[] =
4213 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4214 { TYPE_STRING, &graphics_set_name, "" },
4215 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4216 { TYPE_STRING, &sounds_set_name, "" },
4217 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4218 { TYPE_STRING, &music_set_name, "" },
4219 { TYPE_EMPTY, NULL, "" },
4222 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4223 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4224 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4226 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4227 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4228 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4229 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4232 { TYPE_STRING, NULL, "Override Level Artwork:"},
4233 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4234 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4235 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4237 { TYPE_EMPTY, NULL, "" },
4238 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4243 static struct TokenInfo setup_info_input[] =
4245 { TYPE_SWITCH, NULL, "Player:" },
4246 { TYPE_SWITCH, NULL, "Device:" },
4247 { TYPE_ENTER_MENU, NULL, "" },
4248 { TYPE_EMPTY, NULL, "" },
4249 { TYPE_EMPTY, NULL, "" },
4250 { TYPE_EMPTY, NULL, "" },
4251 { TYPE_EMPTY, NULL, "" },
4252 { TYPE_EMPTY, NULL, "" },
4253 { TYPE_EMPTY, NULL, "" },
4254 { TYPE_EMPTY, NULL, "" },
4255 { TYPE_EMPTY, NULL, "" },
4256 { TYPE_EMPTY, NULL, "" },
4257 { TYPE_EMPTY, NULL, "" },
4258 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4263 static struct TokenInfo setup_info_shortcuts_1[] =
4265 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4266 { TYPE_KEY, &setup.shortcut.save_game, "" },
4267 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4268 { TYPE_KEY, &setup.shortcut.load_game, "" },
4269 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4270 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4271 { TYPE_EMPTY, NULL, "" },
4272 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4273 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4274 { TYPE_EMPTY, NULL, "" },
4275 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4280 static struct TokenInfo setup_info_shortcuts_2[] =
4282 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4283 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4284 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4285 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4286 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4287 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4288 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4289 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4290 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4291 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4292 { TYPE_EMPTY, NULL, "" },
4293 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4298 static Key getSetupKey()
4300 Key key = KSYM_UNDEFINED;
4301 boolean got_key_event = FALSE;
4303 while (!got_key_event)
4305 if (PendingEvent()) /* got event */
4313 case EVENT_KEYPRESS:
4315 key = GetEventKey((KeyEvent *)&event, TRUE);
4317 /* press 'Escape' or 'Enter' to keep the existing key binding */
4318 if (key == KSYM_Escape || key == KSYM_Return)
4319 key = KSYM_UNDEFINED; /* keep old value */
4321 got_key_event = TRUE;
4325 case EVENT_KEYRELEASE:
4326 key_joystick_mapping = 0;
4330 HandleOtherEvents(&event);
4338 /* don't eat all CPU time */
4345 static int getSetupTextFont(int type)
4347 if (type & (TYPE_SWITCH |
4359 static int getSetupValueFont(int type, void *value)
4361 if (type & TYPE_KEY)
4362 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4363 else if (type & TYPE_STRING)
4364 return FONT_VALUE_2;
4365 else if (type & TYPE_ECS_AGA)
4366 return FONT_VALUE_1;
4367 else if (type & TYPE_BOOLEAN_STYLE)
4368 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4369 else if (type & TYPE_YES_NO_AUTO)
4370 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4371 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4373 return FONT_VALUE_1;
4376 static void drawSetupValue(int pos)
4378 boolean font_draw_xoffset_modified = FALSE;
4379 int font_draw_xoffset_old = -1;
4380 int xpos = MENU_SCREEN_VALUE_XPOS;
4381 int ypos = MENU_SCREEN_START_YPOS + pos;
4382 int startx = mSX + xpos * 32;
4383 int starty = mSY + ypos * 32;
4384 int font_nr, font_width, font_height;
4385 int type = setup_info[pos].type;
4386 void *value = setup_info[pos].value;
4387 char *value_string = getSetupValue(type, value);
4392 if (value_string == NULL)
4395 if (type & TYPE_KEY)
4397 xpos = MENU_SCREEN_START_XPOS;
4399 if (type & TYPE_QUERY)
4400 value_string = "<press key>";
4402 else if (type & TYPE_STRING)
4404 int max_value_len = (SCR_FIELDX - 2) * 2;
4406 xpos = MENU_SCREEN_START_XPOS;
4408 if (strlen(value_string) > max_value_len)
4409 value_string[max_value_len] = '\0';
4411 else if (type & TYPE_YES_NO_AUTO)
4413 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4416 startx = mSX + xpos * 32;
4417 starty = mSY + ypos * 32;
4418 font_nr = getSetupValueFont(type, value);
4419 font_width = getFontWidth(font_nr);
4420 font_height = getFontHeight(font_nr);
4422 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4423 if (setup_mode != SETUP_MODE_INPUT)
4425 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4426 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4427 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4428 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4429 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4430 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4431 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4432 boolean correct_font_draw_xoffset = FALSE;
4434 if (xpos == MENU_SCREEN_START_XPOS &&
4435 startx + font1_xoffset < text_startx + text_font_xoffset)
4436 correct_font_draw_xoffset = TRUE;
4438 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4439 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4440 correct_font_draw_xoffset = TRUE;
4442 /* check if setup value would overlap with setup text when printed */
4443 /* (this can happen for extreme/wrong values for font draw offset) */
4444 if (correct_font_draw_xoffset)
4446 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4447 font_draw_xoffset_modified = TRUE;
4449 if (type & TYPE_KEY)
4450 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4451 else if (!(type & TYPE_STRING))
4452 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4453 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4458 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4460 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4461 DrawText(startx + i * font_width, starty, " ", font_nr);
4464 DrawText(startx, starty, value_string, font_nr);
4466 if (font_draw_xoffset_modified)
4467 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4470 static void changeSetupValue(int pos, int dx)
4472 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4474 *(boolean *)setup_info[pos].value ^= TRUE;
4476 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4478 *(int *)setup_info[pos].value =
4480 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4481 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4482 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4483 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4485 else if (setup_info[pos].type & TYPE_KEY)
4489 setup_info[pos].type |= TYPE_QUERY;
4490 drawSetupValue(pos);
4491 setup_info[pos].type &= ~TYPE_QUERY;
4493 key = getSetupKey();
4494 if (key != KSYM_UNDEFINED)
4495 *(Key *)setup_info[pos].value = key;
4498 drawSetupValue(pos);
4501 static void DrawCursorAndText_Setup(int pos, boolean active)
4503 int xpos = MENU_SCREEN_START_XPOS;
4504 int ypos = MENU_SCREEN_START_YPOS + pos;
4505 int font_nr = getSetupTextFont(setup_info[pos].type);
4507 if (setup_info == setup_info_input)
4508 font_nr = FONT_MENU_1;
4511 font_nr = FONT_ACTIVE(font_nr);
4513 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4515 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4516 drawCursor(pos, active);
4519 static void DrawSetupScreen_Generic()
4521 boolean redraw_all = FALSE;
4522 char *title_string = NULL;
4526 CloseDoor(DOOR_CLOSE_2);
4528 if (redraw_mask & REDRAW_ALL)
4532 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4533 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4534 int2str(0, redraw_mask)));
4538 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4539 FadeOut(redraw_mask);
4541 FadeOut(REDRAW_FIELD);
4546 if (setup_mode == SETUP_MODE_MAIN)
4548 setup_info = setup_info_main;
4549 title_string = "Setup";
4551 else if (setup_mode == SETUP_MODE_GAME)
4553 setup_info = setup_info_game;
4554 title_string = "Setup Game";
4556 else if (setup_mode == SETUP_MODE_EDITOR)
4558 setup_info = setup_info_editor;
4559 title_string = "Setup Editor";
4561 else if (setup_mode == SETUP_MODE_GRAPHICS)
4563 setup_info = setup_info_graphics;
4564 title_string = "Setup Graphics";
4566 else if (setup_mode == SETUP_MODE_SOUND)
4568 setup_info = setup_info_sound;
4569 title_string = "Setup Sound";
4571 else if (setup_mode == SETUP_MODE_ARTWORK)
4573 setup_info = setup_info_artwork;
4574 title_string = "Custom Artwork";
4576 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4578 setup_info = setup_info_shortcuts_1;
4579 title_string = "Setup Shortcuts";
4581 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4583 setup_info = setup_info_shortcuts_2;
4584 title_string = "Setup Shortcuts";
4587 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4591 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4593 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4596 void *value_ptr = setup_info[i].value;
4598 /* set some entries to "unchangeable" according to other variables */
4599 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4600 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4601 (value_ptr == &setup.sound_music && !audio.music_available) ||
4602 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4603 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4604 setup_info[i].type |= TYPE_GHOSTED;
4606 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4607 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4608 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4609 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4610 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4611 initCursor(i, IMG_MENU_BUTTON);
4613 DrawCursorAndText_Setup(i, FALSE);
4615 if (setup_info[i].type & TYPE_VALUE)
4622 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4623 "Joysticks deactivated in setup menu");
4627 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4631 redraw_mask = REDRAW_ALL;
4634 FadeIn(redraw_mask);
4636 FadeIn(REDRAW_FIELD);
4641 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4645 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4647 static int choice_store[MAX_SETUP_MODES];
4648 int choice = choice_store[setup_mode]; /* always starts with 0 */
4652 if (button == MB_MENU_INITIALIZE)
4654 /* advance to first valid menu entry */
4655 while (choice < num_setup_info &&
4656 setup_info[choice].type & TYPE_SKIP_ENTRY)
4658 choice_store[setup_mode] = choice;
4660 DrawCursorAndText_Setup(choice, TRUE);
4664 else if (button == MB_MENU_LEAVE)
4666 PlaySound(SND_MENU_ITEM_SELECTING);
4668 for (y = 0; y < num_setup_info; y++)
4670 if (setup_info[y].type & TYPE_LEAVE_MENU)
4672 void (*menu_callback_function)(void) = setup_info[y].value;
4676 menu_callback_function();
4678 break; /* absolutely needed because function changes 'setup_info'! */
4685 if (mx || my) /* mouse input */
4687 x = (mx - mSX) / 32;
4688 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4690 else if (dx || dy) /* keyboard input */
4694 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4696 if (setup_info[choice].type & menu_navigation_type ||
4697 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4698 setup_info[choice].type & TYPE_YES_NO_AUTO)
4699 button = MB_MENU_CHOICE;
4704 /* jump to next non-empty menu entry (up or down) */
4705 while (y > 0 && y < num_setup_info - 1 &&
4706 setup_info[y].type & TYPE_SKIP_ENTRY)
4710 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4714 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4716 PlaySound(SND_MENU_ITEM_ACTIVATING);
4718 DrawCursorAndText_Setup(choice, FALSE);
4719 DrawCursorAndText_Setup(y, TRUE);
4721 choice = choice_store[setup_mode] = y;
4724 else if (!(setup_info[y].type & TYPE_GHOSTED))
4726 PlaySound(SND_MENU_ITEM_SELECTING);
4728 /* when selecting key headline, execute function for key value change */
4729 if (setup_info[y].type & TYPE_KEYTEXT &&
4730 setup_info[y + 1].type & TYPE_KEY)
4733 /* when selecting string value, execute function for list selection */
4734 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4735 setup_info[y - 1].type & TYPE_ENTER_LIST)
4738 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4740 void (*menu_callback_function)(void) = setup_info[y].value;
4742 FadeSetFromType(setup_info[y].type);
4744 menu_callback_function();
4748 if (setup_info[y].type & TYPE_VALUE)
4749 changeSetupValue(y, dx);
4755 void DrawSetupScreen_Input()
4760 FadeOut(REDRAW_FIELD);
4766 setup_info = setup_info_input;
4769 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4773 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4774 "Joysticks deactivated on this screen");
4776 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4777 "Joysticks deactivated on this screen");
4782 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4784 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4787 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4788 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4789 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4790 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4791 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4792 initCursor(i, IMG_MENU_BUTTON);
4794 DrawCursorAndText_Setup(i, FALSE);
4798 DeactivateJoystickForCalibration();
4803 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4804 "Joysticks deactivated on this screen");
4806 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4807 "Joysticks deactivated on this screen");
4811 /* create gadgets for setup input menu screen */
4812 FreeScreenGadgets();
4813 CreateScreenGadgets();
4815 /* map gadgets for setup input menu screen */
4816 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4818 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4821 FadeIn(REDRAW_FIELD);
4827 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4829 if (device_name == NULL)
4832 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4835 if (strlen(device_name) > 1)
4837 char c1 = device_name[strlen(device_name) - 1];
4838 char c2 = device_name[strlen(device_name) - 2];
4840 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4841 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4844 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4845 strlen(device_name));
4848 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4851 static struct SetupKeyboardInfo custom_key;
4858 { &custom_key.left, "Joystick Left" },
4859 { &custom_key.right, "Joystick Right" },
4860 { &custom_key.up, "Joystick Up" },
4861 { &custom_key.down, "Joystick Down" },
4862 { &custom_key.snap, "Button 1" },
4863 { &custom_key.drop, "Button 2" }
4865 static char *joystick_name[MAX_PLAYERS] =
4872 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4876 custom_key = setup.input[player_nr].key;
4878 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4879 FONT_INPUT_1_ACTIVE);
4881 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4883 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4884 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4886 if (setup.input[player_nr].use_joystick)
4888 char *device_name = setup.input[player_nr].joy.device_name;
4889 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4890 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4892 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4893 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4897 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4898 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4901 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4903 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4904 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4905 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4906 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4908 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4909 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4910 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4911 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4912 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4913 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4915 for (i = 0; i < 6; i++)
4917 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4919 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4921 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4922 (setup.input[player_nr].use_joystick ?
4924 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4928 static int input_player_nr = 0;
4930 void HandleSetupScreen_Input_Player(int step, int direction)
4932 int old_player_nr = input_player_nr;
4935 new_player_nr = old_player_nr + step * direction;
4936 if (new_player_nr < 0)
4938 if (new_player_nr > MAX_PLAYERS - 1)
4939 new_player_nr = MAX_PLAYERS - 1;
4941 if (new_player_nr != old_player_nr)
4943 input_player_nr = new_player_nr;
4945 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4949 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
4951 static int choice = 0;
4954 int pos_start = SETUPINPUT_SCREEN_POS_START;
4955 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
4956 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
4957 int pos_end = SETUPINPUT_SCREEN_POS_END;
4959 if (button == MB_MENU_INITIALIZE)
4961 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
4963 DrawCursorAndText_Setup(choice, TRUE);
4967 else if (button == MB_MENU_LEAVE)
4969 setup_mode = SETUP_MODE_MAIN;
4976 if (mx || my) /* mouse input */
4978 x = (mx - mSX) / 32;
4979 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4981 else if (dx || dy) /* keyboard input */
4983 if (dx && choice == 0)
4984 x = (dx < 0 ? 10 : 12);
4985 else if ((dx && choice == 1) ||
4986 (dx == +1 && choice == 2) ||
4987 (dx == -1 && choice == pos_end))
4988 button = MB_MENU_CHOICE;
4992 if (y >= pos_empty1 && y <= pos_empty2)
4993 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
4996 if (y == 0 && dx != 0 && button)
4998 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5000 else if (IN_VIS_FIELD(x, y) &&
5001 y >= pos_start && y <= pos_end &&
5002 !(y >= pos_empty1 && y <= pos_empty2))
5008 DrawCursorAndText_Setup(choice, FALSE);
5009 DrawCursorAndText_Setup(y, TRUE);
5011 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5020 char *device_name = setup.input[input_player_nr].joy.device_name;
5022 if (!setup.input[input_player_nr].use_joystick)
5024 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5026 setJoystickDeviceToNr(device_name, new_device_nr);
5027 setup.input[input_player_nr].use_joystick = TRUE;
5031 int device_nr = getJoystickNrFromDeviceName(device_name);
5032 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5034 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5035 setup.input[input_player_nr].use_joystick = FALSE;
5037 setJoystickDeviceToNr(device_name, new_device_nr);
5040 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5044 if (setup.input[input_player_nr].use_joystick)
5047 CalibrateJoystick(input_player_nr);
5050 CustomizeKeyboard(input_player_nr);
5052 else if (y == pos_end)
5058 setup_mode = SETUP_MODE_MAIN;
5065 void CustomizeKeyboard(int player_nr)
5069 boolean finished = FALSE;
5070 static struct SetupKeyboardInfo custom_key;
5075 } customize_step[] =
5077 { &custom_key.left, "Move Left" },
5078 { &custom_key.right, "Move Right" },
5079 { &custom_key.up, "Move Up" },
5080 { &custom_key.down, "Move Down" },
5081 { &custom_key.snap, "Snap Field" },
5082 { &custom_key.drop, "Drop Element" }
5085 /* read existing key bindings from player setup */
5086 custom_key = setup.input[player_nr].key;
5089 FadeOut(REDRAW_FIELD);
5093 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5101 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5102 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5103 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5104 "Key:", FONT_INPUT_1_ACTIVE);
5105 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5106 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5109 FadeIn(REDRAW_FIELD);
5116 if (PendingEvent()) /* got event */
5124 case EVENT_KEYPRESS:
5126 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5128 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5130 if (key == KSYM_Escape)
5131 FadeSkipNextFadeIn();
5137 /* all keys configured -- wait for "Escape" or "Return" key */
5141 /* press 'Enter' to keep the existing key binding */
5142 if (key == KSYM_Return)
5143 key = *customize_step[step_nr].key;
5145 /* check if key already used */
5146 for (i = 0; i < step_nr; i++)
5147 if (*customize_step[i].key == key)
5152 /* got new key binding */
5153 *customize_step[step_nr].key = key;
5154 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5156 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5157 getKeyNameFromKey(key), FONT_VALUE_1);
5160 /* un-highlight last query */
5161 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5162 customize_step[step_nr - 1].text, FONT_MENU_1);
5163 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5164 "Key:", FONT_MENU_1);
5166 /* press 'Enter' to leave */
5169 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5170 "Press Enter", FONT_TITLE_1);
5174 /* query next key binding */
5175 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5176 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5177 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5178 "Key:", FONT_INPUT_1_ACTIVE);
5179 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5180 getKeyNameFromKey(*customize_step[step_nr].key),
5185 case EVENT_KEYRELEASE:
5186 key_joystick_mapping = 0;
5190 HandleOtherEvents(&event);
5198 /* don't eat all CPU time */
5202 /* write new key bindings back to player setup */
5203 setup.input[player_nr].key = custom_key;
5206 DrawSetupScreen_Input();
5209 static boolean CalibrateJoystickMain(int player_nr)
5211 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5212 int new_joystick_xright = JOYSTICK_XMIDDLE;
5213 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5214 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5215 int new_joystick_xmiddle, new_joystick_ymiddle;
5217 int joystick_fd = joystick.fd[player_nr];
5218 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5219 boolean check[3][3];
5220 int check_remaining = 3 * 3;
5225 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5228 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5232 FadeOut(REDRAW_FIELD);
5236 for (y = 0; y < 3; y++)
5238 for (x = 0; x < 3; x++)
5240 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5241 check[x][y] = FALSE;
5245 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5246 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5247 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5248 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5249 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5250 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5251 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5253 joy_value = Joystick(player_nr);
5254 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5255 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5257 /* eventually uncalibrated center position (joystick could be uncentered) */
5258 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5261 new_joystick_xmiddle = joy_x;
5262 new_joystick_ymiddle = joy_y;
5264 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5266 FadeIn(REDRAW_FIELD);
5268 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5273 if (PendingEvent()) /* got event */
5281 case EVENT_KEYPRESS:
5282 switch (GetEventKey((KeyEvent *)&event, TRUE))
5285 if (check_remaining == 0)
5290 FadeSkipNextFadeIn();
5299 case EVENT_KEYRELEASE:
5300 key_joystick_mapping = 0;
5304 HandleOtherEvents(&event);
5309 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5312 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5313 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5314 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5315 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5317 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5318 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5319 setup.input[player_nr].joy.xright = new_joystick_xright;
5320 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5321 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5322 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5324 CheckJoystickData();
5326 joy_value = Joystick(player_nr);
5328 if (joy_value & JOY_BUTTON && check_remaining == 0)
5331 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5332 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5334 if (x != last_x || y != last_y)
5336 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5337 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5342 if (check_remaining > 0 && !check[x+1][y+1])
5344 check[x+1][y+1] = TRUE;
5350 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5351 setup.input[player_nr].joy.xleft,
5352 setup.input[player_nr].joy.xmiddle,
5353 setup.input[player_nr].joy.xright);
5354 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5355 setup.input[player_nr].joy.yupper,
5356 setup.input[player_nr].joy.ymiddle,
5357 setup.input[player_nr].joy.ylower);
5366 /* don't eat all CPU time */
5370 /* calibrated center position (joystick should now be centered) */
5371 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5374 new_joystick_xmiddle = joy_x;
5375 new_joystick_ymiddle = joy_y;
5380 DrawSetupScreen_Input();
5383 /* wait until the last pressed button was released */
5384 while (Joystick(player_nr) & JOY_BUTTON)
5386 if (PendingEvent()) /* got event */
5391 HandleOtherEvents(&event);
5400 void CalibrateJoystick(int player_nr)
5402 if (!CalibrateJoystickMain(player_nr))
5404 char *device_name = setup.input[player_nr].joy.device_name;
5405 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5406 int xpos = mSX - SX;
5407 int ypos = mSY - SY;
5411 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5412 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5415 Delay(2000); /* show error message for a short time */
5421 DrawSetupScreen_Input();
5425 void DrawSetupScreen()
5427 DeactivateJoystick();
5429 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5431 if (setup_mode == SETUP_MODE_INPUT)
5432 DrawSetupScreen_Input();
5433 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5434 DrawChooseTree(&game_speed_current);
5435 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5436 DrawChooseTree(&screen_mode_current);
5437 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5438 DrawChooseTree(&scroll_delay_current);
5439 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5440 DrawChooseTree(&artwork.gfx_current);
5441 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5442 DrawChooseTree(&artwork.snd_current);
5443 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5444 DrawChooseTree(&artwork.mus_current);
5446 DrawSetupScreen_Generic();
5452 void RedrawSetupScreenAfterFullscreenToggle()
5454 if (setup_mode == SETUP_MODE_GRAPHICS)
5458 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5460 if (setup_mode == SETUP_MODE_INPUT)
5461 HandleSetupScreen_Input(mx, my, dx, dy, button);
5462 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5463 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5464 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5465 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5466 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5467 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5468 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5469 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5470 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5471 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5472 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5473 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5475 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5480 void HandleGameActions()
5482 if (game_status != GAME_MODE_PLAYING)
5485 GameActions(); /* main game loop */
5487 if (tape.auto_play && !tape.playing)
5488 AutoPlayTape(); /* continue automatically playing next tape */
5492 /* ---------- new screen button stuff -------------------------------------- */
5494 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5499 case SCREEN_CTRL_ID_PREV_LEVEL:
5500 *x = mSX + menu.main.button.prev_level.x;
5501 *y = mSY + menu.main.button.prev_level.y;
5504 case SCREEN_CTRL_ID_NEXT_LEVEL:
5505 *x = mSX + menu.main.button.next_level.x;
5506 *y = mSY + menu.main.button.next_level.y;
5509 case SCREEN_CTRL_ID_PREV_LEVEL:
5510 *x = mSX + TILEX * getPrevlevelButtonPos();
5511 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5514 case SCREEN_CTRL_ID_NEXT_LEVEL:
5515 *x = mSX + TILEX * getNextLevelButtonPos();
5516 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5520 case SCREEN_CTRL_ID_PREV_PLAYER:
5521 *x = mSX + TILEX * 10;
5522 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5525 case SCREEN_CTRL_ID_NEXT_PLAYER:
5526 *x = mSX + TILEX * 12;
5527 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5531 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5537 int gfx_unpressed, gfx_pressed;
5538 void (*get_gadget_position)(int *, int *, int);
5542 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5545 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5546 getScreenMenuButtonPos,
5547 SCREEN_CTRL_ID_PREV_LEVEL,
5552 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5553 getScreenMenuButtonPos,
5554 SCREEN_CTRL_ID_NEXT_LEVEL,
5559 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5560 getScreenMenuButtonPos,
5561 SCREEN_CTRL_ID_PREV_PLAYER,
5566 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5567 getScreenMenuButtonPos,
5568 SCREEN_CTRL_ID_NEXT_PLAYER,
5576 int gfx_unpressed, gfx_pressed;
5580 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5583 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5584 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5585 SCREEN_CTRL_ID_SCROLL_UP,
5589 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5590 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5591 SCREEN_CTRL_ID_SCROLL_DOWN,
5598 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5599 Bitmap **gfx_unpressed, **gfx_pressed;
5601 int gfx_unpressed, gfx_pressed;
5608 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5611 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5612 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5614 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5616 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5617 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5618 GD_TYPE_SCROLLBAR_VERTICAL,
5619 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5620 "scroll level series vertically"
5624 static void CreateScreenMenubuttons()
5626 struct GadgetInfo *gi;
5627 unsigned long event_mask;
5630 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5632 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5633 int gfx_unpressed, gfx_pressed;
5634 int x, y, width, height;
5635 int gd_x1, gd_x2, gd_y1, gd_y2;
5636 int id = menubutton_info[i].gadget_id;
5638 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5640 menubutton_info[i].get_gadget_position(&x, &y, id);
5642 width = SC_MENUBUTTON_XSIZE;
5643 height = SC_MENUBUTTON_YSIZE;
5645 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5646 gfx_pressed = menubutton_info[i].gfx_pressed;
5647 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5648 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5649 gd_x1 = graphic_info[gfx_unpressed].src_x;
5650 gd_y1 = graphic_info[gfx_unpressed].src_y;
5651 gd_x2 = graphic_info[gfx_pressed].src_x;
5652 gd_y2 = graphic_info[gfx_pressed].src_y;
5654 gi = CreateGadget(GDI_CUSTOM_ID, id,
5655 GDI_CUSTOM_TYPE_ID, i,
5656 GDI_INFO_TEXT, menubutton_info[i].infotext,
5661 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5662 GDI_STATE, GD_BUTTON_UNPRESSED,
5663 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5664 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5665 GDI_DIRECT_DRAW, FALSE,
5666 GDI_EVENT_MASK, event_mask,
5667 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5671 Error(ERR_EXIT, "cannot create gadget");
5673 screen_gadget[id] = gi;
5677 static void CreateScreenScrollbuttons()
5679 struct GadgetInfo *gi;
5680 unsigned long event_mask;
5683 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5685 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5686 int gfx_unpressed, gfx_pressed;
5687 int x, y, width, height;
5688 int gd_x1, gd_x2, gd_y1, gd_y2;
5689 int id = scrollbutton_info[i].gadget_id;
5691 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5693 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5694 y = mSY + scrollbutton_info[i].y;
5695 width = SC_SCROLLBUTTON_XSIZE;
5696 height = SC_SCROLLBUTTON_YSIZE;
5698 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5699 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5700 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5702 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5703 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5704 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5705 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5706 gd_x1 = graphic_info[gfx_unpressed].src_x;
5707 gd_y1 = graphic_info[gfx_unpressed].src_y;
5708 gd_x2 = graphic_info[gfx_pressed].src_x;
5709 gd_y2 = graphic_info[gfx_pressed].src_y;
5711 gi = CreateGadget(GDI_CUSTOM_ID, id,
5712 GDI_CUSTOM_TYPE_ID, i,
5713 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5718 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5719 GDI_STATE, GD_BUTTON_UNPRESSED,
5720 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5721 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5722 GDI_DIRECT_DRAW, FALSE,
5723 GDI_EVENT_MASK, event_mask,
5724 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5728 Error(ERR_EXIT, "cannot create gadget");
5730 screen_gadget[id] = gi;
5734 static void CreateScreenScrollbars()
5738 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5740 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5741 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5742 int gfx_unpressed, gfx_pressed;
5744 int x, y, width, height;
5745 int gd_x1, gd_x2, gd_y1, gd_y2;
5746 struct GadgetInfo *gi;
5747 int items_max, items_visible, item_position;
5748 unsigned long event_mask;
5749 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5750 int id = scrollbar_info[i].gadget_id;
5752 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5754 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5755 y = mSY + scrollbar_info[i].y;
5756 width = scrollbar_info[i].width;
5757 height = scrollbar_info[i].height;
5759 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5760 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5762 items_max = num_page_entries;
5763 items_visible = num_page_entries;
5766 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5767 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5768 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5774 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5775 gfx_pressed = scrollbar_info[i].gfx_pressed;
5776 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5777 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5778 gd_x1 = graphic_info[gfx_unpressed].src_x;
5779 gd_y1 = graphic_info[gfx_unpressed].src_y;
5780 gd_x2 = graphic_info[gfx_pressed].src_x;
5781 gd_y2 = graphic_info[gfx_pressed].src_y;
5784 gi = CreateGadget(GDI_CUSTOM_ID, id,
5785 GDI_CUSTOM_TYPE_ID, i,
5786 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5791 GDI_TYPE, scrollbar_info[i].type,
5792 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5793 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5794 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5796 GDI_WHEEL_AREA_X, SX,
5797 GDI_WHEEL_AREA_Y, SY,
5798 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5799 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5801 GDI_WHEEL_AREA_X, 0,
5802 GDI_WHEEL_AREA_Y, 0,
5803 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5804 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5806 GDI_STATE, GD_BUTTON_UNPRESSED,
5807 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5808 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5809 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5810 GDI_DIRECT_DRAW, FALSE,
5811 GDI_EVENT_MASK, event_mask,
5812 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5816 Error(ERR_EXIT, "cannot create gadget");
5818 screen_gadget[id] = gi;
5822 void CreateScreenGadgets()
5824 int last_game_status = game_status; /* save current game status */
5826 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5829 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5831 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5833 /* copy pointers to clip mask and GC */
5834 scrollbar_bitmap[i]->clip_mask =
5835 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5836 scrollbar_bitmap[i]->stored_clip_gc =
5837 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5839 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5840 scrollbar_bitmap[i],
5841 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5842 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5843 TILEX, TILEY, 0, 0);
5847 CreateScreenMenubuttons();
5850 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5851 game_status = GAME_MODE_LEVELS;
5854 CreateScreenScrollbuttons();
5855 CreateScreenScrollbars();
5857 game_status = last_game_status; /* restore current game status */
5860 void FreeScreenGadgets()
5864 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5865 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5867 /* prevent freeing clip mask and GC twice */
5868 scrollbar_bitmap[i]->clip_mask = None;
5869 scrollbar_bitmap[i]->stored_clip_gc = None;
5871 FreeBitmap(scrollbar_bitmap[i]);
5875 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5876 FreeGadget(screen_gadget[i]);
5879 void MapScreenMenuGadgets(int screen_mask)
5883 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5884 if (screen_mask & menubutton_info[i].screen_mask)
5885 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5888 void MapScreenTreeGadgets(TreeInfo *ti)
5890 int num_entries = numTreeInfoInGroup(ti);
5893 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5896 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5897 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5899 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5900 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5903 static void HandleScreenGadgets(struct GadgetInfo *gi)
5905 int id = gi->custom_id;
5906 int button = gi->event.button;
5907 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5911 case SCREEN_CTRL_ID_PREV_LEVEL:
5912 HandleMainMenu_SelectLevel(step, -1);
5915 case SCREEN_CTRL_ID_NEXT_LEVEL:
5916 HandleMainMenu_SelectLevel(step, +1);
5919 case SCREEN_CTRL_ID_PREV_PLAYER:
5920 HandleSetupScreen_Input_Player(step, -1);
5923 case SCREEN_CTRL_ID_NEXT_PLAYER:
5924 HandleSetupScreen_Input_Player(step, +1);
5927 case SCREEN_CTRL_ID_SCROLL_UP:
5928 if (game_status == GAME_MODE_LEVELS)
5929 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5930 else if (game_status == GAME_MODE_SETUP)
5931 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5934 case SCREEN_CTRL_ID_SCROLL_DOWN:
5935 if (game_status == GAME_MODE_LEVELS)
5936 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5937 else if (game_status == GAME_MODE_SETUP)
5938 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5941 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5942 if (game_status == GAME_MODE_LEVELS)
5943 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5944 else if (game_status == GAME_MODE_SETUP)
5945 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);