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(fade_mask);
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)
1832 CloseDoor(DOOR_CLOSE_2);
1834 game_status = GAME_MODE_LEVELNR;
1836 ChangeViewportPropertiesIfNeeded();
1838 DrawChooseLevelNr();
1840 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1846 PlaySound(SND_MENU_ITEM_ACTIVATING);
1848 DrawCursorAndText_Main(choice, FALSE, FALSE);
1849 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1856 PlaySound(SND_MENU_ITEM_SELECTING);
1858 if (pos == MAIN_CONTROL_NAME)
1860 game_status = GAME_MODE_PSEUDO_TYPENAME;
1862 HandleTypeName(strlen(setup.player_name), 0);
1864 else if (pos == MAIN_CONTROL_LEVELS)
1870 CloseDoor(DOOR_CLOSE_2);
1872 game_status = GAME_MODE_LEVELS;
1874 SaveLevelSetup_LastSeries();
1875 SaveLevelSetup_SeriesInfo();
1877 if (setup.internal.choose_from_top_leveldir)
1880 ChangeViewportPropertiesIfNeeded();
1882 DrawChooseLevelSet();
1885 else if (pos == MAIN_CONTROL_SCORES)
1889 CloseDoor(DOOR_CLOSE_2);
1891 game_status = GAME_MODE_SCORES;
1895 else if (pos == MAIN_CONTROL_EDITOR)
1897 if (leveldir_current->readonly &&
1898 !strEqual(setup.player_name, "Artsoft"))
1899 Request("This level is read only!", REQ_CONFIRM);
1903 CloseDoor(DOOR_CLOSE_2);
1905 game_status = GAME_MODE_EDITOR;
1907 FadeSetEnterScreen();
1911 else if (pos == MAIN_CONTROL_INFO)
1915 CloseDoor(DOOR_CLOSE_2);
1917 game_status = GAME_MODE_INFO;
1918 info_mode = INFO_MODE_MAIN;
1920 ChangeViewportPropertiesIfNeeded();
1924 else if (pos == MAIN_CONTROL_GAME)
1928 StartGameActions(options.network, setup.autorecord, level.random_seed);
1930 else if (pos == MAIN_CONTROL_SETUP)
1934 CloseDoor(DOOR_CLOSE_2);
1936 game_status = GAME_MODE_SETUP;
1937 setup_mode = SETUP_MODE_MAIN;
1939 ChangeViewportPropertiesIfNeeded();
1943 else if (pos == MAIN_CONTROL_QUIT)
1945 SaveLevelSetup_LastSeries();
1946 SaveLevelSetup_SeriesInfo();
1948 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1949 game_status = GAME_MODE_QUIT;
1954 button_pressed_last = button_pressed;
1958 /* ========================================================================= */
1959 /* info screen functions */
1960 /* ========================================================================= */
1962 static struct TokenInfo *info_info;
1963 static int num_info_info; /* number of info entries shown on screen */
1964 static int max_info_info; /* total number of info entries in list */
1966 static void execInfoTitleScreen()
1968 info_mode = INFO_MODE_TITLE;
1973 static void execInfoElements()
1975 info_mode = INFO_MODE_ELEMENTS;
1980 static void execInfoMusic()
1982 info_mode = INFO_MODE_MUSIC;
1987 static void execInfoCredits()
1989 info_mode = INFO_MODE_CREDITS;
1994 static void execInfoProgram()
1996 info_mode = INFO_MODE_PROGRAM;
2001 static void execInfoVersion()
2003 info_mode = INFO_MODE_VERSION;
2008 static void execInfoLevelSet()
2010 info_mode = INFO_MODE_LEVELSET;
2015 static void execExitInfo()
2017 game_status = GAME_MODE_MAIN;
2022 static struct TokenInfo info_info_main[] =
2024 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2025 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2026 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2027 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2028 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2029 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2030 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2031 { TYPE_EMPTY, NULL, "" },
2032 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2037 static int getMenuTextFont(int type)
2039 if (type & (TYPE_SWITCH |
2051 static struct TokenInfo *setup_info;
2052 static struct TokenInfo setup_info_input[];
2054 static struct TokenInfo *menu_info;
2056 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2057 int screen_pos, int menu_info_pos_raw,
2060 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2061 struct TokenInfo *ti = &token_info[pos];
2062 int xpos = MENU_SCREEN_START_XPOS;
2063 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2064 int font_nr = getMenuTextFont(ti->type);
2066 if (token_info == setup_info_input)
2067 font_nr = FONT_MENU_1;
2070 font_nr = FONT_ACTIVE(font_nr);
2072 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2074 if (ti->type & ~TYPE_SKIP_ENTRY)
2075 drawCursor(screen_pos, active);
2078 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2081 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2084 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2087 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2090 static char *screen_mode_text;
2091 static char *window_size_text;
2092 static char *scaling_type_text;
2094 static void drawSetupValue(int, int);
2096 static void drawMenuInfoList(int first_entry, int num_page_entries,
2097 int max_page_entries)
2101 if (first_entry + num_page_entries > max_page_entries)
2104 clearMenuListArea();
2106 for (i = 0; i < num_page_entries; i++)
2108 int menu_info_pos = first_entry + i;
2109 struct TokenInfo *si = &menu_info[menu_info_pos];
2110 void *value_ptr = si->value;
2112 /* set some entries to "unchangeable" according to other variables */
2113 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2114 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2115 (value_ptr == &setup.sound_music && !audio.music_available) ||
2116 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2117 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2118 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2119 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2120 si->type |= TYPE_GHOSTED;
2122 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2123 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2124 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2125 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2126 else if (si->type & ~TYPE_SKIP_ENTRY)
2127 initCursor(i, IMG_MENU_BUTTON);
2129 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2131 if (si->type & TYPE_VALUE &&
2132 menu_info == setup_info)
2133 drawSetupValue(i, menu_info_pos);
2137 static void DrawInfoScreen_Main()
2139 int fade_mask = REDRAW_FIELD;
2142 if (redraw_mask & REDRAW_ALL)
2143 fade_mask = REDRAW_ALL;
2145 if (CheckIfGlobalBorderHasChanged())
2146 fade_mask = REDRAW_ALL;
2150 FreeScreenGadgets();
2151 CreateScreenGadgets();
2153 CloseDoor(DOOR_CLOSE_2);
2155 /* (needed after displaying title screens which disable auto repeat) */
2156 KeyboardAutoRepeatOn();
2158 FadeSetLeaveScreen();
2162 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2166 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2168 info_info = info_info_main;
2170 // determine maximal number of info entries that can be displayed on screen
2172 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2175 // determine maximal number of info entries available for menu of info screen
2177 for (i = 0; info_info[i].type != 0; i++)
2180 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2182 MapScreenGadgets(max_info_info);
2187 DrawMaskedBorder(fade_mask);
2194 static void changeSetupValue(int, int, int);
2196 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2197 int mode, int num_page_entries, int max_page_entries)
2199 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2200 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2201 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2202 int *num_page_entries_last = num_page_entries_all_last[game_status];
2203 int *choice_store = choice_stores[game_status];
2204 int *first_entry_store = first_entry_stores[game_status];
2205 int choice = choice_store[mode]; /* starts with 0 */
2206 int first_entry = first_entry_store[mode]; /* starts with 0 */
2208 int y = choice - first_entry;
2210 boolean position_set_by_scrollbar = (dx == 999);
2211 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2214 if (button == MB_MENU_INITIALIZE)
2216 // check if number of menu page entries has changed (may happen by change
2217 // of custom artwork definition value for 'list_size' for this menu screen)
2218 // (in this case, the last menu position most probably has to be corrected)
2219 if (num_page_entries != num_page_entries_last[mode])
2221 choice_store[mode] = first_entry_store[mode] = 0;
2223 choice = first_entry = 0;
2226 num_page_entries_last[mode] = num_page_entries;
2229 /* advance to first valid menu entry */
2230 while (choice < num_page_entries &&
2231 menu_info[choice].type & TYPE_SKIP_ENTRY)
2234 if (position_set_by_scrollbar)
2235 first_entry = first_entry_store[mode] = dy;
2237 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2238 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2240 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2242 if (choice < first_entry)
2244 choice = first_entry;
2246 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2249 else if (choice > first_entry + num_page_entries - 1)
2251 choice = first_entry + num_page_entries - 1;
2253 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2257 choice_store[mode] = choice;
2259 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2263 else if (button == MB_MENU_LEAVE)
2265 PlaySound(SND_MENU_ITEM_SELECTING);
2267 for (i = 0; i < max_page_entries; i++)
2269 if (menu_info[i].type & TYPE_LEAVE_MENU)
2271 void (*menu_callback_function)(void) = menu_info[i].value;
2275 menu_callback_function();
2277 break; /* absolutely needed because function changes 'menu_info'! */
2284 if (mx || my) /* mouse input */
2286 x = (mx - mSX) / 32;
2287 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2289 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2291 /* move cursor instead of scrolling when already at start/end of list */
2292 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2294 else if (dy == +1 * SCROLL_LINE &&
2295 first_entry + num_page_entries == max_page_entries)
2298 /* handle scrolling screen one line or page */
2300 y + dy > num_page_entries - 1)
2302 boolean redraw = FALSE;
2304 if (ABS(dy) == SCROLL_PAGE)
2305 step = num_page_entries - 1;
2307 if (dy < 0 && first_entry > 0)
2309 /* scroll page/line up */
2311 first_entry -= step;
2312 if (first_entry < 0)
2317 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2319 /* scroll page/line down */
2321 first_entry += step;
2322 if (first_entry + num_page_entries > max_page_entries)
2323 first_entry = MAX(0, max_page_entries - num_page_entries);
2330 choice += first_entry - first_entry_store[mode];
2332 if (choice < first_entry)
2334 choice = first_entry;
2336 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2339 else if (choice > first_entry + num_page_entries - 1)
2341 choice = first_entry + num_page_entries - 1;
2343 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2346 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2350 if (choice < first_entry ||
2351 choice > first_entry + num_page_entries - 1)
2352 first_entry += SIGN(dy);
2355 first_entry_store[mode] = first_entry;
2356 choice_store[mode] = choice;
2358 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2360 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2362 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2363 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2371 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2373 if (menu_info[choice].type & menu_navigation_type ||
2374 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2375 menu_info[choice].type & TYPE_YES_NO_AUTO)
2376 button = MB_MENU_CHOICE;
2381 /* jump to next non-empty menu entry (up or down) */
2382 while (first_entry + y > 0 &&
2383 first_entry + y < max_page_entries - 1 &&
2384 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2387 if (!IN_VIS_MENU(x, y))
2389 choice += y - y_old;
2391 if (choice < first_entry)
2392 first_entry = choice;
2393 else if (choice > first_entry + num_page_entries - 1)
2394 first_entry = choice - num_page_entries + 1;
2396 if (first_entry >= 0 &&
2397 first_entry + num_page_entries <= max_page_entries)
2399 first_entry_store[mode] = first_entry;
2401 if (choice < first_entry)
2402 choice = first_entry;
2403 else if (choice > first_entry + num_page_entries - 1)
2404 choice = first_entry + num_page_entries - 1;
2406 choice_store[mode] = choice;
2408 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2410 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2412 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2413 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2420 if (!anyScrollbarGadgetActive() &&
2421 IN_VIS_MENU(x, y) &&
2422 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2423 y >= 0 && y < num_page_entries)
2427 if (first_entry + y != choice &&
2428 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2430 PlaySound(SND_MENU_ITEM_ACTIVATING);
2432 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2433 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2435 choice = choice_store[mode] = first_entry + y;
2438 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2440 PlaySound(SND_MENU_ITEM_SELECTING);
2442 /* when selecting key headline, execute function for key value change */
2443 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2444 menu_info[first_entry + y + 1].type & TYPE_KEY)
2447 /* when selecting string value, execute function for list selection */
2448 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2449 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2452 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2454 void (*menu_callback_function)(void) =
2455 menu_info[first_entry + y].value;
2457 FadeSetFromType(menu_info[first_entry + y].type);
2459 menu_callback_function();
2461 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2462 menu_info == setup_info)
2464 changeSetupValue(y, first_entry + y, dx);
2470 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2472 menu_info = info_info;
2474 HandleMenuScreen(mx, my, dx, dy, button,
2475 info_mode, num_info_info, max_info_info);
2478 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2480 int ystart1 = mSY - SY + 100;
2481 int ystart2 = mSY - SY + 150;
2482 int ybottom = mSY - SY + SYSIZE - 20;
2484 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2486 FadeOut(REDRAW_FIELD);
2491 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2492 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2494 DrawTextSCentered(ybottom, FONT_TEXT_4,
2495 "Press any key or button for info menu");
2497 FadeIn(REDRAW_FIELD);
2500 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2502 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2503 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2504 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2505 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2506 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2507 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2508 int ystep = MENU_SCREEN_INFO_YSTEP;
2509 int element, action, direction;
2517 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2518 infoscreen_step[i] = infoscreen_frame[i] = 0;
2523 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2525 DrawTextSCentered(ybottom, FONT_TEXT_4,
2526 "Press any key or button for next page");
2532 while (helpanim_info[j].element != HELPANIM_LIST_END)
2534 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2539 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2548 j += infoscreen_step[i - start];
2550 element = helpanim_info[j].element;
2551 action = helpanim_info[j].action;
2552 direction = helpanim_info[j].direction;
2555 element = EL_UNKNOWN;
2557 if (action != -1 && direction != -1)
2558 graphic = el_act_dir2img(element, action, direction);
2559 else if (action != -1)
2560 graphic = el_act2img(element, action);
2561 else if (direction != -1)
2562 graphic = el_dir2img(element, direction);
2564 graphic = el2img(element);
2566 delay = helpanim_info[j++].delay;
2571 if (infoscreen_frame[i - start] == 0)
2574 infoscreen_frame[i - start] = delay - 1;
2578 sync_frame = delay - infoscreen_frame[i - start];
2579 infoscreen_frame[i - start]--;
2582 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2584 if (!infoscreen_frame[i - start])
2585 infoscreen_step[i - start] = 0;
2589 if (!infoscreen_frame[i - start])
2590 infoscreen_step[i - start]++;
2591 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2597 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2599 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2600 graphic, sync_frame, USE_MASKING);
2603 DrawInfoScreen_HelpText(element, action, direction, i - start);
2608 redraw_mask |= REDRAW_FIELD;
2613 static char *getHelpText(int element, int action, int direction)
2615 char token[MAX_LINE_LEN];
2617 strcpy(token, element_info[element].token_name);
2620 strcat(token, element_action_info[action].suffix);
2622 if (direction != -1)
2623 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2625 return getHashEntry(helptext_info, token);
2628 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2630 int font_nr = FONT_INFO_ELEMENTS;
2631 int font_width = getFontWidth(font_nr);
2632 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2633 int sy = mSY + 65 + 2 * 32 + 1;
2634 int ystep = TILEY + 4;
2635 int pad_x = sx - SX;
2636 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2637 int max_lines_per_text = 2;
2640 if (action != -1 && direction != -1) /* element.action.direction */
2641 text = getHelpText(element, action, direction);
2643 if (text == NULL && action != -1) /* element.action */
2644 text = getHelpText(element, action, -1);
2646 if (text == NULL && direction != -1) /* element.direction */
2647 text = getHelpText(element, -1, direction);
2649 if (text == NULL) /* base element */
2650 text = getHelpText(element, -1, -1);
2652 if (text == NULL) /* not found */
2653 text = "No description available";
2655 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2656 sy += getFontHeight(font_nr) / 2;
2658 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2659 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2660 TRUE, FALSE, FALSE);
2663 void DrawInfoScreen_TitleScreen()
2668 void HandleInfoScreen_TitleScreen(int button)
2670 HandleTitleScreen(0, 0, 0, 0, button);
2673 void DrawInfoScreen_Elements()
2675 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2677 FadeOut(REDRAW_FIELD);
2682 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2684 FadeIn(REDRAW_FIELD);
2689 void HandleInfoScreen_Elements(int button)
2691 static unsigned int info_delay = 0;
2692 static int num_anims;
2693 static int num_pages;
2695 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2698 if (button == MB_MENU_INITIALIZE)
2700 boolean new_element = TRUE;
2704 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2706 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2708 else if (new_element)
2711 new_element = FALSE;
2715 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2719 if (button == MB_MENU_LEAVE)
2721 PlaySound(SND_MENU_ITEM_SELECTING);
2723 info_mode = INFO_MODE_MAIN;
2728 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2730 if (button != MB_MENU_INITIALIZE)
2732 PlaySound(SND_MENU_ITEM_SELECTING);
2737 if (page >= num_pages)
2739 FadeSoundsAndMusic();
2741 info_mode = INFO_MODE_MAIN;
2748 FadeSetNextScreen();
2750 if (button != MB_MENU_INITIALIZE)
2751 FadeOut(REDRAW_FIELD);
2753 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2755 if (button != MB_MENU_INITIALIZE)
2756 FadeIn(REDRAW_FIELD);
2760 if (DelayReached(&info_delay, GameFrameDelay))
2761 if (page < num_pages)
2762 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2764 PlayMenuSoundIfLoop();
2768 void DrawInfoScreen_Music()
2770 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2772 FadeOut(REDRAW_FIELD);
2779 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2781 FadeIn(REDRAW_FIELD);
2784 void HandleInfoScreen_Music(int button)
2786 static struct MusicFileInfo *list = NULL;
2787 int ystart1 = mSY - SY + 100;
2788 int ystart2 = mSY - SY + 150;
2789 int ybottom = mSY - SY + SYSIZE - 20;
2792 if (button == MB_MENU_INITIALIZE)
2794 list = music_file_info;
2798 FadeSoundsAndMusic();
2803 DrawTextSCentered(ystart1, FONT_TEXT_1,
2804 "No music info for this level set.");
2806 DrawTextSCentered(ybottom, FONT_TEXT_4,
2807 "Press any key or button for info menu");
2813 if (button == MB_MENU_LEAVE)
2815 PlaySound(SND_MENU_ITEM_SELECTING);
2817 FadeSoundsAndMusic();
2819 info_mode = INFO_MODE_MAIN;
2824 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2828 if (button != MB_MENU_INITIALIZE)
2830 PlaySound(SND_MENU_ITEM_SELECTING);
2838 FadeSoundsAndMusic();
2840 info_mode = INFO_MODE_MAIN;
2846 FadeSoundsAndMusic();
2848 if (list != music_file_info)
2849 FadeSetNextScreen();
2851 if (button != MB_MENU_INITIALIZE)
2852 FadeOut(REDRAW_FIELD);
2859 int sound = list->music;
2861 if (sound_info[sound].loop)
2862 PlaySoundLoop(sound);
2866 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2870 PlayMusic(list->music);
2872 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2875 if (!strEqual(list->title, UNKNOWN_NAME))
2877 if (!strEqual(list->title_header, UNKNOWN_NAME))
2878 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2880 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2883 if (!strEqual(list->artist, UNKNOWN_NAME))
2885 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2886 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2888 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2890 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2893 if (!strEqual(list->album, UNKNOWN_NAME))
2895 if (!strEqual(list->album_header, UNKNOWN_NAME))
2896 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2898 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2900 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2903 if (!strEqual(list->year, UNKNOWN_NAME))
2905 if (!strEqual(list->year_header, UNKNOWN_NAME))
2906 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2908 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2910 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2913 DrawTextSCentered(ybottom, FONT_TEXT_4,
2914 "Press any key or button for next page");
2916 if (button != MB_MENU_INITIALIZE)
2917 FadeIn(REDRAW_FIELD);
2920 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2921 PlaySoundLoop(list->music);
2924 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2926 int ystart1 = mSY - SY + 100;
2927 int ystart2 = mSY - SY + 150;
2928 int ybottom = mSY - SY + SYSIZE - 20;
2934 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2938 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2939 "Special thanks to");
2940 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2942 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2944 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2945 "\"Boulder Dash\"");
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,
2953 "First Star Software");
2955 else if (screen_nr == 1)
2957 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2958 "Special thanks to");
2959 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2960 "Klaus Heinz & Volker Wertich");
2961 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2963 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2964 "\"Emerald Mine\"");
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,
2974 else if (screen_nr == 2)
2976 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2977 "Special thanks to");
2978 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2979 "Michael Stopp & Philip Jespersen");
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,
2991 "Digital Integration");
2993 else if (screen_nr == 3)
2995 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2996 "Special thanks to");
2997 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2998 "Hiroyuki Imabayashi");
2999 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3001 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3003 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3005 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3007 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3009 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3012 else if (screen_nr == 4)
3014 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3015 "Special thanks to");
3016 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3018 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3020 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3021 "J\xfcrgen Bonhagen");
3022 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3023 "for the continuous creation");
3024 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3025 "of outstanding level sets");
3027 else if (screen_nr == 5)
3029 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3031 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3033 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3034 "for ideas and inspiration by");
3035 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3038 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3040 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3042 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3043 "for ideas and inspiration by");
3044 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3047 else if (screen_nr == 6)
3049 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3051 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3054 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3055 "for the code base used for the");
3056 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3057 "native Emerald Mine engine");
3059 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3060 "for the new Emerald Mine engine");
3063 else if (screen_nr == 7)
3065 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3067 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3069 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3070 "for the initial DOS port");
3072 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3074 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3076 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3077 "for some additional toons");
3079 else if (screen_nr == 8)
3081 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3082 "And not to forget:");
3083 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3085 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3086 "All those who contributed");
3087 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3088 "levels to this game");
3089 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3093 DrawTextSCentered(ybottom, FONT_TEXT_4,
3094 "Press any key or button for next page");
3097 void DrawInfoScreen_Credits()
3099 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3101 FadeSoundsAndMusic();
3103 FadeOut(REDRAW_FIELD);
3105 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3107 FadeIn(REDRAW_FIELD);
3110 void HandleInfoScreen_Credits(int button)
3112 static int screen_nr = 0;
3113 int num_screens = 9;
3115 if (button == MB_MENU_INITIALIZE)
3119 // DrawInfoScreen_CreditsScreen(screen_nr);
3122 if (button == MB_MENU_LEAVE)
3124 PlaySound(SND_MENU_ITEM_SELECTING);
3126 info_mode = INFO_MODE_MAIN;
3131 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3133 if (button != MB_MENU_INITIALIZE)
3135 PlaySound(SND_MENU_ITEM_SELECTING);
3140 if (screen_nr >= num_screens)
3142 FadeSoundsAndMusic();
3144 info_mode = INFO_MODE_MAIN;
3151 FadeSetNextScreen();
3153 if (button != MB_MENU_INITIALIZE)
3154 FadeOut(REDRAW_FIELD);
3156 DrawInfoScreen_CreditsScreen(screen_nr);
3158 if (button != MB_MENU_INITIALIZE)
3159 FadeIn(REDRAW_FIELD);
3163 PlayMenuSoundIfLoop();
3167 void DrawInfoScreen_Program()
3169 int ystart1 = mSY - SY + 100;
3170 int ystart2 = mSY - SY + 150;
3171 int ybottom = mSY - SY + SYSIZE - 20;
3174 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3176 FadeOut(REDRAW_FIELD);
3181 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3183 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3184 "This game is Freeware!");
3185 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3186 "If you like it, send e-mail to:");
3187 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3188 setup.internal.program_email);
3189 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3190 "More information and levels:");
3191 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3192 setup.internal.program_website);
3193 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3194 "If you have created new levels,");
3195 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3196 "send them to me to include them!");
3197 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3200 DrawTextSCentered(ybottom, FONT_TEXT_4,
3201 "Press any key or button for info menu");
3203 FadeIn(REDRAW_FIELD);
3206 void HandleInfoScreen_Program(int button)
3208 if (button == MB_MENU_LEAVE)
3210 PlaySound(SND_MENU_ITEM_SELECTING);
3212 info_mode = INFO_MODE_MAIN;
3217 else if (button == MB_MENU_CHOICE)
3219 PlaySound(SND_MENU_ITEM_SELECTING);
3221 FadeSoundsAndMusic();
3223 info_mode = INFO_MODE_MAIN;
3228 PlayMenuSoundIfLoop();
3232 void DrawInfoScreen_Version()
3234 int font_header = FONT_TEXT_3;
3235 int font_text = FONT_TEXT_2;
3236 int xstep = getFontWidth(font_text);
3237 int ystep = getFontHeight(font_text);
3238 int ystart1 = mSY - SY + 100;
3239 int ystart2 = mSY - SY + 150;
3240 int ybottom = mSY - SY + SYSIZE - 20;
3241 int xstart1 = mSX - SX + 2 * xstep;
3242 int xstart2 = mSX - SX + 18 * xstep;
3243 int xstart3 = mSX - SX + 28 * xstep;
3244 SDL_version sdl_version_compiled;
3245 const SDL_version *sdl_version_linked;
3246 int driver_name_len = 10;
3247 #if defined(TARGET_SDL2)
3248 SDL_version sdl_version_linked_ext;
3249 const char *driver_name = NULL;
3251 char driver_name[driver_name_len];
3254 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3256 FadeOut(REDRAW_FIELD);
3261 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3263 DrawTextF(xstart1, ystart2, font_header, "Name");
3264 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3267 DrawTextF(xstart1, ystart2, font_header, "Version");
3268 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3271 DrawTextF(xstart1, ystart2, font_header, "Platform");
3272 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3275 DrawTextF(xstart1, ystart2, font_header, "Target");
3276 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3279 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3280 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3282 ystart2 += 3 * ystep;
3283 DrawTextF(xstart1, ystart2, font_header, "Library");
3284 DrawTextF(xstart2, ystart2, font_header, "compiled");
3285 DrawTextF(xstart3, ystart2, font_header, "linked");
3287 SDL_VERSION(&sdl_version_compiled);
3288 #if defined(TARGET_SDL2)
3289 SDL_GetVersion(&sdl_version_linked_ext);
3290 sdl_version_linked = &sdl_version_linked_ext;
3292 sdl_version_linked = SDL_Linked_Version();
3295 ystart2 += 2 * ystep;
3296 DrawTextF(xstart1, ystart2, font_text, "SDL");
3297 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3298 sdl_version_compiled.major,
3299 sdl_version_compiled.minor,
3300 sdl_version_compiled.patch);
3301 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3302 sdl_version_linked->major,
3303 sdl_version_linked->minor,
3304 sdl_version_linked->patch);
3306 SDL_IMAGE_VERSION(&sdl_version_compiled);
3307 sdl_version_linked = IMG_Linked_Version();
3310 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3311 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3312 sdl_version_compiled.major,
3313 sdl_version_compiled.minor,
3314 sdl_version_compiled.patch);
3315 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3316 sdl_version_linked->major,
3317 sdl_version_linked->minor,
3318 sdl_version_linked->patch);
3320 SDL_MIXER_VERSION(&sdl_version_compiled);
3321 sdl_version_linked = Mix_Linked_Version();
3324 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3325 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3326 sdl_version_compiled.major,
3327 sdl_version_compiled.minor,
3328 sdl_version_compiled.patch);
3329 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3330 sdl_version_linked->major,
3331 sdl_version_linked->minor,
3332 sdl_version_linked->patch);
3334 SDL_NET_VERSION(&sdl_version_compiled);
3335 sdl_version_linked = SDLNet_Linked_Version();
3338 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3339 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3340 sdl_version_compiled.major,
3341 sdl_version_compiled.minor,
3342 sdl_version_compiled.patch);
3343 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3344 sdl_version_linked->major,
3345 sdl_version_linked->minor,
3346 sdl_version_linked->patch);
3348 ystart2 += 3 * ystep;
3349 DrawTextF(xstart1, ystart2, font_header, "Driver");
3350 DrawTextF(xstart2, ystart2, font_header, "Requested");
3351 DrawTextF(xstart3, ystart2, font_header, "Used");
3353 #if defined(TARGET_SDL2)
3354 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3356 SDL_VideoDriverName(driver_name, driver_name_len);
3359 ystart2 += 2 * ystep;
3360 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3361 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3362 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3364 #if defined(TARGET_SDL2)
3365 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3367 SDL_AudioDriverName(driver_name, driver_name_len);
3371 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3372 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3373 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3375 DrawTextSCentered(ybottom, FONT_TEXT_4,
3376 "Press any key or button for info menu");
3378 FadeIn(REDRAW_FIELD);
3381 void HandleInfoScreen_Version(int button)
3383 if (button == MB_MENU_LEAVE)
3385 PlaySound(SND_MENU_ITEM_SELECTING);
3387 info_mode = INFO_MODE_MAIN;
3392 else if (button == MB_MENU_CHOICE)
3394 PlaySound(SND_MENU_ITEM_SELECTING);
3396 FadeSoundsAndMusic();
3398 info_mode = INFO_MODE_MAIN;
3403 PlayMenuSoundIfLoop();
3407 void DrawInfoScreen_LevelSet()
3409 struct TitleMessageInfo *tmi = &readme;
3410 char *filename = getLevelSetInfoFilename();
3411 char *title = "Level Set Information:";
3412 int ystart1 = mSY - SY + 100;
3413 int ybottom = mSY - SY + SYSIZE - 20;
3415 if (filename == NULL)
3417 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3422 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3424 FadeOut(REDRAW_FIELD);
3429 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3431 /* if x position set to "-1", automatically determine by playfield width */
3433 tmi->x = SXSIZE / 2;
3435 /* if y position set to "-1", use static default value */
3439 /* if width set to "-1", automatically determine by playfield width */
3440 if (tmi->width == -1)
3441 tmi->width = SXSIZE - 2 * TILEX;
3443 /* if height set to "-1", automatically determine by playfield height */
3444 if (tmi->height == -1)
3445 tmi->height = SYSIZE - 20 - tmi->y - 10;
3447 /* if chars set to "-1", automatically determine by text and font width */
3448 if (tmi->chars == -1)
3449 tmi->chars = tmi->width / getFontWidth(tmi->font);
3451 tmi->width = tmi->chars * getFontWidth(tmi->font);
3453 /* if lines set to "-1", automatically determine by text and font height */
3454 if (tmi->lines == -1)
3455 tmi->lines = tmi->height / getFontHeight(tmi->font);
3457 tmi->height = tmi->lines * getFontHeight(tmi->font);
3459 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3460 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3461 tmi->autowrap, tmi->centered, tmi->parse_comments);
3463 DrawTextSCentered(ybottom, FONT_TEXT_4,
3464 "Press any key or button for info menu");
3466 FadeIn(REDRAW_FIELD);
3469 void HandleInfoScreen_LevelSet(int button)
3471 if (button == MB_MENU_LEAVE)
3473 PlaySound(SND_MENU_ITEM_SELECTING);
3475 info_mode = INFO_MODE_MAIN;
3480 else if (button == MB_MENU_CHOICE)
3482 PlaySound(SND_MENU_ITEM_SELECTING);
3484 FadeSoundsAndMusic();
3486 info_mode = INFO_MODE_MAIN;
3491 PlayMenuSoundIfLoop();
3495 static void DrawInfoScreen()
3497 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3499 if (info_mode == INFO_MODE_TITLE)
3500 DrawInfoScreen_TitleScreen();
3501 else if (info_mode == INFO_MODE_ELEMENTS)
3502 DrawInfoScreen_Elements();
3503 else if (info_mode == INFO_MODE_MUSIC)
3504 DrawInfoScreen_Music();
3505 else if (info_mode == INFO_MODE_CREDITS)
3506 DrawInfoScreen_Credits();
3507 else if (info_mode == INFO_MODE_PROGRAM)
3508 DrawInfoScreen_Program();
3509 else if (info_mode == INFO_MODE_VERSION)
3510 DrawInfoScreen_Version();
3511 else if (info_mode == INFO_MODE_LEVELSET)
3512 DrawInfoScreen_LevelSet();
3514 DrawInfoScreen_Main();
3516 if (info_mode != INFO_MODE_MAIN &&
3517 info_mode != INFO_MODE_TITLE &&
3518 info_mode != INFO_MODE_MUSIC)
3525 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3527 if (info_mode == INFO_MODE_TITLE)
3528 HandleInfoScreen_TitleScreen(button);
3529 else if (info_mode == INFO_MODE_ELEMENTS)
3530 HandleInfoScreen_Elements(button);
3531 else if (info_mode == INFO_MODE_MUSIC)
3532 HandleInfoScreen_Music(button);
3533 else if (info_mode == INFO_MODE_CREDITS)
3534 HandleInfoScreen_Credits(button);
3535 else if (info_mode == INFO_MODE_PROGRAM)
3536 HandleInfoScreen_Program(button);
3537 else if (info_mode == INFO_MODE_VERSION)
3538 HandleInfoScreen_Version(button);
3539 else if (info_mode == INFO_MODE_LEVELSET)
3540 HandleInfoScreen_LevelSet(button);
3542 HandleInfoScreen_Main(mx, my, dx, dy, button);
3546 /* ========================================================================= */
3547 /* type name functions */
3548 /* ========================================================================= */
3550 void HandleTypeName(int newxpos, Key key)
3552 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3553 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3554 struct TextPosInfo *pos = mci->pos_input;
3555 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3556 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3557 static int xpos = 0;
3558 int font_nr = pos->font;
3559 int font_active_nr = FONT_ACTIVE(font_nr);
3560 int font_width = getFontWidth(font_active_nr);
3561 char key_char = getValidConfigValueChar(getCharFromKey(key));
3562 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3563 boolean is_active = TRUE;
3565 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3569 strcpy(last_player_name, setup.player_name);
3573 #if defined(TARGET_SDL2)
3574 SDL_StartTextInput();
3577 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3579 setup.player_name[xpos] = key_char;
3580 setup.player_name[xpos + 1] = 0;
3584 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3588 setup.player_name[xpos] = 0;
3590 else if (key == KSYM_Return && xpos > 0)
3596 game_status = GAME_MODE_MAIN;
3598 else if (key == KSYM_Escape)
3600 strcpy(setup.player_name, last_player_name);
3604 game_status = GAME_MODE_MAIN;
3609 pos->width = (strlen(setup.player_name) + 1) * font_width;
3610 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3612 DrawText(startx, starty, setup.player_name, font_active_nr);
3613 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3617 pos->width = strlen(setup.player_name) * font_width;
3618 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3620 DrawText(startx, starty, setup.player_name, font_nr);
3622 #if defined(TARGET_SDL2)
3623 SDL_StopTextInput();
3629 /* ========================================================================= */
3630 /* tree menu functions */
3631 /* ========================================================================= */
3633 static void DrawChooseTree(TreeInfo **ti_ptr)
3635 int fade_mask = REDRAW_FIELD;
3637 if (CheckIfGlobalBorderHasChanged())
3638 fade_mask = REDRAW_ALL;
3640 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3642 game_status = GAME_MODE_MAIN;
3651 FreeScreenGadgets();
3652 CreateScreenGadgets();
3654 CloseDoor(DOOR_CLOSE_2);
3658 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3662 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3663 MapScreenTreeGadgets(*ti_ptr);
3665 DrawMaskedBorder(fade_mask);
3672 static void drawChooseTreeList(int first_entry, int num_page_entries,
3676 char *title_string = NULL;
3677 int yoffset_sets = MENU_TITLE1_YPOS;
3678 int yoffset_setup = 16;
3679 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3680 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3681 int last_game_status = game_status; /* save current game status */
3683 title_string = ti->infotext;
3685 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3687 clearMenuListArea();
3689 for (i = 0; i < num_page_entries; i++)
3691 TreeInfo *node, *node_first;
3692 int entry_pos = first_entry + i;
3693 int xpos = MENU_SCREEN_START_XPOS;
3694 int ypos = MENU_SCREEN_START_YPOS + i;
3695 int startx = mSX + xpos * 32;
3696 int starty = mSY + ypos * 32;
3697 int font_nr = FONT_TEXT_1;
3698 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3699 int startx_text = startx + font_xoffset;
3700 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3701 int text_size = startx_scrollbar - startx_text;
3702 int max_buffer_len = text_size / getFontWidth(font_nr);
3703 char buffer[max_buffer_len + 1];
3705 node_first = getTreeInfoFirstGroupEntry(ti);
3706 node = getTreeInfoFromPos(node_first, entry_pos);
3708 strncpy(buffer, node->name, max_buffer_len);
3709 buffer[max_buffer_len] = '\0';
3711 DrawText(startx, starty, buffer, font_nr + node->color);
3713 if (node->parent_link)
3714 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3715 else if (node->level_group)
3716 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3718 initCursor(i, IMG_MENU_BUTTON);
3721 game_status = last_game_status; /* restore current game status */
3723 redraw_mask |= REDRAW_FIELD;
3726 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3728 TreeInfo *node, *node_first;
3729 int x, last_redraw_mask = redraw_mask;
3730 int ypos = MENU_TITLE2_YPOS;
3731 int font_nr = FONT_TITLE_2;
3733 if (ti->type == TREE_TYPE_LEVEL_NR)
3734 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3736 if (ti->type != TREE_TYPE_LEVEL_DIR)
3739 node_first = getTreeInfoFirstGroupEntry(ti);
3740 node = getTreeInfoFromPos(node_first, entry_pos);
3742 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3744 if (node->parent_link)
3745 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3746 node->node_parent->name);
3747 else if (node->level_group)
3748 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3750 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3751 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3752 node->levels, (node->levels > 1 ? "levels" : "level"),
3755 /* let BackToFront() redraw only what is needed */
3756 redraw_mask = last_redraw_mask;
3757 for (x = 0; x < SCR_FIELDX; x++)
3758 MarkTileDirty(x, 1);
3761 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3764 TreeInfo *ti = *ti_ptr;
3766 int y = ti->cl_cursor;
3767 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3768 int num_entries = numTreeInfoInGroup(ti);
3769 int num_page_entries;
3770 int last_game_status = game_status; /* save current game status */
3771 boolean position_set_by_scrollbar = (dx == 999);
3773 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3774 num_page_entries = num_entries;
3776 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3778 game_status = last_game_status; /* restore current game status */
3780 if (button == MB_MENU_INITIALIZE)
3782 int num_entries = numTreeInfoInGroup(ti);
3783 int entry_pos = posTreeInfo(ti);
3785 if (ti->cl_first == -1)
3787 /* only on initialization */
3788 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3789 ti->cl_cursor = entry_pos - ti->cl_first;
3791 else if (ti->cl_cursor >= num_page_entries ||
3792 (num_entries > num_page_entries &&
3793 num_entries - ti->cl_first < num_page_entries))
3795 /* only after change of list size (by custom graphic configuration) */
3796 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3797 ti->cl_cursor = entry_pos - ti->cl_first;
3800 if (position_set_by_scrollbar)
3803 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3806 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3807 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3808 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3812 else if (button == MB_MENU_LEAVE)
3816 PlaySound(SND_MENU_ITEM_SELECTING);
3818 if (ti->node_parent)
3820 *ti_ptr = ti->node_parent;
3821 DrawChooseTree(ti_ptr);
3823 else if (game_status == GAME_MODE_SETUP)
3825 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3826 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3827 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3829 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3830 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3831 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3832 execSetupGraphics();
3833 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3834 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3835 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3837 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3838 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3839 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3846 if (game_status == GAME_MODE_LEVELNR)
3848 int new_level_nr = atoi(level_number_current->identifier);
3850 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3853 game_status = GAME_MODE_MAIN;
3861 if (mx || my) /* mouse input */
3863 int last_game_status = game_status; /* save current game status */
3865 x = (mx - mSX) / 32;
3866 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3868 game_status = last_game_status; /* restore current game status */
3870 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3872 /* move cursor instead of scrolling when already at start/end of list */
3873 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3875 else if (dy == +1 * SCROLL_LINE &&
3876 ti->cl_first + num_page_entries == num_entries)
3879 /* handle scrolling screen one line or page */
3880 if (ti->cl_cursor + dy < 0 ||
3881 ti->cl_cursor + dy > num_page_entries - 1)
3883 boolean redraw = FALSE;
3885 if (ABS(dy) == SCROLL_PAGE)
3886 step = num_page_entries - 1;
3888 if (dy < 0 && ti->cl_first > 0)
3890 /* scroll page/line up */
3892 ti->cl_first -= step;
3893 if (ti->cl_first < 0)
3898 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3900 /* scroll page/line down */
3902 ti->cl_first += step;
3903 if (ti->cl_first + num_page_entries > num_entries)
3904 ti->cl_first = MAX(0, num_entries - num_page_entries);
3911 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3912 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3913 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3915 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3922 /* handle moving cursor one line */
3923 y = ti->cl_cursor + dy;
3928 TreeInfo *node_first, *node_cursor;
3929 int entry_pos = ti->cl_first + y;
3931 node_first = getTreeInfoFirstGroupEntry(ti);
3932 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3934 if (node_cursor->node_group)
3938 PlaySound(SND_MENU_ITEM_SELECTING);
3940 node_cursor->cl_first = ti->cl_first;
3941 node_cursor->cl_cursor = ti->cl_cursor;
3942 *ti_ptr = node_cursor->node_group;
3943 DrawChooseTree(ti_ptr);
3948 else if (dx == -1 && ti->node_parent)
3952 PlaySound(SND_MENU_ITEM_SELECTING);
3954 *ti_ptr = ti->node_parent;
3955 DrawChooseTree(ti_ptr);
3960 if (!anyScrollbarGadgetActive() &&
3961 IN_VIS_MENU(x, y) &&
3962 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3963 y >= 0 && y < num_page_entries)
3967 if (y != ti->cl_cursor)
3969 PlaySound(SND_MENU_ITEM_ACTIVATING);
3971 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3972 drawChooseTreeCursor(y, TRUE);
3973 drawChooseTreeInfo(ti->cl_first + y, ti);
3980 TreeInfo *node_first, *node_cursor;
3981 int entry_pos = ti->cl_first + y;
3983 PlaySound(SND_MENU_ITEM_SELECTING);
3985 node_first = getTreeInfoFirstGroupEntry(ti);
3986 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3988 if (node_cursor->node_group)
3992 node_cursor->cl_first = ti->cl_first;
3993 node_cursor->cl_cursor = ti->cl_cursor;
3994 *ti_ptr = node_cursor->node_group;
3995 DrawChooseTree(ti_ptr);
3997 else if (node_cursor->parent_link)
4001 *ti_ptr = node_cursor->node_parent;
4002 DrawChooseTree(ti_ptr);
4008 node_cursor->cl_first = ti->cl_first;
4009 node_cursor->cl_cursor = ti->cl_cursor;
4010 *ti_ptr = node_cursor;
4012 if (ti->type == TREE_TYPE_LEVEL_DIR)
4014 LoadLevelSetup_SeriesInfo();
4016 SaveLevelSetup_LastSeries();
4017 SaveLevelSetup_SeriesInfo();
4021 if (game_status == GAME_MODE_SETUP)
4023 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4024 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4025 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4027 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4028 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4029 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4030 execSetupGraphics();
4031 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4032 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4033 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4035 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4036 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4037 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4044 if (game_status == GAME_MODE_LEVELNR)
4046 int new_level_nr = atoi(level_number_current->identifier);
4048 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4051 game_status = GAME_MODE_MAIN;
4060 void DrawChooseLevelSet()
4062 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4064 DrawChooseTree(&leveldir_current);
4070 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4072 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4075 void DrawChooseLevelNr()
4079 if (level_number != NULL)
4081 freeTreeInfo(level_number);
4083 level_number = NULL;
4086 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4088 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4089 char identifier[32], name[32];
4092 /* temporarily load level info to get level name */
4093 LoadLevelInfoOnly(i);
4095 ti->node_top = &level_number;
4096 ti->sort_priority = 10000 + value;
4097 ti->color = (level.no_valid_file ? FC_BLUE :
4098 LevelStats_getSolved(i) ? FC_GREEN :
4099 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4101 sprintf(identifier, "%d", value);
4102 sprintf(name, "%03d: %s", value,
4103 (level.no_valid_file ? "(no file)" : level.name));
4105 setString(&ti->identifier, identifier);
4106 setString(&ti->name, name);
4107 setString(&ti->name_sorting, name);
4109 pushTreeInfo(&level_number, ti);
4112 /* sort level number values to start with lowest level number */
4113 sortTreeInfo(&level_number);
4115 /* set current level number to current level number */
4116 level_number_current =
4117 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4119 /* if that also fails, set current level number to first available level */
4120 if (level_number_current == NULL)
4121 level_number_current = level_number;
4123 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4125 DrawChooseTree(&level_number_current);
4131 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4133 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4136 void DrawHallOfFame(int highlight_position)
4138 int fade_mask = REDRAW_FIELD;
4140 /* required before door position may be changed in next step */
4141 CloseDoor(DOOR_CLOSE_ALL);
4143 /* needed if different viewport properties defined for scores */
4144 ChangeViewportPropertiesIfNeeded();
4146 if (CheckIfGlobalBorderHasChanged())
4147 fade_mask = REDRAW_ALL;
4150 FadeSoundsAndMusic();
4152 /* (this is needed when called from GameEnd() after winning a game) */
4153 KeyboardAutoRepeatOn();
4156 /* (this is needed when called from GameEnd() after winning a game) */
4157 SetDrawDeactivationMask(REDRAW_NONE);
4158 SetDrawBackgroundMask(REDRAW_FIELD);
4160 if (highlight_position < 0)
4161 LoadScore(level_nr);
4163 FadeSetEnterScreen();
4172 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4174 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4176 DrawMaskedBorder(fade_mask);
4181 static void drawHallOfFameList(int first_entry, int highlight_position)
4185 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4188 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4189 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4190 "HighScores of Level %d", level_nr);
4192 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4194 int entry = first_entry + i;
4195 boolean active = (entry == highlight_position);
4196 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4197 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4198 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4199 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4200 int dx1 = 3 * getFontWidth(font_nr1);
4201 int dx2 = dx1 + getFontWidth(font_nr1);
4202 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4203 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4204 int sy = mSY + 64 + i * 32;
4206 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4207 DrawText(mSX + dx1, sy, ".", font_nr1);
4209 for (j = 0; j < num_dots; j++)
4210 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4212 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4213 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4215 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4218 redraw_mask |= REDRAW_FIELD;
4221 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4223 static int first_entry = 0;
4224 static int highlight_position = 0;
4225 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4227 if (button == MB_MENU_INITIALIZE)
4230 highlight_position = mx;
4231 drawHallOfFameList(first_entry, highlight_position);
4236 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4237 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4241 if (first_entry > 0)
4243 first_entry -= step;
4244 if (first_entry < 0)
4247 drawHallOfFameList(first_entry, highlight_position);
4252 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4254 first_entry += step;
4255 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4256 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4258 drawHallOfFameList(first_entry, highlight_position);
4261 else if (button == MB_MENU_LEAVE)
4263 PlaySound(SND_MENU_ITEM_SELECTING);
4265 FadeSound(SND_BACKGROUND_SCORES);
4267 game_status = GAME_MODE_MAIN;
4271 else if (button == MB_MENU_CHOICE)
4273 PlaySound(SND_MENU_ITEM_SELECTING);
4275 FadeSound(SND_BACKGROUND_SCORES);
4277 game_status = GAME_MODE_MAIN;
4282 if (game_status == GAME_MODE_SCORES)
4283 PlayMenuSoundIfLoop();
4287 /* ========================================================================= */
4288 /* setup screen functions */
4289 /* ========================================================================= */
4291 static struct TokenInfo *setup_info;
4292 static int num_setup_info; /* number of setup entries shown on screen */
4293 static int max_setup_info; /* total number of setup entries in list */
4295 static char *screen_mode_text;
4296 static char *window_size_text;
4297 static char *scaling_type_text;
4298 static char *scroll_delay_text;
4299 static char *snapshot_mode_text;
4300 static char *game_speed_text;
4301 static char *graphics_set_name;
4302 static char *sounds_set_name;
4303 static char *music_set_name;
4304 static char *volume_simple_text;
4305 static char *volume_loops_text;
4306 static char *volume_music_text;
4307 static char *touch_controls_text;
4308 static char *move_distance_text;
4309 static char *drop_distance_text;
4311 static void execSetupMain()
4313 setup_mode = SETUP_MODE_MAIN;
4318 static void execSetupGame_setGameSpeeds()
4320 if (game_speeds == NULL)
4324 for (i = 0; game_speeds_list[i].value != -1; i++)
4326 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4327 char identifier[32], name[32];
4328 int value = game_speeds_list[i].value;
4329 char *text = game_speeds_list[i].text;
4331 ti->node_top = &game_speeds;
4332 ti->sort_priority = 10000 - value;
4334 sprintf(identifier, "%d", value);
4335 sprintf(name, "%s", text);
4337 setString(&ti->identifier, identifier);
4338 setString(&ti->name, name);
4339 setString(&ti->name_sorting, name);
4340 setString(&ti->infotext, "Game Speed");
4342 pushTreeInfo(&game_speeds, ti);
4345 /* sort game speed values to start with slowest game speed */
4346 sortTreeInfo(&game_speeds);
4348 /* set current game speed to configured game speed value */
4349 game_speed_current =
4350 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4352 /* if that fails, set current game speed to reliable default value */
4353 if (game_speed_current == NULL)
4354 game_speed_current =
4355 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4357 /* if that also fails, set current game speed to first available speed */
4358 if (game_speed_current == NULL)
4359 game_speed_current = game_speeds;
4362 setup.game_frame_delay = atoi(game_speed_current->identifier);
4364 /* needed for displaying game speed text instead of identifier */
4365 game_speed_text = game_speed_current->name;
4368 static void execSetupGame_setScrollDelays()
4370 if (scroll_delays == NULL)
4374 for (i = 0; scroll_delays_list[i].value != -1; i++)
4376 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4377 char identifier[32], name[32];
4378 int value = scroll_delays_list[i].value;
4379 char *text = scroll_delays_list[i].text;
4381 ti->node_top = &scroll_delays;
4382 ti->sort_priority = value;
4384 sprintf(identifier, "%d", value);
4385 sprintf(name, "%s", text);
4387 setString(&ti->identifier, identifier);
4388 setString(&ti->name, name);
4389 setString(&ti->name_sorting, name);
4390 setString(&ti->infotext, "Scaling Type");
4392 pushTreeInfo(&scroll_delays, ti);
4395 /* sort scaling type values to start with lowest scaling type value */
4396 sortTreeInfo(&scroll_delays);
4398 /* set current scaling type value to configured scaling type value */
4399 scroll_delay_current =
4400 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4402 /* if that fails, set current scaling type to reliable default value */
4403 if (scroll_delay_current == NULL)
4404 scroll_delay_current =
4405 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4407 /* if that also fails, set current scaling type to first available value */
4408 if (scroll_delay_current == NULL)
4409 scroll_delay_current = scroll_delays;
4412 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4414 /* needed for displaying scaling type text instead of identifier */
4415 scroll_delay_text = scroll_delay_current->name;
4418 static void execSetupGame_setSnapshotModes()
4420 if (snapshot_modes == NULL)
4424 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4426 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4427 char identifier[32], name[32];
4428 char *value = snapshot_modes_list[i].value;
4429 char *text = snapshot_modes_list[i].text;
4431 ti->node_top = &snapshot_modes;
4432 ti->sort_priority = i;
4434 sprintf(identifier, "%s", value);
4435 sprintf(name, "%s", text);
4437 setString(&ti->identifier, identifier);
4438 setString(&ti->name, name);
4439 setString(&ti->name_sorting, name);
4440 setString(&ti->infotext, "Snapshot Mode");
4442 pushTreeInfo(&snapshot_modes, ti);
4445 /* sort snapshot mode values to start with lowest snapshot mode value */
4446 sortTreeInfo(&snapshot_modes);
4448 /* set current snapshot mode value to configured snapshot mode value */
4449 snapshot_mode_current =
4450 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4452 /* if that fails, set current snapshot mode to reliable default value */
4453 if (snapshot_mode_current == NULL)
4454 snapshot_mode_current =
4455 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4457 /* if that also fails, set current snapshot mode to first available value */
4458 if (snapshot_mode_current == NULL)
4459 snapshot_mode_current = snapshot_modes;
4462 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4464 /* needed for displaying snapshot mode text instead of identifier */
4465 snapshot_mode_text = snapshot_mode_current->name;
4468 static void execSetupGame()
4470 execSetupGame_setGameSpeeds();
4471 execSetupGame_setScrollDelays();
4472 execSetupGame_setSnapshotModes();
4474 setup_mode = SETUP_MODE_GAME;
4479 static void execSetupChooseGameSpeed()
4481 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4486 static void execSetupChooseScrollDelay()
4488 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4493 static void execSetupChooseSnapshotMode()
4495 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4500 static void execSetupEditor()
4502 setup_mode = SETUP_MODE_EDITOR;
4507 static void execSetupGraphics_setWindowSizes(boolean update_list)
4509 if (window_sizes != NULL && update_list)
4511 freeTreeInfo(window_sizes);
4513 window_sizes = NULL;
4516 if (window_sizes == NULL)
4518 boolean current_window_size_found = FALSE;
4521 for (i = 0; window_sizes_list[i].value != -1; i++)
4523 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4524 char identifier[32], name[32];
4525 int value = window_sizes_list[i].value;
4526 char *text = window_sizes_list[i].text;
4528 ti->node_top = &window_sizes;
4529 ti->sort_priority = value;
4531 sprintf(identifier, "%d", value);
4532 sprintf(name, "%s", text);
4534 setString(&ti->identifier, identifier);
4535 setString(&ti->name, name);
4536 setString(&ti->name_sorting, name);
4537 setString(&ti->infotext, "Window Scaling");
4539 pushTreeInfo(&window_sizes, ti);
4541 if (value == setup.window_scaling_percent)
4542 current_window_size_found = TRUE;
4545 if (!current_window_size_found)
4547 // add entry for non-preset window scaling value
4549 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4550 char identifier[32], name[32];
4551 int value = setup.window_scaling_percent;
4553 ti->node_top = &window_sizes;
4554 ti->sort_priority = value;
4556 sprintf(identifier, "%d", value);
4557 sprintf(name, "%d %% (Current)", value);
4559 setString(&ti->identifier, identifier);
4560 setString(&ti->name, name);
4561 setString(&ti->name_sorting, name);
4562 setString(&ti->infotext, "Window Scaling");
4564 pushTreeInfo(&window_sizes, ti);
4567 /* sort window size values to start with lowest window size value */
4568 sortTreeInfo(&window_sizes);
4570 /* set current window size value to configured window size value */
4571 window_size_current =
4572 getTreeInfoFromIdentifier(window_sizes,
4573 i_to_a(setup.window_scaling_percent));
4575 /* if that fails, set current window size to reliable default value */
4576 if (window_size_current == NULL)
4577 window_size_current =
4578 getTreeInfoFromIdentifier(window_sizes,
4579 i_to_a(STD_WINDOW_SCALING_PERCENT));
4581 /* if that also fails, set current window size to first available value */
4582 if (window_size_current == NULL)
4583 window_size_current = window_sizes;
4586 setup.window_scaling_percent = atoi(window_size_current->identifier);
4588 /* needed for displaying window size text instead of identifier */
4589 window_size_text = window_size_current->name;
4592 static void execSetupGraphics_setScalingTypes()
4594 if (scaling_types == NULL)
4598 for (i = 0; scaling_types_list[i].value != NULL; i++)
4600 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4601 char identifier[32], name[32];
4602 char *value = scaling_types_list[i].value;
4603 char *text = scaling_types_list[i].text;
4605 ti->node_top = &scaling_types;
4606 ti->sort_priority = i;
4608 sprintf(identifier, "%s", value);
4609 sprintf(name, "%s", text);
4611 setString(&ti->identifier, identifier);
4612 setString(&ti->name, name);
4613 setString(&ti->name_sorting, name);
4614 setString(&ti->infotext, "Anti-Aliasing");
4616 pushTreeInfo(&scaling_types, ti);
4619 /* sort scaling type values to start with lowest scaling type value */
4620 sortTreeInfo(&scaling_types);
4622 /* set current scaling type value to configured scaling type value */
4623 scaling_type_current =
4624 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4626 /* if that fails, set current scaling type to reliable default value */
4627 if (scaling_type_current == NULL)
4628 scaling_type_current =
4629 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4631 /* if that also fails, set current scaling type to first available value */
4632 if (scaling_type_current == NULL)
4633 scaling_type_current = scaling_types;
4636 setup.window_scaling_quality = scaling_type_current->identifier;
4638 /* needed for displaying scaling type text instead of identifier */
4639 scaling_type_text = scaling_type_current->name;
4642 static void execSetupGraphics_setScreenModes()
4644 // if (screen_modes == NULL && video.fullscreen_available)
4645 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4649 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4651 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4652 char identifier[32], name[32];
4653 int x = video.fullscreen_modes[i].width;
4654 int y = video.fullscreen_modes[i].height;
4657 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4659 ti->node_top = &screen_modes;
4660 ti->sort_priority = x * 10000 + y;
4662 sprintf(identifier, "%dx%d", x, y);
4663 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4665 setString(&ti->identifier, identifier);
4666 setString(&ti->name, name);
4667 setString(&ti->name_sorting, name);
4668 setString(&ti->infotext, "Fullscreen Mode");
4670 pushTreeInfo(&screen_modes, ti);
4673 /* sort fullscreen modes to start with lowest available screen resolution */
4674 sortTreeInfo(&screen_modes);
4676 /* set current screen mode for fullscreen mode to configured setup value */
4677 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4678 setup.fullscreen_mode);
4680 /* if that fails, set current screen mode to reliable default value */
4681 if (screen_mode_current == NULL)
4682 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4683 DEFAULT_FULLSCREEN_MODE);
4685 /* if that also fails, set current screen mode to first available mode */
4686 if (screen_mode_current == NULL)
4687 screen_mode_current = screen_modes;
4689 if (screen_mode_current == NULL)
4690 video.fullscreen_available = FALSE;
4693 // if (video.fullscreen_available)
4694 if (screen_mode_current != NULL)
4696 setup.fullscreen_mode = screen_mode_current->identifier;
4698 /* needed for displaying screen mode name instead of identifier */
4699 screen_mode_text = screen_mode_current->name;
4703 static void execSetupGraphics()
4705 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4707 // update "setup.window_scaling_percent" from list selection
4708 execSetupGraphics_setWindowSizes(FALSE);
4712 // update list selection from "setup.window_scaling_percent"
4713 execSetupGraphics_setWindowSizes(TRUE);
4716 execSetupGraphics_setScalingTypes();
4717 execSetupGraphics_setScreenModes();
4719 setup_mode = SETUP_MODE_GRAPHICS;
4723 #if defined(TARGET_SDL2)
4724 // window scaling may have changed at this point
4725 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4727 // window scaling quality may have changed at this point
4728 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4729 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4733 #if !defined(PLATFORM_ANDROID)
4734 #if defined(TARGET_SDL2)
4735 static void execSetupChooseWindowSize()
4737 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4742 static void execSetupChooseScalingType()
4744 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4749 static void execSetupChooseScreenMode()
4751 if (!video.fullscreen_available)
4754 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4761 static void execSetupChooseVolumeSimple()
4763 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4768 static void execSetupChooseVolumeLoops()
4770 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4775 static void execSetupChooseVolumeMusic()
4777 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4782 static void execSetupSound()
4784 if (volumes_simple == NULL)
4786 boolean current_volume_simple_found = FALSE;
4789 for (i = 0; volumes_list[i].value != -1; i++)
4791 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4792 char identifier[32], name[32];
4793 int value = volumes_list[i].value;
4794 char *text = volumes_list[i].text;
4796 ti->node_top = &volumes_simple;
4797 ti->sort_priority = value;
4799 sprintf(identifier, "%d", value);
4800 sprintf(name, "%s", text);
4802 setString(&ti->identifier, identifier);
4803 setString(&ti->name, name);
4804 setString(&ti->name_sorting, name);
4805 setString(&ti->infotext, "Sound Volume");
4807 pushTreeInfo(&volumes_simple, ti);
4809 if (value == setup.volume_simple)
4810 current_volume_simple_found = TRUE;
4813 if (!current_volume_simple_found)
4815 // add entry for non-preset volume value
4817 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4818 char identifier[32], name[32];
4819 int value = setup.volume_simple;
4821 ti->node_top = &volumes_simple;
4822 ti->sort_priority = value;
4824 sprintf(identifier, "%d", value);
4825 sprintf(name, "%d %% (Current)", value);
4827 setString(&ti->identifier, identifier);
4828 setString(&ti->name, name);
4829 setString(&ti->name_sorting, name);
4830 setString(&ti->infotext, "Sound Volume");
4832 pushTreeInfo(&volumes_simple, ti);
4835 /* sort volume values to start with lowest volume value */
4836 sortTreeInfo(&volumes_simple);
4838 /* set current volume value to configured volume value */
4839 volume_simple_current =
4840 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4842 /* if that fails, set current volume to reliable default value */
4843 if (volume_simple_current == NULL)
4844 volume_simple_current =
4845 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4847 /* if that also fails, set current volume to first available value */
4848 if (volume_simple_current == NULL)
4849 volume_simple_current = volumes_simple;
4852 if (volumes_loops == NULL)
4854 boolean current_volume_loops_found = FALSE;
4857 for (i = 0; volumes_list[i].value != -1; i++)
4859 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4860 char identifier[32], name[32];
4861 int value = volumes_list[i].value;
4862 char *text = volumes_list[i].text;
4864 ti->node_top = &volumes_loops;
4865 ti->sort_priority = value;
4867 sprintf(identifier, "%d", value);
4868 sprintf(name, "%s", text);
4870 setString(&ti->identifier, identifier);
4871 setString(&ti->name, name);
4872 setString(&ti->name_sorting, name);
4873 setString(&ti->infotext, "Loops Volume");
4875 pushTreeInfo(&volumes_loops, ti);
4877 if (value == setup.volume_loops)
4878 current_volume_loops_found = TRUE;
4881 if (!current_volume_loops_found)
4883 // add entry for non-preset volume value
4885 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4886 char identifier[32], name[32];
4887 int value = setup.volume_loops;
4889 ti->node_top = &volumes_loops;
4890 ti->sort_priority = value;
4892 sprintf(identifier, "%d", value);
4893 sprintf(name, "%d %% (Current)", value);
4895 setString(&ti->identifier, identifier);
4896 setString(&ti->name, name);
4897 setString(&ti->name_sorting, name);
4898 setString(&ti->infotext, "Loops Volume");
4900 pushTreeInfo(&volumes_loops, ti);
4903 /* sort volume values to start with lowest volume value */
4904 sortTreeInfo(&volumes_loops);
4906 /* set current volume value to configured volume value */
4907 volume_loops_current =
4908 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4910 /* if that fails, set current volume to reliable default value */
4911 if (volume_loops_current == NULL)
4912 volume_loops_current =
4913 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4915 /* if that also fails, set current volume to first available value */
4916 if (volume_loops_current == NULL)
4917 volume_loops_current = volumes_loops;
4920 if (volumes_music == NULL)
4922 boolean current_volume_music_found = FALSE;
4925 for (i = 0; volumes_list[i].value != -1; i++)
4927 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4928 char identifier[32], name[32];
4929 int value = volumes_list[i].value;
4930 char *text = volumes_list[i].text;
4932 ti->node_top = &volumes_music;
4933 ti->sort_priority = value;
4935 sprintf(identifier, "%d", value);
4936 sprintf(name, "%s", text);
4938 setString(&ti->identifier, identifier);
4939 setString(&ti->name, name);
4940 setString(&ti->name_sorting, name);
4941 setString(&ti->infotext, "Music Volume");
4943 pushTreeInfo(&volumes_music, ti);
4945 if (value == setup.volume_music)
4946 current_volume_music_found = TRUE;
4949 if (!current_volume_music_found)
4951 // add entry for non-preset volume value
4953 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4954 char identifier[32], name[32];
4955 int value = setup.volume_music;
4957 ti->node_top = &volumes_music;
4958 ti->sort_priority = value;
4960 sprintf(identifier, "%d", value);
4961 sprintf(name, "%d %% (Current)", value);
4963 setString(&ti->identifier, identifier);
4964 setString(&ti->name, name);
4965 setString(&ti->name_sorting, name);
4966 setString(&ti->infotext, "Music Volume");
4968 pushTreeInfo(&volumes_music, ti);
4971 /* sort volume values to start with lowest volume value */
4972 sortTreeInfo(&volumes_music);
4974 /* set current volume value to configured volume value */
4975 volume_music_current =
4976 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4978 /* if that fails, set current volume to reliable default value */
4979 if (volume_music_current == NULL)
4980 volume_music_current =
4981 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4983 /* if that also fails, set current volume to first available value */
4984 if (volume_music_current == NULL)
4985 volume_music_current = volumes_music;
4988 setup.volume_simple = atoi(volume_simple_current->identifier);
4989 setup.volume_loops = atoi(volume_loops_current->identifier);
4990 setup.volume_music = atoi(volume_music_current->identifier);
4992 /* needed for displaying volume text instead of identifier */
4993 volume_simple_text = volume_simple_current->name;
4994 volume_loops_text = volume_loops_current->name;
4995 volume_music_text = volume_music_current->name;
4997 setup_mode = SETUP_MODE_SOUND;
5002 static void execSetupChooseTouchControls()
5004 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5009 static void execSetupChooseMoveDistance()
5011 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5016 static void execSetupChooseDropDistance()
5018 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5023 static void execSetupTouch()
5025 if (touch_controls == NULL)
5029 for (i = 0; touch_controls_list[i].value != NULL; i++)
5031 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5032 char identifier[32], name[32];
5033 char *value = touch_controls_list[i].value;
5034 char *text = touch_controls_list[i].text;
5036 ti->node_top = &touch_controls;
5037 ti->sort_priority = i;
5039 sprintf(identifier, "%s", value);
5040 sprintf(name, "%s", text);
5042 setString(&ti->identifier, identifier);
5043 setString(&ti->name, name);
5044 setString(&ti->name_sorting, name);
5045 setString(&ti->infotext, "Control Type");
5047 pushTreeInfo(&touch_controls, ti);
5050 /* sort touch control values to start with lowest touch control value */
5051 sortTreeInfo(&touch_controls);
5053 /* set current touch control value to configured touch control value */
5054 touch_control_current =
5055 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5057 /* if that fails, set current touch control to reliable default value */
5058 if (touch_control_current == NULL)
5059 touch_control_current =
5060 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5062 /* if that also fails, set current touch control to first available value */
5063 if (touch_control_current == NULL)
5064 touch_control_current = touch_controls;
5067 if (move_distances == NULL)
5071 for (i = 0; distances_list[i].value != -1; i++)
5073 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5074 char identifier[32], name[32];
5075 int value = distances_list[i].value;
5076 char *text = distances_list[i].text;
5078 ti->node_top = &move_distances;
5079 ti->sort_priority = value;
5081 sprintf(identifier, "%d", value);
5082 sprintf(name, "%s", text);
5084 setString(&ti->identifier, identifier);
5085 setString(&ti->name, name);
5086 setString(&ti->name_sorting, name);
5087 setString(&ti->infotext, "Move Distance");
5089 pushTreeInfo(&move_distances, ti);
5092 /* sort distance values to start with lowest distance value */
5093 sortTreeInfo(&move_distances);
5095 /* set current distance value to configured distance value */
5096 move_distance_current =
5097 getTreeInfoFromIdentifier(move_distances,
5098 i_to_a(setup.touch.move_distance));
5100 /* if that fails, set current distance to reliable default value */
5101 if (move_distance_current == NULL)
5102 move_distance_current =
5103 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5105 /* if that also fails, set current distance to first available value */
5106 if (move_distance_current == NULL)
5107 move_distance_current = move_distances;
5110 if (drop_distances == NULL)
5114 for (i = 0; distances_list[i].value != -1; i++)
5116 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5117 char identifier[32], name[32];
5118 int value = distances_list[i].value;
5119 char *text = distances_list[i].text;
5121 ti->node_top = &drop_distances;
5122 ti->sort_priority = value;
5124 sprintf(identifier, "%d", value);
5125 sprintf(name, "%s", text);
5127 setString(&ti->identifier, identifier);
5128 setString(&ti->name, name);
5129 setString(&ti->name_sorting, name);
5130 setString(&ti->infotext, "Drop Distance");
5132 pushTreeInfo(&drop_distances, ti);
5135 /* sort distance values to start with lowest distance value */
5136 sortTreeInfo(&drop_distances);
5138 /* set current distance value to configured distance value */
5139 drop_distance_current =
5140 getTreeInfoFromIdentifier(drop_distances,
5141 i_to_a(setup.touch.drop_distance));
5143 /* if that fails, set current distance to reliable default value */
5144 if (drop_distance_current == NULL)
5145 drop_distance_current =
5146 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5148 /* if that also fails, set current distance to first available value */
5149 if (drop_distance_current == NULL)
5150 drop_distance_current = drop_distances;
5153 setup.touch.control_type = touch_control_current->identifier;
5154 setup.touch.move_distance = atoi(move_distance_current->identifier);
5155 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5157 /* needed for displaying volume text instead of identifier */
5158 touch_controls_text = touch_control_current->name;
5159 move_distance_text = move_distance_current->name;
5160 drop_distance_text = drop_distance_current->name;
5162 setup_mode = SETUP_MODE_TOUCH;
5167 static void execSetupArtwork()
5170 printf("::: '%s', '%s', '%s'\n",
5171 artwork.gfx_current->subdir,
5172 artwork.gfx_current->fullpath,
5173 artwork.gfx_current->basepath);
5176 setup.graphics_set = artwork.gfx_current->identifier;
5177 setup.sounds_set = artwork.snd_current->identifier;
5178 setup.music_set = artwork.mus_current->identifier;
5180 /* needed if last screen (setup choice) changed graphics, sounds or music */
5181 ReloadCustomArtwork(0);
5183 /* needed for displaying artwork name instead of artwork identifier */
5184 graphics_set_name = artwork.gfx_current->name;
5185 sounds_set_name = artwork.snd_current->name;
5186 music_set_name = artwork.mus_current->name;
5188 setup_mode = SETUP_MODE_ARTWORK;
5193 static void execSetupChooseGraphics()
5195 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5200 static void execSetupChooseSounds()
5202 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5207 static void execSetupChooseMusic()
5209 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5214 #if !defined(PLATFORM_ANDROID)
5215 static void execSetupInput()
5217 setup_mode = SETUP_MODE_INPUT;
5223 static void execSetupShortcuts()
5225 setup_mode = SETUP_MODE_SHORTCUTS;
5230 static void execSetupShortcuts1()
5232 setup_mode = SETUP_MODE_SHORTCUTS_1;
5237 static void execSetupShortcuts2()
5239 setup_mode = SETUP_MODE_SHORTCUTS_2;
5244 static void execSetupShortcuts3()
5246 setup_mode = SETUP_MODE_SHORTCUTS_3;
5251 static void execSetupShortcuts4()
5253 setup_mode = SETUP_MODE_SHORTCUTS_4;
5258 static void execSetupShortcuts5()
5260 setup_mode = SETUP_MODE_SHORTCUTS_5;
5265 static void execExitSetup()
5267 game_status = GAME_MODE_MAIN;
5272 static void execSaveAndExitSetup()
5278 static struct TokenInfo setup_info_main[] =
5280 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5281 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5282 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5283 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5284 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5285 #if !defined(PLATFORM_ANDROID)
5286 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5287 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5289 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5291 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5292 { TYPE_EMPTY, NULL, "" },
5293 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5294 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5299 static struct TokenInfo setup_info_game[] =
5301 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5302 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5303 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5304 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5305 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5306 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5307 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5308 { TYPE_STRING, &game_speed_text, "" },
5310 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5311 { TYPE_STRING, &scroll_delay_text, "" },
5313 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5314 { TYPE_STRING, &snapshot_mode_text, "" },
5315 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5316 { TYPE_EMPTY, NULL, "" },
5317 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5322 static struct TokenInfo setup_info_editor[] =
5325 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5326 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5327 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5328 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5329 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5330 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5331 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5332 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5334 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5335 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5336 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5338 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5340 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5341 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5342 { TYPE_EMPTY, NULL, "" },
5344 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5345 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5346 { TYPE_EMPTY, NULL, "" },
5348 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5349 { TYPE_EMPTY, NULL, "" },
5350 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5355 static struct TokenInfo setup_info_graphics[] =
5357 #if !defined(PLATFORM_ANDROID)
5358 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5359 #if defined(TARGET_SDL2)
5360 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5361 { TYPE_STRING, &window_size_text, "" },
5362 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5363 { TYPE_STRING, &scaling_type_text, "" },
5365 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5366 { TYPE_STRING, &screen_mode_text, "" },
5370 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5371 { TYPE_STRING, &scroll_delay_text, "" },
5373 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5374 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5375 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5376 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5377 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5378 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5379 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5380 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5381 { TYPE_EMPTY, NULL, "" },
5382 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5387 static struct TokenInfo setup_info_sound[] =
5389 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5390 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5391 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5392 { TYPE_EMPTY, NULL, "" },
5393 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5394 { TYPE_STRING, &volume_simple_text, "" },
5395 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5396 { TYPE_STRING, &volume_loops_text, "" },
5397 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5398 { TYPE_STRING, &volume_music_text, "" },
5399 { TYPE_EMPTY, NULL, "" },
5400 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5405 static struct TokenInfo setup_info_artwork[] =
5407 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5408 { TYPE_STRING, &graphics_set_name, "" },
5409 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5410 { TYPE_STRING, &sounds_set_name, "" },
5411 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5412 { TYPE_STRING, &music_set_name, "" },
5413 { TYPE_EMPTY, NULL, "" },
5414 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5415 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5416 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5417 { TYPE_EMPTY, NULL, "" },
5418 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5423 static struct TokenInfo setup_info_input[] =
5425 { TYPE_SWITCH, NULL, "Player:" },
5426 { TYPE_SWITCH, NULL, "Device:" },
5427 { TYPE_ENTER_MENU, NULL, "" },
5428 { TYPE_EMPTY, NULL, "" },
5429 { TYPE_EMPTY, NULL, "" },
5430 { TYPE_EMPTY, NULL, "" },
5431 { TYPE_EMPTY, NULL, "" },
5432 { TYPE_EMPTY, NULL, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_EMPTY, NULL, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_EMPTY, NULL, "" },
5437 { TYPE_EMPTY, NULL, "" },
5438 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5443 static struct TokenInfo setup_info_touch[] =
5445 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5446 { TYPE_STRING, &touch_controls_text, "" },
5447 { TYPE_EMPTY, NULL, "" },
5448 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5449 { TYPE_STRING, &move_distance_text, "" },
5450 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5451 { TYPE_STRING, &drop_distance_text, "" },
5452 { TYPE_EMPTY, NULL, "" },
5453 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5458 static struct TokenInfo setup_info_shortcuts[] =
5460 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5461 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5462 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5463 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5464 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5465 { TYPE_EMPTY, NULL, "" },
5466 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5471 static struct TokenInfo setup_info_shortcuts_1[] =
5473 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5474 { TYPE_KEY, &setup.shortcut.save_game, "" },
5475 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5476 { TYPE_KEY, &setup.shortcut.load_game, "" },
5477 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5478 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5479 { TYPE_EMPTY, NULL, "" },
5480 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5481 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5482 { TYPE_EMPTY, NULL, "" },
5483 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5488 static struct TokenInfo setup_info_shortcuts_2[] =
5490 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5491 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5492 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5493 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5494 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5495 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5496 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5497 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5498 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5499 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5500 { TYPE_EMPTY, NULL, "" },
5501 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5506 static struct TokenInfo setup_info_shortcuts_3[] =
5508 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5509 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5510 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5511 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5512 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5513 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5514 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5515 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5516 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5517 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5518 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5519 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5520 { TYPE_EMPTY, NULL, "" },
5521 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5526 static struct TokenInfo setup_info_shortcuts_4[] =
5528 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5529 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5530 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5531 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5532 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5533 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5534 { TYPE_EMPTY, NULL, "" },
5535 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5540 static struct TokenInfo setup_info_shortcuts_5[] =
5542 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5543 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5544 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5545 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5546 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5547 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5548 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5549 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5550 { TYPE_EMPTY, NULL, "" },
5551 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5556 static Key getSetupKey()
5558 Key key = KSYM_UNDEFINED;
5559 boolean got_key_event = FALSE;
5561 while (!got_key_event)
5563 if (PendingEvent()) /* got event */
5571 case EVENT_KEYPRESS:
5573 key = GetEventKey((KeyEvent *)&event, TRUE);
5575 /* press 'Escape' or 'Enter' to keep the existing key binding */
5576 if (key == KSYM_Escape || key == KSYM_Return)
5577 key = KSYM_UNDEFINED; /* keep old value */
5579 got_key_event = TRUE;
5583 case EVENT_KEYRELEASE:
5584 key_joystick_mapping = 0;
5588 HandleOtherEvents(&event);
5596 /* don't eat all CPU time */
5603 static int getSetupValueFont(int type, void *value)
5605 if (type & TYPE_KEY)
5606 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5607 else if (type & TYPE_STRING)
5608 return FONT_VALUE_2;
5609 else if (type & TYPE_ECS_AGA)
5610 return FONT_VALUE_1;
5611 else if (type & TYPE_BOOLEAN_STYLE)
5612 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5613 else if (type & TYPE_YES_NO_AUTO)
5614 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5615 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5617 return FONT_VALUE_1;
5620 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5622 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5623 struct TokenInfo *si = &setup_info[si_pos];
5624 boolean font_draw_xoffset_modified = FALSE;
5625 int font_draw_xoffset_old = -1;
5626 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5627 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5628 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5629 int xpos = menu_screen_value_xpos;
5630 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5631 int startx = mSX + xpos * 32;
5632 int starty = mSY + ypos * 32;
5633 int font_nr, font_width;
5634 int type = si->type;
5635 void *value = si->value;
5636 char *value_string = getSetupValue(type, value);
5639 if (value_string == NULL)
5642 if (type & TYPE_KEY)
5644 xpos = MENU_SCREEN_START_XPOS;
5646 if (type & TYPE_QUERY)
5647 value_string = "<press key>";
5649 else if (type & TYPE_STRING)
5651 int max_value_len = (SCR_FIELDX - 2) * 2;
5653 xpos = MENU_SCREEN_START_XPOS;
5655 if (strlen(value_string) > max_value_len)
5656 value_string[max_value_len] = '\0';
5658 else if (type & TYPE_YES_NO_AUTO)
5660 xpos = menu_screen_value_xpos - 1;
5663 startx = mSX + xpos * 32;
5664 starty = mSY + ypos * 32;
5665 font_nr = getSetupValueFont(type, value);
5666 font_width = getFontWidth(font_nr);
5668 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5669 if (setup_mode != SETUP_MODE_INPUT)
5671 int max_menu_text_length_big = (menu_screen_value_xpos -
5672 MENU_SCREEN_START_XPOS);
5673 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5674 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5675 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5676 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5677 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5678 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5679 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5680 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5681 boolean correct_font_draw_xoffset = FALSE;
5683 if (xpos == MENU_SCREEN_START_XPOS &&
5684 startx + font1_xoffset < text_startx + text_font_xoffset)
5685 correct_font_draw_xoffset = TRUE;
5687 if (xpos == menu_screen_value_xpos &&
5688 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5689 correct_font_draw_xoffset = TRUE;
5691 /* check if setup value would overlap with setup text when printed */
5692 /* (this can happen for extreme/wrong values for font draw offset) */
5693 if (correct_font_draw_xoffset)
5695 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5696 font_draw_xoffset_modified = TRUE;
5698 if (type & TYPE_KEY)
5699 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5700 else if (!(type & TYPE_STRING))
5701 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5702 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5706 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5707 DrawText(startx + i * font_width, starty, " ", font_nr);
5709 DrawText(startx, starty, value_string, font_nr);
5711 if (font_draw_xoffset_modified)
5712 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5715 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5717 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5718 struct TokenInfo *si = &setup_info[si_pos];
5720 if (si->type & TYPE_BOOLEAN_STYLE)
5722 *(boolean *)si->value ^= TRUE;
5724 else if (si->type & TYPE_YES_NO_AUTO)
5728 (*(int *)si->value == AUTO ? TRUE :
5729 *(int *)si->value == TRUE ? FALSE : AUTO) :
5730 (*(int *)si->value == TRUE ? AUTO :
5731 *(int *)si->value == AUTO ? FALSE : TRUE));
5733 else if (si->type & TYPE_KEY)
5737 si->type |= TYPE_QUERY;
5738 drawSetupValue(screen_pos, setup_info_pos_raw);
5739 si->type &= ~TYPE_QUERY;
5741 key = getSetupKey();
5742 if (key != KSYM_UNDEFINED)
5743 *(Key *)si->value = key;
5746 drawSetupValue(screen_pos, setup_info_pos_raw);
5748 // fullscreen state may have changed at this point
5749 if (si->value == &setup.fullscreen)
5750 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5753 static void DrawSetupScreen_Generic()
5755 int fade_mask = REDRAW_FIELD;
5756 boolean redraw_all = FALSE;
5757 char *title_string = NULL;
5760 if (CheckIfGlobalBorderHasChanged())
5761 fade_mask = REDRAW_ALL;
5765 FreeScreenGadgets();
5766 CreateScreenGadgets();
5768 CloseDoor(DOOR_CLOSE_2);
5770 if (redraw_mask & REDRAW_ALL)
5775 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5779 if (setup_mode == SETUP_MODE_MAIN)
5781 setup_info = setup_info_main;
5782 title_string = "Setup";
5784 else if (setup_mode == SETUP_MODE_GAME)
5786 setup_info = setup_info_game;
5787 title_string = "Setup Game";
5789 else if (setup_mode == SETUP_MODE_EDITOR)
5791 setup_info = setup_info_editor;
5792 title_string = "Setup Editor";
5794 else if (setup_mode == SETUP_MODE_GRAPHICS)
5796 setup_info = setup_info_graphics;
5797 title_string = "Setup Graphics";
5799 else if (setup_mode == SETUP_MODE_SOUND)
5801 setup_info = setup_info_sound;
5802 title_string = "Setup Sound";
5804 else if (setup_mode == SETUP_MODE_ARTWORK)
5806 setup_info = setup_info_artwork;
5807 title_string = "Custom Artwork";
5809 else if (setup_mode == SETUP_MODE_TOUCH)
5811 setup_info = setup_info_touch;
5812 title_string = "Setup Touch Ctrls";
5814 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5816 setup_info = setup_info_shortcuts;
5817 title_string = "Setup Shortcuts";
5819 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5821 setup_info = setup_info_shortcuts_1;
5822 title_string = "Setup Shortcuts";
5824 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5826 setup_info = setup_info_shortcuts_2;
5827 title_string = "Setup Shortcuts";
5829 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5831 setup_info = setup_info_shortcuts_3;
5832 title_string = "Setup Shortcuts";
5834 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5836 setup_info = setup_info_shortcuts_4;
5837 title_string = "Setup Shortcuts";
5839 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5841 setup_info = setup_info_shortcuts_5;
5842 title_string = "Setup Shortcuts";
5845 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5847 // determine maximal number of setup entries that can be displayed on screen
5849 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5852 // determine maximal number of setup entries available for this setup screen
5854 for (i = 0; setup_info[i].type != 0; i++)
5857 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5859 MapScreenGadgets(max_setup_info);
5862 redraw_mask = fade_mask = REDRAW_ALL;
5864 DrawMaskedBorder(fade_mask);
5871 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5873 menu_info = setup_info;
5875 HandleMenuScreen(mx, my, dx, dy, button,
5876 setup_mode, num_setup_info, max_setup_info);
5879 void DrawSetupScreen_Input()
5883 FadeOut(REDRAW_FIELD);
5887 setup_info = setup_info_input;
5889 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5891 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5892 "Joysticks deactivated on this screen");
5894 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5896 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5897 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5898 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5899 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5900 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5901 initCursor(i, IMG_MENU_BUTTON);
5903 DrawCursorAndText_Setup(i, -1, FALSE);
5906 /* create gadgets for setup input menu screen */
5907 FreeScreenGadgets();
5908 CreateScreenGadgets();
5910 /* map gadgets for setup input menu screen */
5911 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5913 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5915 FadeIn(REDRAW_FIELD);
5920 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5922 if (device_name == NULL)
5925 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5928 if (strlen(device_name) > 1)
5930 char c1 = device_name[strlen(device_name) - 1];
5931 char c2 = device_name[strlen(device_name) - 2];
5933 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5934 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5937 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5938 strlen(device_name));
5941 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5944 static struct SetupKeyboardInfo custom_key;
5951 { &custom_key.left, "Joystick Left" },
5952 { &custom_key.right, "Joystick Right" },
5953 { &custom_key.up, "Joystick Up" },
5954 { &custom_key.down, "Joystick Down" },
5955 { &custom_key.snap, "Button 1" },
5956 { &custom_key.drop, "Button 2" }
5958 static char *joystick_name[MAX_PLAYERS] =
5965 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5969 custom_key = setup.input[player_nr].key;
5971 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5972 FONT_INPUT_1_ACTIVE);
5974 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5976 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5977 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5979 if (setup.input[player_nr].use_joystick)
5981 char *device_name = setup.input[player_nr].joy.device_name;
5982 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5983 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5985 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5986 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5990 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5991 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5994 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5996 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5997 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5998 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5999 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6001 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6002 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6003 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6004 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6005 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6006 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6008 for (i = 0; i < 6; i++)
6010 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6012 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6014 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6015 (setup.input[player_nr].use_joystick ?
6017 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6021 static int input_player_nr = 0;
6023 void HandleSetupScreen_Input_Player(int step, int direction)
6025 int old_player_nr = input_player_nr;
6028 new_player_nr = old_player_nr + step * direction;
6029 if (new_player_nr < 0)
6031 if (new_player_nr > MAX_PLAYERS - 1)
6032 new_player_nr = MAX_PLAYERS - 1;
6034 if (new_player_nr != old_player_nr)
6036 input_player_nr = new_player_nr;
6038 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6042 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6044 static int choice = 0;
6047 int pos_start = SETUPINPUT_SCREEN_POS_START;
6048 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6049 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6050 int pos_end = SETUPINPUT_SCREEN_POS_END;
6052 if (button == MB_MENU_INITIALIZE)
6054 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6056 DrawCursorAndText_Setup(choice, -1, TRUE);
6060 else if (button == MB_MENU_LEAVE)
6062 setup_mode = SETUP_MODE_MAIN;
6069 if (mx || my) /* mouse input */
6071 x = (mx - mSX) / 32;
6072 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6074 else if (dx || dy) /* keyboard input */
6076 if (dx && choice == 0)
6077 x = (dx < 0 ? 10 : 12);
6078 else if ((dx && choice == 1) ||
6079 (dx == +1 && choice == 2) ||
6080 (dx == -1 && choice == pos_end))
6081 button = MB_MENU_CHOICE;
6085 if (y >= pos_empty1 && y <= pos_empty2)
6086 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6089 if (y == 0 && dx != 0 && button)
6091 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6093 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6094 y >= pos_start && y <= pos_end &&
6095 !(y >= pos_empty1 && y <= pos_empty2))
6101 DrawCursorAndText_Setup(choice, -1, FALSE);
6102 DrawCursorAndText_Setup(y, -1, TRUE);
6104 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6113 char *device_name = setup.input[input_player_nr].joy.device_name;
6115 if (!setup.input[input_player_nr].use_joystick)
6117 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6119 setJoystickDeviceToNr(device_name, new_device_nr);
6120 setup.input[input_player_nr].use_joystick = TRUE;
6124 int device_nr = getJoystickNrFromDeviceName(device_name);
6125 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6127 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6128 setup.input[input_player_nr].use_joystick = FALSE;
6130 setJoystickDeviceToNr(device_name, new_device_nr);
6133 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6137 if (setup.input[input_player_nr].use_joystick)
6140 CalibrateJoystick(input_player_nr);
6143 CustomizeKeyboard(input_player_nr);
6145 else if (y == pos_end)
6151 setup_mode = SETUP_MODE_MAIN;
6158 void CustomizeKeyboard(int player_nr)
6162 boolean finished = FALSE;
6163 static struct SetupKeyboardInfo custom_key;
6168 } customize_step[] =
6170 { &custom_key.left, "Move Left" },
6171 { &custom_key.right, "Move Right" },
6172 { &custom_key.up, "Move Up" },
6173 { &custom_key.down, "Move Down" },
6174 { &custom_key.snap, "Snap Field" },
6175 { &custom_key.drop, "Drop Element" }
6178 /* read existing key bindings from player setup */
6179 custom_key = setup.input[player_nr].key;
6182 FadeOut(REDRAW_FIELD);
6186 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6189 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6190 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6191 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6192 "Key:", FONT_INPUT_1_ACTIVE);
6193 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6194 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6196 FadeIn(REDRAW_FIELD);
6202 if (PendingEvent()) /* got event */
6210 case EVENT_KEYPRESS:
6212 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6214 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6216 if (key == KSYM_Escape)
6217 FadeSkipNextFadeIn();
6223 /* all keys configured -- wait for "Escape" or "Return" key */
6227 /* press 'Enter' to keep the existing key binding */
6228 if (key == KSYM_Return)
6229 key = *customize_step[step_nr].key;
6231 /* check if key already used */
6232 for (i = 0; i < step_nr; i++)
6233 if (*customize_step[i].key == key)
6238 /* got new key binding */
6239 *customize_step[step_nr].key = key;
6240 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6242 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6243 getKeyNameFromKey(key), FONT_VALUE_1);
6246 /* un-highlight last query */
6247 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6248 customize_step[step_nr - 1].text, FONT_MENU_1);
6249 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6250 "Key:", FONT_MENU_1);
6252 /* press 'Enter' to leave */
6255 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6256 "Press Enter", FONT_TITLE_1);
6260 /* query next key binding */
6261 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6262 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6263 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6264 "Key:", FONT_INPUT_1_ACTIVE);
6265 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6266 getKeyNameFromKey(*customize_step[step_nr].key),
6271 case EVENT_KEYRELEASE:
6272 key_joystick_mapping = 0;
6276 HandleOtherEvents(&event);
6284 /* don't eat all CPU time */
6288 /* write new key bindings back to player setup */
6289 setup.input[player_nr].key = custom_key;
6292 DrawSetupScreen_Input();
6295 static boolean CalibrateJoystickMain(int player_nr)
6297 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6298 int new_joystick_xright = JOYSTICK_XMIDDLE;
6299 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6300 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6301 int new_joystick_xmiddle, new_joystick_ymiddle;
6303 int joystick_fd = joystick.fd[player_nr];
6304 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6305 boolean check[3][3];
6306 int check_remaining = 3 * 3;
6311 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6314 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6318 FadeOut(REDRAW_FIELD);
6322 for (y = 0; y < 3; y++)
6324 for (x = 0; x < 3; x++)
6326 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6327 check[x][y] = FALSE;
6331 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6332 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6333 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6334 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6335 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6336 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6337 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6339 joy_value = Joystick(player_nr);
6340 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6341 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6343 /* eventually uncalibrated center position (joystick could be uncentered) */
6344 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6347 new_joystick_xmiddle = joy_x;
6348 new_joystick_ymiddle = joy_y;
6350 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6352 FadeIn(REDRAW_FIELD);
6354 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6359 if (PendingEvent()) /* got event */
6367 case EVENT_KEYPRESS:
6368 switch (GetEventKey((KeyEvent *)&event, TRUE))
6371 if (check_remaining == 0)
6376 FadeSkipNextFadeIn();
6385 case EVENT_KEYRELEASE:
6386 key_joystick_mapping = 0;
6390 HandleOtherEvents(&event);
6395 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6398 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6399 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6400 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6401 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6403 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6404 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6405 setup.input[player_nr].joy.xright = new_joystick_xright;
6406 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6407 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6408 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6410 CheckJoystickData();
6412 joy_value = Joystick(player_nr);
6414 if (joy_value & JOY_BUTTON && check_remaining == 0)
6417 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6418 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6420 if (x != last_x || y != last_y)
6422 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6423 IMG_MENU_CALIBRATE_YELLOW, 0);
6424 DrawFixedGraphic(xpos + x, ypos + y,
6425 IMG_MENU_CALIBRATE_RED, 0);
6430 if (check_remaining > 0 && !check[x+1][y+1])
6432 check[x+1][y+1] = TRUE;
6440 /* don't eat all CPU time */
6444 /* calibrated center position (joystick should now be centered) */
6445 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6448 new_joystick_xmiddle = joy_x;
6449 new_joystick_ymiddle = joy_y;
6453 /* wait until the last pressed button was released */
6454 while (Joystick(player_nr) & JOY_BUTTON)
6456 if (PendingEvent()) /* got event */
6461 HandleOtherEvents(&event);
6470 void CalibrateJoystick(int player_nr)
6472 if (!CalibrateJoystickMain(player_nr))
6474 char *device_name = setup.input[player_nr].joy.device_name;
6475 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6476 int xpos = mSX - SX;
6477 int ypos = mSY - SY;
6481 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6482 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6485 Delay(2000); /* show error message for a short time */
6490 DrawSetupScreen_Input();
6493 void DrawSetupScreen()
6495 DeactivateJoystick();
6497 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6499 if (setup_mode == SETUP_MODE_INPUT)
6500 DrawSetupScreen_Input();
6501 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6502 DrawChooseTree(&game_speed_current);
6503 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6504 DrawChooseTree(&scroll_delay_current);
6505 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6506 DrawChooseTree(&snapshot_mode_current);
6507 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6508 DrawChooseTree(&screen_mode_current);
6509 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6510 DrawChooseTree(&window_size_current);
6511 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6512 DrawChooseTree(&scaling_type_current);
6513 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6514 DrawChooseTree(&artwork.gfx_current);
6515 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6516 DrawChooseTree(&artwork.snd_current);
6517 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6518 DrawChooseTree(&artwork.mus_current);
6519 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6520 DrawChooseTree(&volume_simple_current);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6522 DrawChooseTree(&volume_loops_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6524 DrawChooseTree(&volume_music_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6526 DrawChooseTree(&touch_control_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6528 DrawChooseTree(&move_distance_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6530 DrawChooseTree(&drop_distance_current);
6532 DrawSetupScreen_Generic();
6538 void RedrawSetupScreenAfterFullscreenToggle()
6540 if (setup_mode == SETUP_MODE_GRAPHICS ||
6541 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6543 // update list selection from "setup.window_scaling_percent"
6544 execSetupGraphics_setWindowSizes(TRUE);
6550 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6552 if (setup_mode == SETUP_MODE_INPUT)
6553 HandleSetupScreen_Input(mx, my, dx, dy, button);
6554 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6555 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6556 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6557 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6558 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6559 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6560 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6561 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6562 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6563 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6564 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6565 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6566 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6567 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6568 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6569 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6570 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6571 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6573 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6575 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6577 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6579 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6581 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6582 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6583 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6585 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6588 void HandleGameActions()
6590 if (game_status != GAME_MODE_PLAYING)
6593 GameActions(); /* main game loop */
6595 if (tape.auto_play && !tape.playing)
6596 AutoPlayTape(); /* continue automatically playing next tape */
6600 /* ---------- new screen button stuff -------------------------------------- */
6602 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6606 case SCREEN_CTRL_ID_PREV_LEVEL:
6607 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6608 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6611 case SCREEN_CTRL_ID_NEXT_LEVEL:
6612 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6613 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6616 case SCREEN_CTRL_ID_PREV_PLAYER:
6617 *x = mSX + TILEX * 10;
6618 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6621 case SCREEN_CTRL_ID_NEXT_PLAYER:
6622 *x = mSX + TILEX * 12;
6623 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6627 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6633 int gfx_unpressed, gfx_pressed;
6634 void (*get_gadget_position)(int *, int *, int);
6638 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6641 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6642 getScreenMenuButtonPos,
6643 SCREEN_CTRL_ID_PREV_LEVEL,
6648 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6649 getScreenMenuButtonPos,
6650 SCREEN_CTRL_ID_NEXT_LEVEL,
6655 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6656 getScreenMenuButtonPos,
6657 SCREEN_CTRL_ID_PREV_PLAYER,
6662 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6663 getScreenMenuButtonPos,
6664 SCREEN_CTRL_ID_NEXT_PLAYER,
6672 int gfx_unpressed, gfx_pressed;
6676 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6679 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6680 -1, -1, /* these values are not constant, but can change at runtime */
6681 SCREEN_CTRL_ID_SCROLL_UP,
6685 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6686 -1, -1, /* these values are not constant, but can change at runtime */
6687 SCREEN_CTRL_ID_SCROLL_DOWN,
6694 int gfx_unpressed, gfx_pressed;
6700 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6703 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6704 -1, -1, /* these values are not constant, but can change at runtime */
6705 -1, -1, /* these values are not constant, but can change at runtime */
6706 GD_TYPE_SCROLLBAR_VERTICAL,
6707 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6708 "scroll level series vertically"
6712 static void CreateScreenMenubuttons()
6714 struct GadgetInfo *gi;
6715 unsigned int event_mask;
6718 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6720 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6721 int gfx_unpressed, gfx_pressed;
6722 int x, y, width, height;
6723 int gd_x1, gd_x2, gd_y1, gd_y2;
6724 int id = menubutton_info[i].gadget_id;
6726 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6728 menubutton_info[i].get_gadget_position(&x, &y, id);
6730 width = SC_MENUBUTTON_XSIZE;
6731 height = SC_MENUBUTTON_YSIZE;
6733 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6734 gfx_pressed = menubutton_info[i].gfx_pressed;
6735 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6736 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6737 gd_x1 = graphic_info[gfx_unpressed].src_x;
6738 gd_y1 = graphic_info[gfx_unpressed].src_y;
6739 gd_x2 = graphic_info[gfx_pressed].src_x;
6740 gd_y2 = graphic_info[gfx_pressed].src_y;
6742 gi = CreateGadget(GDI_CUSTOM_ID, id,
6743 GDI_CUSTOM_TYPE_ID, i,
6744 GDI_INFO_TEXT, menubutton_info[i].infotext,
6749 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6750 GDI_STATE, GD_BUTTON_UNPRESSED,
6751 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6752 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6753 GDI_DIRECT_DRAW, FALSE,
6754 GDI_EVENT_MASK, event_mask,
6755 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6759 Error(ERR_EXIT, "cannot create gadget");
6761 screen_gadget[id] = gi;
6765 static void CreateScreenScrollbuttons()
6767 struct GadgetInfo *gi;
6768 unsigned int event_mask;
6771 /* these values are not constant, but can change at runtime */
6772 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6773 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6774 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6775 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6777 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6779 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6780 int gfx_unpressed, gfx_pressed;
6781 int x, y, width, height;
6782 int gd_x1, gd_x2, gd_y1, gd_y2;
6783 int id = scrollbutton_info[i].gadget_id;
6785 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6787 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6788 y = mSY + scrollbutton_info[i].y;
6789 width = SC_SCROLLBUTTON_XSIZE;
6790 height = SC_SCROLLBUTTON_YSIZE;
6792 /* correct scrollbar position if placed outside menu (playfield) area */
6793 if (x > SX + SC_SCROLL_UP_XPOS)
6794 x = SX + SC_SCROLL_UP_XPOS;
6796 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6797 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6798 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6800 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6801 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6802 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6803 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6804 gd_x1 = graphic_info[gfx_unpressed].src_x;
6805 gd_y1 = graphic_info[gfx_unpressed].src_y;
6806 gd_x2 = graphic_info[gfx_pressed].src_x;
6807 gd_y2 = graphic_info[gfx_pressed].src_y;
6809 gi = CreateGadget(GDI_CUSTOM_ID, id,
6810 GDI_CUSTOM_TYPE_ID, i,
6811 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6816 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6817 GDI_STATE, GD_BUTTON_UNPRESSED,
6818 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6819 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6820 GDI_DIRECT_DRAW, FALSE,
6821 GDI_EVENT_MASK, event_mask,
6822 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6826 Error(ERR_EXIT, "cannot create gadget");
6828 screen_gadget[id] = gi;
6832 static void CreateScreenScrollbars()
6836 /* these values are not constant, but can change at runtime */
6837 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6838 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6839 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6840 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6842 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6844 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6845 int gfx_unpressed, gfx_pressed;
6846 int x, y, width, height;
6847 int gd_x1, gd_x2, gd_y1, gd_y2;
6848 struct GadgetInfo *gi;
6849 int items_max, items_visible, item_position;
6850 unsigned int event_mask;
6851 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6852 int id = scrollbar_info[i].gadget_id;
6854 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6856 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6857 y = mSY + scrollbar_info[i].y;
6858 width = scrollbar_info[i].width;
6859 height = scrollbar_info[i].height;
6861 /* correct scrollbar position if placed outside menu (playfield) area */
6862 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6863 x = SX + SC_SCROLL_VERTICAL_XPOS;
6865 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6866 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6868 items_max = num_page_entries;
6869 items_visible = num_page_entries;
6872 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6873 gfx_pressed = scrollbar_info[i].gfx_pressed;
6874 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6875 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6876 gd_x1 = graphic_info[gfx_unpressed].src_x;
6877 gd_y1 = graphic_info[gfx_unpressed].src_y;
6878 gd_x2 = graphic_info[gfx_pressed].src_x;
6879 gd_y2 = graphic_info[gfx_pressed].src_y;
6881 gi = CreateGadget(GDI_CUSTOM_ID, id,
6882 GDI_CUSTOM_TYPE_ID, i,
6883 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6888 GDI_TYPE, scrollbar_info[i].type,
6889 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6890 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6891 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6892 GDI_WHEEL_AREA_X, SX,
6893 GDI_WHEEL_AREA_Y, SY,
6894 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6895 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6896 GDI_STATE, GD_BUTTON_UNPRESSED,
6897 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6898 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6899 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6900 GDI_DIRECT_DRAW, FALSE,
6901 GDI_EVENT_MASK, event_mask,
6902 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6906 Error(ERR_EXIT, "cannot create gadget");
6908 screen_gadget[id] = gi;
6912 void CreateScreenGadgets()
6914 int last_game_status = game_status; /* save current game status */
6916 CreateScreenMenubuttons();
6918 CreateScreenScrollbuttons();
6919 CreateScreenScrollbars();
6921 game_status = last_game_status; /* restore current game status */
6924 void FreeScreenGadgets()
6928 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6929 FreeGadget(screen_gadget[i]);
6932 void MapScreenMenuGadgets(int screen_mask)
6936 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6937 if (screen_mask & menubutton_info[i].screen_mask)
6938 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6941 void MapScreenGadgets(int num_entries)
6945 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6948 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6949 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6951 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6952 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6955 void MapScreenTreeGadgets(TreeInfo *ti)
6957 MapScreenGadgets(numTreeInfoInGroup(ti));
6960 static void HandleScreenGadgets(struct GadgetInfo *gi)
6962 int id = gi->custom_id;
6963 int button = gi->event.button;
6964 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6968 case SCREEN_CTRL_ID_PREV_LEVEL:
6969 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6972 case SCREEN_CTRL_ID_NEXT_LEVEL:
6973 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6976 case SCREEN_CTRL_ID_PREV_PLAYER:
6977 HandleSetupScreen_Input_Player(step, -1);
6980 case SCREEN_CTRL_ID_NEXT_PLAYER:
6981 HandleSetupScreen_Input_Player(step, +1);
6984 case SCREEN_CTRL_ID_SCROLL_UP:
6985 if (game_status == GAME_MODE_LEVELS)
6986 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6987 else if (game_status == GAME_MODE_LEVELNR)
6988 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6989 else if (game_status == GAME_MODE_SETUP)
6990 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6991 else if (game_status == GAME_MODE_INFO)
6992 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6995 case SCREEN_CTRL_ID_SCROLL_DOWN:
6996 if (game_status == GAME_MODE_LEVELS)
6997 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6998 else if (game_status == GAME_MODE_LEVELNR)
6999 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7000 else if (game_status == GAME_MODE_SETUP)
7001 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7002 else if (game_status == GAME_MODE_INFO)
7003 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7006 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7007 if (game_status == GAME_MODE_LEVELS)
7008 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7009 else if (game_status == GAME_MODE_LEVELNR)
7010 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7011 else if (game_status == GAME_MODE_SETUP)
7012 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7013 else if (game_status == GAME_MODE_INFO)
7014 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);