1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
26 /* screens on the info screen */
27 #define INFO_MODE_MAIN 0
28 #define INFO_MODE_TITLE 1
29 #define INFO_MODE_ELEMENTS 2
30 #define INFO_MODE_MUSIC 3
31 #define INFO_MODE_CREDITS 4
32 #define INFO_MODE_PROGRAM 5
33 #define INFO_MODE_VERSION 6
34 #define INFO_MODE_LEVELSET 7
36 #define MAX_INFO_MODES 8
38 /* screens on the setup screen */
39 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
40 /* (should also match corresponding entries in src/conf_gfx.c) */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_TOUCH 7
49 #define SETUP_MODE_SHORTCUTS 8
50 #define SETUP_MODE_SHORTCUTS_1 9
51 #define SETUP_MODE_SHORTCUTS_2 10
52 #define SETUP_MODE_SHORTCUTS_3 11
53 #define SETUP_MODE_SHORTCUTS_4 12
54 #define SETUP_MODE_SHORTCUTS_5 13
56 /* sub-screens on the setup screen (generic) */
57 #define SETUP_MODE_CHOOSE_ARTWORK 14
58 #define SETUP_MODE_CHOOSE_OTHER 15
60 /* sub-screens on the setup screen (specific) */
61 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
64 #define SETUP_MODE_CHOOSE_SCREEN_MODE 19
65 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
66 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
67 #define SETUP_MODE_CHOOSE_GRAPHICS 22
68 #define SETUP_MODE_CHOOSE_SOUNDS 23
69 #define SETUP_MODE_CHOOSE_MUSIC 24
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
73 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
74 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
75 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
77 #define MAX_SETUP_MODES 31
79 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
81 /* for input setup functions */
82 #define SETUPINPUT_SCREEN_POS_START 0
83 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
84 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
85 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
87 /* for various menu stuff */
88 #define MENU_SCREEN_START_XPOS 1
89 #define MENU_SCREEN_START_YPOS 2
90 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
91 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
103 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
104 MENU_SCREEN_INFO_YSTEP)
105 #define NUM_INFO_ELEMENTS_FROM_CONF \
106 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
107 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
108 MAX_MENU_ENTRIES_ON_SCREEN)
109 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
110 MAX_INFO_ELEMENTS_ON_SCREEN), \
111 NUM_INFO_ELEMENTS_FROM_CONF)
112 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
113 #define MAX_MENU_TEXT_LENGTH_BIG 13
114 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
116 /* buttons and scrollbars identifiers */
117 #define SCREEN_CTRL_ID_PREV_LEVEL 0
118 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
119 #define SCREEN_CTRL_ID_PREV_PLAYER 2
120 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
121 #define SCREEN_CTRL_ID_SCROLL_UP 4
122 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
123 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
125 #define NUM_SCREEN_GADGETS 7
127 #define NUM_SCREEN_MENUBUTTONS 4
128 #define NUM_SCREEN_SCROLLBUTTONS 2
129 #define NUM_SCREEN_SCROLLBARS 1
131 #define SCREEN_MASK_MAIN (1 << 0)
132 #define SCREEN_MASK_INPUT (1 << 1)
134 /* graphic position and size values for buttons and scrollbars */
135 #define SC_MENUBUTTON_XSIZE TILEX
136 #define SC_MENUBUTTON_YSIZE TILEY
138 #define SC_SCROLLBUTTON_XSIZE TILEX
139 #define SC_SCROLLBUTTON_YSIZE TILEY
141 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
143 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
144 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
145 SC_SCROLLBUTTON_YSIZE)
147 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
148 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
150 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
151 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
152 SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
156 SC_SCROLL_VERTICAL_YSIZE)
158 #define SC_BORDER_SIZE 14
161 /* forward declarations of internal functions */
162 static void HandleScreenGadgets(struct GadgetInfo *);
163 static void HandleSetupScreen_Generic(int, int, int, int, int);
164 static void HandleSetupScreen_Input(int, int, int, int, int);
165 static void CustomizeKeyboard(int);
166 static void CalibrateJoystick(int);
167 static void execSetupGame(void);
168 static void execSetupGraphics(void);
169 static void execSetupSound(void);
170 static void execSetupTouch(void);
171 static void execSetupArtwork(void);
172 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
174 static void DrawChooseLevelSet(void);
175 static void DrawChooseLevelNr(void);
176 static void DrawInfoScreen(void);
177 static void DrawSetupScreen(void);
179 static void DrawInfoScreen_NotAvailable(char *, char *);
180 static void DrawInfoScreen_HelpAnim(int, int, boolean);
181 static void DrawInfoScreen_HelpText(int, int, int, int);
182 static void HandleInfoScreen_Main(int, int, int, int, int);
183 static void HandleInfoScreen_TitleScreen(int);
184 static void HandleInfoScreen_Elements(int);
185 static void HandleInfoScreen_Music(int);
186 static void HandleInfoScreen_Credits(int);
187 static void HandleInfoScreen_Program(int);
188 static void HandleInfoScreen_Version(int);
190 static void MapScreenMenuGadgets(int);
191 static void MapScreenGadgets(int);
192 static void MapScreenTreeGadgets(TreeInfo *);
194 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
196 static int info_mode = INFO_MODE_MAIN;
197 static int setup_mode = SETUP_MODE_MAIN;
199 static TreeInfo *screen_modes = NULL;
200 static TreeInfo *screen_mode_current = NULL;
202 static TreeInfo *window_sizes = NULL;
203 static TreeInfo *window_size_current = NULL;
205 static TreeInfo *scaling_types = NULL;
206 static TreeInfo *scaling_type_current = NULL;
208 static TreeInfo *scroll_delays = NULL;
209 static TreeInfo *scroll_delay_current = NULL;
211 static TreeInfo *snapshot_modes = NULL;
212 static TreeInfo *snapshot_mode_current = NULL;
214 static TreeInfo *game_speeds = NULL;
215 static TreeInfo *game_speed_current = NULL;
217 static TreeInfo *volumes_simple = NULL;
218 static TreeInfo *volume_simple_current = NULL;
220 static TreeInfo *volumes_loops = NULL;
221 static TreeInfo *volume_loops_current = NULL;
223 static TreeInfo *volumes_music = NULL;
224 static TreeInfo *volume_music_current = NULL;
226 static TreeInfo *touch_controls = NULL;
227 static TreeInfo *touch_control_current = NULL;
229 static TreeInfo *move_distances = NULL;
230 static TreeInfo *move_distance_current = NULL;
232 static TreeInfo *drop_distances = NULL;
233 static TreeInfo *drop_distance_current = NULL;
235 static TreeInfo *level_number = NULL;
236 static TreeInfo *level_number_current = NULL;
242 } window_sizes_list[] =
247 { 100, "100 % (Default)" },
264 } scaling_types_list[] =
266 { SCALING_QUALITY_NEAREST, "None" },
267 { SCALING_QUALITY_LINEAR, "Linear" },
268 { SCALING_QUALITY_BEST, "Anisotropic" },
277 } game_speeds_list[] =
286 { 1000, "1/1s (Extremely Slow)" },
291 { 29, "1/35s (Original Supaplex)" },
293 { 20, "1/50s (Normal Speed)" },
294 { 14, "1/70s (Maximum Supaplex)" },
298 { 1, "1/1000s (Extremely Fast)" },
308 } scroll_delays_list[] =
310 { 0, "0 Tiles (No Scroll Delay)" },
313 { 3, "3 Tiles (Default)" },
318 { 8, "8 Tiles (Maximum Scroll Delay)"},
327 } snapshot_modes_list[] =
329 { STR_SNAPSHOT_MODE_OFF, "Off" },
330 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
331 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
364 } touch_controls_list[] =
366 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
367 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
391 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
392 (s) <= GAME_MODE_SETUP ? (s) : \
393 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
394 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
396 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
397 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
398 (i) <= INFO_MODE_LEVELSET ? (i) : \
401 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
402 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
403 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
404 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
405 SETUP_MODE_CHOOSE_ARTWORK : \
406 SETUP_MODE_CHOOSE_OTHER)
408 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
409 menu.draw_xoffset[GAME_MODE_INFO] : \
410 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
411 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
412 menu.draw_yoffset[GAME_MODE_INFO] : \
413 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
415 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
416 menu.draw_xoffset[GAME_MODE_SETUP] : \
417 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
418 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
419 menu.draw_yoffset[GAME_MODE_SETUP] : \
420 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
422 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
423 DRAW_XOFFSET_INFO(info_mode) : \
424 (s) == GAME_MODE_SETUP ? \
425 DRAW_XOFFSET_SETUP(setup_mode) : \
426 menu.draw_xoffset[DRAW_MODE(s)])
427 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
428 DRAW_YOFFSET_INFO(info_mode) : \
429 (s) == GAME_MODE_SETUP ? \
430 DRAW_YOFFSET_SETUP(setup_mode) : \
431 menu.draw_yoffset[DRAW_MODE(s)])
433 #define mSX (SX + DRAW_XOFFSET(game_status))
434 #define mSY (SY + DRAW_YOFFSET(game_status))
436 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
437 menu.list_size[game_status] : \
438 MAX_MENU_ENTRIES_ON_SCREEN)
440 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
441 NUM_MENU_ENTRIES_ON_SCREEN)
444 /* title display and control definitions */
446 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
447 2 * MAX_NUM_TITLE_MESSAGES)
449 #define NO_DIRECT_LEVEL_SELECT (-1)
452 static int num_title_screens = 0;
454 struct TitleControlInfo
462 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
464 /* main menu display and control definitions */
466 #define MAIN_CONTROL_NAME 0
467 #define MAIN_CONTROL_LEVELS 1
468 #define MAIN_CONTROL_SCORES 2
469 #define MAIN_CONTROL_EDITOR 3
470 #define MAIN_CONTROL_INFO 4
471 #define MAIN_CONTROL_GAME 5
472 #define MAIN_CONTROL_SETUP 6
473 #define MAIN_CONTROL_QUIT 7
474 #define MAIN_CONTROL_PREV_LEVEL 8
475 #define MAIN_CONTROL_NEXT_LEVEL 9
476 #define MAIN_CONTROL_FIRST_LEVEL 10
477 #define MAIN_CONTROL_LAST_LEVEL 11
478 #define MAIN_CONTROL_LEVEL_NUMBER 12
479 #define MAIN_CONTROL_LEVEL_INFO_1 13
480 #define MAIN_CONTROL_LEVEL_INFO_2 14
481 #define MAIN_CONTROL_LEVEL_NAME 15
482 #define MAIN_CONTROL_LEVEL_AUTHOR 16
483 #define MAIN_CONTROL_LEVEL_YEAR 17
484 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
485 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
486 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
487 #define MAIN_CONTROL_TITLE_1 21
488 #define MAIN_CONTROL_TITLE_2 22
489 #define MAIN_CONTROL_TITLE_3 23
491 static char str_main_text_name[10];
492 static char str_main_text_first_level[10];
493 static char str_main_text_last_level[10];
494 static char str_main_text_level_number[10];
496 static char *main_text_name = str_main_text_name;
497 static char *main_text_first_level = str_main_text_first_level;
498 static char *main_text_last_level = str_main_text_last_level;
499 static char *main_text_level_number = str_main_text_level_number;
500 static char *main_text_levels = "Levelset";
501 static char *main_text_scores = "Hall Of Fame";
502 static char *main_text_editor = "Level Creator";
503 static char *main_text_info = "Info Screen";
504 static char *main_text_game = "Start Game";
505 static char *main_text_setup = "Setup";
506 static char *main_text_quit = "Quit";
507 static char *main_text_level_name = level.name;
508 static char *main_text_level_author = level.author;
509 static char *main_text_level_year = NULL;
510 static char *main_text_level_imported_from = NULL;
511 static char *main_text_level_imported_by = NULL;
512 static char *main_text_level_tested_by = NULL;
514 struct MainControlInfo
518 struct MenuPosInfo *pos_button;
521 struct TextPosInfo *pos_text;
524 struct TextPosInfo *pos_input;
528 static struct MainControlInfo main_controls[] =
532 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
533 &menu.main.text.name, &main_text_name,
534 &menu.main.input.name, &setup.player_name,
538 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
539 &menu.main.text.levels, &main_text_levels,
544 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
545 &menu.main.text.scores, &main_text_scores,
550 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
551 &menu.main.text.editor, &main_text_editor,
556 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
557 &menu.main.text.info, &main_text_info,
562 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
563 &menu.main.text.game, &main_text_game,
568 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
569 &menu.main.text.setup, &main_text_setup,
574 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
575 &menu.main.text.quit, &main_text_quit,
579 /* (these two buttons are real gadgets) */
581 MAIN_CONTROL_PREV_LEVEL,
582 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
587 MAIN_CONTROL_NEXT_LEVEL,
588 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
594 MAIN_CONTROL_FIRST_LEVEL,
596 &menu.main.text.first_level, &main_text_first_level,
600 MAIN_CONTROL_LAST_LEVEL,
602 &menu.main.text.last_level, &main_text_last_level,
606 MAIN_CONTROL_LEVEL_NUMBER,
608 &menu.main.text.level_number, &main_text_level_number,
612 MAIN_CONTROL_LEVEL_INFO_1,
614 &menu.main.text.level_info_1, NULL,
618 MAIN_CONTROL_LEVEL_INFO_2,
620 &menu.main.text.level_info_2, NULL,
624 MAIN_CONTROL_LEVEL_NAME,
626 &menu.main.text.level_name, &main_text_level_name,
630 MAIN_CONTROL_LEVEL_AUTHOR,
632 &menu.main.text.level_author, &main_text_level_author,
636 MAIN_CONTROL_LEVEL_YEAR,
638 &menu.main.text.level_year, &main_text_level_year,
642 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
644 &menu.main.text.level_imported_from, &main_text_level_imported_from,
648 MAIN_CONTROL_LEVEL_IMPORTED_BY,
650 &menu.main.text.level_imported_by, &main_text_level_imported_by,
654 MAIN_CONTROL_LEVEL_TESTED_BY,
656 &menu.main.text.level_tested_by, &main_text_level_tested_by,
660 MAIN_CONTROL_TITLE_1,
662 &menu.main.text.title_1, &setup.internal.program_title,
666 MAIN_CONTROL_TITLE_2,
668 &menu.main.text.title_2, &setup.internal.program_copyright,
672 MAIN_CONTROL_TITLE_3,
674 &menu.main.text.title_3, &setup.internal.program_company,
687 static int getTitleScreenGraphic(int nr, boolean initial)
689 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
692 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
694 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
698 static int getTitleScreenGameMode(boolean initial)
700 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
704 static int getTitleMessageGameMode(boolean initial)
706 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
710 static int getTitleScreenBackground(boolean initial)
712 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
717 static int getTitleMessageBackground(int nr, boolean initial)
719 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
723 static int getTitleBackground(int nr, boolean initial, boolean is_image)
725 int base = (is_image ?
726 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
727 IMG_BACKGROUND_TITLESCREEN_1) :
728 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
729 IMG_BACKGROUND_TITLEMESSAGE_1));
730 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
731 IMG_BACKGROUND_TITLE);
732 int graphic_local = base + nr;
734 if (graphic_info[graphic_local].bitmap != NULL)
735 return graphic_local;
737 if (graphic_info[graphic_global].bitmap != NULL)
738 return graphic_global;
740 return IMG_UNDEFINED;
743 static int getTitleSound(struct TitleControlInfo *tci)
745 boolean is_image = tci->is_image;
746 int initial = tci->initial;
747 int nr = tci->local_nr;
748 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
749 int base = (is_image ?
750 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
751 SND_BACKGROUND_TITLESCREEN_1) :
752 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
753 SND_BACKGROUND_TITLEMESSAGE_1));
754 int sound_global = menu.sound[mode];
755 int sound_local = base + nr;
758 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
759 nr, initial, is_image,
760 sound_global, getSoundListEntry(sound_global)->filename,
761 sound_local, getSoundListEntry(sound_local)->filename);
764 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
767 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
770 return SND_UNDEFINED;
773 static int getTitleMusic(struct TitleControlInfo *tci)
775 boolean is_image = tci->is_image;
776 int initial = tci->initial;
777 int nr = tci->local_nr;
778 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
779 int base = (is_image ?
780 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
781 MUS_BACKGROUND_TITLESCREEN_1) :
782 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
783 MUS_BACKGROUND_TITLEMESSAGE_1));
784 int music_global = menu.music[mode];
785 int music_local = base + nr;
788 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
789 nr, initial, is_image,
790 music_global, getMusicListEntry(music_global)->filename,
791 music_local, getMusicListEntry(music_local)->filename);
794 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
797 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
800 return MUS_UNDEFINED;
803 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
805 boolean is_image = tci->is_image;
806 int initial = tci->initial;
807 int nr = tci->local_nr;
808 struct TitleFadingInfo ti;
812 int graphic = getTitleScreenGraphic(nr, initial);
814 /* initialize fading control values to default title config settings */
815 ti = (initial ? title_initial_default : title_default);
817 /* override default settings with image config settings, if defined */
818 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
819 ti.fade_mode = graphic_info[graphic].fade_mode;
820 if (graphic_info[graphic].fade_delay > -1)
821 ti.fade_delay = graphic_info[graphic].fade_delay;
822 if (graphic_info[graphic].post_delay > -1)
823 ti.post_delay = graphic_info[graphic].post_delay;
824 if (graphic_info[graphic].auto_delay > -1)
825 ti.auto_delay = graphic_info[graphic].auto_delay;
831 ti.fade_mode = titlemessage_initial[nr].fade_mode;
832 ti.fade_delay = titlemessage_initial[nr].fade_delay;
833 ti.post_delay = titlemessage_initial[nr].post_delay;
834 ti.auto_delay = titlemessage_initial[nr].auto_delay;
838 ti.fade_mode = titlemessage[nr].fade_mode;
839 ti.fade_delay = titlemessage[nr].fade_delay;
840 ti.post_delay = titlemessage[nr].post_delay;
841 ti.auto_delay = titlemessage[nr].auto_delay;
848 static int compareTitleControlInfo(const void *object1, const void *object2)
850 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
851 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
854 if (tci1->initial != tci2->initial)
855 compare_result = (tci1->initial ? -1 : +1);
856 else if (tci1->sort_priority != tci2->sort_priority)
857 compare_result = tci1->sort_priority - tci2->sort_priority;
858 else if (tci1->is_image != tci2->is_image)
859 compare_result = (tci1->is_image ? -1 : +1);
861 compare_result = tci1->local_nr - tci2->local_nr;
863 return compare_result;
866 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
868 int nr, int sort_priority)
870 title_controls[num_title_screens].is_image = is_image;
871 title_controls[num_title_screens].initial = initial;
872 title_controls[num_title_screens].local_nr = nr;
873 title_controls[num_title_screens].sort_priority = sort_priority;
878 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
882 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
884 int graphic = getTitleScreenGraphic(i, initial);
885 Bitmap *bitmap = graphic_info[graphic].bitmap;
886 int sort_priority = graphic_info[graphic].sort_priority;
889 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
892 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
894 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
895 char *filename = getLevelSetTitleMessageFilename(i, initial);
896 int sort_priority = tmi->sort_priority;
898 if (filename != NULL)
899 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
903 static void InitializeTitleControls(boolean show_title_initial)
905 num_title_screens = 0;
907 /* 1st step: initialize title screens for game start (only when starting) */
908 if (show_title_initial)
909 InitializeTitleControls_CheckTitleInfo(TRUE);
911 /* 2nd step: initialize title screens for current level set */
912 InitializeTitleControls_CheckTitleInfo(FALSE);
914 /* sort title screens according to sort_priority and title number */
915 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
916 compareTitleControlInfo);
919 static boolean visibleMenuPos(struct MenuPosInfo *pos)
921 return (pos != NULL && pos->x != -1 && pos->y != -1);
924 static boolean visibleTextPos(struct TextPosInfo *pos)
926 return (pos != NULL && pos->x != -1 && pos->y != -1);
929 static void InitializeMainControls()
931 boolean local_team_mode = (!options.network && setup.team_mode);
934 /* set main control text values to dynamically determined values */
935 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
937 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
938 menu.main.text.first_level.size));
939 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
940 menu.main.text.last_level.size));
941 strcpy(main_text_level_number, int2str(level_nr,
942 menu.main.text.level_number.size));
944 main_text_level_year = leveldir_current->year;
945 main_text_level_imported_from = leveldir_current->imported_from;
946 main_text_level_imported_by = leveldir_current->imported_by;
947 main_text_level_tested_by = leveldir_current->tested_by;
949 /* set main control screen positions to dynamically determined values */
950 for (i = 0; main_controls[i].nr != -1; i++)
952 struct MainControlInfo *mci = &main_controls[i];
954 struct MenuPosInfo *pos_button = mci->pos_button;
955 struct TextPosInfo *pos_text = mci->pos_text;
956 struct TextPosInfo *pos_input = mci->pos_input;
957 char *text = (mci->text ? *mci->text : NULL);
958 char *input = (mci->input ? *mci->input : NULL);
959 int button_graphic = mci->button_graphic;
960 int font_text = (pos_text ? pos_text->font : -1);
961 int font_input = (pos_input ? pos_input->font : -1);
963 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
964 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
965 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
966 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
967 int text_chars = (text != NULL ? strlen(text) : 0);
968 int input_chars = (input != NULL ? strlen(input) : 0);
971 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
973 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
974 int text_width = font_text_width * text_chars;
975 int text_height = font_text_height;
976 int input_width = font_input_width * input_chars;
977 int input_height = font_input_height;
979 if (nr == MAIN_CONTROL_NAME)
981 menu.main.input.name.width = input_width;
982 menu.main.input.name.height = input_height;
985 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
987 pos_button->width = button_width;
988 pos_button->height = button_height;
991 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
993 /* calculate size for non-clickable text -- needed for text alignment */
994 boolean calculate_text_size = (pos_button == NULL && text != NULL);
996 if (pos_text->width == -1 || calculate_text_size)
997 pos_text->width = text_width;
998 if (pos_text->height == -1 || calculate_text_size)
999 pos_text->height = text_height;
1001 if (visibleMenuPos(pos_button))
1003 if (pos_text->x == -1)
1004 pos_text->x = pos_button->x + pos_button->width;
1005 if (pos_text->y == -1)
1007 pos_button->y + (pos_button->height - pos_text->height) / 2;
1011 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1013 if (visibleTextPos(pos_text))
1015 if (pos_input->x == -1)
1016 pos_input->x = pos_text->x + pos_text->width;
1017 if (pos_input->y == -1)
1018 pos_input->y = pos_text->y;
1021 if (pos_input->width == -1)
1022 pos_input->width = input_width;
1023 if (pos_input->height == -1)
1024 pos_input->height = input_height;
1029 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1030 int graphic, boolean pressed)
1032 struct GraphicInfo *g = &graphic_info[graphic];
1035 int xoffset = (pressed ? g->pressed_xoffset : 0);
1036 int yoffset = (pressed ? g->pressed_yoffset : 0);
1038 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1040 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1041 g->width, g->height, dst_x, dst_y);
1044 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1045 boolean active_input,
1046 boolean pressed_button)
1050 for (i = 0; main_controls[i].nr != -1; i++)
1052 struct MainControlInfo *mci = &main_controls[i];
1054 if (mci->nr == nr || nr == -1)
1056 struct MenuPosInfo *pos_button = mci->pos_button;
1057 struct TextPosInfo *pos_text = mci->pos_text;
1058 struct TextPosInfo *pos_input = mci->pos_input;
1059 char *text = (mci->text ? *mci->text : NULL);
1060 char *input = (mci->input ? *mci->input : NULL);
1061 int button_graphic = mci->button_graphic;
1062 int font_text = (pos_text ? pos_text->font : -1);
1063 int font_input = (pos_input ? pos_input->font : -1);
1067 button_graphic = BUTTON_ACTIVE(button_graphic);
1068 font_text = FONT_ACTIVE(font_text);
1073 font_input = FONT_ACTIVE(font_input);
1076 if (visibleMenuPos(pos_button))
1078 struct MenuPosInfo *pos = pos_button;
1079 int x = mSX + pos->x;
1080 int y = mSY + pos->y;
1082 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1083 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1086 if (visibleTextPos(pos_text) && text != NULL)
1088 struct TextPosInfo *pos = pos_text;
1089 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1090 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1093 /* (check why/if this is needed) */
1094 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1096 DrawText(x, y, text, font_text);
1099 if (visibleTextPos(pos_input) && input != NULL)
1101 struct TextPosInfo *pos = pos_input;
1102 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1103 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1106 /* (check why/if this is needed) */
1107 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1109 DrawText(x, y, input, font_input);
1115 static void DrawCursorAndText_Main(int nr, boolean active_text,
1116 boolean pressed_button)
1118 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1122 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1123 boolean pressed_button)
1125 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1129 static struct MainControlInfo *getMainControlInfo(int nr)
1133 for (i = 0; main_controls[i].nr != -1; i++)
1134 if (main_controls[i].nr == nr)
1135 return &main_controls[i];
1140 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1145 int rect_x = ALIGNED_TEXT_XPOS(rect);
1146 int rect_y = ALIGNED_TEXT_YPOS(rect);
1148 return (x >= rect_x && x < rect_x + rect->width &&
1149 y >= rect_y && y < rect_y + rect->height);
1152 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1157 int rect_x = ALIGNED_TEXT_XPOS(rect);
1158 int rect_y = ALIGNED_TEXT_YPOS(rect);
1161 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1162 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1163 (x >= rect_x && x < rect_x + rect->width &&
1164 y >= rect_y && y < rect_y + rect->height));
1167 return (x >= rect_x && x < rect_x + rect->width &&
1168 y >= rect_y && y < rect_y + rect->height);
1171 static void AdjustScrollbar(int id, int items_max, int items_visible,
1174 struct GadgetInfo *gi = screen_gadget[id];
1176 if (item_position > items_max - items_visible)
1177 item_position = items_max - items_visible;
1179 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1180 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1181 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1184 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1186 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1190 static void clearMenuListArea()
1192 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1194 /* correct scrollbar position if placed outside menu (playfield) area */
1195 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1196 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1198 /* clear menu list area, but not title or scrollbar */
1199 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1200 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1203 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1205 static int cursor_array[MAX_LEV_FIELDY];
1206 int x = mSX + TILEX * xpos;
1207 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1212 cursor_array[ypos] = graphic;
1214 graphic = cursor_array[ypos];
1218 graphic = BUTTON_ACTIVE(graphic);
1220 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1221 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1224 static void initCursor(int ypos, int graphic)
1226 drawCursorExt(0, ypos, FALSE, graphic);
1229 static void drawCursor(int ypos, boolean active)
1231 drawCursorExt(0, ypos, active, -1);
1234 static void drawCursorXY(int xpos, int ypos, int graphic)
1236 drawCursorExt(xpos, ypos, FALSE, graphic);
1239 static void drawChooseTreeCursor(int ypos, boolean active)
1241 int last_game_status = game_status; /* save current game status */
1243 drawCursorExt(0, ypos, active, -1);
1245 game_status = last_game_status; /* restore current game status */
1250 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1251 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1252 setup.internal.program_copyright);
1255 int effectiveGameStatus()
1257 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1258 return GAME_MODE_TITLE;
1263 void DrawTitleScreenImage(int nr, boolean initial)
1265 int graphic = getTitleScreenGraphic(nr, initial);
1266 Bitmap *bitmap = graphic_info[graphic].bitmap;
1267 int width = graphic_info[graphic].width;
1268 int height = graphic_info[graphic].height;
1269 int src_x = graphic_info[graphic].src_x;
1270 int src_y = graphic_info[graphic].src_y;
1276 if (width > WIN_XSIZE)
1278 /* image width too large for window => center image horizontally */
1279 src_x = (width - WIN_XSIZE) / 2;
1283 if (height > WIN_YSIZE)
1285 /* image height too large for window => center image vertically */
1286 src_y = (height - WIN_YSIZE) / 2;
1290 /* always display title screens centered */
1291 dst_x = (WIN_XSIZE - width) / 2;
1292 dst_y = (WIN_YSIZE - height) / 2;
1294 SetDrawBackgroundMask(REDRAW_ALL);
1295 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1297 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1299 if (DrawingOnBackground(dst_x, dst_y))
1300 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1302 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1304 redraw_mask = REDRAW_ALL;
1307 void DrawTitleScreenMessage(int nr, boolean initial)
1309 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1310 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1311 int last_game_status = game_status; /* save current game status */
1313 if (filename == NULL)
1316 /* force TITLE font on title message screen */
1317 game_status = getTitleMessageGameMode(initial);
1319 /* if chars set to "-1", automatically determine by text and font width */
1320 if (tmi->chars == -1)
1321 tmi->chars = tmi->width / getFontWidth(tmi->font);
1323 tmi->width = tmi->chars * getFontWidth(tmi->font);
1325 /* if lines set to "-1", automatically determine by text and font height */
1326 if (tmi->lines == -1)
1327 tmi->lines = tmi->height / getFontHeight(tmi->font);
1329 tmi->height = tmi->lines * getFontHeight(tmi->font);
1331 SetDrawBackgroundMask(REDRAW_ALL);
1332 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1334 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1336 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1337 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1338 tmi->autowrap, tmi->centered, tmi->parse_comments);
1340 game_status = last_game_status; /* restore current game status */
1343 void DrawTitleScreen()
1345 KeyboardAutoRepeatOff();
1347 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1352 boolean CheckTitleScreen(boolean levelset_has_changed)
1354 static boolean show_title_initial = TRUE;
1355 boolean show_titlescreen = FALSE;
1357 /* needed to be able to skip title screen, if no image or message defined */
1358 InitializeTitleControls(show_title_initial);
1360 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1361 show_titlescreen = TRUE;
1363 /* show initial title images and messages only once at program start */
1364 show_title_initial = FALSE;
1366 return (show_titlescreen && num_title_screens > 0);
1371 static LevelDirTree *leveldir_last_valid = NULL;
1372 boolean levelset_has_changed = FALSE;
1373 int fade_mask = REDRAW_FIELD;
1375 LimitScreenUpdates(FALSE);
1377 FadeSetLeaveScreen();
1379 /* do not fade out here -- function may continue and fade on editor screen */
1382 FadeSoundsAndMusic();
1384 KeyboardAutoRepeatOn();
1387 audio.sound_deactivated = FALSE;
1391 /* needed if last screen was the playing screen, invoked from level editor */
1392 if (level_editor_test_game)
1394 game_status = GAME_MODE_EDITOR;
1400 /* needed if last screen was the setup screen and fullscreen state changed */
1401 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1402 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1404 /* leveldir_current may be invalid (level group, parent link) */
1405 if (!validLevelSeries(leveldir_current))
1406 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1408 if (leveldir_current != leveldir_last_valid)
1409 levelset_has_changed = TRUE;
1411 /* store valid level series information */
1412 leveldir_last_valid = leveldir_current;
1414 init_last = init; /* switch to new busy animation */
1416 /* needed if last screen (level choice) changed graphics, sounds or music */
1417 ReloadCustomArtwork(0);
1419 /* needed if different viewport properties defined for menues */
1420 ChangeViewportPropertiesIfNeeded();
1422 if (redraw_mask & REDRAW_ALL)
1423 fade_mask = REDRAW_ALL;
1425 if (CheckIfGlobalBorderHasChanged())
1426 fade_mask = REDRAW_ALL;
1430 /* needed if last screen was the editor screen */
1431 UndrawSpecialEditorDoor();
1433 SetDrawtoField(DRAW_BACKBUFFER);
1435 if (CheckTitleScreen(levelset_has_changed))
1437 game_status = GAME_MODE_TITLE;
1444 /* level_nr may have been set to value over handicap with level editor */
1445 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1446 level_nr = leveldir_current->handicap_level;
1448 LoadLevel(level_nr);
1449 LoadScore(level_nr);
1451 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1452 SetDrawDeactivationMask(REDRAW_NONE);
1453 SetDrawBackgroundMask(REDRAW_FIELD);
1455 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1458 if (fade_mask == REDRAW_ALL)
1459 RedrawGlobalBorder();
1464 InitializeMainControls();
1466 DrawCursorAndText_Main(-1, FALSE, FALSE);
1467 DrawPreviewLevelInitial();
1469 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1472 if (TAPE_IS_EMPTY(tape))
1474 DrawCompleteVideoDisplay();
1479 /* create gadgets for main menu screen */
1480 FreeScreenGadgets();
1481 CreateScreenGadgets();
1483 /* map gadgets for main menu screen */
1485 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1487 /* copy actual game door content to door double buffer for OpenDoor() */
1488 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1489 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1491 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1493 DrawMaskedBorder(REDRAW_ALL);
1498 /* update screen area with special editor door */
1499 redraw_mask |= REDRAW_ALL;
1502 SetMouseCursor(CURSOR_DEFAULT);
1506 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1509 static void gotoTopLevelDir()
1511 /* move upwards until inside (but not above) top level directory */
1512 while (leveldir_current->node_parent &&
1513 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1515 /* write a "path" into level tree for easy navigation to last level */
1516 if (leveldir_current->node_parent->node_group->cl_first == -1)
1518 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1519 int leveldir_pos = posTreeInfo(leveldir_current);
1520 int num_page_entries;
1521 int cl_first, cl_cursor;
1523 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1524 num_page_entries = num_leveldirs;
1526 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1528 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1529 cl_cursor = leveldir_pos - cl_first;
1531 leveldir_current->node_parent->node_group->cl_first = cl_first;
1532 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1535 leveldir_current = leveldir_current->node_parent;
1539 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1541 static unsigned int title_delay = 0;
1542 static int title_screen_nr = 0;
1543 static int last_sound = -1, last_music = -1;
1544 boolean return_to_main_menu = FALSE;
1545 struct TitleControlInfo *tci;
1546 struct TitleFadingInfo fading_default;
1547 struct TitleFadingInfo fading_last = fading;
1548 struct TitleFadingInfo fading_next;
1551 if (button == MB_MENU_INITIALIZE)
1554 title_screen_nr = 0;
1555 tci = &title_controls[title_screen_nr];
1557 last_sound = SND_UNDEFINED;
1558 last_music = MUS_UNDEFINED;
1560 if (game_status == GAME_MODE_INFO)
1562 if (num_title_screens == 0)
1564 DrawInfoScreen_NotAvailable("Title screen information:",
1565 "No title screen for this level set.");
1570 FadeSoundsAndMusic();
1572 FadeOut(REDRAW_ALL);
1576 DrawTitleScreenImage(tci->local_nr, tci->initial);
1578 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1580 fading_default = (tci->initial ? title_initial_default : title_default);
1582 fading = fading_next = getTitleFading(tci);
1584 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1585 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1587 fading.fade_mode = FADE_MODE_FADE;
1588 fading.fade_delay = fading_default.fade_delay;
1591 sound = getTitleSound(tci);
1592 music = getTitleMusic(tci);
1594 if (sound != last_sound)
1595 PlayMenuSoundExt(sound);
1596 if (music != last_music)
1597 PlayMenuMusicExt(music);
1602 SetMouseCursor(CURSOR_NONE);
1606 fading = fading_next;
1608 DelayReached(&title_delay, 0); /* reset delay counter */
1613 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1614 button = MB_MENU_CHOICE;
1616 if (button == MB_MENU_LEAVE)
1618 return_to_main_menu = TRUE;
1620 else if (button == MB_MENU_CHOICE)
1622 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1624 FadeSetEnterScreen();
1626 info_mode = INFO_MODE_MAIN;
1633 tci = &title_controls[title_screen_nr];
1635 if (title_screen_nr < num_title_screens)
1637 sound = getTitleSound(tci);
1638 music = getTitleMusic(tci);
1640 if (sound == SND_UNDEFINED || sound != last_sound)
1642 if (music == MUS_UNDEFINED || music != last_music)
1645 FadeOut(REDRAW_ALL);
1648 DrawTitleScreenImage(tci->local_nr, tci->initial);
1650 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1652 fading_next = getTitleFading(tci);
1654 sound = getTitleSound(tci);
1655 music = getTitleMusic(tci);
1657 if (sound != last_sound)
1658 PlayMenuSoundExt(sound);
1659 if (music != last_music)
1660 PlayMenuMusicExt(music);
1665 /* last screen already faded out, next screen has no animation */
1666 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1667 fading_next.fade_mode == FADE_MODE_NONE)
1668 fading = fading_next;
1672 fading = fading_next;
1674 DelayReached(&title_delay, 0); /* reset delay counter */
1678 FadeSoundsAndMusic();
1680 return_to_main_menu = TRUE;
1684 if (return_to_main_menu)
1686 SetMouseCursor(CURSOR_DEFAULT);
1688 /* force full menu screen redraw after displaying title screens */
1689 redraw_mask = REDRAW_ALL;
1691 if (game_status == GAME_MODE_INFO)
1693 info_mode = INFO_MODE_MAIN;
1697 else /* default: return to main menu */
1699 game_status = GAME_MODE_MAIN;
1706 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1708 int old_level_nr = level_nr;
1711 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1712 new_level_nr = selected_level_nr;
1714 new_level_nr = old_level_nr + step * direction;
1716 if (new_level_nr < leveldir_current->first_level)
1717 new_level_nr = leveldir_current->first_level;
1718 if (new_level_nr > leveldir_current->last_level)
1719 new_level_nr = leveldir_current->last_level;
1721 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1723 /* skipping levels is only allowed when trying to skip single level */
1724 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1725 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1727 leveldir_current->handicap_level++;
1728 SaveLevelSetup_SeriesInfo();
1731 new_level_nr = leveldir_current->handicap_level;
1734 if (new_level_nr != old_level_nr)
1736 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1738 PlaySound(SND_MENU_ITEM_SELECTING);
1740 level_nr = new_level_nr;
1742 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1743 int2str(level_nr, menu.main.text.level_number.size),
1744 mci->pos_text->font);
1746 LoadLevel(level_nr);
1747 DrawPreviewLevelInitial();
1751 DrawCompleteVideoDisplay();
1753 /* needed because DrawPreviewLevelInitial() takes some time */
1755 /* SyncDisplay(); */
1759 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1761 static int choice = MAIN_CONTROL_GAME;
1762 static boolean button_pressed_last = FALSE;
1763 boolean button_pressed = FALSE;
1767 if (button == MB_MENU_INITIALIZE)
1769 DrawCursorAndText_Main(choice, TRUE, FALSE);
1774 if (mx || my) /* mouse input */
1778 for (i = 0; main_controls[i].nr != -1; i++)
1780 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1781 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1782 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1784 pos = main_controls[i].nr;
1790 // handle pressed/unpressed state for active/inactive menu buttons
1791 // (if pos != -1, "i" contains index position corresponding to "pos")
1793 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1794 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1795 button_pressed = TRUE;
1797 if (button_pressed != button_pressed_last)
1799 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1802 PlaySound(SND_MENU_BUTTON_PRESSING);
1804 PlaySound(SND_MENU_BUTTON_RELEASING);
1807 else if (dx || dy) /* keyboard input */
1809 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1810 choice == MAIN_CONTROL_SETUP))
1811 button = MB_MENU_CHOICE;
1816 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1818 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1820 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1822 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1824 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1826 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1828 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1830 game_status = GAME_MODE_LEVELNR;
1832 ChangeViewportPropertiesIfNeeded();
1834 DrawChooseLevelNr();
1836 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1842 PlaySound(SND_MENU_ITEM_ACTIVATING);
1844 DrawCursorAndText_Main(choice, FALSE, FALSE);
1845 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1852 PlaySound(SND_MENU_ITEM_SELECTING);
1854 if (pos == MAIN_CONTROL_NAME)
1856 game_status = GAME_MODE_PSEUDO_TYPENAME;
1858 HandleTypeName(strlen(setup.player_name), 0);
1860 else if (pos == MAIN_CONTROL_LEVELS)
1864 game_status = GAME_MODE_LEVELS;
1866 SaveLevelSetup_LastSeries();
1867 SaveLevelSetup_SeriesInfo();
1869 if (setup.internal.choose_from_top_leveldir)
1872 ChangeViewportPropertiesIfNeeded();
1874 DrawChooseLevelSet();
1877 else if (pos == MAIN_CONTROL_SCORES)
1879 game_status = GAME_MODE_SCORES;
1883 else if (pos == MAIN_CONTROL_EDITOR)
1885 if (leveldir_current->readonly &&
1886 !strEqual(setup.player_name, "Artsoft"))
1887 Request("This level is read only!", REQ_CONFIRM);
1889 CloseDoor(DOOR_CLOSE_2);
1891 game_status = GAME_MODE_EDITOR;
1893 FadeSetEnterScreen();
1897 else if (pos == MAIN_CONTROL_INFO)
1899 game_status = GAME_MODE_INFO;
1900 info_mode = INFO_MODE_MAIN;
1902 ChangeViewportPropertiesIfNeeded();
1906 else if (pos == MAIN_CONTROL_GAME)
1908 StartGameActions(options.network, setup.autorecord, level.random_seed);
1910 else if (pos == MAIN_CONTROL_SETUP)
1912 game_status = GAME_MODE_SETUP;
1913 setup_mode = SETUP_MODE_MAIN;
1915 ChangeViewportPropertiesIfNeeded();
1919 else if (pos == MAIN_CONTROL_QUIT)
1921 SaveLevelSetup_LastSeries();
1922 SaveLevelSetup_SeriesInfo();
1924 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1925 game_status = GAME_MODE_QUIT;
1930 button_pressed_last = button_pressed;
1934 /* ========================================================================= */
1935 /* info screen functions */
1936 /* ========================================================================= */
1938 static struct TokenInfo *info_info;
1939 static int num_info_info; /* number of info entries shown on screen */
1940 static int max_info_info; /* total number of info entries in list */
1942 static void execInfoTitleScreen()
1944 info_mode = INFO_MODE_TITLE;
1949 static void execInfoElements()
1951 info_mode = INFO_MODE_ELEMENTS;
1956 static void execInfoMusic()
1958 info_mode = INFO_MODE_MUSIC;
1963 static void execInfoCredits()
1965 info_mode = INFO_MODE_CREDITS;
1970 static void execInfoProgram()
1972 info_mode = INFO_MODE_PROGRAM;
1977 static void execInfoVersion()
1979 info_mode = INFO_MODE_VERSION;
1984 static void execInfoLevelSet()
1986 info_mode = INFO_MODE_LEVELSET;
1991 static void execExitInfo()
1993 game_status = GAME_MODE_MAIN;
1998 static struct TokenInfo info_info_main[] =
2000 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2001 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2002 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2003 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2004 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2005 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2006 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2007 { TYPE_EMPTY, NULL, "" },
2008 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2013 static int getMenuTextFont(int type)
2015 if (type & (TYPE_SWITCH |
2027 static struct TokenInfo *setup_info;
2028 static struct TokenInfo setup_info_input[];
2030 static struct TokenInfo *menu_info;
2032 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2033 int screen_pos, int menu_info_pos_raw,
2036 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2037 struct TokenInfo *ti = &token_info[pos];
2038 int xpos = MENU_SCREEN_START_XPOS;
2039 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2040 int font_nr = getMenuTextFont(ti->type);
2042 if (token_info == setup_info_input)
2043 font_nr = FONT_MENU_1;
2046 font_nr = FONT_ACTIVE(font_nr);
2048 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2050 if (ti->type & ~TYPE_SKIP_ENTRY)
2051 drawCursor(screen_pos, active);
2054 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2057 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2060 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2063 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2066 static char *screen_mode_text;
2067 static char *window_size_text;
2068 static char *scaling_type_text;
2070 static void drawSetupValue(int, int);
2072 static void drawMenuInfoList(int first_entry, int num_page_entries,
2073 int max_page_entries)
2077 if (first_entry + num_page_entries > max_page_entries)
2080 clearMenuListArea();
2082 for (i = 0; i < num_page_entries; i++)
2084 int menu_info_pos = first_entry + i;
2085 struct TokenInfo *si = &menu_info[menu_info_pos];
2086 void *value_ptr = si->value;
2088 /* set some entries to "unchangeable" according to other variables */
2089 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2090 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2091 (value_ptr == &setup.sound_music && !audio.music_available) ||
2092 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2093 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2094 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2095 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2096 si->type |= TYPE_GHOSTED;
2098 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2099 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2100 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2101 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2102 else if (si->type & ~TYPE_SKIP_ENTRY)
2103 initCursor(i, IMG_MENU_BUTTON);
2105 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2107 if (si->type & TYPE_VALUE &&
2108 menu_info == setup_info)
2109 drawSetupValue(i, menu_info_pos);
2113 static void DrawInfoScreen_Main()
2115 int fade_mask = REDRAW_FIELD;
2118 if (redraw_mask & REDRAW_ALL)
2119 fade_mask = REDRAW_ALL;
2121 if (CheckIfGlobalBorderHasChanged())
2122 fade_mask = REDRAW_ALL;
2126 FreeScreenGadgets();
2127 CreateScreenGadgets();
2129 CloseDoor(DOOR_CLOSE_2);
2131 /* (needed after displaying title screens which disable auto repeat) */
2132 KeyboardAutoRepeatOn();
2134 FadeSetLeaveScreen();
2138 if (fade_mask == REDRAW_ALL)
2140 RedrawGlobalBorder();
2142 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2147 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2149 info_info = info_info_main;
2151 // determine maximal number of info entries that can be displayed on screen
2153 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2156 // determine maximal number of info entries available for menu of info screen
2158 for (i = 0; info_info[i].type != 0; i++)
2161 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2163 MapScreenGadgets(max_info_info);
2168 DrawMaskedBorder(fade_mask);
2175 static void changeSetupValue(int, int, int);
2177 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2178 int mode, int num_page_entries, int max_page_entries)
2180 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2181 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2182 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2183 int *num_page_entries_last = num_page_entries_all_last[game_status];
2184 int *choice_store = choice_stores[game_status];
2185 int *first_entry_store = first_entry_stores[game_status];
2186 int choice = choice_store[mode]; /* starts with 0 */
2187 int first_entry = first_entry_store[mode]; /* starts with 0 */
2189 int y = choice - first_entry;
2191 boolean position_set_by_scrollbar = (dx == 999);
2192 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2195 if (button == MB_MENU_INITIALIZE)
2197 // check if number of menu page entries has changed (may happen by change
2198 // of custom artwork definition value for 'list_size' for this menu screen)
2199 // (in this case, the last menu position most probably has to be corrected)
2200 if (num_page_entries != num_page_entries_last[mode])
2202 choice_store[mode] = first_entry_store[mode] = 0;
2204 choice = first_entry = 0;
2207 num_page_entries_last[mode] = num_page_entries;
2210 /* advance to first valid menu entry */
2211 while (choice < num_page_entries &&
2212 menu_info[choice].type & TYPE_SKIP_ENTRY)
2215 if (position_set_by_scrollbar)
2216 first_entry = first_entry_store[mode] = dy;
2218 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2219 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2221 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2223 if (choice < first_entry)
2225 choice = first_entry;
2227 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2230 else if (choice > first_entry + num_page_entries - 1)
2232 choice = first_entry + num_page_entries - 1;
2234 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2238 choice_store[mode] = choice;
2240 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2244 else if (button == MB_MENU_LEAVE)
2246 PlaySound(SND_MENU_ITEM_SELECTING);
2248 for (i = 0; i < max_page_entries; i++)
2250 if (menu_info[i].type & TYPE_LEAVE_MENU)
2252 void (*menu_callback_function)(void) = menu_info[i].value;
2256 menu_callback_function();
2258 break; /* absolutely needed because function changes 'menu_info'! */
2265 if (mx || my) /* mouse input */
2267 x = (mx - mSX) / 32;
2268 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2270 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2272 /* move cursor instead of scrolling when already at start/end of list */
2273 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2275 else if (dy == +1 * SCROLL_LINE &&
2276 first_entry + num_page_entries == max_page_entries)
2279 /* handle scrolling screen one line or page */
2281 y + dy > num_page_entries - 1)
2283 boolean redraw = FALSE;
2285 if (ABS(dy) == SCROLL_PAGE)
2286 step = num_page_entries - 1;
2288 if (dy < 0 && first_entry > 0)
2290 /* scroll page/line up */
2292 first_entry -= step;
2293 if (first_entry < 0)
2298 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2300 /* scroll page/line down */
2302 first_entry += step;
2303 if (first_entry + num_page_entries > max_page_entries)
2304 first_entry = MAX(0, max_page_entries - num_page_entries);
2311 choice += first_entry - first_entry_store[mode];
2313 if (choice < first_entry)
2315 choice = first_entry;
2317 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2320 else if (choice > first_entry + num_page_entries - 1)
2322 choice = first_entry + num_page_entries - 1;
2324 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2327 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2331 if (choice < first_entry ||
2332 choice > first_entry + num_page_entries - 1)
2333 first_entry += SIGN(dy);
2336 first_entry_store[mode] = first_entry;
2337 choice_store[mode] = choice;
2339 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2341 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2343 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2344 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2352 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2354 if (menu_info[choice].type & menu_navigation_type ||
2355 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2356 menu_info[choice].type & TYPE_YES_NO_AUTO)
2357 button = MB_MENU_CHOICE;
2362 /* jump to next non-empty menu entry (up or down) */
2363 while (first_entry + y > 0 &&
2364 first_entry + y < max_page_entries - 1 &&
2365 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2368 if (!IN_VIS_MENU(x, y))
2370 choice += y - y_old;
2372 if (choice < first_entry)
2373 first_entry = choice;
2374 else if (choice > first_entry + num_page_entries - 1)
2375 first_entry = choice - num_page_entries + 1;
2377 if (first_entry >= 0 &&
2378 first_entry + num_page_entries <= max_page_entries)
2380 first_entry_store[mode] = first_entry;
2382 if (choice < first_entry)
2383 choice = first_entry;
2384 else if (choice > first_entry + num_page_entries - 1)
2385 choice = first_entry + num_page_entries - 1;
2387 choice_store[mode] = choice;
2389 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2391 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2393 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2394 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2401 if (!anyScrollbarGadgetActive() &&
2402 IN_VIS_MENU(x, y) &&
2403 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2404 y >= 0 && y < num_page_entries)
2408 if (first_entry + y != choice &&
2409 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2411 PlaySound(SND_MENU_ITEM_ACTIVATING);
2413 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2414 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2416 choice = choice_store[mode] = first_entry + y;
2419 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2421 PlaySound(SND_MENU_ITEM_SELECTING);
2423 /* when selecting key headline, execute function for key value change */
2424 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2425 menu_info[first_entry + y + 1].type & TYPE_KEY)
2428 /* when selecting string value, execute function for list selection */
2429 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2430 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2433 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2435 void (*menu_callback_function)(void) =
2436 menu_info[first_entry + y].value;
2438 FadeSetFromType(menu_info[first_entry + y].type);
2440 menu_callback_function();
2442 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2443 menu_info == setup_info)
2445 changeSetupValue(y, first_entry + y, dx);
2451 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2453 menu_info = info_info;
2455 HandleMenuScreen(mx, my, dx, dy, button,
2456 info_mode, num_info_info, max_info_info);
2459 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2461 int ystart1 = mSY - SY + 100;
2462 int ystart2 = mSY - SY + 150;
2463 int ybottom = mSY - SY + SYSIZE - 20;
2465 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2467 FadeOut(REDRAW_FIELD);
2472 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2473 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2475 DrawTextSCentered(ybottom, FONT_TEXT_4,
2476 "Press any key or button for info menu");
2478 FadeIn(REDRAW_FIELD);
2481 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2483 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2484 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2485 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2486 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2487 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2488 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2489 int ystep = MENU_SCREEN_INFO_YSTEP;
2490 int element, action, direction;
2498 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2499 infoscreen_step[i] = infoscreen_frame[i] = 0;
2504 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2506 DrawTextSCentered(ybottom, FONT_TEXT_4,
2507 "Press any key or button for next page");
2513 while (helpanim_info[j].element != HELPANIM_LIST_END)
2515 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2520 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2529 j += infoscreen_step[i - start];
2531 element = helpanim_info[j].element;
2532 action = helpanim_info[j].action;
2533 direction = helpanim_info[j].direction;
2536 element = EL_UNKNOWN;
2538 if (action != -1 && direction != -1)
2539 graphic = el_act_dir2img(element, action, direction);
2540 else if (action != -1)
2541 graphic = el_act2img(element, action);
2542 else if (direction != -1)
2543 graphic = el_dir2img(element, direction);
2545 graphic = el2img(element);
2547 delay = helpanim_info[j++].delay;
2552 if (infoscreen_frame[i - start] == 0)
2555 infoscreen_frame[i - start] = delay - 1;
2559 sync_frame = delay - infoscreen_frame[i - start];
2560 infoscreen_frame[i - start]--;
2563 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2565 if (!infoscreen_frame[i - start])
2566 infoscreen_step[i - start] = 0;
2570 if (!infoscreen_frame[i - start])
2571 infoscreen_step[i - start]++;
2572 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2578 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2580 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2581 graphic, sync_frame, USE_MASKING);
2584 DrawInfoScreen_HelpText(element, action, direction, i - start);
2589 redraw_mask |= REDRAW_FIELD;
2594 static char *getHelpText(int element, int action, int direction)
2596 char token[MAX_LINE_LEN];
2598 strcpy(token, element_info[element].token_name);
2601 strcat(token, element_action_info[action].suffix);
2603 if (direction != -1)
2604 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2606 return getHashEntry(helptext_info, token);
2609 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2611 int font_nr = FONT_INFO_ELEMENTS;
2612 int font_width = getFontWidth(font_nr);
2613 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2614 int sy = mSY + 65 + 2 * 32 + 1;
2615 int ystep = TILEY + 4;
2616 int pad_x = sx - SX;
2617 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2618 int max_lines_per_text = 2;
2621 if (action != -1 && direction != -1) /* element.action.direction */
2622 text = getHelpText(element, action, direction);
2624 if (text == NULL && action != -1) /* element.action */
2625 text = getHelpText(element, action, -1);
2627 if (text == NULL && direction != -1) /* element.direction */
2628 text = getHelpText(element, -1, direction);
2630 if (text == NULL) /* base element */
2631 text = getHelpText(element, -1, -1);
2633 if (text == NULL) /* not found */
2634 text = "No description available";
2636 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2637 sy += getFontHeight(font_nr) / 2;
2639 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2640 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2641 TRUE, FALSE, FALSE);
2644 void DrawInfoScreen_TitleScreen()
2649 void HandleInfoScreen_TitleScreen(int button)
2651 HandleTitleScreen(0, 0, 0, 0, button);
2654 void DrawInfoScreen_Elements()
2656 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2658 FadeOut(REDRAW_FIELD);
2663 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2665 FadeIn(REDRAW_FIELD);
2670 void HandleInfoScreen_Elements(int button)
2672 static unsigned int info_delay = 0;
2673 static int num_anims;
2674 static int num_pages;
2676 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2679 if (button == MB_MENU_INITIALIZE)
2681 boolean new_element = TRUE;
2685 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2687 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2689 else if (new_element)
2692 new_element = FALSE;
2696 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2700 if (button == MB_MENU_LEAVE)
2702 PlaySound(SND_MENU_ITEM_SELECTING);
2704 info_mode = INFO_MODE_MAIN;
2709 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2711 if (button != MB_MENU_INITIALIZE)
2713 PlaySound(SND_MENU_ITEM_SELECTING);
2718 if (page >= num_pages)
2720 FadeSoundsAndMusic();
2722 info_mode = INFO_MODE_MAIN;
2729 FadeSetNextScreen();
2731 if (button != MB_MENU_INITIALIZE)
2732 FadeOut(REDRAW_FIELD);
2734 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2736 if (button != MB_MENU_INITIALIZE)
2737 FadeIn(REDRAW_FIELD);
2741 if (DelayReached(&info_delay, GameFrameDelay))
2742 if (page < num_pages)
2743 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2745 PlayMenuSoundIfLoop();
2749 void DrawInfoScreen_Music()
2751 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2753 FadeOut(REDRAW_FIELD);
2760 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2762 FadeIn(REDRAW_FIELD);
2765 void HandleInfoScreen_Music(int button)
2767 static struct MusicFileInfo *list = NULL;
2768 int ystart1 = mSY - SY + 100;
2769 int ystart2 = mSY - SY + 150;
2770 int ybottom = mSY - SY + SYSIZE - 20;
2773 if (button == MB_MENU_INITIALIZE)
2775 list = music_file_info;
2779 FadeSoundsAndMusic();
2784 DrawTextSCentered(ystart1, FONT_TEXT_1,
2785 "No music info for this level set.");
2787 DrawTextSCentered(ybottom, FONT_TEXT_4,
2788 "Press any key or button for info menu");
2794 if (button == MB_MENU_LEAVE)
2796 PlaySound(SND_MENU_ITEM_SELECTING);
2798 FadeSoundsAndMusic();
2800 info_mode = INFO_MODE_MAIN;
2805 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2809 if (button != MB_MENU_INITIALIZE)
2811 PlaySound(SND_MENU_ITEM_SELECTING);
2819 FadeSoundsAndMusic();
2821 info_mode = INFO_MODE_MAIN;
2827 FadeSoundsAndMusic();
2829 if (list != music_file_info)
2830 FadeSetNextScreen();
2832 if (button != MB_MENU_INITIALIZE)
2833 FadeOut(REDRAW_FIELD);
2840 int sound = list->music;
2842 if (sound_info[sound].loop)
2843 PlaySoundLoop(sound);
2847 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2851 PlayMusic(list->music);
2853 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2856 if (!strEqual(list->title, UNKNOWN_NAME))
2858 if (!strEqual(list->title_header, UNKNOWN_NAME))
2859 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2861 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2864 if (!strEqual(list->artist, UNKNOWN_NAME))
2866 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2867 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2869 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2871 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2874 if (!strEqual(list->album, UNKNOWN_NAME))
2876 if (!strEqual(list->album_header, UNKNOWN_NAME))
2877 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2879 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2881 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2884 if (!strEqual(list->year, UNKNOWN_NAME))
2886 if (!strEqual(list->year_header, UNKNOWN_NAME))
2887 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2889 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2891 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2894 DrawTextSCentered(ybottom, FONT_TEXT_4,
2895 "Press any key or button for next page");
2897 if (button != MB_MENU_INITIALIZE)
2898 FadeIn(REDRAW_FIELD);
2901 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2902 PlaySoundLoop(list->music);
2905 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2907 int ystart1 = mSY - SY + 100;
2908 int ystart2 = mSY - SY + 150;
2909 int ybottom = mSY - SY + SYSIZE - 20;
2915 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2919 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2920 "Special thanks to");
2921 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2923 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2925 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2926 "\"Boulder Dash\"");
2927 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2929 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2931 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2933 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2934 "First Star Software");
2936 else if (screen_nr == 1)
2938 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2939 "Special thanks to");
2940 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2941 "Klaus Heinz & Volker Wertich");
2942 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2944 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2945 "\"Emerald Mine\"");
2946 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2948 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2950 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2952 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2955 else if (screen_nr == 2)
2957 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2958 "Special thanks to");
2959 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2960 "Michael Stopp & Philip Jespersen");
2961 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2963 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2965 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2967 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2969 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2971 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2972 "Digital Integration");
2974 else if (screen_nr == 3)
2976 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2977 "Special thanks to");
2978 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2979 "Hiroyuki Imabayashi");
2980 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2982 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2984 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2986 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2988 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2990 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2993 else if (screen_nr == 4)
2995 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2996 "Special thanks to");
2997 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2999 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3001 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3002 "J\xfcrgen Bonhagen");
3003 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3004 "for the continuous creation");
3005 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3006 "of outstanding level sets");
3008 else if (screen_nr == 5)
3010 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3012 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3015 "for ideas and inspiration by");
3016 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3019 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3021 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3023 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3024 "for ideas and inspiration by");
3025 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3028 else if (screen_nr == 6)
3030 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3032 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3035 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3036 "for the code base used for the");
3037 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3038 "native Emerald Mine engine");
3040 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3041 "for the new Emerald Mine engine");
3044 else if (screen_nr == 7)
3046 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3048 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3050 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3051 "for the initial DOS port");
3053 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3055 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3057 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3058 "for some additional toons");
3060 else if (screen_nr == 8)
3062 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3063 "And not to forget:");
3064 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3066 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3067 "All those who contributed");
3068 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3069 "levels to this game");
3070 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3074 DrawTextSCentered(ybottom, FONT_TEXT_4,
3075 "Press any key or button for next page");
3078 void DrawInfoScreen_Credits()
3080 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3082 FadeSoundsAndMusic();
3084 FadeOut(REDRAW_FIELD);
3086 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3088 FadeIn(REDRAW_FIELD);
3091 void HandleInfoScreen_Credits(int button)
3093 static int screen_nr = 0;
3094 int num_screens = 9;
3096 if (button == MB_MENU_INITIALIZE)
3100 // DrawInfoScreen_CreditsScreen(screen_nr);
3103 if (button == MB_MENU_LEAVE)
3105 PlaySound(SND_MENU_ITEM_SELECTING);
3107 info_mode = INFO_MODE_MAIN;
3112 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3114 if (button != MB_MENU_INITIALIZE)
3116 PlaySound(SND_MENU_ITEM_SELECTING);
3121 if (screen_nr >= num_screens)
3123 FadeSoundsAndMusic();
3125 info_mode = INFO_MODE_MAIN;
3132 FadeSetNextScreen();
3134 if (button != MB_MENU_INITIALIZE)
3135 FadeOut(REDRAW_FIELD);
3137 DrawInfoScreen_CreditsScreen(screen_nr);
3139 if (button != MB_MENU_INITIALIZE)
3140 FadeIn(REDRAW_FIELD);
3144 PlayMenuSoundIfLoop();
3148 void DrawInfoScreen_Program()
3150 int ystart1 = mSY - SY + 100;
3151 int ystart2 = mSY - SY + 150;
3152 int ybottom = mSY - SY + SYSIZE - 20;
3155 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3157 FadeOut(REDRAW_FIELD);
3162 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3164 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3165 "This game is Freeware!");
3166 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3167 "If you like it, send e-mail to:");
3168 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3169 setup.internal.program_email);
3170 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3171 "More information and levels:");
3172 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3173 setup.internal.program_website);
3174 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3175 "If you have created new levels,");
3176 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3177 "send them to me to include them!");
3178 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3181 DrawTextSCentered(ybottom, FONT_TEXT_4,
3182 "Press any key or button for info menu");
3184 FadeIn(REDRAW_FIELD);
3187 void HandleInfoScreen_Program(int button)
3189 if (button == MB_MENU_LEAVE)
3191 PlaySound(SND_MENU_ITEM_SELECTING);
3193 info_mode = INFO_MODE_MAIN;
3198 else if (button == MB_MENU_CHOICE)
3200 PlaySound(SND_MENU_ITEM_SELECTING);
3202 FadeSoundsAndMusic();
3204 info_mode = INFO_MODE_MAIN;
3209 PlayMenuSoundIfLoop();
3213 void DrawInfoScreen_Version()
3215 int font_header = FONT_TEXT_3;
3216 int font_text = FONT_TEXT_2;
3217 int xstep = getFontWidth(font_text);
3218 int ystep = getFontHeight(font_text);
3219 int ystart1 = mSY - SY + 100;
3220 int ystart2 = mSY - SY + 150;
3221 int ybottom = mSY - SY + SYSIZE - 20;
3222 int xstart1 = mSX - SX + 2 * xstep;
3223 int xstart2 = mSX - SX + 18 * xstep;
3224 int xstart3 = mSX - SX + 28 * xstep;
3225 SDL_version sdl_version_compiled;
3226 const SDL_version *sdl_version_linked;
3227 int driver_name_len = 10;
3228 #if defined(TARGET_SDL2)
3229 SDL_version sdl_version_linked_ext;
3230 const char *driver_name = NULL;
3232 char driver_name[driver_name_len];
3235 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3237 FadeOut(REDRAW_FIELD);
3242 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3244 DrawTextF(xstart1, ystart2, font_header, "Name");
3245 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3248 DrawTextF(xstart1, ystart2, font_header, "Version");
3249 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3252 DrawTextF(xstart1, ystart2, font_header, "Platform");
3253 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3256 DrawTextF(xstart1, ystart2, font_header, "Target");
3257 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3260 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3261 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3263 ystart2 += 3 * ystep;
3264 DrawTextF(xstart1, ystart2, font_header, "Library");
3265 DrawTextF(xstart2, ystart2, font_header, "compiled");
3266 DrawTextF(xstart3, ystart2, font_header, "linked");
3268 SDL_VERSION(&sdl_version_compiled);
3269 #if defined(TARGET_SDL2)
3270 SDL_GetVersion(&sdl_version_linked_ext);
3271 sdl_version_linked = &sdl_version_linked_ext;
3273 sdl_version_linked = SDL_Linked_Version();
3276 ystart2 += 2 * ystep;
3277 DrawTextF(xstart1, ystart2, font_text, "SDL");
3278 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3279 sdl_version_compiled.major,
3280 sdl_version_compiled.minor,
3281 sdl_version_compiled.patch);
3282 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3283 sdl_version_linked->major,
3284 sdl_version_linked->minor,
3285 sdl_version_linked->patch);
3287 SDL_IMAGE_VERSION(&sdl_version_compiled);
3288 sdl_version_linked = IMG_Linked_Version();
3291 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3292 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3293 sdl_version_compiled.major,
3294 sdl_version_compiled.minor,
3295 sdl_version_compiled.patch);
3296 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3297 sdl_version_linked->major,
3298 sdl_version_linked->minor,
3299 sdl_version_linked->patch);
3301 SDL_MIXER_VERSION(&sdl_version_compiled);
3302 sdl_version_linked = Mix_Linked_Version();
3305 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3306 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3307 sdl_version_compiled.major,
3308 sdl_version_compiled.minor,
3309 sdl_version_compiled.patch);
3310 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3311 sdl_version_linked->major,
3312 sdl_version_linked->minor,
3313 sdl_version_linked->patch);
3315 SDL_NET_VERSION(&sdl_version_compiled);
3316 sdl_version_linked = SDLNet_Linked_Version();
3319 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3320 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3321 sdl_version_compiled.major,
3322 sdl_version_compiled.minor,
3323 sdl_version_compiled.patch);
3324 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3325 sdl_version_linked->major,
3326 sdl_version_linked->minor,
3327 sdl_version_linked->patch);
3329 ystart2 += 3 * ystep;
3330 DrawTextF(xstart1, ystart2, font_header, "Driver");
3331 DrawTextF(xstart2, ystart2, font_header, "Requested");
3332 DrawTextF(xstart3, ystart2, font_header, "Used");
3334 #if defined(TARGET_SDL2)
3335 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3337 SDL_VideoDriverName(driver_name, driver_name_len);
3340 ystart2 += 2 * ystep;
3341 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3342 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3343 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3345 #if defined(TARGET_SDL2)
3346 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3348 SDL_AudioDriverName(driver_name, driver_name_len);
3352 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3353 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3354 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3356 DrawTextSCentered(ybottom, FONT_TEXT_4,
3357 "Press any key or button for info menu");
3359 FadeIn(REDRAW_FIELD);
3362 void HandleInfoScreen_Version(int button)
3364 if (button == MB_MENU_LEAVE)
3366 PlaySound(SND_MENU_ITEM_SELECTING);
3368 info_mode = INFO_MODE_MAIN;
3373 else if (button == MB_MENU_CHOICE)
3375 PlaySound(SND_MENU_ITEM_SELECTING);
3377 FadeSoundsAndMusic();
3379 info_mode = INFO_MODE_MAIN;
3384 PlayMenuSoundIfLoop();
3388 void DrawInfoScreen_LevelSet()
3390 struct TitleMessageInfo *tmi = &readme;
3391 char *filename = getLevelSetInfoFilename();
3392 char *title = "Level Set Information:";
3393 int ystart1 = mSY - SY + 100;
3394 int ybottom = mSY - SY + SYSIZE - 20;
3396 if (filename == NULL)
3398 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3403 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3405 FadeOut(REDRAW_FIELD);
3410 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3412 /* if x position set to "-1", automatically determine by playfield width */
3414 tmi->x = SXSIZE / 2;
3416 /* if y position set to "-1", use static default value */
3420 /* if width set to "-1", automatically determine by playfield width */
3421 if (tmi->width == -1)
3422 tmi->width = SXSIZE - 2 * TILEX;
3424 /* if height set to "-1", automatically determine by playfield height */
3425 if (tmi->height == -1)
3426 tmi->height = SYSIZE - 20 - tmi->y - 10;
3428 /* if chars set to "-1", automatically determine by text and font width */
3429 if (tmi->chars == -1)
3430 tmi->chars = tmi->width / getFontWidth(tmi->font);
3432 tmi->width = tmi->chars * getFontWidth(tmi->font);
3434 /* if lines set to "-1", automatically determine by text and font height */
3435 if (tmi->lines == -1)
3436 tmi->lines = tmi->height / getFontHeight(tmi->font);
3438 tmi->height = tmi->lines * getFontHeight(tmi->font);
3440 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3441 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3442 tmi->autowrap, tmi->centered, tmi->parse_comments);
3444 DrawTextSCentered(ybottom, FONT_TEXT_4,
3445 "Press any key or button for info menu");
3447 FadeIn(REDRAW_FIELD);
3450 void HandleInfoScreen_LevelSet(int button)
3452 if (button == MB_MENU_LEAVE)
3454 PlaySound(SND_MENU_ITEM_SELECTING);
3456 info_mode = INFO_MODE_MAIN;
3461 else if (button == MB_MENU_CHOICE)
3463 PlaySound(SND_MENU_ITEM_SELECTING);
3465 FadeSoundsAndMusic();
3467 info_mode = INFO_MODE_MAIN;
3472 PlayMenuSoundIfLoop();
3476 static void DrawInfoScreen()
3478 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3480 if (info_mode == INFO_MODE_TITLE)
3481 DrawInfoScreen_TitleScreen();
3482 else if (info_mode == INFO_MODE_ELEMENTS)
3483 DrawInfoScreen_Elements();
3484 else if (info_mode == INFO_MODE_MUSIC)
3485 DrawInfoScreen_Music();
3486 else if (info_mode == INFO_MODE_CREDITS)
3487 DrawInfoScreen_Credits();
3488 else if (info_mode == INFO_MODE_PROGRAM)
3489 DrawInfoScreen_Program();
3490 else if (info_mode == INFO_MODE_VERSION)
3491 DrawInfoScreen_Version();
3492 else if (info_mode == INFO_MODE_LEVELSET)
3493 DrawInfoScreen_LevelSet();
3495 DrawInfoScreen_Main();
3497 if (info_mode != INFO_MODE_MAIN &&
3498 info_mode != INFO_MODE_TITLE &&
3499 info_mode != INFO_MODE_MUSIC)
3506 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3508 if (info_mode == INFO_MODE_TITLE)
3509 HandleInfoScreen_TitleScreen(button);
3510 else if (info_mode == INFO_MODE_ELEMENTS)
3511 HandleInfoScreen_Elements(button);
3512 else if (info_mode == INFO_MODE_MUSIC)
3513 HandleInfoScreen_Music(button);
3514 else if (info_mode == INFO_MODE_CREDITS)
3515 HandleInfoScreen_Credits(button);
3516 else if (info_mode == INFO_MODE_PROGRAM)
3517 HandleInfoScreen_Program(button);
3518 else if (info_mode == INFO_MODE_VERSION)
3519 HandleInfoScreen_Version(button);
3520 else if (info_mode == INFO_MODE_LEVELSET)
3521 HandleInfoScreen_LevelSet(button);
3523 HandleInfoScreen_Main(mx, my, dx, dy, button);
3527 /* ========================================================================= */
3528 /* type name functions */
3529 /* ========================================================================= */
3531 void HandleTypeName(int newxpos, Key key)
3533 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3534 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3535 struct TextPosInfo *pos = mci->pos_input;
3536 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3537 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3538 static int xpos = 0;
3539 int font_nr = pos->font;
3540 int font_active_nr = FONT_ACTIVE(font_nr);
3541 int font_width = getFontWidth(font_active_nr);
3542 char key_char = getValidConfigValueChar(getCharFromKey(key));
3543 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3544 boolean is_active = TRUE;
3546 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3550 strcpy(last_player_name, setup.player_name);
3554 #if defined(TARGET_SDL2)
3555 SDL_StartTextInput();
3558 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3560 setup.player_name[xpos] = key_char;
3561 setup.player_name[xpos + 1] = 0;
3565 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3569 setup.player_name[xpos] = 0;
3571 else if (key == KSYM_Return && xpos > 0)
3577 game_status = GAME_MODE_MAIN;
3579 else if (key == KSYM_Escape)
3581 strcpy(setup.player_name, last_player_name);
3585 game_status = GAME_MODE_MAIN;
3590 pos->width = (strlen(setup.player_name) + 1) * font_width;
3591 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3593 DrawText(startx, starty, setup.player_name, font_active_nr);
3594 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3598 pos->width = strlen(setup.player_name) * font_width;
3599 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3601 DrawText(startx, starty, setup.player_name, font_nr);
3603 #if defined(TARGET_SDL2)
3604 SDL_StopTextInput();
3610 /* ========================================================================= */
3611 /* tree menu functions */
3612 /* ========================================================================= */
3614 static void DrawChooseTree(TreeInfo **ti_ptr)
3616 int fade_mask = REDRAW_FIELD;
3618 if (CheckIfGlobalBorderHasChanged())
3619 fade_mask = REDRAW_ALL;
3621 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3623 game_status = GAME_MODE_MAIN;
3632 FreeScreenGadgets();
3633 CreateScreenGadgets();
3635 CloseDoor(DOOR_CLOSE_2);
3641 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3642 MapScreenTreeGadgets(*ti_ptr);
3649 static void drawChooseTreeList(int first_entry, int num_page_entries,
3653 char *title_string = NULL;
3654 int yoffset_sets = MENU_TITLE1_YPOS;
3655 int yoffset_setup = 16;
3656 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3657 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3658 int last_game_status = game_status; /* save current game status */
3660 title_string = ti->infotext;
3662 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3664 clearMenuListArea();
3666 for (i = 0; i < num_page_entries; i++)
3668 TreeInfo *node, *node_first;
3669 int entry_pos = first_entry + i;
3670 int xpos = MENU_SCREEN_START_XPOS;
3671 int ypos = MENU_SCREEN_START_YPOS + i;
3672 int startx = mSX + xpos * 32;
3673 int starty = mSY + ypos * 32;
3674 int font_nr = FONT_TEXT_1;
3675 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3676 int startx_text = startx + font_xoffset;
3677 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3678 int text_size = startx_scrollbar - startx_text;
3679 int max_buffer_len = text_size / getFontWidth(font_nr);
3680 char buffer[max_buffer_len + 1];
3682 node_first = getTreeInfoFirstGroupEntry(ti);
3683 node = getTreeInfoFromPos(node_first, entry_pos);
3685 strncpy(buffer, node->name, max_buffer_len);
3686 buffer[max_buffer_len] = '\0';
3688 DrawText(startx, starty, buffer, font_nr + node->color);
3690 if (node->parent_link)
3691 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3692 else if (node->level_group)
3693 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3695 initCursor(i, IMG_MENU_BUTTON);
3698 game_status = last_game_status; /* restore current game status */
3700 redraw_mask |= REDRAW_FIELD;
3703 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3705 TreeInfo *node, *node_first;
3706 int x, last_redraw_mask = redraw_mask;
3707 int ypos = MENU_TITLE2_YPOS;
3708 int font_nr = FONT_TITLE_2;
3710 if (ti->type == TREE_TYPE_LEVEL_NR)
3711 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3713 if (ti->type != TREE_TYPE_LEVEL_DIR)
3716 node_first = getTreeInfoFirstGroupEntry(ti);
3717 node = getTreeInfoFromPos(node_first, entry_pos);
3719 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3721 if (node->parent_link)
3722 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3723 node->node_parent->name);
3724 else if (node->level_group)
3725 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3727 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3728 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3729 node->levels, (node->levels > 1 ? "levels" : "level"),
3732 /* let BackToFront() redraw only what is needed */
3733 redraw_mask = last_redraw_mask;
3734 for (x = 0; x < SCR_FIELDX; x++)
3735 MarkTileDirty(x, 1);
3738 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3741 TreeInfo *ti = *ti_ptr;
3743 int y = ti->cl_cursor;
3744 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3745 int num_entries = numTreeInfoInGroup(ti);
3746 int num_page_entries;
3747 int last_game_status = game_status; /* save current game status */
3748 boolean position_set_by_scrollbar = (dx == 999);
3750 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3751 num_page_entries = num_entries;
3753 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3755 game_status = last_game_status; /* restore current game status */
3757 if (button == MB_MENU_INITIALIZE)
3759 int num_entries = numTreeInfoInGroup(ti);
3760 int entry_pos = posTreeInfo(ti);
3762 if (ti->cl_first == -1)
3764 /* only on initialization */
3765 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3766 ti->cl_cursor = entry_pos - ti->cl_first;
3768 else if (ti->cl_cursor >= num_page_entries ||
3769 (num_entries > num_page_entries &&
3770 num_entries - ti->cl_first < num_page_entries))
3772 /* only after change of list size (by custom graphic configuration) */
3773 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3774 ti->cl_cursor = entry_pos - ti->cl_first;
3777 if (position_set_by_scrollbar)
3780 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3783 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3784 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3785 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3789 else if (button == MB_MENU_LEAVE)
3793 PlaySound(SND_MENU_ITEM_SELECTING);
3795 if (ti->node_parent)
3797 *ti_ptr = ti->node_parent;
3798 DrawChooseTree(ti_ptr);
3800 else if (game_status == GAME_MODE_SETUP)
3802 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3803 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3804 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3806 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3807 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3808 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3809 execSetupGraphics();
3810 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3811 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3812 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3814 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3815 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3816 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3823 if (game_status == GAME_MODE_LEVELNR)
3825 int new_level_nr = atoi(level_number_current->identifier);
3827 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3830 game_status = GAME_MODE_MAIN;
3838 if (mx || my) /* mouse input */
3840 int last_game_status = game_status; /* save current game status */
3842 x = (mx - mSX) / 32;
3843 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3845 game_status = last_game_status; /* restore current game status */
3847 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3849 /* move cursor instead of scrolling when already at start/end of list */
3850 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3852 else if (dy == +1 * SCROLL_LINE &&
3853 ti->cl_first + num_page_entries == num_entries)
3856 /* handle scrolling screen one line or page */
3857 if (ti->cl_cursor + dy < 0 ||
3858 ti->cl_cursor + dy > num_page_entries - 1)
3860 boolean redraw = FALSE;
3862 if (ABS(dy) == SCROLL_PAGE)
3863 step = num_page_entries - 1;
3865 if (dy < 0 && ti->cl_first > 0)
3867 /* scroll page/line up */
3869 ti->cl_first -= step;
3870 if (ti->cl_first < 0)
3875 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3877 /* scroll page/line down */
3879 ti->cl_first += step;
3880 if (ti->cl_first + num_page_entries > num_entries)
3881 ti->cl_first = MAX(0, num_entries - num_page_entries);
3888 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3889 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3890 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3892 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3899 /* handle moving cursor one line */
3900 y = ti->cl_cursor + dy;
3905 TreeInfo *node_first, *node_cursor;
3906 int entry_pos = ti->cl_first + y;
3908 node_first = getTreeInfoFirstGroupEntry(ti);
3909 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3911 if (node_cursor->node_group)
3915 PlaySound(SND_MENU_ITEM_SELECTING);
3917 node_cursor->cl_first = ti->cl_first;
3918 node_cursor->cl_cursor = ti->cl_cursor;
3919 *ti_ptr = node_cursor->node_group;
3920 DrawChooseTree(ti_ptr);
3925 else if (dx == -1 && ti->node_parent)
3929 PlaySound(SND_MENU_ITEM_SELECTING);
3931 *ti_ptr = ti->node_parent;
3932 DrawChooseTree(ti_ptr);
3937 if (!anyScrollbarGadgetActive() &&
3938 IN_VIS_MENU(x, y) &&
3939 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3940 y >= 0 && y < num_page_entries)
3944 if (y != ti->cl_cursor)
3946 PlaySound(SND_MENU_ITEM_ACTIVATING);
3948 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3949 drawChooseTreeCursor(y, TRUE);
3950 drawChooseTreeInfo(ti->cl_first + y, ti);
3957 TreeInfo *node_first, *node_cursor;
3958 int entry_pos = ti->cl_first + y;
3960 PlaySound(SND_MENU_ITEM_SELECTING);
3962 node_first = getTreeInfoFirstGroupEntry(ti);
3963 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3965 if (node_cursor->node_group)
3969 node_cursor->cl_first = ti->cl_first;
3970 node_cursor->cl_cursor = ti->cl_cursor;
3971 *ti_ptr = node_cursor->node_group;
3972 DrawChooseTree(ti_ptr);
3974 else if (node_cursor->parent_link)
3978 *ti_ptr = node_cursor->node_parent;
3979 DrawChooseTree(ti_ptr);
3985 node_cursor->cl_first = ti->cl_first;
3986 node_cursor->cl_cursor = ti->cl_cursor;
3987 *ti_ptr = node_cursor;
3989 if (ti->type == TREE_TYPE_LEVEL_DIR)
3991 LoadLevelSetup_SeriesInfo();
3993 SaveLevelSetup_LastSeries();
3994 SaveLevelSetup_SeriesInfo();
3998 if (game_status == GAME_MODE_SETUP)
4000 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4001 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4002 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4004 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4005 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4006 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4007 execSetupGraphics();
4008 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4009 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4010 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4012 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4013 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4014 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4021 if (game_status == GAME_MODE_LEVELNR)
4023 int new_level_nr = atoi(level_number_current->identifier);
4025 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4028 game_status = GAME_MODE_MAIN;
4037 void DrawChooseLevelSet()
4039 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4041 DrawChooseTree(&leveldir_current);
4047 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4049 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4052 void DrawChooseLevelNr()
4056 if (level_number != NULL)
4058 freeTreeInfo(level_number);
4060 level_number = NULL;
4063 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4065 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4066 char identifier[32], name[32];
4069 /* temporarily load level info to get level name */
4070 LoadLevelInfoOnly(i);
4072 ti->node_top = &level_number;
4073 ti->sort_priority = 10000 + value;
4074 ti->color = (level.no_valid_file ? FC_BLUE :
4075 LevelStats_getSolved(i) ? FC_GREEN :
4076 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4078 sprintf(identifier, "%d", value);
4079 sprintf(name, "%03d: %s", value,
4080 (level.no_valid_file ? "(no file)" : level.name));
4082 setString(&ti->identifier, identifier);
4083 setString(&ti->name, name);
4084 setString(&ti->name_sorting, name);
4086 pushTreeInfo(&level_number, ti);
4089 /* sort level number values to start with lowest level number */
4090 sortTreeInfo(&level_number);
4092 /* set current level number to current level number */
4093 level_number_current =
4094 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4096 /* if that also fails, set current level number to first available level */
4097 if (level_number_current == NULL)
4098 level_number_current = level_number;
4100 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4102 DrawChooseTree(&level_number_current);
4108 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4110 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4113 void DrawHallOfFame(int highlight_position)
4115 int fade_mask = REDRAW_FIELD;
4117 /* required before door position may be changed in next step */
4118 CloseDoor(DOOR_CLOSE_ALL);
4120 /* needed if different viewport properties defined for scores */
4121 ChangeViewportPropertiesIfNeeded();
4123 if (CheckIfGlobalBorderHasChanged())
4124 fade_mask = REDRAW_ALL;
4127 FadeSoundsAndMusic();
4129 /* (this is needed when called from GameEnd() after winning a game) */
4130 KeyboardAutoRepeatOn();
4133 /* (this is needed when called from GameEnd() after winning a game) */
4134 SetDrawDeactivationMask(REDRAW_NONE);
4135 SetDrawBackgroundMask(REDRAW_FIELD);
4137 if (highlight_position < 0)
4138 LoadScore(level_nr);
4140 FadeSetEnterScreen();
4149 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4154 static void drawHallOfFameList(int first_entry, int highlight_position)
4158 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4161 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4162 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4163 "HighScores of Level %d", level_nr);
4165 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4167 int entry = first_entry + i;
4168 boolean active = (entry == highlight_position);
4169 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4170 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4171 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4172 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4173 int dx1 = 3 * getFontWidth(font_nr1);
4174 int dx2 = dx1 + getFontWidth(font_nr1);
4175 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4176 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4177 int sy = mSY + 64 + i * 32;
4179 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4180 DrawText(mSX + dx1, sy, ".", font_nr1);
4182 for (j = 0; j < num_dots; j++)
4183 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4185 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4186 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4188 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4191 redraw_mask |= REDRAW_FIELD;
4194 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4196 static int first_entry = 0;
4197 static int highlight_position = 0;
4198 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4200 if (button == MB_MENU_INITIALIZE)
4203 highlight_position = mx;
4204 drawHallOfFameList(first_entry, highlight_position);
4209 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4210 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4214 if (first_entry > 0)
4216 first_entry -= step;
4217 if (first_entry < 0)
4220 drawHallOfFameList(first_entry, highlight_position);
4225 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4227 first_entry += step;
4228 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4229 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4231 drawHallOfFameList(first_entry, highlight_position);
4234 else if (button == MB_MENU_LEAVE)
4236 PlaySound(SND_MENU_ITEM_SELECTING);
4238 FadeSound(SND_BACKGROUND_SCORES);
4240 game_status = GAME_MODE_MAIN;
4244 else if (button == MB_MENU_CHOICE)
4246 PlaySound(SND_MENU_ITEM_SELECTING);
4248 FadeSound(SND_BACKGROUND_SCORES);
4250 game_status = GAME_MODE_MAIN;
4255 if (game_status == GAME_MODE_SCORES)
4256 PlayMenuSoundIfLoop();
4260 /* ========================================================================= */
4261 /* setup screen functions */
4262 /* ========================================================================= */
4264 static struct TokenInfo *setup_info;
4265 static int num_setup_info; /* number of setup entries shown on screen */
4266 static int max_setup_info; /* total number of setup entries in list */
4268 static char *screen_mode_text;
4269 static char *window_size_text;
4270 static char *scaling_type_text;
4271 static char *scroll_delay_text;
4272 static char *snapshot_mode_text;
4273 static char *game_speed_text;
4274 static char *graphics_set_name;
4275 static char *sounds_set_name;
4276 static char *music_set_name;
4277 static char *volume_simple_text;
4278 static char *volume_loops_text;
4279 static char *volume_music_text;
4280 static char *touch_controls_text;
4281 static char *move_distance_text;
4282 static char *drop_distance_text;
4284 static void execSetupMain()
4286 setup_mode = SETUP_MODE_MAIN;
4291 static void execSetupGame_setGameSpeeds()
4293 if (game_speeds == NULL)
4297 for (i = 0; game_speeds_list[i].value != -1; i++)
4299 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4300 char identifier[32], name[32];
4301 int value = game_speeds_list[i].value;
4302 char *text = game_speeds_list[i].text;
4304 ti->node_top = &game_speeds;
4305 ti->sort_priority = 10000 - value;
4307 sprintf(identifier, "%d", value);
4308 sprintf(name, "%s", text);
4310 setString(&ti->identifier, identifier);
4311 setString(&ti->name, name);
4312 setString(&ti->name_sorting, name);
4313 setString(&ti->infotext, "Game Speed");
4315 pushTreeInfo(&game_speeds, ti);
4318 /* sort game speed values to start with slowest game speed */
4319 sortTreeInfo(&game_speeds);
4321 /* set current game speed to configured game speed value */
4322 game_speed_current =
4323 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4325 /* if that fails, set current game speed to reliable default value */
4326 if (game_speed_current == NULL)
4327 game_speed_current =
4328 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4330 /* if that also fails, set current game speed to first available speed */
4331 if (game_speed_current == NULL)
4332 game_speed_current = game_speeds;
4335 setup.game_frame_delay = atoi(game_speed_current->identifier);
4337 /* needed for displaying game speed text instead of identifier */
4338 game_speed_text = game_speed_current->name;
4341 static void execSetupGame_setScrollDelays()
4343 if (scroll_delays == NULL)
4347 for (i = 0; scroll_delays_list[i].value != -1; i++)
4349 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4350 char identifier[32], name[32];
4351 int value = scroll_delays_list[i].value;
4352 char *text = scroll_delays_list[i].text;
4354 ti->node_top = &scroll_delays;
4355 ti->sort_priority = value;
4357 sprintf(identifier, "%d", value);
4358 sprintf(name, "%s", text);
4360 setString(&ti->identifier, identifier);
4361 setString(&ti->name, name);
4362 setString(&ti->name_sorting, name);
4363 setString(&ti->infotext, "Scaling Type");
4365 pushTreeInfo(&scroll_delays, ti);
4368 /* sort scaling type values to start with lowest scaling type value */
4369 sortTreeInfo(&scroll_delays);
4371 /* set current scaling type value to configured scaling type value */
4372 scroll_delay_current =
4373 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4375 /* if that fails, set current scaling type to reliable default value */
4376 if (scroll_delay_current == NULL)
4377 scroll_delay_current =
4378 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4380 /* if that also fails, set current scaling type to first available value */
4381 if (scroll_delay_current == NULL)
4382 scroll_delay_current = scroll_delays;
4385 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4387 /* needed for displaying scaling type text instead of identifier */
4388 scroll_delay_text = scroll_delay_current->name;
4391 static void execSetupGame_setSnapshotModes()
4393 if (snapshot_modes == NULL)
4397 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4399 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4400 char identifier[32], name[32];
4401 char *value = snapshot_modes_list[i].value;
4402 char *text = snapshot_modes_list[i].text;
4404 ti->node_top = &snapshot_modes;
4405 ti->sort_priority = i;
4407 sprintf(identifier, "%s", value);
4408 sprintf(name, "%s", text);
4410 setString(&ti->identifier, identifier);
4411 setString(&ti->name, name);
4412 setString(&ti->name_sorting, name);
4413 setString(&ti->infotext, "Snapshot Mode");
4415 pushTreeInfo(&snapshot_modes, ti);
4418 /* sort snapshot mode values to start with lowest snapshot mode value */
4419 sortTreeInfo(&snapshot_modes);
4421 /* set current snapshot mode value to configured snapshot mode value */
4422 snapshot_mode_current =
4423 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4425 /* if that fails, set current snapshot mode to reliable default value */
4426 if (snapshot_mode_current == NULL)
4427 snapshot_mode_current =
4428 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4430 /* if that also fails, set current snapshot mode to first available value */
4431 if (snapshot_mode_current == NULL)
4432 snapshot_mode_current = snapshot_modes;
4435 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4437 /* needed for displaying snapshot mode text instead of identifier */
4438 snapshot_mode_text = snapshot_mode_current->name;
4441 static void execSetupGame()
4443 execSetupGame_setGameSpeeds();
4444 execSetupGame_setScrollDelays();
4445 execSetupGame_setSnapshotModes();
4447 setup_mode = SETUP_MODE_GAME;
4452 static void execSetupChooseGameSpeed()
4454 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4459 static void execSetupChooseScrollDelay()
4461 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4466 static void execSetupChooseSnapshotMode()
4468 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4473 static void execSetupEditor()
4475 setup_mode = SETUP_MODE_EDITOR;
4480 static void execSetupGraphics_setWindowSizes(boolean update_list)
4482 if (window_sizes != NULL && update_list)
4484 freeTreeInfo(window_sizes);
4486 window_sizes = NULL;
4489 if (window_sizes == NULL)
4491 boolean current_window_size_found = FALSE;
4494 for (i = 0; window_sizes_list[i].value != -1; i++)
4496 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4497 char identifier[32], name[32];
4498 int value = window_sizes_list[i].value;
4499 char *text = window_sizes_list[i].text;
4501 ti->node_top = &window_sizes;
4502 ti->sort_priority = value;
4504 sprintf(identifier, "%d", value);
4505 sprintf(name, "%s", text);
4507 setString(&ti->identifier, identifier);
4508 setString(&ti->name, name);
4509 setString(&ti->name_sorting, name);
4510 setString(&ti->infotext, "Window Scaling");
4512 pushTreeInfo(&window_sizes, ti);
4514 if (value == setup.window_scaling_percent)
4515 current_window_size_found = TRUE;
4518 if (!current_window_size_found)
4520 // add entry for non-preset window scaling value
4522 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4523 char identifier[32], name[32];
4524 int value = setup.window_scaling_percent;
4526 ti->node_top = &window_sizes;
4527 ti->sort_priority = value;
4529 sprintf(identifier, "%d", value);
4530 sprintf(name, "%d %% (Current)", value);
4532 setString(&ti->identifier, identifier);
4533 setString(&ti->name, name);
4534 setString(&ti->name_sorting, name);
4535 setString(&ti->infotext, "Window Scaling");
4537 pushTreeInfo(&window_sizes, ti);
4540 /* sort window size values to start with lowest window size value */
4541 sortTreeInfo(&window_sizes);
4543 /* set current window size value to configured window size value */
4544 window_size_current =
4545 getTreeInfoFromIdentifier(window_sizes,
4546 i_to_a(setup.window_scaling_percent));
4548 /* if that fails, set current window size to reliable default value */
4549 if (window_size_current == NULL)
4550 window_size_current =
4551 getTreeInfoFromIdentifier(window_sizes,
4552 i_to_a(STD_WINDOW_SCALING_PERCENT));
4554 /* if that also fails, set current window size to first available value */
4555 if (window_size_current == NULL)
4556 window_size_current = window_sizes;
4559 setup.window_scaling_percent = atoi(window_size_current->identifier);
4561 /* needed for displaying window size text instead of identifier */
4562 window_size_text = window_size_current->name;
4565 static void execSetupGraphics_setScalingTypes()
4567 if (scaling_types == NULL)
4571 for (i = 0; scaling_types_list[i].value != NULL; i++)
4573 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4574 char identifier[32], name[32];
4575 char *value = scaling_types_list[i].value;
4576 char *text = scaling_types_list[i].text;
4578 ti->node_top = &scaling_types;
4579 ti->sort_priority = i;
4581 sprintf(identifier, "%s", value);
4582 sprintf(name, "%s", text);
4584 setString(&ti->identifier, identifier);
4585 setString(&ti->name, name);
4586 setString(&ti->name_sorting, name);
4587 setString(&ti->infotext, "Anti-Aliasing");
4589 pushTreeInfo(&scaling_types, ti);
4592 /* sort scaling type values to start with lowest scaling type value */
4593 sortTreeInfo(&scaling_types);
4595 /* set current scaling type value to configured scaling type value */
4596 scaling_type_current =
4597 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4599 /* if that fails, set current scaling type to reliable default value */
4600 if (scaling_type_current == NULL)
4601 scaling_type_current =
4602 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4604 /* if that also fails, set current scaling type to first available value */
4605 if (scaling_type_current == NULL)
4606 scaling_type_current = scaling_types;
4609 setup.window_scaling_quality = scaling_type_current->identifier;
4611 /* needed for displaying scaling type text instead of identifier */
4612 scaling_type_text = scaling_type_current->name;
4615 static void execSetupGraphics_setScreenModes()
4617 // if (screen_modes == NULL && video.fullscreen_available)
4618 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4622 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4624 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4625 char identifier[32], name[32];
4626 int x = video.fullscreen_modes[i].width;
4627 int y = video.fullscreen_modes[i].height;
4630 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4632 ti->node_top = &screen_modes;
4633 ti->sort_priority = x * 10000 + y;
4635 sprintf(identifier, "%dx%d", x, y);
4636 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4638 setString(&ti->identifier, identifier);
4639 setString(&ti->name, name);
4640 setString(&ti->name_sorting, name);
4641 setString(&ti->infotext, "Fullscreen Mode");
4643 pushTreeInfo(&screen_modes, ti);
4646 /* sort fullscreen modes to start with lowest available screen resolution */
4647 sortTreeInfo(&screen_modes);
4649 /* set current screen mode for fullscreen mode to configured setup value */
4650 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4651 setup.fullscreen_mode);
4653 /* if that fails, set current screen mode to reliable default value */
4654 if (screen_mode_current == NULL)
4655 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4656 DEFAULT_FULLSCREEN_MODE);
4658 /* if that also fails, set current screen mode to first available mode */
4659 if (screen_mode_current == NULL)
4660 screen_mode_current = screen_modes;
4662 if (screen_mode_current == NULL)
4663 video.fullscreen_available = FALSE;
4666 // if (video.fullscreen_available)
4667 if (screen_mode_current != NULL)
4669 setup.fullscreen_mode = screen_mode_current->identifier;
4671 /* needed for displaying screen mode name instead of identifier */
4672 screen_mode_text = screen_mode_current->name;
4676 static void execSetupGraphics()
4678 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4680 // update "setup.window_scaling_percent" from list selection
4681 execSetupGraphics_setWindowSizes(FALSE);
4685 // update list selection from "setup.window_scaling_percent"
4686 execSetupGraphics_setWindowSizes(TRUE);
4689 execSetupGraphics_setScalingTypes();
4690 execSetupGraphics_setScreenModes();
4692 setup_mode = SETUP_MODE_GRAPHICS;
4696 #if defined(TARGET_SDL2)
4697 // window scaling may have changed at this point
4698 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4700 // window scaling quality may have changed at this point
4701 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4702 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4706 #if !defined(PLATFORM_ANDROID)
4707 #if defined(TARGET_SDL2)
4708 static void execSetupChooseWindowSize()
4710 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4715 static void execSetupChooseScalingType()
4717 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4722 static void execSetupChooseScreenMode()
4724 if (!video.fullscreen_available)
4727 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4734 static void execSetupChooseVolumeSimple()
4736 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4741 static void execSetupChooseVolumeLoops()
4743 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4748 static void execSetupChooseVolumeMusic()
4750 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4755 static void execSetupSound()
4757 if (volumes_simple == NULL)
4759 boolean current_volume_simple_found = FALSE;
4762 for (i = 0; volumes_list[i].value != -1; i++)
4764 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4765 char identifier[32], name[32];
4766 int value = volumes_list[i].value;
4767 char *text = volumes_list[i].text;
4769 ti->node_top = &volumes_simple;
4770 ti->sort_priority = value;
4772 sprintf(identifier, "%d", value);
4773 sprintf(name, "%s", text);
4775 setString(&ti->identifier, identifier);
4776 setString(&ti->name, name);
4777 setString(&ti->name_sorting, name);
4778 setString(&ti->infotext, "Sound Volume");
4780 pushTreeInfo(&volumes_simple, ti);
4782 if (value == setup.volume_simple)
4783 current_volume_simple_found = TRUE;
4786 if (!current_volume_simple_found)
4788 // add entry for non-preset volume value
4790 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4791 char identifier[32], name[32];
4792 int value = setup.volume_simple;
4794 ti->node_top = &volumes_simple;
4795 ti->sort_priority = value;
4797 sprintf(identifier, "%d", value);
4798 sprintf(name, "%d %% (Current)", value);
4800 setString(&ti->identifier, identifier);
4801 setString(&ti->name, name);
4802 setString(&ti->name_sorting, name);
4803 setString(&ti->infotext, "Sound Volume");
4805 pushTreeInfo(&volumes_simple, ti);
4808 /* sort volume values to start with lowest volume value */
4809 sortTreeInfo(&volumes_simple);
4811 /* set current volume value to configured volume value */
4812 volume_simple_current =
4813 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4815 /* if that fails, set current volume to reliable default value */
4816 if (volume_simple_current == NULL)
4817 volume_simple_current =
4818 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4820 /* if that also fails, set current volume to first available value */
4821 if (volume_simple_current == NULL)
4822 volume_simple_current = volumes_simple;
4825 if (volumes_loops == NULL)
4827 boolean current_volume_loops_found = FALSE;
4830 for (i = 0; volumes_list[i].value != -1; i++)
4832 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4833 char identifier[32], name[32];
4834 int value = volumes_list[i].value;
4835 char *text = volumes_list[i].text;
4837 ti->node_top = &volumes_loops;
4838 ti->sort_priority = value;
4840 sprintf(identifier, "%d", value);
4841 sprintf(name, "%s", text);
4843 setString(&ti->identifier, identifier);
4844 setString(&ti->name, name);
4845 setString(&ti->name_sorting, name);
4846 setString(&ti->infotext, "Loops Volume");
4848 pushTreeInfo(&volumes_loops, ti);
4850 if (value == setup.volume_loops)
4851 current_volume_loops_found = TRUE;
4854 if (!current_volume_loops_found)
4856 // add entry for non-preset volume value
4858 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4859 char identifier[32], name[32];
4860 int value = setup.volume_loops;
4862 ti->node_top = &volumes_loops;
4863 ti->sort_priority = value;
4865 sprintf(identifier, "%d", value);
4866 sprintf(name, "%d %% (Current)", value);
4868 setString(&ti->identifier, identifier);
4869 setString(&ti->name, name);
4870 setString(&ti->name_sorting, name);
4871 setString(&ti->infotext, "Loops Volume");
4873 pushTreeInfo(&volumes_loops, ti);
4876 /* sort volume values to start with lowest volume value */
4877 sortTreeInfo(&volumes_loops);
4879 /* set current volume value to configured volume value */
4880 volume_loops_current =
4881 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4883 /* if that fails, set current volume to reliable default value */
4884 if (volume_loops_current == NULL)
4885 volume_loops_current =
4886 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4888 /* if that also fails, set current volume to first available value */
4889 if (volume_loops_current == NULL)
4890 volume_loops_current = volumes_loops;
4893 if (volumes_music == NULL)
4895 boolean current_volume_music_found = FALSE;
4898 for (i = 0; volumes_list[i].value != -1; i++)
4900 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4901 char identifier[32], name[32];
4902 int value = volumes_list[i].value;
4903 char *text = volumes_list[i].text;
4905 ti->node_top = &volumes_music;
4906 ti->sort_priority = value;
4908 sprintf(identifier, "%d", value);
4909 sprintf(name, "%s", text);
4911 setString(&ti->identifier, identifier);
4912 setString(&ti->name, name);
4913 setString(&ti->name_sorting, name);
4914 setString(&ti->infotext, "Music Volume");
4916 pushTreeInfo(&volumes_music, ti);
4918 if (value == setup.volume_music)
4919 current_volume_music_found = TRUE;
4922 if (!current_volume_music_found)
4924 // add entry for non-preset volume value
4926 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4927 char identifier[32], name[32];
4928 int value = setup.volume_music;
4930 ti->node_top = &volumes_music;
4931 ti->sort_priority = value;
4933 sprintf(identifier, "%d", value);
4934 sprintf(name, "%d %% (Current)", value);
4936 setString(&ti->identifier, identifier);
4937 setString(&ti->name, name);
4938 setString(&ti->name_sorting, name);
4939 setString(&ti->infotext, "Music Volume");
4941 pushTreeInfo(&volumes_music, ti);
4944 /* sort volume values to start with lowest volume value */
4945 sortTreeInfo(&volumes_music);
4947 /* set current volume value to configured volume value */
4948 volume_music_current =
4949 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4951 /* if that fails, set current volume to reliable default value */
4952 if (volume_music_current == NULL)
4953 volume_music_current =
4954 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4956 /* if that also fails, set current volume to first available value */
4957 if (volume_music_current == NULL)
4958 volume_music_current = volumes_music;
4961 setup.volume_simple = atoi(volume_simple_current->identifier);
4962 setup.volume_loops = atoi(volume_loops_current->identifier);
4963 setup.volume_music = atoi(volume_music_current->identifier);
4965 /* needed for displaying volume text instead of identifier */
4966 volume_simple_text = volume_simple_current->name;
4967 volume_loops_text = volume_loops_current->name;
4968 volume_music_text = volume_music_current->name;
4970 setup_mode = SETUP_MODE_SOUND;
4975 static void execSetupChooseTouchControls()
4977 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4982 static void execSetupChooseMoveDistance()
4984 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4989 static void execSetupChooseDropDistance()
4991 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4996 static void execSetupTouch()
4998 if (touch_controls == NULL)
5002 for (i = 0; touch_controls_list[i].value != NULL; i++)
5004 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5005 char identifier[32], name[32];
5006 char *value = touch_controls_list[i].value;
5007 char *text = touch_controls_list[i].text;
5009 ti->node_top = &touch_controls;
5010 ti->sort_priority = i;
5012 sprintf(identifier, "%s", value);
5013 sprintf(name, "%s", text);
5015 setString(&ti->identifier, identifier);
5016 setString(&ti->name, name);
5017 setString(&ti->name_sorting, name);
5018 setString(&ti->infotext, "Control Type");
5020 pushTreeInfo(&touch_controls, ti);
5023 /* sort touch control values to start with lowest touch control value */
5024 sortTreeInfo(&touch_controls);
5026 /* set current touch control value to configured touch control value */
5027 touch_control_current =
5028 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5030 /* if that fails, set current touch control to reliable default value */
5031 if (touch_control_current == NULL)
5032 touch_control_current =
5033 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5035 /* if that also fails, set current touch control to first available value */
5036 if (touch_control_current == NULL)
5037 touch_control_current = touch_controls;
5040 if (move_distances == NULL)
5044 for (i = 0; distances_list[i].value != -1; i++)
5046 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5047 char identifier[32], name[32];
5048 int value = distances_list[i].value;
5049 char *text = distances_list[i].text;
5051 ti->node_top = &move_distances;
5052 ti->sort_priority = value;
5054 sprintf(identifier, "%d", value);
5055 sprintf(name, "%s", text);
5057 setString(&ti->identifier, identifier);
5058 setString(&ti->name, name);
5059 setString(&ti->name_sorting, name);
5060 setString(&ti->infotext, "Move Distance");
5062 pushTreeInfo(&move_distances, ti);
5065 /* sort distance values to start with lowest distance value */
5066 sortTreeInfo(&move_distances);
5068 /* set current distance value to configured distance value */
5069 move_distance_current =
5070 getTreeInfoFromIdentifier(move_distances,
5071 i_to_a(setup.touch.move_distance));
5073 /* if that fails, set current distance to reliable default value */
5074 if (move_distance_current == NULL)
5075 move_distance_current =
5076 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5078 /* if that also fails, set current distance to first available value */
5079 if (move_distance_current == NULL)
5080 move_distance_current = move_distances;
5083 if (drop_distances == NULL)
5087 for (i = 0; distances_list[i].value != -1; i++)
5089 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5090 char identifier[32], name[32];
5091 int value = distances_list[i].value;
5092 char *text = distances_list[i].text;
5094 ti->node_top = &drop_distances;
5095 ti->sort_priority = value;
5097 sprintf(identifier, "%d", value);
5098 sprintf(name, "%s", text);
5100 setString(&ti->identifier, identifier);
5101 setString(&ti->name, name);
5102 setString(&ti->name_sorting, name);
5103 setString(&ti->infotext, "Drop Distance");
5105 pushTreeInfo(&drop_distances, ti);
5108 /* sort distance values to start with lowest distance value */
5109 sortTreeInfo(&drop_distances);
5111 /* set current distance value to configured distance value */
5112 drop_distance_current =
5113 getTreeInfoFromIdentifier(drop_distances,
5114 i_to_a(setup.touch.drop_distance));
5116 /* if that fails, set current distance to reliable default value */
5117 if (drop_distance_current == NULL)
5118 drop_distance_current =
5119 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5121 /* if that also fails, set current distance to first available value */
5122 if (drop_distance_current == NULL)
5123 drop_distance_current = drop_distances;
5126 setup.touch.control_type = touch_control_current->identifier;
5127 setup.touch.move_distance = atoi(move_distance_current->identifier);
5128 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5130 /* needed for displaying volume text instead of identifier */
5131 touch_controls_text = touch_control_current->name;
5132 move_distance_text = move_distance_current->name;
5133 drop_distance_text = drop_distance_current->name;
5135 setup_mode = SETUP_MODE_TOUCH;
5140 static void execSetupArtwork()
5143 printf("::: '%s', '%s', '%s'\n",
5144 artwork.gfx_current->subdir,
5145 artwork.gfx_current->fullpath,
5146 artwork.gfx_current->basepath);
5149 setup.graphics_set = artwork.gfx_current->identifier;
5150 setup.sounds_set = artwork.snd_current->identifier;
5151 setup.music_set = artwork.mus_current->identifier;
5153 /* needed if last screen (setup choice) changed graphics, sounds or music */
5154 ReloadCustomArtwork(0);
5156 /* needed for displaying artwork name instead of artwork identifier */
5157 graphics_set_name = artwork.gfx_current->name;
5158 sounds_set_name = artwork.snd_current->name;
5159 music_set_name = artwork.mus_current->name;
5161 setup_mode = SETUP_MODE_ARTWORK;
5166 static void execSetupChooseGraphics()
5168 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5173 static void execSetupChooseSounds()
5175 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5180 static void execSetupChooseMusic()
5182 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5187 #if !defined(PLATFORM_ANDROID)
5188 static void execSetupInput()
5190 setup_mode = SETUP_MODE_INPUT;
5196 static void execSetupShortcuts()
5198 setup_mode = SETUP_MODE_SHORTCUTS;
5203 static void execSetupShortcuts1()
5205 setup_mode = SETUP_MODE_SHORTCUTS_1;
5210 static void execSetupShortcuts2()
5212 setup_mode = SETUP_MODE_SHORTCUTS_2;
5217 static void execSetupShortcuts3()
5219 setup_mode = SETUP_MODE_SHORTCUTS_3;
5224 static void execSetupShortcuts4()
5226 setup_mode = SETUP_MODE_SHORTCUTS_4;
5231 static void execSetupShortcuts5()
5233 setup_mode = SETUP_MODE_SHORTCUTS_5;
5238 static void execExitSetup()
5240 game_status = GAME_MODE_MAIN;
5245 static void execSaveAndExitSetup()
5251 static struct TokenInfo setup_info_main[] =
5253 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5254 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5255 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5256 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5257 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5258 #if !defined(PLATFORM_ANDROID)
5259 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5260 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5262 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5264 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5265 { TYPE_EMPTY, NULL, "" },
5266 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5267 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5272 static struct TokenInfo setup_info_game[] =
5274 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5275 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5276 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5277 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5278 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5279 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5280 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5281 { TYPE_STRING, &game_speed_text, "" },
5283 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5284 { TYPE_STRING, &scroll_delay_text, "" },
5286 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5287 { TYPE_STRING, &snapshot_mode_text, "" },
5288 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5289 { TYPE_EMPTY, NULL, "" },
5290 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5295 static struct TokenInfo setup_info_editor[] =
5298 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5299 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5300 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5301 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5302 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5303 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5304 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5305 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5307 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5308 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5309 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5311 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5313 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5314 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5315 { TYPE_EMPTY, NULL, "" },
5317 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5318 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5319 { TYPE_EMPTY, NULL, "" },
5321 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5322 { TYPE_EMPTY, NULL, "" },
5323 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5328 static struct TokenInfo setup_info_graphics[] =
5330 #if !defined(PLATFORM_ANDROID)
5331 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5332 #if defined(TARGET_SDL2)
5333 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5334 { TYPE_STRING, &window_size_text, "" },
5335 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5336 { TYPE_STRING, &scaling_type_text, "" },
5338 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5339 { TYPE_STRING, &screen_mode_text, "" },
5343 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5344 { TYPE_STRING, &scroll_delay_text, "" },
5346 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5347 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5348 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5349 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5350 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5351 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5352 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5353 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5354 { TYPE_EMPTY, NULL, "" },
5355 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5360 static struct TokenInfo setup_info_sound[] =
5362 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5363 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5364 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5365 { TYPE_EMPTY, NULL, "" },
5366 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5367 { TYPE_STRING, &volume_simple_text, "" },
5368 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5369 { TYPE_STRING, &volume_loops_text, "" },
5370 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5371 { TYPE_STRING, &volume_music_text, "" },
5372 { TYPE_EMPTY, NULL, "" },
5373 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5378 static struct TokenInfo setup_info_artwork[] =
5380 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5381 { TYPE_STRING, &graphics_set_name, "" },
5382 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5383 { TYPE_STRING, &sounds_set_name, "" },
5384 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5385 { TYPE_STRING, &music_set_name, "" },
5386 { TYPE_EMPTY, NULL, "" },
5387 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5388 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5389 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5390 { TYPE_EMPTY, NULL, "" },
5391 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5396 static struct TokenInfo setup_info_input[] =
5398 { TYPE_SWITCH, NULL, "Player:" },
5399 { TYPE_SWITCH, NULL, "Device:" },
5400 { TYPE_ENTER_MENU, NULL, "" },
5401 { TYPE_EMPTY, NULL, "" },
5402 { TYPE_EMPTY, NULL, "" },
5403 { TYPE_EMPTY, NULL, "" },
5404 { TYPE_EMPTY, NULL, "" },
5405 { TYPE_EMPTY, NULL, "" },
5406 { TYPE_EMPTY, NULL, "" },
5407 { TYPE_EMPTY, NULL, "" },
5408 { TYPE_EMPTY, NULL, "" },
5409 { TYPE_EMPTY, NULL, "" },
5410 { TYPE_EMPTY, NULL, "" },
5411 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5416 static struct TokenInfo setup_info_touch[] =
5418 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5419 { TYPE_STRING, &touch_controls_text, "" },
5420 { TYPE_EMPTY, NULL, "" },
5421 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5422 { TYPE_STRING, &move_distance_text, "" },
5423 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5424 { TYPE_STRING, &drop_distance_text, "" },
5425 { TYPE_EMPTY, NULL, "" },
5426 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5431 static struct TokenInfo setup_info_shortcuts[] =
5433 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5434 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5435 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5436 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5437 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5438 { TYPE_EMPTY, NULL, "" },
5439 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5444 static struct TokenInfo setup_info_shortcuts_1[] =
5446 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5447 { TYPE_KEY, &setup.shortcut.save_game, "" },
5448 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5449 { TYPE_KEY, &setup.shortcut.load_game, "" },
5450 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5451 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5452 { TYPE_EMPTY, NULL, "" },
5453 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5454 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5455 { TYPE_EMPTY, NULL, "" },
5456 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5461 static struct TokenInfo setup_info_shortcuts_2[] =
5463 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5464 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5465 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5466 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5467 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5468 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5469 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5470 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5471 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5472 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5473 { TYPE_EMPTY, NULL, "" },
5474 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5479 static struct TokenInfo setup_info_shortcuts_3[] =
5481 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5482 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5483 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5484 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5485 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5486 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5487 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5488 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5489 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5490 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5491 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5492 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5493 { TYPE_EMPTY, NULL, "" },
5494 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5499 static struct TokenInfo setup_info_shortcuts_4[] =
5501 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5502 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5503 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5504 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5505 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5506 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5507 { TYPE_EMPTY, NULL, "" },
5508 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5513 static struct TokenInfo setup_info_shortcuts_5[] =
5515 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5516 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5517 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5518 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5519 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5520 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5521 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5522 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5523 { TYPE_EMPTY, NULL, "" },
5524 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5529 static Key getSetupKey()
5531 Key key = KSYM_UNDEFINED;
5532 boolean got_key_event = FALSE;
5534 while (!got_key_event)
5536 if (PendingEvent()) /* got event */
5544 case EVENT_KEYPRESS:
5546 key = GetEventKey((KeyEvent *)&event, TRUE);
5548 /* press 'Escape' or 'Enter' to keep the existing key binding */
5549 if (key == KSYM_Escape || key == KSYM_Return)
5550 key = KSYM_UNDEFINED; /* keep old value */
5552 got_key_event = TRUE;
5556 case EVENT_KEYRELEASE:
5557 key_joystick_mapping = 0;
5561 HandleOtherEvents(&event);
5569 /* don't eat all CPU time */
5576 static int getSetupValueFont(int type, void *value)
5578 if (type & TYPE_KEY)
5579 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5580 else if (type & TYPE_STRING)
5581 return FONT_VALUE_2;
5582 else if (type & TYPE_ECS_AGA)
5583 return FONT_VALUE_1;
5584 else if (type & TYPE_BOOLEAN_STYLE)
5585 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5586 else if (type & TYPE_YES_NO_AUTO)
5587 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5588 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5590 return FONT_VALUE_1;
5593 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5595 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5596 struct TokenInfo *si = &setup_info[si_pos];
5597 boolean font_draw_xoffset_modified = FALSE;
5598 int font_draw_xoffset_old = -1;
5599 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5600 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5601 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5602 int xpos = menu_screen_value_xpos;
5603 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5604 int startx = mSX + xpos * 32;
5605 int starty = mSY + ypos * 32;
5606 int font_nr, font_width;
5607 int type = si->type;
5608 void *value = si->value;
5609 char *value_string = getSetupValue(type, value);
5612 if (value_string == NULL)
5615 if (type & TYPE_KEY)
5617 xpos = MENU_SCREEN_START_XPOS;
5619 if (type & TYPE_QUERY)
5620 value_string = "<press key>";
5622 else if (type & TYPE_STRING)
5624 int max_value_len = (SCR_FIELDX - 2) * 2;
5626 xpos = MENU_SCREEN_START_XPOS;
5628 if (strlen(value_string) > max_value_len)
5629 value_string[max_value_len] = '\0';
5631 else if (type & TYPE_YES_NO_AUTO)
5633 xpos = menu_screen_value_xpos - 1;
5636 startx = mSX + xpos * 32;
5637 starty = mSY + ypos * 32;
5638 font_nr = getSetupValueFont(type, value);
5639 font_width = getFontWidth(font_nr);
5641 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5642 if (setup_mode != SETUP_MODE_INPUT)
5644 int max_menu_text_length_big = (menu_screen_value_xpos -
5645 MENU_SCREEN_START_XPOS);
5646 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5647 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5648 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5649 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5650 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5651 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5652 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5653 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5654 boolean correct_font_draw_xoffset = FALSE;
5656 if (xpos == MENU_SCREEN_START_XPOS &&
5657 startx + font1_xoffset < text_startx + text_font_xoffset)
5658 correct_font_draw_xoffset = TRUE;
5660 if (xpos == menu_screen_value_xpos &&
5661 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5662 correct_font_draw_xoffset = TRUE;
5664 /* check if setup value would overlap with setup text when printed */
5665 /* (this can happen for extreme/wrong values for font draw offset) */
5666 if (correct_font_draw_xoffset)
5668 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5669 font_draw_xoffset_modified = TRUE;
5671 if (type & TYPE_KEY)
5672 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5673 else if (!(type & TYPE_STRING))
5674 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5675 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5679 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5680 DrawText(startx + i * font_width, starty, " ", font_nr);
5682 DrawText(startx, starty, value_string, font_nr);
5684 if (font_draw_xoffset_modified)
5685 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5688 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5690 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5691 struct TokenInfo *si = &setup_info[si_pos];
5693 if (si->type & TYPE_BOOLEAN_STYLE)
5695 *(boolean *)si->value ^= TRUE;
5697 else if (si->type & TYPE_YES_NO_AUTO)
5701 (*(int *)si->value == AUTO ? TRUE :
5702 *(int *)si->value == TRUE ? FALSE : AUTO) :
5703 (*(int *)si->value == TRUE ? AUTO :
5704 *(int *)si->value == AUTO ? FALSE : TRUE));
5706 else if (si->type & TYPE_KEY)
5710 si->type |= TYPE_QUERY;
5711 drawSetupValue(screen_pos, setup_info_pos_raw);
5712 si->type &= ~TYPE_QUERY;
5714 key = getSetupKey();
5715 if (key != KSYM_UNDEFINED)
5716 *(Key *)si->value = key;
5719 drawSetupValue(screen_pos, setup_info_pos_raw);
5721 // fullscreen state may have changed at this point
5722 if (si->value == &setup.fullscreen)
5723 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5726 static void DrawSetupScreen_Generic()
5728 int fade_mask = REDRAW_FIELD;
5729 boolean redraw_all = FALSE;
5730 char *title_string = NULL;
5733 if (CheckIfGlobalBorderHasChanged())
5734 fade_mask = REDRAW_ALL;
5738 FreeScreenGadgets();
5739 CreateScreenGadgets();
5741 CloseDoor(DOOR_CLOSE_2);
5743 if (redraw_mask & REDRAW_ALL)
5750 if (setup_mode == SETUP_MODE_MAIN)
5752 setup_info = setup_info_main;
5753 title_string = "Setup";
5755 else if (setup_mode == SETUP_MODE_GAME)
5757 setup_info = setup_info_game;
5758 title_string = "Setup Game";
5760 else if (setup_mode == SETUP_MODE_EDITOR)
5762 setup_info = setup_info_editor;
5763 title_string = "Setup Editor";
5765 else if (setup_mode == SETUP_MODE_GRAPHICS)
5767 setup_info = setup_info_graphics;
5768 title_string = "Setup Graphics";
5770 else if (setup_mode == SETUP_MODE_SOUND)
5772 setup_info = setup_info_sound;
5773 title_string = "Setup Sound";
5775 else if (setup_mode == SETUP_MODE_ARTWORK)
5777 setup_info = setup_info_artwork;
5778 title_string = "Custom Artwork";
5780 else if (setup_mode == SETUP_MODE_TOUCH)
5782 setup_info = setup_info_touch;
5783 title_string = "Setup Touch Ctrls";
5785 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5787 setup_info = setup_info_shortcuts;
5788 title_string = "Setup Shortcuts";
5790 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5792 setup_info = setup_info_shortcuts_1;
5793 title_string = "Setup Shortcuts";
5795 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5797 setup_info = setup_info_shortcuts_2;
5798 title_string = "Setup Shortcuts";
5800 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5802 setup_info = setup_info_shortcuts_3;
5803 title_string = "Setup Shortcuts";
5805 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5807 setup_info = setup_info_shortcuts_4;
5808 title_string = "Setup Shortcuts";
5810 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5812 setup_info = setup_info_shortcuts_5;
5813 title_string = "Setup Shortcuts";
5816 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5818 // determine maximal number of setup entries that can be displayed on screen
5820 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5823 // determine maximal number of setup entries available for this setup screen
5825 for (i = 0; setup_info[i].type != 0; i++)
5828 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5830 MapScreenGadgets(max_setup_info);
5833 redraw_mask = fade_mask = REDRAW_ALL;
5840 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5842 menu_info = setup_info;
5844 HandleMenuScreen(mx, my, dx, dy, button,
5845 setup_mode, num_setup_info, max_setup_info);
5848 void DrawSetupScreen_Input()
5852 FadeOut(REDRAW_FIELD);
5856 setup_info = setup_info_input;
5858 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5860 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5861 "Joysticks deactivated on this screen");
5863 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5865 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5866 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5867 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5868 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5869 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5870 initCursor(i, IMG_MENU_BUTTON);
5872 DrawCursorAndText_Setup(i, -1, FALSE);
5875 /* create gadgets for setup input menu screen */
5876 FreeScreenGadgets();
5877 CreateScreenGadgets();
5879 /* map gadgets for setup input menu screen */
5880 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5882 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5884 FadeIn(REDRAW_FIELD);
5889 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5891 if (device_name == NULL)
5894 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5897 if (strlen(device_name) > 1)
5899 char c1 = device_name[strlen(device_name) - 1];
5900 char c2 = device_name[strlen(device_name) - 2];
5902 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5903 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5906 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5907 strlen(device_name));
5910 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5913 static struct SetupKeyboardInfo custom_key;
5920 { &custom_key.left, "Joystick Left" },
5921 { &custom_key.right, "Joystick Right" },
5922 { &custom_key.up, "Joystick Up" },
5923 { &custom_key.down, "Joystick Down" },
5924 { &custom_key.snap, "Button 1" },
5925 { &custom_key.drop, "Button 2" }
5927 static char *joystick_name[MAX_PLAYERS] =
5934 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5938 custom_key = setup.input[player_nr].key;
5940 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5941 FONT_INPUT_1_ACTIVE);
5943 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5945 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5946 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5948 if (setup.input[player_nr].use_joystick)
5950 char *device_name = setup.input[player_nr].joy.device_name;
5951 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5952 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5954 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5955 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5959 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5960 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5963 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5965 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5966 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5967 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5968 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5970 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5971 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5972 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5973 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5974 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5975 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5977 for (i = 0; i < 6; i++)
5979 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5981 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5983 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5984 (setup.input[player_nr].use_joystick ?
5986 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5990 static int input_player_nr = 0;
5992 void HandleSetupScreen_Input_Player(int step, int direction)
5994 int old_player_nr = input_player_nr;
5997 new_player_nr = old_player_nr + step * direction;
5998 if (new_player_nr < 0)
6000 if (new_player_nr > MAX_PLAYERS - 1)
6001 new_player_nr = MAX_PLAYERS - 1;
6003 if (new_player_nr != old_player_nr)
6005 input_player_nr = new_player_nr;
6007 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6011 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6013 static int choice = 0;
6016 int pos_start = SETUPINPUT_SCREEN_POS_START;
6017 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6018 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6019 int pos_end = SETUPINPUT_SCREEN_POS_END;
6021 if (button == MB_MENU_INITIALIZE)
6023 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6025 DrawCursorAndText_Setup(choice, -1, TRUE);
6029 else if (button == MB_MENU_LEAVE)
6031 setup_mode = SETUP_MODE_MAIN;
6038 if (mx || my) /* mouse input */
6040 x = (mx - mSX) / 32;
6041 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6043 else if (dx || dy) /* keyboard input */
6045 if (dx && choice == 0)
6046 x = (dx < 0 ? 10 : 12);
6047 else if ((dx && choice == 1) ||
6048 (dx == +1 && choice == 2) ||
6049 (dx == -1 && choice == pos_end))
6050 button = MB_MENU_CHOICE;
6054 if (y >= pos_empty1 && y <= pos_empty2)
6055 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6058 if (y == 0 && dx != 0 && button)
6060 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6062 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6063 y >= pos_start && y <= pos_end &&
6064 !(y >= pos_empty1 && y <= pos_empty2))
6070 DrawCursorAndText_Setup(choice, -1, FALSE);
6071 DrawCursorAndText_Setup(y, -1, TRUE);
6073 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6082 char *device_name = setup.input[input_player_nr].joy.device_name;
6084 if (!setup.input[input_player_nr].use_joystick)
6086 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6088 setJoystickDeviceToNr(device_name, new_device_nr);
6089 setup.input[input_player_nr].use_joystick = TRUE;
6093 int device_nr = getJoystickNrFromDeviceName(device_name);
6094 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6096 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6097 setup.input[input_player_nr].use_joystick = FALSE;
6099 setJoystickDeviceToNr(device_name, new_device_nr);
6102 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6106 if (setup.input[input_player_nr].use_joystick)
6109 CalibrateJoystick(input_player_nr);
6112 CustomizeKeyboard(input_player_nr);
6114 else if (y == pos_end)
6120 setup_mode = SETUP_MODE_MAIN;
6127 void CustomizeKeyboard(int player_nr)
6131 boolean finished = FALSE;
6132 static struct SetupKeyboardInfo custom_key;
6137 } customize_step[] =
6139 { &custom_key.left, "Move Left" },
6140 { &custom_key.right, "Move Right" },
6141 { &custom_key.up, "Move Up" },
6142 { &custom_key.down, "Move Down" },
6143 { &custom_key.snap, "Snap Field" },
6144 { &custom_key.drop, "Drop Element" }
6147 /* read existing key bindings from player setup */
6148 custom_key = setup.input[player_nr].key;
6151 FadeOut(REDRAW_FIELD);
6155 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6158 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6159 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6160 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6161 "Key:", FONT_INPUT_1_ACTIVE);
6162 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6163 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6165 FadeIn(REDRAW_FIELD);
6171 if (PendingEvent()) /* got event */
6179 case EVENT_KEYPRESS:
6181 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6183 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6185 if (key == KSYM_Escape)
6186 FadeSkipNextFadeIn();
6192 /* all keys configured -- wait for "Escape" or "Return" key */
6196 /* press 'Enter' to keep the existing key binding */
6197 if (key == KSYM_Return)
6198 key = *customize_step[step_nr].key;
6200 /* check if key already used */
6201 for (i = 0; i < step_nr; i++)
6202 if (*customize_step[i].key == key)
6207 /* got new key binding */
6208 *customize_step[step_nr].key = key;
6209 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6211 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6212 getKeyNameFromKey(key), FONT_VALUE_1);
6215 /* un-highlight last query */
6216 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6217 customize_step[step_nr - 1].text, FONT_MENU_1);
6218 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6219 "Key:", FONT_MENU_1);
6221 /* press 'Enter' to leave */
6224 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6225 "Press Enter", FONT_TITLE_1);
6229 /* query next key binding */
6230 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6231 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6232 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6233 "Key:", FONT_INPUT_1_ACTIVE);
6234 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6235 getKeyNameFromKey(*customize_step[step_nr].key),
6240 case EVENT_KEYRELEASE:
6241 key_joystick_mapping = 0;
6245 HandleOtherEvents(&event);
6253 /* don't eat all CPU time */
6257 /* write new key bindings back to player setup */
6258 setup.input[player_nr].key = custom_key;
6261 DrawSetupScreen_Input();
6264 static boolean CalibrateJoystickMain(int player_nr)
6266 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6267 int new_joystick_xright = JOYSTICK_XMIDDLE;
6268 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6269 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6270 int new_joystick_xmiddle, new_joystick_ymiddle;
6272 int joystick_fd = joystick.fd[player_nr];
6273 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6274 boolean check[3][3];
6275 int check_remaining = 3 * 3;
6280 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6283 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6287 FadeOut(REDRAW_FIELD);
6291 for (y = 0; y < 3; y++)
6293 for (x = 0; x < 3; x++)
6295 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6296 check[x][y] = FALSE;
6300 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6301 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6302 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6303 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6304 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6305 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6306 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6308 joy_value = Joystick(player_nr);
6309 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6310 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6312 /* eventually uncalibrated center position (joystick could be uncentered) */
6313 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6316 new_joystick_xmiddle = joy_x;
6317 new_joystick_ymiddle = joy_y;
6319 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6321 FadeIn(REDRAW_FIELD);
6323 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6328 if (PendingEvent()) /* got event */
6336 case EVENT_KEYPRESS:
6337 switch (GetEventKey((KeyEvent *)&event, TRUE))
6340 if (check_remaining == 0)
6345 FadeSkipNextFadeIn();
6354 case EVENT_KEYRELEASE:
6355 key_joystick_mapping = 0;
6359 HandleOtherEvents(&event);
6364 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6367 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6368 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6369 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6370 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6372 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6373 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6374 setup.input[player_nr].joy.xright = new_joystick_xright;
6375 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6376 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6377 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6379 CheckJoystickData();
6381 joy_value = Joystick(player_nr);
6383 if (joy_value & JOY_BUTTON && check_remaining == 0)
6386 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6387 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6389 if (x != last_x || y != last_y)
6391 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6392 IMG_MENU_CALIBRATE_YELLOW, 0);
6393 DrawFixedGraphic(xpos + x, ypos + y,
6394 IMG_MENU_CALIBRATE_RED, 0);
6399 if (check_remaining > 0 && !check[x+1][y+1])
6401 check[x+1][y+1] = TRUE;
6409 /* don't eat all CPU time */
6413 /* calibrated center position (joystick should now be centered) */
6414 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6417 new_joystick_xmiddle = joy_x;
6418 new_joystick_ymiddle = joy_y;
6422 /* wait until the last pressed button was released */
6423 while (Joystick(player_nr) & JOY_BUTTON)
6425 if (PendingEvent()) /* got event */
6430 HandleOtherEvents(&event);
6439 void CalibrateJoystick(int player_nr)
6441 if (!CalibrateJoystickMain(player_nr))
6443 char *device_name = setup.input[player_nr].joy.device_name;
6444 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6445 int xpos = mSX - SX;
6446 int ypos = mSY - SY;
6450 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6451 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6454 Delay(2000); /* show error message for a short time */
6459 DrawSetupScreen_Input();
6462 void DrawSetupScreen()
6464 DeactivateJoystick();
6466 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6468 if (setup_mode == SETUP_MODE_INPUT)
6469 DrawSetupScreen_Input();
6470 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6471 DrawChooseTree(&game_speed_current);
6472 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6473 DrawChooseTree(&scroll_delay_current);
6474 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6475 DrawChooseTree(&snapshot_mode_current);
6476 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6477 DrawChooseTree(&screen_mode_current);
6478 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6479 DrawChooseTree(&window_size_current);
6480 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6481 DrawChooseTree(&scaling_type_current);
6482 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6483 DrawChooseTree(&artwork.gfx_current);
6484 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6485 DrawChooseTree(&artwork.snd_current);
6486 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6487 DrawChooseTree(&artwork.mus_current);
6488 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6489 DrawChooseTree(&volume_simple_current);
6490 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6491 DrawChooseTree(&volume_loops_current);
6492 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6493 DrawChooseTree(&volume_music_current);
6494 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6495 DrawChooseTree(&touch_control_current);
6496 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6497 DrawChooseTree(&move_distance_current);
6498 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6499 DrawChooseTree(&drop_distance_current);
6501 DrawSetupScreen_Generic();
6507 void RedrawSetupScreenAfterFullscreenToggle()
6509 if (setup_mode == SETUP_MODE_GRAPHICS ||
6510 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6512 // update list selection from "setup.window_scaling_percent"
6513 execSetupGraphics_setWindowSizes(TRUE);
6519 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6521 if (setup_mode == SETUP_MODE_INPUT)
6522 HandleSetupScreen_Input(mx, my, dx, dy, button);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6524 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6526 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6528 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6530 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6531 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6532 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6533 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6534 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6535 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6536 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6537 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6538 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6539 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6540 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6541 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6542 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6543 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6544 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6545 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6546 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6547 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6548 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6549 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6550 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6551 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6552 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6554 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6557 void HandleGameActions()
6559 if (game_status != GAME_MODE_PLAYING)
6562 GameActions(); /* main game loop */
6564 if (tape.auto_play && !tape.playing)
6565 AutoPlayTape(); /* continue automatically playing next tape */
6569 /* ---------- new screen button stuff -------------------------------------- */
6571 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6575 case SCREEN_CTRL_ID_PREV_LEVEL:
6576 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6577 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6580 case SCREEN_CTRL_ID_NEXT_LEVEL:
6581 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6582 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6585 case SCREEN_CTRL_ID_PREV_PLAYER:
6586 *x = mSX + TILEX * 10;
6587 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6590 case SCREEN_CTRL_ID_NEXT_PLAYER:
6591 *x = mSX + TILEX * 12;
6592 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6596 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6602 int gfx_unpressed, gfx_pressed;
6603 void (*get_gadget_position)(int *, int *, int);
6607 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6610 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6611 getScreenMenuButtonPos,
6612 SCREEN_CTRL_ID_PREV_LEVEL,
6617 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6618 getScreenMenuButtonPos,
6619 SCREEN_CTRL_ID_NEXT_LEVEL,
6624 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6625 getScreenMenuButtonPos,
6626 SCREEN_CTRL_ID_PREV_PLAYER,
6631 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6632 getScreenMenuButtonPos,
6633 SCREEN_CTRL_ID_NEXT_PLAYER,
6641 int gfx_unpressed, gfx_pressed;
6645 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6648 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6649 -1, -1, /* these values are not constant, but can change at runtime */
6650 SCREEN_CTRL_ID_SCROLL_UP,
6654 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6655 -1, -1, /* these values are not constant, but can change at runtime */
6656 SCREEN_CTRL_ID_SCROLL_DOWN,
6663 int gfx_unpressed, gfx_pressed;
6669 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6672 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6673 -1, -1, /* these values are not constant, but can change at runtime */
6674 -1, -1, /* these values are not constant, but can change at runtime */
6675 GD_TYPE_SCROLLBAR_VERTICAL,
6676 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6677 "scroll level series vertically"
6681 static void CreateScreenMenubuttons()
6683 struct GadgetInfo *gi;
6684 unsigned int event_mask;
6687 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6689 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6690 int gfx_unpressed, gfx_pressed;
6691 int x, y, width, height;
6692 int gd_x1, gd_x2, gd_y1, gd_y2;
6693 int id = menubutton_info[i].gadget_id;
6695 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6697 menubutton_info[i].get_gadget_position(&x, &y, id);
6699 width = SC_MENUBUTTON_XSIZE;
6700 height = SC_MENUBUTTON_YSIZE;
6702 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6703 gfx_pressed = menubutton_info[i].gfx_pressed;
6704 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6705 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6706 gd_x1 = graphic_info[gfx_unpressed].src_x;
6707 gd_y1 = graphic_info[gfx_unpressed].src_y;
6708 gd_x2 = graphic_info[gfx_pressed].src_x;
6709 gd_y2 = graphic_info[gfx_pressed].src_y;
6711 gi = CreateGadget(GDI_CUSTOM_ID, id,
6712 GDI_CUSTOM_TYPE_ID, i,
6713 GDI_INFO_TEXT, menubutton_info[i].infotext,
6718 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6719 GDI_STATE, GD_BUTTON_UNPRESSED,
6720 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6721 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6722 GDI_DIRECT_DRAW, FALSE,
6723 GDI_EVENT_MASK, event_mask,
6724 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6728 Error(ERR_EXIT, "cannot create gadget");
6730 screen_gadget[id] = gi;
6734 static void CreateScreenScrollbuttons()
6736 struct GadgetInfo *gi;
6737 unsigned int event_mask;
6740 /* these values are not constant, but can change at runtime */
6741 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6742 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6743 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6744 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6746 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6748 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6749 int gfx_unpressed, gfx_pressed;
6750 int x, y, width, height;
6751 int gd_x1, gd_x2, gd_y1, gd_y2;
6752 int id = scrollbutton_info[i].gadget_id;
6754 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6756 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6757 y = mSY + scrollbutton_info[i].y;
6758 width = SC_SCROLLBUTTON_XSIZE;
6759 height = SC_SCROLLBUTTON_YSIZE;
6761 /* correct scrollbar position if placed outside menu (playfield) area */
6762 if (x > SX + SC_SCROLL_UP_XPOS)
6763 x = SX + SC_SCROLL_UP_XPOS;
6765 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6766 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6767 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6769 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6770 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6771 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6772 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6773 gd_x1 = graphic_info[gfx_unpressed].src_x;
6774 gd_y1 = graphic_info[gfx_unpressed].src_y;
6775 gd_x2 = graphic_info[gfx_pressed].src_x;
6776 gd_y2 = graphic_info[gfx_pressed].src_y;
6778 gi = CreateGadget(GDI_CUSTOM_ID, id,
6779 GDI_CUSTOM_TYPE_ID, i,
6780 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6785 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6786 GDI_STATE, GD_BUTTON_UNPRESSED,
6787 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6788 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6789 GDI_DIRECT_DRAW, FALSE,
6790 GDI_EVENT_MASK, event_mask,
6791 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6795 Error(ERR_EXIT, "cannot create gadget");
6797 screen_gadget[id] = gi;
6801 static void CreateScreenScrollbars()
6805 /* these values are not constant, but can change at runtime */
6806 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6807 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6808 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6809 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6811 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6813 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6814 int gfx_unpressed, gfx_pressed;
6815 int x, y, width, height;
6816 int gd_x1, gd_x2, gd_y1, gd_y2;
6817 struct GadgetInfo *gi;
6818 int items_max, items_visible, item_position;
6819 unsigned int event_mask;
6820 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6821 int id = scrollbar_info[i].gadget_id;
6823 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6825 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6826 y = mSY + scrollbar_info[i].y;
6827 width = scrollbar_info[i].width;
6828 height = scrollbar_info[i].height;
6830 /* correct scrollbar position if placed outside menu (playfield) area */
6831 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6832 x = SX + SC_SCROLL_VERTICAL_XPOS;
6834 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6835 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6837 items_max = num_page_entries;
6838 items_visible = num_page_entries;
6841 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6842 gfx_pressed = scrollbar_info[i].gfx_pressed;
6843 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6844 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6845 gd_x1 = graphic_info[gfx_unpressed].src_x;
6846 gd_y1 = graphic_info[gfx_unpressed].src_y;
6847 gd_x2 = graphic_info[gfx_pressed].src_x;
6848 gd_y2 = graphic_info[gfx_pressed].src_y;
6850 gi = CreateGadget(GDI_CUSTOM_ID, id,
6851 GDI_CUSTOM_TYPE_ID, i,
6852 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6857 GDI_TYPE, scrollbar_info[i].type,
6858 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6859 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6860 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6861 GDI_WHEEL_AREA_X, SX,
6862 GDI_WHEEL_AREA_Y, SY,
6863 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6864 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6865 GDI_STATE, GD_BUTTON_UNPRESSED,
6866 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6867 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6868 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6869 GDI_DIRECT_DRAW, FALSE,
6870 GDI_EVENT_MASK, event_mask,
6871 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6875 Error(ERR_EXIT, "cannot create gadget");
6877 screen_gadget[id] = gi;
6881 void CreateScreenGadgets()
6883 int last_game_status = game_status; /* save current game status */
6885 CreateScreenMenubuttons();
6887 CreateScreenScrollbuttons();
6888 CreateScreenScrollbars();
6890 game_status = last_game_status; /* restore current game status */
6893 void FreeScreenGadgets()
6897 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6898 FreeGadget(screen_gadget[i]);
6901 void MapScreenMenuGadgets(int screen_mask)
6905 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6906 if (screen_mask & menubutton_info[i].screen_mask)
6907 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6910 void MapScreenGadgets(int num_entries)
6914 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6917 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6918 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6920 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6921 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6924 void MapScreenTreeGadgets(TreeInfo *ti)
6926 MapScreenGadgets(numTreeInfoInGroup(ti));
6929 static void HandleScreenGadgets(struct GadgetInfo *gi)
6931 int id = gi->custom_id;
6932 int button = gi->event.button;
6933 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6937 case SCREEN_CTRL_ID_PREV_LEVEL:
6938 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6941 case SCREEN_CTRL_ID_NEXT_LEVEL:
6942 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6945 case SCREEN_CTRL_ID_PREV_PLAYER:
6946 HandleSetupScreen_Input_Player(step, -1);
6949 case SCREEN_CTRL_ID_NEXT_PLAYER:
6950 HandleSetupScreen_Input_Player(step, +1);
6953 case SCREEN_CTRL_ID_SCROLL_UP:
6954 if (game_status == GAME_MODE_LEVELS)
6955 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6956 else if (game_status == GAME_MODE_LEVELNR)
6957 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6958 else if (game_status == GAME_MODE_SETUP)
6959 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6960 else if (game_status == GAME_MODE_INFO)
6961 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6964 case SCREEN_CTRL_ID_SCROLL_DOWN:
6965 if (game_status == GAME_MODE_LEVELS)
6966 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6967 else if (game_status == GAME_MODE_LEVELNR)
6968 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6969 else if (game_status == GAME_MODE_SETUP)
6970 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6971 else if (game_status == GAME_MODE_INFO)
6972 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6975 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6976 if (game_status == GAME_MODE_LEVELS)
6977 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6978 else if (game_status == GAME_MODE_LEVELNR)
6979 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6980 else if (game_status == GAME_MODE_SETUP)
6981 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6982 else if (game_status == GAME_MODE_INFO)
6983 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);