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 void DrawTitleScreenImage(int nr, boolean initial)
1257 int graphic = getTitleScreenGraphic(nr, initial);
1258 Bitmap *bitmap = graphic_info[graphic].bitmap;
1259 int width = graphic_info[graphic].width;
1260 int height = graphic_info[graphic].height;
1261 int src_x = graphic_info[graphic].src_x;
1262 int src_y = graphic_info[graphic].src_y;
1268 if (width > WIN_XSIZE)
1270 /* image width too large for window => center image horizontally */
1271 src_x = (width - WIN_XSIZE) / 2;
1275 if (height > WIN_YSIZE)
1277 /* image height too large for window => center image vertically */
1278 src_y = (height - WIN_YSIZE) / 2;
1282 /* always display title screens centered */
1283 dst_x = (WIN_XSIZE - width) / 2;
1284 dst_y = (WIN_YSIZE - height) / 2;
1286 SetDrawBackgroundMask(REDRAW_ALL);
1287 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1289 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1291 if (DrawingOnBackground(dst_x, dst_y))
1292 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1294 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1296 redraw_mask = REDRAW_ALL;
1299 void DrawTitleScreenMessage(int nr, boolean initial)
1301 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1302 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1303 int last_game_status = game_status; /* save current game status */
1305 if (filename == NULL)
1308 /* force TITLE font on title message screen */
1309 game_status = getTitleMessageGameMode(initial);
1311 /* if chars *and* width set to "-1", automatically determine width */
1312 if (tmi->chars == -1 && tmi->width == -1)
1313 tmi->width = viewport.window[game_status].width;
1315 /* if lines *and* height set to "-1", automatically determine height */
1316 if (tmi->lines == -1 && tmi->height == -1)
1317 tmi->height = viewport.window[game_status].height;
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 /* if x set to "-1", automatically determine by width and alignment */
1333 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1335 /* if y set to "-1", automatically determine by height and alignment */
1337 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1339 SetDrawBackgroundMask(REDRAW_ALL);
1340 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1342 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1344 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1345 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1346 tmi->autowrap, tmi->centered, tmi->parse_comments);
1348 game_status = last_game_status; /* restore current game status */
1351 void DrawTitleScreen()
1353 KeyboardAutoRepeatOff();
1355 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1360 boolean CheckTitleScreen(boolean levelset_has_changed)
1362 static boolean show_title_initial = TRUE;
1363 boolean show_titlescreen = FALSE;
1365 /* needed to be able to skip title screen, if no image or message defined */
1366 InitializeTitleControls(show_title_initial);
1368 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1369 show_titlescreen = TRUE;
1371 /* show initial title images and messages only once at program start */
1372 show_title_initial = FALSE;
1374 return (show_titlescreen && num_title_screens > 0);
1379 static LevelDirTree *leveldir_last_valid = NULL;
1380 boolean levelset_has_changed = FALSE;
1381 int fade_mask = REDRAW_FIELD;
1383 LimitScreenUpdates(FALSE);
1385 FadeSetLeaveScreen();
1387 /* do not fade out here -- function may continue and fade on editor screen */
1390 FadeSoundsAndMusic();
1392 KeyboardAutoRepeatOn();
1395 audio.sound_deactivated = FALSE;
1399 /* needed if last screen was the playing screen, invoked from level editor */
1400 if (level_editor_test_game)
1402 game_status = GAME_MODE_EDITOR;
1408 /* needed if last screen was the setup screen and fullscreen state changed */
1409 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1410 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1412 /* leveldir_current may be invalid (level group, parent link) */
1413 if (!validLevelSeries(leveldir_current))
1414 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1416 if (leveldir_current != leveldir_last_valid)
1417 levelset_has_changed = TRUE;
1419 /* store valid level series information */
1420 leveldir_last_valid = leveldir_current;
1422 init_last = init; /* switch to new busy animation */
1424 /* needed if last screen (level choice) changed graphics, sounds or music */
1425 ReloadCustomArtwork(0);
1427 /* needed if different viewport properties defined for menues */
1428 ChangeViewportPropertiesIfNeeded();
1430 if (redraw_mask & REDRAW_ALL)
1431 fade_mask = REDRAW_ALL;
1433 if (CheckIfGlobalBorderHasChanged())
1434 fade_mask = REDRAW_ALL;
1438 /* needed if last screen was the editor screen */
1439 UndrawSpecialEditorDoor();
1441 SetDrawtoField(DRAW_BACKBUFFER);
1443 if (CheckTitleScreen(levelset_has_changed))
1445 game_status_last_screen = GAME_MODE_MAIN;
1446 game_status = GAME_MODE_TITLE;
1453 /* level_nr may have been set to value over handicap with level editor */
1454 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1455 level_nr = leveldir_current->handicap_level;
1457 LoadLevel(level_nr);
1458 LoadScore(level_nr);
1460 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1461 SetDrawDeactivationMask(REDRAW_NONE);
1462 SetDrawBackgroundMask(REDRAW_FIELD);
1464 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1467 if (fade_mask == REDRAW_ALL)
1468 RedrawGlobalBorder();
1473 InitializeMainControls();
1475 DrawCursorAndText_Main(-1, FALSE, FALSE);
1476 DrawPreviewLevelInitial();
1478 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1481 if (TAPE_IS_EMPTY(tape))
1483 DrawCompleteVideoDisplay();
1488 /* create gadgets for main menu screen */
1489 FreeScreenGadgets();
1490 CreateScreenGadgets();
1492 /* map gadgets for main menu screen */
1494 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1496 /* copy actual game door content to door double buffer for OpenDoor() */
1497 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1498 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1500 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1502 DrawMaskedBorder(fade_mask);
1507 /* update screen area with special editor door */
1508 redraw_mask |= REDRAW_ALL;
1511 SetMouseCursor(CURSOR_DEFAULT);
1515 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1518 static void gotoTopLevelDir()
1520 /* move upwards until inside (but not above) top level directory */
1521 while (leveldir_current->node_parent &&
1522 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1524 /* write a "path" into level tree for easy navigation to last level */
1525 if (leveldir_current->node_parent->node_group->cl_first == -1)
1527 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1528 int leveldir_pos = posTreeInfo(leveldir_current);
1529 int num_page_entries;
1530 int cl_first, cl_cursor;
1532 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1533 num_page_entries = num_leveldirs;
1535 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1537 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1538 cl_cursor = leveldir_pos - cl_first;
1540 leveldir_current->node_parent->node_group->cl_first = cl_first;
1541 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1544 leveldir_current = leveldir_current->node_parent;
1548 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1550 static unsigned int title_delay = 0;
1551 static int title_screen_nr = 0;
1552 static int last_sound = -1, last_music = -1;
1553 boolean return_to_main_menu = FALSE;
1554 struct TitleControlInfo *tci;
1557 if (button == MB_MENU_INITIALIZE)
1560 title_screen_nr = 0;
1561 tci = &title_controls[title_screen_nr];
1563 last_sound = SND_UNDEFINED;
1564 last_music = MUS_UNDEFINED;
1566 FadeSetEnterScreen();
1568 if (game_status_last_screen == GAME_MODE_INFO)
1570 if (num_title_screens == 0)
1572 DrawInfoScreen_NotAvailable("Title screen information:",
1573 "No title screen for this level set.");
1578 FadeSoundsAndMusic();
1580 FadeOut(REDRAW_ALL);
1583 /* only required to update logic for redrawing global border */
1586 /* title screens may have different window size */
1587 ChangeViewportPropertiesIfNeeded();
1590 DrawTitleScreenImage(tci->local_nr, tci->initial);
1592 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1594 sound = getTitleSound(tci);
1595 music = getTitleMusic(tci);
1597 if (sound != last_sound)
1598 PlayMenuSoundExt(sound);
1599 if (music != last_music)
1600 PlayMenuMusicExt(music);
1605 SetMouseCursor(CURSOR_NONE);
1609 DelayReached(&title_delay, 0); /* reset delay counter */
1614 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1615 button = MB_MENU_CHOICE;
1617 if (button == MB_MENU_LEAVE)
1619 return_to_main_menu = TRUE;
1621 else if (button == MB_MENU_CHOICE)
1623 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1625 FadeSetEnterScreen();
1627 game_status = GAME_MODE_INFO;
1628 info_mode = INFO_MODE_MAIN;
1636 tci = &title_controls[title_screen_nr];
1638 if (title_screen_nr < num_title_screens)
1640 sound = getTitleSound(tci);
1641 music = getTitleMusic(tci);
1643 if (sound == SND_UNDEFINED || sound != last_sound)
1645 if (music == MUS_UNDEFINED || music != last_music)
1648 fading = getTitleFading(tci);
1650 FadeOut(REDRAW_ALL);
1653 DrawTitleScreenImage(tci->local_nr, tci->initial);
1655 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1657 sound = getTitleSound(tci);
1658 music = getTitleMusic(tci);
1660 if (sound != last_sound)
1661 PlayMenuSoundExt(sound);
1662 if (music != last_music)
1663 PlayMenuMusicExt(music);
1670 DelayReached(&title_delay, 0); /* reset delay counter */
1674 FadeSoundsAndMusic();
1676 return_to_main_menu = TRUE;
1680 if (return_to_main_menu)
1682 SetMouseCursor(CURSOR_DEFAULT);
1684 /* force full menu screen redraw after displaying title screens */
1685 redraw_mask = REDRAW_ALL;
1687 if (game_status_last_screen == GAME_MODE_INFO)
1689 game_status = GAME_MODE_INFO;
1690 info_mode = INFO_MODE_MAIN;
1694 else /* default: return to main menu */
1696 game_status = GAME_MODE_MAIN;
1703 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1705 int old_level_nr = level_nr;
1708 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1709 new_level_nr = selected_level_nr;
1711 new_level_nr = old_level_nr + step * direction;
1713 if (new_level_nr < leveldir_current->first_level)
1714 new_level_nr = leveldir_current->first_level;
1715 if (new_level_nr > leveldir_current->last_level)
1716 new_level_nr = leveldir_current->last_level;
1718 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1720 /* skipping levels is only allowed when trying to skip single level */
1721 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1722 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1724 leveldir_current->handicap_level++;
1725 SaveLevelSetup_SeriesInfo();
1728 new_level_nr = leveldir_current->handicap_level;
1731 if (new_level_nr != old_level_nr)
1733 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1735 PlaySound(SND_MENU_ITEM_SELECTING);
1737 level_nr = new_level_nr;
1739 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1740 int2str(level_nr, menu.main.text.level_number.size),
1741 mci->pos_text->font);
1743 LoadLevel(level_nr);
1744 DrawPreviewLevelInitial();
1748 DrawCompleteVideoDisplay();
1750 /* needed because DrawPreviewLevelInitial() takes some time */
1752 /* SyncDisplay(); */
1756 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1758 static int choice = MAIN_CONTROL_GAME;
1759 static boolean button_pressed_last = FALSE;
1760 boolean button_pressed = FALSE;
1764 if (button == MB_MENU_INITIALIZE)
1766 DrawCursorAndText_Main(choice, TRUE, FALSE);
1771 if (mx || my) /* mouse input */
1775 for (i = 0; main_controls[i].nr != -1; i++)
1777 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1778 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1779 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1781 pos = main_controls[i].nr;
1787 // handle pressed/unpressed state for active/inactive menu buttons
1788 // (if pos != -1, "i" contains index position corresponding to "pos")
1790 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1791 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1792 button_pressed = TRUE;
1794 if (button_pressed != button_pressed_last)
1796 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1799 PlaySound(SND_MENU_BUTTON_PRESSING);
1801 PlaySound(SND_MENU_BUTTON_RELEASING);
1804 else if (dx || dy) /* keyboard input */
1806 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1807 choice == MAIN_CONTROL_SETUP))
1808 button = MB_MENU_CHOICE;
1813 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1815 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1817 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1819 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1821 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1823 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1825 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1829 CloseDoor(DOOR_CLOSE_2);
1831 game_status = GAME_MODE_LEVELNR;
1833 ChangeViewportPropertiesIfNeeded();
1835 DrawChooseLevelNr();
1837 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1843 PlaySound(SND_MENU_ITEM_ACTIVATING);
1845 DrawCursorAndText_Main(choice, FALSE, FALSE);
1846 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1853 PlaySound(SND_MENU_ITEM_SELECTING);
1855 if (pos == MAIN_CONTROL_NAME)
1857 game_status = GAME_MODE_PSEUDO_TYPENAME;
1859 HandleTypeName(strlen(setup.player_name), 0);
1861 else if (pos == MAIN_CONTROL_LEVELS)
1867 CloseDoor(DOOR_CLOSE_2);
1869 game_status = GAME_MODE_LEVELS;
1871 SaveLevelSetup_LastSeries();
1872 SaveLevelSetup_SeriesInfo();
1874 if (setup.internal.choose_from_top_leveldir)
1877 ChangeViewportPropertiesIfNeeded();
1879 DrawChooseLevelSet();
1882 else if (pos == MAIN_CONTROL_SCORES)
1886 CloseDoor(DOOR_CLOSE_2);
1888 game_status = GAME_MODE_SCORES;
1892 else if (pos == MAIN_CONTROL_EDITOR)
1894 if (leveldir_current->readonly &&
1895 !strEqual(setup.player_name, "Artsoft"))
1896 Request("This level is read only!", REQ_CONFIRM);
1900 CloseDoor(DOOR_CLOSE_2);
1902 game_status = GAME_MODE_EDITOR;
1904 FadeSetEnterScreen();
1908 else if (pos == MAIN_CONTROL_INFO)
1912 CloseDoor(DOOR_CLOSE_2);
1914 game_status = GAME_MODE_INFO;
1915 info_mode = INFO_MODE_MAIN;
1917 ChangeViewportPropertiesIfNeeded();
1921 else if (pos == MAIN_CONTROL_GAME)
1925 StartGameActions(options.network, setup.autorecord, level.random_seed);
1927 else if (pos == MAIN_CONTROL_SETUP)
1931 CloseDoor(DOOR_CLOSE_2);
1933 game_status = GAME_MODE_SETUP;
1934 setup_mode = SETUP_MODE_MAIN;
1936 ChangeViewportPropertiesIfNeeded();
1940 else if (pos == MAIN_CONTROL_QUIT)
1942 SaveLevelSetup_LastSeries();
1943 SaveLevelSetup_SeriesInfo();
1945 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1946 game_status = GAME_MODE_QUIT;
1951 button_pressed_last = button_pressed;
1955 /* ========================================================================= */
1956 /* info screen functions */
1957 /* ========================================================================= */
1959 static struct TokenInfo *info_info;
1960 static int num_info_info; /* number of info entries shown on screen */
1961 static int max_info_info; /* total number of info entries in list */
1963 static void execInfoTitleScreen()
1965 info_mode = INFO_MODE_TITLE;
1970 static void execInfoElements()
1972 info_mode = INFO_MODE_ELEMENTS;
1977 static void execInfoMusic()
1979 info_mode = INFO_MODE_MUSIC;
1984 static void execInfoCredits()
1986 info_mode = INFO_MODE_CREDITS;
1991 static void execInfoProgram()
1993 info_mode = INFO_MODE_PROGRAM;
1998 static void execInfoVersion()
2000 info_mode = INFO_MODE_VERSION;
2005 static void execInfoLevelSet()
2007 info_mode = INFO_MODE_LEVELSET;
2012 static void execExitInfo()
2014 game_status = GAME_MODE_MAIN;
2019 static struct TokenInfo info_info_main[] =
2021 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2022 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2023 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2024 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2025 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2026 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2027 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2028 { TYPE_EMPTY, NULL, "" },
2029 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2034 static int getMenuTextFont(int type)
2036 if (type & (TYPE_SWITCH |
2048 static struct TokenInfo *setup_info;
2049 static struct TokenInfo setup_info_input[];
2051 static struct TokenInfo *menu_info;
2053 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2054 int screen_pos, int menu_info_pos_raw,
2057 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2058 struct TokenInfo *ti = &token_info[pos];
2059 int xpos = MENU_SCREEN_START_XPOS;
2060 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2061 int font_nr = getMenuTextFont(ti->type);
2063 if (token_info == setup_info_input)
2064 font_nr = FONT_MENU_1;
2067 font_nr = FONT_ACTIVE(font_nr);
2069 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2071 if (ti->type & ~TYPE_SKIP_ENTRY)
2072 drawCursor(screen_pos, active);
2075 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2078 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2081 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2084 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2087 static char *screen_mode_text;
2088 static char *window_size_text;
2089 static char *scaling_type_text;
2091 static void drawSetupValue(int, int);
2093 static void drawMenuInfoList(int first_entry, int num_page_entries,
2094 int max_page_entries)
2098 if (first_entry + num_page_entries > max_page_entries)
2101 clearMenuListArea();
2103 for (i = 0; i < num_page_entries; i++)
2105 int menu_info_pos = first_entry + i;
2106 struct TokenInfo *si = &menu_info[menu_info_pos];
2107 void *value_ptr = si->value;
2109 /* set some entries to "unchangeable" according to other variables */
2110 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2111 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2112 (value_ptr == &setup.sound_music && !audio.music_available) ||
2113 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2114 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2115 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2116 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2117 si->type |= TYPE_GHOSTED;
2119 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2120 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2121 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2122 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2123 else if (si->type & ~TYPE_SKIP_ENTRY)
2124 initCursor(i, IMG_MENU_BUTTON);
2126 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2128 if (si->type & TYPE_VALUE &&
2129 menu_info == setup_info)
2130 drawSetupValue(i, menu_info_pos);
2134 static void DrawInfoScreen_Main()
2136 int fade_mask = REDRAW_FIELD;
2139 if (redraw_mask & REDRAW_ALL)
2140 fade_mask = REDRAW_ALL;
2142 if (CheckIfGlobalBorderHasChanged())
2143 fade_mask = REDRAW_ALL;
2147 FreeScreenGadgets();
2148 CreateScreenGadgets();
2150 CloseDoor(DOOR_CLOSE_2);
2152 /* (needed after displaying title screens which disable auto repeat) */
2153 KeyboardAutoRepeatOn();
2155 FadeSetLeaveScreen();
2159 ChangeViewportPropertiesIfNeeded();
2161 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2165 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2167 info_info = info_info_main;
2169 // determine maximal number of info entries that can be displayed on screen
2171 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2174 // determine maximal number of info entries available for menu of info screen
2176 for (i = 0; info_info[i].type != 0; i++)
2179 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2181 MapScreenGadgets(max_info_info);
2187 // needed after returning from title screens with different window size
2188 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2191 DrawMaskedBorder(fade_mask);
2198 static void changeSetupValue(int, int, int);
2200 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2201 int mode, int num_page_entries, int max_page_entries)
2203 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2204 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2205 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2206 int *num_page_entries_last = num_page_entries_all_last[game_status];
2207 int *choice_store = choice_stores[game_status];
2208 int *first_entry_store = first_entry_stores[game_status];
2209 int choice = choice_store[mode]; /* starts with 0 */
2210 int first_entry = first_entry_store[mode]; /* starts with 0 */
2212 int y = choice - first_entry;
2214 boolean position_set_by_scrollbar = (dx == 999);
2215 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2218 if (button == MB_MENU_INITIALIZE)
2220 // check if number of menu page entries has changed (may happen by change
2221 // of custom artwork definition value for 'list_size' for this menu screen)
2222 // (in this case, the last menu position most probably has to be corrected)
2223 if (num_page_entries != num_page_entries_last[mode])
2225 choice_store[mode] = first_entry_store[mode] = 0;
2227 choice = first_entry = 0;
2230 num_page_entries_last[mode] = num_page_entries;
2233 /* advance to first valid menu entry */
2234 while (choice < num_page_entries &&
2235 menu_info[choice].type & TYPE_SKIP_ENTRY)
2238 if (position_set_by_scrollbar)
2239 first_entry = first_entry_store[mode] = dy;
2241 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2242 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2244 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2246 if (choice < first_entry)
2248 choice = first_entry;
2250 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2253 else if (choice > first_entry + num_page_entries - 1)
2255 choice = first_entry + num_page_entries - 1;
2257 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2261 choice_store[mode] = choice;
2263 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2267 else if (button == MB_MENU_LEAVE)
2269 PlaySound(SND_MENU_ITEM_SELECTING);
2271 for (i = 0; i < max_page_entries; i++)
2273 if (menu_info[i].type & TYPE_LEAVE_MENU)
2275 void (*menu_callback_function)(void) = menu_info[i].value;
2279 menu_callback_function();
2281 break; /* absolutely needed because function changes 'menu_info'! */
2288 if (mx || my) /* mouse input */
2290 x = (mx - mSX) / 32;
2291 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2293 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2295 /* move cursor instead of scrolling when already at start/end of list */
2296 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2298 else if (dy == +1 * SCROLL_LINE &&
2299 first_entry + num_page_entries == max_page_entries)
2302 /* handle scrolling screen one line or page */
2304 y + dy > num_page_entries - 1)
2306 boolean redraw = FALSE;
2308 if (ABS(dy) == SCROLL_PAGE)
2309 step = num_page_entries - 1;
2311 if (dy < 0 && first_entry > 0)
2313 /* scroll page/line up */
2315 first_entry -= step;
2316 if (first_entry < 0)
2321 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2323 /* scroll page/line down */
2325 first_entry += step;
2326 if (first_entry + num_page_entries > max_page_entries)
2327 first_entry = MAX(0, max_page_entries - num_page_entries);
2334 choice += first_entry - first_entry_store[mode];
2336 if (choice < first_entry)
2338 choice = first_entry;
2340 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2343 else if (choice > first_entry + num_page_entries - 1)
2345 choice = first_entry + num_page_entries - 1;
2347 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2350 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2354 if (choice < first_entry ||
2355 choice > first_entry + num_page_entries - 1)
2356 first_entry += SIGN(dy);
2359 first_entry_store[mode] = first_entry;
2360 choice_store[mode] = choice;
2362 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2364 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2366 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2367 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2375 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2377 if (menu_info[choice].type & menu_navigation_type ||
2378 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2379 menu_info[choice].type & TYPE_YES_NO_AUTO)
2380 button = MB_MENU_CHOICE;
2385 /* jump to next non-empty menu entry (up or down) */
2386 while (first_entry + y > 0 &&
2387 first_entry + y < max_page_entries - 1 &&
2388 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2391 if (!IN_VIS_MENU(x, y))
2393 choice += y - y_old;
2395 if (choice < first_entry)
2396 first_entry = choice;
2397 else if (choice > first_entry + num_page_entries - 1)
2398 first_entry = choice - num_page_entries + 1;
2400 if (first_entry >= 0 &&
2401 first_entry + num_page_entries <= max_page_entries)
2403 first_entry_store[mode] = first_entry;
2405 if (choice < first_entry)
2406 choice = first_entry;
2407 else if (choice > first_entry + num_page_entries - 1)
2408 choice = first_entry + num_page_entries - 1;
2410 choice_store[mode] = choice;
2412 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2414 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2416 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2417 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2424 if (!anyScrollbarGadgetActive() &&
2425 IN_VIS_MENU(x, y) &&
2426 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2427 y >= 0 && y < num_page_entries)
2431 if (first_entry + y != choice &&
2432 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2434 PlaySound(SND_MENU_ITEM_ACTIVATING);
2436 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2437 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2439 choice = choice_store[mode] = first_entry + y;
2442 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2444 PlaySound(SND_MENU_ITEM_SELECTING);
2446 /* when selecting key headline, execute function for key value change */
2447 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2448 menu_info[first_entry + y + 1].type & TYPE_KEY)
2451 /* when selecting string value, execute function for list selection */
2452 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2453 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2456 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2458 void (*menu_callback_function)(void) =
2459 menu_info[first_entry + y].value;
2461 FadeSetFromType(menu_info[first_entry + y].type);
2463 menu_callback_function();
2465 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2466 menu_info == setup_info)
2468 changeSetupValue(y, first_entry + y, dx);
2474 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2476 menu_info = info_info;
2478 HandleMenuScreen(mx, my, dx, dy, button,
2479 info_mode, num_info_info, max_info_info);
2482 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2484 int ystart1 = mSY - SY + 100;
2485 int ystart2 = mSY - SY + 150;
2486 int ybottom = mSY - SY + SYSIZE - 20;
2488 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2490 FadeOut(REDRAW_FIELD);
2495 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2496 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2498 DrawTextSCentered(ybottom, FONT_TEXT_4,
2499 "Press any key or button for info menu");
2501 FadeIn(REDRAW_FIELD);
2504 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2506 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2507 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2508 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2509 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2510 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2511 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2512 int ystep = MENU_SCREEN_INFO_YSTEP;
2513 int element, action, direction;
2521 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2522 infoscreen_step[i] = infoscreen_frame[i] = 0;
2527 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2529 DrawTextSCentered(ybottom, FONT_TEXT_4,
2530 "Press any key or button for next page");
2536 while (helpanim_info[j].element != HELPANIM_LIST_END)
2538 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2543 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2552 j += infoscreen_step[i - start];
2554 element = helpanim_info[j].element;
2555 action = helpanim_info[j].action;
2556 direction = helpanim_info[j].direction;
2559 element = EL_UNKNOWN;
2561 if (action != -1 && direction != -1)
2562 graphic = el_act_dir2img(element, action, direction);
2563 else if (action != -1)
2564 graphic = el_act2img(element, action);
2565 else if (direction != -1)
2566 graphic = el_dir2img(element, direction);
2568 graphic = el2img(element);
2570 delay = helpanim_info[j++].delay;
2575 if (infoscreen_frame[i - start] == 0)
2578 infoscreen_frame[i - start] = delay - 1;
2582 sync_frame = delay - infoscreen_frame[i - start];
2583 infoscreen_frame[i - start]--;
2586 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2588 if (!infoscreen_frame[i - start])
2589 infoscreen_step[i - start] = 0;
2593 if (!infoscreen_frame[i - start])
2594 infoscreen_step[i - start]++;
2595 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2601 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2603 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2604 graphic, sync_frame, USE_MASKING);
2607 DrawInfoScreen_HelpText(element, action, direction, i - start);
2612 redraw_mask |= REDRAW_FIELD;
2617 static char *getHelpText(int element, int action, int direction)
2619 char token[MAX_LINE_LEN];
2621 strcpy(token, element_info[element].token_name);
2624 strcat(token, element_action_info[action].suffix);
2626 if (direction != -1)
2627 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2629 return getHashEntry(helptext_info, token);
2632 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2634 int font_nr = FONT_INFO_ELEMENTS;
2635 int font_width = getFontWidth(font_nr);
2636 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2637 int sy = mSY + 65 + 2 * 32 + 1;
2638 int ystep = TILEY + 4;
2639 int pad_x = sx - SX;
2640 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2641 int max_lines_per_text = 2;
2644 if (action != -1 && direction != -1) /* element.action.direction */
2645 text = getHelpText(element, action, direction);
2647 if (text == NULL && action != -1) /* element.action */
2648 text = getHelpText(element, action, -1);
2650 if (text == NULL && direction != -1) /* element.direction */
2651 text = getHelpText(element, -1, direction);
2653 if (text == NULL) /* base element */
2654 text = getHelpText(element, -1, -1);
2656 if (text == NULL) /* not found */
2657 text = "No description available";
2659 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2660 sy += getFontHeight(font_nr) / 2;
2662 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2663 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2664 TRUE, FALSE, FALSE);
2667 void DrawInfoScreen_TitleScreen()
2669 game_status_last_screen = GAME_MODE_INFO;
2670 game_status = GAME_MODE_TITLE;
2675 void HandleInfoScreen_TitleScreen(int button)
2677 HandleTitleScreen(0, 0, 0, 0, button);
2680 void DrawInfoScreen_Elements()
2682 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2684 FadeOut(REDRAW_FIELD);
2689 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2691 FadeIn(REDRAW_FIELD);
2696 void HandleInfoScreen_Elements(int button)
2698 static unsigned int info_delay = 0;
2699 static int num_anims;
2700 static int num_pages;
2702 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2705 if (button == MB_MENU_INITIALIZE)
2707 boolean new_element = TRUE;
2711 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2713 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2715 else if (new_element)
2718 new_element = FALSE;
2722 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2726 if (button == MB_MENU_LEAVE)
2728 PlaySound(SND_MENU_ITEM_SELECTING);
2730 info_mode = INFO_MODE_MAIN;
2735 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2737 if (button != MB_MENU_INITIALIZE)
2739 PlaySound(SND_MENU_ITEM_SELECTING);
2744 if (page >= num_pages)
2746 FadeSoundsAndMusic();
2748 info_mode = INFO_MODE_MAIN;
2755 FadeSetNextScreen();
2757 if (button != MB_MENU_INITIALIZE)
2758 FadeOut(REDRAW_FIELD);
2760 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2762 if (button != MB_MENU_INITIALIZE)
2763 FadeIn(REDRAW_FIELD);
2767 if (DelayReached(&info_delay, GameFrameDelay))
2768 if (page < num_pages)
2769 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2771 PlayMenuSoundIfLoop();
2775 void DrawInfoScreen_Music()
2777 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2779 FadeOut(REDRAW_FIELD);
2786 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2788 FadeIn(REDRAW_FIELD);
2791 void HandleInfoScreen_Music(int button)
2793 static struct MusicFileInfo *list = NULL;
2794 int ystart1 = mSY - SY + 100;
2795 int ystart2 = mSY - SY + 150;
2796 int ybottom = mSY - SY + SYSIZE - 20;
2799 if (button == MB_MENU_INITIALIZE)
2801 list = music_file_info;
2805 FadeSoundsAndMusic();
2810 DrawTextSCentered(ystart1, FONT_TEXT_1,
2811 "No music info for this level set.");
2813 DrawTextSCentered(ybottom, FONT_TEXT_4,
2814 "Press any key or button for info menu");
2820 if (button == MB_MENU_LEAVE)
2822 PlaySound(SND_MENU_ITEM_SELECTING);
2824 FadeSoundsAndMusic();
2826 info_mode = INFO_MODE_MAIN;
2831 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2835 if (button != MB_MENU_INITIALIZE)
2837 PlaySound(SND_MENU_ITEM_SELECTING);
2845 FadeSoundsAndMusic();
2847 info_mode = INFO_MODE_MAIN;
2853 FadeSoundsAndMusic();
2855 if (list != music_file_info)
2856 FadeSetNextScreen();
2858 if (button != MB_MENU_INITIALIZE)
2859 FadeOut(REDRAW_FIELD);
2866 int sound = list->music;
2868 if (sound_info[sound].loop)
2869 PlaySoundLoop(sound);
2873 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2877 PlayMusic(list->music);
2879 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2882 if (!strEqual(list->title, UNKNOWN_NAME))
2884 if (!strEqual(list->title_header, UNKNOWN_NAME))
2885 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2887 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2890 if (!strEqual(list->artist, UNKNOWN_NAME))
2892 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2893 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2895 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2897 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2900 if (!strEqual(list->album, UNKNOWN_NAME))
2902 if (!strEqual(list->album_header, UNKNOWN_NAME))
2903 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2905 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2907 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2910 if (!strEqual(list->year, UNKNOWN_NAME))
2912 if (!strEqual(list->year_header, UNKNOWN_NAME))
2913 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2915 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2917 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2920 DrawTextSCentered(ybottom, FONT_TEXT_4,
2921 "Press any key or button for next page");
2923 if (button != MB_MENU_INITIALIZE)
2924 FadeIn(REDRAW_FIELD);
2927 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2928 PlaySoundLoop(list->music);
2931 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2933 int ystart1 = mSY - SY + 100;
2934 int ystart2 = mSY - SY + 150;
2935 int ybottom = mSY - SY + SYSIZE - 20;
2941 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2945 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2946 "Special thanks to");
2947 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2949 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2951 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2952 "\"Boulder Dash\"");
2953 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2955 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2957 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2959 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2960 "First Star Software");
2962 else if (screen_nr == 1)
2964 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2965 "Special thanks to");
2966 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2967 "Klaus Heinz & Volker Wertich");
2968 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2970 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2971 "\"Emerald Mine\"");
2972 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2974 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2976 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2978 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2981 else if (screen_nr == 2)
2983 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2984 "Special thanks to");
2985 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2986 "Michael Stopp & Philip Jespersen");
2987 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2989 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2991 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2993 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2995 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2997 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2998 "Digital Integration");
3000 else if (screen_nr == 3)
3002 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3003 "Special thanks to");
3004 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3005 "Hiroyuki Imabayashi");
3006 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3008 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3010 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3012 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3016 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3019 else if (screen_nr == 4)
3021 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3022 "Special thanks to");
3023 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3025 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3027 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3028 "J\xfcrgen Bonhagen");
3029 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3030 "for the continuous creation");
3031 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3032 "of outstanding level sets");
3034 else if (screen_nr == 5)
3036 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3038 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3040 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3041 "for ideas and inspiration by");
3042 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3045 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3047 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3049 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3050 "for ideas and inspiration by");
3051 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3054 else if (screen_nr == 6)
3056 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3058 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3061 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3062 "for the code base used for the");
3063 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3064 "native Emerald Mine engine");
3066 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3067 "for the new Emerald Mine engine");
3070 else if (screen_nr == 7)
3072 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3074 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3076 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3077 "for the initial DOS port");
3079 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3081 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3083 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3084 "for some additional toons");
3086 else if (screen_nr == 8)
3088 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3089 "And not to forget:");
3090 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3092 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3093 "All those who contributed");
3094 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3095 "levels to this game");
3096 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3100 DrawTextSCentered(ybottom, FONT_TEXT_4,
3101 "Press any key or button for next page");
3104 void DrawInfoScreen_Credits()
3106 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3108 FadeSoundsAndMusic();
3110 FadeOut(REDRAW_FIELD);
3112 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3114 FadeIn(REDRAW_FIELD);
3117 void HandleInfoScreen_Credits(int button)
3119 static int screen_nr = 0;
3120 int num_screens = 9;
3122 if (button == MB_MENU_INITIALIZE)
3126 // DrawInfoScreen_CreditsScreen(screen_nr);
3129 if (button == MB_MENU_LEAVE)
3131 PlaySound(SND_MENU_ITEM_SELECTING);
3133 info_mode = INFO_MODE_MAIN;
3138 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3140 if (button != MB_MENU_INITIALIZE)
3142 PlaySound(SND_MENU_ITEM_SELECTING);
3147 if (screen_nr >= num_screens)
3149 FadeSoundsAndMusic();
3151 info_mode = INFO_MODE_MAIN;
3158 FadeSetNextScreen();
3160 if (button != MB_MENU_INITIALIZE)
3161 FadeOut(REDRAW_FIELD);
3163 DrawInfoScreen_CreditsScreen(screen_nr);
3165 if (button != MB_MENU_INITIALIZE)
3166 FadeIn(REDRAW_FIELD);
3170 PlayMenuSoundIfLoop();
3174 void DrawInfoScreen_Program()
3176 int ystart1 = mSY - SY + 100;
3177 int ystart2 = mSY - SY + 150;
3178 int ybottom = mSY - SY + SYSIZE - 20;
3181 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3183 FadeOut(REDRAW_FIELD);
3188 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3190 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3191 "This game is Freeware!");
3192 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3193 "If you like it, send e-mail to:");
3194 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3195 setup.internal.program_email);
3196 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3197 "More information and levels:");
3198 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3199 setup.internal.program_website);
3200 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3201 "If you have created new levels,");
3202 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3203 "send them to me to include them!");
3204 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3207 DrawTextSCentered(ybottom, FONT_TEXT_4,
3208 "Press any key or button for info menu");
3210 FadeIn(REDRAW_FIELD);
3213 void HandleInfoScreen_Program(int button)
3215 if (button == MB_MENU_LEAVE)
3217 PlaySound(SND_MENU_ITEM_SELECTING);
3219 info_mode = INFO_MODE_MAIN;
3224 else if (button == MB_MENU_CHOICE)
3226 PlaySound(SND_MENU_ITEM_SELECTING);
3228 FadeSoundsAndMusic();
3230 info_mode = INFO_MODE_MAIN;
3235 PlayMenuSoundIfLoop();
3239 void DrawInfoScreen_Version()
3241 int font_header = FONT_TEXT_3;
3242 int font_text = FONT_TEXT_2;
3243 int xstep = getFontWidth(font_text);
3244 int ystep = getFontHeight(font_text);
3245 int ystart1 = mSY - SY + 100;
3246 int ystart2 = mSY - SY + 150;
3247 int ybottom = mSY - SY + SYSIZE - 20;
3248 int xstart1 = mSX - SX + 2 * xstep;
3249 int xstart2 = mSX - SX + 18 * xstep;
3250 int xstart3 = mSX - SX + 28 * xstep;
3251 SDL_version sdl_version_compiled;
3252 const SDL_version *sdl_version_linked;
3253 int driver_name_len = 10;
3254 #if defined(TARGET_SDL2)
3255 SDL_version sdl_version_linked_ext;
3256 const char *driver_name = NULL;
3258 char driver_name[driver_name_len];
3261 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3263 FadeOut(REDRAW_FIELD);
3268 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3270 DrawTextF(xstart1, ystart2, font_header, "Name");
3271 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3274 DrawTextF(xstart1, ystart2, font_header, "Version");
3275 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3278 DrawTextF(xstart1, ystart2, font_header, "Platform");
3279 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3282 DrawTextF(xstart1, ystart2, font_header, "Target");
3283 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3286 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3287 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3289 ystart2 += 3 * ystep;
3290 DrawTextF(xstart1, ystart2, font_header, "Library");
3291 DrawTextF(xstart2, ystart2, font_header, "compiled");
3292 DrawTextF(xstart3, ystart2, font_header, "linked");
3294 SDL_VERSION(&sdl_version_compiled);
3295 #if defined(TARGET_SDL2)
3296 SDL_GetVersion(&sdl_version_linked_ext);
3297 sdl_version_linked = &sdl_version_linked_ext;
3299 sdl_version_linked = SDL_Linked_Version();
3302 ystart2 += 2 * ystep;
3303 DrawTextF(xstart1, ystart2, font_text, "SDL");
3304 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3305 sdl_version_compiled.major,
3306 sdl_version_compiled.minor,
3307 sdl_version_compiled.patch);
3308 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3309 sdl_version_linked->major,
3310 sdl_version_linked->minor,
3311 sdl_version_linked->patch);
3313 SDL_IMAGE_VERSION(&sdl_version_compiled);
3314 sdl_version_linked = IMG_Linked_Version();
3317 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3318 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3319 sdl_version_compiled.major,
3320 sdl_version_compiled.minor,
3321 sdl_version_compiled.patch);
3322 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3323 sdl_version_linked->major,
3324 sdl_version_linked->minor,
3325 sdl_version_linked->patch);
3327 SDL_MIXER_VERSION(&sdl_version_compiled);
3328 sdl_version_linked = Mix_Linked_Version();
3331 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3332 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3333 sdl_version_compiled.major,
3334 sdl_version_compiled.minor,
3335 sdl_version_compiled.patch);
3336 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3337 sdl_version_linked->major,
3338 sdl_version_linked->minor,
3339 sdl_version_linked->patch);
3341 SDL_NET_VERSION(&sdl_version_compiled);
3342 sdl_version_linked = SDLNet_Linked_Version();
3345 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3346 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3347 sdl_version_compiled.major,
3348 sdl_version_compiled.minor,
3349 sdl_version_compiled.patch);
3350 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3351 sdl_version_linked->major,
3352 sdl_version_linked->minor,
3353 sdl_version_linked->patch);
3355 ystart2 += 3 * ystep;
3356 DrawTextF(xstart1, ystart2, font_header, "Driver");
3357 DrawTextF(xstart2, ystart2, font_header, "Requested");
3358 DrawTextF(xstart3, ystart2, font_header, "Used");
3360 #if defined(TARGET_SDL2)
3361 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3363 SDL_VideoDriverName(driver_name, driver_name_len);
3366 ystart2 += 2 * ystep;
3367 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3368 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3369 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3371 #if defined(TARGET_SDL2)
3372 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3374 SDL_AudioDriverName(driver_name, driver_name_len);
3378 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3379 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3380 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3382 DrawTextSCentered(ybottom, FONT_TEXT_4,
3383 "Press any key or button for info menu");
3385 FadeIn(REDRAW_FIELD);
3388 void HandleInfoScreen_Version(int button)
3390 if (button == MB_MENU_LEAVE)
3392 PlaySound(SND_MENU_ITEM_SELECTING);
3394 info_mode = INFO_MODE_MAIN;
3399 else if (button == MB_MENU_CHOICE)
3401 PlaySound(SND_MENU_ITEM_SELECTING);
3403 FadeSoundsAndMusic();
3405 info_mode = INFO_MODE_MAIN;
3410 PlayMenuSoundIfLoop();
3414 void DrawInfoScreen_LevelSet()
3416 struct TitleMessageInfo *tmi = &readme;
3417 char *filename = getLevelSetInfoFilename();
3418 char *title = "Level Set Information:";
3419 int ystart1 = mSY - SY + 100;
3420 int ybottom = mSY - SY + SYSIZE - 20;
3422 if (filename == NULL)
3424 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3429 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3431 FadeOut(REDRAW_FIELD);
3436 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3438 /* if x position set to "-1", automatically determine by playfield width */
3440 tmi->x = SXSIZE / 2;
3442 /* if y position set to "-1", use static default value */
3446 /* if width set to "-1", automatically determine by playfield width */
3447 if (tmi->width == -1)
3448 tmi->width = SXSIZE - 2 * TILEX;
3450 /* if height set to "-1", automatically determine by playfield height */
3451 if (tmi->height == -1)
3452 tmi->height = SYSIZE - 20 - tmi->y - 10;
3454 /* if chars set to "-1", automatically determine by text and font width */
3455 if (tmi->chars == -1)
3456 tmi->chars = tmi->width / getFontWidth(tmi->font);
3458 tmi->width = tmi->chars * getFontWidth(tmi->font);
3460 /* if lines set to "-1", automatically determine by text and font height */
3461 if (tmi->lines == -1)
3462 tmi->lines = tmi->height / getFontHeight(tmi->font);
3464 tmi->height = tmi->lines * getFontHeight(tmi->font);
3466 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3467 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3468 tmi->autowrap, tmi->centered, tmi->parse_comments);
3470 DrawTextSCentered(ybottom, FONT_TEXT_4,
3471 "Press any key or button for info menu");
3473 FadeIn(REDRAW_FIELD);
3476 void HandleInfoScreen_LevelSet(int button)
3478 if (button == MB_MENU_LEAVE)
3480 PlaySound(SND_MENU_ITEM_SELECTING);
3482 info_mode = INFO_MODE_MAIN;
3487 else if (button == MB_MENU_CHOICE)
3489 PlaySound(SND_MENU_ITEM_SELECTING);
3491 FadeSoundsAndMusic();
3493 info_mode = INFO_MODE_MAIN;
3498 PlayMenuSoundIfLoop();
3502 static void DrawInfoScreen()
3504 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3506 if (info_mode == INFO_MODE_TITLE)
3507 DrawInfoScreen_TitleScreen();
3508 else if (info_mode == INFO_MODE_ELEMENTS)
3509 DrawInfoScreen_Elements();
3510 else if (info_mode == INFO_MODE_MUSIC)
3511 DrawInfoScreen_Music();
3512 else if (info_mode == INFO_MODE_CREDITS)
3513 DrawInfoScreen_Credits();
3514 else if (info_mode == INFO_MODE_PROGRAM)
3515 DrawInfoScreen_Program();
3516 else if (info_mode == INFO_MODE_VERSION)
3517 DrawInfoScreen_Version();
3518 else if (info_mode == INFO_MODE_LEVELSET)
3519 DrawInfoScreen_LevelSet();
3521 DrawInfoScreen_Main();
3523 if (info_mode != INFO_MODE_MAIN &&
3524 info_mode != INFO_MODE_TITLE &&
3525 info_mode != INFO_MODE_MUSIC)
3532 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3534 if (info_mode == INFO_MODE_TITLE)
3535 HandleInfoScreen_TitleScreen(button);
3536 else if (info_mode == INFO_MODE_ELEMENTS)
3537 HandleInfoScreen_Elements(button);
3538 else if (info_mode == INFO_MODE_MUSIC)
3539 HandleInfoScreen_Music(button);
3540 else if (info_mode == INFO_MODE_CREDITS)
3541 HandleInfoScreen_Credits(button);
3542 else if (info_mode == INFO_MODE_PROGRAM)
3543 HandleInfoScreen_Program(button);
3544 else if (info_mode == INFO_MODE_VERSION)
3545 HandleInfoScreen_Version(button);
3546 else if (info_mode == INFO_MODE_LEVELSET)
3547 HandleInfoScreen_LevelSet(button);
3549 HandleInfoScreen_Main(mx, my, dx, dy, button);
3553 /* ========================================================================= */
3554 /* type name functions */
3555 /* ========================================================================= */
3557 void HandleTypeName(int newxpos, Key key)
3559 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3560 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3561 struct TextPosInfo *pos = mci->pos_input;
3562 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3563 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3564 static int xpos = 0;
3565 int font_nr = pos->font;
3566 int font_active_nr = FONT_ACTIVE(font_nr);
3567 int font_width = getFontWidth(font_active_nr);
3568 char key_char = getValidConfigValueChar(getCharFromKey(key));
3569 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3570 boolean is_active = TRUE;
3572 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3576 strcpy(last_player_name, setup.player_name);
3580 #if defined(TARGET_SDL2)
3581 SDL_StartTextInput();
3584 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3586 setup.player_name[xpos] = key_char;
3587 setup.player_name[xpos + 1] = 0;
3591 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3595 setup.player_name[xpos] = 0;
3597 else if (key == KSYM_Return && xpos > 0)
3603 game_status = GAME_MODE_MAIN;
3605 else if (key == KSYM_Escape)
3607 strcpy(setup.player_name, last_player_name);
3611 game_status = GAME_MODE_MAIN;
3616 pos->width = (strlen(setup.player_name) + 1) * font_width;
3617 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3619 DrawText(startx, starty, setup.player_name, font_active_nr);
3620 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3624 pos->width = strlen(setup.player_name) * font_width;
3625 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3627 DrawText(startx, starty, setup.player_name, font_nr);
3629 #if defined(TARGET_SDL2)
3630 SDL_StopTextInput();
3636 /* ========================================================================= */
3637 /* tree menu functions */
3638 /* ========================================================================= */
3640 static void DrawChooseTree(TreeInfo **ti_ptr)
3642 int fade_mask = REDRAW_FIELD;
3644 if (CheckIfGlobalBorderHasChanged())
3645 fade_mask = REDRAW_ALL;
3647 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3649 game_status = GAME_MODE_MAIN;
3658 FreeScreenGadgets();
3659 CreateScreenGadgets();
3661 CloseDoor(DOOR_CLOSE_2);
3665 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3669 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3670 MapScreenTreeGadgets(*ti_ptr);
3672 DrawMaskedBorder(fade_mask);
3679 static void drawChooseTreeList(int first_entry, int num_page_entries,
3683 char *title_string = NULL;
3684 int yoffset_sets = MENU_TITLE1_YPOS;
3685 int yoffset_setup = 16;
3686 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3687 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3688 int last_game_status = game_status; /* save current game status */
3690 title_string = ti->infotext;
3692 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3694 clearMenuListArea();
3696 for (i = 0; i < num_page_entries; i++)
3698 TreeInfo *node, *node_first;
3699 int entry_pos = first_entry + i;
3700 int xpos = MENU_SCREEN_START_XPOS;
3701 int ypos = MENU_SCREEN_START_YPOS + i;
3702 int startx = mSX + xpos * 32;
3703 int starty = mSY + ypos * 32;
3704 int font_nr = FONT_TEXT_1;
3705 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3706 int startx_text = startx + font_xoffset;
3707 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3708 int text_size = startx_scrollbar - startx_text;
3709 int max_buffer_len = text_size / getFontWidth(font_nr);
3710 char buffer[max_buffer_len + 1];
3712 node_first = getTreeInfoFirstGroupEntry(ti);
3713 node = getTreeInfoFromPos(node_first, entry_pos);
3715 strncpy(buffer, node->name, max_buffer_len);
3716 buffer[max_buffer_len] = '\0';
3718 DrawText(startx, starty, buffer, font_nr + node->color);
3720 if (node->parent_link)
3721 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3722 else if (node->level_group)
3723 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3725 initCursor(i, IMG_MENU_BUTTON);
3728 game_status = last_game_status; /* restore current game status */
3730 redraw_mask |= REDRAW_FIELD;
3733 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3735 TreeInfo *node, *node_first;
3736 int x, last_redraw_mask = redraw_mask;
3737 int ypos = MENU_TITLE2_YPOS;
3738 int font_nr = FONT_TITLE_2;
3740 if (ti->type == TREE_TYPE_LEVEL_NR)
3741 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3743 if (ti->type != TREE_TYPE_LEVEL_DIR)
3746 node_first = getTreeInfoFirstGroupEntry(ti);
3747 node = getTreeInfoFromPos(node_first, entry_pos);
3749 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3751 if (node->parent_link)
3752 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3753 node->node_parent->name);
3754 else if (node->level_group)
3755 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3757 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3758 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3759 node->levels, (node->levels > 1 ? "levels" : "level"),
3762 /* let BackToFront() redraw only what is needed */
3763 redraw_mask = last_redraw_mask;
3764 for (x = 0; x < SCR_FIELDX; x++)
3765 MarkTileDirty(x, 1);
3768 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3771 TreeInfo *ti = *ti_ptr;
3773 int y = ti->cl_cursor;
3774 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3775 int num_entries = numTreeInfoInGroup(ti);
3776 int num_page_entries;
3777 int last_game_status = game_status; /* save current game status */
3778 boolean position_set_by_scrollbar = (dx == 999);
3780 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3781 num_page_entries = num_entries;
3783 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3785 game_status = last_game_status; /* restore current game status */
3787 if (button == MB_MENU_INITIALIZE)
3789 int num_entries = numTreeInfoInGroup(ti);
3790 int entry_pos = posTreeInfo(ti);
3792 if (ti->cl_first == -1)
3794 /* only on initialization */
3795 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3796 ti->cl_cursor = entry_pos - ti->cl_first;
3798 else if (ti->cl_cursor >= num_page_entries ||
3799 (num_entries > num_page_entries &&
3800 num_entries - ti->cl_first < num_page_entries))
3802 /* only after change of list size (by custom graphic configuration) */
3803 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3804 ti->cl_cursor = entry_pos - ti->cl_first;
3807 if (position_set_by_scrollbar)
3810 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3813 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3814 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3815 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3819 else if (button == MB_MENU_LEAVE)
3823 PlaySound(SND_MENU_ITEM_SELECTING);
3825 if (ti->node_parent)
3827 *ti_ptr = ti->node_parent;
3828 DrawChooseTree(ti_ptr);
3830 else if (game_status == GAME_MODE_SETUP)
3832 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3833 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3834 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3836 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3837 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3838 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3839 execSetupGraphics();
3840 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3841 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3842 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3844 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3845 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3846 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3853 if (game_status == GAME_MODE_LEVELNR)
3855 int new_level_nr = atoi(level_number_current->identifier);
3857 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3860 game_status = GAME_MODE_MAIN;
3868 if (mx || my) /* mouse input */
3870 int last_game_status = game_status; /* save current game status */
3872 x = (mx - mSX) / 32;
3873 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3875 game_status = last_game_status; /* restore current game status */
3877 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3879 /* move cursor instead of scrolling when already at start/end of list */
3880 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3882 else if (dy == +1 * SCROLL_LINE &&
3883 ti->cl_first + num_page_entries == num_entries)
3886 /* handle scrolling screen one line or page */
3887 if (ti->cl_cursor + dy < 0 ||
3888 ti->cl_cursor + dy > num_page_entries - 1)
3890 boolean redraw = FALSE;
3892 if (ABS(dy) == SCROLL_PAGE)
3893 step = num_page_entries - 1;
3895 if (dy < 0 && ti->cl_first > 0)
3897 /* scroll page/line up */
3899 ti->cl_first -= step;
3900 if (ti->cl_first < 0)
3905 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3907 /* scroll page/line down */
3909 ti->cl_first += step;
3910 if (ti->cl_first + num_page_entries > num_entries)
3911 ti->cl_first = MAX(0, num_entries - num_page_entries);
3918 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3919 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3920 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3922 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3929 /* handle moving cursor one line */
3930 y = ti->cl_cursor + dy;
3935 TreeInfo *node_first, *node_cursor;
3936 int entry_pos = ti->cl_first + y;
3938 node_first = getTreeInfoFirstGroupEntry(ti);
3939 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3941 if (node_cursor->node_group)
3945 PlaySound(SND_MENU_ITEM_SELECTING);
3947 node_cursor->cl_first = ti->cl_first;
3948 node_cursor->cl_cursor = ti->cl_cursor;
3949 *ti_ptr = node_cursor->node_group;
3950 DrawChooseTree(ti_ptr);
3955 else if (dx == -1 && ti->node_parent)
3959 PlaySound(SND_MENU_ITEM_SELECTING);
3961 *ti_ptr = ti->node_parent;
3962 DrawChooseTree(ti_ptr);
3967 if (!anyScrollbarGadgetActive() &&
3968 IN_VIS_MENU(x, y) &&
3969 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3970 y >= 0 && y < num_page_entries)
3974 if (y != ti->cl_cursor)
3976 PlaySound(SND_MENU_ITEM_ACTIVATING);
3978 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3979 drawChooseTreeCursor(y, TRUE);
3980 drawChooseTreeInfo(ti->cl_first + y, ti);
3987 TreeInfo *node_first, *node_cursor;
3988 int entry_pos = ti->cl_first + y;
3990 PlaySound(SND_MENU_ITEM_SELECTING);
3992 node_first = getTreeInfoFirstGroupEntry(ti);
3993 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3995 if (node_cursor->node_group)
3999 node_cursor->cl_first = ti->cl_first;
4000 node_cursor->cl_cursor = ti->cl_cursor;
4001 *ti_ptr = node_cursor->node_group;
4002 DrawChooseTree(ti_ptr);
4004 else if (node_cursor->parent_link)
4008 *ti_ptr = node_cursor->node_parent;
4009 DrawChooseTree(ti_ptr);
4015 node_cursor->cl_first = ti->cl_first;
4016 node_cursor->cl_cursor = ti->cl_cursor;
4017 *ti_ptr = node_cursor;
4019 if (ti->type == TREE_TYPE_LEVEL_DIR)
4021 LoadLevelSetup_SeriesInfo();
4023 SaveLevelSetup_LastSeries();
4024 SaveLevelSetup_SeriesInfo();
4028 if (game_status == GAME_MODE_SETUP)
4030 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4031 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4032 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4034 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4035 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4036 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4037 execSetupGraphics();
4038 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4039 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4040 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4042 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4043 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4044 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4051 if (game_status == GAME_MODE_LEVELNR)
4053 int new_level_nr = atoi(level_number_current->identifier);
4055 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4058 game_status = GAME_MODE_MAIN;
4067 void DrawChooseLevelSet()
4069 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4071 DrawChooseTree(&leveldir_current);
4077 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4079 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4082 void DrawChooseLevelNr()
4086 if (level_number != NULL)
4088 freeTreeInfo(level_number);
4090 level_number = NULL;
4093 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4095 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4096 char identifier[32], name[32];
4099 /* temporarily load level info to get level name */
4100 LoadLevelInfoOnly(i);
4102 ti->node_top = &level_number;
4103 ti->sort_priority = 10000 + value;
4104 ti->color = (level.no_valid_file ? FC_BLUE :
4105 LevelStats_getSolved(i) ? FC_GREEN :
4106 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4108 sprintf(identifier, "%d", value);
4109 sprintf(name, "%03d: %s", value,
4110 (level.no_valid_file ? "(no file)" : level.name));
4112 setString(&ti->identifier, identifier);
4113 setString(&ti->name, name);
4114 setString(&ti->name_sorting, name);
4116 pushTreeInfo(&level_number, ti);
4119 /* sort level number values to start with lowest level number */
4120 sortTreeInfo(&level_number);
4122 /* set current level number to current level number */
4123 level_number_current =
4124 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4126 /* if that also fails, set current level number to first available level */
4127 if (level_number_current == NULL)
4128 level_number_current = level_number;
4130 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4132 DrawChooseTree(&level_number_current);
4138 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4140 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4143 void DrawHallOfFame(int highlight_position)
4145 int fade_mask = REDRAW_FIELD;
4147 /* required before door position may be changed in next step */
4148 CloseDoor(DOOR_CLOSE_ALL);
4150 /* needed if different viewport properties defined for scores */
4151 ChangeViewportPropertiesIfNeeded();
4153 if (CheckIfGlobalBorderHasChanged())
4154 fade_mask = REDRAW_ALL;
4157 FadeSoundsAndMusic();
4159 /* (this is needed when called from GameEnd() after winning a game) */
4160 KeyboardAutoRepeatOn();
4163 /* (this is needed when called from GameEnd() after winning a game) */
4164 SetDrawDeactivationMask(REDRAW_NONE);
4165 SetDrawBackgroundMask(REDRAW_FIELD);
4167 if (highlight_position < 0)
4168 LoadScore(level_nr);
4170 FadeSetEnterScreen();
4179 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4181 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4183 DrawMaskedBorder(fade_mask);
4188 static void drawHallOfFameList(int first_entry, int highlight_position)
4192 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4195 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4196 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4197 "HighScores of Level %d", level_nr);
4199 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4201 int entry = first_entry + i;
4202 boolean active = (entry == highlight_position);
4203 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4204 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4205 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4206 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4207 int dx1 = 3 * getFontWidth(font_nr1);
4208 int dx2 = dx1 + getFontWidth(font_nr1);
4209 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4210 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4211 int sy = mSY + 64 + i * 32;
4213 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4214 DrawText(mSX + dx1, sy, ".", font_nr1);
4216 for (j = 0; j < num_dots; j++)
4217 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4219 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4220 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4222 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4225 redraw_mask |= REDRAW_FIELD;
4228 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4230 static int first_entry = 0;
4231 static int highlight_position = 0;
4232 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4234 if (button == MB_MENU_INITIALIZE)
4237 highlight_position = mx;
4238 drawHallOfFameList(first_entry, highlight_position);
4243 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4244 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4248 if (first_entry > 0)
4250 first_entry -= step;
4251 if (first_entry < 0)
4254 drawHallOfFameList(first_entry, highlight_position);
4259 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4261 first_entry += step;
4262 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4263 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4265 drawHallOfFameList(first_entry, highlight_position);
4268 else if (button == MB_MENU_LEAVE)
4270 PlaySound(SND_MENU_ITEM_SELECTING);
4272 FadeSound(SND_BACKGROUND_SCORES);
4274 game_status = GAME_MODE_MAIN;
4278 else if (button == MB_MENU_CHOICE)
4280 PlaySound(SND_MENU_ITEM_SELECTING);
4282 FadeSound(SND_BACKGROUND_SCORES);
4284 game_status = GAME_MODE_MAIN;
4289 if (game_status == GAME_MODE_SCORES)
4290 PlayMenuSoundIfLoop();
4294 /* ========================================================================= */
4295 /* setup screen functions */
4296 /* ========================================================================= */
4298 static struct TokenInfo *setup_info;
4299 static int num_setup_info; /* number of setup entries shown on screen */
4300 static int max_setup_info; /* total number of setup entries in list */
4302 static char *screen_mode_text;
4303 static char *window_size_text;
4304 static char *scaling_type_text;
4305 static char *scroll_delay_text;
4306 static char *snapshot_mode_text;
4307 static char *game_speed_text;
4308 static char *graphics_set_name;
4309 static char *sounds_set_name;
4310 static char *music_set_name;
4311 static char *volume_simple_text;
4312 static char *volume_loops_text;
4313 static char *volume_music_text;
4314 static char *touch_controls_text;
4315 static char *move_distance_text;
4316 static char *drop_distance_text;
4318 static void execSetupMain()
4320 setup_mode = SETUP_MODE_MAIN;
4325 static void execSetupGame_setGameSpeeds()
4327 if (game_speeds == NULL)
4331 for (i = 0; game_speeds_list[i].value != -1; i++)
4333 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4334 char identifier[32], name[32];
4335 int value = game_speeds_list[i].value;
4336 char *text = game_speeds_list[i].text;
4338 ti->node_top = &game_speeds;
4339 ti->sort_priority = 10000 - value;
4341 sprintf(identifier, "%d", value);
4342 sprintf(name, "%s", text);
4344 setString(&ti->identifier, identifier);
4345 setString(&ti->name, name);
4346 setString(&ti->name_sorting, name);
4347 setString(&ti->infotext, "Game Speed");
4349 pushTreeInfo(&game_speeds, ti);
4352 /* sort game speed values to start with slowest game speed */
4353 sortTreeInfo(&game_speeds);
4355 /* set current game speed to configured game speed value */
4356 game_speed_current =
4357 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4359 /* if that fails, set current game speed to reliable default value */
4360 if (game_speed_current == NULL)
4361 game_speed_current =
4362 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4364 /* if that also fails, set current game speed to first available speed */
4365 if (game_speed_current == NULL)
4366 game_speed_current = game_speeds;
4369 setup.game_frame_delay = atoi(game_speed_current->identifier);
4371 /* needed for displaying game speed text instead of identifier */
4372 game_speed_text = game_speed_current->name;
4375 static void execSetupGame_setScrollDelays()
4377 if (scroll_delays == NULL)
4381 for (i = 0; scroll_delays_list[i].value != -1; i++)
4383 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4384 char identifier[32], name[32];
4385 int value = scroll_delays_list[i].value;
4386 char *text = scroll_delays_list[i].text;
4388 ti->node_top = &scroll_delays;
4389 ti->sort_priority = value;
4391 sprintf(identifier, "%d", value);
4392 sprintf(name, "%s", text);
4394 setString(&ti->identifier, identifier);
4395 setString(&ti->name, name);
4396 setString(&ti->name_sorting, name);
4397 setString(&ti->infotext, "Scaling Type");
4399 pushTreeInfo(&scroll_delays, ti);
4402 /* sort scaling type values to start with lowest scaling type value */
4403 sortTreeInfo(&scroll_delays);
4405 /* set current scaling type value to configured scaling type value */
4406 scroll_delay_current =
4407 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4409 /* if that fails, set current scaling type to reliable default value */
4410 if (scroll_delay_current == NULL)
4411 scroll_delay_current =
4412 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4414 /* if that also fails, set current scaling type to first available value */
4415 if (scroll_delay_current == NULL)
4416 scroll_delay_current = scroll_delays;
4419 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4421 /* needed for displaying scaling type text instead of identifier */
4422 scroll_delay_text = scroll_delay_current->name;
4425 static void execSetupGame_setSnapshotModes()
4427 if (snapshot_modes == NULL)
4431 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4433 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4434 char identifier[32], name[32];
4435 char *value = snapshot_modes_list[i].value;
4436 char *text = snapshot_modes_list[i].text;
4438 ti->node_top = &snapshot_modes;
4439 ti->sort_priority = i;
4441 sprintf(identifier, "%s", value);
4442 sprintf(name, "%s", text);
4444 setString(&ti->identifier, identifier);
4445 setString(&ti->name, name);
4446 setString(&ti->name_sorting, name);
4447 setString(&ti->infotext, "Snapshot Mode");
4449 pushTreeInfo(&snapshot_modes, ti);
4452 /* sort snapshot mode values to start with lowest snapshot mode value */
4453 sortTreeInfo(&snapshot_modes);
4455 /* set current snapshot mode value to configured snapshot mode value */
4456 snapshot_mode_current =
4457 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4459 /* if that fails, set current snapshot mode to reliable default value */
4460 if (snapshot_mode_current == NULL)
4461 snapshot_mode_current =
4462 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4464 /* if that also fails, set current snapshot mode to first available value */
4465 if (snapshot_mode_current == NULL)
4466 snapshot_mode_current = snapshot_modes;
4469 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4471 /* needed for displaying snapshot mode text instead of identifier */
4472 snapshot_mode_text = snapshot_mode_current->name;
4475 static void execSetupGame()
4477 execSetupGame_setGameSpeeds();
4478 execSetupGame_setScrollDelays();
4479 execSetupGame_setSnapshotModes();
4481 setup_mode = SETUP_MODE_GAME;
4486 static void execSetupChooseGameSpeed()
4488 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4493 static void execSetupChooseScrollDelay()
4495 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4500 static void execSetupChooseSnapshotMode()
4502 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4507 static void execSetupEditor()
4509 setup_mode = SETUP_MODE_EDITOR;
4514 static void execSetupGraphics_setWindowSizes(boolean update_list)
4516 if (window_sizes != NULL && update_list)
4518 freeTreeInfo(window_sizes);
4520 window_sizes = NULL;
4523 if (window_sizes == NULL)
4525 boolean current_window_size_found = FALSE;
4528 for (i = 0; window_sizes_list[i].value != -1; i++)
4530 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4531 char identifier[32], name[32];
4532 int value = window_sizes_list[i].value;
4533 char *text = window_sizes_list[i].text;
4535 ti->node_top = &window_sizes;
4536 ti->sort_priority = value;
4538 sprintf(identifier, "%d", value);
4539 sprintf(name, "%s", text);
4541 setString(&ti->identifier, identifier);
4542 setString(&ti->name, name);
4543 setString(&ti->name_sorting, name);
4544 setString(&ti->infotext, "Window Scaling");
4546 pushTreeInfo(&window_sizes, ti);
4548 if (value == setup.window_scaling_percent)
4549 current_window_size_found = TRUE;
4552 if (!current_window_size_found)
4554 // add entry for non-preset window scaling value
4556 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4557 char identifier[32], name[32];
4558 int value = setup.window_scaling_percent;
4560 ti->node_top = &window_sizes;
4561 ti->sort_priority = value;
4563 sprintf(identifier, "%d", value);
4564 sprintf(name, "%d %% (Current)", value);
4566 setString(&ti->identifier, identifier);
4567 setString(&ti->name, name);
4568 setString(&ti->name_sorting, name);
4569 setString(&ti->infotext, "Window Scaling");
4571 pushTreeInfo(&window_sizes, ti);
4574 /* sort window size values to start with lowest window size value */
4575 sortTreeInfo(&window_sizes);
4577 /* set current window size value to configured window size value */
4578 window_size_current =
4579 getTreeInfoFromIdentifier(window_sizes,
4580 i_to_a(setup.window_scaling_percent));
4582 /* if that fails, set current window size to reliable default value */
4583 if (window_size_current == NULL)
4584 window_size_current =
4585 getTreeInfoFromIdentifier(window_sizes,
4586 i_to_a(STD_WINDOW_SCALING_PERCENT));
4588 /* if that also fails, set current window size to first available value */
4589 if (window_size_current == NULL)
4590 window_size_current = window_sizes;
4593 setup.window_scaling_percent = atoi(window_size_current->identifier);
4595 /* needed for displaying window size text instead of identifier */
4596 window_size_text = window_size_current->name;
4599 static void execSetupGraphics_setScalingTypes()
4601 if (scaling_types == NULL)
4605 for (i = 0; scaling_types_list[i].value != NULL; i++)
4607 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4608 char identifier[32], name[32];
4609 char *value = scaling_types_list[i].value;
4610 char *text = scaling_types_list[i].text;
4612 ti->node_top = &scaling_types;
4613 ti->sort_priority = i;
4615 sprintf(identifier, "%s", value);
4616 sprintf(name, "%s", text);
4618 setString(&ti->identifier, identifier);
4619 setString(&ti->name, name);
4620 setString(&ti->name_sorting, name);
4621 setString(&ti->infotext, "Anti-Aliasing");
4623 pushTreeInfo(&scaling_types, ti);
4626 /* sort scaling type values to start with lowest scaling type value */
4627 sortTreeInfo(&scaling_types);
4629 /* set current scaling type value to configured scaling type value */
4630 scaling_type_current =
4631 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4633 /* if that fails, set current scaling type to reliable default value */
4634 if (scaling_type_current == NULL)
4635 scaling_type_current =
4636 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4638 /* if that also fails, set current scaling type to first available value */
4639 if (scaling_type_current == NULL)
4640 scaling_type_current = scaling_types;
4643 setup.window_scaling_quality = scaling_type_current->identifier;
4645 /* needed for displaying scaling type text instead of identifier */
4646 scaling_type_text = scaling_type_current->name;
4649 static void execSetupGraphics_setScreenModes()
4651 // if (screen_modes == NULL && video.fullscreen_available)
4652 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4656 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4658 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4659 char identifier[32], name[32];
4660 int x = video.fullscreen_modes[i].width;
4661 int y = video.fullscreen_modes[i].height;
4664 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4666 ti->node_top = &screen_modes;
4667 ti->sort_priority = x * 10000 + y;
4669 sprintf(identifier, "%dx%d", x, y);
4670 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4672 setString(&ti->identifier, identifier);
4673 setString(&ti->name, name);
4674 setString(&ti->name_sorting, name);
4675 setString(&ti->infotext, "Fullscreen Mode");
4677 pushTreeInfo(&screen_modes, ti);
4680 /* sort fullscreen modes to start with lowest available screen resolution */
4681 sortTreeInfo(&screen_modes);
4683 /* set current screen mode for fullscreen mode to configured setup value */
4684 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4685 setup.fullscreen_mode);
4687 /* if that fails, set current screen mode to reliable default value */
4688 if (screen_mode_current == NULL)
4689 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4690 DEFAULT_FULLSCREEN_MODE);
4692 /* if that also fails, set current screen mode to first available mode */
4693 if (screen_mode_current == NULL)
4694 screen_mode_current = screen_modes;
4696 if (screen_mode_current == NULL)
4697 video.fullscreen_available = FALSE;
4700 // if (video.fullscreen_available)
4701 if (screen_mode_current != NULL)
4703 setup.fullscreen_mode = screen_mode_current->identifier;
4705 /* needed for displaying screen mode name instead of identifier */
4706 screen_mode_text = screen_mode_current->name;
4710 static void execSetupGraphics()
4712 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4714 // update "setup.window_scaling_percent" from list selection
4715 execSetupGraphics_setWindowSizes(FALSE);
4719 // update list selection from "setup.window_scaling_percent"
4720 execSetupGraphics_setWindowSizes(TRUE);
4723 execSetupGraphics_setScalingTypes();
4724 execSetupGraphics_setScreenModes();
4726 setup_mode = SETUP_MODE_GRAPHICS;
4730 #if defined(TARGET_SDL2)
4731 // window scaling may have changed at this point
4732 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4734 // window scaling quality may have changed at this point
4735 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4736 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4740 #if !defined(PLATFORM_ANDROID)
4741 #if defined(TARGET_SDL2)
4742 static void execSetupChooseWindowSize()
4744 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4749 static void execSetupChooseScalingType()
4751 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4756 static void execSetupChooseScreenMode()
4758 if (!video.fullscreen_available)
4761 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4768 static void execSetupChooseVolumeSimple()
4770 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4775 static void execSetupChooseVolumeLoops()
4777 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4782 static void execSetupChooseVolumeMusic()
4784 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4789 static void execSetupSound()
4791 if (volumes_simple == NULL)
4793 boolean current_volume_simple_found = FALSE;
4796 for (i = 0; volumes_list[i].value != -1; i++)
4798 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4799 char identifier[32], name[32];
4800 int value = volumes_list[i].value;
4801 char *text = volumes_list[i].text;
4803 ti->node_top = &volumes_simple;
4804 ti->sort_priority = value;
4806 sprintf(identifier, "%d", value);
4807 sprintf(name, "%s", text);
4809 setString(&ti->identifier, identifier);
4810 setString(&ti->name, name);
4811 setString(&ti->name_sorting, name);
4812 setString(&ti->infotext, "Sound Volume");
4814 pushTreeInfo(&volumes_simple, ti);
4816 if (value == setup.volume_simple)
4817 current_volume_simple_found = TRUE;
4820 if (!current_volume_simple_found)
4822 // add entry for non-preset volume value
4824 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4825 char identifier[32], name[32];
4826 int value = setup.volume_simple;
4828 ti->node_top = &volumes_simple;
4829 ti->sort_priority = value;
4831 sprintf(identifier, "%d", value);
4832 sprintf(name, "%d %% (Current)", value);
4834 setString(&ti->identifier, identifier);
4835 setString(&ti->name, name);
4836 setString(&ti->name_sorting, name);
4837 setString(&ti->infotext, "Sound Volume");
4839 pushTreeInfo(&volumes_simple, ti);
4842 /* sort volume values to start with lowest volume value */
4843 sortTreeInfo(&volumes_simple);
4845 /* set current volume value to configured volume value */
4846 volume_simple_current =
4847 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4849 /* if that fails, set current volume to reliable default value */
4850 if (volume_simple_current == NULL)
4851 volume_simple_current =
4852 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4854 /* if that also fails, set current volume to first available value */
4855 if (volume_simple_current == NULL)
4856 volume_simple_current = volumes_simple;
4859 if (volumes_loops == NULL)
4861 boolean current_volume_loops_found = FALSE;
4864 for (i = 0; volumes_list[i].value != -1; i++)
4866 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4867 char identifier[32], name[32];
4868 int value = volumes_list[i].value;
4869 char *text = volumes_list[i].text;
4871 ti->node_top = &volumes_loops;
4872 ti->sort_priority = value;
4874 sprintf(identifier, "%d", value);
4875 sprintf(name, "%s", text);
4877 setString(&ti->identifier, identifier);
4878 setString(&ti->name, name);
4879 setString(&ti->name_sorting, name);
4880 setString(&ti->infotext, "Loops Volume");
4882 pushTreeInfo(&volumes_loops, ti);
4884 if (value == setup.volume_loops)
4885 current_volume_loops_found = TRUE;
4888 if (!current_volume_loops_found)
4890 // add entry for non-preset volume value
4892 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4893 char identifier[32], name[32];
4894 int value = setup.volume_loops;
4896 ti->node_top = &volumes_loops;
4897 ti->sort_priority = value;
4899 sprintf(identifier, "%d", value);
4900 sprintf(name, "%d %% (Current)", value);
4902 setString(&ti->identifier, identifier);
4903 setString(&ti->name, name);
4904 setString(&ti->name_sorting, name);
4905 setString(&ti->infotext, "Loops Volume");
4907 pushTreeInfo(&volumes_loops, ti);
4910 /* sort volume values to start with lowest volume value */
4911 sortTreeInfo(&volumes_loops);
4913 /* set current volume value to configured volume value */
4914 volume_loops_current =
4915 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4917 /* if that fails, set current volume to reliable default value */
4918 if (volume_loops_current == NULL)
4919 volume_loops_current =
4920 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4922 /* if that also fails, set current volume to first available value */
4923 if (volume_loops_current == NULL)
4924 volume_loops_current = volumes_loops;
4927 if (volumes_music == NULL)
4929 boolean current_volume_music_found = FALSE;
4932 for (i = 0; volumes_list[i].value != -1; i++)
4934 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4935 char identifier[32], name[32];
4936 int value = volumes_list[i].value;
4937 char *text = volumes_list[i].text;
4939 ti->node_top = &volumes_music;
4940 ti->sort_priority = value;
4942 sprintf(identifier, "%d", value);
4943 sprintf(name, "%s", text);
4945 setString(&ti->identifier, identifier);
4946 setString(&ti->name, name);
4947 setString(&ti->name_sorting, name);
4948 setString(&ti->infotext, "Music Volume");
4950 pushTreeInfo(&volumes_music, ti);
4952 if (value == setup.volume_music)
4953 current_volume_music_found = TRUE;
4956 if (!current_volume_music_found)
4958 // add entry for non-preset volume value
4960 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4961 char identifier[32], name[32];
4962 int value = setup.volume_music;
4964 ti->node_top = &volumes_music;
4965 ti->sort_priority = value;
4967 sprintf(identifier, "%d", value);
4968 sprintf(name, "%d %% (Current)", value);
4970 setString(&ti->identifier, identifier);
4971 setString(&ti->name, name);
4972 setString(&ti->name_sorting, name);
4973 setString(&ti->infotext, "Music Volume");
4975 pushTreeInfo(&volumes_music, ti);
4978 /* sort volume values to start with lowest volume value */
4979 sortTreeInfo(&volumes_music);
4981 /* set current volume value to configured volume value */
4982 volume_music_current =
4983 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4985 /* if that fails, set current volume to reliable default value */
4986 if (volume_music_current == NULL)
4987 volume_music_current =
4988 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4990 /* if that also fails, set current volume to first available value */
4991 if (volume_music_current == NULL)
4992 volume_music_current = volumes_music;
4995 setup.volume_simple = atoi(volume_simple_current->identifier);
4996 setup.volume_loops = atoi(volume_loops_current->identifier);
4997 setup.volume_music = atoi(volume_music_current->identifier);
4999 /* needed for displaying volume text instead of identifier */
5000 volume_simple_text = volume_simple_current->name;
5001 volume_loops_text = volume_loops_current->name;
5002 volume_music_text = volume_music_current->name;
5004 setup_mode = SETUP_MODE_SOUND;
5009 static void execSetupChooseTouchControls()
5011 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5016 static void execSetupChooseMoveDistance()
5018 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5023 static void execSetupChooseDropDistance()
5025 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5030 static void execSetupTouch()
5032 if (touch_controls == NULL)
5036 for (i = 0; touch_controls_list[i].value != NULL; i++)
5038 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5039 char identifier[32], name[32];
5040 char *value = touch_controls_list[i].value;
5041 char *text = touch_controls_list[i].text;
5043 ti->node_top = &touch_controls;
5044 ti->sort_priority = i;
5046 sprintf(identifier, "%s", value);
5047 sprintf(name, "%s", text);
5049 setString(&ti->identifier, identifier);
5050 setString(&ti->name, name);
5051 setString(&ti->name_sorting, name);
5052 setString(&ti->infotext, "Control Type");
5054 pushTreeInfo(&touch_controls, ti);
5057 /* sort touch control values to start with lowest touch control value */
5058 sortTreeInfo(&touch_controls);
5060 /* set current touch control value to configured touch control value */
5061 touch_control_current =
5062 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5064 /* if that fails, set current touch control to reliable default value */
5065 if (touch_control_current == NULL)
5066 touch_control_current =
5067 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5069 /* if that also fails, set current touch control to first available value */
5070 if (touch_control_current == NULL)
5071 touch_control_current = touch_controls;
5074 if (move_distances == NULL)
5078 for (i = 0; distances_list[i].value != -1; i++)
5080 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5081 char identifier[32], name[32];
5082 int value = distances_list[i].value;
5083 char *text = distances_list[i].text;
5085 ti->node_top = &move_distances;
5086 ti->sort_priority = value;
5088 sprintf(identifier, "%d", value);
5089 sprintf(name, "%s", text);
5091 setString(&ti->identifier, identifier);
5092 setString(&ti->name, name);
5093 setString(&ti->name_sorting, name);
5094 setString(&ti->infotext, "Move Distance");
5096 pushTreeInfo(&move_distances, ti);
5099 /* sort distance values to start with lowest distance value */
5100 sortTreeInfo(&move_distances);
5102 /* set current distance value to configured distance value */
5103 move_distance_current =
5104 getTreeInfoFromIdentifier(move_distances,
5105 i_to_a(setup.touch.move_distance));
5107 /* if that fails, set current distance to reliable default value */
5108 if (move_distance_current == NULL)
5109 move_distance_current =
5110 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5112 /* if that also fails, set current distance to first available value */
5113 if (move_distance_current == NULL)
5114 move_distance_current = move_distances;
5117 if (drop_distances == NULL)
5121 for (i = 0; distances_list[i].value != -1; i++)
5123 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5124 char identifier[32], name[32];
5125 int value = distances_list[i].value;
5126 char *text = distances_list[i].text;
5128 ti->node_top = &drop_distances;
5129 ti->sort_priority = value;
5131 sprintf(identifier, "%d", value);
5132 sprintf(name, "%s", text);
5134 setString(&ti->identifier, identifier);
5135 setString(&ti->name, name);
5136 setString(&ti->name_sorting, name);
5137 setString(&ti->infotext, "Drop Distance");
5139 pushTreeInfo(&drop_distances, ti);
5142 /* sort distance values to start with lowest distance value */
5143 sortTreeInfo(&drop_distances);
5145 /* set current distance value to configured distance value */
5146 drop_distance_current =
5147 getTreeInfoFromIdentifier(drop_distances,
5148 i_to_a(setup.touch.drop_distance));
5150 /* if that fails, set current distance to reliable default value */
5151 if (drop_distance_current == NULL)
5152 drop_distance_current =
5153 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5155 /* if that also fails, set current distance to first available value */
5156 if (drop_distance_current == NULL)
5157 drop_distance_current = drop_distances;
5160 setup.touch.control_type = touch_control_current->identifier;
5161 setup.touch.move_distance = atoi(move_distance_current->identifier);
5162 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5164 /* needed for displaying volume text instead of identifier */
5165 touch_controls_text = touch_control_current->name;
5166 move_distance_text = move_distance_current->name;
5167 drop_distance_text = drop_distance_current->name;
5169 setup_mode = SETUP_MODE_TOUCH;
5174 static void execSetupArtwork()
5177 printf("::: '%s', '%s', '%s'\n",
5178 artwork.gfx_current->subdir,
5179 artwork.gfx_current->fullpath,
5180 artwork.gfx_current->basepath);
5183 setup.graphics_set = artwork.gfx_current->identifier;
5184 setup.sounds_set = artwork.snd_current->identifier;
5185 setup.music_set = artwork.mus_current->identifier;
5187 /* needed if last screen (setup choice) changed graphics, sounds or music */
5188 ReloadCustomArtwork(0);
5190 /* needed for displaying artwork name instead of artwork identifier */
5191 graphics_set_name = artwork.gfx_current->name;
5192 sounds_set_name = artwork.snd_current->name;
5193 music_set_name = artwork.mus_current->name;
5195 setup_mode = SETUP_MODE_ARTWORK;
5200 static void execSetupChooseGraphics()
5202 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5207 static void execSetupChooseSounds()
5209 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5214 static void execSetupChooseMusic()
5216 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5221 #if !defined(PLATFORM_ANDROID)
5222 static void execSetupInput()
5224 setup_mode = SETUP_MODE_INPUT;
5230 static void execSetupShortcuts()
5232 setup_mode = SETUP_MODE_SHORTCUTS;
5237 static void execSetupShortcuts1()
5239 setup_mode = SETUP_MODE_SHORTCUTS_1;
5244 static void execSetupShortcuts2()
5246 setup_mode = SETUP_MODE_SHORTCUTS_2;
5251 static void execSetupShortcuts3()
5253 setup_mode = SETUP_MODE_SHORTCUTS_3;
5258 static void execSetupShortcuts4()
5260 setup_mode = SETUP_MODE_SHORTCUTS_4;
5265 static void execSetupShortcuts5()
5267 setup_mode = SETUP_MODE_SHORTCUTS_5;
5272 static void execExitSetup()
5274 game_status = GAME_MODE_MAIN;
5279 static void execSaveAndExitSetup()
5285 static struct TokenInfo setup_info_main[] =
5287 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5288 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5289 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5290 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5291 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5292 #if !defined(PLATFORM_ANDROID)
5293 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5294 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5296 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5298 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5299 { TYPE_EMPTY, NULL, "" },
5300 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5301 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5306 static struct TokenInfo setup_info_game[] =
5308 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5309 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5310 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5311 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5312 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5313 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5314 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5315 { TYPE_STRING, &game_speed_text, "" },
5317 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5318 { TYPE_STRING, &scroll_delay_text, "" },
5320 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5321 { TYPE_STRING, &snapshot_mode_text, "" },
5322 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5323 { TYPE_EMPTY, NULL, "" },
5324 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5329 static struct TokenInfo setup_info_editor[] =
5332 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5333 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5334 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5335 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5336 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5337 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5338 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5339 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5341 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5342 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5343 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5345 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5347 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5348 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5349 { TYPE_EMPTY, NULL, "" },
5351 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5352 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5353 { TYPE_EMPTY, NULL, "" },
5355 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5356 { TYPE_EMPTY, NULL, "" },
5357 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5362 static struct TokenInfo setup_info_graphics[] =
5364 #if !defined(PLATFORM_ANDROID)
5365 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5366 #if defined(TARGET_SDL2)
5367 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5368 { TYPE_STRING, &window_size_text, "" },
5369 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5370 { TYPE_STRING, &scaling_type_text, "" },
5372 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5373 { TYPE_STRING, &screen_mode_text, "" },
5377 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5378 { TYPE_STRING, &scroll_delay_text, "" },
5380 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5381 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5382 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5383 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5384 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5385 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5386 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5387 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5388 { TYPE_EMPTY, NULL, "" },
5389 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5394 static struct TokenInfo setup_info_sound[] =
5396 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5397 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5398 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5399 { TYPE_EMPTY, NULL, "" },
5400 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5401 { TYPE_STRING, &volume_simple_text, "" },
5402 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5403 { TYPE_STRING, &volume_loops_text, "" },
5404 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5405 { TYPE_STRING, &volume_music_text, "" },
5406 { TYPE_EMPTY, NULL, "" },
5407 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5412 static struct TokenInfo setup_info_artwork[] =
5414 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5415 { TYPE_STRING, &graphics_set_name, "" },
5416 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5417 { TYPE_STRING, &sounds_set_name, "" },
5418 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5419 { TYPE_STRING, &music_set_name, "" },
5420 { TYPE_EMPTY, NULL, "" },
5421 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5422 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5423 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5424 { TYPE_EMPTY, NULL, "" },
5425 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5430 static struct TokenInfo setup_info_input[] =
5432 { TYPE_SWITCH, NULL, "Player:" },
5433 { TYPE_SWITCH, NULL, "Device:" },
5434 { TYPE_ENTER_MENU, NULL, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_EMPTY, NULL, "" },
5437 { TYPE_EMPTY, 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_LEAVE_MENU, execSetupMain, "Back" },
5450 static struct TokenInfo setup_info_touch[] =
5452 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5453 { TYPE_STRING, &touch_controls_text, "" },
5454 { TYPE_EMPTY, NULL, "" },
5455 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5456 { TYPE_STRING, &move_distance_text, "" },
5457 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5458 { TYPE_STRING, &drop_distance_text, "" },
5459 { TYPE_EMPTY, NULL, "" },
5460 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5465 static struct TokenInfo setup_info_shortcuts[] =
5467 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5468 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5469 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5470 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5471 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5472 { TYPE_EMPTY, NULL, "" },
5473 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5478 static struct TokenInfo setup_info_shortcuts_1[] =
5480 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5481 { TYPE_KEY, &setup.shortcut.save_game, "" },
5482 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5483 { TYPE_KEY, &setup.shortcut.load_game, "" },
5484 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5485 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5486 { TYPE_EMPTY, NULL, "" },
5487 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5488 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5489 { TYPE_EMPTY, NULL, "" },
5490 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5495 static struct TokenInfo setup_info_shortcuts_2[] =
5497 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5498 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5499 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5500 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5501 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5502 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5503 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5504 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5505 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5506 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5507 { TYPE_EMPTY, NULL, "" },
5508 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5513 static struct TokenInfo setup_info_shortcuts_3[] =
5515 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5516 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5517 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5518 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5519 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5520 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5521 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5522 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5523 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5524 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5525 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5526 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5527 { TYPE_EMPTY, NULL, "" },
5528 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5533 static struct TokenInfo setup_info_shortcuts_4[] =
5535 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5536 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5537 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5538 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5539 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5540 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5541 { TYPE_EMPTY, NULL, "" },
5542 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5547 static struct TokenInfo setup_info_shortcuts_5[] =
5549 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5550 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5551 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5552 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5553 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5554 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5555 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5556 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5557 { TYPE_EMPTY, NULL, "" },
5558 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5563 static Key getSetupKey()
5565 Key key = KSYM_UNDEFINED;
5566 boolean got_key_event = FALSE;
5568 while (!got_key_event)
5570 if (PendingEvent()) /* got event */
5578 case EVENT_KEYPRESS:
5580 key = GetEventKey((KeyEvent *)&event, TRUE);
5582 /* press 'Escape' or 'Enter' to keep the existing key binding */
5583 if (key == KSYM_Escape || key == KSYM_Return)
5584 key = KSYM_UNDEFINED; /* keep old value */
5586 got_key_event = TRUE;
5590 case EVENT_KEYRELEASE:
5591 key_joystick_mapping = 0;
5595 HandleOtherEvents(&event);
5603 /* don't eat all CPU time */
5610 static int getSetupValueFont(int type, void *value)
5612 if (type & TYPE_KEY)
5613 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5614 else if (type & TYPE_STRING)
5615 return FONT_VALUE_2;
5616 else if (type & TYPE_ECS_AGA)
5617 return FONT_VALUE_1;
5618 else if (type & TYPE_BOOLEAN_STYLE)
5619 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5620 else if (type & TYPE_YES_NO_AUTO)
5621 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5622 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5624 return FONT_VALUE_1;
5627 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5629 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5630 struct TokenInfo *si = &setup_info[si_pos];
5631 boolean font_draw_xoffset_modified = FALSE;
5632 int font_draw_xoffset_old = -1;
5633 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5634 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5635 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5636 int xpos = menu_screen_value_xpos;
5637 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5638 int startx = mSX + xpos * 32;
5639 int starty = mSY + ypos * 32;
5640 int font_nr, font_width;
5641 int type = si->type;
5642 void *value = si->value;
5643 char *value_string = getSetupValue(type, value);
5646 if (value_string == NULL)
5649 if (type & TYPE_KEY)
5651 xpos = MENU_SCREEN_START_XPOS;
5653 if (type & TYPE_QUERY)
5654 value_string = "<press key>";
5656 else if (type & TYPE_STRING)
5658 int max_value_len = (SCR_FIELDX - 2) * 2;
5660 xpos = MENU_SCREEN_START_XPOS;
5662 if (strlen(value_string) > max_value_len)
5663 value_string[max_value_len] = '\0';
5665 else if (type & TYPE_YES_NO_AUTO)
5667 xpos = menu_screen_value_xpos - 1;
5670 startx = mSX + xpos * 32;
5671 starty = mSY + ypos * 32;
5672 font_nr = getSetupValueFont(type, value);
5673 font_width = getFontWidth(font_nr);
5675 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5676 if (setup_mode != SETUP_MODE_INPUT)
5678 int max_menu_text_length_big = (menu_screen_value_xpos -
5679 MENU_SCREEN_START_XPOS);
5680 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5681 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5682 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5683 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5684 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5685 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5686 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5687 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5688 boolean correct_font_draw_xoffset = FALSE;
5690 if (xpos == MENU_SCREEN_START_XPOS &&
5691 startx + font1_xoffset < text_startx + text_font_xoffset)
5692 correct_font_draw_xoffset = TRUE;
5694 if (xpos == menu_screen_value_xpos &&
5695 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5696 correct_font_draw_xoffset = TRUE;
5698 /* check if setup value would overlap with setup text when printed */
5699 /* (this can happen for extreme/wrong values for font draw offset) */
5700 if (correct_font_draw_xoffset)
5702 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5703 font_draw_xoffset_modified = TRUE;
5705 if (type & TYPE_KEY)
5706 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5707 else if (!(type & TYPE_STRING))
5708 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5709 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5713 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5714 DrawText(startx + i * font_width, starty, " ", font_nr);
5716 DrawText(startx, starty, value_string, font_nr);
5718 if (font_draw_xoffset_modified)
5719 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5722 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5724 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5725 struct TokenInfo *si = &setup_info[si_pos];
5727 if (si->type & TYPE_BOOLEAN_STYLE)
5729 *(boolean *)si->value ^= TRUE;
5731 else if (si->type & TYPE_YES_NO_AUTO)
5735 (*(int *)si->value == AUTO ? TRUE :
5736 *(int *)si->value == TRUE ? FALSE : AUTO) :
5737 (*(int *)si->value == TRUE ? AUTO :
5738 *(int *)si->value == AUTO ? FALSE : TRUE));
5740 else if (si->type & TYPE_KEY)
5744 si->type |= TYPE_QUERY;
5745 drawSetupValue(screen_pos, setup_info_pos_raw);
5746 si->type &= ~TYPE_QUERY;
5748 key = getSetupKey();
5749 if (key != KSYM_UNDEFINED)
5750 *(Key *)si->value = key;
5753 drawSetupValue(screen_pos, setup_info_pos_raw);
5755 // fullscreen state may have changed at this point
5756 if (si->value == &setup.fullscreen)
5757 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5760 static void DrawSetupScreen_Generic()
5762 int fade_mask = REDRAW_FIELD;
5763 boolean redraw_all = FALSE;
5764 char *title_string = NULL;
5767 if (CheckIfGlobalBorderHasChanged())
5768 fade_mask = REDRAW_ALL;
5772 FreeScreenGadgets();
5773 CreateScreenGadgets();
5775 CloseDoor(DOOR_CLOSE_2);
5777 if (redraw_mask & REDRAW_ALL)
5782 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5786 if (setup_mode == SETUP_MODE_MAIN)
5788 setup_info = setup_info_main;
5789 title_string = "Setup";
5791 else if (setup_mode == SETUP_MODE_GAME)
5793 setup_info = setup_info_game;
5794 title_string = "Setup Game";
5796 else if (setup_mode == SETUP_MODE_EDITOR)
5798 setup_info = setup_info_editor;
5799 title_string = "Setup Editor";
5801 else if (setup_mode == SETUP_MODE_GRAPHICS)
5803 setup_info = setup_info_graphics;
5804 title_string = "Setup Graphics";
5806 else if (setup_mode == SETUP_MODE_SOUND)
5808 setup_info = setup_info_sound;
5809 title_string = "Setup Sound";
5811 else if (setup_mode == SETUP_MODE_ARTWORK)
5813 setup_info = setup_info_artwork;
5814 title_string = "Custom Artwork";
5816 else if (setup_mode == SETUP_MODE_TOUCH)
5818 setup_info = setup_info_touch;
5819 title_string = "Setup Touch Ctrls";
5821 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5823 setup_info = setup_info_shortcuts;
5824 title_string = "Setup Shortcuts";
5826 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5828 setup_info = setup_info_shortcuts_1;
5829 title_string = "Setup Shortcuts";
5831 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5833 setup_info = setup_info_shortcuts_2;
5834 title_string = "Setup Shortcuts";
5836 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5838 setup_info = setup_info_shortcuts_3;
5839 title_string = "Setup Shortcuts";
5841 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5843 setup_info = setup_info_shortcuts_4;
5844 title_string = "Setup Shortcuts";
5846 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5848 setup_info = setup_info_shortcuts_5;
5849 title_string = "Setup Shortcuts";
5852 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5854 // determine maximal number of setup entries that can be displayed on screen
5856 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5859 // determine maximal number of setup entries available for this setup screen
5861 for (i = 0; setup_info[i].type != 0; i++)
5864 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5866 MapScreenGadgets(max_setup_info);
5869 redraw_mask = fade_mask = REDRAW_ALL;
5871 DrawMaskedBorder(fade_mask);
5878 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5880 menu_info = setup_info;
5882 HandleMenuScreen(mx, my, dx, dy, button,
5883 setup_mode, num_setup_info, max_setup_info);
5886 void DrawSetupScreen_Input()
5890 FadeOut(REDRAW_FIELD);
5894 setup_info = setup_info_input;
5896 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5898 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5899 "Joysticks deactivated on this screen");
5901 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5903 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5904 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5905 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5906 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5907 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5908 initCursor(i, IMG_MENU_BUTTON);
5910 DrawCursorAndText_Setup(i, -1, FALSE);
5913 /* create gadgets for setup input menu screen */
5914 FreeScreenGadgets();
5915 CreateScreenGadgets();
5917 /* map gadgets for setup input menu screen */
5918 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5920 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5922 FadeIn(REDRAW_FIELD);
5927 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5929 if (device_name == NULL)
5932 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5935 if (strlen(device_name) > 1)
5937 char c1 = device_name[strlen(device_name) - 1];
5938 char c2 = device_name[strlen(device_name) - 2];
5940 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5941 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5944 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5945 strlen(device_name));
5948 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5951 static struct SetupKeyboardInfo custom_key;
5958 { &custom_key.left, "Joystick Left" },
5959 { &custom_key.right, "Joystick Right" },
5960 { &custom_key.up, "Joystick Up" },
5961 { &custom_key.down, "Joystick Down" },
5962 { &custom_key.snap, "Button 1" },
5963 { &custom_key.drop, "Button 2" }
5965 static char *joystick_name[MAX_PLAYERS] =
5972 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5976 custom_key = setup.input[player_nr].key;
5978 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5979 FONT_INPUT_1_ACTIVE);
5981 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5983 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5984 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5986 if (setup.input[player_nr].use_joystick)
5988 char *device_name = setup.input[player_nr].joy.device_name;
5989 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5990 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5992 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5993 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5997 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5998 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6001 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6003 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6004 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6005 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6006 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6008 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6009 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6010 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6011 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6012 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6013 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6015 for (i = 0; i < 6; i++)
6017 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6019 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6021 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6022 (setup.input[player_nr].use_joystick ?
6024 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6028 static int input_player_nr = 0;
6030 void HandleSetupScreen_Input_Player(int step, int direction)
6032 int old_player_nr = input_player_nr;
6035 new_player_nr = old_player_nr + step * direction;
6036 if (new_player_nr < 0)
6038 if (new_player_nr > MAX_PLAYERS - 1)
6039 new_player_nr = MAX_PLAYERS - 1;
6041 if (new_player_nr != old_player_nr)
6043 input_player_nr = new_player_nr;
6045 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6049 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6051 static int choice = 0;
6054 int pos_start = SETUPINPUT_SCREEN_POS_START;
6055 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6056 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6057 int pos_end = SETUPINPUT_SCREEN_POS_END;
6059 if (button == MB_MENU_INITIALIZE)
6061 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6063 DrawCursorAndText_Setup(choice, -1, TRUE);
6067 else if (button == MB_MENU_LEAVE)
6069 setup_mode = SETUP_MODE_MAIN;
6076 if (mx || my) /* mouse input */
6078 x = (mx - mSX) / 32;
6079 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6081 else if (dx || dy) /* keyboard input */
6083 if (dx && choice == 0)
6084 x = (dx < 0 ? 10 : 12);
6085 else if ((dx && choice == 1) ||
6086 (dx == +1 && choice == 2) ||
6087 (dx == -1 && choice == pos_end))
6088 button = MB_MENU_CHOICE;
6092 if (y >= pos_empty1 && y <= pos_empty2)
6093 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6096 if (y == 0 && dx != 0 && button)
6098 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6100 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6101 y >= pos_start && y <= pos_end &&
6102 !(y >= pos_empty1 && y <= pos_empty2))
6108 DrawCursorAndText_Setup(choice, -1, FALSE);
6109 DrawCursorAndText_Setup(y, -1, TRUE);
6111 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6120 char *device_name = setup.input[input_player_nr].joy.device_name;
6122 if (!setup.input[input_player_nr].use_joystick)
6124 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6126 setJoystickDeviceToNr(device_name, new_device_nr);
6127 setup.input[input_player_nr].use_joystick = TRUE;
6131 int device_nr = getJoystickNrFromDeviceName(device_name);
6132 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6134 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6135 setup.input[input_player_nr].use_joystick = FALSE;
6137 setJoystickDeviceToNr(device_name, new_device_nr);
6140 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6144 if (setup.input[input_player_nr].use_joystick)
6147 CalibrateJoystick(input_player_nr);
6150 CustomizeKeyboard(input_player_nr);
6152 else if (y == pos_end)
6158 setup_mode = SETUP_MODE_MAIN;
6165 void CustomizeKeyboard(int player_nr)
6169 boolean finished = FALSE;
6170 static struct SetupKeyboardInfo custom_key;
6175 } customize_step[] =
6177 { &custom_key.left, "Move Left" },
6178 { &custom_key.right, "Move Right" },
6179 { &custom_key.up, "Move Up" },
6180 { &custom_key.down, "Move Down" },
6181 { &custom_key.snap, "Snap Field" },
6182 { &custom_key.drop, "Drop Element" }
6185 /* read existing key bindings from player setup */
6186 custom_key = setup.input[player_nr].key;
6189 FadeOut(REDRAW_FIELD);
6193 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6196 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6197 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6198 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6199 "Key:", FONT_INPUT_1_ACTIVE);
6200 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6201 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6203 FadeIn(REDRAW_FIELD);
6209 if (PendingEvent()) /* got event */
6217 case EVENT_KEYPRESS:
6219 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6221 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6223 if (key == KSYM_Escape)
6224 FadeSkipNextFadeIn();
6230 /* all keys configured -- wait for "Escape" or "Return" key */
6234 /* press 'Enter' to keep the existing key binding */
6235 if (key == KSYM_Return)
6236 key = *customize_step[step_nr].key;
6238 /* check if key already used */
6239 for (i = 0; i < step_nr; i++)
6240 if (*customize_step[i].key == key)
6245 /* got new key binding */
6246 *customize_step[step_nr].key = key;
6247 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6249 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6250 getKeyNameFromKey(key), FONT_VALUE_1);
6253 /* un-highlight last query */
6254 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6255 customize_step[step_nr - 1].text, FONT_MENU_1);
6256 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6257 "Key:", FONT_MENU_1);
6259 /* press 'Enter' to leave */
6262 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6263 "Press Enter", FONT_TITLE_1);
6267 /* query next key binding */
6268 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6269 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6270 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6271 "Key:", FONT_INPUT_1_ACTIVE);
6272 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6273 getKeyNameFromKey(*customize_step[step_nr].key),
6278 case EVENT_KEYRELEASE:
6279 key_joystick_mapping = 0;
6283 HandleOtherEvents(&event);
6291 /* don't eat all CPU time */
6295 /* write new key bindings back to player setup */
6296 setup.input[player_nr].key = custom_key;
6299 DrawSetupScreen_Input();
6302 static boolean CalibrateJoystickMain(int player_nr)
6304 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6305 int new_joystick_xright = JOYSTICK_XMIDDLE;
6306 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6307 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6308 int new_joystick_xmiddle, new_joystick_ymiddle;
6310 int joystick_fd = joystick.fd[player_nr];
6311 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6312 boolean check[3][3];
6313 int check_remaining = 3 * 3;
6318 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6321 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6325 FadeOut(REDRAW_FIELD);
6329 for (y = 0; y < 3; y++)
6331 for (x = 0; x < 3; x++)
6333 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6334 check[x][y] = FALSE;
6338 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6339 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6340 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6341 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6342 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6343 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6344 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6346 joy_value = Joystick(player_nr);
6347 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6348 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6350 /* eventually uncalibrated center position (joystick could be uncentered) */
6351 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6354 new_joystick_xmiddle = joy_x;
6355 new_joystick_ymiddle = joy_y;
6357 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6359 FadeIn(REDRAW_FIELD);
6361 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6366 if (PendingEvent()) /* got event */
6374 case EVENT_KEYPRESS:
6375 switch (GetEventKey((KeyEvent *)&event, TRUE))
6378 if (check_remaining == 0)
6383 FadeSkipNextFadeIn();
6392 case EVENT_KEYRELEASE:
6393 key_joystick_mapping = 0;
6397 HandleOtherEvents(&event);
6402 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6405 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6406 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6407 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6408 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6410 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6411 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6412 setup.input[player_nr].joy.xright = new_joystick_xright;
6413 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6414 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6415 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6417 CheckJoystickData();
6419 joy_value = Joystick(player_nr);
6421 if (joy_value & JOY_BUTTON && check_remaining == 0)
6424 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6425 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6427 if (x != last_x || y != last_y)
6429 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6430 IMG_MENU_CALIBRATE_YELLOW, 0);
6431 DrawFixedGraphic(xpos + x, ypos + y,
6432 IMG_MENU_CALIBRATE_RED, 0);
6437 if (check_remaining > 0 && !check[x+1][y+1])
6439 check[x+1][y+1] = TRUE;
6447 /* don't eat all CPU time */
6451 /* calibrated center position (joystick should now be centered) */
6452 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6455 new_joystick_xmiddle = joy_x;
6456 new_joystick_ymiddle = joy_y;
6460 /* wait until the last pressed button was released */
6461 while (Joystick(player_nr) & JOY_BUTTON)
6463 if (PendingEvent()) /* got event */
6468 HandleOtherEvents(&event);
6477 void CalibrateJoystick(int player_nr)
6479 if (!CalibrateJoystickMain(player_nr))
6481 char *device_name = setup.input[player_nr].joy.device_name;
6482 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6483 int xpos = mSX - SX;
6484 int ypos = mSY - SY;
6488 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6489 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6492 Delay(2000); /* show error message for a short time */
6497 DrawSetupScreen_Input();
6500 void DrawSetupScreen()
6502 DeactivateJoystick();
6504 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6506 if (setup_mode == SETUP_MODE_INPUT)
6507 DrawSetupScreen_Input();
6508 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6509 DrawChooseTree(&game_speed_current);
6510 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6511 DrawChooseTree(&scroll_delay_current);
6512 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6513 DrawChooseTree(&snapshot_mode_current);
6514 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6515 DrawChooseTree(&screen_mode_current);
6516 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6517 DrawChooseTree(&window_size_current);
6518 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6519 DrawChooseTree(&scaling_type_current);
6520 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6521 DrawChooseTree(&artwork.gfx_current);
6522 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6523 DrawChooseTree(&artwork.snd_current);
6524 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6525 DrawChooseTree(&artwork.mus_current);
6526 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6527 DrawChooseTree(&volume_simple_current);
6528 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6529 DrawChooseTree(&volume_loops_current);
6530 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6531 DrawChooseTree(&volume_music_current);
6532 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6533 DrawChooseTree(&touch_control_current);
6534 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6535 DrawChooseTree(&move_distance_current);
6536 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6537 DrawChooseTree(&drop_distance_current);
6539 DrawSetupScreen_Generic();
6545 void RedrawSetupScreenAfterFullscreenToggle()
6547 if (setup_mode == SETUP_MODE_GRAPHICS ||
6548 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6550 // update list selection from "setup.window_scaling_percent"
6551 execSetupGraphics_setWindowSizes(TRUE);
6557 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6559 if (setup_mode == SETUP_MODE_INPUT)
6560 HandleSetupScreen_Input(mx, my, dx, dy, button);
6561 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6562 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6563 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6564 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6565 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6566 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6567 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6568 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6569 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6570 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6571 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6572 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6573 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6574 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6575 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6576 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6577 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6578 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6579 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6580 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6581 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6582 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6583 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6584 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6585 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6586 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6587 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6588 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6589 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6590 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6592 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6595 void HandleGameActions()
6597 if (game_status != GAME_MODE_PLAYING)
6600 GameActions(); /* main game loop */
6602 if (tape.auto_play && !tape.playing)
6603 AutoPlayTape(); /* continue automatically playing next tape */
6607 /* ---------- new screen button stuff -------------------------------------- */
6609 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6613 case SCREEN_CTRL_ID_PREV_LEVEL:
6614 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6615 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6618 case SCREEN_CTRL_ID_NEXT_LEVEL:
6619 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6620 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6623 case SCREEN_CTRL_ID_PREV_PLAYER:
6624 *x = mSX + TILEX * 10;
6625 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6628 case SCREEN_CTRL_ID_NEXT_PLAYER:
6629 *x = mSX + TILEX * 12;
6630 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6634 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6640 int gfx_unpressed, gfx_pressed;
6641 void (*get_gadget_position)(int *, int *, int);
6645 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6648 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6649 getScreenMenuButtonPos,
6650 SCREEN_CTRL_ID_PREV_LEVEL,
6655 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6656 getScreenMenuButtonPos,
6657 SCREEN_CTRL_ID_NEXT_LEVEL,
6662 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6663 getScreenMenuButtonPos,
6664 SCREEN_CTRL_ID_PREV_PLAYER,
6669 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6670 getScreenMenuButtonPos,
6671 SCREEN_CTRL_ID_NEXT_PLAYER,
6679 int gfx_unpressed, gfx_pressed;
6683 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6686 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6687 -1, -1, /* these values are not constant, but can change at runtime */
6688 SCREEN_CTRL_ID_SCROLL_UP,
6692 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6693 -1, -1, /* these values are not constant, but can change at runtime */
6694 SCREEN_CTRL_ID_SCROLL_DOWN,
6701 int gfx_unpressed, gfx_pressed;
6707 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6710 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6711 -1, -1, /* these values are not constant, but can change at runtime */
6712 -1, -1, /* these values are not constant, but can change at runtime */
6713 GD_TYPE_SCROLLBAR_VERTICAL,
6714 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6715 "scroll level series vertically"
6719 static void CreateScreenMenubuttons()
6721 struct GadgetInfo *gi;
6722 unsigned int event_mask;
6725 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6727 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6728 int gfx_unpressed, gfx_pressed;
6729 int x, y, width, height;
6730 int gd_x1, gd_x2, gd_y1, gd_y2;
6731 int id = menubutton_info[i].gadget_id;
6733 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6735 menubutton_info[i].get_gadget_position(&x, &y, id);
6737 width = SC_MENUBUTTON_XSIZE;
6738 height = SC_MENUBUTTON_YSIZE;
6740 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6741 gfx_pressed = menubutton_info[i].gfx_pressed;
6742 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6743 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6744 gd_x1 = graphic_info[gfx_unpressed].src_x;
6745 gd_y1 = graphic_info[gfx_unpressed].src_y;
6746 gd_x2 = graphic_info[gfx_pressed].src_x;
6747 gd_y2 = graphic_info[gfx_pressed].src_y;
6749 gi = CreateGadget(GDI_CUSTOM_ID, id,
6750 GDI_CUSTOM_TYPE_ID, i,
6751 GDI_INFO_TEXT, menubutton_info[i].infotext,
6756 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6757 GDI_STATE, GD_BUTTON_UNPRESSED,
6758 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6759 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6760 GDI_DIRECT_DRAW, FALSE,
6761 GDI_EVENT_MASK, event_mask,
6762 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6766 Error(ERR_EXIT, "cannot create gadget");
6768 screen_gadget[id] = gi;
6772 static void CreateScreenScrollbuttons()
6774 struct GadgetInfo *gi;
6775 unsigned int event_mask;
6778 /* these values are not constant, but can change at runtime */
6779 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6780 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6781 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6782 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6784 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6786 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6787 int gfx_unpressed, gfx_pressed;
6788 int x, y, width, height;
6789 int gd_x1, gd_x2, gd_y1, gd_y2;
6790 int id = scrollbutton_info[i].gadget_id;
6792 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6794 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6795 y = mSY + scrollbutton_info[i].y;
6796 width = SC_SCROLLBUTTON_XSIZE;
6797 height = SC_SCROLLBUTTON_YSIZE;
6799 /* correct scrollbar position if placed outside menu (playfield) area */
6800 if (x > SX + SC_SCROLL_UP_XPOS)
6801 x = SX + SC_SCROLL_UP_XPOS;
6803 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6804 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6805 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6807 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6808 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6809 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6810 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6811 gd_x1 = graphic_info[gfx_unpressed].src_x;
6812 gd_y1 = graphic_info[gfx_unpressed].src_y;
6813 gd_x2 = graphic_info[gfx_pressed].src_x;
6814 gd_y2 = graphic_info[gfx_pressed].src_y;
6816 gi = CreateGadget(GDI_CUSTOM_ID, id,
6817 GDI_CUSTOM_TYPE_ID, i,
6818 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6823 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6824 GDI_STATE, GD_BUTTON_UNPRESSED,
6825 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6826 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6827 GDI_DIRECT_DRAW, FALSE,
6828 GDI_EVENT_MASK, event_mask,
6829 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6833 Error(ERR_EXIT, "cannot create gadget");
6835 screen_gadget[id] = gi;
6839 static void CreateScreenScrollbars()
6843 /* these values are not constant, but can change at runtime */
6844 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6845 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6846 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6847 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6849 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6851 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6852 int gfx_unpressed, gfx_pressed;
6853 int x, y, width, height;
6854 int gd_x1, gd_x2, gd_y1, gd_y2;
6855 struct GadgetInfo *gi;
6856 int items_max, items_visible, item_position;
6857 unsigned int event_mask;
6858 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6859 int id = scrollbar_info[i].gadget_id;
6861 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6863 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6864 y = mSY + scrollbar_info[i].y;
6865 width = scrollbar_info[i].width;
6866 height = scrollbar_info[i].height;
6868 /* correct scrollbar position if placed outside menu (playfield) area */
6869 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6870 x = SX + SC_SCROLL_VERTICAL_XPOS;
6872 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6873 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6875 items_max = num_page_entries;
6876 items_visible = num_page_entries;
6879 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6880 gfx_pressed = scrollbar_info[i].gfx_pressed;
6881 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6882 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6883 gd_x1 = graphic_info[gfx_unpressed].src_x;
6884 gd_y1 = graphic_info[gfx_unpressed].src_y;
6885 gd_x2 = graphic_info[gfx_pressed].src_x;
6886 gd_y2 = graphic_info[gfx_pressed].src_y;
6888 gi = CreateGadget(GDI_CUSTOM_ID, id,
6889 GDI_CUSTOM_TYPE_ID, i,
6890 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6895 GDI_TYPE, scrollbar_info[i].type,
6896 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6897 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6898 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6899 GDI_WHEEL_AREA_X, SX,
6900 GDI_WHEEL_AREA_Y, SY,
6901 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6902 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6903 GDI_STATE, GD_BUTTON_UNPRESSED,
6904 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6905 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6906 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6907 GDI_DIRECT_DRAW, FALSE,
6908 GDI_EVENT_MASK, event_mask,
6909 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6913 Error(ERR_EXIT, "cannot create gadget");
6915 screen_gadget[id] = gi;
6919 void CreateScreenGadgets()
6921 int last_game_status = game_status; /* save current game status */
6923 CreateScreenMenubuttons();
6925 CreateScreenScrollbuttons();
6926 CreateScreenScrollbars();
6928 game_status = last_game_status; /* restore current game status */
6931 void FreeScreenGadgets()
6935 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6936 FreeGadget(screen_gadget[i]);
6939 void MapScreenMenuGadgets(int screen_mask)
6943 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6944 if (screen_mask & menubutton_info[i].screen_mask)
6945 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6948 void MapScreenGadgets(int num_entries)
6952 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6955 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6956 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6958 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6959 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6962 void MapScreenTreeGadgets(TreeInfo *ti)
6964 MapScreenGadgets(numTreeInfoInGroup(ti));
6967 static void HandleScreenGadgets(struct GadgetInfo *gi)
6969 int id = gi->custom_id;
6970 int button = gi->event.button;
6971 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6975 case SCREEN_CTRL_ID_PREV_LEVEL:
6976 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6979 case SCREEN_CTRL_ID_NEXT_LEVEL:
6980 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6983 case SCREEN_CTRL_ID_PREV_PLAYER:
6984 HandleSetupScreen_Input_Player(step, -1);
6987 case SCREEN_CTRL_ID_NEXT_PLAYER:
6988 HandleSetupScreen_Input_Player(step, +1);
6991 case SCREEN_CTRL_ID_SCROLL_UP:
6992 if (game_status == GAME_MODE_LEVELS)
6993 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6994 else if (game_status == GAME_MODE_LEVELNR)
6995 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6996 else if (game_status == GAME_MODE_SETUP)
6997 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6998 else if (game_status == GAME_MODE_INFO)
6999 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7002 case SCREEN_CTRL_ID_SCROLL_DOWN:
7003 if (game_status == GAME_MODE_LEVELS)
7004 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7005 else if (game_status == GAME_MODE_LEVELNR)
7006 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7007 else if (game_status == GAME_MODE_SETUP)
7008 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7009 else if (game_status == GAME_MODE_INFO)
7010 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7013 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7014 if (game_status == GAME_MODE_LEVELS)
7015 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7016 else if (game_status == GAME_MODE_LEVELNR)
7017 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7018 else if (game_status == GAME_MODE_SETUP)
7019 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7020 else if (game_status == GAME_MODE_INFO)
7021 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);