1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
28 /* screens on the info screen */
29 #define INFO_MODE_MAIN 0
30 #define INFO_MODE_TITLE 1
31 #define INFO_MODE_ELEMENTS 2
32 #define INFO_MODE_MUSIC 3
33 #define INFO_MODE_CREDITS 4
34 #define INFO_MODE_PROGRAM 5
35 #define INFO_MODE_VERSION 6
36 #define INFO_MODE_LEVELSET 7
38 #define MAX_INFO_MODES 8
40 /* screens on the setup screen */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_SHORTCUTS_1 7
49 #define SETUP_MODE_SHORTCUTS_2 8
51 /* sub-screens on the setup screen (generic) */
52 #define SETUP_MODE_CHOOSE_ARTWORK 9
53 #define SETUP_MODE_CHOOSE_OTHER 10
55 /* sub-screens on the setup screen (specific) */
56 #define SETUP_MODE_CHOOSE_GAME_SPEED 11
57 #define SETUP_MODE_CHOOSE_SCREEN_MODE 12
58 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 13
59 #define SETUP_MODE_CHOOSE_GRAPHICS 14
60 #define SETUP_MODE_CHOOSE_SOUNDS 15
61 #define SETUP_MODE_CHOOSE_MUSIC 16
63 #define MAX_SETUP_MODES 17
65 /* for input setup functions */
66 #define SETUPINPUT_SCREEN_POS_START 0
67 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
68 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
69 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
71 /* for various menu stuff */
72 #define MENU_SCREEN_START_XPOS 1
73 #define MENU_SCREEN_START_YPOS 2
74 #define MENU_SCREEN_VALUE_XPOS 14
75 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
76 #define MENU_TITLE1_YPOS 8
77 #define MENU_TITLE2_YPOS 46
78 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
79 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
80 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
81 MENU_SCREEN_START_XPOS)
82 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
84 /* buttons and scrollbars identifiers */
85 #define SCREEN_CTRL_ID_PREV_LEVEL 0
86 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
87 #define SCREEN_CTRL_ID_PREV_PLAYER 2
88 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
89 #define SCREEN_CTRL_ID_SCROLL_UP 4
90 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
91 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
93 #define NUM_SCREEN_GADGETS 7
95 #define NUM_SCREEN_MENUBUTTONS 4
96 #define NUM_SCREEN_SCROLLBUTTONS 2
97 #define NUM_SCREEN_SCROLLBARS 1
99 #define SCREEN_MASK_MAIN (1 << 0)
100 #define SCREEN_MASK_INPUT (1 << 1)
102 /* graphic position and size values for buttons and scrollbars */
103 #define SC_MENUBUTTON_XSIZE TILEX
104 #define SC_MENUBUTTON_YSIZE TILEY
106 #define SC_SCROLLBUTTON_XSIZE TILEX
107 #define SC_SCROLLBUTTON_YSIZE TILEY
109 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
111 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
112 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
113 SC_SCROLLBUTTON_YSIZE)
115 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
118 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
119 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
120 SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
124 SC_SCROLL_VERTICAL_YSIZE)
126 #define SC_BORDER_SIZE 14
129 /* forward declarations of internal functions */
130 static void HandleScreenGadgets(struct GadgetInfo *);
131 static void HandleSetupScreen_Generic(int, int, int, int, int);
132 static void HandleSetupScreen_Input(int, int, int, int, int);
133 static void CustomizeKeyboard(int);
134 static void CalibrateJoystick(int);
135 static void execSetupGame(void);
136 static void execSetupGraphics(void);
137 static void execSetupArtwork(void);
138 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
140 static void DrawChooseLevel(void);
141 static void DrawInfoScreen(void);
142 static void DrawAndFadeInInfoScreen(int);
143 static void DrawSetupScreen(void);
145 static void DrawInfoScreenExt(int, int);
146 static void DrawInfoScreen_NotAvailable(char *, char *);
147 static void DrawInfoScreen_HelpAnim(int, int, boolean);
148 static void DrawInfoScreen_HelpText(int, int, int, int);
149 static void HandleInfoScreen_Main(int, int, int, int, int);
150 static void HandleInfoScreen_TitleScreen(int);
151 static void HandleInfoScreen_Elements(int);
152 static void HandleInfoScreen_Music(int);
153 static void HandleInfoScreen_Credits(int);
154 static void HandleInfoScreen_Program(int);
155 static void HandleInfoScreen_Version(int);
157 static void MapScreenMenuGadgets(int);
158 static void MapScreenTreeGadgets(TreeInfo *);
160 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
162 static int info_mode = INFO_MODE_MAIN;
163 static int setup_mode = SETUP_MODE_MAIN;
165 static TreeInfo *screen_modes = NULL;
166 static TreeInfo *screen_mode_current = NULL;
168 static TreeInfo *scroll_delays = NULL;
169 static TreeInfo *scroll_delay_current = NULL;
171 static TreeInfo *game_speeds = NULL;
172 static TreeInfo *game_speed_current = NULL;
178 } game_speeds_list[] =
187 { 1000, "1/1s (Extremely Slow)" },
192 { 29, "1/35s (Original Supaplex)" },
194 { 20, "1/50s (Normal Speed)" },
195 { 14, "1/70s (Maximum Supaplex)" },
199 { 1, "1/1000s (Extremely Fast)" },
209 } scroll_delays_list[] =
211 { 0, "0 Tiles (No Scroll Delay)" },
214 { 3, "3 Tiles (Default)" },
219 { 8, "8 Tiles (Maximum Scroll Delay)"},
224 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
225 (s) <= GAME_MODE_SETUP ? (s) : \
226 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
227 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
229 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
230 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
231 (i) <= INFO_MODE_LEVELSET ? (i) : \
234 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
235 (i) <= SETUP_MODE_SHORTCUTS_2 ? (i) : \
236 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
237 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
238 SETUP_MODE_CHOOSE_ARTWORK : \
239 SETUP_MODE_CHOOSE_OTHER)
241 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
242 menu.draw_xoffset[GAME_MODE_INFO] : \
243 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
244 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
245 menu.draw_yoffset[GAME_MODE_INFO] : \
246 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
248 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
249 menu.draw_xoffset[GAME_MODE_SETUP] : \
250 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
251 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
252 menu.draw_yoffset[GAME_MODE_SETUP] : \
253 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
255 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
256 DRAW_XOFFSET_INFO(info_mode) : \
257 (s) == GAME_MODE_SETUP ? \
258 DRAW_XOFFSET_SETUP(setup_mode) : \
259 menu.draw_xoffset[DRAW_MODE(s)])
260 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
261 DRAW_YOFFSET_INFO(info_mode) : \
262 (s) == GAME_MODE_SETUP ? \
263 DRAW_YOFFSET_SETUP(setup_mode) : \
264 menu.draw_yoffset[DRAW_MODE(s)])
266 #define mSX (SX + DRAW_XOFFSET(game_status))
267 #define mSY (SY + DRAW_YOFFSET(game_status))
269 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
270 menu.list_size[game_status] : \
271 MAX_MENU_ENTRIES_ON_SCREEN)
273 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
274 #define NUM_SCROLLBAR_BITMAPS 2
275 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
279 /* title display and control definitions */
281 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
282 2 * MAX_NUM_TITLE_MESSAGES)
284 static int num_title_screens = 0;
286 struct TitleControlInfo
294 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
296 /* main menu display and control definitions */
298 #define MAIN_CONTROL_NAME 0
299 #define MAIN_CONTROL_LEVELS 1
300 #define MAIN_CONTROL_SCORES 2
301 #define MAIN_CONTROL_EDITOR 3
302 #define MAIN_CONTROL_INFO 4
303 #define MAIN_CONTROL_GAME 5
304 #define MAIN_CONTROL_SETUP 6
305 #define MAIN_CONTROL_QUIT 7
306 #define MAIN_CONTROL_PREV_LEVEL 8
307 #define MAIN_CONTROL_NEXT_LEVEL 9
308 #define MAIN_CONTROL_FIRST_LEVEL 10
309 #define MAIN_CONTROL_LAST_LEVEL 11
310 #define MAIN_CONTROL_LEVEL_NUMBER 12
311 #define MAIN_CONTROL_LEVEL_INFO_1 13
312 #define MAIN_CONTROL_LEVEL_INFO_2 14
313 #define MAIN_CONTROL_LEVEL_NAME 15
314 #define MAIN_CONTROL_LEVEL_AUTHOR 16
315 #define MAIN_CONTROL_LEVEL_YEAR 17
316 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
317 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
318 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
319 #define MAIN_CONTROL_TITLE_1 21
320 #define MAIN_CONTROL_TITLE_2 22
321 #define MAIN_CONTROL_TITLE_3 23
323 static char str_main_text_name[10];
324 static char str_main_text_first_level[10];
325 static char str_main_text_last_level[10];
326 static char str_main_text_level_number[10];
328 static char *main_text_name = str_main_text_name;
329 static char *main_text_first_level = str_main_text_first_level;
330 static char *main_text_last_level = str_main_text_last_level;
331 static char *main_text_level_number = str_main_text_level_number;
332 static char *main_text_levels = "Levelset";
333 static char *main_text_scores = "Hall Of Fame";
334 static char *main_text_editor = "Level Creator";
335 static char *main_text_info = "Info Screen";
336 static char *main_text_game = "Start Game";
337 static char *main_text_setup = "Setup";
338 static char *main_text_quit = "Quit";
339 static char *main_text_level_name = level.name;
340 static char *main_text_level_author = level.author;
341 static char *main_text_level_year = NULL;
342 static char *main_text_level_imported_from = NULL;
343 static char *main_text_level_imported_by = NULL;
344 static char *main_text_level_tested_by = NULL;
345 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
346 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
347 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
349 struct MainControlInfo
353 struct MenuPosInfo *pos_button;
356 struct TextPosInfo *pos_text;
359 struct TextPosInfo *pos_input;
363 static struct MainControlInfo main_controls[] =
367 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
368 &menu.main.text.name, &main_text_name,
369 &menu.main.input.name, &setup.player_name,
373 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
374 &menu.main.text.levels, &main_text_levels,
379 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
380 &menu.main.text.scores, &main_text_scores,
385 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
386 &menu.main.text.editor, &main_text_editor,
391 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
392 &menu.main.text.info, &main_text_info,
397 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
398 &menu.main.text.game, &main_text_game,
403 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
404 &menu.main.text.setup, &main_text_setup,
409 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
410 &menu.main.text.quit, &main_text_quit,
414 /* (these two buttons are real gadgets) */
416 MAIN_CONTROL_PREV_LEVEL,
417 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
422 MAIN_CONTROL_NEXT_LEVEL,
423 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
429 MAIN_CONTROL_FIRST_LEVEL,
431 &menu.main.text.first_level, &main_text_first_level,
435 MAIN_CONTROL_LAST_LEVEL,
437 &menu.main.text.last_level, &main_text_last_level,
441 MAIN_CONTROL_LEVEL_NUMBER,
443 &menu.main.text.level_number, &main_text_level_number,
447 MAIN_CONTROL_LEVEL_INFO_1,
449 &menu.main.text.level_info_1, NULL,
453 MAIN_CONTROL_LEVEL_INFO_2,
455 &menu.main.text.level_info_2, NULL,
459 MAIN_CONTROL_LEVEL_NAME,
461 &menu.main.text.level_name, &main_text_level_name,
465 MAIN_CONTROL_LEVEL_AUTHOR,
467 &menu.main.text.level_author, &main_text_level_author,
471 MAIN_CONTROL_LEVEL_YEAR,
473 &menu.main.text.level_year, &main_text_level_year,
477 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
479 &menu.main.text.level_imported_from, &main_text_level_imported_from,
483 MAIN_CONTROL_LEVEL_IMPORTED_BY,
485 &menu.main.text.level_imported_by, &main_text_level_imported_by,
489 MAIN_CONTROL_LEVEL_TESTED_BY,
491 &menu.main.text.level_tested_by, &main_text_level_tested_by,
495 MAIN_CONTROL_TITLE_1,
497 &menu.main.text.title_1, &main_text_title_1,
501 MAIN_CONTROL_TITLE_2,
503 &menu.main.text.title_2, &main_text_title_2,
507 MAIN_CONTROL_TITLE_3,
509 &menu.main.text.title_3, &main_text_title_3,
522 static int getTitleScreenGraphic(int nr, boolean initial)
524 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
527 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
529 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
533 static int getTitleScreenGameMode(boolean initial)
535 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
539 static int getTitleMessageGameMode(boolean initial)
541 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
545 static int getTitleScreenBackground(boolean initial)
547 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
552 static int getTitleMessageBackground(int nr, boolean initial)
554 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
558 static int getTitleBackground(int nr, boolean initial, boolean is_image)
560 int base = (is_image ?
561 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
562 IMG_BACKGROUND_TITLESCREEN_1) :
563 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
564 IMG_BACKGROUND_TITLEMESSAGE_1));
565 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
566 IMG_BACKGROUND_TITLE);
567 int graphic_local = base + nr;
569 if (graphic_info[graphic_local].bitmap != NULL)
570 return graphic_local;
572 if (graphic_info[graphic_global].bitmap != NULL)
573 return graphic_global;
575 return IMG_UNDEFINED;
578 static int getTitleSound(struct TitleControlInfo *tci)
580 boolean is_image = tci->is_image;
581 int initial = tci->initial;
582 int nr = tci->local_nr;
583 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
584 int base = (is_image ?
585 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
586 SND_BACKGROUND_TITLESCREEN_1) :
587 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
588 SND_BACKGROUND_TITLEMESSAGE_1));
589 int sound_global = menu.sound[mode];
590 int sound_local = base + nr;
593 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
594 nr, initial, is_image,
595 sound_global, getSoundListEntry(sound_global)->filename,
596 sound_local, getSoundListEntry(sound_local)->filename);
599 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
602 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
605 return SND_UNDEFINED;
608 static int getTitleMusic(struct TitleControlInfo *tci)
610 boolean is_image = tci->is_image;
611 int initial = tci->initial;
612 int nr = tci->local_nr;
613 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
614 int base = (is_image ?
615 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
616 MUS_BACKGROUND_TITLESCREEN_1) :
617 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
618 MUS_BACKGROUND_TITLEMESSAGE_1));
619 int music_global = menu.music[mode];
620 int music_local = base + nr;
623 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
624 nr, initial, is_image,
625 music_global, getMusicListEntry(music_global)->filename,
626 music_local, getMusicListEntry(music_local)->filename);
629 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
632 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
635 return MUS_UNDEFINED;
638 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
640 boolean is_image = tci->is_image;
641 int initial = tci->initial;
642 int nr = tci->local_nr;
643 struct TitleFadingInfo ti;
647 int graphic = getTitleScreenGraphic(nr, initial);
649 /* initialize fading control values to default title config settings */
650 ti = (initial ? title_initial_default : title_default);
652 /* override default settings with image config settings, if defined */
653 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
654 ti.fade_mode = graphic_info[graphic].fade_mode;
655 if (graphic_info[graphic].fade_delay > -1)
656 ti.fade_delay = graphic_info[graphic].fade_delay;
657 if (graphic_info[graphic].post_delay > -1)
658 ti.post_delay = graphic_info[graphic].post_delay;
659 if (graphic_info[graphic].auto_delay > -1)
660 ti.auto_delay = graphic_info[graphic].auto_delay;
666 ti.fade_mode = titlemessage_initial[nr].fade_mode;
667 ti.fade_delay = titlemessage_initial[nr].fade_delay;
668 ti.post_delay = titlemessage_initial[nr].post_delay;
669 ti.auto_delay = titlemessage_initial[nr].auto_delay;
673 ti.fade_mode = titlemessage[nr].fade_mode;
674 ti.fade_delay = titlemessage[nr].fade_delay;
675 ti.post_delay = titlemessage[nr].post_delay;
676 ti.auto_delay = titlemessage[nr].auto_delay;
681 if (ti.anim_mode == ANIM_NONE)
682 ti.fade_delay = ti.post_delay = 0;
688 static int compareTitleControlInfo(const void *object1, const void *object2)
690 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
691 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
694 if (tci1->initial != tci2->initial)
695 compare_result = (tci1->initial ? -1 : +1);
696 else if (tci1->sort_priority != tci2->sort_priority)
697 compare_result = tci1->sort_priority - tci2->sort_priority;
698 else if (tci1->is_image != tci2->is_image)
699 compare_result = (tci1->is_image ? -1 : +1);
701 compare_result = tci1->local_nr - tci2->local_nr;
703 return compare_result;
706 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
708 int nr, int sort_priority)
710 title_controls[num_title_screens].is_image = is_image;
711 title_controls[num_title_screens].initial = initial;
712 title_controls[num_title_screens].local_nr = nr;
713 title_controls[num_title_screens].sort_priority = sort_priority;
718 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
722 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
724 int graphic = getTitleScreenGraphic(i, initial);
725 Bitmap *bitmap = graphic_info[graphic].bitmap;
726 int sort_priority = graphic_info[graphic].sort_priority;
729 /* skip images and messages (fonts!) when using forced custom graphics */
730 if (setup.override_level_graphics && !initial)
735 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
738 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
740 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
741 char *filename = getLevelSetTitleMessageFilename(i, initial);
742 int sort_priority = tmi->sort_priority;
745 /* skip images and messages (fonts!) when using forced custom graphics */
746 if (setup.override_level_graphics)
750 if (filename != NULL)
751 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
755 static void InitializeTitleControls(boolean show_title_initial)
757 num_title_screens = 0;
760 if (show_title_initial)
761 InitializeTitleControls_CheckTitleInfo(TRUE);
764 InitializeTitleControls_CheckTitleInfo(FALSE);
766 /* sort title screens according to sort_priority and title number */
767 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
768 compareTitleControlInfo);
771 static boolean visibleMenuPos(struct MenuPosInfo *pos)
773 return (pos != NULL && pos->x != -1 && pos->y != -1);
776 static boolean visibleTextPos(struct TextPosInfo *pos)
778 return (pos != NULL && pos->x != -1 && pos->y != -1);
781 static void InitializeMainControls()
783 boolean local_team_mode = (!options.network && setup.team_mode);
786 /* set main control text values to dynamically determined values */
787 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
789 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
790 menu.main.text.first_level.size));
791 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
792 menu.main.text.last_level.size));
793 strcpy(main_text_level_number, int2str(level_nr,
794 menu.main.text.level_number.size));
796 main_text_level_year = leveldir_current->year;
797 main_text_level_imported_from = leveldir_current->imported_from;
798 main_text_level_imported_by = leveldir_current->imported_by;
799 main_text_level_tested_by = leveldir_current->tested_by;
801 /* set main control screen positions to dynamically determined values */
802 for (i = 0; main_controls[i].nr != -1; i++)
804 struct MainControlInfo *mci = &main_controls[i];
806 struct MenuPosInfo *pos_button = mci->pos_button;
807 struct TextPosInfo *pos_text = mci->pos_text;
808 struct TextPosInfo *pos_input = mci->pos_input;
809 char *text = (mci->text ? *mci->text : NULL);
810 char *input = (mci->input ? *mci->input : NULL);
811 int button_graphic = mci->button_graphic;
813 int font_text = (pos_text ? pos_text->font : -1);
814 int font_input = (pos_input ? pos_input->font : -1);
816 int font_text = mci->font_text;
817 int font_input = mci->font_input;
820 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
821 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
822 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
823 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
824 int text_chars = (text != NULL ? strlen(text) : 0);
825 int input_chars = (input != NULL ? strlen(input) : 0);
828 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
830 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
831 int text_width = font_text_width * text_chars;
832 int text_height = font_text_height;
833 int input_width = font_input_width * input_chars;
834 int input_height = font_input_height;
836 if (nr == MAIN_CONTROL_NAME)
839 if (menu.main.input.name.x == -1)
840 menu.main.input.name.x = menu.main.text.name.x + text_width;
841 if (menu.main.input.name.y == -1)
842 menu.main.input.name.y = menu.main.text.name.y;
846 menu.main.input.name.width = input_width;
847 menu.main.input.name.height = input_height;
849 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
850 menu.main.input.name.height = font_input_height;
854 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
856 if (pos_button->width == 0)
857 pos_button->width = button_width;
858 if (pos_button->height == 0)
859 pos_button->height = button_height;
862 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
864 /* calculate width for non-clickable text -- needed for text alignment */
865 boolean calculate_text_width = (pos_button == NULL && text != NULL);
867 if (visibleMenuPos(pos_button))
869 if (pos_text->x == -1)
870 pos_text->x = pos_button->x + pos_button->width;
871 if (pos_text->y == -1)
872 pos_text->y = pos_button->y;
875 if (pos_text->width == -1 || calculate_text_width)
876 pos_text->width = text_width;
877 if (pos_text->height == -1)
878 pos_text->height = text_height;
881 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
883 if (visibleTextPos(pos_text))
885 if (pos_input->x == -1)
886 pos_input->x = pos_text->x + pos_text->width;
887 if (pos_input->y == -1)
888 pos_input->y = pos_text->y;
891 if (pos_input->width == -1)
892 pos_input->width = input_width;
893 if (pos_input->height == -1)
894 pos_input->height = input_height;
899 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
900 boolean active_input)
904 for (i = 0; main_controls[i].nr != -1; i++)
906 struct MainControlInfo *mci = &main_controls[i];
908 if (mci->nr == nr || nr == -1)
910 struct MenuPosInfo *pos_button = mci->pos_button;
911 struct TextPosInfo *pos_text = mci->pos_text;
912 struct TextPosInfo *pos_input = mci->pos_input;
913 char *text = (mci->text ? *mci->text : NULL);
914 char *input = (mci->input ? *mci->input : NULL);
915 int button_graphic = mci->button_graphic;
917 int font_text = (pos_text ? pos_text->font : -1);
918 int font_input = (pos_input ? pos_input->font : -1);
920 int font_text = mci->font_text;
921 int font_input = mci->font_input;
926 button_graphic = BUTTON_ACTIVE(button_graphic);
927 font_text = FONT_ACTIVE(font_text);
932 font_input = FONT_ACTIVE(font_input);
935 if (visibleMenuPos(pos_button))
937 struct MenuPosInfo *pos = pos_button;
938 int x = mSX + pos->x;
939 int y = mSY + pos->y;
941 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
942 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
945 if (visibleTextPos(pos_text) && text != NULL)
947 struct TextPosInfo *pos = pos_text;
948 int x = mSX + ALIGNED_TEXT_XPOS(pos);
949 int y = mSY + ALIGNED_TEXT_YPOS(pos);
952 /* (check why/if this is needed) */
953 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
955 DrawText(x, y, text, font_text);
958 if (visibleTextPos(pos_input) && input != NULL)
960 struct TextPosInfo *pos = pos_input;
961 int x = mSX + ALIGNED_TEXT_XPOS(pos);
962 int y = mSY + ALIGNED_TEXT_YPOS(pos);
965 /* (check why/if this is needed) */
966 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
968 DrawText(x, y, input, font_input);
974 static void DrawCursorAndText_Main(int nr, boolean active_text)
976 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
980 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
982 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
986 static struct MainControlInfo *getMainControlInfo(int nr)
990 for (i = 0; main_controls[i].nr != -1; i++)
991 if (main_controls[i].nr == nr)
992 return &main_controls[i];
997 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1002 int rect_x = ALIGNED_TEXT_XPOS(rect);
1003 int rect_y = ALIGNED_TEXT_YPOS(rect);
1005 return (x >= rect_x && x < rect_x + rect->width &&
1006 y >= rect_y && y < rect_y + rect->height);
1009 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1014 int rect_x = ALIGNED_TEXT_XPOS(rect);
1015 int rect_y = ALIGNED_TEXT_YPOS(rect);
1017 return (x >= rect_x && x < rect_x + rect->width &&
1018 y >= rect_y && y < rect_y + rect->height);
1021 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1023 static int cursor_array[SCR_FIELDY];
1024 int x = mSX + TILEX * xpos;
1025 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1030 cursor_array[ypos] = graphic;
1032 graphic = cursor_array[ypos];
1036 graphic = BUTTON_ACTIVE(graphic);
1038 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1039 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1042 static void initCursor(int ypos, int graphic)
1044 drawCursorExt(0, ypos, FALSE, graphic);
1047 static void drawCursor(int ypos, boolean active)
1049 drawCursorExt(0, ypos, active, -1);
1052 static void drawCursorXY(int xpos, int ypos, int graphic)
1054 drawCursorExt(xpos, ypos, FALSE, graphic);
1057 static void drawChooseTreeCursor(int ypos, boolean active)
1059 int last_game_status = game_status; /* save current game status */
1062 /* force LEVELS draw offset on artwork setup screen */
1063 game_status = GAME_MODE_LEVELS;
1066 drawCursorExt(0, ypos, active, -1);
1068 game_status = last_game_status; /* restore current game status */
1073 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1074 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1078 static int getPrevlevelButtonPos()
1083 static int getCurrentLevelTextPos()
1085 return (getPrevlevelButtonPos() + 1);
1088 static int getNextLevelButtonPos()
1090 return getPrevlevelButtonPos() + 3 + 1;
1093 static int getLevelRangeTextPos()
1095 return getNextLevelButtonPos() + 1;
1099 int effectiveGameStatus()
1101 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1102 return GAME_MODE_TITLE;
1107 void DrawTitleScreenImage(int nr, boolean initial)
1109 int graphic = getTitleScreenGraphic(nr, initial);
1110 Bitmap *bitmap = graphic_info[graphic].bitmap;
1111 int width = graphic_info[graphic].width;
1112 int height = graphic_info[graphic].height;
1113 int src_x = graphic_info[graphic].src_x;
1114 int src_y = graphic_info[graphic].src_y;
1120 if (width > WIN_XSIZE)
1122 /* image width too large for window => center image horizontally */
1123 src_x = (width - WIN_XSIZE) / 2;
1127 if (height > WIN_YSIZE)
1129 /* image height too large for window => center image vertically */
1130 src_y = (height - WIN_YSIZE) / 2;
1134 /* always display title screens centered */
1135 dst_x = (WIN_XSIZE - width) / 2;
1136 dst_y = (WIN_YSIZE - height) / 2;
1138 SetDrawBackgroundMask(REDRAW_ALL);
1139 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1141 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1143 if (DrawingOnBackground(dst_x, dst_y))
1144 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1146 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1148 redraw_mask = REDRAW_ALL;
1151 void DrawTitleScreenMessage(int nr, boolean initial)
1153 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1154 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1155 int last_game_status = game_status; /* save current game status */
1157 if (filename == NULL)
1160 /* force TITLE font on title message screen */
1161 game_status = getTitleMessageGameMode(initial);
1163 /* if chars set to "-1", automatically determine by text and font width */
1164 if (tmi->chars == -1)
1165 tmi->chars = tmi->width / getFontWidth(tmi->font);
1167 tmi->width = tmi->chars * getFontWidth(tmi->font);
1169 /* if lines set to "-1", automatically determine by text and font height */
1170 if (tmi->lines == -1)
1171 tmi->lines = tmi->height / getFontHeight(tmi->font);
1173 tmi->height = tmi->lines * getFontHeight(tmi->font);
1175 SetDrawBackgroundMask(REDRAW_ALL);
1176 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1178 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1180 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1181 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1182 tmi->autowrap, tmi->centered, tmi->parse_comments);
1184 game_status = last_game_status; /* restore current game status */
1187 void DrawTitleScreen()
1189 KeyboardAutoRepeatOff();
1192 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1195 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1200 boolean CheckTitleScreen(boolean levelset_has_changed)
1202 static boolean show_title_initial = TRUE;
1203 boolean show_titlescreen = FALSE;
1205 /* needed to be able to skip title screen, if no image or message defined */
1206 InitializeTitleControls(show_title_initial);
1208 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1209 show_titlescreen = TRUE;
1211 /* show initial title images and messages only once at program start */
1212 show_title_initial = FALSE;
1214 return (show_titlescreen && num_title_screens > 0);
1217 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1219 static LevelDirTree *leveldir_last_valid = NULL;
1220 boolean levelset_has_changed = FALSE;
1222 FadeSetLeaveScreen();
1224 /* do not fade out here -- function may continue and fade on editor screen */
1227 FadeSoundsAndMusic();
1229 KeyboardAutoRepeatOn();
1232 SetDrawDeactivationMask(REDRAW_NONE);
1233 SetDrawBackgroundMask(REDRAW_FIELD);
1235 audio.sound_deactivated = FALSE;
1239 /* needed if last screen was the playing screen, invoked from level editor */
1240 if (level_editor_test_game)
1242 game_status = GAME_MODE_EDITOR;
1248 /* needed if last screen was the setup screen and fullscreen state changed */
1249 ToggleFullscreenIfNeeded();
1251 /* leveldir_current may be invalid (level group, parent link) */
1252 if (!validLevelSeries(leveldir_current))
1253 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1255 if (leveldir_current != leveldir_last_valid)
1256 levelset_has_changed = TRUE;
1258 /* store valid level series information */
1259 leveldir_last_valid = leveldir_current;
1261 /* needed if last screen (level choice) changed graphics, sounds or music */
1262 ReloadCustomArtwork(0);
1264 if (redraw_mask & REDRAW_ALL)
1265 fade_mask = REDRAW_ALL;
1270 /* needed if last screen was the editor screen */
1271 UndrawSpecialEditorDoor();
1272 if (fade_mask == REDRAW_FIELD)
1276 #if defined(TARGET_SDL)
1277 SetDrawtoField(DRAW_BACKBUFFER);
1280 if (CheckTitleScreen(levelset_has_changed))
1282 game_status = GAME_MODE_TITLE;
1289 /* level_nr may have been set to value over handicap with level editor */
1290 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1291 level_nr = leveldir_current->handicap_level;
1293 LoadLevel(level_nr);
1295 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1298 if (fade_mask == REDRAW_ALL)
1300 // int door_state = GetDoorState();
1304 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1310 InitializeMainControls();
1312 DrawCursorAndText_Main(-1, FALSE);
1313 DrawPreviewLevel(TRUE);
1315 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1318 if (TAPE_IS_EMPTY(tape))
1320 DrawCompleteVideoDisplay();
1325 /* create gadgets for main menu screen */
1326 FreeScreenGadgets();
1327 CreateScreenGadgets();
1329 /* map gadgets for main menu screen */
1331 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1334 if (fade_mask == REDRAW_ALL)
1336 int door_state = GetDoorState();
1338 // RedrawBackground();
1340 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1344 DrawMaskedBorder(REDRAW_ALL);
1349 SetMouseCursor(CURSOR_DEFAULT);
1353 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1356 void DrawAndFadeInMainMenu(int fade_mask)
1358 DrawMainMenuExt(fade_mask, TRUE);
1363 DrawMainMenuExt(REDRAW_ALL, FALSE);
1367 static void gotoTopLevelDir()
1369 /* move upwards to top level directory */
1370 while (leveldir_current->node_parent)
1372 /* write a "path" into level tree for easy navigation to last level */
1373 if (leveldir_current->node_parent->node_group->cl_first == -1)
1375 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1376 int leveldir_pos = posTreeInfo(leveldir_current);
1377 int num_page_entries;
1378 int cl_first, cl_cursor;
1380 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1381 num_page_entries = num_leveldirs;
1383 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1385 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1386 cl_cursor = leveldir_pos - cl_first;
1388 leveldir_current->node_parent->node_group->cl_first = cl_first;
1389 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1392 leveldir_current = leveldir_current->node_parent;
1397 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1399 static unsigned long title_delay = 0;
1400 static int title_screen_nr = 0;
1401 static int last_sound = -1, last_music = -1;
1402 boolean return_to_main_menu = FALSE;
1403 boolean use_fading_main_menu = TRUE;
1404 struct TitleControlInfo *tci;
1405 struct TitleFadingInfo fading_default;
1406 struct TitleFadingInfo fading_last = fading;
1407 struct TitleFadingInfo fading_next;
1410 if (button == MB_MENU_INITIALIZE)
1413 title_screen_nr = 0;
1414 tci = &title_controls[title_screen_nr];
1416 last_sound = SND_UNDEFINED;
1417 last_music = MUS_UNDEFINED;
1419 if (game_status == GAME_MODE_INFO)
1421 if (num_title_screens == 0)
1423 DrawInfoScreen_NotAvailable("Title screen information:",
1424 "No title screen for this level set.");
1429 FadeSoundsAndMusic();
1432 FadeOut(REDRAW_ALL);
1437 DrawTitleScreenImage(tci->local_nr, tci->initial);
1439 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1441 fading_default = (tci->initial ? title_initial_default : title_default);
1443 fading = fading_next = getTitleFading(tci);
1447 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1448 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1450 fading.fade_mode = FADE_MODE_FADE;
1451 fading.fade_delay = fading_default.fade_delay;
1454 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1455 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1456 fading.fade_mode = FADE_MODE_FADE;
1461 sound = getTitleSound(tci);
1462 music = getTitleMusic(tci);
1464 if (sound != last_sound)
1465 PlayMenuSoundExt(sound);
1466 if (music != last_music)
1467 PlayMenuMusicExt(music);
1473 SetMouseCursor(CURSOR_NONE);
1479 fading = fading_next;
1481 DelayReached(&title_delay, 0); /* reset delay counter */
1487 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1488 button = MB_MENU_CHOICE;
1490 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1491 button = MB_MENU_CHOICE;
1494 if (button == MB_MENU_LEAVE)
1496 return_to_main_menu = TRUE;
1497 use_fading_main_menu = FALSE;
1499 else if (button == MB_MENU_CHOICE)
1501 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1504 FadeOut(REDRAW_FIELD);
1507 FadeSetEnterScreen();
1509 info_mode = INFO_MODE_MAIN;
1510 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1516 tci = &title_controls[title_screen_nr];
1518 if (title_screen_nr < num_title_screens)
1520 sound = getTitleSound(tci);
1521 music = getTitleMusic(tci);
1523 if (sound == SND_UNDEFINED || sound != last_sound)
1525 if (music == MUS_UNDEFINED || music != last_music)
1529 FadeOut(REDRAW_ALL);
1533 DrawTitleScreenImage(tci->local_nr, tci->initial);
1535 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1537 fading_next = getTitleFading(tci);
1540 sound = getTitleSound(tci);
1541 music = getTitleMusic(tci);
1543 if (sound != last_sound)
1544 PlayMenuSoundExt(sound);
1545 if (music != last_music)
1546 PlayMenuMusicExt(music);
1553 /* last screen already faded out, next screen has no animation */
1554 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1555 fading_next.fade_mode == FADE_MODE_NONE)
1556 fading = fading_next;
1558 /* last screen already faded out, next screen has no animation */
1559 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1560 fading_next.fade_mode == FADE_MODE_NONE)
1561 fading = fading_next;
1568 fading = fading_next;
1570 DelayReached(&title_delay, 0); /* reset delay counter */
1574 FadeSoundsAndMusic();
1576 return_to_main_menu = TRUE;
1580 if (return_to_main_menu)
1586 SetMouseCursor(CURSOR_DEFAULT);
1588 if (game_status == GAME_MODE_INFO)
1591 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1594 info_mode = INFO_MODE_MAIN;
1595 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1597 else /* default: return to main menu */
1600 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1603 game_status = GAME_MODE_MAIN;
1604 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1609 void HandleMainMenu_SelectLevel(int step, int direction)
1611 int old_level_nr = level_nr;
1614 new_level_nr = old_level_nr + step * direction;
1615 if (new_level_nr < leveldir_current->first_level)
1616 new_level_nr = leveldir_current->first_level;
1617 if (new_level_nr > leveldir_current->last_level)
1618 new_level_nr = leveldir_current->last_level;
1620 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1622 /* skipping levels is only allowed when trying to skip single level */
1623 if (setup.skip_levels && step == 1 &&
1624 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1626 leveldir_current->handicap_level++;
1627 SaveLevelSetup_SeriesInfo();
1630 new_level_nr = leveldir_current->handicap_level;
1633 if (new_level_nr != old_level_nr)
1635 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1637 PlaySound(SND_MENU_ITEM_SELECTING);
1639 level_nr = new_level_nr;
1641 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1642 int2str(level_nr, menu.main.text.level_number.size),
1643 mci->pos_text->font);
1645 LoadLevel(level_nr);
1646 DrawPreviewLevel(TRUE);
1650 DrawCompleteVideoDisplay();
1652 /* needed because DrawPreviewLevel() takes some time */
1658 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1660 static int choice = MAIN_CONTROL_GAME;
1664 if (button == MB_MENU_INITIALIZE)
1666 DrawCursorAndText_Main(choice, TRUE);
1671 if (mx || my) /* mouse input */
1675 for (i = 0; main_controls[i].nr != -1; i++)
1677 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1678 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1679 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1681 pos = main_controls[i].nr;
1687 else if (dx || dy) /* keyboard input */
1689 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1690 choice == MAIN_CONTROL_SETUP))
1691 button = MB_MENU_CHOICE;
1696 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1698 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1700 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1706 PlaySound(SND_MENU_ITEM_ACTIVATING);
1708 DrawCursorAndText_Main(choice, FALSE);
1709 DrawCursorAndText_Main(pos, TRUE);
1716 PlaySound(SND_MENU_ITEM_SELECTING);
1718 if (pos == MAIN_CONTROL_NAME)
1720 game_status = GAME_MODE_PSEUDO_TYPENAME;
1722 HandleTypeName(strlen(setup.player_name), 0);
1724 else if (pos == MAIN_CONTROL_LEVELS)
1728 game_status = GAME_MODE_LEVELS;
1730 SaveLevelSetup_LastSeries();
1731 SaveLevelSetup_SeriesInfo();
1740 else if (pos == MAIN_CONTROL_SCORES)
1742 game_status = GAME_MODE_SCORES;
1746 else if (pos == MAIN_CONTROL_EDITOR)
1748 if (leveldir_current->readonly &&
1749 !strEqual(setup.player_name, "Artsoft"))
1750 Request("This level is read only !", REQ_CONFIRM);
1752 game_status = GAME_MODE_EDITOR;
1754 FadeSetEnterScreen();
1758 else if (pos == MAIN_CONTROL_INFO)
1760 game_status = GAME_MODE_INFO;
1761 info_mode = INFO_MODE_MAIN;
1765 else if (pos == MAIN_CONTROL_GAME)
1767 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1769 else if (pos == MAIN_CONTROL_SETUP)
1771 game_status = GAME_MODE_SETUP;
1772 setup_mode = SETUP_MODE_MAIN;
1776 else if (pos == MAIN_CONTROL_QUIT)
1778 SaveLevelSetup_LastSeries();
1779 SaveLevelSetup_SeriesInfo();
1781 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1782 game_status = GAME_MODE_QUIT;
1787 if (game_status == GAME_MODE_MAIN)
1789 DrawPreviewLevel(FALSE);
1795 /* ========================================================================= */
1796 /* info screen functions */
1797 /* ========================================================================= */
1799 static struct TokenInfo *info_info;
1800 static int num_info_info;
1802 static void execInfoTitleScreen()
1804 info_mode = INFO_MODE_TITLE;
1809 static void execInfoElements()
1811 info_mode = INFO_MODE_ELEMENTS;
1816 static void execInfoMusic()
1818 info_mode = INFO_MODE_MUSIC;
1823 static void execInfoCredits()
1825 info_mode = INFO_MODE_CREDITS;
1830 static void execInfoProgram()
1832 info_mode = INFO_MODE_PROGRAM;
1837 static void execInfoVersion()
1839 info_mode = INFO_MODE_VERSION;
1844 static void execInfoLevelSet()
1846 info_mode = INFO_MODE_LEVELSET;
1851 static void execExitInfo()
1853 game_status = GAME_MODE_MAIN;
1855 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1858 static struct TokenInfo info_info_main[] =
1860 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1861 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1862 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1863 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1864 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1865 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1866 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1867 { TYPE_EMPTY, NULL, "" },
1868 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1873 static void DrawCursorAndText_Info(int pos, boolean active)
1875 int xpos = MENU_SCREEN_START_XPOS;
1876 int ypos = MENU_SCREEN_START_YPOS + pos;
1877 int font_nr = FONT_MENU_1;
1880 font_nr = FONT_ACTIVE(font_nr);
1882 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1884 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1885 drawCursor(pos, active);
1888 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1893 CloseDoor(DOOR_CLOSE_2);
1895 /* (needed after displaying title screens which disable auto repeat) */
1896 KeyboardAutoRepeatOn();
1898 FadeSetLeaveScreen();
1905 if (fade_mask == REDRAW_ALL)
1909 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1915 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1917 info_info = info_info_main;
1921 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1923 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1926 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1927 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1928 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1929 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1930 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1931 initCursor(i, IMG_MENU_BUTTON);
1933 DrawCursorAndText_Info(i, FALSE);
1938 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1943 DrawMaskedBorder(fade_mask);
1950 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1952 static int choice_store[MAX_INFO_MODES];
1953 int choice = choice_store[info_mode]; /* always starts with 0 */
1957 if (button == MB_MENU_INITIALIZE)
1959 /* advance to first valid menu entry */
1960 while (choice < num_info_info &&
1961 info_info[choice].type & TYPE_SKIP_ENTRY)
1963 choice_store[info_mode] = choice;
1965 DrawCursorAndText_Info(choice, TRUE);
1969 else if (button == MB_MENU_LEAVE)
1971 for (y = 0; y < num_info_info; y++)
1973 if (info_info[y].type & TYPE_LEAVE_MENU)
1975 void (*menu_callback_function)(void) = info_info[y].value;
1979 menu_callback_function();
1981 break; /* absolutely needed because function changes 'info_info'! */
1988 if (mx || my) /* mouse input */
1990 x = (mx - mSX) / 32;
1991 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1993 else if (dx || dy) /* keyboard input */
1997 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
1999 if (info_info[choice].type & menu_navigation_type ||
2000 info_info[choice].type & TYPE_ENTER_SCREEN ||
2001 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2002 button = MB_MENU_CHOICE;
2007 /* jump to next non-empty menu entry (up or down) */
2008 while (y > 0 && y < num_info_info - 1 &&
2009 info_info[y].type & TYPE_SKIP_ENTRY)
2013 if (IN_VIS_FIELD(x, y) &&
2014 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2020 PlaySound(SND_MENU_ITEM_ACTIVATING);
2022 DrawCursorAndText_Info(choice, FALSE);
2023 DrawCursorAndText_Info(y, TRUE);
2025 choice = choice_store[info_mode] = y;
2028 else if (!(info_info[y].type & TYPE_GHOSTED))
2030 PlaySound(SND_MENU_ITEM_SELECTING);
2032 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2034 void (*menu_callback_function)(void) = info_info[choice].value;
2036 FadeSetFromType(info_info[y].type);
2038 menu_callback_function();
2044 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2046 int ystart1 = mSY - SY + 100;
2047 int ystart2 = mSY - SY + 150;
2048 int ybottom = mSY - SY + SYSIZE - 20;
2050 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2052 FadeOut(REDRAW_FIELD);
2057 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2058 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2060 DrawTextSCentered(ybottom, FONT_TEXT_4,
2061 "Press any key or button for info menu");
2063 FadeIn(REDRAW_FIELD);
2066 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2068 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2069 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2070 int xstart = mSX + 16;
2071 int ystart1 = mSY - SY + 100;
2072 int ystart2 = mSY + 64 + 2 * 32;
2073 int ybottom = mSY - SY + SYSIZE - 20;
2074 int ystep = TILEY + 4;
2075 int element, action, direction;
2083 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2084 infoscreen_step[i] = infoscreen_frame[i] = 0;
2089 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2091 DrawTextSCentered(ybottom, FONT_TEXT_4,
2092 "Press any key or button for next page");
2098 while (helpanim_info[j].element != HELPANIM_LIST_END)
2100 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2105 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2114 j += infoscreen_step[i - start];
2116 element = helpanim_info[j].element;
2117 action = helpanim_info[j].action;
2118 direction = helpanim_info[j].direction;
2121 element = EL_UNKNOWN;
2123 if (action != -1 && direction != -1)
2124 graphic = el_act_dir2img(element, action, direction);
2125 else if (action != -1)
2126 graphic = el_act2img(element, action);
2127 else if (direction != -1)
2128 graphic = el_dir2img(element, direction);
2130 graphic = el2img(element);
2132 delay = helpanim_info[j++].delay;
2137 if (infoscreen_frame[i - start] == 0)
2140 infoscreen_frame[i - start] = delay - 1;
2144 sync_frame = delay - infoscreen_frame[i - start];
2145 infoscreen_frame[i - start]--;
2148 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2150 if (!infoscreen_frame[i - start])
2151 infoscreen_step[i - start] = 0;
2155 if (!infoscreen_frame[i - start])
2156 infoscreen_step[i - start]++;
2157 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2163 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2165 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2166 graphic, sync_frame, USE_MASKING);
2169 DrawInfoScreen_HelpText(element, action, direction, i - start);
2174 redraw_mask |= REDRAW_FIELD;
2179 static char *getHelpText(int element, int action, int direction)
2181 char token[MAX_LINE_LEN];
2183 strcpy(token, element_info[element].token_name);
2186 strcat(token, element_action_info[action].suffix);
2188 if (direction != -1)
2189 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2191 return getHashEntry(helptext_info, token);
2194 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2196 int font_nr = FONT_INFO_ELEMENTS;
2197 int font_width = getFontWidth(font_nr);
2198 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2199 int sy = mSY + 65 + 2 * 32 + 1;
2200 int ystep = TILEY + 4;
2201 int pad_x = sx - SX;
2202 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2203 int max_lines_per_text = 2;
2206 if (action != -1 && direction != -1) /* element.action.direction */
2207 text = getHelpText(element, action, direction);
2209 if (text == NULL && action != -1) /* element.action */
2210 text = getHelpText(element, action, -1);
2212 if (text == NULL && direction != -1) /* element.direction */
2213 text = getHelpText(element, -1, direction);
2215 if (text == NULL) /* base element */
2216 text = getHelpText(element, -1, -1);
2218 if (text == NULL) /* not found */
2219 text = "No description available";
2221 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2222 sy += getFontHeight(font_nr) / 2;
2224 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2225 max_chars_per_line, -1, max_lines_per_text, -1,
2226 TRUE, FALSE, FALSE);
2229 void DrawInfoScreen_TitleScreen()
2234 void HandleInfoScreen_TitleScreen(int button)
2236 HandleTitleScreen(0, 0, 0, 0, button);
2239 void DrawInfoScreen_Elements()
2241 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2243 FadeOut(REDRAW_FIELD);
2248 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2250 FadeIn(REDRAW_FIELD);
2255 void HandleInfoScreen_Elements(int button)
2257 static unsigned long info_delay = 0;
2258 static int num_anims;
2259 static int num_pages;
2261 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2264 if (button == MB_MENU_INITIALIZE)
2266 boolean new_element = TRUE;
2270 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2272 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2274 else if (new_element)
2277 new_element = FALSE;
2281 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2285 if (button == MB_MENU_LEAVE)
2287 PlaySound(SND_MENU_ITEM_SELECTING);
2289 info_mode = INFO_MODE_MAIN;
2294 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2296 if (button != MB_MENU_INITIALIZE)
2298 PlaySound(SND_MENU_ITEM_SELECTING);
2303 if (page >= num_pages)
2305 FadeSoundsAndMusic();
2307 info_mode = INFO_MODE_MAIN;
2308 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2315 FadeSetNextScreen();
2318 if (button != MB_MENU_INITIALIZE)
2319 FadeOut(REDRAW_FIELD);
2321 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2323 if (button != MB_MENU_INITIALIZE)
2324 FadeIn(REDRAW_FIELD);
2328 if (DelayReached(&info_delay, GameFrameDelay))
2329 if (page < num_pages)
2330 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2332 PlayMenuSoundIfLoop();
2336 void DrawInfoScreen_Music()
2338 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2341 FadeOut(REDRAW_FIELD);
2349 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2352 FadeIn(REDRAW_FIELD);
2356 void HandleInfoScreen_Music(int button)
2358 static struct MusicFileInfo *list = NULL;
2359 int ystart1 = mSY - SY + 100;
2360 int ystart2 = mSY - SY + 150;
2361 int ybottom = mSY - SY + SYSIZE - 20;
2364 if (button == MB_MENU_INITIALIZE)
2366 list = music_file_info;
2370 FadeSoundsAndMusic();
2375 DrawTextSCentered(ystart1, FONT_TEXT_1,
2376 "No music info for this level set.");
2378 DrawTextSCentered(ybottom, FONT_TEXT_4,
2379 "Press any key or button for info menu");
2385 if (button == MB_MENU_LEAVE)
2387 PlaySound(SND_MENU_ITEM_SELECTING);
2389 FadeSoundsAndMusic();
2391 info_mode = INFO_MODE_MAIN;
2396 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2400 if (button != MB_MENU_INITIALIZE)
2402 PlaySound(SND_MENU_ITEM_SELECTING);
2410 FadeSoundsAndMusic();
2412 info_mode = INFO_MODE_MAIN;
2413 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2418 FadeSoundsAndMusic();
2421 if (list != music_file_info)
2422 FadeSetNextScreen();
2425 if (button != MB_MENU_INITIALIZE)
2426 FadeOut(REDRAW_FIELD);
2433 int sound = list->music;
2435 if (sound_info[sound].loop)
2436 PlaySoundLoop(sound);
2440 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2444 PlayMusic(list->music);
2446 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2449 if (!strEqual(list->title, UNKNOWN_NAME))
2451 if (!strEqual(list->title_header, UNKNOWN_NAME))
2452 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2454 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2457 if (!strEqual(list->artist, UNKNOWN_NAME))
2459 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2460 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2462 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2464 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2467 if (!strEqual(list->album, UNKNOWN_NAME))
2469 if (!strEqual(list->album_header, UNKNOWN_NAME))
2470 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2472 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2474 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2477 if (!strEqual(list->year, UNKNOWN_NAME))
2479 if (!strEqual(list->year_header, UNKNOWN_NAME))
2480 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2482 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2484 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2487 DrawTextSCentered(ybottom, FONT_TEXT_4,
2488 "Press any key or button for next page");
2490 if (button != MB_MENU_INITIALIZE)
2491 FadeIn(REDRAW_FIELD);
2494 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2495 PlaySoundLoop(list->music);
2498 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2500 int ystart1 = mSY - SY + 100;
2501 int ystart2 = mSY - SY + 150;
2502 int ybottom = mSY - SY + SYSIZE - 20;
2508 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2512 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2513 "Special thanks to");
2514 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2516 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2518 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2519 "\"Boulder Dash\"");
2520 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2522 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2524 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2526 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2527 "First Star Software");
2529 else if (screen_nr == 1)
2531 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2532 "Special thanks to");
2533 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2534 "Klaus Heinz & Volker Wertich");
2535 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2537 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2538 "\"Emerald Mine\"");
2539 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2541 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2543 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2545 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2548 else if (screen_nr == 2)
2550 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2551 "Special thanks to");
2552 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2553 "Michael Stopp & Philip Jespersen");
2554 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2556 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2558 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2560 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2562 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2564 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2565 "Digital Integration");
2567 else if (screen_nr == 3)
2569 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2570 "Special thanks to");
2571 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2572 "Hiroyuki Imabayashi");
2573 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2575 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2577 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2579 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2581 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2583 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2586 else if (screen_nr == 4)
2588 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2589 "Special thanks to");
2590 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2592 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2594 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2595 "Jürgen Bonhagen");
2596 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2597 "for the continuous creation");
2598 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2599 "of outstanding level sets");
2601 else if (screen_nr == 5)
2603 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2605 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2607 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2608 "for ideas and inspiration by");
2609 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2612 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2614 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2616 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2617 "for ideas and inspiration by");
2618 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2621 else if (screen_nr == 6)
2623 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2625 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2627 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2628 "for the new Emerald Mine engine");
2630 else if (screen_nr == 7)
2632 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2634 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2636 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2637 "for the initial DOS port");
2639 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2641 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2643 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2644 "for some additional toons");
2646 else if (screen_nr == 8)
2648 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2649 "And not to forget:");
2650 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2652 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2653 "All those who contributed");
2654 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2655 "levels to this game");
2656 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2660 DrawTextSCentered(ybottom, FONT_TEXT_4,
2661 "Press any key or button for next page");
2664 void DrawInfoScreen_Credits()
2666 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2668 FadeSoundsAndMusic();
2671 FadeOut(REDRAW_FIELD);
2674 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2677 FadeIn(REDRAW_FIELD);
2681 void HandleInfoScreen_Credits(int button)
2683 static int screen_nr = 0;
2684 int num_screens = 9;
2686 if (button == MB_MENU_INITIALIZE)
2690 // DrawInfoScreen_CreditsScreen(screen_nr);
2693 if (button == MB_MENU_LEAVE)
2695 PlaySound(SND_MENU_ITEM_SELECTING);
2697 info_mode = INFO_MODE_MAIN;
2702 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2704 if (button != MB_MENU_INITIALIZE)
2706 PlaySound(SND_MENU_ITEM_SELECTING);
2711 if (screen_nr >= num_screens)
2713 FadeSoundsAndMusic();
2715 info_mode = INFO_MODE_MAIN;
2716 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2723 FadeSetNextScreen();
2726 if (button != MB_MENU_INITIALIZE)
2727 FadeOut(REDRAW_FIELD);
2729 DrawInfoScreen_CreditsScreen(screen_nr);
2731 if (button != MB_MENU_INITIALIZE)
2732 FadeIn(REDRAW_FIELD);
2736 PlayMenuSoundIfLoop();
2740 void DrawInfoScreen_Program()
2742 int ystart1 = mSY - SY + 100;
2743 int ystart2 = mSY - SY + 150;
2744 int ybottom = mSY - SY + SYSIZE - 20;
2747 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2750 FadeOut(REDRAW_FIELD);
2756 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2758 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2759 "This game is Freeware!");
2760 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2761 "If you like it, send e-mail to:");
2762 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2763 PROGRAM_EMAIL_STRING);
2764 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2765 "or SnailMail to:");
2766 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2768 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2769 "Detmolder Strasse 189");
2770 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2772 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2774 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2775 "More information and levels:");
2776 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2777 PROGRAM_WEBSITE_STRING);
2778 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2779 "If you have created new levels,");
2780 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2781 "send them to me to include them!");
2782 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2785 DrawTextSCentered(ybottom, FONT_TEXT_4,
2786 "Press any key or button for info menu");
2789 FadeIn(REDRAW_FIELD);
2793 void HandleInfoScreen_Program(int button)
2795 if (button == MB_MENU_LEAVE)
2797 PlaySound(SND_MENU_ITEM_SELECTING);
2799 info_mode = INFO_MODE_MAIN;
2804 else if (button == MB_MENU_CHOICE)
2806 PlaySound(SND_MENU_ITEM_SELECTING);
2808 FadeSoundsAndMusic();
2811 FadeOut(REDRAW_FIELD);
2814 info_mode = INFO_MODE_MAIN;
2815 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2819 PlayMenuSoundIfLoop();
2823 void DrawInfoScreen_Version()
2825 int font_header = FONT_TEXT_3;
2826 int font_text = FONT_TEXT_2;
2827 int xstep = getFontWidth(font_text);
2828 int ystep = getFontHeight(font_text);
2829 int ystart1 = mSY - SY + 100;
2830 int ystart2 = mSY - SY + 150;
2831 int ybottom = mSY - SY + SYSIZE - 20;
2832 int xstart1 = mSX + 2 * xstep;
2833 int xstart2 = mSX + 19 * xstep;
2834 #if defined(TARGET_SDL)
2835 int xstart3 = mSX + 29 * xstep;
2836 SDL_version sdl_version_compiled;
2837 const SDL_version *sdl_version_linked;
2838 int driver_name_len = 8;
2839 char driver_name[driver_name_len];
2842 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2845 FadeOut(REDRAW_FIELD);
2851 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2853 DrawTextF(xstart1, ystart2, font_header, "Name");
2854 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2857 DrawTextF(xstart1, ystart2, font_header, "Version");
2858 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2861 DrawTextF(xstart1, ystart2, font_header, "Platform");
2862 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2865 DrawTextF(xstart1, ystart2, font_header, "Target");
2866 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2869 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2870 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2872 #if defined(TARGET_SDL)
2873 ystart2 += 3 * ystep;
2874 DrawTextF(xstart1, ystart2, font_header, "Library");
2875 DrawTextF(xstart2, ystart2, font_header, "compiled");
2876 DrawTextF(xstart3, ystart2, font_header, "linked");
2878 SDL_VERSION(&sdl_version_compiled);
2879 sdl_version_linked = SDL_Linked_Version();
2881 ystart2 += 2 * ystep;
2882 DrawTextF(xstart1, ystart2, font_text, "SDL");
2883 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2884 sdl_version_compiled.major,
2885 sdl_version_compiled.minor,
2886 sdl_version_compiled.patch);
2887 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2888 sdl_version_linked->major,
2889 sdl_version_linked->minor,
2890 sdl_version_linked->patch);
2892 SDL_IMAGE_VERSION(&sdl_version_compiled);
2893 sdl_version_linked = IMG_Linked_Version();
2896 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2897 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2898 sdl_version_compiled.major,
2899 sdl_version_compiled.minor,
2900 sdl_version_compiled.patch);
2901 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2902 sdl_version_linked->major,
2903 sdl_version_linked->minor,
2904 sdl_version_linked->patch);
2906 SDL_MIXER_VERSION(&sdl_version_compiled);
2907 sdl_version_linked = Mix_Linked_Version();
2910 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2911 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2912 sdl_version_compiled.major,
2913 sdl_version_compiled.minor,
2914 sdl_version_compiled.patch);
2915 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2916 sdl_version_linked->major,
2917 sdl_version_linked->minor,
2918 sdl_version_linked->patch);
2920 SDL_NET_VERSION(&sdl_version_compiled);
2921 sdl_version_linked = SDLNet_Linked_Version();
2924 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2925 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2926 sdl_version_compiled.major,
2927 sdl_version_compiled.minor,
2928 sdl_version_compiled.patch);
2929 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2930 sdl_version_linked->major,
2931 sdl_version_linked->minor,
2932 sdl_version_linked->patch);
2934 ystart2 += 3 * ystep;
2935 DrawTextF(xstart1, ystart2, font_header, "Driver");
2936 DrawTextF(xstart2, ystart2, font_header, "Requested");
2937 DrawTextF(xstart3, ystart2, font_header, "Used");
2939 SDL_VideoDriverName(driver_name, driver_name_len);
2941 ystart2 += 2 * ystep;
2942 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2943 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2944 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2946 SDL_AudioDriverName(driver_name, driver_name_len);
2949 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2950 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2951 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2954 DrawTextSCentered(ybottom, FONT_TEXT_4,
2955 "Press any key or button for info menu");
2958 FadeIn(REDRAW_FIELD);
2962 void HandleInfoScreen_Version(int button)
2964 if (button == MB_MENU_LEAVE)
2966 PlaySound(SND_MENU_ITEM_SELECTING);
2968 info_mode = INFO_MODE_MAIN;
2973 else if (button == MB_MENU_CHOICE)
2975 PlaySound(SND_MENU_ITEM_SELECTING);
2977 FadeSoundsAndMusic();
2980 FadeOut(REDRAW_FIELD);
2983 info_mode = INFO_MODE_MAIN;
2984 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2988 PlayMenuSoundIfLoop();
2992 void DrawInfoScreen_LevelSet()
2994 struct TitleMessageInfo *tmi = &readme;
2995 char *filename = getLevelSetInfoFilename();
2997 /* if chars set to "-1", automatically determine by text and font width */
2998 if (tmi->chars == -1)
2999 tmi->chars = tmi->width / getFontWidth(tmi->font);
3001 tmi->width = tmi->chars * getFontWidth(tmi->font);
3003 /* if lines set to "-1", automatically determine by text and font height */
3004 if (tmi->lines == -1)
3005 tmi->lines = tmi->height / getFontHeight(tmi->font);
3007 tmi->height = tmi->lines * getFontHeight(tmi->font);
3009 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3012 FadeOut(REDRAW_FIELD);
3018 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3020 if (filename != NULL)
3021 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3022 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3023 tmi->autowrap, tmi->centered, tmi->parse_comments);
3025 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3026 "No information for this level set.");
3028 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3029 "Press any key or button for info menu");
3032 FadeIn(REDRAW_FIELD);
3036 void HandleInfoScreen_LevelSet(int button)
3038 if (button == MB_MENU_LEAVE)
3040 PlaySound(SND_MENU_ITEM_SELECTING);
3042 info_mode = INFO_MODE_MAIN;
3047 else if (button == MB_MENU_CHOICE)
3049 PlaySound(SND_MENU_ITEM_SELECTING);
3051 FadeSoundsAndMusic();
3054 FadeOut(REDRAW_FIELD);
3057 info_mode = INFO_MODE_MAIN;
3058 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3062 PlayMenuSoundIfLoop();
3066 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3068 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3070 if (info_mode == INFO_MODE_TITLE)
3071 DrawInfoScreen_TitleScreen();
3072 else if (info_mode == INFO_MODE_ELEMENTS)
3073 DrawInfoScreen_Elements();
3074 else if (info_mode == INFO_MODE_MUSIC)
3075 DrawInfoScreen_Music();
3076 else if (info_mode == INFO_MODE_CREDITS)
3077 DrawInfoScreen_Credits();
3078 else if (info_mode == INFO_MODE_PROGRAM)
3079 DrawInfoScreen_Program();
3080 else if (info_mode == INFO_MODE_VERSION)
3081 DrawInfoScreen_Version();
3082 else if (info_mode == INFO_MODE_LEVELSET)
3083 DrawInfoScreen_LevelSet();
3085 DrawInfoScreen_Main(fade_mask, do_fading);
3087 if (info_mode != INFO_MODE_MAIN &&
3088 info_mode != INFO_MODE_TITLE &&
3089 info_mode != INFO_MODE_MUSIC)
3096 void DrawAndFadeInInfoScreen(int fade_mask)
3098 DrawInfoScreenExt(fade_mask, TRUE);
3101 void DrawInfoScreen()
3103 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3106 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3108 if (info_mode == INFO_MODE_TITLE)
3109 HandleInfoScreen_TitleScreen(button);
3110 else if (info_mode == INFO_MODE_ELEMENTS)
3111 HandleInfoScreen_Elements(button);
3112 else if (info_mode == INFO_MODE_MUSIC)
3113 HandleInfoScreen_Music(button);
3114 else if (info_mode == INFO_MODE_CREDITS)
3115 HandleInfoScreen_Credits(button);
3116 else if (info_mode == INFO_MODE_PROGRAM)
3117 HandleInfoScreen_Program(button);
3118 else if (info_mode == INFO_MODE_VERSION)
3119 HandleInfoScreen_Version(button);
3120 else if (info_mode == INFO_MODE_LEVELSET)
3121 HandleInfoScreen_LevelSet(button);
3123 HandleInfoScreen_Main(mx, my, dx, dy, button);
3129 /* ========================================================================= */
3130 /* type name functions */
3131 /* ========================================================================= */
3133 void HandleTypeName(int newxpos, Key key)
3135 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3136 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3137 struct TextPosInfo *pos = mci->pos_input;
3138 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3139 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3140 static int xpos = 0;
3141 int font_nr = pos->font;
3142 int font_active_nr = FONT_ACTIVE(font_nr);
3143 int font_width = getFontWidth(font_active_nr);
3144 char key_char = getValidConfigValueChar(getCharFromKey(key));
3145 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3146 boolean is_active = TRUE;
3148 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3152 strcpy(last_player_name, setup.player_name);
3156 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3158 setup.player_name[xpos] = key_char;
3159 setup.player_name[xpos + 1] = 0;
3163 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3167 setup.player_name[xpos] = 0;
3169 else if (key == KSYM_Return && xpos > 0)
3175 game_status = GAME_MODE_MAIN;
3177 else if (key == KSYM_Escape)
3179 strcpy(setup.player_name, last_player_name);
3183 game_status = GAME_MODE_MAIN;
3188 pos->width = (strlen(setup.player_name) + 1) * font_width;
3189 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3191 DrawText(startx, starty, setup.player_name, font_active_nr);
3192 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3196 pos->width = strlen(setup.player_name) * font_width;
3197 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3199 DrawText(startx, starty, setup.player_name, font_nr);
3204 /* ========================================================================= */
3205 /* tree menu functions */
3206 /* ========================================================================= */
3208 static void DrawChooseTree(TreeInfo **ti_ptr)
3212 FreeScreenGadgets();
3213 CreateScreenGadgets();
3215 CloseDoor(DOOR_CLOSE_2);
3218 FadeOut(REDRAW_FIELD);
3223 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3224 MapScreenTreeGadgets(*ti_ptr);
3227 FadeIn(REDRAW_FIELD);
3233 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3235 struct GadgetInfo *gi = screen_gadget[id];
3236 int items_max, items_visible, item_position;
3238 items_max = numTreeInfoInGroup(ti);
3239 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3240 item_position = first_entry;
3242 if (item_position > items_max - items_visible)
3243 item_position = items_max - items_visible;
3245 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3246 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3247 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3250 static void drawChooseTreeList(int first_entry, int num_page_entries,
3254 char *title_string = NULL;
3255 int yoffset_sets = MENU_TITLE1_YPOS;
3256 int yoffset_setup = 16;
3257 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3259 int last_game_status = game_status; /* save current game status */
3261 title_string = ti->infotext;
3263 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3266 /* force LEVELS font on artwork setup screen */
3267 game_status = GAME_MODE_LEVELS;
3271 /* clear tree list area, but not title or scrollbar */
3272 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3273 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3274 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3276 /* clear tree list area, but not title or scrollbar */
3277 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3278 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3279 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3282 for (i = 0; i < num_page_entries; i++)
3284 TreeInfo *node, *node_first;
3285 int entry_pos = first_entry + i;
3286 int xpos = MENU_SCREEN_START_XPOS;
3287 int ypos = MENU_SCREEN_START_YPOS + i;
3288 int startx = mSX + xpos * 32;
3289 int starty = mSY + ypos * 32;
3290 int font_nr = FONT_TEXT_1;
3291 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3292 int startx_text = startx + font_xoffset;
3293 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3294 int text_size = startx_scrollbar - startx_text;
3295 int max_buffer_len = text_size / getFontWidth(font_nr);
3296 char buffer[max_buffer_len + 1];
3298 node_first = getTreeInfoFirstGroupEntry(ti);
3299 node = getTreeInfoFromPos(node_first, entry_pos);
3301 strncpy(buffer, node->name, max_buffer_len);
3302 buffer[max_buffer_len] = '\0';
3304 DrawText(startx, starty, buffer, font_nr + node->color);
3306 if (node->parent_link)
3307 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3308 else if (node->level_group)
3309 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3311 initCursor(i, IMG_MENU_BUTTON);
3314 game_status = last_game_status; /* restore current game status */
3316 redraw_mask |= REDRAW_FIELD;
3319 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3321 TreeInfo *node, *node_first;
3322 int x, last_redraw_mask = redraw_mask;
3323 int ypos = MENU_TITLE2_YPOS;
3324 int font_nr = FONT_TITLE_2;
3326 if (ti->type != TREE_TYPE_LEVEL_DIR)
3329 node_first = getTreeInfoFirstGroupEntry(ti);
3330 node = getTreeInfoFromPos(node_first, entry_pos);
3332 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3334 if (node->parent_link)
3335 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3337 else if (node->level_group)
3338 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3340 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3341 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3342 node->levels, node->class_desc);
3344 /* let BackToFront() redraw only what is needed */
3345 redraw_mask = last_redraw_mask | REDRAW_TILES;
3346 for (x = 0; x < SCR_FIELDX; x++)
3347 MarkTileDirty(x, 1);
3350 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3353 TreeInfo *ti = *ti_ptr;
3355 int y = ti->cl_cursor;
3356 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3357 int num_entries = numTreeInfoInGroup(ti);
3358 int num_page_entries;
3359 int last_game_status = game_status; /* save current game status */
3360 boolean position_set_by_scrollbar = (dx == 999);
3363 /* force LEVELS draw offset on choose level and artwork setup screen */
3364 game_status = GAME_MODE_LEVELS;
3367 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3368 num_page_entries = num_entries;
3370 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3372 game_status = last_game_status; /* restore current game status */
3374 if (button == MB_MENU_INITIALIZE)
3376 int num_entries = numTreeInfoInGroup(ti);
3377 int entry_pos = posTreeInfo(ti);
3379 if (ti->cl_first == -1)
3381 /* only on initialization */
3382 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3383 ti->cl_cursor = entry_pos - ti->cl_first;
3385 else if (ti->cl_cursor >= num_page_entries ||
3386 (num_entries > num_page_entries &&
3387 num_entries - ti->cl_first < num_page_entries))
3389 /* only after change of list size (by custom graphic configuration) */
3390 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3391 ti->cl_cursor = entry_pos - ti->cl_first;
3394 if (position_set_by_scrollbar)
3397 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3400 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3401 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3402 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3406 else if (button == MB_MENU_LEAVE)
3410 PlaySound(SND_MENU_ITEM_SELECTING);
3412 if (ti->node_parent)
3414 *ti_ptr = ti->node_parent;
3415 DrawChooseTree(ti_ptr);
3417 else if (game_status == GAME_MODE_SETUP)
3419 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3421 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3422 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3423 execSetupGraphics();
3429 game_status = GAME_MODE_MAIN;
3431 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3437 if (mx || my) /* mouse input */
3439 int last_game_status = game_status; /* save current game status */
3442 /* force LEVELS draw offset on artwork setup screen */
3443 game_status = GAME_MODE_LEVELS;
3446 x = (mx - mSX) / 32;
3447 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3449 game_status = last_game_status; /* restore current game status */
3451 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3453 /* move cursor instead of scrolling when already at start/end of list */
3454 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3456 else if (dy == +1 * SCROLL_LINE &&
3457 ti->cl_first + num_page_entries == num_entries)
3460 /* handle scrolling screen one line or page */
3461 if (ti->cl_cursor + dy < 0 ||
3462 ti->cl_cursor + dy > num_page_entries - 1)
3464 if (ABS(dy) == SCROLL_PAGE)
3465 step = num_page_entries - 1;
3467 if (dy < 0 && ti->cl_first > 0)
3469 /* scroll page/line up */
3471 ti->cl_first -= step;
3472 if (ti->cl_first < 0)
3475 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3476 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3477 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3479 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3482 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3484 /* scroll page/line down */
3486 ti->cl_first += step;
3487 if (ti->cl_first + num_page_entries > num_entries)
3488 ti->cl_first = MAX(0, num_entries - num_page_entries);
3490 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3491 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3492 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3494 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3501 /* handle moving cursor one line */
3502 y = ti->cl_cursor + dy;
3507 TreeInfo *node_first, *node_cursor;
3508 int entry_pos = ti->cl_first + y;
3510 node_first = getTreeInfoFirstGroupEntry(ti);
3511 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3513 if (node_cursor->node_group)
3517 PlaySound(SND_MENU_ITEM_SELECTING);
3519 node_cursor->cl_first = ti->cl_first;
3520 node_cursor->cl_cursor = ti->cl_cursor;
3521 *ti_ptr = node_cursor->node_group;
3522 DrawChooseTree(ti_ptr);
3527 else if (dx == -1 && ti->node_parent)
3531 PlaySound(SND_MENU_ITEM_SELECTING);
3533 *ti_ptr = ti->node_parent;
3534 DrawChooseTree(ti_ptr);
3539 if (!anyScrollbarGadgetActive() &&
3540 IN_VIS_FIELD(x, y) &&
3541 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3542 y >= 0 && y < num_page_entries)
3546 if (y != ti->cl_cursor)
3548 PlaySound(SND_MENU_ITEM_ACTIVATING);
3550 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3551 drawChooseTreeCursor(y, TRUE);
3552 drawChooseTreeInfo(ti->cl_first + y, ti);
3559 TreeInfo *node_first, *node_cursor;
3560 int entry_pos = ti->cl_first + y;
3562 PlaySound(SND_MENU_ITEM_SELECTING);
3564 node_first = getTreeInfoFirstGroupEntry(ti);
3565 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3567 if (node_cursor->node_group)
3571 node_cursor->cl_first = ti->cl_first;
3572 node_cursor->cl_cursor = ti->cl_cursor;
3573 *ti_ptr = node_cursor->node_group;
3574 DrawChooseTree(ti_ptr);
3576 else if (node_cursor->parent_link)
3580 *ti_ptr = node_cursor->node_parent;
3581 DrawChooseTree(ti_ptr);
3585 FadeSetEnterScreen();
3587 node_cursor->cl_first = ti->cl_first;
3588 node_cursor->cl_cursor = ti->cl_cursor;
3589 *ti_ptr = node_cursor;
3591 if (ti->type == TREE_TYPE_LEVEL_DIR)
3593 LoadLevelSetup_SeriesInfo();
3595 SaveLevelSetup_LastSeries();
3596 SaveLevelSetup_SeriesInfo();
3600 if (game_status == GAME_MODE_SETUP)
3602 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3604 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3605 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3606 execSetupGraphics();
3612 game_status = GAME_MODE_MAIN;
3620 void DrawChooseLevel()
3622 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3624 DrawChooseTree(&leveldir_current);
3630 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3632 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3637 void DrawHallOfFame(int highlight_position)
3640 FadeSoundsAndMusic();
3642 /* (this is needed when called from GameEnd() after winning a game) */
3643 KeyboardAutoRepeatOn();
3646 /* (this is needed when called from GameEnd() after winning a game) */
3647 SetDrawDeactivationMask(REDRAW_NONE);
3648 SetDrawBackgroundMask(REDRAW_FIELD);
3650 CloseDoor(DOOR_CLOSE_2);
3652 if (highlight_position < 0)
3653 LoadScore(level_nr);
3655 FadeSetEnterScreen();
3657 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3660 FadeOut(REDRAW_FIELD);
3668 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3671 FadeIn(REDRAW_FIELD);
3675 static void drawHallOfFameList(int first_entry, int highlight_position)
3679 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3682 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3683 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3684 "HighScores of Level %d", level_nr);
3686 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3688 int entry = first_entry + i;
3689 boolean active = (entry == highlight_position);
3690 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3691 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3692 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3693 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3694 int dx1 = 3 * getFontWidth(font_nr1);
3695 int dx2 = dx1 + getFontWidth(font_nr1);
3696 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3697 int sy = mSY + 64 + i * 32;
3699 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3700 DrawText(mSX + dx1, sy, ".", font_nr1);
3701 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3703 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3704 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3706 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3709 redraw_mask |= REDRAW_FIELD;
3712 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3714 static int first_entry = 0;
3715 static int highlight_position = 0;
3716 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3718 if (button == MB_MENU_INITIALIZE)
3721 highlight_position = mx;
3722 drawHallOfFameList(first_entry, highlight_position);
3727 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3728 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3732 if (first_entry > 0)
3734 first_entry -= step;
3735 if (first_entry < 0)
3738 drawHallOfFameList(first_entry, highlight_position);
3743 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3745 first_entry += step;
3746 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3747 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3749 drawHallOfFameList(first_entry, highlight_position);
3752 else if (button == MB_MENU_LEAVE)
3754 PlaySound(SND_MENU_ITEM_SELECTING);
3756 FadeSound(SND_BACKGROUND_SCORES);
3758 game_status = GAME_MODE_MAIN;
3762 else if (button == MB_MENU_CHOICE)
3764 PlaySound(SND_MENU_ITEM_SELECTING);
3766 FadeSound(SND_BACKGROUND_SCORES);
3769 FadeOut(REDRAW_FIELD);
3772 game_status = GAME_MODE_MAIN;
3774 DrawAndFadeInMainMenu(REDRAW_FIELD);
3777 if (game_status == GAME_MODE_SCORES)
3778 PlayMenuSoundIfLoop();
3784 /* ========================================================================= */
3785 /* setup screen functions */
3786 /* ========================================================================= */
3788 static struct TokenInfo *setup_info;
3789 static int num_setup_info;
3791 static char *screen_mode_text;
3792 static char *scroll_delay_text;
3793 static char *game_speed_text;
3794 static char *graphics_set_name;
3795 static char *sounds_set_name;
3796 static char *music_set_name;
3798 static void execSetupMain()
3800 setup_mode = SETUP_MODE_MAIN;
3805 static void execSetupGame()
3807 if (game_speeds == NULL)
3811 for (i = 0; game_speeds_list[i].value != -1; i++)
3813 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3814 char identifier[32], name[32];
3815 int value = game_speeds_list[i].value;
3816 char *text = game_speeds_list[i].text;
3818 ti->node_top = &game_speeds;
3819 ti->sort_priority = 10000 - value;
3821 sprintf(identifier, "%d", value);
3822 sprintf(name, "%s", text);
3824 setString(&ti->identifier, identifier);
3825 setString(&ti->name, name);
3826 setString(&ti->name_sorting, name);
3827 setString(&ti->infotext, "Game Speed");
3829 pushTreeInfo(&game_speeds, ti);
3832 /* sort game speed values to start with slowest game speed */
3833 sortTreeInfo(&game_speeds);
3835 /* set current game speed to configured game speed value */
3836 game_speed_current =
3837 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3839 /* if that fails, set current game speed to reliable default value */
3840 if (game_speed_current == NULL)
3841 game_speed_current =
3842 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3844 /* if that also fails, set current game speed to first available speed */
3845 if (game_speed_current == NULL)
3846 game_speed_current = game_speeds;
3849 setup.game_frame_delay = atoi(game_speed_current->identifier);
3851 /* needed for displaying game speed text instead of identifier */
3852 game_speed_text = game_speed_current->name;
3854 setup_mode = SETUP_MODE_GAME;
3859 static void execSetupChooseGameSpeed()
3861 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3866 static void execSetupEditor()
3868 setup_mode = SETUP_MODE_EDITOR;
3873 static void execSetupGraphics()
3875 if (video.fullscreen_available && screen_modes == NULL)
3879 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3881 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3882 char identifier[32], name[32];
3883 int x = video.fullscreen_modes[i].width;
3884 int y = video.fullscreen_modes[i].height;
3887 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3889 ti->node_top = &screen_modes;
3890 ti->sort_priority = x * 10000 + y;
3892 sprintf(identifier, "%dx%d", x, y);
3893 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3895 setString(&ti->identifier, identifier);
3896 setString(&ti->name, name);
3897 setString(&ti->name_sorting, name);
3898 setString(&ti->infotext, "Fullscreen Mode");
3900 pushTreeInfo(&screen_modes, ti);
3903 /* sort fullscreen modes to start with lowest available screen resolution */
3904 sortTreeInfo(&screen_modes);
3906 /* set current screen mode for fullscreen mode to configured setup value */
3907 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3908 setup.fullscreen_mode);
3910 /* if that fails, set current screen mode to reliable default value */
3911 if (screen_mode_current == NULL)
3912 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3913 DEFAULT_FULLSCREEN_MODE);
3915 /* if that also fails, set current screen mode to first available mode */
3916 if (screen_mode_current == NULL)
3917 screen_mode_current = screen_modes;
3919 if (screen_mode_current == NULL)
3920 video.fullscreen_available = FALSE;
3923 if (video.fullscreen_available)
3925 setup.fullscreen_mode = screen_mode_current->identifier;
3927 /* needed for displaying screen mode name instead of identifier */
3928 screen_mode_text = screen_mode_current->name;
3932 if (scroll_delays == NULL)
3936 for (i = 0; scroll_delays_list[i].value != -1; i++)
3938 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3939 char identifier[32], name[32];
3940 int value = scroll_delays_list[i].value;
3941 char *text = scroll_delays_list[i].text;
3943 ti->node_top = &scroll_delays;
3944 ti->sort_priority = value;
3946 sprintf(identifier, "%d", value);
3947 sprintf(name, "%s", text);
3949 setString(&ti->identifier, identifier);
3950 setString(&ti->name, name);
3951 setString(&ti->name_sorting, name);
3952 setString(&ti->infotext, "Scroll Delay");
3954 pushTreeInfo(&scroll_delays, ti);
3957 /* sort scroll delay values to start with lowest scroll delay value */
3958 sortTreeInfo(&scroll_delays);
3960 /* set current scroll delay value to configured scroll delay value */
3961 scroll_delay_current =
3962 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
3964 /* if that fails, set current scroll delay to reliable default value */
3965 if (scroll_delay_current == NULL)
3966 scroll_delay_current =
3967 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
3969 /* if that also fails, set current scroll delay to first available value */
3970 if (scroll_delay_current == NULL)
3971 scroll_delay_current = scroll_delays;
3974 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
3976 /* needed for displaying scroll delay text instead of identifier */
3977 scroll_delay_text = scroll_delay_current->name;
3980 setup_mode = SETUP_MODE_GRAPHICS;
3984 static void execSetupChooseScreenMode()
3986 if (!video.fullscreen_available)
3989 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
3994 static void execSetupChooseScrollDelay()
3996 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4001 static void execSetupSound()
4003 setup_mode = SETUP_MODE_SOUND;
4008 static void execSetupArtwork()
4010 setup.graphics_set = artwork.gfx_current->identifier;
4011 setup.sounds_set = artwork.snd_current->identifier;
4012 setup.music_set = artwork.mus_current->identifier;
4014 /* needed if last screen (setup choice) changed graphics, sounds or music */
4015 ReloadCustomArtwork(0);
4017 /* needed for displaying artwork name instead of artwork identifier */
4018 graphics_set_name = artwork.gfx_current->name;
4019 sounds_set_name = artwork.snd_current->name;
4020 music_set_name = artwork.mus_current->name;
4022 setup_mode = SETUP_MODE_ARTWORK;
4027 static void execSetupChooseGraphics()
4029 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4034 static void execSetupChooseSounds()
4036 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4041 static void execSetupChooseMusic()
4043 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4048 static void execSetupInput()
4050 setup_mode = SETUP_MODE_INPUT;
4055 static void execSetupShortcuts1()
4057 setup_mode = SETUP_MODE_SHORTCUTS_1;
4062 static void execSetupShortcuts2()
4064 setup_mode = SETUP_MODE_SHORTCUTS_2;
4069 static void execExitSetup()
4071 game_status = GAME_MODE_MAIN;
4073 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4076 static void execSaveAndExitSetup()
4082 static struct TokenInfo setup_info_main[] =
4084 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4085 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4086 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4087 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4088 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4089 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4090 { TYPE_ENTER_MENU, execSetupShortcuts1, "Key Shortcuts 1" },
4091 { TYPE_ENTER_MENU, execSetupShortcuts2, "Key Shortcuts 2" },
4092 { TYPE_EMPTY, NULL, "" },
4093 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4094 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4099 static struct TokenInfo setup_info_game[] =
4101 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4102 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4103 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4104 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4105 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4106 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4107 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4108 { TYPE_STRING, &game_speed_text, "" },
4109 { TYPE_EMPTY, NULL, "" },
4110 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4115 static struct TokenInfo setup_info_editor[] =
4118 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4119 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4120 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4121 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4122 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4123 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4124 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4125 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4127 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4128 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4129 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4131 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4133 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4134 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4135 { TYPE_EMPTY, NULL, "" },
4137 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4138 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4139 { TYPE_EMPTY, NULL, "" },
4141 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4142 { TYPE_EMPTY, NULL, "" },
4143 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4148 static struct TokenInfo setup_info_graphics[] =
4150 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4151 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4152 { TYPE_STRING, &screen_mode_text, "" },
4154 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4156 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4157 { TYPE_STRING, &scroll_delay_text, "" },
4159 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4161 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4162 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4163 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4164 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4165 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4166 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4167 { TYPE_EMPTY, NULL, "" },
4168 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4173 static struct TokenInfo setup_info_sound[] =
4175 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4176 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4177 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4178 { TYPE_EMPTY, NULL, "" },
4179 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4184 static struct TokenInfo setup_info_artwork[] =
4186 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4187 { TYPE_STRING, &graphics_set_name, "" },
4188 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4189 { TYPE_STRING, &sounds_set_name, "" },
4190 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4191 { TYPE_STRING, &music_set_name, "" },
4192 { TYPE_EMPTY, NULL, "" },
4194 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4195 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4196 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4198 { TYPE_STRING, NULL, "Override Level Artwork:"},
4199 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4200 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4201 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4203 { TYPE_EMPTY, NULL, "" },
4204 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4209 static struct TokenInfo setup_info_input[] =
4211 { TYPE_SWITCH, NULL, "Player:" },
4212 { TYPE_SWITCH, NULL, "Device:" },
4213 { TYPE_ENTER_MENU, NULL, "" },
4214 { TYPE_EMPTY, NULL, "" },
4215 { TYPE_EMPTY, NULL, "" },
4216 { TYPE_EMPTY, NULL, "" },
4217 { TYPE_EMPTY, NULL, "" },
4218 { TYPE_EMPTY, NULL, "" },
4219 { TYPE_EMPTY, NULL, "" },
4220 { TYPE_EMPTY, NULL, "" },
4221 { TYPE_EMPTY, NULL, "" },
4222 { TYPE_EMPTY, NULL, "" },
4223 { TYPE_EMPTY, NULL, "" },
4224 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4229 static struct TokenInfo setup_info_shortcuts_1[] =
4231 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4232 { TYPE_KEY, &setup.shortcut.save_game, "" },
4233 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4234 { TYPE_KEY, &setup.shortcut.load_game, "" },
4235 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4236 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4237 { TYPE_EMPTY, NULL, "" },
4238 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4239 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4240 { TYPE_EMPTY, NULL, "" },
4241 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4246 static struct TokenInfo setup_info_shortcuts_2[] =
4248 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4249 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4250 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4251 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4252 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4253 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4254 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4255 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4256 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4257 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4258 { TYPE_EMPTY, NULL, "" },
4259 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4264 static Key getSetupKey()
4266 Key key = KSYM_UNDEFINED;
4267 boolean got_key_event = FALSE;
4269 while (!got_key_event)
4271 if (PendingEvent()) /* got event */
4279 case EVENT_KEYPRESS:
4281 key = GetEventKey((KeyEvent *)&event, TRUE);
4283 /* press 'Escape' or 'Enter' to keep the existing key binding */
4284 if (key == KSYM_Escape || key == KSYM_Return)
4285 key = KSYM_UNDEFINED; /* keep old value */
4287 got_key_event = TRUE;
4291 case EVENT_KEYRELEASE:
4292 key_joystick_mapping = 0;
4296 HandleOtherEvents(&event);
4304 /* don't eat all CPU time */
4311 static int getSetupTextFont(int type)
4313 if (type & (TYPE_SWITCH |
4324 static int getSetupValueFont(int type, void *value)
4326 if (type & TYPE_KEY)
4327 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4328 else if (type & TYPE_STRING)
4329 return FONT_VALUE_2;
4330 else if (type & TYPE_ECS_AGA)
4331 return FONT_VALUE_1;
4332 else if (type & TYPE_BOOLEAN_STYLE)
4333 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4335 return FONT_VALUE_1;
4338 static void drawSetupValue(int pos)
4340 boolean font_draw_xoffset_modified = FALSE;
4341 int font_draw_xoffset_old = -1;
4342 int xpos = MENU_SCREEN_VALUE_XPOS;
4343 int ypos = MENU_SCREEN_START_YPOS + pos;
4344 int startx = mSX + xpos * 32;
4345 int starty = mSY + ypos * 32;
4346 int font_nr, font_width;
4347 int type = setup_info[pos].type;
4348 void *value = setup_info[pos].value;
4349 char *value_string = getSetupValue(type, value);
4352 if (value_string == NULL)
4355 if (type & TYPE_KEY)
4357 xpos = MENU_SCREEN_START_XPOS;
4359 if (type & TYPE_QUERY)
4361 value_string = "<press key>";
4364 else if (type & TYPE_STRING)
4366 int max_value_len = (SCR_FIELDX - 2) * 2;
4368 xpos = MENU_SCREEN_START_XPOS;
4370 if (strlen(value_string) > max_value_len)
4371 value_string[max_value_len] = '\0';
4374 startx = mSX + xpos * 32;
4375 starty = mSY + ypos * 32;
4376 font_nr = getSetupValueFont(type, value);
4377 font_width = getFontWidth(font_nr);
4379 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4380 if (setup_mode != SETUP_MODE_INPUT)
4382 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4383 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4384 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4385 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4386 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4387 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4388 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4389 boolean correct_font_draw_xoffset = FALSE;
4391 if (xpos == MENU_SCREEN_START_XPOS &&
4392 startx + font1_xoffset < text_startx + text_font_xoffset)
4393 correct_font_draw_xoffset = TRUE;
4395 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4396 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4397 correct_font_draw_xoffset = TRUE;
4399 /* check if setup value would overlap with setup text when printed */
4400 /* (this can happen for extreme/wrong values for font draw offset) */
4401 if (correct_font_draw_xoffset)
4403 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4404 font_draw_xoffset_modified = TRUE;
4406 if (type & TYPE_KEY)
4407 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4408 else if (!(type & TYPE_STRING))
4409 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4410 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4414 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4415 DrawText(startx + i * font_width, starty, " ", font_nr);
4417 DrawText(startx, starty, value_string, font_nr);
4419 if (font_draw_xoffset_modified)
4420 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4423 static void changeSetupValue(int pos)
4425 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4427 *(boolean *)setup_info[pos].value ^= TRUE;
4429 else if (setup_info[pos].type & TYPE_KEY)
4433 setup_info[pos].type |= TYPE_QUERY;
4434 drawSetupValue(pos);
4435 setup_info[pos].type &= ~TYPE_QUERY;
4437 key = getSetupKey();
4438 if (key != KSYM_UNDEFINED)
4439 *(Key *)setup_info[pos].value = key;
4442 drawSetupValue(pos);
4445 static void DrawCursorAndText_Setup(int pos, boolean active)
4447 int xpos = MENU_SCREEN_START_XPOS;
4448 int ypos = MENU_SCREEN_START_YPOS + pos;
4449 int font_nr = getSetupTextFont(setup_info[pos].type);
4451 if (setup_info == setup_info_input)
4452 font_nr = FONT_MENU_1;
4455 font_nr = FONT_ACTIVE(font_nr);
4457 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4459 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4460 drawCursor(pos, active);
4463 static void DrawSetupScreen_Generic()
4465 boolean redraw_all = FALSE;
4466 char *title_string = NULL;
4470 CloseDoor(DOOR_CLOSE_2);
4472 if (redraw_mask & REDRAW_ALL)
4476 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4477 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4478 int2str(0, redraw_mask)));
4482 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4483 FadeOut(redraw_mask);
4485 FadeOut(REDRAW_FIELD);
4490 if (setup_mode == SETUP_MODE_MAIN)
4492 setup_info = setup_info_main;
4493 title_string = "Setup";
4495 else if (setup_mode == SETUP_MODE_GAME)
4497 setup_info = setup_info_game;
4498 title_string = "Setup Game";
4500 else if (setup_mode == SETUP_MODE_EDITOR)
4502 setup_info = setup_info_editor;
4503 title_string = "Setup Editor";
4505 else if (setup_mode == SETUP_MODE_GRAPHICS)
4507 setup_info = setup_info_graphics;
4508 title_string = "Setup Graphics";
4510 else if (setup_mode == SETUP_MODE_SOUND)
4512 setup_info = setup_info_sound;
4513 title_string = "Setup Sound";
4515 else if (setup_mode == SETUP_MODE_ARTWORK)
4517 setup_info = setup_info_artwork;
4518 title_string = "Custom Artwork";
4520 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4522 setup_info = setup_info_shortcuts_1;
4523 title_string = "Setup Shortcuts";
4525 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4527 setup_info = setup_info_shortcuts_2;
4528 title_string = "Setup Shortcuts";
4531 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4535 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4537 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4540 void *value_ptr = setup_info[i].value;
4542 /* set some entries to "unchangeable" according to other variables */
4543 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4544 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4545 (value_ptr == &setup.sound_music && !audio.music_available) ||
4546 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4547 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4548 setup_info[i].type |= TYPE_GHOSTED;
4550 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4551 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4552 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4553 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4554 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4555 initCursor(i, IMG_MENU_BUTTON);
4557 DrawCursorAndText_Setup(i, FALSE);
4559 if (setup_info[i].type & TYPE_VALUE)
4566 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4567 "Joysticks deactivated in setup menu");
4571 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4575 redraw_mask = REDRAW_ALL;
4578 FadeIn(redraw_mask);
4580 FadeIn(REDRAW_FIELD);
4585 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4589 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4591 static int choice_store[MAX_SETUP_MODES];
4592 int choice = choice_store[setup_mode]; /* always starts with 0 */
4596 if (button == MB_MENU_INITIALIZE)
4598 /* advance to first valid menu entry */
4599 while (choice < num_setup_info &&
4600 setup_info[choice].type & TYPE_SKIP_ENTRY)
4602 choice_store[setup_mode] = choice;
4604 DrawCursorAndText_Setup(choice, TRUE);
4608 else if (button == MB_MENU_LEAVE)
4610 PlaySound(SND_MENU_ITEM_SELECTING);
4612 for (y = 0; y < num_setup_info; y++)
4614 if (setup_info[y].type & TYPE_LEAVE_MENU)
4616 void (*menu_callback_function)(void) = setup_info[y].value;
4620 menu_callback_function();
4622 break; /* absolutely needed because function changes 'setup_info'! */
4629 if (mx || my) /* mouse input */
4631 x = (mx - mSX) / 32;
4632 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4634 else if (dx || dy) /* keyboard input */
4638 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4640 if (setup_info[choice].type & menu_navigation_type ||
4641 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
4642 button = MB_MENU_CHOICE;
4647 /* jump to next non-empty menu entry (up or down) */
4648 while (y > 0 && y < num_setup_info - 1 &&
4649 setup_info[y].type & TYPE_SKIP_ENTRY)
4653 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4657 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4659 PlaySound(SND_MENU_ITEM_ACTIVATING);
4661 DrawCursorAndText_Setup(choice, FALSE);
4662 DrawCursorAndText_Setup(y, TRUE);
4664 choice = choice_store[setup_mode] = y;
4667 else if (!(setup_info[y].type & TYPE_GHOSTED))
4669 PlaySound(SND_MENU_ITEM_SELECTING);
4671 /* when selecting key headline, execute function for key value change */
4672 if (setup_info[y].type & TYPE_KEYTEXT &&
4673 setup_info[y + 1].type & TYPE_KEY)
4676 /* when selecting string value, execute function for list selection */
4677 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4678 setup_info[y - 1].type & TYPE_ENTER_LIST)
4681 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4683 void (*menu_callback_function)(void) = setup_info[y].value;
4685 FadeSetFromType(setup_info[y].type);
4687 menu_callback_function();
4691 if (setup_info[y].type & TYPE_VALUE)
4692 changeSetupValue(y);
4698 void DrawSetupScreen_Input()
4703 FadeOut(REDRAW_FIELD);
4709 setup_info = setup_info_input;
4712 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4716 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4717 "Joysticks deactivated on this screen");
4719 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4720 "Joysticks deactivated on this screen");
4725 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4727 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4730 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4731 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4732 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4733 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4734 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4735 initCursor(i, IMG_MENU_BUTTON);
4737 DrawCursorAndText_Setup(i, FALSE);
4741 DeactivateJoystickForCalibration();
4746 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4747 "Joysticks deactivated on this screen");
4749 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4750 "Joysticks deactivated on this screen");
4754 /* create gadgets for setup input menu screen */
4755 FreeScreenGadgets();
4756 CreateScreenGadgets();
4758 /* map gadgets for setup input menu screen */
4759 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4761 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4764 FadeIn(REDRAW_FIELD);
4770 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4772 if (device_name == NULL)
4775 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4778 if (strlen(device_name) > 1)
4780 char c1 = device_name[strlen(device_name) - 1];
4781 char c2 = device_name[strlen(device_name) - 2];
4783 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4784 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4787 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4788 strlen(device_name));
4791 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4794 static struct SetupKeyboardInfo custom_key;
4801 { &custom_key.left, "Joystick Left" },
4802 { &custom_key.right, "Joystick Right" },
4803 { &custom_key.up, "Joystick Up" },
4804 { &custom_key.down, "Joystick Down" },
4805 { &custom_key.snap, "Button 1" },
4806 { &custom_key.drop, "Button 2" }
4808 static char *joystick_name[MAX_PLAYERS] =
4815 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4819 custom_key = setup.input[player_nr].key;
4821 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4822 FONT_INPUT_1_ACTIVE);
4824 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4826 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4827 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4829 if (setup.input[player_nr].use_joystick)
4831 char *device_name = setup.input[player_nr].joy.device_name;
4832 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4833 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4835 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4836 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4840 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4841 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4844 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4846 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4847 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4848 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4849 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4851 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4852 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4853 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4854 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4855 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4856 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4858 for (i = 0; i < 6; i++)
4860 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4862 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4864 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4865 (setup.input[player_nr].use_joystick ?
4867 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4871 static int input_player_nr = 0;
4873 void HandleSetupScreen_Input_Player(int step, int direction)
4875 int old_player_nr = input_player_nr;
4878 new_player_nr = old_player_nr + step * direction;
4879 if (new_player_nr < 0)
4881 if (new_player_nr > MAX_PLAYERS - 1)
4882 new_player_nr = MAX_PLAYERS - 1;
4884 if (new_player_nr != old_player_nr)
4886 input_player_nr = new_player_nr;
4888 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4892 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
4894 static int choice = 0;
4897 int pos_start = SETUPINPUT_SCREEN_POS_START;
4898 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
4899 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
4900 int pos_end = SETUPINPUT_SCREEN_POS_END;
4902 if (button == MB_MENU_INITIALIZE)
4904 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
4906 DrawCursorAndText_Setup(choice, TRUE);
4910 else if (button == MB_MENU_LEAVE)
4912 setup_mode = SETUP_MODE_MAIN;
4919 if (mx || my) /* mouse input */
4921 x = (mx - mSX) / 32;
4922 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4924 else if (dx || dy) /* keyboard input */
4926 if (dx && choice == 0)
4927 x = (dx < 0 ? 10 : 12);
4928 else if ((dx && choice == 1) ||
4929 (dx == +1 && choice == 2) ||
4930 (dx == -1 && choice == pos_end))
4931 button = MB_MENU_CHOICE;
4935 if (y >= pos_empty1 && y <= pos_empty2)
4936 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
4939 if (y == 0 && dx != 0 && button)
4941 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
4943 else if (IN_VIS_FIELD(x, y) &&
4944 y >= pos_start && y <= pos_end &&
4945 !(y >= pos_empty1 && y <= pos_empty2))
4951 DrawCursorAndText_Setup(choice, FALSE);
4952 DrawCursorAndText_Setup(y, TRUE);
4954 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
4963 char *device_name = setup.input[input_player_nr].joy.device_name;
4965 if (!setup.input[input_player_nr].use_joystick)
4967 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
4969 setJoystickDeviceToNr(device_name, new_device_nr);
4970 setup.input[input_player_nr].use_joystick = TRUE;
4974 int device_nr = getJoystickNrFromDeviceName(device_name);
4975 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
4977 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
4978 setup.input[input_player_nr].use_joystick = FALSE;
4980 setJoystickDeviceToNr(device_name, new_device_nr);
4983 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4987 if (setup.input[input_player_nr].use_joystick)
4990 CalibrateJoystick(input_player_nr);
4993 CustomizeKeyboard(input_player_nr);
4995 else if (y == pos_end)
5001 setup_mode = SETUP_MODE_MAIN;
5008 void CustomizeKeyboard(int player_nr)
5012 boolean finished = FALSE;
5013 static struct SetupKeyboardInfo custom_key;
5018 } customize_step[] =
5020 { &custom_key.left, "Move Left" },
5021 { &custom_key.right, "Move Right" },
5022 { &custom_key.up, "Move Up" },
5023 { &custom_key.down, "Move Down" },
5024 { &custom_key.snap, "Snap Field" },
5025 { &custom_key.drop, "Drop Element" }
5028 /* read existing key bindings from player setup */
5029 custom_key = setup.input[player_nr].key;
5032 FadeOut(REDRAW_FIELD);
5036 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5044 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5045 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5046 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5047 "Key:", FONT_INPUT_1_ACTIVE);
5048 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5049 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5052 FadeIn(REDRAW_FIELD);
5059 if (PendingEvent()) /* got event */
5067 case EVENT_KEYPRESS:
5069 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5071 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5073 if (key == KSYM_Escape)
5074 FadeSkipNextFadeIn();
5080 /* all keys configured -- wait for "Escape" or "Return" key */
5084 /* press 'Enter' to keep the existing key binding */
5085 if (key == KSYM_Return)
5086 key = *customize_step[step_nr].key;
5088 /* check if key already used */
5089 for (i = 0; i < step_nr; i++)
5090 if (*customize_step[i].key == key)
5095 /* got new key binding */
5096 *customize_step[step_nr].key = key;
5097 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5099 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5100 getKeyNameFromKey(key), FONT_VALUE_1);
5103 /* un-highlight last query */
5104 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5105 customize_step[step_nr - 1].text, FONT_MENU_1);
5106 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5107 "Key:", FONT_MENU_1);
5109 /* press 'Enter' to leave */
5112 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5113 "Press Enter", FONT_TITLE_1);
5117 /* query next key binding */
5118 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5119 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5120 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5121 "Key:", FONT_INPUT_1_ACTIVE);
5122 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5123 getKeyNameFromKey(*customize_step[step_nr].key),
5128 case EVENT_KEYRELEASE:
5129 key_joystick_mapping = 0;
5133 HandleOtherEvents(&event);
5141 /* don't eat all CPU time */
5145 /* write new key bindings back to player setup */
5146 setup.input[player_nr].key = custom_key;
5149 DrawSetupScreen_Input();
5152 static boolean CalibrateJoystickMain(int player_nr)
5154 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5155 int new_joystick_xright = JOYSTICK_XMIDDLE;
5156 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5157 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5158 int new_joystick_xmiddle, new_joystick_ymiddle;
5160 int joystick_fd = joystick.fd[player_nr];
5161 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5162 boolean check[3][3];
5163 int check_remaining = 3 * 3;
5168 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5171 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5175 FadeOut(REDRAW_FIELD);
5179 for (y = 0; y < 3; y++)
5181 for (x = 0; x < 3; x++)
5183 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5184 check[x][y] = FALSE;
5188 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5189 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5190 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5191 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5192 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5193 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5194 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5196 joy_value = Joystick(player_nr);
5197 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5198 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5200 /* eventually uncalibrated center position (joystick could be uncentered) */
5201 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5204 new_joystick_xmiddle = joy_x;
5205 new_joystick_ymiddle = joy_y;
5207 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5209 FadeIn(REDRAW_FIELD);
5211 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5216 if (PendingEvent()) /* got event */
5224 case EVENT_KEYPRESS:
5225 switch (GetEventKey((KeyEvent *)&event, TRUE))
5228 if (check_remaining == 0)
5233 FadeSkipNextFadeIn();
5242 case EVENT_KEYRELEASE:
5243 key_joystick_mapping = 0;
5247 HandleOtherEvents(&event);
5252 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5255 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5256 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5257 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5258 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5260 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5261 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5262 setup.input[player_nr].joy.xright = new_joystick_xright;
5263 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5264 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5265 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5267 CheckJoystickData();
5269 joy_value = Joystick(player_nr);
5271 if (joy_value & JOY_BUTTON && check_remaining == 0)
5274 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5275 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5277 if (x != last_x || y != last_y)
5279 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5280 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5285 if (check_remaining > 0 && !check[x+1][y+1])
5287 check[x+1][y+1] = TRUE;
5293 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5294 setup.input[player_nr].joy.xleft,
5295 setup.input[player_nr].joy.xmiddle,
5296 setup.input[player_nr].joy.xright);
5297 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5298 setup.input[player_nr].joy.yupper,
5299 setup.input[player_nr].joy.ymiddle,
5300 setup.input[player_nr].joy.ylower);
5309 /* don't eat all CPU time */
5313 /* calibrated center position (joystick should now be centered) */
5314 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5317 new_joystick_xmiddle = joy_x;
5318 new_joystick_ymiddle = joy_y;
5323 DrawSetupScreen_Input();
5326 /* wait until the last pressed button was released */
5327 while (Joystick(player_nr) & JOY_BUTTON)
5329 if (PendingEvent()) /* got event */
5334 HandleOtherEvents(&event);
5343 void CalibrateJoystick(int player_nr)
5345 if (!CalibrateJoystickMain(player_nr))
5347 char *device_name = setup.input[player_nr].joy.device_name;
5348 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5349 int xpos = mSX - SX;
5350 int ypos = mSY - SY;
5354 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5355 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5358 Delay(2000); /* show error message for a short time */
5364 DrawSetupScreen_Input();
5368 void DrawSetupScreen()
5370 DeactivateJoystick();
5372 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5374 if (setup_mode == SETUP_MODE_INPUT)
5375 DrawSetupScreen_Input();
5376 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5377 DrawChooseTree(&game_speed_current);
5378 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5379 DrawChooseTree(&screen_mode_current);
5380 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5381 DrawChooseTree(&scroll_delay_current);
5382 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5383 DrawChooseTree(&artwork.gfx_current);
5384 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5385 DrawChooseTree(&artwork.snd_current);
5386 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5387 DrawChooseTree(&artwork.mus_current);
5389 DrawSetupScreen_Generic();
5395 void RedrawSetupScreenAfterFullscreenToggle()
5397 if (setup_mode == SETUP_MODE_GRAPHICS)
5401 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5403 if (setup_mode == SETUP_MODE_INPUT)
5404 HandleSetupScreen_Input(mx, my, dx, dy, button);
5405 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5406 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5407 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5408 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5409 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5410 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5411 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5412 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5413 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5414 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5415 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5416 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5418 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5423 void HandleGameActions()
5425 if (game_status != GAME_MODE_PLAYING)
5428 GameActions(); /* main game loop */
5430 if (tape.auto_play && !tape.playing)
5431 AutoPlayTape(); /* continue automatically playing next tape */
5435 /* ---------- new screen button stuff -------------------------------------- */
5437 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5442 case SCREEN_CTRL_ID_PREV_LEVEL:
5443 *x = mSX + menu.main.button.prev_level.x;
5444 *y = mSY + menu.main.button.prev_level.y;
5447 case SCREEN_CTRL_ID_NEXT_LEVEL:
5448 *x = mSX + menu.main.button.next_level.x;
5449 *y = mSY + menu.main.button.next_level.y;
5452 case SCREEN_CTRL_ID_PREV_LEVEL:
5453 *x = mSX + TILEX * getPrevlevelButtonPos();
5454 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5457 case SCREEN_CTRL_ID_NEXT_LEVEL:
5458 *x = mSX + TILEX * getNextLevelButtonPos();
5459 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5463 case SCREEN_CTRL_ID_PREV_PLAYER:
5464 *x = mSX + TILEX * 10;
5465 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5468 case SCREEN_CTRL_ID_NEXT_PLAYER:
5469 *x = mSX + TILEX * 12;
5470 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5474 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5480 int gfx_unpressed, gfx_pressed;
5481 void (*get_gadget_position)(int *, int *, int);
5485 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5488 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5489 getScreenMenuButtonPos,
5490 SCREEN_CTRL_ID_PREV_LEVEL,
5495 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5496 getScreenMenuButtonPos,
5497 SCREEN_CTRL_ID_NEXT_LEVEL,
5502 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5503 getScreenMenuButtonPos,
5504 SCREEN_CTRL_ID_PREV_PLAYER,
5509 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5510 getScreenMenuButtonPos,
5511 SCREEN_CTRL_ID_NEXT_PLAYER,
5519 int gfx_unpressed, gfx_pressed;
5523 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5526 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5527 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5528 SCREEN_CTRL_ID_SCROLL_UP,
5532 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5533 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5534 SCREEN_CTRL_ID_SCROLL_DOWN,
5541 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5542 Bitmap **gfx_unpressed, **gfx_pressed;
5544 int gfx_unpressed, gfx_pressed;
5551 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5554 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5555 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5557 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5559 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5560 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5561 GD_TYPE_SCROLLBAR_VERTICAL,
5562 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5563 "scroll level series vertically"
5567 static void CreateScreenMenubuttons()
5569 struct GadgetInfo *gi;
5570 unsigned long event_mask;
5573 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5575 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5576 int gfx_unpressed, gfx_pressed;
5577 int x, y, width, height;
5578 int gd_x1, gd_x2, gd_y1, gd_y2;
5579 int id = menubutton_info[i].gadget_id;
5581 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5583 menubutton_info[i].get_gadget_position(&x, &y, id);
5585 width = SC_MENUBUTTON_XSIZE;
5586 height = SC_MENUBUTTON_YSIZE;
5588 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5589 gfx_pressed = menubutton_info[i].gfx_pressed;
5590 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5591 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5592 gd_x1 = graphic_info[gfx_unpressed].src_x;
5593 gd_y1 = graphic_info[gfx_unpressed].src_y;
5594 gd_x2 = graphic_info[gfx_pressed].src_x;
5595 gd_y2 = graphic_info[gfx_pressed].src_y;
5597 gi = CreateGadget(GDI_CUSTOM_ID, id,
5598 GDI_CUSTOM_TYPE_ID, i,
5599 GDI_INFO_TEXT, menubutton_info[i].infotext,
5604 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5605 GDI_STATE, GD_BUTTON_UNPRESSED,
5606 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5607 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5608 GDI_DIRECT_DRAW, FALSE,
5609 GDI_EVENT_MASK, event_mask,
5610 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5614 Error(ERR_EXIT, "cannot create gadget");
5616 screen_gadget[id] = gi;
5620 static void CreateScreenScrollbuttons()
5622 struct GadgetInfo *gi;
5623 unsigned long event_mask;
5626 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5628 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5629 int gfx_unpressed, gfx_pressed;
5630 int x, y, width, height;
5631 int gd_x1, gd_x2, gd_y1, gd_y2;
5632 int id = scrollbutton_info[i].gadget_id;
5634 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5636 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5637 y = mSY + scrollbutton_info[i].y;
5638 width = SC_SCROLLBUTTON_XSIZE;
5639 height = SC_SCROLLBUTTON_YSIZE;
5641 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5642 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5643 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5645 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5646 gfx_pressed = scrollbutton_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, scrollbutton_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 CreateScreenScrollbars()
5681 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5683 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5684 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5685 int gfx_unpressed, gfx_pressed;
5687 int x, y, width, height;
5688 int gd_x1, gd_x2, gd_y1, gd_y2;
5689 struct GadgetInfo *gi;
5690 int items_max, items_visible, item_position;
5691 unsigned long event_mask;
5692 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5693 int id = scrollbar_info[i].gadget_id;
5695 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5697 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5698 y = mSY + scrollbar_info[i].y;
5699 width = scrollbar_info[i].width;
5700 height = scrollbar_info[i].height;
5702 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5703 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5705 items_max = num_page_entries;
5706 items_visible = num_page_entries;
5709 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5710 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5711 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5717 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5718 gfx_pressed = scrollbar_info[i].gfx_pressed;
5719 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5720 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5721 gd_x1 = graphic_info[gfx_unpressed].src_x;
5722 gd_y1 = graphic_info[gfx_unpressed].src_y;
5723 gd_x2 = graphic_info[gfx_pressed].src_x;
5724 gd_y2 = graphic_info[gfx_pressed].src_y;
5727 gi = CreateGadget(GDI_CUSTOM_ID, id,
5728 GDI_CUSTOM_TYPE_ID, i,
5729 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5734 GDI_TYPE, scrollbar_info[i].type,
5735 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5736 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5737 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5739 GDI_WHEEL_AREA_X, SX,
5740 GDI_WHEEL_AREA_Y, SY,
5741 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5742 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5744 GDI_WHEEL_AREA_X, 0,
5745 GDI_WHEEL_AREA_Y, 0,
5746 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5747 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5749 GDI_STATE, GD_BUTTON_UNPRESSED,
5750 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5751 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5752 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5753 GDI_DIRECT_DRAW, FALSE,
5754 GDI_EVENT_MASK, event_mask,
5755 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5759 Error(ERR_EXIT, "cannot create gadget");
5761 screen_gadget[id] = gi;
5765 void CreateScreenGadgets()
5767 int last_game_status = game_status; /* save current game status */
5769 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5772 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5774 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5776 /* copy pointers to clip mask and GC */
5777 scrollbar_bitmap[i]->clip_mask =
5778 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5779 scrollbar_bitmap[i]->stored_clip_gc =
5780 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5782 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5783 scrollbar_bitmap[i],
5784 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5785 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5786 TILEX, TILEY, 0, 0);
5790 CreateScreenMenubuttons();
5793 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5794 game_status = GAME_MODE_LEVELS;
5797 CreateScreenScrollbuttons();
5798 CreateScreenScrollbars();
5800 game_status = last_game_status; /* restore current game status */
5803 void FreeScreenGadgets()
5807 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5808 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5810 /* prevent freeing clip mask and GC twice */
5811 scrollbar_bitmap[i]->clip_mask = None;
5812 scrollbar_bitmap[i]->stored_clip_gc = None;
5814 FreeBitmap(scrollbar_bitmap[i]);
5818 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5819 FreeGadget(screen_gadget[i]);
5822 void MapScreenMenuGadgets(int screen_mask)
5826 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5827 if (screen_mask & menubutton_info[i].screen_mask)
5828 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5831 void MapScreenTreeGadgets(TreeInfo *ti)
5833 int num_entries = numTreeInfoInGroup(ti);
5836 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5839 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5840 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5842 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5843 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5846 static void HandleScreenGadgets(struct GadgetInfo *gi)
5848 int id = gi->custom_id;
5849 int button = gi->event.button;
5850 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5854 case SCREEN_CTRL_ID_PREV_LEVEL:
5855 HandleMainMenu_SelectLevel(step, -1);
5858 case SCREEN_CTRL_ID_NEXT_LEVEL:
5859 HandleMainMenu_SelectLevel(step, +1);
5862 case SCREEN_CTRL_ID_PREV_PLAYER:
5863 HandleSetupScreen_Input_Player(step, -1);
5866 case SCREEN_CTRL_ID_NEXT_PLAYER:
5867 HandleSetupScreen_Input_Player(step, +1);
5870 case SCREEN_CTRL_ID_SCROLL_UP:
5871 if (game_status == GAME_MODE_LEVELS)
5872 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5873 else if (game_status == GAME_MODE_SETUP)
5874 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5877 case SCREEN_CTRL_ID_SCROLL_DOWN:
5878 if (game_status == GAME_MODE_LEVELS)
5879 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5880 else if (game_status == GAME_MODE_SETUP)
5881 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5884 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5885 if (game_status == GAME_MODE_LEVELS)
5886 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5887 else if (game_status == GAME_MODE_SETUP)
5888 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);