1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
26 /* screens on the info screen */
27 #define INFO_MODE_MAIN 0
28 #define INFO_MODE_TITLE 1
29 #define INFO_MODE_ELEMENTS 2
30 #define INFO_MODE_MUSIC 3
31 #define INFO_MODE_CREDITS 4
32 #define INFO_MODE_PROGRAM 5
33 #define INFO_MODE_VERSION 6
34 #define INFO_MODE_LEVELSET 7
36 #define MAX_INFO_MODES 8
38 /* screens on the setup screen */
39 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
40 /* (should also match corresponding entries in src/conf_gfx.c) */
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_TOUCH 7
49 #define SETUP_MODE_SHORTCUTS 8
50 #define SETUP_MODE_SHORTCUTS_1 9
51 #define SETUP_MODE_SHORTCUTS_2 10
52 #define SETUP_MODE_SHORTCUTS_3 11
53 #define SETUP_MODE_SHORTCUTS_4 12
54 #define SETUP_MODE_SHORTCUTS_5 13
56 /* sub-screens on the setup screen (generic) */
57 #define SETUP_MODE_CHOOSE_ARTWORK 14
58 #define SETUP_MODE_CHOOSE_OTHER 15
60 /* sub-screens on the setup screen (specific) */
61 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
64 #define SETUP_MODE_CHOOSE_SCREEN_MODE 19
65 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
66 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
67 #define SETUP_MODE_CHOOSE_GRAPHICS 22
68 #define SETUP_MODE_CHOOSE_SOUNDS 23
69 #define SETUP_MODE_CHOOSE_MUSIC 24
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
73 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
74 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
75 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
77 #define MAX_SETUP_MODES 31
79 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
81 /* for input setup functions */
82 #define SETUPINPUT_SCREEN_POS_START 0
83 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
84 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
85 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
87 /* for various menu stuff */
88 #define MENU_SCREEN_START_XPOS 1
89 #define MENU_SCREEN_START_YPOS 2
90 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
91 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
103 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
104 MENU_SCREEN_INFO_YSTEP)
105 #define NUM_INFO_ELEMENTS_FROM_CONF \
106 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
107 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
108 MAX_MENU_ENTRIES_ON_SCREEN)
109 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
110 MAX_INFO_ELEMENTS_ON_SCREEN), \
111 NUM_INFO_ELEMENTS_FROM_CONF)
112 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
113 #define MAX_MENU_TEXT_LENGTH_BIG 13
114 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
116 /* buttons and scrollbars identifiers */
117 #define SCREEN_CTRL_ID_PREV_LEVEL 0
118 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
119 #define SCREEN_CTRL_ID_PREV_PLAYER 2
120 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
121 #define SCREEN_CTRL_ID_SCROLL_UP 4
122 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
123 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
125 #define NUM_SCREEN_GADGETS 7
127 #define NUM_SCREEN_MENUBUTTONS 4
128 #define NUM_SCREEN_SCROLLBUTTONS 2
129 #define NUM_SCREEN_SCROLLBARS 1
131 #define SCREEN_MASK_MAIN (1 << 0)
132 #define SCREEN_MASK_INPUT (1 << 1)
134 /* graphic position and size values for buttons and scrollbars */
135 #define SC_MENUBUTTON_XSIZE TILEX
136 #define SC_MENUBUTTON_YSIZE TILEY
138 #define SC_SCROLLBUTTON_XSIZE TILEX
139 #define SC_SCROLLBUTTON_YSIZE TILEY
141 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
143 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
144 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
145 SC_SCROLLBUTTON_YSIZE)
147 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
148 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
150 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
151 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
152 SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
156 SC_SCROLL_VERTICAL_YSIZE)
158 #define SC_BORDER_SIZE 14
161 /* forward declarations of internal functions */
162 static void HandleScreenGadgets(struct GadgetInfo *);
163 static void HandleSetupScreen_Generic(int, int, int, int, int);
164 static void HandleSetupScreen_Input(int, int, int, int, int);
165 static void CustomizeKeyboard(int);
166 static void CalibrateJoystick(int);
167 static void execSetupGame(void);
168 static void execSetupGraphics(void);
169 static void execSetupSound(void);
170 static void execSetupTouch(void);
171 static void execSetupArtwork(void);
172 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
174 static void DrawChooseLevelSet(void);
175 static void DrawChooseLevelNr(void);
176 static void DrawInfoScreen(void);
177 static void DrawSetupScreen(void);
179 static void DrawInfoScreen_NotAvailable(char *, char *);
180 static void DrawInfoScreen_HelpAnim(int, int, boolean);
181 static void DrawInfoScreen_HelpText(int, int, int, int);
182 static void HandleInfoScreen_Main(int, int, int, int, int);
183 static void HandleInfoScreen_TitleScreen(int);
184 static void HandleInfoScreen_Elements(int);
185 static void HandleInfoScreen_Music(int);
186 static void HandleInfoScreen_Credits(int);
187 static void HandleInfoScreen_Program(int);
188 static void HandleInfoScreen_Version(int);
190 static void MapScreenMenuGadgets(int);
191 static void MapScreenGadgets(int);
192 static void MapScreenTreeGadgets(TreeInfo *);
194 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
196 static int info_mode = INFO_MODE_MAIN;
197 static int setup_mode = SETUP_MODE_MAIN;
199 static TreeInfo *screen_modes = NULL;
200 static TreeInfo *screen_mode_current = NULL;
202 static TreeInfo *window_sizes = NULL;
203 static TreeInfo *window_size_current = NULL;
205 static TreeInfo *scaling_types = NULL;
206 static TreeInfo *scaling_type_current = NULL;
208 static TreeInfo *scroll_delays = NULL;
209 static TreeInfo *scroll_delay_current = NULL;
211 static TreeInfo *snapshot_modes = NULL;
212 static TreeInfo *snapshot_mode_current = NULL;
214 static TreeInfo *game_speeds = NULL;
215 static TreeInfo *game_speed_current = NULL;
217 static TreeInfo *volumes_simple = NULL;
218 static TreeInfo *volume_simple_current = NULL;
220 static TreeInfo *volumes_loops = NULL;
221 static TreeInfo *volume_loops_current = NULL;
223 static TreeInfo *volumes_music = NULL;
224 static TreeInfo *volume_music_current = NULL;
226 static TreeInfo *touch_controls = NULL;
227 static TreeInfo *touch_control_current = NULL;
229 static TreeInfo *move_distances = NULL;
230 static TreeInfo *move_distance_current = NULL;
232 static TreeInfo *drop_distances = NULL;
233 static TreeInfo *drop_distance_current = NULL;
235 static TreeInfo *level_number = NULL;
236 static TreeInfo *level_number_current = NULL;
242 } window_sizes_list[] =
247 { 100, "100 % (Default)" },
264 } scaling_types_list[] =
266 { SCALING_QUALITY_NEAREST, "None" },
267 { SCALING_QUALITY_LINEAR, "Linear" },
268 { SCALING_QUALITY_BEST, "Anisotropic" },
277 } game_speeds_list[] =
286 { 1000, "1/1s (Extremely Slow)" },
291 { 29, "1/35s (Original Supaplex)" },
293 { 20, "1/50s (Normal Speed)" },
294 { 14, "1/70s (Maximum Supaplex)" },
298 { 1, "1/1000s (Extremely Fast)" },
308 } scroll_delays_list[] =
310 { 0, "0 Tiles (No Scroll Delay)" },
313 { 3, "3 Tiles (Default)" },
318 { 8, "8 Tiles (Maximum Scroll Delay)"},
327 } snapshot_modes_list[] =
329 { STR_SNAPSHOT_MODE_OFF, "Off" },
330 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
331 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
364 } touch_controls_list[] =
366 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
367 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
391 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
392 (s) <= GAME_MODE_SETUP ? (s) : \
393 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
394 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
396 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
397 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
398 (i) <= INFO_MODE_LEVELSET ? (i) : \
401 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
402 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
403 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
404 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
405 SETUP_MODE_CHOOSE_ARTWORK : \
406 SETUP_MODE_CHOOSE_OTHER)
408 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
409 menu.draw_xoffset[GAME_MODE_INFO] : \
410 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
411 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
412 menu.draw_yoffset[GAME_MODE_INFO] : \
413 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
415 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
416 menu.draw_xoffset[GAME_MODE_SETUP] : \
417 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
418 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
419 menu.draw_yoffset[GAME_MODE_SETUP] : \
420 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
422 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
423 DRAW_XOFFSET_INFO(info_mode) : \
424 (s) == GAME_MODE_SETUP ? \
425 DRAW_XOFFSET_SETUP(setup_mode) : \
426 menu.draw_xoffset[DRAW_MODE(s)])
427 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
428 DRAW_YOFFSET_INFO(info_mode) : \
429 (s) == GAME_MODE_SETUP ? \
430 DRAW_YOFFSET_SETUP(setup_mode) : \
431 menu.draw_yoffset[DRAW_MODE(s)])
433 #define mSX (SX + DRAW_XOFFSET(game_status))
434 #define mSY (SY + DRAW_YOFFSET(game_status))
436 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
437 menu.list_size[game_status] : \
438 MAX_MENU_ENTRIES_ON_SCREEN)
440 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
441 NUM_MENU_ENTRIES_ON_SCREEN)
444 /* title display and control definitions */
446 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
447 2 * MAX_NUM_TITLE_MESSAGES)
449 #define NO_DIRECT_LEVEL_SELECT (-1)
452 static int num_title_screens = 0;
454 struct TitleControlInfo
462 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
464 /* main menu display and control definitions */
466 #define MAIN_CONTROL_NAME 0
467 #define MAIN_CONTROL_LEVELS 1
468 #define MAIN_CONTROL_SCORES 2
469 #define MAIN_CONTROL_EDITOR 3
470 #define MAIN_CONTROL_INFO 4
471 #define MAIN_CONTROL_GAME 5
472 #define MAIN_CONTROL_SETUP 6
473 #define MAIN_CONTROL_QUIT 7
474 #define MAIN_CONTROL_PREV_LEVEL 8
475 #define MAIN_CONTROL_NEXT_LEVEL 9
476 #define MAIN_CONTROL_FIRST_LEVEL 10
477 #define MAIN_CONTROL_LAST_LEVEL 11
478 #define MAIN_CONTROL_LEVEL_NUMBER 12
479 #define MAIN_CONTROL_LEVEL_INFO_1 13
480 #define MAIN_CONTROL_LEVEL_INFO_2 14
481 #define MAIN_CONTROL_LEVEL_NAME 15
482 #define MAIN_CONTROL_LEVEL_AUTHOR 16
483 #define MAIN_CONTROL_LEVEL_YEAR 17
484 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
485 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
486 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
487 #define MAIN_CONTROL_TITLE_1 21
488 #define MAIN_CONTROL_TITLE_2 22
489 #define MAIN_CONTROL_TITLE_3 23
491 static char str_main_text_name[10];
492 static char str_main_text_first_level[10];
493 static char str_main_text_last_level[10];
494 static char str_main_text_level_number[10];
496 static char *main_text_name = str_main_text_name;
497 static char *main_text_first_level = str_main_text_first_level;
498 static char *main_text_last_level = str_main_text_last_level;
499 static char *main_text_level_number = str_main_text_level_number;
500 static char *main_text_levels = "Levelset";
501 static char *main_text_scores = "Hall Of Fame";
502 static char *main_text_editor = "Level Creator";
503 static char *main_text_info = "Info Screen";
504 static char *main_text_game = "Start Game";
505 static char *main_text_setup = "Setup";
506 static char *main_text_quit = "Quit";
507 static char *main_text_level_name = level.name;
508 static char *main_text_level_author = level.author;
509 static char *main_text_level_year = NULL;
510 static char *main_text_level_imported_from = NULL;
511 static char *main_text_level_imported_by = NULL;
512 static char *main_text_level_tested_by = NULL;
514 struct MainControlInfo
518 struct MenuPosInfo *pos_button;
521 struct TextPosInfo *pos_text;
524 struct TextPosInfo *pos_input;
528 static struct MainControlInfo main_controls[] =
532 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
533 &menu.main.text.name, &main_text_name,
534 &menu.main.input.name, &setup.player_name,
538 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
539 &menu.main.text.levels, &main_text_levels,
544 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
545 &menu.main.text.scores, &main_text_scores,
550 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
551 &menu.main.text.editor, &main_text_editor,
556 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
557 &menu.main.text.info, &main_text_info,
562 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
563 &menu.main.text.game, &main_text_game,
568 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
569 &menu.main.text.setup, &main_text_setup,
574 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
575 &menu.main.text.quit, &main_text_quit,
579 /* (these two buttons are real gadgets) */
581 MAIN_CONTROL_PREV_LEVEL,
582 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
587 MAIN_CONTROL_NEXT_LEVEL,
588 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
594 MAIN_CONTROL_FIRST_LEVEL,
596 &menu.main.text.first_level, &main_text_first_level,
600 MAIN_CONTROL_LAST_LEVEL,
602 &menu.main.text.last_level, &main_text_last_level,
606 MAIN_CONTROL_LEVEL_NUMBER,
608 &menu.main.text.level_number, &main_text_level_number,
612 MAIN_CONTROL_LEVEL_INFO_1,
614 &menu.main.text.level_info_1, NULL,
618 MAIN_CONTROL_LEVEL_INFO_2,
620 &menu.main.text.level_info_2, NULL,
624 MAIN_CONTROL_LEVEL_NAME,
626 &menu.main.text.level_name, &main_text_level_name,
630 MAIN_CONTROL_LEVEL_AUTHOR,
632 &menu.main.text.level_author, &main_text_level_author,
636 MAIN_CONTROL_LEVEL_YEAR,
638 &menu.main.text.level_year, &main_text_level_year,
642 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
644 &menu.main.text.level_imported_from, &main_text_level_imported_from,
648 MAIN_CONTROL_LEVEL_IMPORTED_BY,
650 &menu.main.text.level_imported_by, &main_text_level_imported_by,
654 MAIN_CONTROL_LEVEL_TESTED_BY,
656 &menu.main.text.level_tested_by, &main_text_level_tested_by,
660 MAIN_CONTROL_TITLE_1,
662 &menu.main.text.title_1, &setup.internal.program_title,
666 MAIN_CONTROL_TITLE_2,
668 &menu.main.text.title_2, &setup.internal.program_copyright,
672 MAIN_CONTROL_TITLE_3,
674 &menu.main.text.title_3, &setup.internal.program_company,
687 static int getTitleScreenGraphic(int nr, boolean initial)
689 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
692 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
694 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
698 static int getTitleScreenGameMode(boolean initial)
700 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
704 static int getTitleMessageGameMode(boolean initial)
706 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
710 static int getTitleScreenBackground(boolean initial)
712 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
717 static int getTitleMessageBackground(int nr, boolean initial)
719 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
723 static int getTitleBackground(int nr, boolean initial, boolean is_image)
725 int base = (is_image ?
726 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
727 IMG_BACKGROUND_TITLESCREEN_1) :
728 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
729 IMG_BACKGROUND_TITLEMESSAGE_1));
730 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
731 IMG_BACKGROUND_TITLE);
732 int graphic_local = base + nr;
734 if (graphic_info[graphic_local].bitmap != NULL)
735 return graphic_local;
737 if (graphic_info[graphic_global].bitmap != NULL)
738 return graphic_global;
740 return IMG_UNDEFINED;
743 static int getTitleSound(struct TitleControlInfo *tci)
745 boolean is_image = tci->is_image;
746 int initial = tci->initial;
747 int nr = tci->local_nr;
748 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
749 int base = (is_image ?
750 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
751 SND_BACKGROUND_TITLESCREEN_1) :
752 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
753 SND_BACKGROUND_TITLEMESSAGE_1));
754 int sound_global = menu.sound[mode];
755 int sound_local = base + nr;
758 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
759 nr, initial, is_image,
760 sound_global, getSoundListEntry(sound_global)->filename,
761 sound_local, getSoundListEntry(sound_local)->filename);
764 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
767 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
770 return SND_UNDEFINED;
773 static int getTitleMusic(struct TitleControlInfo *tci)
775 boolean is_image = tci->is_image;
776 int initial = tci->initial;
777 int nr = tci->local_nr;
778 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
779 int base = (is_image ?
780 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
781 MUS_BACKGROUND_TITLESCREEN_1) :
782 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
783 MUS_BACKGROUND_TITLEMESSAGE_1));
784 int music_global = menu.music[mode];
785 int music_local = base + nr;
788 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
789 nr, initial, is_image,
790 music_global, getMusicListEntry(music_global)->filename,
791 music_local, getMusicListEntry(music_local)->filename);
794 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
797 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
800 return MUS_UNDEFINED;
803 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
805 boolean is_image = tci->is_image;
806 int initial = tci->initial;
807 int nr = tci->local_nr;
808 struct TitleFadingInfo ti;
812 int graphic = getTitleScreenGraphic(nr, initial);
814 /* initialize fading control values to default title config settings */
815 ti = (initial ? title_initial_default : title_default);
817 /* override default settings with image config settings, if defined */
818 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
819 ti.fade_mode = graphic_info[graphic].fade_mode;
820 if (graphic_info[graphic].fade_delay > -1)
821 ti.fade_delay = graphic_info[graphic].fade_delay;
822 if (graphic_info[graphic].post_delay > -1)
823 ti.post_delay = graphic_info[graphic].post_delay;
824 if (graphic_info[graphic].auto_delay > -1)
825 ti.auto_delay = graphic_info[graphic].auto_delay;
831 ti.fade_mode = titlemessage_initial[nr].fade_mode;
832 ti.fade_delay = titlemessage_initial[nr].fade_delay;
833 ti.post_delay = titlemessage_initial[nr].post_delay;
834 ti.auto_delay = titlemessage_initial[nr].auto_delay;
838 ti.fade_mode = titlemessage[nr].fade_mode;
839 ti.fade_delay = titlemessage[nr].fade_delay;
840 ti.post_delay = titlemessage[nr].post_delay;
841 ti.auto_delay = titlemessage[nr].auto_delay;
848 static int compareTitleControlInfo(const void *object1, const void *object2)
850 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
851 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
854 if (tci1->initial != tci2->initial)
855 compare_result = (tci1->initial ? -1 : +1);
856 else if (tci1->sort_priority != tci2->sort_priority)
857 compare_result = tci1->sort_priority - tci2->sort_priority;
858 else if (tci1->is_image != tci2->is_image)
859 compare_result = (tci1->is_image ? -1 : +1);
861 compare_result = tci1->local_nr - tci2->local_nr;
863 return compare_result;
866 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
868 int nr, int sort_priority)
870 title_controls[num_title_screens].is_image = is_image;
871 title_controls[num_title_screens].initial = initial;
872 title_controls[num_title_screens].local_nr = nr;
873 title_controls[num_title_screens].sort_priority = sort_priority;
878 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
882 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
884 int graphic = getTitleScreenGraphic(i, initial);
885 Bitmap *bitmap = graphic_info[graphic].bitmap;
886 int sort_priority = graphic_info[graphic].sort_priority;
889 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
892 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
894 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
895 char *filename = getLevelSetTitleMessageFilename(i, initial);
896 int sort_priority = tmi->sort_priority;
898 if (filename != NULL)
899 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
903 static void InitializeTitleControls(boolean show_title_initial)
905 num_title_screens = 0;
907 /* 1st step: initialize title screens for game start (only when starting) */
908 if (show_title_initial)
909 InitializeTitleControls_CheckTitleInfo(TRUE);
911 /* 2nd step: initialize title screens for current level set */
912 InitializeTitleControls_CheckTitleInfo(FALSE);
914 /* sort title screens according to sort_priority and title number */
915 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
916 compareTitleControlInfo);
919 static boolean visibleMenuPos(struct MenuPosInfo *pos)
921 return (pos != NULL && pos->x != -1 && pos->y != -1);
924 static boolean visibleTextPos(struct TextPosInfo *pos)
926 return (pos != NULL && pos->x != -1 && pos->y != -1);
929 static void InitializeMainControls()
931 boolean local_team_mode = (!options.network && setup.team_mode);
934 /* set main control text values to dynamically determined values */
935 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
937 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
938 menu.main.text.first_level.size));
939 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
940 menu.main.text.last_level.size));
941 strcpy(main_text_level_number, int2str(level_nr,
942 menu.main.text.level_number.size));
944 main_text_level_year = leveldir_current->year;
945 main_text_level_imported_from = leveldir_current->imported_from;
946 main_text_level_imported_by = leveldir_current->imported_by;
947 main_text_level_tested_by = leveldir_current->tested_by;
949 /* set main control screen positions to dynamically determined values */
950 for (i = 0; main_controls[i].nr != -1; i++)
952 struct MainControlInfo *mci = &main_controls[i];
954 struct MenuPosInfo *pos_button = mci->pos_button;
955 struct TextPosInfo *pos_text = mci->pos_text;
956 struct TextPosInfo *pos_input = mci->pos_input;
957 char *text = (mci->text ? *mci->text : NULL);
958 char *input = (mci->input ? *mci->input : NULL);
959 int button_graphic = mci->button_graphic;
960 int font_text = (pos_text ? pos_text->font : -1);
961 int font_input = (pos_input ? pos_input->font : -1);
963 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
964 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
965 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
966 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
967 int text_chars = (text != NULL ? strlen(text) : 0);
968 int input_chars = (input != NULL ? strlen(input) : 0);
971 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
973 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
974 int text_width = font_text_width * text_chars;
975 int text_height = font_text_height;
976 int input_width = font_input_width * input_chars;
977 int input_height = font_input_height;
979 if (nr == MAIN_CONTROL_NAME)
981 menu.main.input.name.width = input_width;
982 menu.main.input.name.height = input_height;
985 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
987 pos_button->width = button_width;
988 pos_button->height = button_height;
991 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
993 /* calculate size for non-clickable text -- needed for text alignment */
994 boolean calculate_text_size = (pos_button == NULL && text != NULL);
996 if (pos_text->width == -1 || calculate_text_size)
997 pos_text->width = text_width;
998 if (pos_text->height == -1 || calculate_text_size)
999 pos_text->height = text_height;
1001 if (visibleMenuPos(pos_button))
1003 if (pos_text->x == -1)
1004 pos_text->x = pos_button->x + pos_button->width;
1005 if (pos_text->y == -1)
1007 pos_button->y + (pos_button->height - pos_text->height) / 2;
1011 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1013 if (visibleTextPos(pos_text))
1015 if (pos_input->x == -1)
1016 pos_input->x = pos_text->x + pos_text->width;
1017 if (pos_input->y == -1)
1018 pos_input->y = pos_text->y;
1021 if (pos_input->width == -1)
1022 pos_input->width = input_width;
1023 if (pos_input->height == -1)
1024 pos_input->height = input_height;
1029 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1030 int graphic, boolean pressed)
1032 struct GraphicInfo *g = &graphic_info[graphic];
1035 int xoffset = (pressed ? g->pressed_xoffset : 0);
1036 int yoffset = (pressed ? g->pressed_yoffset : 0);
1038 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1040 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1041 g->width, g->height, dst_x, dst_y);
1044 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1045 boolean active_input,
1046 boolean pressed_button)
1050 for (i = 0; main_controls[i].nr != -1; i++)
1052 struct MainControlInfo *mci = &main_controls[i];
1054 if (mci->nr == nr || nr == -1)
1056 struct MenuPosInfo *pos_button = mci->pos_button;
1057 struct TextPosInfo *pos_text = mci->pos_text;
1058 struct TextPosInfo *pos_input = mci->pos_input;
1059 char *text = (mci->text ? *mci->text : NULL);
1060 char *input = (mci->input ? *mci->input : NULL);
1061 int button_graphic = mci->button_graphic;
1062 int font_text = (pos_text ? pos_text->font : -1);
1063 int font_input = (pos_input ? pos_input->font : -1);
1067 button_graphic = BUTTON_ACTIVE(button_graphic);
1068 font_text = FONT_ACTIVE(font_text);
1073 font_input = FONT_ACTIVE(font_input);
1076 if (visibleMenuPos(pos_button))
1078 struct MenuPosInfo *pos = pos_button;
1079 int x = mSX + pos->x;
1080 int y = mSY + pos->y;
1082 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1083 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1086 if (visibleTextPos(pos_text) && text != NULL)
1088 struct TextPosInfo *pos = pos_text;
1089 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1090 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1093 /* (check why/if this is needed) */
1094 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1096 DrawText(x, y, text, font_text);
1099 if (visibleTextPos(pos_input) && input != NULL)
1101 struct TextPosInfo *pos = pos_input;
1102 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1103 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1106 /* (check why/if this is needed) */
1107 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1109 DrawText(x, y, input, font_input);
1115 static void DrawCursorAndText_Main(int nr, boolean active_text,
1116 boolean pressed_button)
1118 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1122 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1123 boolean pressed_button)
1125 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1129 static struct MainControlInfo *getMainControlInfo(int nr)
1133 for (i = 0; main_controls[i].nr != -1; i++)
1134 if (main_controls[i].nr == nr)
1135 return &main_controls[i];
1140 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1145 int rect_x = ALIGNED_TEXT_XPOS(rect);
1146 int rect_y = ALIGNED_TEXT_YPOS(rect);
1148 return (x >= rect_x && x < rect_x + rect->width &&
1149 y >= rect_y && y < rect_y + rect->height);
1152 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1157 int rect_x = ALIGNED_TEXT_XPOS(rect);
1158 int rect_y = ALIGNED_TEXT_YPOS(rect);
1161 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1162 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1163 (x >= rect_x && x < rect_x + rect->width &&
1164 y >= rect_y && y < rect_y + rect->height));
1167 return (x >= rect_x && x < rect_x + rect->width &&
1168 y >= rect_y && y < rect_y + rect->height);
1171 static void AdjustScrollbar(int id, int items_max, int items_visible,
1174 struct GadgetInfo *gi = screen_gadget[id];
1176 if (item_position > items_max - items_visible)
1177 item_position = items_max - items_visible;
1179 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1180 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1181 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1184 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1186 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1190 static void clearMenuListArea()
1192 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1194 /* correct scrollbar position if placed outside menu (playfield) area */
1195 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1196 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1198 /* clear menu list area, but not title or scrollbar */
1199 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1200 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1203 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1205 static int cursor_array[MAX_LEV_FIELDY];
1206 int x = mSX + TILEX * xpos;
1207 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1212 cursor_array[ypos] = graphic;
1214 graphic = cursor_array[ypos];
1218 graphic = BUTTON_ACTIVE(graphic);
1220 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1221 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1224 static void initCursor(int ypos, int graphic)
1226 drawCursorExt(0, ypos, FALSE, graphic);
1229 static void drawCursor(int ypos, boolean active)
1231 drawCursorExt(0, ypos, active, -1);
1234 static void drawCursorXY(int xpos, int ypos, int graphic)
1236 drawCursorExt(xpos, ypos, FALSE, graphic);
1239 static void drawChooseTreeCursor(int ypos, boolean active)
1241 int last_game_status = game_status; /* save current game status */
1243 drawCursorExt(0, ypos, active, -1);
1245 game_status = last_game_status; /* restore current game status */
1250 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1251 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1252 setup.internal.program_copyright);
1255 int effectiveGameStatus()
1257 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1258 return GAME_MODE_TITLE;
1263 void DrawTitleScreenImage(int nr, boolean initial)
1265 int graphic = getTitleScreenGraphic(nr, initial);
1266 Bitmap *bitmap = graphic_info[graphic].bitmap;
1267 int width = graphic_info[graphic].width;
1268 int height = graphic_info[graphic].height;
1269 int src_x = graphic_info[graphic].src_x;
1270 int src_y = graphic_info[graphic].src_y;
1276 if (width > WIN_XSIZE)
1278 /* image width too large for window => center image horizontally */
1279 src_x = (width - WIN_XSIZE) / 2;
1283 if (height > WIN_YSIZE)
1285 /* image height too large for window => center image vertically */
1286 src_y = (height - WIN_YSIZE) / 2;
1290 /* always display title screens centered */
1291 dst_x = (WIN_XSIZE - width) / 2;
1292 dst_y = (WIN_YSIZE - height) / 2;
1294 SetDrawBackgroundMask(REDRAW_ALL);
1295 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1297 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1299 if (DrawingOnBackground(dst_x, dst_y))
1300 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1302 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1304 redraw_mask = REDRAW_ALL;
1307 void DrawTitleScreenMessage(int nr, boolean initial)
1309 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1310 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1311 int last_game_status = game_status; /* save current game status */
1313 if (filename == NULL)
1316 /* force TITLE font on title message screen */
1317 game_status = getTitleMessageGameMode(initial);
1319 /* if chars set to "-1", automatically determine by text and font width */
1320 if (tmi->chars == -1)
1321 tmi->chars = tmi->width / getFontWidth(tmi->font);
1323 tmi->width = tmi->chars * getFontWidth(tmi->font);
1325 /* if lines set to "-1", automatically determine by text and font height */
1326 if (tmi->lines == -1)
1327 tmi->lines = tmi->height / getFontHeight(tmi->font);
1329 tmi->height = tmi->lines * getFontHeight(tmi->font);
1331 SetDrawBackgroundMask(REDRAW_ALL);
1332 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1334 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1336 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1337 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1338 tmi->autowrap, tmi->centered, tmi->parse_comments);
1340 game_status = last_game_status; /* restore current game status */
1343 void DrawTitleScreen()
1345 KeyboardAutoRepeatOff();
1347 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1352 boolean CheckTitleScreen(boolean levelset_has_changed)
1354 static boolean show_title_initial = TRUE;
1355 boolean show_titlescreen = FALSE;
1357 /* needed to be able to skip title screen, if no image or message defined */
1358 InitializeTitleControls(show_title_initial);
1360 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1361 show_titlescreen = TRUE;
1363 /* show initial title images and messages only once at program start */
1364 show_title_initial = FALSE;
1366 return (show_titlescreen && num_title_screens > 0);
1371 static LevelDirTree *leveldir_last_valid = NULL;
1372 boolean levelset_has_changed = FALSE;
1373 int fade_mask = REDRAW_FIELD;
1375 LimitScreenUpdates(FALSE);
1377 FadeSetLeaveScreen();
1379 /* do not fade out here -- function may continue and fade on editor screen */
1382 FadeSoundsAndMusic();
1384 KeyboardAutoRepeatOn();
1387 audio.sound_deactivated = FALSE;
1391 /* needed if last screen was the playing screen, invoked from level editor */
1392 if (level_editor_test_game)
1394 game_status = GAME_MODE_EDITOR;
1400 /* needed if last screen was the setup screen and fullscreen state changed */
1401 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1402 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1404 /* leveldir_current may be invalid (level group, parent link) */
1405 if (!validLevelSeries(leveldir_current))
1406 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1408 if (leveldir_current != leveldir_last_valid)
1409 levelset_has_changed = TRUE;
1411 /* store valid level series information */
1412 leveldir_last_valid = leveldir_current;
1414 init_last = init; /* switch to new busy animation */
1416 /* needed if last screen (level choice) changed graphics, sounds or music */
1417 ReloadCustomArtwork(0);
1419 /* needed if different viewport properties defined for menues */
1420 ChangeViewportPropertiesIfNeeded();
1422 if (redraw_mask & REDRAW_ALL)
1423 fade_mask = REDRAW_ALL;
1425 if (CheckIfGlobalBorderHasChanged())
1426 fade_mask = REDRAW_ALL;
1430 /* needed if last screen was the editor screen */
1431 UndrawSpecialEditorDoor();
1433 SetDrawtoField(DRAW_BACKBUFFER);
1435 if (CheckTitleScreen(levelset_has_changed))
1437 game_status_last_screen = GAME_MODE_MAIN;
1438 game_status = GAME_MODE_TITLE;
1445 /* level_nr may have been set to value over handicap with level editor */
1446 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1447 level_nr = leveldir_current->handicap_level;
1449 LoadLevel(level_nr);
1450 LoadScore(level_nr);
1452 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1453 SetDrawDeactivationMask(REDRAW_NONE);
1454 SetDrawBackgroundMask(REDRAW_FIELD);
1456 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1459 if (fade_mask == REDRAW_ALL)
1460 RedrawGlobalBorder();
1465 InitializeMainControls();
1467 DrawCursorAndText_Main(-1, FALSE, FALSE);
1468 DrawPreviewLevelInitial();
1470 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1473 if (TAPE_IS_EMPTY(tape))
1475 DrawCompleteVideoDisplay();
1480 /* create gadgets for main menu screen */
1481 FreeScreenGadgets();
1482 CreateScreenGadgets();
1484 /* map gadgets for main menu screen */
1486 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1488 /* copy actual game door content to door double buffer for OpenDoor() */
1489 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1490 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1492 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1494 DrawMaskedBorder(fade_mask);
1499 /* update screen area with special editor door */
1500 redraw_mask |= REDRAW_ALL;
1503 SetMouseCursor(CURSOR_DEFAULT);
1507 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1510 static void gotoTopLevelDir()
1512 /* move upwards until inside (but not above) top level directory */
1513 while (leveldir_current->node_parent &&
1514 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1516 /* write a "path" into level tree for easy navigation to last level */
1517 if (leveldir_current->node_parent->node_group->cl_first == -1)
1519 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1520 int leveldir_pos = posTreeInfo(leveldir_current);
1521 int num_page_entries;
1522 int cl_first, cl_cursor;
1524 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1525 num_page_entries = num_leveldirs;
1527 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1529 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1530 cl_cursor = leveldir_pos - cl_first;
1532 leveldir_current->node_parent->node_group->cl_first = cl_first;
1533 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1536 leveldir_current = leveldir_current->node_parent;
1540 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1542 static unsigned int title_delay = 0;
1543 static int title_screen_nr = 0;
1544 static int last_sound = -1, last_music = -1;
1545 boolean return_to_main_menu = FALSE;
1546 struct TitleControlInfo *tci;
1547 struct TitleFadingInfo fading_default;
1548 struct TitleFadingInfo fading_last = fading;
1549 struct TitleFadingInfo fading_next;
1552 if (button == MB_MENU_INITIALIZE)
1555 title_screen_nr = 0;
1556 tci = &title_controls[title_screen_nr];
1558 last_sound = SND_UNDEFINED;
1559 last_music = MUS_UNDEFINED;
1561 if (game_status_last_screen == GAME_MODE_INFO)
1563 if (num_title_screens == 0)
1565 DrawInfoScreen_NotAvailable("Title screen information:",
1566 "No title screen for this level set.");
1571 FadeSoundsAndMusic();
1573 FadeOut(REDRAW_ALL);
1575 /* only required to update logic for redrawing global border */
1580 DrawTitleScreenImage(tci->local_nr, tci->initial);
1582 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1584 fading_default = (tci->initial ? title_initial_default : title_default);
1586 fading = fading_next = getTitleFading(tci);
1588 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1589 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1591 fading.fade_mode = FADE_MODE_FADE;
1592 fading.fade_delay = fading_default.fade_delay;
1595 sound = getTitleSound(tci);
1596 music = getTitleMusic(tci);
1598 if (sound != last_sound)
1599 PlayMenuSoundExt(sound);
1600 if (music != last_music)
1601 PlayMenuMusicExt(music);
1606 SetMouseCursor(CURSOR_NONE);
1610 fading = fading_next;
1612 DelayReached(&title_delay, 0); /* reset delay counter */
1617 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1618 button = MB_MENU_CHOICE;
1620 if (button == MB_MENU_LEAVE)
1622 return_to_main_menu = TRUE;
1624 else if (button == MB_MENU_CHOICE)
1626 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1628 FadeSetEnterScreen();
1630 game_status = GAME_MODE_INFO;
1631 info_mode = INFO_MODE_MAIN;
1639 tci = &title_controls[title_screen_nr];
1641 if (title_screen_nr < num_title_screens)
1643 sound = getTitleSound(tci);
1644 music = getTitleMusic(tci);
1646 if (sound == SND_UNDEFINED || sound != last_sound)
1648 if (music == MUS_UNDEFINED || music != last_music)
1651 FadeOut(REDRAW_ALL);
1654 DrawTitleScreenImage(tci->local_nr, tci->initial);
1656 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1658 fading_next = getTitleFading(tci);
1660 sound = getTitleSound(tci);
1661 music = getTitleMusic(tci);
1663 if (sound != last_sound)
1664 PlayMenuSoundExt(sound);
1665 if (music != last_music)
1666 PlayMenuMusicExt(music);
1671 /* last screen already faded out, next screen has no animation */
1672 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1673 fading_next.fade_mode == FADE_MODE_NONE)
1674 fading = fading_next;
1678 fading = fading_next;
1680 DelayReached(&title_delay, 0); /* reset delay counter */
1684 FadeSoundsAndMusic();
1686 return_to_main_menu = TRUE;
1690 if (return_to_main_menu)
1692 SetMouseCursor(CURSOR_DEFAULT);
1694 /* force full menu screen redraw after displaying title screens */
1695 redraw_mask = REDRAW_ALL;
1697 if (game_status_last_screen == GAME_MODE_INFO)
1699 game_status = GAME_MODE_INFO;
1700 info_mode = INFO_MODE_MAIN;
1704 else /* default: return to main menu */
1706 game_status = GAME_MODE_MAIN;
1713 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1715 int old_level_nr = level_nr;
1718 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1719 new_level_nr = selected_level_nr;
1721 new_level_nr = old_level_nr + step * direction;
1723 if (new_level_nr < leveldir_current->first_level)
1724 new_level_nr = leveldir_current->first_level;
1725 if (new_level_nr > leveldir_current->last_level)
1726 new_level_nr = leveldir_current->last_level;
1728 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1730 /* skipping levels is only allowed when trying to skip single level */
1731 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1732 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1734 leveldir_current->handicap_level++;
1735 SaveLevelSetup_SeriesInfo();
1738 new_level_nr = leveldir_current->handicap_level;
1741 if (new_level_nr != old_level_nr)
1743 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1745 PlaySound(SND_MENU_ITEM_SELECTING);
1747 level_nr = new_level_nr;
1749 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1750 int2str(level_nr, menu.main.text.level_number.size),
1751 mci->pos_text->font);
1753 LoadLevel(level_nr);
1754 DrawPreviewLevelInitial();
1758 DrawCompleteVideoDisplay();
1760 /* needed because DrawPreviewLevelInitial() takes some time */
1762 /* SyncDisplay(); */
1766 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1768 static int choice = MAIN_CONTROL_GAME;
1769 static boolean button_pressed_last = FALSE;
1770 boolean button_pressed = FALSE;
1774 if (button == MB_MENU_INITIALIZE)
1776 DrawCursorAndText_Main(choice, TRUE, FALSE);
1781 if (mx || my) /* mouse input */
1785 for (i = 0; main_controls[i].nr != -1; i++)
1787 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1788 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1789 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1791 pos = main_controls[i].nr;
1797 // handle pressed/unpressed state for active/inactive menu buttons
1798 // (if pos != -1, "i" contains index position corresponding to "pos")
1800 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1801 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1802 button_pressed = TRUE;
1804 if (button_pressed != button_pressed_last)
1806 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1809 PlaySound(SND_MENU_BUTTON_PRESSING);
1811 PlaySound(SND_MENU_BUTTON_RELEASING);
1814 else if (dx || dy) /* keyboard input */
1816 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1817 choice == MAIN_CONTROL_SETUP))
1818 button = MB_MENU_CHOICE;
1823 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1825 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1827 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1829 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1831 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1833 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1835 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1839 CloseDoor(DOOR_CLOSE_2);
1841 game_status = GAME_MODE_LEVELNR;
1843 ChangeViewportPropertiesIfNeeded();
1845 DrawChooseLevelNr();
1847 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1853 PlaySound(SND_MENU_ITEM_ACTIVATING);
1855 DrawCursorAndText_Main(choice, FALSE, FALSE);
1856 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1863 PlaySound(SND_MENU_ITEM_SELECTING);
1865 if (pos == MAIN_CONTROL_NAME)
1867 game_status = GAME_MODE_PSEUDO_TYPENAME;
1869 HandleTypeName(strlen(setup.player_name), 0);
1871 else if (pos == MAIN_CONTROL_LEVELS)
1877 CloseDoor(DOOR_CLOSE_2);
1879 game_status = GAME_MODE_LEVELS;
1881 SaveLevelSetup_LastSeries();
1882 SaveLevelSetup_SeriesInfo();
1884 if (setup.internal.choose_from_top_leveldir)
1887 ChangeViewportPropertiesIfNeeded();
1889 DrawChooseLevelSet();
1892 else if (pos == MAIN_CONTROL_SCORES)
1896 CloseDoor(DOOR_CLOSE_2);
1898 game_status = GAME_MODE_SCORES;
1902 else if (pos == MAIN_CONTROL_EDITOR)
1904 if (leveldir_current->readonly &&
1905 !strEqual(setup.player_name, "Artsoft"))
1906 Request("This level is read only!", REQ_CONFIRM);
1910 CloseDoor(DOOR_CLOSE_2);
1912 game_status = GAME_MODE_EDITOR;
1914 FadeSetEnterScreen();
1918 else if (pos == MAIN_CONTROL_INFO)
1922 CloseDoor(DOOR_CLOSE_2);
1924 game_status = GAME_MODE_INFO;
1925 info_mode = INFO_MODE_MAIN;
1927 ChangeViewportPropertiesIfNeeded();
1931 else if (pos == MAIN_CONTROL_GAME)
1935 StartGameActions(options.network, setup.autorecord, level.random_seed);
1937 else if (pos == MAIN_CONTROL_SETUP)
1941 CloseDoor(DOOR_CLOSE_2);
1943 game_status = GAME_MODE_SETUP;
1944 setup_mode = SETUP_MODE_MAIN;
1946 ChangeViewportPropertiesIfNeeded();
1950 else if (pos == MAIN_CONTROL_QUIT)
1952 SaveLevelSetup_LastSeries();
1953 SaveLevelSetup_SeriesInfo();
1955 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1956 game_status = GAME_MODE_QUIT;
1961 button_pressed_last = button_pressed;
1965 /* ========================================================================= */
1966 /* info screen functions */
1967 /* ========================================================================= */
1969 static struct TokenInfo *info_info;
1970 static int num_info_info; /* number of info entries shown on screen */
1971 static int max_info_info; /* total number of info entries in list */
1973 static void execInfoTitleScreen()
1975 info_mode = INFO_MODE_TITLE;
1980 static void execInfoElements()
1982 info_mode = INFO_MODE_ELEMENTS;
1987 static void execInfoMusic()
1989 info_mode = INFO_MODE_MUSIC;
1994 static void execInfoCredits()
1996 info_mode = INFO_MODE_CREDITS;
2001 static void execInfoProgram()
2003 info_mode = INFO_MODE_PROGRAM;
2008 static void execInfoVersion()
2010 info_mode = INFO_MODE_VERSION;
2015 static void execInfoLevelSet()
2017 info_mode = INFO_MODE_LEVELSET;
2022 static void execExitInfo()
2024 game_status = GAME_MODE_MAIN;
2029 static struct TokenInfo info_info_main[] =
2031 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2032 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2033 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2034 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2035 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2036 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2037 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2038 { TYPE_EMPTY, NULL, "" },
2039 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2044 static int getMenuTextFont(int type)
2046 if (type & (TYPE_SWITCH |
2058 static struct TokenInfo *setup_info;
2059 static struct TokenInfo setup_info_input[];
2061 static struct TokenInfo *menu_info;
2063 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2064 int screen_pos, int menu_info_pos_raw,
2067 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2068 struct TokenInfo *ti = &token_info[pos];
2069 int xpos = MENU_SCREEN_START_XPOS;
2070 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2071 int font_nr = getMenuTextFont(ti->type);
2073 if (token_info == setup_info_input)
2074 font_nr = FONT_MENU_1;
2077 font_nr = FONT_ACTIVE(font_nr);
2079 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2081 if (ti->type & ~TYPE_SKIP_ENTRY)
2082 drawCursor(screen_pos, active);
2085 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2088 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2091 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2094 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2097 static char *screen_mode_text;
2098 static char *window_size_text;
2099 static char *scaling_type_text;
2101 static void drawSetupValue(int, int);
2103 static void drawMenuInfoList(int first_entry, int num_page_entries,
2104 int max_page_entries)
2108 if (first_entry + num_page_entries > max_page_entries)
2111 clearMenuListArea();
2113 for (i = 0; i < num_page_entries; i++)
2115 int menu_info_pos = first_entry + i;
2116 struct TokenInfo *si = &menu_info[menu_info_pos];
2117 void *value_ptr = si->value;
2119 /* set some entries to "unchangeable" according to other variables */
2120 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2121 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2122 (value_ptr == &setup.sound_music && !audio.music_available) ||
2123 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2124 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2125 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2126 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2127 si->type |= TYPE_GHOSTED;
2129 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2130 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2131 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2132 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2133 else if (si->type & ~TYPE_SKIP_ENTRY)
2134 initCursor(i, IMG_MENU_BUTTON);
2136 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2138 if (si->type & TYPE_VALUE &&
2139 menu_info == setup_info)
2140 drawSetupValue(i, menu_info_pos);
2144 static void DrawInfoScreen_Main()
2146 int fade_mask = REDRAW_FIELD;
2149 if (redraw_mask & REDRAW_ALL)
2150 fade_mask = REDRAW_ALL;
2152 if (CheckIfGlobalBorderHasChanged())
2153 fade_mask = REDRAW_ALL;
2157 FreeScreenGadgets();
2158 CreateScreenGadgets();
2160 CloseDoor(DOOR_CLOSE_2);
2162 /* (needed after displaying title screens which disable auto repeat) */
2163 KeyboardAutoRepeatOn();
2165 FadeSetLeaveScreen();
2169 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2173 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2175 info_info = info_info_main;
2177 // determine maximal number of info entries that can be displayed on screen
2179 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2182 // determine maximal number of info entries available for menu of info screen
2184 for (i = 0; info_info[i].type != 0; i++)
2187 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2189 MapScreenGadgets(max_info_info);
2194 DrawMaskedBorder(fade_mask);
2201 static void changeSetupValue(int, int, int);
2203 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2204 int mode, int num_page_entries, int max_page_entries)
2206 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2207 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2208 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2209 int *num_page_entries_last = num_page_entries_all_last[game_status];
2210 int *choice_store = choice_stores[game_status];
2211 int *first_entry_store = first_entry_stores[game_status];
2212 int choice = choice_store[mode]; /* starts with 0 */
2213 int first_entry = first_entry_store[mode]; /* starts with 0 */
2215 int y = choice - first_entry;
2217 boolean position_set_by_scrollbar = (dx == 999);
2218 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2221 if (button == MB_MENU_INITIALIZE)
2223 // check if number of menu page entries has changed (may happen by change
2224 // of custom artwork definition value for 'list_size' for this menu screen)
2225 // (in this case, the last menu position most probably has to be corrected)
2226 if (num_page_entries != num_page_entries_last[mode])
2228 choice_store[mode] = first_entry_store[mode] = 0;
2230 choice = first_entry = 0;
2233 num_page_entries_last[mode] = num_page_entries;
2236 /* advance to first valid menu entry */
2237 while (choice < num_page_entries &&
2238 menu_info[choice].type & TYPE_SKIP_ENTRY)
2241 if (position_set_by_scrollbar)
2242 first_entry = first_entry_store[mode] = dy;
2244 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2245 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2247 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2249 if (choice < first_entry)
2251 choice = first_entry;
2253 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2256 else if (choice > first_entry + num_page_entries - 1)
2258 choice = first_entry + num_page_entries - 1;
2260 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2264 choice_store[mode] = choice;
2266 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2270 else if (button == MB_MENU_LEAVE)
2272 PlaySound(SND_MENU_ITEM_SELECTING);
2274 for (i = 0; i < max_page_entries; i++)
2276 if (menu_info[i].type & TYPE_LEAVE_MENU)
2278 void (*menu_callback_function)(void) = menu_info[i].value;
2282 menu_callback_function();
2284 break; /* absolutely needed because function changes 'menu_info'! */
2291 if (mx || my) /* mouse input */
2293 x = (mx - mSX) / 32;
2294 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2296 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2298 /* move cursor instead of scrolling when already at start/end of list */
2299 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2301 else if (dy == +1 * SCROLL_LINE &&
2302 first_entry + num_page_entries == max_page_entries)
2305 /* handle scrolling screen one line or page */
2307 y + dy > num_page_entries - 1)
2309 boolean redraw = FALSE;
2311 if (ABS(dy) == SCROLL_PAGE)
2312 step = num_page_entries - 1;
2314 if (dy < 0 && first_entry > 0)
2316 /* scroll page/line up */
2318 first_entry -= step;
2319 if (first_entry < 0)
2324 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2326 /* scroll page/line down */
2328 first_entry += step;
2329 if (first_entry + num_page_entries > max_page_entries)
2330 first_entry = MAX(0, max_page_entries - num_page_entries);
2337 choice += first_entry - first_entry_store[mode];
2339 if (choice < first_entry)
2341 choice = first_entry;
2343 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2346 else if (choice > first_entry + num_page_entries - 1)
2348 choice = first_entry + num_page_entries - 1;
2350 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2353 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2357 if (choice < first_entry ||
2358 choice > first_entry + num_page_entries - 1)
2359 first_entry += SIGN(dy);
2362 first_entry_store[mode] = first_entry;
2363 choice_store[mode] = choice;
2365 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2367 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2369 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2370 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2378 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2380 if (menu_info[choice].type & menu_navigation_type ||
2381 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2382 menu_info[choice].type & TYPE_YES_NO_AUTO)
2383 button = MB_MENU_CHOICE;
2388 /* jump to next non-empty menu entry (up or down) */
2389 while (first_entry + y > 0 &&
2390 first_entry + y < max_page_entries - 1 &&
2391 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2394 if (!IN_VIS_MENU(x, y))
2396 choice += y - y_old;
2398 if (choice < first_entry)
2399 first_entry = choice;
2400 else if (choice > first_entry + num_page_entries - 1)
2401 first_entry = choice - num_page_entries + 1;
2403 if (first_entry >= 0 &&
2404 first_entry + num_page_entries <= max_page_entries)
2406 first_entry_store[mode] = first_entry;
2408 if (choice < first_entry)
2409 choice = first_entry;
2410 else if (choice > first_entry + num_page_entries - 1)
2411 choice = first_entry + num_page_entries - 1;
2413 choice_store[mode] = choice;
2415 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2417 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2419 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2420 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2427 if (!anyScrollbarGadgetActive() &&
2428 IN_VIS_MENU(x, y) &&
2429 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2430 y >= 0 && y < num_page_entries)
2434 if (first_entry + y != choice &&
2435 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2437 PlaySound(SND_MENU_ITEM_ACTIVATING);
2439 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2440 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2442 choice = choice_store[mode] = first_entry + y;
2445 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2447 PlaySound(SND_MENU_ITEM_SELECTING);
2449 /* when selecting key headline, execute function for key value change */
2450 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2451 menu_info[first_entry + y + 1].type & TYPE_KEY)
2454 /* when selecting string value, execute function for list selection */
2455 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2456 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2459 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2461 void (*menu_callback_function)(void) =
2462 menu_info[first_entry + y].value;
2464 FadeSetFromType(menu_info[first_entry + y].type);
2466 menu_callback_function();
2468 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2469 menu_info == setup_info)
2471 changeSetupValue(y, first_entry + y, dx);
2477 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2479 menu_info = info_info;
2481 HandleMenuScreen(mx, my, dx, dy, button,
2482 info_mode, num_info_info, max_info_info);
2485 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2487 int ystart1 = mSY - SY + 100;
2488 int ystart2 = mSY - SY + 150;
2489 int ybottom = mSY - SY + SYSIZE - 20;
2491 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2493 FadeOut(REDRAW_FIELD);
2498 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2499 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2501 DrawTextSCentered(ybottom, FONT_TEXT_4,
2502 "Press any key or button for info menu");
2504 FadeIn(REDRAW_FIELD);
2507 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2509 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2510 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2511 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2512 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2513 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2514 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2515 int ystep = MENU_SCREEN_INFO_YSTEP;
2516 int element, action, direction;
2524 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2525 infoscreen_step[i] = infoscreen_frame[i] = 0;
2530 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2532 DrawTextSCentered(ybottom, FONT_TEXT_4,
2533 "Press any key or button for next page");
2539 while (helpanim_info[j].element != HELPANIM_LIST_END)
2541 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2546 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2555 j += infoscreen_step[i - start];
2557 element = helpanim_info[j].element;
2558 action = helpanim_info[j].action;
2559 direction = helpanim_info[j].direction;
2562 element = EL_UNKNOWN;
2564 if (action != -1 && direction != -1)
2565 graphic = el_act_dir2img(element, action, direction);
2566 else if (action != -1)
2567 graphic = el_act2img(element, action);
2568 else if (direction != -1)
2569 graphic = el_dir2img(element, direction);
2571 graphic = el2img(element);
2573 delay = helpanim_info[j++].delay;
2578 if (infoscreen_frame[i - start] == 0)
2581 infoscreen_frame[i - start] = delay - 1;
2585 sync_frame = delay - infoscreen_frame[i - start];
2586 infoscreen_frame[i - start]--;
2589 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2591 if (!infoscreen_frame[i - start])
2592 infoscreen_step[i - start] = 0;
2596 if (!infoscreen_frame[i - start])
2597 infoscreen_step[i - start]++;
2598 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2604 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2606 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2607 graphic, sync_frame, USE_MASKING);
2610 DrawInfoScreen_HelpText(element, action, direction, i - start);
2615 redraw_mask |= REDRAW_FIELD;
2620 static char *getHelpText(int element, int action, int direction)
2622 char token[MAX_LINE_LEN];
2624 strcpy(token, element_info[element].token_name);
2627 strcat(token, element_action_info[action].suffix);
2629 if (direction != -1)
2630 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2632 return getHashEntry(helptext_info, token);
2635 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2637 int font_nr = FONT_INFO_ELEMENTS;
2638 int font_width = getFontWidth(font_nr);
2639 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2640 int sy = mSY + 65 + 2 * 32 + 1;
2641 int ystep = TILEY + 4;
2642 int pad_x = sx - SX;
2643 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2644 int max_lines_per_text = 2;
2647 if (action != -1 && direction != -1) /* element.action.direction */
2648 text = getHelpText(element, action, direction);
2650 if (text == NULL && action != -1) /* element.action */
2651 text = getHelpText(element, action, -1);
2653 if (text == NULL && direction != -1) /* element.direction */
2654 text = getHelpText(element, -1, direction);
2656 if (text == NULL) /* base element */
2657 text = getHelpText(element, -1, -1);
2659 if (text == NULL) /* not found */
2660 text = "No description available";
2662 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2663 sy += getFontHeight(font_nr) / 2;
2665 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2666 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2667 TRUE, FALSE, FALSE);
2670 void DrawInfoScreen_TitleScreen()
2672 game_status_last_screen = GAME_MODE_INFO;
2673 game_status = GAME_MODE_TITLE;
2678 void HandleInfoScreen_TitleScreen(int button)
2680 HandleTitleScreen(0, 0, 0, 0, button);
2683 void DrawInfoScreen_Elements()
2685 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2687 FadeOut(REDRAW_FIELD);
2692 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2694 FadeIn(REDRAW_FIELD);
2699 void HandleInfoScreen_Elements(int button)
2701 static unsigned int info_delay = 0;
2702 static int num_anims;
2703 static int num_pages;
2705 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2708 if (button == MB_MENU_INITIALIZE)
2710 boolean new_element = TRUE;
2714 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2716 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2718 else if (new_element)
2721 new_element = FALSE;
2725 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2729 if (button == MB_MENU_LEAVE)
2731 PlaySound(SND_MENU_ITEM_SELECTING);
2733 info_mode = INFO_MODE_MAIN;
2738 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2740 if (button != MB_MENU_INITIALIZE)
2742 PlaySound(SND_MENU_ITEM_SELECTING);
2747 if (page >= num_pages)
2749 FadeSoundsAndMusic();
2751 info_mode = INFO_MODE_MAIN;
2758 FadeSetNextScreen();
2760 if (button != MB_MENU_INITIALIZE)
2761 FadeOut(REDRAW_FIELD);
2763 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2765 if (button != MB_MENU_INITIALIZE)
2766 FadeIn(REDRAW_FIELD);
2770 if (DelayReached(&info_delay, GameFrameDelay))
2771 if (page < num_pages)
2772 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2774 PlayMenuSoundIfLoop();
2778 void DrawInfoScreen_Music()
2780 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2782 FadeOut(REDRAW_FIELD);
2789 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2791 FadeIn(REDRAW_FIELD);
2794 void HandleInfoScreen_Music(int button)
2796 static struct MusicFileInfo *list = NULL;
2797 int ystart1 = mSY - SY + 100;
2798 int ystart2 = mSY - SY + 150;
2799 int ybottom = mSY - SY + SYSIZE - 20;
2802 if (button == MB_MENU_INITIALIZE)
2804 list = music_file_info;
2808 FadeSoundsAndMusic();
2813 DrawTextSCentered(ystart1, FONT_TEXT_1,
2814 "No music info for this level set.");
2816 DrawTextSCentered(ybottom, FONT_TEXT_4,
2817 "Press any key or button for info menu");
2823 if (button == MB_MENU_LEAVE)
2825 PlaySound(SND_MENU_ITEM_SELECTING);
2827 FadeSoundsAndMusic();
2829 info_mode = INFO_MODE_MAIN;
2834 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2838 if (button != MB_MENU_INITIALIZE)
2840 PlaySound(SND_MENU_ITEM_SELECTING);
2848 FadeSoundsAndMusic();
2850 info_mode = INFO_MODE_MAIN;
2856 FadeSoundsAndMusic();
2858 if (list != music_file_info)
2859 FadeSetNextScreen();
2861 if (button != MB_MENU_INITIALIZE)
2862 FadeOut(REDRAW_FIELD);
2869 int sound = list->music;
2871 if (sound_info[sound].loop)
2872 PlaySoundLoop(sound);
2876 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2880 PlayMusic(list->music);
2882 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2885 if (!strEqual(list->title, UNKNOWN_NAME))
2887 if (!strEqual(list->title_header, UNKNOWN_NAME))
2888 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2890 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2893 if (!strEqual(list->artist, UNKNOWN_NAME))
2895 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2896 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2898 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2900 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2903 if (!strEqual(list->album, UNKNOWN_NAME))
2905 if (!strEqual(list->album_header, UNKNOWN_NAME))
2906 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2908 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2910 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2913 if (!strEqual(list->year, UNKNOWN_NAME))
2915 if (!strEqual(list->year_header, UNKNOWN_NAME))
2916 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2918 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2920 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2923 DrawTextSCentered(ybottom, FONT_TEXT_4,
2924 "Press any key or button for next page");
2926 if (button != MB_MENU_INITIALIZE)
2927 FadeIn(REDRAW_FIELD);
2930 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2931 PlaySoundLoop(list->music);
2934 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2936 int ystart1 = mSY - SY + 100;
2937 int ystart2 = mSY - SY + 150;
2938 int ybottom = mSY - SY + SYSIZE - 20;
2944 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2948 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2949 "Special thanks to");
2950 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2952 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2954 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2955 "\"Boulder Dash\"");
2956 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2958 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2960 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2962 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2963 "First Star Software");
2965 else if (screen_nr == 1)
2967 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2968 "Special thanks to");
2969 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2970 "Klaus Heinz & Volker Wertich");
2971 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2973 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2974 "\"Emerald Mine\"");
2975 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2977 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2979 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2981 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2984 else if (screen_nr == 2)
2986 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2987 "Special thanks to");
2988 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2989 "Michael Stopp & Philip Jespersen");
2990 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2992 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2994 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2996 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2998 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3000 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3001 "Digital Integration");
3003 else if (screen_nr == 3)
3005 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3006 "Special thanks to");
3007 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3008 "Hiroyuki Imabayashi");
3009 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3011 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3013 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3015 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3017 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3019 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3022 else if (screen_nr == 4)
3024 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3025 "Special thanks to");
3026 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3028 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3030 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3031 "J\xfcrgen Bonhagen");
3032 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3033 "for the continuous creation");
3034 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3035 "of outstanding level sets");
3037 else if (screen_nr == 5)
3039 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3041 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3043 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3044 "for ideas and inspiration by");
3045 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3048 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3050 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3052 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3053 "for ideas and inspiration by");
3054 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3057 else if (screen_nr == 6)
3059 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3061 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3064 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3065 "for the code base used for the");
3066 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3067 "native Emerald Mine engine");
3069 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3070 "for the new Emerald Mine engine");
3073 else if (screen_nr == 7)
3075 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3077 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3079 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3080 "for the initial DOS port");
3082 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3084 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3086 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3087 "for some additional toons");
3089 else if (screen_nr == 8)
3091 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3092 "And not to forget:");
3093 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3095 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3096 "All those who contributed");
3097 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3098 "levels to this game");
3099 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3103 DrawTextSCentered(ybottom, FONT_TEXT_4,
3104 "Press any key or button for next page");
3107 void DrawInfoScreen_Credits()
3109 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3111 FadeSoundsAndMusic();
3113 FadeOut(REDRAW_FIELD);
3115 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3117 FadeIn(REDRAW_FIELD);
3120 void HandleInfoScreen_Credits(int button)
3122 static int screen_nr = 0;
3123 int num_screens = 9;
3125 if (button == MB_MENU_INITIALIZE)
3129 // DrawInfoScreen_CreditsScreen(screen_nr);
3132 if (button == MB_MENU_LEAVE)
3134 PlaySound(SND_MENU_ITEM_SELECTING);
3136 info_mode = INFO_MODE_MAIN;
3141 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3143 if (button != MB_MENU_INITIALIZE)
3145 PlaySound(SND_MENU_ITEM_SELECTING);
3150 if (screen_nr >= num_screens)
3152 FadeSoundsAndMusic();
3154 info_mode = INFO_MODE_MAIN;
3161 FadeSetNextScreen();
3163 if (button != MB_MENU_INITIALIZE)
3164 FadeOut(REDRAW_FIELD);
3166 DrawInfoScreen_CreditsScreen(screen_nr);
3168 if (button != MB_MENU_INITIALIZE)
3169 FadeIn(REDRAW_FIELD);
3173 PlayMenuSoundIfLoop();
3177 void DrawInfoScreen_Program()
3179 int ystart1 = mSY - SY + 100;
3180 int ystart2 = mSY - SY + 150;
3181 int ybottom = mSY - SY + SYSIZE - 20;
3184 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3186 FadeOut(REDRAW_FIELD);
3191 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3193 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3194 "This game is Freeware!");
3195 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3196 "If you like it, send e-mail to:");
3197 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3198 setup.internal.program_email);
3199 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3200 "More information and levels:");
3201 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3202 setup.internal.program_website);
3203 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3204 "If you have created new levels,");
3205 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3206 "send them to me to include them!");
3207 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3210 DrawTextSCentered(ybottom, FONT_TEXT_4,
3211 "Press any key or button for info menu");
3213 FadeIn(REDRAW_FIELD);
3216 void HandleInfoScreen_Program(int button)
3218 if (button == MB_MENU_LEAVE)
3220 PlaySound(SND_MENU_ITEM_SELECTING);
3222 info_mode = INFO_MODE_MAIN;
3227 else if (button == MB_MENU_CHOICE)
3229 PlaySound(SND_MENU_ITEM_SELECTING);
3231 FadeSoundsAndMusic();
3233 info_mode = INFO_MODE_MAIN;
3238 PlayMenuSoundIfLoop();
3242 void DrawInfoScreen_Version()
3244 int font_header = FONT_TEXT_3;
3245 int font_text = FONT_TEXT_2;
3246 int xstep = getFontWidth(font_text);
3247 int ystep = getFontHeight(font_text);
3248 int ystart1 = mSY - SY + 100;
3249 int ystart2 = mSY - SY + 150;
3250 int ybottom = mSY - SY + SYSIZE - 20;
3251 int xstart1 = mSX - SX + 2 * xstep;
3252 int xstart2 = mSX - SX + 18 * xstep;
3253 int xstart3 = mSX - SX + 28 * xstep;
3254 SDL_version sdl_version_compiled;
3255 const SDL_version *sdl_version_linked;
3256 int driver_name_len = 10;
3257 #if defined(TARGET_SDL2)
3258 SDL_version sdl_version_linked_ext;
3259 const char *driver_name = NULL;
3261 char driver_name[driver_name_len];
3264 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3266 FadeOut(REDRAW_FIELD);
3271 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3273 DrawTextF(xstart1, ystart2, font_header, "Name");
3274 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3277 DrawTextF(xstart1, ystart2, font_header, "Version");
3278 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3281 DrawTextF(xstart1, ystart2, font_header, "Platform");
3282 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3285 DrawTextF(xstart1, ystart2, font_header, "Target");
3286 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3289 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3290 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3292 ystart2 += 3 * ystep;
3293 DrawTextF(xstart1, ystart2, font_header, "Library");
3294 DrawTextF(xstart2, ystart2, font_header, "compiled");
3295 DrawTextF(xstart3, ystart2, font_header, "linked");
3297 SDL_VERSION(&sdl_version_compiled);
3298 #if defined(TARGET_SDL2)
3299 SDL_GetVersion(&sdl_version_linked_ext);
3300 sdl_version_linked = &sdl_version_linked_ext;
3302 sdl_version_linked = SDL_Linked_Version();
3305 ystart2 += 2 * ystep;
3306 DrawTextF(xstart1, ystart2, font_text, "SDL");
3307 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3308 sdl_version_compiled.major,
3309 sdl_version_compiled.minor,
3310 sdl_version_compiled.patch);
3311 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3312 sdl_version_linked->major,
3313 sdl_version_linked->minor,
3314 sdl_version_linked->patch);
3316 SDL_IMAGE_VERSION(&sdl_version_compiled);
3317 sdl_version_linked = IMG_Linked_Version();
3320 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3321 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3322 sdl_version_compiled.major,
3323 sdl_version_compiled.minor,
3324 sdl_version_compiled.patch);
3325 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3326 sdl_version_linked->major,
3327 sdl_version_linked->minor,
3328 sdl_version_linked->patch);
3330 SDL_MIXER_VERSION(&sdl_version_compiled);
3331 sdl_version_linked = Mix_Linked_Version();
3334 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3335 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3336 sdl_version_compiled.major,
3337 sdl_version_compiled.minor,
3338 sdl_version_compiled.patch);
3339 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3340 sdl_version_linked->major,
3341 sdl_version_linked->minor,
3342 sdl_version_linked->patch);
3344 SDL_NET_VERSION(&sdl_version_compiled);
3345 sdl_version_linked = SDLNet_Linked_Version();
3348 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3349 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3350 sdl_version_compiled.major,
3351 sdl_version_compiled.minor,
3352 sdl_version_compiled.patch);
3353 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3354 sdl_version_linked->major,
3355 sdl_version_linked->minor,
3356 sdl_version_linked->patch);
3358 ystart2 += 3 * ystep;
3359 DrawTextF(xstart1, ystart2, font_header, "Driver");
3360 DrawTextF(xstart2, ystart2, font_header, "Requested");
3361 DrawTextF(xstart3, ystart2, font_header, "Used");
3363 #if defined(TARGET_SDL2)
3364 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3366 SDL_VideoDriverName(driver_name, driver_name_len);
3369 ystart2 += 2 * ystep;
3370 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3371 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3372 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3374 #if defined(TARGET_SDL2)
3375 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3377 SDL_AudioDriverName(driver_name, driver_name_len);
3381 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3382 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3383 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3385 DrawTextSCentered(ybottom, FONT_TEXT_4,
3386 "Press any key or button for info menu");
3388 FadeIn(REDRAW_FIELD);
3391 void HandleInfoScreen_Version(int button)
3393 if (button == MB_MENU_LEAVE)
3395 PlaySound(SND_MENU_ITEM_SELECTING);
3397 info_mode = INFO_MODE_MAIN;
3402 else if (button == MB_MENU_CHOICE)
3404 PlaySound(SND_MENU_ITEM_SELECTING);
3406 FadeSoundsAndMusic();
3408 info_mode = INFO_MODE_MAIN;
3413 PlayMenuSoundIfLoop();
3417 void DrawInfoScreen_LevelSet()
3419 struct TitleMessageInfo *tmi = &readme;
3420 char *filename = getLevelSetInfoFilename();
3421 char *title = "Level Set Information:";
3422 int ystart1 = mSY - SY + 100;
3423 int ybottom = mSY - SY + SYSIZE - 20;
3425 if (filename == NULL)
3427 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3432 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3434 FadeOut(REDRAW_FIELD);
3439 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3441 /* if x position set to "-1", automatically determine by playfield width */
3443 tmi->x = SXSIZE / 2;
3445 /* if y position set to "-1", use static default value */
3449 /* if width set to "-1", automatically determine by playfield width */
3450 if (tmi->width == -1)
3451 tmi->width = SXSIZE - 2 * TILEX;
3453 /* if height set to "-1", automatically determine by playfield height */
3454 if (tmi->height == -1)
3455 tmi->height = SYSIZE - 20 - tmi->y - 10;
3457 /* if chars set to "-1", automatically determine by text and font width */
3458 if (tmi->chars == -1)
3459 tmi->chars = tmi->width / getFontWidth(tmi->font);
3461 tmi->width = tmi->chars * getFontWidth(tmi->font);
3463 /* if lines set to "-1", automatically determine by text and font height */
3464 if (tmi->lines == -1)
3465 tmi->lines = tmi->height / getFontHeight(tmi->font);
3467 tmi->height = tmi->lines * getFontHeight(tmi->font);
3469 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3470 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3471 tmi->autowrap, tmi->centered, tmi->parse_comments);
3473 DrawTextSCentered(ybottom, FONT_TEXT_4,
3474 "Press any key or button for info menu");
3476 FadeIn(REDRAW_FIELD);
3479 void HandleInfoScreen_LevelSet(int button)
3481 if (button == MB_MENU_LEAVE)
3483 PlaySound(SND_MENU_ITEM_SELECTING);
3485 info_mode = INFO_MODE_MAIN;
3490 else if (button == MB_MENU_CHOICE)
3492 PlaySound(SND_MENU_ITEM_SELECTING);
3494 FadeSoundsAndMusic();
3496 info_mode = INFO_MODE_MAIN;
3501 PlayMenuSoundIfLoop();
3505 static void DrawInfoScreen()
3507 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3509 if (info_mode == INFO_MODE_TITLE)
3510 DrawInfoScreen_TitleScreen();
3511 else if (info_mode == INFO_MODE_ELEMENTS)
3512 DrawInfoScreen_Elements();
3513 else if (info_mode == INFO_MODE_MUSIC)
3514 DrawInfoScreen_Music();
3515 else if (info_mode == INFO_MODE_CREDITS)
3516 DrawInfoScreen_Credits();
3517 else if (info_mode == INFO_MODE_PROGRAM)
3518 DrawInfoScreen_Program();
3519 else if (info_mode == INFO_MODE_VERSION)
3520 DrawInfoScreen_Version();
3521 else if (info_mode == INFO_MODE_LEVELSET)
3522 DrawInfoScreen_LevelSet();
3524 DrawInfoScreen_Main();
3526 if (info_mode != INFO_MODE_MAIN &&
3527 info_mode != INFO_MODE_TITLE &&
3528 info_mode != INFO_MODE_MUSIC)
3535 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3537 if (info_mode == INFO_MODE_TITLE)
3538 HandleInfoScreen_TitleScreen(button);
3539 else if (info_mode == INFO_MODE_ELEMENTS)
3540 HandleInfoScreen_Elements(button);
3541 else if (info_mode == INFO_MODE_MUSIC)
3542 HandleInfoScreen_Music(button);
3543 else if (info_mode == INFO_MODE_CREDITS)
3544 HandleInfoScreen_Credits(button);
3545 else if (info_mode == INFO_MODE_PROGRAM)
3546 HandleInfoScreen_Program(button);
3547 else if (info_mode == INFO_MODE_VERSION)
3548 HandleInfoScreen_Version(button);
3549 else if (info_mode == INFO_MODE_LEVELSET)
3550 HandleInfoScreen_LevelSet(button);
3552 HandleInfoScreen_Main(mx, my, dx, dy, button);
3556 /* ========================================================================= */
3557 /* type name functions */
3558 /* ========================================================================= */
3560 void HandleTypeName(int newxpos, Key key)
3562 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3563 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3564 struct TextPosInfo *pos = mci->pos_input;
3565 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3566 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3567 static int xpos = 0;
3568 int font_nr = pos->font;
3569 int font_active_nr = FONT_ACTIVE(font_nr);
3570 int font_width = getFontWidth(font_active_nr);
3571 char key_char = getValidConfigValueChar(getCharFromKey(key));
3572 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3573 boolean is_active = TRUE;
3575 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3579 strcpy(last_player_name, setup.player_name);
3583 #if defined(TARGET_SDL2)
3584 SDL_StartTextInput();
3587 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3589 setup.player_name[xpos] = key_char;
3590 setup.player_name[xpos + 1] = 0;
3594 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3598 setup.player_name[xpos] = 0;
3600 else if (key == KSYM_Return && xpos > 0)
3606 game_status = GAME_MODE_MAIN;
3608 else if (key == KSYM_Escape)
3610 strcpy(setup.player_name, last_player_name);
3614 game_status = GAME_MODE_MAIN;
3619 pos->width = (strlen(setup.player_name) + 1) * font_width;
3620 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3622 DrawText(startx, starty, setup.player_name, font_active_nr);
3623 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3627 pos->width = strlen(setup.player_name) * font_width;
3628 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3630 DrawText(startx, starty, setup.player_name, font_nr);
3632 #if defined(TARGET_SDL2)
3633 SDL_StopTextInput();
3639 /* ========================================================================= */
3640 /* tree menu functions */
3641 /* ========================================================================= */
3643 static void DrawChooseTree(TreeInfo **ti_ptr)
3645 int fade_mask = REDRAW_FIELD;
3647 if (CheckIfGlobalBorderHasChanged())
3648 fade_mask = REDRAW_ALL;
3650 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3652 game_status = GAME_MODE_MAIN;
3661 FreeScreenGadgets();
3662 CreateScreenGadgets();
3664 CloseDoor(DOOR_CLOSE_2);
3668 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3672 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3673 MapScreenTreeGadgets(*ti_ptr);
3675 DrawMaskedBorder(fade_mask);
3682 static void drawChooseTreeList(int first_entry, int num_page_entries,
3686 char *title_string = NULL;
3687 int yoffset_sets = MENU_TITLE1_YPOS;
3688 int yoffset_setup = 16;
3689 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3690 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3691 int last_game_status = game_status; /* save current game status */
3693 title_string = ti->infotext;
3695 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3697 clearMenuListArea();
3699 for (i = 0; i < num_page_entries; i++)
3701 TreeInfo *node, *node_first;
3702 int entry_pos = first_entry + i;
3703 int xpos = MENU_SCREEN_START_XPOS;
3704 int ypos = MENU_SCREEN_START_YPOS + i;
3705 int startx = mSX + xpos * 32;
3706 int starty = mSY + ypos * 32;
3707 int font_nr = FONT_TEXT_1;
3708 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3709 int startx_text = startx + font_xoffset;
3710 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3711 int text_size = startx_scrollbar - startx_text;
3712 int max_buffer_len = text_size / getFontWidth(font_nr);
3713 char buffer[max_buffer_len + 1];
3715 node_first = getTreeInfoFirstGroupEntry(ti);
3716 node = getTreeInfoFromPos(node_first, entry_pos);
3718 strncpy(buffer, node->name, max_buffer_len);
3719 buffer[max_buffer_len] = '\0';
3721 DrawText(startx, starty, buffer, font_nr + node->color);
3723 if (node->parent_link)
3724 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3725 else if (node->level_group)
3726 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3728 initCursor(i, IMG_MENU_BUTTON);
3731 game_status = last_game_status; /* restore current game status */
3733 redraw_mask |= REDRAW_FIELD;
3736 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3738 TreeInfo *node, *node_first;
3739 int x, last_redraw_mask = redraw_mask;
3740 int ypos = MENU_TITLE2_YPOS;
3741 int font_nr = FONT_TITLE_2;
3743 if (ti->type == TREE_TYPE_LEVEL_NR)
3744 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3746 if (ti->type != TREE_TYPE_LEVEL_DIR)
3749 node_first = getTreeInfoFirstGroupEntry(ti);
3750 node = getTreeInfoFromPos(node_first, entry_pos);
3752 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3754 if (node->parent_link)
3755 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3756 node->node_parent->name);
3757 else if (node->level_group)
3758 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3760 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3761 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3762 node->levels, (node->levels > 1 ? "levels" : "level"),
3765 /* let BackToFront() redraw only what is needed */
3766 redraw_mask = last_redraw_mask;
3767 for (x = 0; x < SCR_FIELDX; x++)
3768 MarkTileDirty(x, 1);
3771 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3774 TreeInfo *ti = *ti_ptr;
3776 int y = ti->cl_cursor;
3777 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3778 int num_entries = numTreeInfoInGroup(ti);
3779 int num_page_entries;
3780 int last_game_status = game_status; /* save current game status */
3781 boolean position_set_by_scrollbar = (dx == 999);
3783 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3784 num_page_entries = num_entries;
3786 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3788 game_status = last_game_status; /* restore current game status */
3790 if (button == MB_MENU_INITIALIZE)
3792 int num_entries = numTreeInfoInGroup(ti);
3793 int entry_pos = posTreeInfo(ti);
3795 if (ti->cl_first == -1)
3797 /* only on initialization */
3798 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3799 ti->cl_cursor = entry_pos - ti->cl_first;
3801 else if (ti->cl_cursor >= num_page_entries ||
3802 (num_entries > num_page_entries &&
3803 num_entries - ti->cl_first < num_page_entries))
3805 /* only after change of list size (by custom graphic configuration) */
3806 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3807 ti->cl_cursor = entry_pos - ti->cl_first;
3810 if (position_set_by_scrollbar)
3813 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3816 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3817 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3818 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3822 else if (button == MB_MENU_LEAVE)
3826 PlaySound(SND_MENU_ITEM_SELECTING);
3828 if (ti->node_parent)
3830 *ti_ptr = ti->node_parent;
3831 DrawChooseTree(ti_ptr);
3833 else if (game_status == GAME_MODE_SETUP)
3835 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3836 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3837 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3839 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3840 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3841 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3842 execSetupGraphics();
3843 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3844 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3845 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3847 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3848 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3849 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3856 if (game_status == GAME_MODE_LEVELNR)
3858 int new_level_nr = atoi(level_number_current->identifier);
3860 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3863 game_status = GAME_MODE_MAIN;
3871 if (mx || my) /* mouse input */
3873 int last_game_status = game_status; /* save current game status */
3875 x = (mx - mSX) / 32;
3876 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3878 game_status = last_game_status; /* restore current game status */
3880 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3882 /* move cursor instead of scrolling when already at start/end of list */
3883 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3885 else if (dy == +1 * SCROLL_LINE &&
3886 ti->cl_first + num_page_entries == num_entries)
3889 /* handle scrolling screen one line or page */
3890 if (ti->cl_cursor + dy < 0 ||
3891 ti->cl_cursor + dy > num_page_entries - 1)
3893 boolean redraw = FALSE;
3895 if (ABS(dy) == SCROLL_PAGE)
3896 step = num_page_entries - 1;
3898 if (dy < 0 && ti->cl_first > 0)
3900 /* scroll page/line up */
3902 ti->cl_first -= step;
3903 if (ti->cl_first < 0)
3908 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3910 /* scroll page/line down */
3912 ti->cl_first += step;
3913 if (ti->cl_first + num_page_entries > num_entries)
3914 ti->cl_first = MAX(0, num_entries - num_page_entries);
3921 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3922 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3923 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3925 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3932 /* handle moving cursor one line */
3933 y = ti->cl_cursor + dy;
3938 TreeInfo *node_first, *node_cursor;
3939 int entry_pos = ti->cl_first + y;
3941 node_first = getTreeInfoFirstGroupEntry(ti);
3942 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3944 if (node_cursor->node_group)
3948 PlaySound(SND_MENU_ITEM_SELECTING);
3950 node_cursor->cl_first = ti->cl_first;
3951 node_cursor->cl_cursor = ti->cl_cursor;
3952 *ti_ptr = node_cursor->node_group;
3953 DrawChooseTree(ti_ptr);
3958 else if (dx == -1 && ti->node_parent)
3962 PlaySound(SND_MENU_ITEM_SELECTING);
3964 *ti_ptr = ti->node_parent;
3965 DrawChooseTree(ti_ptr);
3970 if (!anyScrollbarGadgetActive() &&
3971 IN_VIS_MENU(x, y) &&
3972 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3973 y >= 0 && y < num_page_entries)
3977 if (y != ti->cl_cursor)
3979 PlaySound(SND_MENU_ITEM_ACTIVATING);
3981 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3982 drawChooseTreeCursor(y, TRUE);
3983 drawChooseTreeInfo(ti->cl_first + y, ti);
3990 TreeInfo *node_first, *node_cursor;
3991 int entry_pos = ti->cl_first + y;
3993 PlaySound(SND_MENU_ITEM_SELECTING);
3995 node_first = getTreeInfoFirstGroupEntry(ti);
3996 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3998 if (node_cursor->node_group)
4002 node_cursor->cl_first = ti->cl_first;
4003 node_cursor->cl_cursor = ti->cl_cursor;
4004 *ti_ptr = node_cursor->node_group;
4005 DrawChooseTree(ti_ptr);
4007 else if (node_cursor->parent_link)
4011 *ti_ptr = node_cursor->node_parent;
4012 DrawChooseTree(ti_ptr);
4018 node_cursor->cl_first = ti->cl_first;
4019 node_cursor->cl_cursor = ti->cl_cursor;
4020 *ti_ptr = node_cursor;
4022 if (ti->type == TREE_TYPE_LEVEL_DIR)
4024 LoadLevelSetup_SeriesInfo();
4026 SaveLevelSetup_LastSeries();
4027 SaveLevelSetup_SeriesInfo();
4031 if (game_status == GAME_MODE_SETUP)
4033 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4034 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4035 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4037 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4038 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4039 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4040 execSetupGraphics();
4041 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4042 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4043 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4045 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4046 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4047 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4054 if (game_status == GAME_MODE_LEVELNR)
4056 int new_level_nr = atoi(level_number_current->identifier);
4058 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4061 game_status = GAME_MODE_MAIN;
4070 void DrawChooseLevelSet()
4072 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4074 DrawChooseTree(&leveldir_current);
4080 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4082 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4085 void DrawChooseLevelNr()
4089 if (level_number != NULL)
4091 freeTreeInfo(level_number);
4093 level_number = NULL;
4096 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4098 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4099 char identifier[32], name[32];
4102 /* temporarily load level info to get level name */
4103 LoadLevelInfoOnly(i);
4105 ti->node_top = &level_number;
4106 ti->sort_priority = 10000 + value;
4107 ti->color = (level.no_valid_file ? FC_BLUE :
4108 LevelStats_getSolved(i) ? FC_GREEN :
4109 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4111 sprintf(identifier, "%d", value);
4112 sprintf(name, "%03d: %s", value,
4113 (level.no_valid_file ? "(no file)" : level.name));
4115 setString(&ti->identifier, identifier);
4116 setString(&ti->name, name);
4117 setString(&ti->name_sorting, name);
4119 pushTreeInfo(&level_number, ti);
4122 /* sort level number values to start with lowest level number */
4123 sortTreeInfo(&level_number);
4125 /* set current level number to current level number */
4126 level_number_current =
4127 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4129 /* if that also fails, set current level number to first available level */
4130 if (level_number_current == NULL)
4131 level_number_current = level_number;
4133 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4135 DrawChooseTree(&level_number_current);
4141 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4143 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4146 void DrawHallOfFame(int highlight_position)
4148 int fade_mask = REDRAW_FIELD;
4150 /* required before door position may be changed in next step */
4151 CloseDoor(DOOR_CLOSE_ALL);
4153 /* needed if different viewport properties defined for scores */
4154 ChangeViewportPropertiesIfNeeded();
4156 if (CheckIfGlobalBorderHasChanged())
4157 fade_mask = REDRAW_ALL;
4160 FadeSoundsAndMusic();
4162 /* (this is needed when called from GameEnd() after winning a game) */
4163 KeyboardAutoRepeatOn();
4166 /* (this is needed when called from GameEnd() after winning a game) */
4167 SetDrawDeactivationMask(REDRAW_NONE);
4168 SetDrawBackgroundMask(REDRAW_FIELD);
4170 if (highlight_position < 0)
4171 LoadScore(level_nr);
4173 FadeSetEnterScreen();
4182 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4184 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4186 DrawMaskedBorder(fade_mask);
4191 static void drawHallOfFameList(int first_entry, int highlight_position)
4195 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4198 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4199 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4200 "HighScores of Level %d", level_nr);
4202 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4204 int entry = first_entry + i;
4205 boolean active = (entry == highlight_position);
4206 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4207 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4208 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4209 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4210 int dx1 = 3 * getFontWidth(font_nr1);
4211 int dx2 = dx1 + getFontWidth(font_nr1);
4212 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4213 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4214 int sy = mSY + 64 + i * 32;
4216 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4217 DrawText(mSX + dx1, sy, ".", font_nr1);
4219 for (j = 0; j < num_dots; j++)
4220 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4222 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4223 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4225 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4228 redraw_mask |= REDRAW_FIELD;
4231 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4233 static int first_entry = 0;
4234 static int highlight_position = 0;
4235 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4237 if (button == MB_MENU_INITIALIZE)
4240 highlight_position = mx;
4241 drawHallOfFameList(first_entry, highlight_position);
4246 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4247 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4251 if (first_entry > 0)
4253 first_entry -= step;
4254 if (first_entry < 0)
4257 drawHallOfFameList(first_entry, highlight_position);
4262 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4264 first_entry += step;
4265 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4266 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4268 drawHallOfFameList(first_entry, highlight_position);
4271 else if (button == MB_MENU_LEAVE)
4273 PlaySound(SND_MENU_ITEM_SELECTING);
4275 FadeSound(SND_BACKGROUND_SCORES);
4277 game_status = GAME_MODE_MAIN;
4281 else if (button == MB_MENU_CHOICE)
4283 PlaySound(SND_MENU_ITEM_SELECTING);
4285 FadeSound(SND_BACKGROUND_SCORES);
4287 game_status = GAME_MODE_MAIN;
4292 if (game_status == GAME_MODE_SCORES)
4293 PlayMenuSoundIfLoop();
4297 /* ========================================================================= */
4298 /* setup screen functions */
4299 /* ========================================================================= */
4301 static struct TokenInfo *setup_info;
4302 static int num_setup_info; /* number of setup entries shown on screen */
4303 static int max_setup_info; /* total number of setup entries in list */
4305 static char *screen_mode_text;
4306 static char *window_size_text;
4307 static char *scaling_type_text;
4308 static char *scroll_delay_text;
4309 static char *snapshot_mode_text;
4310 static char *game_speed_text;
4311 static char *graphics_set_name;
4312 static char *sounds_set_name;
4313 static char *music_set_name;
4314 static char *volume_simple_text;
4315 static char *volume_loops_text;
4316 static char *volume_music_text;
4317 static char *touch_controls_text;
4318 static char *move_distance_text;
4319 static char *drop_distance_text;
4321 static void execSetupMain()
4323 setup_mode = SETUP_MODE_MAIN;
4328 static void execSetupGame_setGameSpeeds()
4330 if (game_speeds == NULL)
4334 for (i = 0; game_speeds_list[i].value != -1; i++)
4336 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4337 char identifier[32], name[32];
4338 int value = game_speeds_list[i].value;
4339 char *text = game_speeds_list[i].text;
4341 ti->node_top = &game_speeds;
4342 ti->sort_priority = 10000 - value;
4344 sprintf(identifier, "%d", value);
4345 sprintf(name, "%s", text);
4347 setString(&ti->identifier, identifier);
4348 setString(&ti->name, name);
4349 setString(&ti->name_sorting, name);
4350 setString(&ti->infotext, "Game Speed");
4352 pushTreeInfo(&game_speeds, ti);
4355 /* sort game speed values to start with slowest game speed */
4356 sortTreeInfo(&game_speeds);
4358 /* set current game speed to configured game speed value */
4359 game_speed_current =
4360 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4362 /* if that fails, set current game speed to reliable default value */
4363 if (game_speed_current == NULL)
4364 game_speed_current =
4365 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4367 /* if that also fails, set current game speed to first available speed */
4368 if (game_speed_current == NULL)
4369 game_speed_current = game_speeds;
4372 setup.game_frame_delay = atoi(game_speed_current->identifier);
4374 /* needed for displaying game speed text instead of identifier */
4375 game_speed_text = game_speed_current->name;
4378 static void execSetupGame_setScrollDelays()
4380 if (scroll_delays == NULL)
4384 for (i = 0; scroll_delays_list[i].value != -1; i++)
4386 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4387 char identifier[32], name[32];
4388 int value = scroll_delays_list[i].value;
4389 char *text = scroll_delays_list[i].text;
4391 ti->node_top = &scroll_delays;
4392 ti->sort_priority = value;
4394 sprintf(identifier, "%d", value);
4395 sprintf(name, "%s", text);
4397 setString(&ti->identifier, identifier);
4398 setString(&ti->name, name);
4399 setString(&ti->name_sorting, name);
4400 setString(&ti->infotext, "Scaling Type");
4402 pushTreeInfo(&scroll_delays, ti);
4405 /* sort scaling type values to start with lowest scaling type value */
4406 sortTreeInfo(&scroll_delays);
4408 /* set current scaling type value to configured scaling type value */
4409 scroll_delay_current =
4410 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4412 /* if that fails, set current scaling type to reliable default value */
4413 if (scroll_delay_current == NULL)
4414 scroll_delay_current =
4415 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4417 /* if that also fails, set current scaling type to first available value */
4418 if (scroll_delay_current == NULL)
4419 scroll_delay_current = scroll_delays;
4422 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4424 /* needed for displaying scaling type text instead of identifier */
4425 scroll_delay_text = scroll_delay_current->name;
4428 static void execSetupGame_setSnapshotModes()
4430 if (snapshot_modes == NULL)
4434 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4436 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4437 char identifier[32], name[32];
4438 char *value = snapshot_modes_list[i].value;
4439 char *text = snapshot_modes_list[i].text;
4441 ti->node_top = &snapshot_modes;
4442 ti->sort_priority = i;
4444 sprintf(identifier, "%s", value);
4445 sprintf(name, "%s", text);
4447 setString(&ti->identifier, identifier);
4448 setString(&ti->name, name);
4449 setString(&ti->name_sorting, name);
4450 setString(&ti->infotext, "Snapshot Mode");
4452 pushTreeInfo(&snapshot_modes, ti);
4455 /* sort snapshot mode values to start with lowest snapshot mode value */
4456 sortTreeInfo(&snapshot_modes);
4458 /* set current snapshot mode value to configured snapshot mode value */
4459 snapshot_mode_current =
4460 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4462 /* if that fails, set current snapshot mode to reliable default value */
4463 if (snapshot_mode_current == NULL)
4464 snapshot_mode_current =
4465 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4467 /* if that also fails, set current snapshot mode to first available value */
4468 if (snapshot_mode_current == NULL)
4469 snapshot_mode_current = snapshot_modes;
4472 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4474 /* needed for displaying snapshot mode text instead of identifier */
4475 snapshot_mode_text = snapshot_mode_current->name;
4478 static void execSetupGame()
4480 execSetupGame_setGameSpeeds();
4481 execSetupGame_setScrollDelays();
4482 execSetupGame_setSnapshotModes();
4484 setup_mode = SETUP_MODE_GAME;
4489 static void execSetupChooseGameSpeed()
4491 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4496 static void execSetupChooseScrollDelay()
4498 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4503 static void execSetupChooseSnapshotMode()
4505 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4510 static void execSetupEditor()
4512 setup_mode = SETUP_MODE_EDITOR;
4517 static void execSetupGraphics_setWindowSizes(boolean update_list)
4519 if (window_sizes != NULL && update_list)
4521 freeTreeInfo(window_sizes);
4523 window_sizes = NULL;
4526 if (window_sizes == NULL)
4528 boolean current_window_size_found = FALSE;
4531 for (i = 0; window_sizes_list[i].value != -1; i++)
4533 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4534 char identifier[32], name[32];
4535 int value = window_sizes_list[i].value;
4536 char *text = window_sizes_list[i].text;
4538 ti->node_top = &window_sizes;
4539 ti->sort_priority = value;
4541 sprintf(identifier, "%d", value);
4542 sprintf(name, "%s", text);
4544 setString(&ti->identifier, identifier);
4545 setString(&ti->name, name);
4546 setString(&ti->name_sorting, name);
4547 setString(&ti->infotext, "Window Scaling");
4549 pushTreeInfo(&window_sizes, ti);
4551 if (value == setup.window_scaling_percent)
4552 current_window_size_found = TRUE;
4555 if (!current_window_size_found)
4557 // add entry for non-preset window scaling value
4559 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4560 char identifier[32], name[32];
4561 int value = setup.window_scaling_percent;
4563 ti->node_top = &window_sizes;
4564 ti->sort_priority = value;
4566 sprintf(identifier, "%d", value);
4567 sprintf(name, "%d %% (Current)", value);
4569 setString(&ti->identifier, identifier);
4570 setString(&ti->name, name);
4571 setString(&ti->name_sorting, name);
4572 setString(&ti->infotext, "Window Scaling");
4574 pushTreeInfo(&window_sizes, ti);
4577 /* sort window size values to start with lowest window size value */
4578 sortTreeInfo(&window_sizes);
4580 /* set current window size value to configured window size value */
4581 window_size_current =
4582 getTreeInfoFromIdentifier(window_sizes,
4583 i_to_a(setup.window_scaling_percent));
4585 /* if that fails, set current window size to reliable default value */
4586 if (window_size_current == NULL)
4587 window_size_current =
4588 getTreeInfoFromIdentifier(window_sizes,
4589 i_to_a(STD_WINDOW_SCALING_PERCENT));
4591 /* if that also fails, set current window size to first available value */
4592 if (window_size_current == NULL)
4593 window_size_current = window_sizes;
4596 setup.window_scaling_percent = atoi(window_size_current->identifier);
4598 /* needed for displaying window size text instead of identifier */
4599 window_size_text = window_size_current->name;
4602 static void execSetupGraphics_setScalingTypes()
4604 if (scaling_types == NULL)
4608 for (i = 0; scaling_types_list[i].value != NULL; i++)
4610 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4611 char identifier[32], name[32];
4612 char *value = scaling_types_list[i].value;
4613 char *text = scaling_types_list[i].text;
4615 ti->node_top = &scaling_types;
4616 ti->sort_priority = i;
4618 sprintf(identifier, "%s", value);
4619 sprintf(name, "%s", text);
4621 setString(&ti->identifier, identifier);
4622 setString(&ti->name, name);
4623 setString(&ti->name_sorting, name);
4624 setString(&ti->infotext, "Anti-Aliasing");
4626 pushTreeInfo(&scaling_types, ti);
4629 /* sort scaling type values to start with lowest scaling type value */
4630 sortTreeInfo(&scaling_types);
4632 /* set current scaling type value to configured scaling type value */
4633 scaling_type_current =
4634 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4636 /* if that fails, set current scaling type to reliable default value */
4637 if (scaling_type_current == NULL)
4638 scaling_type_current =
4639 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4641 /* if that also fails, set current scaling type to first available value */
4642 if (scaling_type_current == NULL)
4643 scaling_type_current = scaling_types;
4646 setup.window_scaling_quality = scaling_type_current->identifier;
4648 /* needed for displaying scaling type text instead of identifier */
4649 scaling_type_text = scaling_type_current->name;
4652 static void execSetupGraphics_setScreenModes()
4654 // if (screen_modes == NULL && video.fullscreen_available)
4655 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4659 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4661 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4662 char identifier[32], name[32];
4663 int x = video.fullscreen_modes[i].width;
4664 int y = video.fullscreen_modes[i].height;
4667 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4669 ti->node_top = &screen_modes;
4670 ti->sort_priority = x * 10000 + y;
4672 sprintf(identifier, "%dx%d", x, y);
4673 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4675 setString(&ti->identifier, identifier);
4676 setString(&ti->name, name);
4677 setString(&ti->name_sorting, name);
4678 setString(&ti->infotext, "Fullscreen Mode");
4680 pushTreeInfo(&screen_modes, ti);
4683 /* sort fullscreen modes to start with lowest available screen resolution */
4684 sortTreeInfo(&screen_modes);
4686 /* set current screen mode for fullscreen mode to configured setup value */
4687 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4688 setup.fullscreen_mode);
4690 /* if that fails, set current screen mode to reliable default value */
4691 if (screen_mode_current == NULL)
4692 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4693 DEFAULT_FULLSCREEN_MODE);
4695 /* if that also fails, set current screen mode to first available mode */
4696 if (screen_mode_current == NULL)
4697 screen_mode_current = screen_modes;
4699 if (screen_mode_current == NULL)
4700 video.fullscreen_available = FALSE;
4703 // if (video.fullscreen_available)
4704 if (screen_mode_current != NULL)
4706 setup.fullscreen_mode = screen_mode_current->identifier;
4708 /* needed for displaying screen mode name instead of identifier */
4709 screen_mode_text = screen_mode_current->name;
4713 static void execSetupGraphics()
4715 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4717 // update "setup.window_scaling_percent" from list selection
4718 execSetupGraphics_setWindowSizes(FALSE);
4722 // update list selection from "setup.window_scaling_percent"
4723 execSetupGraphics_setWindowSizes(TRUE);
4726 execSetupGraphics_setScalingTypes();
4727 execSetupGraphics_setScreenModes();
4729 setup_mode = SETUP_MODE_GRAPHICS;
4733 #if defined(TARGET_SDL2)
4734 // window scaling may have changed at this point
4735 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4737 // window scaling quality may have changed at this point
4738 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4739 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4743 #if !defined(PLATFORM_ANDROID)
4744 #if defined(TARGET_SDL2)
4745 static void execSetupChooseWindowSize()
4747 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4752 static void execSetupChooseScalingType()
4754 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4759 static void execSetupChooseScreenMode()
4761 if (!video.fullscreen_available)
4764 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4771 static void execSetupChooseVolumeSimple()
4773 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4778 static void execSetupChooseVolumeLoops()
4780 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4785 static void execSetupChooseVolumeMusic()
4787 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4792 static void execSetupSound()
4794 if (volumes_simple == NULL)
4796 boolean current_volume_simple_found = FALSE;
4799 for (i = 0; volumes_list[i].value != -1; i++)
4801 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4802 char identifier[32], name[32];
4803 int value = volumes_list[i].value;
4804 char *text = volumes_list[i].text;
4806 ti->node_top = &volumes_simple;
4807 ti->sort_priority = value;
4809 sprintf(identifier, "%d", value);
4810 sprintf(name, "%s", text);
4812 setString(&ti->identifier, identifier);
4813 setString(&ti->name, name);
4814 setString(&ti->name_sorting, name);
4815 setString(&ti->infotext, "Sound Volume");
4817 pushTreeInfo(&volumes_simple, ti);
4819 if (value == setup.volume_simple)
4820 current_volume_simple_found = TRUE;
4823 if (!current_volume_simple_found)
4825 // add entry for non-preset volume value
4827 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4828 char identifier[32], name[32];
4829 int value = setup.volume_simple;
4831 ti->node_top = &volumes_simple;
4832 ti->sort_priority = value;
4834 sprintf(identifier, "%d", value);
4835 sprintf(name, "%d %% (Current)", value);
4837 setString(&ti->identifier, identifier);
4838 setString(&ti->name, name);
4839 setString(&ti->name_sorting, name);
4840 setString(&ti->infotext, "Sound Volume");
4842 pushTreeInfo(&volumes_simple, ti);
4845 /* sort volume values to start with lowest volume value */
4846 sortTreeInfo(&volumes_simple);
4848 /* set current volume value to configured volume value */
4849 volume_simple_current =
4850 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4852 /* if that fails, set current volume to reliable default value */
4853 if (volume_simple_current == NULL)
4854 volume_simple_current =
4855 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4857 /* if that also fails, set current volume to first available value */
4858 if (volume_simple_current == NULL)
4859 volume_simple_current = volumes_simple;
4862 if (volumes_loops == NULL)
4864 boolean current_volume_loops_found = FALSE;
4867 for (i = 0; volumes_list[i].value != -1; i++)
4869 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4870 char identifier[32], name[32];
4871 int value = volumes_list[i].value;
4872 char *text = volumes_list[i].text;
4874 ti->node_top = &volumes_loops;
4875 ti->sort_priority = value;
4877 sprintf(identifier, "%d", value);
4878 sprintf(name, "%s", text);
4880 setString(&ti->identifier, identifier);
4881 setString(&ti->name, name);
4882 setString(&ti->name_sorting, name);
4883 setString(&ti->infotext, "Loops Volume");
4885 pushTreeInfo(&volumes_loops, ti);
4887 if (value == setup.volume_loops)
4888 current_volume_loops_found = TRUE;
4891 if (!current_volume_loops_found)
4893 // add entry for non-preset volume value
4895 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4896 char identifier[32], name[32];
4897 int value = setup.volume_loops;
4899 ti->node_top = &volumes_loops;
4900 ti->sort_priority = value;
4902 sprintf(identifier, "%d", value);
4903 sprintf(name, "%d %% (Current)", value);
4905 setString(&ti->identifier, identifier);
4906 setString(&ti->name, name);
4907 setString(&ti->name_sorting, name);
4908 setString(&ti->infotext, "Loops Volume");
4910 pushTreeInfo(&volumes_loops, ti);
4913 /* sort volume values to start with lowest volume value */
4914 sortTreeInfo(&volumes_loops);
4916 /* set current volume value to configured volume value */
4917 volume_loops_current =
4918 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4920 /* if that fails, set current volume to reliable default value */
4921 if (volume_loops_current == NULL)
4922 volume_loops_current =
4923 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4925 /* if that also fails, set current volume to first available value */
4926 if (volume_loops_current == NULL)
4927 volume_loops_current = volumes_loops;
4930 if (volumes_music == NULL)
4932 boolean current_volume_music_found = FALSE;
4935 for (i = 0; volumes_list[i].value != -1; i++)
4937 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4938 char identifier[32], name[32];
4939 int value = volumes_list[i].value;
4940 char *text = volumes_list[i].text;
4942 ti->node_top = &volumes_music;
4943 ti->sort_priority = value;
4945 sprintf(identifier, "%d", value);
4946 sprintf(name, "%s", text);
4948 setString(&ti->identifier, identifier);
4949 setString(&ti->name, name);
4950 setString(&ti->name_sorting, name);
4951 setString(&ti->infotext, "Music Volume");
4953 pushTreeInfo(&volumes_music, ti);
4955 if (value == setup.volume_music)
4956 current_volume_music_found = TRUE;
4959 if (!current_volume_music_found)
4961 // add entry for non-preset volume value
4963 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4964 char identifier[32], name[32];
4965 int value = setup.volume_music;
4967 ti->node_top = &volumes_music;
4968 ti->sort_priority = value;
4970 sprintf(identifier, "%d", value);
4971 sprintf(name, "%d %% (Current)", value);
4973 setString(&ti->identifier, identifier);
4974 setString(&ti->name, name);
4975 setString(&ti->name_sorting, name);
4976 setString(&ti->infotext, "Music Volume");
4978 pushTreeInfo(&volumes_music, ti);
4981 /* sort volume values to start with lowest volume value */
4982 sortTreeInfo(&volumes_music);
4984 /* set current volume value to configured volume value */
4985 volume_music_current =
4986 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4988 /* if that fails, set current volume to reliable default value */
4989 if (volume_music_current == NULL)
4990 volume_music_current =
4991 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4993 /* if that also fails, set current volume to first available value */
4994 if (volume_music_current == NULL)
4995 volume_music_current = volumes_music;
4998 setup.volume_simple = atoi(volume_simple_current->identifier);
4999 setup.volume_loops = atoi(volume_loops_current->identifier);
5000 setup.volume_music = atoi(volume_music_current->identifier);
5002 /* needed for displaying volume text instead of identifier */
5003 volume_simple_text = volume_simple_current->name;
5004 volume_loops_text = volume_loops_current->name;
5005 volume_music_text = volume_music_current->name;
5007 setup_mode = SETUP_MODE_SOUND;
5012 static void execSetupChooseTouchControls()
5014 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5019 static void execSetupChooseMoveDistance()
5021 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5026 static void execSetupChooseDropDistance()
5028 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5033 static void execSetupTouch()
5035 if (touch_controls == NULL)
5039 for (i = 0; touch_controls_list[i].value != NULL; i++)
5041 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5042 char identifier[32], name[32];
5043 char *value = touch_controls_list[i].value;
5044 char *text = touch_controls_list[i].text;
5046 ti->node_top = &touch_controls;
5047 ti->sort_priority = i;
5049 sprintf(identifier, "%s", value);
5050 sprintf(name, "%s", text);
5052 setString(&ti->identifier, identifier);
5053 setString(&ti->name, name);
5054 setString(&ti->name_sorting, name);
5055 setString(&ti->infotext, "Control Type");
5057 pushTreeInfo(&touch_controls, ti);
5060 /* sort touch control values to start with lowest touch control value */
5061 sortTreeInfo(&touch_controls);
5063 /* set current touch control value to configured touch control value */
5064 touch_control_current =
5065 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5067 /* if that fails, set current touch control to reliable default value */
5068 if (touch_control_current == NULL)
5069 touch_control_current =
5070 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5072 /* if that also fails, set current touch control to first available value */
5073 if (touch_control_current == NULL)
5074 touch_control_current = touch_controls;
5077 if (move_distances == NULL)
5081 for (i = 0; distances_list[i].value != -1; i++)
5083 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5084 char identifier[32], name[32];
5085 int value = distances_list[i].value;
5086 char *text = distances_list[i].text;
5088 ti->node_top = &move_distances;
5089 ti->sort_priority = value;
5091 sprintf(identifier, "%d", value);
5092 sprintf(name, "%s", text);
5094 setString(&ti->identifier, identifier);
5095 setString(&ti->name, name);
5096 setString(&ti->name_sorting, name);
5097 setString(&ti->infotext, "Move Distance");
5099 pushTreeInfo(&move_distances, ti);
5102 /* sort distance values to start with lowest distance value */
5103 sortTreeInfo(&move_distances);
5105 /* set current distance value to configured distance value */
5106 move_distance_current =
5107 getTreeInfoFromIdentifier(move_distances,
5108 i_to_a(setup.touch.move_distance));
5110 /* if that fails, set current distance to reliable default value */
5111 if (move_distance_current == NULL)
5112 move_distance_current =
5113 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5115 /* if that also fails, set current distance to first available value */
5116 if (move_distance_current == NULL)
5117 move_distance_current = move_distances;
5120 if (drop_distances == NULL)
5124 for (i = 0; distances_list[i].value != -1; i++)
5126 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5127 char identifier[32], name[32];
5128 int value = distances_list[i].value;
5129 char *text = distances_list[i].text;
5131 ti->node_top = &drop_distances;
5132 ti->sort_priority = value;
5134 sprintf(identifier, "%d", value);
5135 sprintf(name, "%s", text);
5137 setString(&ti->identifier, identifier);
5138 setString(&ti->name, name);
5139 setString(&ti->name_sorting, name);
5140 setString(&ti->infotext, "Drop Distance");
5142 pushTreeInfo(&drop_distances, ti);
5145 /* sort distance values to start with lowest distance value */
5146 sortTreeInfo(&drop_distances);
5148 /* set current distance value to configured distance value */
5149 drop_distance_current =
5150 getTreeInfoFromIdentifier(drop_distances,
5151 i_to_a(setup.touch.drop_distance));
5153 /* if that fails, set current distance to reliable default value */
5154 if (drop_distance_current == NULL)
5155 drop_distance_current =
5156 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5158 /* if that also fails, set current distance to first available value */
5159 if (drop_distance_current == NULL)
5160 drop_distance_current = drop_distances;
5163 setup.touch.control_type = touch_control_current->identifier;
5164 setup.touch.move_distance = atoi(move_distance_current->identifier);
5165 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5167 /* needed for displaying volume text instead of identifier */
5168 touch_controls_text = touch_control_current->name;
5169 move_distance_text = move_distance_current->name;
5170 drop_distance_text = drop_distance_current->name;
5172 setup_mode = SETUP_MODE_TOUCH;
5177 static void execSetupArtwork()
5180 printf("::: '%s', '%s', '%s'\n",
5181 artwork.gfx_current->subdir,
5182 artwork.gfx_current->fullpath,
5183 artwork.gfx_current->basepath);
5186 setup.graphics_set = artwork.gfx_current->identifier;
5187 setup.sounds_set = artwork.snd_current->identifier;
5188 setup.music_set = artwork.mus_current->identifier;
5190 /* needed if last screen (setup choice) changed graphics, sounds or music */
5191 ReloadCustomArtwork(0);
5193 /* needed for displaying artwork name instead of artwork identifier */
5194 graphics_set_name = artwork.gfx_current->name;
5195 sounds_set_name = artwork.snd_current->name;
5196 music_set_name = artwork.mus_current->name;
5198 setup_mode = SETUP_MODE_ARTWORK;
5203 static void execSetupChooseGraphics()
5205 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5210 static void execSetupChooseSounds()
5212 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5217 static void execSetupChooseMusic()
5219 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5224 #if !defined(PLATFORM_ANDROID)
5225 static void execSetupInput()
5227 setup_mode = SETUP_MODE_INPUT;
5233 static void execSetupShortcuts()
5235 setup_mode = SETUP_MODE_SHORTCUTS;
5240 static void execSetupShortcuts1()
5242 setup_mode = SETUP_MODE_SHORTCUTS_1;
5247 static void execSetupShortcuts2()
5249 setup_mode = SETUP_MODE_SHORTCUTS_2;
5254 static void execSetupShortcuts3()
5256 setup_mode = SETUP_MODE_SHORTCUTS_3;
5261 static void execSetupShortcuts4()
5263 setup_mode = SETUP_MODE_SHORTCUTS_4;
5268 static void execSetupShortcuts5()
5270 setup_mode = SETUP_MODE_SHORTCUTS_5;
5275 static void execExitSetup()
5277 game_status = GAME_MODE_MAIN;
5282 static void execSaveAndExitSetup()
5288 static struct TokenInfo setup_info_main[] =
5290 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5291 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5292 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5293 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5294 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5295 #if !defined(PLATFORM_ANDROID)
5296 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5297 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5299 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5301 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5302 { TYPE_EMPTY, NULL, "" },
5303 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5304 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5309 static struct TokenInfo setup_info_game[] =
5311 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5312 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5313 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5314 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5315 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5316 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5317 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5318 { TYPE_STRING, &game_speed_text, "" },
5320 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5321 { TYPE_STRING, &scroll_delay_text, "" },
5323 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5324 { TYPE_STRING, &snapshot_mode_text, "" },
5325 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5326 { TYPE_EMPTY, NULL, "" },
5327 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5332 static struct TokenInfo setup_info_editor[] =
5335 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5336 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5337 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5338 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5339 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5340 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5341 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5342 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5344 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5345 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5346 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5348 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5350 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5351 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5352 { TYPE_EMPTY, NULL, "" },
5354 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5355 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5356 { TYPE_EMPTY, NULL, "" },
5358 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5359 { TYPE_EMPTY, NULL, "" },
5360 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5365 static struct TokenInfo setup_info_graphics[] =
5367 #if !defined(PLATFORM_ANDROID)
5368 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5369 #if defined(TARGET_SDL2)
5370 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5371 { TYPE_STRING, &window_size_text, "" },
5372 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5373 { TYPE_STRING, &scaling_type_text, "" },
5375 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5376 { TYPE_STRING, &screen_mode_text, "" },
5380 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5381 { TYPE_STRING, &scroll_delay_text, "" },
5383 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5384 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5385 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5386 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5387 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5388 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5389 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5390 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5391 { TYPE_EMPTY, NULL, "" },
5392 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5397 static struct TokenInfo setup_info_sound[] =
5399 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5400 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5401 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5402 { TYPE_EMPTY, NULL, "" },
5403 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5404 { TYPE_STRING, &volume_simple_text, "" },
5405 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5406 { TYPE_STRING, &volume_loops_text, "" },
5407 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5408 { TYPE_STRING, &volume_music_text, "" },
5409 { TYPE_EMPTY, NULL, "" },
5410 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5415 static struct TokenInfo setup_info_artwork[] =
5417 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5418 { TYPE_STRING, &graphics_set_name, "" },
5419 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5420 { TYPE_STRING, &sounds_set_name, "" },
5421 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5422 { TYPE_STRING, &music_set_name, "" },
5423 { TYPE_EMPTY, NULL, "" },
5424 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5425 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5426 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5427 { TYPE_EMPTY, NULL, "" },
5428 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5433 static struct TokenInfo setup_info_input[] =
5435 { TYPE_SWITCH, NULL, "Player:" },
5436 { TYPE_SWITCH, NULL, "Device:" },
5437 { TYPE_ENTER_MENU, NULL, "" },
5438 { TYPE_EMPTY, NULL, "" },
5439 { TYPE_EMPTY, NULL, "" },
5440 { TYPE_EMPTY, NULL, "" },
5441 { TYPE_EMPTY, NULL, "" },
5442 { TYPE_EMPTY, NULL, "" },
5443 { TYPE_EMPTY, NULL, "" },
5444 { TYPE_EMPTY, NULL, "" },
5445 { TYPE_EMPTY, NULL, "" },
5446 { TYPE_EMPTY, NULL, "" },
5447 { TYPE_EMPTY, NULL, "" },
5448 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5453 static struct TokenInfo setup_info_touch[] =
5455 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5456 { TYPE_STRING, &touch_controls_text, "" },
5457 { TYPE_EMPTY, NULL, "" },
5458 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5459 { TYPE_STRING, &move_distance_text, "" },
5460 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5461 { TYPE_STRING, &drop_distance_text, "" },
5462 { TYPE_EMPTY, NULL, "" },
5463 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5468 static struct TokenInfo setup_info_shortcuts[] =
5470 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5471 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5472 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5473 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5474 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5475 { TYPE_EMPTY, NULL, "" },
5476 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5481 static struct TokenInfo setup_info_shortcuts_1[] =
5483 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5484 { TYPE_KEY, &setup.shortcut.save_game, "" },
5485 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5486 { TYPE_KEY, &setup.shortcut.load_game, "" },
5487 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5488 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5489 { TYPE_EMPTY, NULL, "" },
5490 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5491 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5492 { TYPE_EMPTY, NULL, "" },
5493 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5498 static struct TokenInfo setup_info_shortcuts_2[] =
5500 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5501 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5502 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5503 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5504 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5505 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5506 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5507 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5508 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5509 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5510 { TYPE_EMPTY, NULL, "" },
5511 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5516 static struct TokenInfo setup_info_shortcuts_3[] =
5518 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5519 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5520 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5521 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5522 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5523 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5524 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5525 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5526 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5527 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5528 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5529 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5530 { TYPE_EMPTY, NULL, "" },
5531 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5536 static struct TokenInfo setup_info_shortcuts_4[] =
5538 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5539 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5540 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5541 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5542 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5543 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5544 { TYPE_EMPTY, NULL, "" },
5545 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5550 static struct TokenInfo setup_info_shortcuts_5[] =
5552 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5553 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5554 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5555 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5556 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5557 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5558 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5559 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5560 { TYPE_EMPTY, NULL, "" },
5561 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5566 static Key getSetupKey()
5568 Key key = KSYM_UNDEFINED;
5569 boolean got_key_event = FALSE;
5571 while (!got_key_event)
5573 if (PendingEvent()) /* got event */
5581 case EVENT_KEYPRESS:
5583 key = GetEventKey((KeyEvent *)&event, TRUE);
5585 /* press 'Escape' or 'Enter' to keep the existing key binding */
5586 if (key == KSYM_Escape || key == KSYM_Return)
5587 key = KSYM_UNDEFINED; /* keep old value */
5589 got_key_event = TRUE;
5593 case EVENT_KEYRELEASE:
5594 key_joystick_mapping = 0;
5598 HandleOtherEvents(&event);
5606 /* don't eat all CPU time */
5613 static int getSetupValueFont(int type, void *value)
5615 if (type & TYPE_KEY)
5616 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5617 else if (type & TYPE_STRING)
5618 return FONT_VALUE_2;
5619 else if (type & TYPE_ECS_AGA)
5620 return FONT_VALUE_1;
5621 else if (type & TYPE_BOOLEAN_STYLE)
5622 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5623 else if (type & TYPE_YES_NO_AUTO)
5624 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5625 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5627 return FONT_VALUE_1;
5630 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5632 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5633 struct TokenInfo *si = &setup_info[si_pos];
5634 boolean font_draw_xoffset_modified = FALSE;
5635 int font_draw_xoffset_old = -1;
5636 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5637 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5638 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5639 int xpos = menu_screen_value_xpos;
5640 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5641 int startx = mSX + xpos * 32;
5642 int starty = mSY + ypos * 32;
5643 int font_nr, font_width;
5644 int type = si->type;
5645 void *value = si->value;
5646 char *value_string = getSetupValue(type, value);
5649 if (value_string == NULL)
5652 if (type & TYPE_KEY)
5654 xpos = MENU_SCREEN_START_XPOS;
5656 if (type & TYPE_QUERY)
5657 value_string = "<press key>";
5659 else if (type & TYPE_STRING)
5661 int max_value_len = (SCR_FIELDX - 2) * 2;
5663 xpos = MENU_SCREEN_START_XPOS;
5665 if (strlen(value_string) > max_value_len)
5666 value_string[max_value_len] = '\0';
5668 else if (type & TYPE_YES_NO_AUTO)
5670 xpos = menu_screen_value_xpos - 1;
5673 startx = mSX + xpos * 32;
5674 starty = mSY + ypos * 32;
5675 font_nr = getSetupValueFont(type, value);
5676 font_width = getFontWidth(font_nr);
5678 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5679 if (setup_mode != SETUP_MODE_INPUT)
5681 int max_menu_text_length_big = (menu_screen_value_xpos -
5682 MENU_SCREEN_START_XPOS);
5683 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5684 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5685 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5686 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5687 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5688 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5689 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5690 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5691 boolean correct_font_draw_xoffset = FALSE;
5693 if (xpos == MENU_SCREEN_START_XPOS &&
5694 startx + font1_xoffset < text_startx + text_font_xoffset)
5695 correct_font_draw_xoffset = TRUE;
5697 if (xpos == menu_screen_value_xpos &&
5698 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5699 correct_font_draw_xoffset = TRUE;
5701 /* check if setup value would overlap with setup text when printed */
5702 /* (this can happen for extreme/wrong values for font draw offset) */
5703 if (correct_font_draw_xoffset)
5705 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5706 font_draw_xoffset_modified = TRUE;
5708 if (type & TYPE_KEY)
5709 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5710 else if (!(type & TYPE_STRING))
5711 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5712 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5716 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5717 DrawText(startx + i * font_width, starty, " ", font_nr);
5719 DrawText(startx, starty, value_string, font_nr);
5721 if (font_draw_xoffset_modified)
5722 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5725 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5727 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5728 struct TokenInfo *si = &setup_info[si_pos];
5730 if (si->type & TYPE_BOOLEAN_STYLE)
5732 *(boolean *)si->value ^= TRUE;
5734 else if (si->type & TYPE_YES_NO_AUTO)
5738 (*(int *)si->value == AUTO ? TRUE :
5739 *(int *)si->value == TRUE ? FALSE : AUTO) :
5740 (*(int *)si->value == TRUE ? AUTO :
5741 *(int *)si->value == AUTO ? FALSE : TRUE));
5743 else if (si->type & TYPE_KEY)
5747 si->type |= TYPE_QUERY;
5748 drawSetupValue(screen_pos, setup_info_pos_raw);
5749 si->type &= ~TYPE_QUERY;
5751 key = getSetupKey();
5752 if (key != KSYM_UNDEFINED)
5753 *(Key *)si->value = key;
5756 drawSetupValue(screen_pos, setup_info_pos_raw);
5758 // fullscreen state may have changed at this point
5759 if (si->value == &setup.fullscreen)
5760 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5763 static void DrawSetupScreen_Generic()
5765 int fade_mask = REDRAW_FIELD;
5766 boolean redraw_all = FALSE;
5767 char *title_string = NULL;
5770 if (CheckIfGlobalBorderHasChanged())
5771 fade_mask = REDRAW_ALL;
5775 FreeScreenGadgets();
5776 CreateScreenGadgets();
5778 CloseDoor(DOOR_CLOSE_2);
5780 if (redraw_mask & REDRAW_ALL)
5785 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5789 if (setup_mode == SETUP_MODE_MAIN)
5791 setup_info = setup_info_main;
5792 title_string = "Setup";
5794 else if (setup_mode == SETUP_MODE_GAME)
5796 setup_info = setup_info_game;
5797 title_string = "Setup Game";
5799 else if (setup_mode == SETUP_MODE_EDITOR)
5801 setup_info = setup_info_editor;
5802 title_string = "Setup Editor";
5804 else if (setup_mode == SETUP_MODE_GRAPHICS)
5806 setup_info = setup_info_graphics;
5807 title_string = "Setup Graphics";
5809 else if (setup_mode == SETUP_MODE_SOUND)
5811 setup_info = setup_info_sound;
5812 title_string = "Setup Sound";
5814 else if (setup_mode == SETUP_MODE_ARTWORK)
5816 setup_info = setup_info_artwork;
5817 title_string = "Custom Artwork";
5819 else if (setup_mode == SETUP_MODE_TOUCH)
5821 setup_info = setup_info_touch;
5822 title_string = "Setup Touch Ctrls";
5824 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5826 setup_info = setup_info_shortcuts;
5827 title_string = "Setup Shortcuts";
5829 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5831 setup_info = setup_info_shortcuts_1;
5832 title_string = "Setup Shortcuts";
5834 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5836 setup_info = setup_info_shortcuts_2;
5837 title_string = "Setup Shortcuts";
5839 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5841 setup_info = setup_info_shortcuts_3;
5842 title_string = "Setup Shortcuts";
5844 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5846 setup_info = setup_info_shortcuts_4;
5847 title_string = "Setup Shortcuts";
5849 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5851 setup_info = setup_info_shortcuts_5;
5852 title_string = "Setup Shortcuts";
5855 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5857 // determine maximal number of setup entries that can be displayed on screen
5859 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5862 // determine maximal number of setup entries available for this setup screen
5864 for (i = 0; setup_info[i].type != 0; i++)
5867 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5869 MapScreenGadgets(max_setup_info);
5872 redraw_mask = fade_mask = REDRAW_ALL;
5874 DrawMaskedBorder(fade_mask);
5881 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5883 menu_info = setup_info;
5885 HandleMenuScreen(mx, my, dx, dy, button,
5886 setup_mode, num_setup_info, max_setup_info);
5889 void DrawSetupScreen_Input()
5893 FadeOut(REDRAW_FIELD);
5897 setup_info = setup_info_input;
5899 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5901 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5902 "Joysticks deactivated on this screen");
5904 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5906 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5907 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5908 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5909 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5910 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5911 initCursor(i, IMG_MENU_BUTTON);
5913 DrawCursorAndText_Setup(i, -1, FALSE);
5916 /* create gadgets for setup input menu screen */
5917 FreeScreenGadgets();
5918 CreateScreenGadgets();
5920 /* map gadgets for setup input menu screen */
5921 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5923 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5925 FadeIn(REDRAW_FIELD);
5930 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5932 if (device_name == NULL)
5935 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5938 if (strlen(device_name) > 1)
5940 char c1 = device_name[strlen(device_name) - 1];
5941 char c2 = device_name[strlen(device_name) - 2];
5943 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5944 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5947 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5948 strlen(device_name));
5951 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5954 static struct SetupKeyboardInfo custom_key;
5961 { &custom_key.left, "Joystick Left" },
5962 { &custom_key.right, "Joystick Right" },
5963 { &custom_key.up, "Joystick Up" },
5964 { &custom_key.down, "Joystick Down" },
5965 { &custom_key.snap, "Button 1" },
5966 { &custom_key.drop, "Button 2" }
5968 static char *joystick_name[MAX_PLAYERS] =
5975 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5979 custom_key = setup.input[player_nr].key;
5981 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5982 FONT_INPUT_1_ACTIVE);
5984 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5986 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5987 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5989 if (setup.input[player_nr].use_joystick)
5991 char *device_name = setup.input[player_nr].joy.device_name;
5992 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5993 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5995 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5996 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6000 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6001 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6004 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6006 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6007 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6008 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6009 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6011 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6012 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6013 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6014 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6015 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6016 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6018 for (i = 0; i < 6; i++)
6020 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6022 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6024 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6025 (setup.input[player_nr].use_joystick ?
6027 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6031 static int input_player_nr = 0;
6033 void HandleSetupScreen_Input_Player(int step, int direction)
6035 int old_player_nr = input_player_nr;
6038 new_player_nr = old_player_nr + step * direction;
6039 if (new_player_nr < 0)
6041 if (new_player_nr > MAX_PLAYERS - 1)
6042 new_player_nr = MAX_PLAYERS - 1;
6044 if (new_player_nr != old_player_nr)
6046 input_player_nr = new_player_nr;
6048 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6052 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6054 static int choice = 0;
6057 int pos_start = SETUPINPUT_SCREEN_POS_START;
6058 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6059 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6060 int pos_end = SETUPINPUT_SCREEN_POS_END;
6062 if (button == MB_MENU_INITIALIZE)
6064 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6066 DrawCursorAndText_Setup(choice, -1, TRUE);
6070 else if (button == MB_MENU_LEAVE)
6072 setup_mode = SETUP_MODE_MAIN;
6079 if (mx || my) /* mouse input */
6081 x = (mx - mSX) / 32;
6082 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6084 else if (dx || dy) /* keyboard input */
6086 if (dx && choice == 0)
6087 x = (dx < 0 ? 10 : 12);
6088 else if ((dx && choice == 1) ||
6089 (dx == +1 && choice == 2) ||
6090 (dx == -1 && choice == pos_end))
6091 button = MB_MENU_CHOICE;
6095 if (y >= pos_empty1 && y <= pos_empty2)
6096 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6099 if (y == 0 && dx != 0 && button)
6101 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6103 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6104 y >= pos_start && y <= pos_end &&
6105 !(y >= pos_empty1 && y <= pos_empty2))
6111 DrawCursorAndText_Setup(choice, -1, FALSE);
6112 DrawCursorAndText_Setup(y, -1, TRUE);
6114 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6123 char *device_name = setup.input[input_player_nr].joy.device_name;
6125 if (!setup.input[input_player_nr].use_joystick)
6127 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6129 setJoystickDeviceToNr(device_name, new_device_nr);
6130 setup.input[input_player_nr].use_joystick = TRUE;
6134 int device_nr = getJoystickNrFromDeviceName(device_name);
6135 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6137 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6138 setup.input[input_player_nr].use_joystick = FALSE;
6140 setJoystickDeviceToNr(device_name, new_device_nr);
6143 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6147 if (setup.input[input_player_nr].use_joystick)
6150 CalibrateJoystick(input_player_nr);
6153 CustomizeKeyboard(input_player_nr);
6155 else if (y == pos_end)
6161 setup_mode = SETUP_MODE_MAIN;
6168 void CustomizeKeyboard(int player_nr)
6172 boolean finished = FALSE;
6173 static struct SetupKeyboardInfo custom_key;
6178 } customize_step[] =
6180 { &custom_key.left, "Move Left" },
6181 { &custom_key.right, "Move Right" },
6182 { &custom_key.up, "Move Up" },
6183 { &custom_key.down, "Move Down" },
6184 { &custom_key.snap, "Snap Field" },
6185 { &custom_key.drop, "Drop Element" }
6188 /* read existing key bindings from player setup */
6189 custom_key = setup.input[player_nr].key;
6192 FadeOut(REDRAW_FIELD);
6196 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6199 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6200 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6201 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6202 "Key:", FONT_INPUT_1_ACTIVE);
6203 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6204 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6206 FadeIn(REDRAW_FIELD);
6212 if (PendingEvent()) /* got event */
6220 case EVENT_KEYPRESS:
6222 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6224 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6226 if (key == KSYM_Escape)
6227 FadeSkipNextFadeIn();
6233 /* all keys configured -- wait for "Escape" or "Return" key */
6237 /* press 'Enter' to keep the existing key binding */
6238 if (key == KSYM_Return)
6239 key = *customize_step[step_nr].key;
6241 /* check if key already used */
6242 for (i = 0; i < step_nr; i++)
6243 if (*customize_step[i].key == key)
6248 /* got new key binding */
6249 *customize_step[step_nr].key = key;
6250 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6252 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6253 getKeyNameFromKey(key), FONT_VALUE_1);
6256 /* un-highlight last query */
6257 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6258 customize_step[step_nr - 1].text, FONT_MENU_1);
6259 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6260 "Key:", FONT_MENU_1);
6262 /* press 'Enter' to leave */
6265 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6266 "Press Enter", FONT_TITLE_1);
6270 /* query next key binding */
6271 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6272 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6273 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6274 "Key:", FONT_INPUT_1_ACTIVE);
6275 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6276 getKeyNameFromKey(*customize_step[step_nr].key),
6281 case EVENT_KEYRELEASE:
6282 key_joystick_mapping = 0;
6286 HandleOtherEvents(&event);
6294 /* don't eat all CPU time */
6298 /* write new key bindings back to player setup */
6299 setup.input[player_nr].key = custom_key;
6302 DrawSetupScreen_Input();
6305 static boolean CalibrateJoystickMain(int player_nr)
6307 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6308 int new_joystick_xright = JOYSTICK_XMIDDLE;
6309 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6310 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6311 int new_joystick_xmiddle, new_joystick_ymiddle;
6313 int joystick_fd = joystick.fd[player_nr];
6314 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6315 boolean check[3][3];
6316 int check_remaining = 3 * 3;
6321 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6324 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6328 FadeOut(REDRAW_FIELD);
6332 for (y = 0; y < 3; y++)
6334 for (x = 0; x < 3; x++)
6336 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6337 check[x][y] = FALSE;
6341 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6342 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6343 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6344 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6345 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6346 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6347 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6349 joy_value = Joystick(player_nr);
6350 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6351 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6353 /* eventually uncalibrated center position (joystick could be uncentered) */
6354 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6357 new_joystick_xmiddle = joy_x;
6358 new_joystick_ymiddle = joy_y;
6360 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6362 FadeIn(REDRAW_FIELD);
6364 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6369 if (PendingEvent()) /* got event */
6377 case EVENT_KEYPRESS:
6378 switch (GetEventKey((KeyEvent *)&event, TRUE))
6381 if (check_remaining == 0)
6386 FadeSkipNextFadeIn();
6395 case EVENT_KEYRELEASE:
6396 key_joystick_mapping = 0;
6400 HandleOtherEvents(&event);
6405 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6408 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6409 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6410 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6411 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6413 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6414 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6415 setup.input[player_nr].joy.xright = new_joystick_xright;
6416 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6417 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6418 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6420 CheckJoystickData();
6422 joy_value = Joystick(player_nr);
6424 if (joy_value & JOY_BUTTON && check_remaining == 0)
6427 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6428 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6430 if (x != last_x || y != last_y)
6432 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6433 IMG_MENU_CALIBRATE_YELLOW, 0);
6434 DrawFixedGraphic(xpos + x, ypos + y,
6435 IMG_MENU_CALIBRATE_RED, 0);
6440 if (check_remaining > 0 && !check[x+1][y+1])
6442 check[x+1][y+1] = TRUE;
6450 /* don't eat all CPU time */
6454 /* calibrated center position (joystick should now be centered) */
6455 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6458 new_joystick_xmiddle = joy_x;
6459 new_joystick_ymiddle = joy_y;
6463 /* wait until the last pressed button was released */
6464 while (Joystick(player_nr) & JOY_BUTTON)
6466 if (PendingEvent()) /* got event */
6471 HandleOtherEvents(&event);
6480 void CalibrateJoystick(int player_nr)
6482 if (!CalibrateJoystickMain(player_nr))
6484 char *device_name = setup.input[player_nr].joy.device_name;
6485 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6486 int xpos = mSX - SX;
6487 int ypos = mSY - SY;
6491 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6492 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6495 Delay(2000); /* show error message for a short time */
6500 DrawSetupScreen_Input();
6503 void DrawSetupScreen()
6505 DeactivateJoystick();
6507 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6509 if (setup_mode == SETUP_MODE_INPUT)
6510 DrawSetupScreen_Input();
6511 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6512 DrawChooseTree(&game_speed_current);
6513 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6514 DrawChooseTree(&scroll_delay_current);
6515 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6516 DrawChooseTree(&snapshot_mode_current);
6517 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6518 DrawChooseTree(&screen_mode_current);
6519 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6520 DrawChooseTree(&window_size_current);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6522 DrawChooseTree(&scaling_type_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6524 DrawChooseTree(&artwork.gfx_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6526 DrawChooseTree(&artwork.snd_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6528 DrawChooseTree(&artwork.mus_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6530 DrawChooseTree(&volume_simple_current);
6531 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6532 DrawChooseTree(&volume_loops_current);
6533 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6534 DrawChooseTree(&volume_music_current);
6535 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6536 DrawChooseTree(&touch_control_current);
6537 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6538 DrawChooseTree(&move_distance_current);
6539 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6540 DrawChooseTree(&drop_distance_current);
6542 DrawSetupScreen_Generic();
6548 void RedrawSetupScreenAfterFullscreenToggle()
6550 if (setup_mode == SETUP_MODE_GRAPHICS ||
6551 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6553 // update list selection from "setup.window_scaling_percent"
6554 execSetupGraphics_setWindowSizes(TRUE);
6560 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6562 if (setup_mode == SETUP_MODE_INPUT)
6563 HandleSetupScreen_Input(mx, my, dx, dy, button);
6564 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6565 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6566 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6567 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6568 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6569 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6570 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6571 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6573 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6575 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6577 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6579 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6581 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6582 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6583 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6584 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6585 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6586 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6587 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6588 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6589 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6590 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6591 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6592 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6593 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6595 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6598 void HandleGameActions()
6600 if (game_status != GAME_MODE_PLAYING)
6603 GameActions(); /* main game loop */
6605 if (tape.auto_play && !tape.playing)
6606 AutoPlayTape(); /* continue automatically playing next tape */
6610 /* ---------- new screen button stuff -------------------------------------- */
6612 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6616 case SCREEN_CTRL_ID_PREV_LEVEL:
6617 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6618 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6621 case SCREEN_CTRL_ID_NEXT_LEVEL:
6622 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6623 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6626 case SCREEN_CTRL_ID_PREV_PLAYER:
6627 *x = mSX + TILEX * 10;
6628 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6631 case SCREEN_CTRL_ID_NEXT_PLAYER:
6632 *x = mSX + TILEX * 12;
6633 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6637 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6643 int gfx_unpressed, gfx_pressed;
6644 void (*get_gadget_position)(int *, int *, int);
6648 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6651 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6652 getScreenMenuButtonPos,
6653 SCREEN_CTRL_ID_PREV_LEVEL,
6658 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6659 getScreenMenuButtonPos,
6660 SCREEN_CTRL_ID_NEXT_LEVEL,
6665 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6666 getScreenMenuButtonPos,
6667 SCREEN_CTRL_ID_PREV_PLAYER,
6672 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6673 getScreenMenuButtonPos,
6674 SCREEN_CTRL_ID_NEXT_PLAYER,
6682 int gfx_unpressed, gfx_pressed;
6686 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6689 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6690 -1, -1, /* these values are not constant, but can change at runtime */
6691 SCREEN_CTRL_ID_SCROLL_UP,
6695 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6696 -1, -1, /* these values are not constant, but can change at runtime */
6697 SCREEN_CTRL_ID_SCROLL_DOWN,
6704 int gfx_unpressed, gfx_pressed;
6710 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6713 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6714 -1, -1, /* these values are not constant, but can change at runtime */
6715 -1, -1, /* these values are not constant, but can change at runtime */
6716 GD_TYPE_SCROLLBAR_VERTICAL,
6717 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6718 "scroll level series vertically"
6722 static void CreateScreenMenubuttons()
6724 struct GadgetInfo *gi;
6725 unsigned int event_mask;
6728 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6730 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6731 int gfx_unpressed, gfx_pressed;
6732 int x, y, width, height;
6733 int gd_x1, gd_x2, gd_y1, gd_y2;
6734 int id = menubutton_info[i].gadget_id;
6736 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6738 menubutton_info[i].get_gadget_position(&x, &y, id);
6740 width = SC_MENUBUTTON_XSIZE;
6741 height = SC_MENUBUTTON_YSIZE;
6743 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6744 gfx_pressed = menubutton_info[i].gfx_pressed;
6745 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6746 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6747 gd_x1 = graphic_info[gfx_unpressed].src_x;
6748 gd_y1 = graphic_info[gfx_unpressed].src_y;
6749 gd_x2 = graphic_info[gfx_pressed].src_x;
6750 gd_y2 = graphic_info[gfx_pressed].src_y;
6752 gi = CreateGadget(GDI_CUSTOM_ID, id,
6753 GDI_CUSTOM_TYPE_ID, i,
6754 GDI_INFO_TEXT, menubutton_info[i].infotext,
6759 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6760 GDI_STATE, GD_BUTTON_UNPRESSED,
6761 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6762 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6763 GDI_DIRECT_DRAW, FALSE,
6764 GDI_EVENT_MASK, event_mask,
6765 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6769 Error(ERR_EXIT, "cannot create gadget");
6771 screen_gadget[id] = gi;
6775 static void CreateScreenScrollbuttons()
6777 struct GadgetInfo *gi;
6778 unsigned int event_mask;
6781 /* these values are not constant, but can change at runtime */
6782 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6783 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6784 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6785 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6787 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6789 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6790 int gfx_unpressed, gfx_pressed;
6791 int x, y, width, height;
6792 int gd_x1, gd_x2, gd_y1, gd_y2;
6793 int id = scrollbutton_info[i].gadget_id;
6795 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6797 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6798 y = mSY + scrollbutton_info[i].y;
6799 width = SC_SCROLLBUTTON_XSIZE;
6800 height = SC_SCROLLBUTTON_YSIZE;
6802 /* correct scrollbar position if placed outside menu (playfield) area */
6803 if (x > SX + SC_SCROLL_UP_XPOS)
6804 x = SX + SC_SCROLL_UP_XPOS;
6806 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6807 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6808 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6810 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6811 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6812 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6813 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6814 gd_x1 = graphic_info[gfx_unpressed].src_x;
6815 gd_y1 = graphic_info[gfx_unpressed].src_y;
6816 gd_x2 = graphic_info[gfx_pressed].src_x;
6817 gd_y2 = graphic_info[gfx_pressed].src_y;
6819 gi = CreateGadget(GDI_CUSTOM_ID, id,
6820 GDI_CUSTOM_TYPE_ID, i,
6821 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6826 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6827 GDI_STATE, GD_BUTTON_UNPRESSED,
6828 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6829 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6830 GDI_DIRECT_DRAW, FALSE,
6831 GDI_EVENT_MASK, event_mask,
6832 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6836 Error(ERR_EXIT, "cannot create gadget");
6838 screen_gadget[id] = gi;
6842 static void CreateScreenScrollbars()
6846 /* these values are not constant, but can change at runtime */
6847 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6848 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6849 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6850 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6852 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6854 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6855 int gfx_unpressed, gfx_pressed;
6856 int x, y, width, height;
6857 int gd_x1, gd_x2, gd_y1, gd_y2;
6858 struct GadgetInfo *gi;
6859 int items_max, items_visible, item_position;
6860 unsigned int event_mask;
6861 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6862 int id = scrollbar_info[i].gadget_id;
6864 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6866 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6867 y = mSY + scrollbar_info[i].y;
6868 width = scrollbar_info[i].width;
6869 height = scrollbar_info[i].height;
6871 /* correct scrollbar position if placed outside menu (playfield) area */
6872 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6873 x = SX + SC_SCROLL_VERTICAL_XPOS;
6875 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6876 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6878 items_max = num_page_entries;
6879 items_visible = num_page_entries;
6882 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6883 gfx_pressed = scrollbar_info[i].gfx_pressed;
6884 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6885 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6886 gd_x1 = graphic_info[gfx_unpressed].src_x;
6887 gd_y1 = graphic_info[gfx_unpressed].src_y;
6888 gd_x2 = graphic_info[gfx_pressed].src_x;
6889 gd_y2 = graphic_info[gfx_pressed].src_y;
6891 gi = CreateGadget(GDI_CUSTOM_ID, id,
6892 GDI_CUSTOM_TYPE_ID, i,
6893 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6898 GDI_TYPE, scrollbar_info[i].type,
6899 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6900 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6901 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6902 GDI_WHEEL_AREA_X, SX,
6903 GDI_WHEEL_AREA_Y, SY,
6904 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6905 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6906 GDI_STATE, GD_BUTTON_UNPRESSED,
6907 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6908 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6909 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6910 GDI_DIRECT_DRAW, FALSE,
6911 GDI_EVENT_MASK, event_mask,
6912 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6916 Error(ERR_EXIT, "cannot create gadget");
6918 screen_gadget[id] = gi;
6922 void CreateScreenGadgets()
6924 int last_game_status = game_status; /* save current game status */
6926 CreateScreenMenubuttons();
6928 CreateScreenScrollbuttons();
6929 CreateScreenScrollbars();
6931 game_status = last_game_status; /* restore current game status */
6934 void FreeScreenGadgets()
6938 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6939 FreeGadget(screen_gadget[i]);
6942 void MapScreenMenuGadgets(int screen_mask)
6946 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6947 if (screen_mask & menubutton_info[i].screen_mask)
6948 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6951 void MapScreenGadgets(int num_entries)
6955 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6958 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6959 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6961 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6962 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6965 void MapScreenTreeGadgets(TreeInfo *ti)
6967 MapScreenGadgets(numTreeInfoInGroup(ti));
6970 static void HandleScreenGadgets(struct GadgetInfo *gi)
6972 int id = gi->custom_id;
6973 int button = gi->event.button;
6974 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6978 case SCREEN_CTRL_ID_PREV_LEVEL:
6979 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6982 case SCREEN_CTRL_ID_NEXT_LEVEL:
6983 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6986 case SCREEN_CTRL_ID_PREV_PLAYER:
6987 HandleSetupScreen_Input_Player(step, -1);
6990 case SCREEN_CTRL_ID_NEXT_PLAYER:
6991 HandleSetupScreen_Input_Player(step, +1);
6994 case SCREEN_CTRL_ID_SCROLL_UP:
6995 if (game_status == GAME_MODE_LEVELS)
6996 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6997 else if (game_status == GAME_MODE_LEVELNR)
6998 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6999 else if (game_status == GAME_MODE_SETUP)
7000 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7001 else if (game_status == GAME_MODE_INFO)
7002 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7005 case SCREEN_CTRL_ID_SCROLL_DOWN:
7006 if (game_status == GAME_MODE_LEVELS)
7007 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7008 else if (game_status == GAME_MODE_LEVELNR)
7009 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7010 else if (game_status == GAME_MODE_SETUP)
7011 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7012 else if (game_status == GAME_MODE_INFO)
7013 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7016 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7017 if (game_status == GAME_MODE_LEVELS)
7018 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7019 else if (game_status == GAME_MODE_LEVELNR)
7020 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7021 else if (game_status == GAME_MODE_SETUP)
7022 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7023 else if (game_status == GAME_MODE_INFO)
7024 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);