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 /* for input setup functions */
80 #define SETUPINPUT_SCREEN_POS_START 0
81 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
82 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
83 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
85 /* for various menu stuff */
86 #define MENU_SCREEN_START_XPOS 1
87 #define MENU_SCREEN_START_YPOS 2
88 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
89 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
90 #define MENU_TITLE1_YPOS 8
91 #define MENU_TITLE2_YPOS 46
92 #define MENU_SCREEN_INFO_XSTART 16
93 #define MENU_SCREEN_INFO_YSTART1 100
94 #define MENU_SCREEN_INFO_YSTART2 128
95 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
96 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
97 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
98 MENU_SCREEN_INFO_YSTART2 - \
100 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
101 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
102 MENU_SCREEN_INFO_YSTEP)
103 #define NUM_INFO_ELEMENTS_FROM_CONF \
104 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
105 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
106 MAX_MENU_ENTRIES_ON_SCREEN)
107 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
108 MAX_INFO_ELEMENTS_ON_SCREEN), \
109 NUM_INFO_ELEMENTS_FROM_CONF)
110 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
111 #define MAX_MENU_TEXT_LENGTH_BIG 13
112 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
114 /* buttons and scrollbars identifiers */
115 #define SCREEN_CTRL_ID_PREV_LEVEL 0
116 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
117 #define SCREEN_CTRL_ID_PREV_PLAYER 2
118 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
119 #define SCREEN_CTRL_ID_SCROLL_UP 4
120 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
121 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
123 #define NUM_SCREEN_GADGETS 7
125 #define NUM_SCREEN_MENUBUTTONS 4
126 #define NUM_SCREEN_SCROLLBUTTONS 2
127 #define NUM_SCREEN_SCROLLBARS 1
129 #define SCREEN_MASK_MAIN (1 << 0)
130 #define SCREEN_MASK_INPUT (1 << 1)
132 /* graphic position and size values for buttons and scrollbars */
133 #define SC_MENUBUTTON_XSIZE TILEX
134 #define SC_MENUBUTTON_YSIZE TILEY
136 #define SC_SCROLLBUTTON_XSIZE TILEX
137 #define SC_SCROLLBUTTON_YSIZE TILEY
139 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
141 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
142 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
143 SC_SCROLLBUTTON_YSIZE)
145 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
146 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
148 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
149 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
150 SC_SCROLLBUTTON_YSIZE)
152 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
153 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
154 SC_SCROLL_VERTICAL_YSIZE)
156 #define SC_BORDER_SIZE 14
159 /* forward declarations of internal functions */
160 static void HandleScreenGadgets(struct GadgetInfo *);
161 static void HandleSetupScreen_Generic(int, int, int, int, int);
162 static void HandleSetupScreen_Input(int, int, int, int, int);
163 static void CustomizeKeyboard(int);
164 static void CalibrateJoystick(int);
165 static void execSetupGame(void);
166 static void execSetupGraphics(void);
167 static void execSetupSound(void);
168 static void execSetupTouch(void);
169 static void execSetupArtwork(void);
170 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
172 static void DrawChooseLevelSet(void);
173 static void DrawChooseLevelNr(void);
174 static void DrawInfoScreen(void);
175 static void DrawAndFadeInInfoScreen(int);
176 static void DrawSetupScreen(void);
178 static void DrawInfoScreenExt(int, int);
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);
1369 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1371 static LevelDirTree *leveldir_last_valid = NULL;
1372 boolean levelset_has_changed = FALSE;
1374 LimitScreenUpdates(FALSE);
1376 FadeSetLeaveScreen();
1378 /* do not fade out here -- function may continue and fade on editor screen */
1381 FadeSoundsAndMusic();
1383 KeyboardAutoRepeatOn();
1386 audio.sound_deactivated = FALSE;
1390 /* needed if last screen was the playing screen, invoked from level editor */
1391 if (level_editor_test_game)
1393 game_status = GAME_MODE_EDITOR;
1399 /* needed if last screen was the setup screen and fullscreen state changed */
1400 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1401 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1403 /* leveldir_current may be invalid (level group, parent link) */
1404 if (!validLevelSeries(leveldir_current))
1405 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1407 if (leveldir_current != leveldir_last_valid)
1408 levelset_has_changed = TRUE;
1410 /* store valid level series information */
1411 leveldir_last_valid = leveldir_current;
1413 init_last = init; /* switch to new busy animation */
1415 /* needed if last screen (level choice) changed graphics, sounds or music */
1416 ReloadCustomArtwork(0);
1418 if (redraw_mask & REDRAW_ALL)
1419 fade_mask = REDRAW_ALL;
1423 /* needed if different viewport properties defined for menues */
1424 ChangeViewportPropertiesIfNeeded();
1426 /* needed if last screen was the editor screen */
1427 UndrawSpecialEditorDoor();
1429 SetDrawtoField(DRAW_BACKBUFFER);
1431 if (CheckTitleScreen(levelset_has_changed))
1433 game_status = GAME_MODE_TITLE;
1440 /* level_nr may have been set to value over handicap with level editor */
1441 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1442 level_nr = leveldir_current->handicap_level;
1444 LoadLevel(level_nr);
1445 LoadScore(level_nr);
1447 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1448 SetDrawDeactivationMask(REDRAW_NONE);
1449 SetDrawBackgroundMask(REDRAW_FIELD);
1451 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1453 if (fade_mask == REDRAW_ALL)
1454 RedrawGlobalBorder();
1458 InitializeMainControls();
1460 DrawCursorAndText_Main(-1, FALSE, FALSE);
1461 DrawPreviewLevelInitial();
1463 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1466 if (TAPE_IS_EMPTY(tape))
1468 DrawCompleteVideoDisplay();
1473 /* create gadgets for main menu screen */
1474 FreeScreenGadgets();
1475 CreateScreenGadgets();
1477 /* map gadgets for main menu screen */
1479 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1481 /* copy actual game door content to door double buffer for OpenDoor() */
1482 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1484 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1486 DrawMaskedBorder(REDRAW_ALL);
1491 /* update screen area with special editor door */
1492 redraw_mask |= REDRAW_ALL;
1495 SetMouseCursor(CURSOR_DEFAULT);
1499 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1502 void DrawAndFadeInMainMenu(int fade_mask)
1504 DrawMainMenuExt(fade_mask, TRUE);
1509 DrawMainMenuExt(REDRAW_ALL, FALSE);
1512 static void gotoTopLevelDir()
1514 /* move upwards until inside (but not above) top level directory */
1515 while (leveldir_current->node_parent &&
1516 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1518 /* write a "path" into level tree for easy navigation to last level */
1519 if (leveldir_current->node_parent->node_group->cl_first == -1)
1521 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1522 int leveldir_pos = posTreeInfo(leveldir_current);
1523 int num_page_entries;
1524 int cl_first, cl_cursor;
1526 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1527 num_page_entries = num_leveldirs;
1529 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1531 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1532 cl_cursor = leveldir_pos - cl_first;
1534 leveldir_current->node_parent->node_group->cl_first = cl_first;
1535 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1538 leveldir_current = leveldir_current->node_parent;
1542 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1544 static unsigned int title_delay = 0;
1545 static int title_screen_nr = 0;
1546 static int last_sound = -1, last_music = -1;
1547 boolean return_to_main_menu = FALSE;
1548 boolean use_fading_main_menu = TRUE;
1549 struct TitleControlInfo *tci;
1550 struct TitleFadingInfo fading_default;
1551 struct TitleFadingInfo fading_last = fading;
1552 struct TitleFadingInfo fading_next;
1555 if (button == MB_MENU_INITIALIZE)
1558 title_screen_nr = 0;
1559 tci = &title_controls[title_screen_nr];
1561 last_sound = SND_UNDEFINED;
1562 last_music = MUS_UNDEFINED;
1564 if (game_status == GAME_MODE_INFO)
1566 if (num_title_screens == 0)
1568 DrawInfoScreen_NotAvailable("Title screen information:",
1569 "No title screen for this level set.");
1574 FadeSoundsAndMusic();
1576 FadeOut(REDRAW_ALL);
1580 DrawTitleScreenImage(tci->local_nr, tci->initial);
1582 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1584 fading_default = (tci->initial ? title_initial_default : title_default);
1586 fading = fading_next = getTitleFading(tci);
1588 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1589 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1591 fading.fade_mode = FADE_MODE_FADE;
1592 fading.fade_delay = fading_default.fade_delay;
1595 sound = getTitleSound(tci);
1596 music = getTitleMusic(tci);
1598 if (sound != last_sound)
1599 PlayMenuSoundExt(sound);
1600 if (music != last_music)
1601 PlayMenuMusicExt(music);
1606 SetMouseCursor(CURSOR_NONE);
1610 fading = fading_next;
1612 DelayReached(&title_delay, 0); /* reset delay counter */
1617 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1618 button = MB_MENU_CHOICE;
1620 if (button == MB_MENU_LEAVE)
1622 return_to_main_menu = TRUE;
1623 use_fading_main_menu = FALSE;
1625 else if (button == MB_MENU_CHOICE)
1627 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1629 FadeSetEnterScreen();
1631 info_mode = INFO_MODE_MAIN;
1632 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1638 tci = &title_controls[title_screen_nr];
1640 if (title_screen_nr < num_title_screens)
1642 sound = getTitleSound(tci);
1643 music = getTitleMusic(tci);
1645 if (sound == SND_UNDEFINED || sound != last_sound)
1647 if (music == MUS_UNDEFINED || music != last_music)
1650 FadeOut(REDRAW_ALL);
1653 DrawTitleScreenImage(tci->local_nr, tci->initial);
1655 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1657 fading_next = getTitleFading(tci);
1659 sound = getTitleSound(tci);
1660 music = getTitleMusic(tci);
1662 if (sound != last_sound)
1663 PlayMenuSoundExt(sound);
1664 if (music != last_music)
1665 PlayMenuMusicExt(music);
1670 /* last screen already faded out, next screen has no animation */
1671 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1672 fading_next.fade_mode == FADE_MODE_NONE)
1673 fading = fading_next;
1677 fading = fading_next;
1679 DelayReached(&title_delay, 0); /* reset delay counter */
1683 FadeSoundsAndMusic();
1685 return_to_main_menu = TRUE;
1689 if (return_to_main_menu)
1691 SetMouseCursor(CURSOR_DEFAULT);
1693 if (game_status == GAME_MODE_INFO)
1695 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1697 info_mode = INFO_MODE_MAIN;
1699 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1701 else /* default: return to main menu */
1703 game_status = GAME_MODE_MAIN;
1705 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1710 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1712 int old_level_nr = level_nr;
1715 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1716 new_level_nr = selected_level_nr;
1718 new_level_nr = old_level_nr + step * direction;
1720 if (new_level_nr < leveldir_current->first_level)
1721 new_level_nr = leveldir_current->first_level;
1722 if (new_level_nr > leveldir_current->last_level)
1723 new_level_nr = leveldir_current->last_level;
1725 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1727 /* skipping levels is only allowed when trying to skip single level */
1728 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1729 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1731 leveldir_current->handicap_level++;
1732 SaveLevelSetup_SeriesInfo();
1735 new_level_nr = leveldir_current->handicap_level;
1738 if (new_level_nr != old_level_nr)
1740 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1742 PlaySound(SND_MENU_ITEM_SELECTING);
1744 level_nr = new_level_nr;
1746 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1747 int2str(level_nr, menu.main.text.level_number.size),
1748 mci->pos_text->font);
1750 LoadLevel(level_nr);
1751 DrawPreviewLevelInitial();
1755 DrawCompleteVideoDisplay();
1757 /* needed because DrawPreviewLevelInitial() takes some time */
1759 /* SyncDisplay(); */
1763 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1765 static int choice = MAIN_CONTROL_GAME;
1766 static boolean button_pressed_last = FALSE;
1767 boolean button_pressed = FALSE;
1771 if (button == MB_MENU_INITIALIZE)
1773 DrawCursorAndText_Main(choice, TRUE, FALSE);
1778 if (mx || my) /* mouse input */
1782 for (i = 0; main_controls[i].nr != -1; i++)
1784 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1785 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1786 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1788 pos = main_controls[i].nr;
1794 // handle pressed/unpressed state for active/inactive menu buttons
1795 // (if pos != -1, "i" contains index position corresponding to "pos")
1797 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1798 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1799 button_pressed = TRUE;
1801 if (button_pressed != button_pressed_last)
1803 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1806 PlaySound(SND_MENU_BUTTON_PRESSING);
1808 PlaySound(SND_MENU_BUTTON_RELEASING);
1811 else if (dx || dy) /* keyboard input */
1813 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1814 choice == MAIN_CONTROL_SETUP))
1815 button = MB_MENU_CHOICE;
1820 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1822 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1824 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1826 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1828 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1830 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1832 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
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)
1868 game_status = GAME_MODE_LEVELS;
1870 SaveLevelSetup_LastSeries();
1871 SaveLevelSetup_SeriesInfo();
1873 if (setup.internal.choose_from_top_leveldir)
1876 ChangeViewportPropertiesIfNeeded();
1878 DrawChooseLevelSet();
1881 else if (pos == MAIN_CONTROL_SCORES)
1883 game_status = GAME_MODE_SCORES;
1885 ChangeViewportPropertiesIfNeeded();
1889 else if (pos == MAIN_CONTROL_EDITOR)
1891 if (leveldir_current->readonly &&
1892 !strEqual(setup.player_name, "Artsoft"))
1893 Request("This level is read only!", REQ_CONFIRM);
1895 CloseDoor(DOOR_CLOSE_2);
1897 game_status = GAME_MODE_EDITOR;
1899 FadeSetEnterScreen();
1903 else if (pos == MAIN_CONTROL_INFO)
1905 game_status = GAME_MODE_INFO;
1906 info_mode = INFO_MODE_MAIN;
1908 ChangeViewportPropertiesIfNeeded();
1912 else if (pos == MAIN_CONTROL_GAME)
1914 StartGameActions(options.network, setup.autorecord, level.random_seed);
1916 else if (pos == MAIN_CONTROL_SETUP)
1918 game_status = GAME_MODE_SETUP;
1919 setup_mode = SETUP_MODE_MAIN;
1921 ChangeViewportPropertiesIfNeeded();
1925 else if (pos == MAIN_CONTROL_QUIT)
1927 SaveLevelSetup_LastSeries();
1928 SaveLevelSetup_SeriesInfo();
1930 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1931 game_status = GAME_MODE_QUIT;
1936 button_pressed_last = button_pressed;
1940 /* ========================================================================= */
1941 /* info screen functions */
1942 /* ========================================================================= */
1944 static struct TokenInfo *info_info;
1945 static int num_info_info; /* number of info entries shown on screen */
1946 static int max_info_info; /* total number of info entries in list */
1948 static void execInfoTitleScreen()
1950 info_mode = INFO_MODE_TITLE;
1955 static void execInfoElements()
1957 info_mode = INFO_MODE_ELEMENTS;
1962 static void execInfoMusic()
1964 info_mode = INFO_MODE_MUSIC;
1969 static void execInfoCredits()
1971 info_mode = INFO_MODE_CREDITS;
1976 static void execInfoProgram()
1978 info_mode = INFO_MODE_PROGRAM;
1983 static void execInfoVersion()
1985 info_mode = INFO_MODE_VERSION;
1990 static void execInfoLevelSet()
1992 info_mode = INFO_MODE_LEVELSET;
1997 static void execExitInfo()
1999 game_status = GAME_MODE_MAIN;
2001 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2004 static struct TokenInfo info_info_main[] =
2006 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2007 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2008 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2009 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2010 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2011 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2012 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2013 { TYPE_EMPTY, NULL, "" },
2014 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2019 static void DrawCursorAndText_Info(int screen_pos, int info_info_pos_raw,
2022 int ii_pos = (info_info_pos_raw < 0 ? screen_pos : info_info_pos_raw);
2023 struct TokenInfo *ii = &info_info[ii_pos];
2024 int xpos = MENU_SCREEN_START_XPOS;
2025 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2026 int font_nr = FONT_MENU_1;
2029 font_nr = FONT_ACTIVE(font_nr);
2031 DrawText(mSX + xpos * 32, mSY + ypos * 32, ii->text, font_nr);
2033 if (ii->type & ~TYPE_SKIP_ENTRY)
2034 drawCursor(screen_pos, active);
2037 static void drawInfoInfoList(struct TokenInfo *info_info,
2038 int first_entry, int num_page_entries)
2042 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
2043 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
2045 if (num_page_entries > max_info_info)
2046 num_page_entries = max_info_info;
2048 if (first_entry + num_page_entries > max_info_info)
2051 clearMenuListArea();
2053 for (i = 0; i < num_page_entries; i++)
2055 int info_info_pos = first_entry + i;
2056 struct TokenInfo *ii = &info_info[info_info_pos];
2058 if (ii->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2059 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2060 else if (ii->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2061 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2062 else if (ii->type & ~TYPE_SKIP_ENTRY)
2063 initCursor(i, IMG_MENU_BUTTON);
2065 DrawCursorAndText_Info(i, info_info_pos, FALSE);
2069 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2075 FreeScreenGadgets();
2076 CreateScreenGadgets();
2078 CloseDoor(DOOR_CLOSE_2);
2080 /* (needed after displaying title screens which disable auto repeat) */
2081 KeyboardAutoRepeatOn();
2083 FadeSetLeaveScreen();
2087 if (fade_mask == REDRAW_ALL)
2089 RedrawGlobalBorder();
2091 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2096 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2098 info_info = info_info_main;
2100 // determine maximal number of info entries that can be displayed on screen
2102 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2105 // determine maximal number of info entries available for menu of info screen
2107 for (i = 0; info_info[i].type != 0; i++)
2110 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2112 MapScreenGadgets(max_info_info);
2117 DrawMaskedBorder(fade_mask);
2124 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2126 static int choice_store[MAX_INFO_MODES];
2127 static int first_entry_store[MAX_INFO_MODES];
2128 static int num_page_entries_last = 0;
2129 int choice = choice_store[info_mode]; /* starts with 0 */
2130 int first_entry = first_entry_store[info_mode]; /* starts with 0 */
2132 int y = choice - first_entry;
2134 boolean position_set_by_scrollbar = (dx == 999);
2135 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2136 int num_page_entries;
2138 num_page_entries = MIN(max_info_info, NUM_MENU_ENTRIES_ON_SCREEN);
2140 if (button == MB_MENU_INITIALIZE)
2142 // check if number of menu page entries has changed (may happen by change
2143 // of custom artwork definition value for 'list_size' for this menu screen)
2144 // (in this case, the last menu position most probably has to be corrected)
2145 if (num_page_entries != num_page_entries_last)
2149 for (i = 0; i < MAX_INFO_MODES; i++)
2150 choice_store[i] = first_entry_store[i] = 0;
2152 num_page_entries_last = num_page_entries;
2154 HandleInfoScreen_Main(mx, my, dx, dy, button);
2159 /* advance to first valid menu entry */
2160 while (choice < num_info_info &&
2161 info_info[choice].type & TYPE_SKIP_ENTRY)
2164 if (position_set_by_scrollbar)
2165 first_entry = first_entry_store[info_mode] = dy;
2167 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_info_info,
2168 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2170 drawInfoInfoList(info_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
2172 if (choice < first_entry)
2174 choice = first_entry;
2176 if (info_info[choice].type & TYPE_SKIP_ENTRY)
2179 else if (choice > first_entry + num_page_entries - 1)
2181 choice = first_entry + num_page_entries - 1;
2183 if (info_info[choice].type & TYPE_SKIP_ENTRY)
2187 choice_store[info_mode] = choice;
2189 DrawCursorAndText_Info(choice - first_entry, choice, TRUE);
2193 else if (button == MB_MENU_LEAVE)
2195 for (y = 0; y < num_info_info; y++)
2197 if (info_info[y].type & TYPE_LEAVE_MENU)
2199 void (*menu_callback_function)(void) = info_info[y].value;
2203 menu_callback_function();
2205 break; /* absolutely needed because function changes 'info_info'! */
2212 if (mx || my) /* mouse input */
2214 x = (mx - mSX) / 32;
2215 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2217 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2219 /* move cursor instead of scrolling when already at start/end of list */
2220 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2222 else if (dy == +1 * SCROLL_LINE &&
2223 first_entry + num_page_entries == max_info_info)
2226 /* handle scrolling screen one line or page */
2228 y + dy > num_page_entries - 1)
2230 boolean redraw = FALSE;
2232 if (ABS(dy) == SCROLL_PAGE)
2233 step = num_page_entries - 1;
2235 if (dy < 0 && first_entry > 0)
2237 /* scroll page/line up */
2239 first_entry -= step;
2240 if (first_entry < 0)
2245 else if (dy > 0 && first_entry + num_page_entries < max_info_info)
2247 /* scroll page/line down */
2249 first_entry += step;
2250 if (first_entry + num_page_entries > max_info_info)
2251 first_entry = MAX(0, max_info_info - num_page_entries);
2258 choice += first_entry - first_entry_store[info_mode];
2260 if (choice < first_entry)
2262 choice = first_entry;
2264 if (info_info[choice].type & TYPE_SKIP_ENTRY)
2267 else if (choice > first_entry + num_page_entries - 1)
2269 choice = first_entry + num_page_entries - 1;
2271 if (info_info[choice].type & TYPE_SKIP_ENTRY)
2274 else if (info_info[choice].type & TYPE_SKIP_ENTRY)
2278 if (choice < first_entry ||
2279 choice > first_entry + num_page_entries - 1)
2280 first_entry += SIGN(dy);
2283 first_entry_store[info_mode] = first_entry;
2284 choice_store[info_mode] = choice;
2286 drawInfoInfoList(info_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
2288 DrawCursorAndText_Info(choice - first_entry, choice, TRUE);
2290 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_info_info,
2291 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2299 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2301 if (info_info[choice].type & menu_navigation_type ||
2302 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2303 info_info[choice].type & TYPE_YES_NO_AUTO)
2304 button = MB_MENU_CHOICE;
2309 /* jump to next non-empty menu entry (up or down) */
2310 while (first_entry + y > 0 &&
2311 first_entry + y < max_info_info - 1 &&
2312 info_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2315 if (!IN_VIS_MENU(x, y))
2317 choice += y - y_old;
2319 if (choice < first_entry)
2320 first_entry = choice;
2321 else if (choice > first_entry + num_page_entries - 1)
2322 first_entry = choice - num_page_entries + 1;
2324 if (first_entry >= 0 &&
2325 first_entry + num_page_entries <= max_info_info)
2327 first_entry_store[info_mode] = first_entry;
2329 if (choice < first_entry)
2330 choice = first_entry;
2331 else if (choice > first_entry + num_page_entries - 1)
2332 choice = first_entry + num_page_entries - 1;
2334 choice_store[info_mode] = choice;
2336 drawInfoInfoList(info_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
2338 DrawCursorAndText_Info(choice - first_entry, choice, TRUE);
2340 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_info_info,
2341 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2348 if (!anyScrollbarGadgetActive() &&
2349 IN_VIS_MENU(x, y) &&
2350 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2351 y >= 0 && y < num_page_entries)
2355 if (first_entry + y != choice &&
2356 info_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2358 PlaySound(SND_MENU_ITEM_ACTIVATING);
2360 DrawCursorAndText_Info(choice - first_entry, choice, FALSE);
2361 DrawCursorAndText_Info(y, first_entry + y, TRUE);
2363 choice = choice_store[info_mode] = first_entry + y;
2366 else if (!(info_info[first_entry + y].type & TYPE_GHOSTED))
2368 PlaySound(SND_MENU_ITEM_SELECTING);
2370 if (info_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2372 void (*menu_callback_function)(void) =
2373 info_info[first_entry + y].value;
2375 FadeSetFromType(info_info[first_entry + y].type);
2377 menu_callback_function();
2383 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2385 int ystart1 = mSY - SY + 100;
2386 int ystart2 = mSY - SY + 150;
2387 int ybottom = mSY - SY + SYSIZE - 20;
2389 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2391 FadeOut(REDRAW_FIELD);
2396 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2397 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2399 DrawTextSCentered(ybottom, FONT_TEXT_4,
2400 "Press any key or button for info menu");
2402 FadeIn(REDRAW_FIELD);
2405 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2407 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2408 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2409 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2410 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2411 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2412 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2413 int ystep = MENU_SCREEN_INFO_YSTEP;
2414 int element, action, direction;
2422 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2423 infoscreen_step[i] = infoscreen_frame[i] = 0;
2428 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2430 DrawTextSCentered(ybottom, FONT_TEXT_4,
2431 "Press any key or button for next page");
2437 while (helpanim_info[j].element != HELPANIM_LIST_END)
2439 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2444 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2453 j += infoscreen_step[i - start];
2455 element = helpanim_info[j].element;
2456 action = helpanim_info[j].action;
2457 direction = helpanim_info[j].direction;
2460 element = EL_UNKNOWN;
2462 if (action != -1 && direction != -1)
2463 graphic = el_act_dir2img(element, action, direction);
2464 else if (action != -1)
2465 graphic = el_act2img(element, action);
2466 else if (direction != -1)
2467 graphic = el_dir2img(element, direction);
2469 graphic = el2img(element);
2471 delay = helpanim_info[j++].delay;
2476 if (infoscreen_frame[i - start] == 0)
2479 infoscreen_frame[i - start] = delay - 1;
2483 sync_frame = delay - infoscreen_frame[i - start];
2484 infoscreen_frame[i - start]--;
2487 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2489 if (!infoscreen_frame[i - start])
2490 infoscreen_step[i - start] = 0;
2494 if (!infoscreen_frame[i - start])
2495 infoscreen_step[i - start]++;
2496 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2502 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2504 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2505 graphic, sync_frame, USE_MASKING);
2508 DrawInfoScreen_HelpText(element, action, direction, i - start);
2513 redraw_mask |= REDRAW_FIELD;
2518 static char *getHelpText(int element, int action, int direction)
2520 char token[MAX_LINE_LEN];
2522 strcpy(token, element_info[element].token_name);
2525 strcat(token, element_action_info[action].suffix);
2527 if (direction != -1)
2528 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2530 return getHashEntry(helptext_info, token);
2533 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2535 int font_nr = FONT_INFO_ELEMENTS;
2536 int font_width = getFontWidth(font_nr);
2537 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2538 int sy = mSY + 65 + 2 * 32 + 1;
2539 int ystep = TILEY + 4;
2540 int pad_x = sx - SX;
2541 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2542 int max_lines_per_text = 2;
2545 if (action != -1 && direction != -1) /* element.action.direction */
2546 text = getHelpText(element, action, direction);
2548 if (text == NULL && action != -1) /* element.action */
2549 text = getHelpText(element, action, -1);
2551 if (text == NULL && direction != -1) /* element.direction */
2552 text = getHelpText(element, -1, direction);
2554 if (text == NULL) /* base element */
2555 text = getHelpText(element, -1, -1);
2557 if (text == NULL) /* not found */
2558 text = "No description available";
2560 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2561 sy += getFontHeight(font_nr) / 2;
2563 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2564 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2565 TRUE, FALSE, FALSE);
2568 void DrawInfoScreen_TitleScreen()
2573 void HandleInfoScreen_TitleScreen(int button)
2575 HandleTitleScreen(0, 0, 0, 0, button);
2578 void DrawInfoScreen_Elements()
2580 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2582 FadeOut(REDRAW_FIELD);
2587 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2589 FadeIn(REDRAW_FIELD);
2594 void HandleInfoScreen_Elements(int button)
2596 static unsigned int info_delay = 0;
2597 static int num_anims;
2598 static int num_pages;
2600 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2603 if (button == MB_MENU_INITIALIZE)
2605 boolean new_element = TRUE;
2609 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2611 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2613 else if (new_element)
2616 new_element = FALSE;
2620 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2624 if (button == MB_MENU_LEAVE)
2626 PlaySound(SND_MENU_ITEM_SELECTING);
2628 info_mode = INFO_MODE_MAIN;
2633 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2635 if (button != MB_MENU_INITIALIZE)
2637 PlaySound(SND_MENU_ITEM_SELECTING);
2642 if (page >= num_pages)
2644 FadeSoundsAndMusic();
2646 info_mode = INFO_MODE_MAIN;
2647 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2653 FadeSetNextScreen();
2655 if (button != MB_MENU_INITIALIZE)
2656 FadeOut(REDRAW_FIELD);
2658 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2660 if (button != MB_MENU_INITIALIZE)
2661 FadeIn(REDRAW_FIELD);
2665 if (DelayReached(&info_delay, GameFrameDelay))
2666 if (page < num_pages)
2667 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2669 PlayMenuSoundIfLoop();
2673 void DrawInfoScreen_Music()
2675 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2677 FadeOut(REDRAW_FIELD);
2684 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2686 FadeIn(REDRAW_FIELD);
2689 void HandleInfoScreen_Music(int button)
2691 static struct MusicFileInfo *list = NULL;
2692 int ystart1 = mSY - SY + 100;
2693 int ystart2 = mSY - SY + 150;
2694 int ybottom = mSY - SY + SYSIZE - 20;
2697 if (button == MB_MENU_INITIALIZE)
2699 list = music_file_info;
2703 FadeSoundsAndMusic();
2708 DrawTextSCentered(ystart1, FONT_TEXT_1,
2709 "No music info for this level set.");
2711 DrawTextSCentered(ybottom, FONT_TEXT_4,
2712 "Press any key or button for info menu");
2718 if (button == MB_MENU_LEAVE)
2720 PlaySound(SND_MENU_ITEM_SELECTING);
2722 FadeSoundsAndMusic();
2724 info_mode = INFO_MODE_MAIN;
2729 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2733 if (button != MB_MENU_INITIALIZE)
2735 PlaySound(SND_MENU_ITEM_SELECTING);
2743 FadeSoundsAndMusic();
2745 info_mode = INFO_MODE_MAIN;
2746 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2751 FadeSoundsAndMusic();
2753 if (list != music_file_info)
2754 FadeSetNextScreen();
2756 if (button != MB_MENU_INITIALIZE)
2757 FadeOut(REDRAW_FIELD);
2764 int sound = list->music;
2766 if (sound_info[sound].loop)
2767 PlaySoundLoop(sound);
2771 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2775 PlayMusic(list->music);
2777 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2780 if (!strEqual(list->title, UNKNOWN_NAME))
2782 if (!strEqual(list->title_header, UNKNOWN_NAME))
2783 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2785 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2788 if (!strEqual(list->artist, UNKNOWN_NAME))
2790 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2791 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2793 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2795 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2798 if (!strEqual(list->album, UNKNOWN_NAME))
2800 if (!strEqual(list->album_header, UNKNOWN_NAME))
2801 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2803 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2805 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2808 if (!strEqual(list->year, UNKNOWN_NAME))
2810 if (!strEqual(list->year_header, UNKNOWN_NAME))
2811 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2813 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2815 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2818 DrawTextSCentered(ybottom, FONT_TEXT_4,
2819 "Press any key or button for next page");
2821 if (button != MB_MENU_INITIALIZE)
2822 FadeIn(REDRAW_FIELD);
2825 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2826 PlaySoundLoop(list->music);
2829 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2831 int ystart1 = mSY - SY + 100;
2832 int ystart2 = mSY - SY + 150;
2833 int ybottom = mSY - SY + SYSIZE - 20;
2839 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2843 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2844 "Special thanks to");
2845 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2847 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2849 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2850 "\"Boulder Dash\"");
2851 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2853 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2855 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2857 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2858 "First Star Software");
2860 else if (screen_nr == 1)
2862 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2863 "Special thanks to");
2864 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2865 "Klaus Heinz & Volker Wertich");
2866 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2868 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2869 "\"Emerald Mine\"");
2870 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2872 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2874 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2876 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2879 else if (screen_nr == 2)
2881 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2882 "Special thanks to");
2883 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2884 "Michael Stopp & Philip Jespersen");
2885 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2887 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2889 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2891 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2893 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2895 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2896 "Digital Integration");
2898 else if (screen_nr == 3)
2900 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2901 "Special thanks to");
2902 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2903 "Hiroyuki Imabayashi");
2904 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2906 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2908 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2910 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2912 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2914 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2917 else if (screen_nr == 4)
2919 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2920 "Special thanks to");
2921 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2923 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2925 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2926 "J\xfcrgen Bonhagen");
2927 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2928 "for the continuous creation");
2929 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2930 "of outstanding level sets");
2932 else if (screen_nr == 5)
2934 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2936 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2938 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2939 "for ideas and inspiration by");
2940 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2943 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2945 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2947 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2948 "for ideas and inspiration by");
2949 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2952 else if (screen_nr == 6)
2954 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2956 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2959 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2960 "for the code base used for the");
2961 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2962 "native Emerald Mine engine");
2964 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2965 "for the new Emerald Mine engine");
2968 else if (screen_nr == 7)
2970 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2972 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2974 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2975 "for the initial DOS port");
2977 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2979 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2981 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2982 "for some additional toons");
2984 else if (screen_nr == 8)
2986 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2987 "And not to forget:");
2988 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2990 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2991 "All those who contributed");
2992 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2993 "levels to this game");
2994 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2998 DrawTextSCentered(ybottom, FONT_TEXT_4,
2999 "Press any key or button for next page");
3002 void DrawInfoScreen_Credits()
3004 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3006 FadeSoundsAndMusic();
3008 FadeOut(REDRAW_FIELD);
3010 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3012 FadeIn(REDRAW_FIELD);
3015 void HandleInfoScreen_Credits(int button)
3017 static int screen_nr = 0;
3018 int num_screens = 9;
3020 if (button == MB_MENU_INITIALIZE)
3024 // DrawInfoScreen_CreditsScreen(screen_nr);
3027 if (button == MB_MENU_LEAVE)
3029 PlaySound(SND_MENU_ITEM_SELECTING);
3031 info_mode = INFO_MODE_MAIN;
3036 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3038 if (button != MB_MENU_INITIALIZE)
3040 PlaySound(SND_MENU_ITEM_SELECTING);
3045 if (screen_nr >= num_screens)
3047 FadeSoundsAndMusic();
3049 info_mode = INFO_MODE_MAIN;
3050 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3056 FadeSetNextScreen();
3058 if (button != MB_MENU_INITIALIZE)
3059 FadeOut(REDRAW_FIELD);
3061 DrawInfoScreen_CreditsScreen(screen_nr);
3063 if (button != MB_MENU_INITIALIZE)
3064 FadeIn(REDRAW_FIELD);
3068 PlayMenuSoundIfLoop();
3072 void DrawInfoScreen_Program()
3074 int ystart1 = mSY - SY + 100;
3075 int ystart2 = mSY - SY + 150;
3076 int ybottom = mSY - SY + SYSIZE - 20;
3079 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3081 FadeOut(REDRAW_FIELD);
3086 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3088 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3089 "This game is Freeware!");
3090 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3091 "If you like it, send e-mail to:");
3092 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3093 setup.internal.program_email);
3094 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3095 "More information and levels:");
3096 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3097 setup.internal.program_website);
3098 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3099 "If you have created new levels,");
3100 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3101 "send them to me to include them!");
3102 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3105 DrawTextSCentered(ybottom, FONT_TEXT_4,
3106 "Press any key or button for info menu");
3108 FadeIn(REDRAW_FIELD);
3111 void HandleInfoScreen_Program(int button)
3113 if (button == MB_MENU_LEAVE)
3115 PlaySound(SND_MENU_ITEM_SELECTING);
3117 info_mode = INFO_MODE_MAIN;
3122 else if (button == MB_MENU_CHOICE)
3124 PlaySound(SND_MENU_ITEM_SELECTING);
3126 FadeSoundsAndMusic();
3128 info_mode = INFO_MODE_MAIN;
3129 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3133 PlayMenuSoundIfLoop();
3137 void DrawInfoScreen_Version()
3139 int font_header = FONT_TEXT_3;
3140 int font_text = FONT_TEXT_2;
3141 int xstep = getFontWidth(font_text);
3142 int ystep = getFontHeight(font_text);
3143 int ystart1 = mSY - SY + 100;
3144 int ystart2 = mSY - SY + 150;
3145 int ybottom = mSY - SY + SYSIZE - 20;
3146 int xstart1 = mSX - SX + 2 * xstep;
3147 int xstart2 = mSX - SX + 18 * xstep;
3148 int xstart3 = mSX - SX + 28 * xstep;
3149 SDL_version sdl_version_compiled;
3150 const SDL_version *sdl_version_linked;
3151 int driver_name_len = 10;
3152 #if defined(TARGET_SDL2)
3153 SDL_version sdl_version_linked_ext;
3154 const char *driver_name = NULL;
3156 char driver_name[driver_name_len];
3159 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3161 FadeOut(REDRAW_FIELD);
3166 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3168 DrawTextF(xstart1, ystart2, font_header, "Name");
3169 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3172 DrawTextF(xstart1, ystart2, font_header, "Version");
3173 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3176 DrawTextF(xstart1, ystart2, font_header, "Platform");
3177 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3180 DrawTextF(xstart1, ystart2, font_header, "Target");
3181 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3184 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3185 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3187 ystart2 += 3 * ystep;
3188 DrawTextF(xstart1, ystart2, font_header, "Library");
3189 DrawTextF(xstart2, ystart2, font_header, "compiled");
3190 DrawTextF(xstart3, ystart2, font_header, "linked");
3192 SDL_VERSION(&sdl_version_compiled);
3193 #if defined(TARGET_SDL2)
3194 SDL_GetVersion(&sdl_version_linked_ext);
3195 sdl_version_linked = &sdl_version_linked_ext;
3197 sdl_version_linked = SDL_Linked_Version();
3200 ystart2 += 2 * ystep;
3201 DrawTextF(xstart1, ystart2, font_text, "SDL");
3202 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3203 sdl_version_compiled.major,
3204 sdl_version_compiled.minor,
3205 sdl_version_compiled.patch);
3206 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3207 sdl_version_linked->major,
3208 sdl_version_linked->minor,
3209 sdl_version_linked->patch);
3211 SDL_IMAGE_VERSION(&sdl_version_compiled);
3212 sdl_version_linked = IMG_Linked_Version();
3215 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3216 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3217 sdl_version_compiled.major,
3218 sdl_version_compiled.minor,
3219 sdl_version_compiled.patch);
3220 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3221 sdl_version_linked->major,
3222 sdl_version_linked->minor,
3223 sdl_version_linked->patch);
3225 SDL_MIXER_VERSION(&sdl_version_compiled);
3226 sdl_version_linked = Mix_Linked_Version();
3229 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3230 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3231 sdl_version_compiled.major,
3232 sdl_version_compiled.minor,
3233 sdl_version_compiled.patch);
3234 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3235 sdl_version_linked->major,
3236 sdl_version_linked->minor,
3237 sdl_version_linked->patch);
3239 SDL_NET_VERSION(&sdl_version_compiled);
3240 sdl_version_linked = SDLNet_Linked_Version();
3243 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3244 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3245 sdl_version_compiled.major,
3246 sdl_version_compiled.minor,
3247 sdl_version_compiled.patch);
3248 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3249 sdl_version_linked->major,
3250 sdl_version_linked->minor,
3251 sdl_version_linked->patch);
3253 ystart2 += 3 * ystep;
3254 DrawTextF(xstart1, ystart2, font_header, "Driver");
3255 DrawTextF(xstart2, ystart2, font_header, "Requested");
3256 DrawTextF(xstart3, ystart2, font_header, "Used");
3258 #if defined(TARGET_SDL2)
3259 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3261 SDL_VideoDriverName(driver_name, driver_name_len);
3264 ystart2 += 2 * ystep;
3265 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3266 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3267 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3269 #if defined(TARGET_SDL2)
3270 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3272 SDL_AudioDriverName(driver_name, driver_name_len);
3276 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3277 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3278 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3280 DrawTextSCentered(ybottom, FONT_TEXT_4,
3281 "Press any key or button for info menu");
3283 FadeIn(REDRAW_FIELD);
3286 void HandleInfoScreen_Version(int button)
3288 if (button == MB_MENU_LEAVE)
3290 PlaySound(SND_MENU_ITEM_SELECTING);
3292 info_mode = INFO_MODE_MAIN;
3297 else if (button == MB_MENU_CHOICE)
3299 PlaySound(SND_MENU_ITEM_SELECTING);
3301 FadeSoundsAndMusic();
3303 info_mode = INFO_MODE_MAIN;
3304 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3308 PlayMenuSoundIfLoop();
3312 void DrawInfoScreen_LevelSet()
3314 struct TitleMessageInfo *tmi = &readme;
3315 char *filename = getLevelSetInfoFilename();
3316 char *title = "Level Set Information:";
3317 int ystart1 = mSY - SY + 100;
3318 int ybottom = mSY - SY + SYSIZE - 20;
3320 if (filename == NULL)
3322 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3327 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3329 FadeOut(REDRAW_FIELD);
3334 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3336 /* if x position set to "-1", automatically determine by playfield width */
3338 tmi->x = SXSIZE / 2;
3340 /* if y position set to "-1", use static default value */
3344 /* if width set to "-1", automatically determine by playfield width */
3345 if (tmi->width == -1)
3346 tmi->width = SXSIZE - 2 * TILEX;
3348 /* if height set to "-1", automatically determine by playfield height */
3349 if (tmi->height == -1)
3350 tmi->height = SYSIZE - 20 - tmi->y - 10;
3352 /* if chars set to "-1", automatically determine by text and font width */
3353 if (tmi->chars == -1)
3354 tmi->chars = tmi->width / getFontWidth(tmi->font);
3356 tmi->width = tmi->chars * getFontWidth(tmi->font);
3358 /* if lines set to "-1", automatically determine by text and font height */
3359 if (tmi->lines == -1)
3360 tmi->lines = tmi->height / getFontHeight(tmi->font);
3362 tmi->height = tmi->lines * getFontHeight(tmi->font);
3364 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3365 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3366 tmi->autowrap, tmi->centered, tmi->parse_comments);
3368 DrawTextSCentered(ybottom, FONT_TEXT_4,
3369 "Press any key or button for info menu");
3371 FadeIn(REDRAW_FIELD);
3374 void HandleInfoScreen_LevelSet(int button)
3376 if (button == MB_MENU_LEAVE)
3378 PlaySound(SND_MENU_ITEM_SELECTING);
3380 info_mode = INFO_MODE_MAIN;
3385 else if (button == MB_MENU_CHOICE)
3387 PlaySound(SND_MENU_ITEM_SELECTING);
3389 FadeSoundsAndMusic();
3391 info_mode = INFO_MODE_MAIN;
3392 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3396 PlayMenuSoundIfLoop();
3400 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3402 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3404 if (info_mode == INFO_MODE_TITLE)
3405 DrawInfoScreen_TitleScreen();
3406 else if (info_mode == INFO_MODE_ELEMENTS)
3407 DrawInfoScreen_Elements();
3408 else if (info_mode == INFO_MODE_MUSIC)
3409 DrawInfoScreen_Music();
3410 else if (info_mode == INFO_MODE_CREDITS)
3411 DrawInfoScreen_Credits();
3412 else if (info_mode == INFO_MODE_PROGRAM)
3413 DrawInfoScreen_Program();
3414 else if (info_mode == INFO_MODE_VERSION)
3415 DrawInfoScreen_Version();
3416 else if (info_mode == INFO_MODE_LEVELSET)
3417 DrawInfoScreen_LevelSet();
3419 DrawInfoScreen_Main(fade_mask, do_fading);
3421 if (info_mode != INFO_MODE_MAIN &&
3422 info_mode != INFO_MODE_TITLE &&
3423 info_mode != INFO_MODE_MUSIC)
3430 void DrawAndFadeInInfoScreen(int fade_mask)
3432 DrawInfoScreenExt(fade_mask, TRUE);
3435 void DrawInfoScreen()
3437 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3440 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3442 if (info_mode == INFO_MODE_TITLE)
3443 HandleInfoScreen_TitleScreen(button);
3444 else if (info_mode == INFO_MODE_ELEMENTS)
3445 HandleInfoScreen_Elements(button);
3446 else if (info_mode == INFO_MODE_MUSIC)
3447 HandleInfoScreen_Music(button);
3448 else if (info_mode == INFO_MODE_CREDITS)
3449 HandleInfoScreen_Credits(button);
3450 else if (info_mode == INFO_MODE_PROGRAM)
3451 HandleInfoScreen_Program(button);
3452 else if (info_mode == INFO_MODE_VERSION)
3453 HandleInfoScreen_Version(button);
3454 else if (info_mode == INFO_MODE_LEVELSET)
3455 HandleInfoScreen_LevelSet(button);
3457 HandleInfoScreen_Main(mx, my, dx, dy, button);
3461 /* ========================================================================= */
3462 /* type name functions */
3463 /* ========================================================================= */
3465 void HandleTypeName(int newxpos, Key key)
3467 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3468 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3469 struct TextPosInfo *pos = mci->pos_input;
3470 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3471 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3472 static int xpos = 0;
3473 int font_nr = pos->font;
3474 int font_active_nr = FONT_ACTIVE(font_nr);
3475 int font_width = getFontWidth(font_active_nr);
3476 char key_char = getValidConfigValueChar(getCharFromKey(key));
3477 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3478 boolean is_active = TRUE;
3480 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3484 strcpy(last_player_name, setup.player_name);
3488 #if defined(TARGET_SDL2)
3489 SDL_StartTextInput();
3492 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3494 setup.player_name[xpos] = key_char;
3495 setup.player_name[xpos + 1] = 0;
3499 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3503 setup.player_name[xpos] = 0;
3505 else if (key == KSYM_Return && xpos > 0)
3511 game_status = GAME_MODE_MAIN;
3513 else if (key == KSYM_Escape)
3515 strcpy(setup.player_name, last_player_name);
3519 game_status = GAME_MODE_MAIN;
3524 pos->width = (strlen(setup.player_name) + 1) * font_width;
3525 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3527 DrawText(startx, starty, setup.player_name, font_active_nr);
3528 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3532 pos->width = strlen(setup.player_name) * font_width;
3533 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3535 DrawText(startx, starty, setup.player_name, font_nr);
3537 #if defined(TARGET_SDL2)
3538 SDL_StopTextInput();
3544 /* ========================================================================= */
3545 /* tree menu functions */
3546 /* ========================================================================= */
3548 static void DrawChooseTree(TreeInfo **ti_ptr)
3550 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3552 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3554 game_status = GAME_MODE_MAIN;
3556 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3563 FreeScreenGadgets();
3564 CreateScreenGadgets();
3566 CloseDoor(DOOR_CLOSE_2);
3572 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3573 MapScreenTreeGadgets(*ti_ptr);
3580 static void drawChooseTreeList(int first_entry, int num_page_entries,
3584 char *title_string = NULL;
3585 int yoffset_sets = MENU_TITLE1_YPOS;
3586 int yoffset_setup = 16;
3587 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3588 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3589 int last_game_status = game_status; /* save current game status */
3591 title_string = ti->infotext;
3593 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3595 clearMenuListArea();
3597 for (i = 0; i < num_page_entries; i++)
3599 TreeInfo *node, *node_first;
3600 int entry_pos = first_entry + i;
3601 int xpos = MENU_SCREEN_START_XPOS;
3602 int ypos = MENU_SCREEN_START_YPOS + i;
3603 int startx = mSX + xpos * 32;
3604 int starty = mSY + ypos * 32;
3605 int font_nr = FONT_TEXT_1;
3606 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3607 int startx_text = startx + font_xoffset;
3608 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3609 int text_size = startx_scrollbar - startx_text;
3610 int max_buffer_len = text_size / getFontWidth(font_nr);
3611 char buffer[max_buffer_len + 1];
3613 node_first = getTreeInfoFirstGroupEntry(ti);
3614 node = getTreeInfoFromPos(node_first, entry_pos);
3616 strncpy(buffer, node->name, max_buffer_len);
3617 buffer[max_buffer_len] = '\0';
3619 DrawText(startx, starty, buffer, font_nr + node->color);
3621 if (node->parent_link)
3622 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3623 else if (node->level_group)
3624 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3626 initCursor(i, IMG_MENU_BUTTON);
3629 game_status = last_game_status; /* restore current game status */
3631 redraw_mask |= REDRAW_FIELD;
3634 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3636 TreeInfo *node, *node_first;
3637 int x, last_redraw_mask = redraw_mask;
3638 int ypos = MENU_TITLE2_YPOS;
3639 int font_nr = FONT_TITLE_2;
3641 if (ti->type == TREE_TYPE_LEVEL_NR)
3642 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3644 if (ti->type != TREE_TYPE_LEVEL_DIR)
3647 node_first = getTreeInfoFirstGroupEntry(ti);
3648 node = getTreeInfoFromPos(node_first, entry_pos);
3650 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3652 if (node->parent_link)
3653 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3654 node->node_parent->name);
3655 else if (node->level_group)
3656 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3658 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3659 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3660 node->levels, (node->levels > 1 ? "levels" : "level"),
3663 /* let BackToFront() redraw only what is needed */
3664 redraw_mask = last_redraw_mask;
3665 for (x = 0; x < SCR_FIELDX; x++)
3666 MarkTileDirty(x, 1);
3669 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3672 TreeInfo *ti = *ti_ptr;
3674 int y = ti->cl_cursor;
3675 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3676 int num_entries = numTreeInfoInGroup(ti);
3677 int num_page_entries;
3678 int last_game_status = game_status; /* save current game status */
3679 boolean position_set_by_scrollbar = (dx == 999);
3681 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3682 num_page_entries = num_entries;
3684 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3686 game_status = last_game_status; /* restore current game status */
3688 if (button == MB_MENU_INITIALIZE)
3690 int num_entries = numTreeInfoInGroup(ti);
3691 int entry_pos = posTreeInfo(ti);
3693 if (ti->cl_first == -1)
3695 /* only on initialization */
3696 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3697 ti->cl_cursor = entry_pos - ti->cl_first;
3699 else if (ti->cl_cursor >= num_page_entries ||
3700 (num_entries > num_page_entries &&
3701 num_entries - ti->cl_first < num_page_entries))
3703 /* only after change of list size (by custom graphic configuration) */
3704 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3705 ti->cl_cursor = entry_pos - ti->cl_first;
3708 if (position_set_by_scrollbar)
3711 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3714 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3715 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3716 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3720 else if (button == MB_MENU_LEAVE)
3724 PlaySound(SND_MENU_ITEM_SELECTING);
3726 if (ti->node_parent)
3728 *ti_ptr = ti->node_parent;
3729 DrawChooseTree(ti_ptr);
3731 else if (game_status == GAME_MODE_SETUP)
3733 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3734 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3735 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3737 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3738 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3739 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3740 execSetupGraphics();
3741 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3742 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3743 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3745 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3746 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3747 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3754 if (game_status == GAME_MODE_LEVELNR)
3756 int new_level_nr = atoi(level_number_current->identifier);
3758 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3761 game_status = GAME_MODE_MAIN;
3763 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3769 if (mx || my) /* mouse input */
3771 int last_game_status = game_status; /* save current game status */
3773 x = (mx - mSX) / 32;
3774 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3776 game_status = last_game_status; /* restore current game status */
3778 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3780 /* move cursor instead of scrolling when already at start/end of list */
3781 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3783 else if (dy == +1 * SCROLL_LINE &&
3784 ti->cl_first + num_page_entries == num_entries)
3787 /* handle scrolling screen one line or page */
3788 if (ti->cl_cursor + dy < 0 ||
3789 ti->cl_cursor + dy > num_page_entries - 1)
3791 boolean redraw = FALSE;
3793 if (ABS(dy) == SCROLL_PAGE)
3794 step = num_page_entries - 1;
3796 if (dy < 0 && ti->cl_first > 0)
3798 /* scroll page/line up */
3800 ti->cl_first -= step;
3801 if (ti->cl_first < 0)
3806 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3808 /* scroll page/line down */
3810 ti->cl_first += step;
3811 if (ti->cl_first + num_page_entries > num_entries)
3812 ti->cl_first = MAX(0, num_entries - num_page_entries);
3819 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3820 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3821 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3823 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3830 /* handle moving cursor one line */
3831 y = ti->cl_cursor + dy;
3836 TreeInfo *node_first, *node_cursor;
3837 int entry_pos = ti->cl_first + y;
3839 node_first = getTreeInfoFirstGroupEntry(ti);
3840 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3842 if (node_cursor->node_group)
3846 PlaySound(SND_MENU_ITEM_SELECTING);
3848 node_cursor->cl_first = ti->cl_first;
3849 node_cursor->cl_cursor = ti->cl_cursor;
3850 *ti_ptr = node_cursor->node_group;
3851 DrawChooseTree(ti_ptr);
3856 else if (dx == -1 && ti->node_parent)
3860 PlaySound(SND_MENU_ITEM_SELECTING);
3862 *ti_ptr = ti->node_parent;
3863 DrawChooseTree(ti_ptr);
3868 if (!anyScrollbarGadgetActive() &&
3869 IN_VIS_MENU(x, y) &&
3870 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3871 y >= 0 && y < num_page_entries)
3875 if (y != ti->cl_cursor)
3877 PlaySound(SND_MENU_ITEM_ACTIVATING);
3879 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3880 drawChooseTreeCursor(y, TRUE);
3881 drawChooseTreeInfo(ti->cl_first + y, ti);
3888 TreeInfo *node_first, *node_cursor;
3889 int entry_pos = ti->cl_first + y;
3891 PlaySound(SND_MENU_ITEM_SELECTING);
3893 node_first = getTreeInfoFirstGroupEntry(ti);
3894 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3896 if (node_cursor->node_group)
3900 node_cursor->cl_first = ti->cl_first;
3901 node_cursor->cl_cursor = ti->cl_cursor;
3902 *ti_ptr = node_cursor->node_group;
3903 DrawChooseTree(ti_ptr);
3905 else if (node_cursor->parent_link)
3909 *ti_ptr = node_cursor->node_parent;
3910 DrawChooseTree(ti_ptr);
3916 node_cursor->cl_first = ti->cl_first;
3917 node_cursor->cl_cursor = ti->cl_cursor;
3918 *ti_ptr = node_cursor;
3920 if (ti->type == TREE_TYPE_LEVEL_DIR)
3922 LoadLevelSetup_SeriesInfo();
3924 SaveLevelSetup_LastSeries();
3925 SaveLevelSetup_SeriesInfo();
3929 if (game_status == GAME_MODE_SETUP)
3931 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3932 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3933 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3935 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3936 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3937 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3938 execSetupGraphics();
3939 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3940 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3941 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3943 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3944 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3945 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3952 if (game_status == GAME_MODE_LEVELNR)
3954 int new_level_nr = atoi(level_number_current->identifier);
3956 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3959 game_status = GAME_MODE_MAIN;
3968 void DrawChooseLevelSet()
3970 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3972 DrawChooseTree(&leveldir_current);
3978 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3980 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3983 void DrawChooseLevelNr()
3987 if (level_number != NULL)
3989 freeTreeInfo(level_number);
3991 level_number = NULL;
3994 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3996 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3997 char identifier[32], name[32];
4000 /* temporarily load level info to get level name */
4001 LoadLevelInfoOnly(i);
4003 ti->node_top = &level_number;
4004 ti->sort_priority = 10000 + value;
4005 ti->color = (level.no_valid_file ? FC_BLUE :
4006 LevelStats_getSolved(i) ? FC_GREEN :
4007 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4009 sprintf(identifier, "%d", value);
4010 sprintf(name, "%03d: %s", value,
4011 (level.no_valid_file ? "(no file)" : level.name));
4013 setString(&ti->identifier, identifier);
4014 setString(&ti->name, name);
4015 setString(&ti->name_sorting, name);
4017 pushTreeInfo(&level_number, ti);
4020 /* sort level number values to start with lowest level number */
4021 sortTreeInfo(&level_number);
4023 /* set current level number to current level number */
4024 level_number_current =
4025 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4027 /* if that also fails, set current level number to first available level */
4028 if (level_number_current == NULL)
4029 level_number_current = level_number;
4031 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4033 DrawChooseTree(&level_number_current);
4039 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4041 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4044 void DrawHallOfFame(int highlight_position)
4046 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
4049 FadeSoundsAndMusic();
4051 /* (this is needed when called from GameEnd() after winning a game) */
4052 KeyboardAutoRepeatOn();
4055 /* (this is needed when called from GameEnd() after winning a game) */
4056 SetDrawDeactivationMask(REDRAW_NONE);
4057 SetDrawBackgroundMask(REDRAW_FIELD);
4059 CloseDoor(DOOR_CLOSE_ALL);
4061 if (highlight_position < 0)
4062 LoadScore(level_nr);
4064 FadeSetEnterScreen();
4073 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4078 static void drawHallOfFameList(int first_entry, int highlight_position)
4082 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4085 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4086 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4087 "HighScores of Level %d", level_nr);
4089 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4091 int entry = first_entry + i;
4092 boolean active = (entry == highlight_position);
4093 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4094 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4095 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4096 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4097 int dx1 = 3 * getFontWidth(font_nr1);
4098 int dx2 = dx1 + getFontWidth(font_nr1);
4099 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4100 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4101 int sy = mSY + 64 + i * 32;
4103 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4104 DrawText(mSX + dx1, sy, ".", font_nr1);
4106 for (j = 0; j < num_dots; j++)
4107 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4109 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4110 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4112 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4115 redraw_mask |= REDRAW_FIELD;
4118 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4120 static int first_entry = 0;
4121 static int highlight_position = 0;
4122 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4124 if (button == MB_MENU_INITIALIZE)
4127 highlight_position = mx;
4128 drawHallOfFameList(first_entry, highlight_position);
4133 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4134 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4138 if (first_entry > 0)
4140 first_entry -= step;
4141 if (first_entry < 0)
4144 drawHallOfFameList(first_entry, highlight_position);
4149 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4151 first_entry += step;
4152 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4153 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4155 drawHallOfFameList(first_entry, highlight_position);
4158 else if (button == MB_MENU_LEAVE)
4160 PlaySound(SND_MENU_ITEM_SELECTING);
4162 FadeSound(SND_BACKGROUND_SCORES);
4164 game_status = GAME_MODE_MAIN;
4168 else if (button == MB_MENU_CHOICE)
4170 PlaySound(SND_MENU_ITEM_SELECTING);
4172 FadeSound(SND_BACKGROUND_SCORES);
4174 game_status = GAME_MODE_MAIN;
4176 DrawAndFadeInMainMenu(REDRAW_FIELD);
4179 if (game_status == GAME_MODE_SCORES)
4180 PlayMenuSoundIfLoop();
4184 /* ========================================================================= */
4185 /* setup screen functions */
4186 /* ========================================================================= */
4188 static struct TokenInfo *setup_info;
4189 static int num_setup_info; /* number of setup entries shown on screen */
4190 static int max_setup_info; /* total number of setup entries in list */
4192 static char *screen_mode_text;
4193 static char *window_size_text;
4194 static char *scaling_type_text;
4195 static char *scroll_delay_text;
4196 static char *snapshot_mode_text;
4197 static char *game_speed_text;
4198 static char *graphics_set_name;
4199 static char *sounds_set_name;
4200 static char *music_set_name;
4201 static char *volume_simple_text;
4202 static char *volume_loops_text;
4203 static char *volume_music_text;
4204 static char *touch_controls_text;
4205 static char *move_distance_text;
4206 static char *drop_distance_text;
4208 static void execSetupMain()
4210 setup_mode = SETUP_MODE_MAIN;
4215 static void execSetupGame_setGameSpeeds()
4217 if (game_speeds == NULL)
4221 for (i = 0; game_speeds_list[i].value != -1; i++)
4223 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4224 char identifier[32], name[32];
4225 int value = game_speeds_list[i].value;
4226 char *text = game_speeds_list[i].text;
4228 ti->node_top = &game_speeds;
4229 ti->sort_priority = 10000 - value;
4231 sprintf(identifier, "%d", value);
4232 sprintf(name, "%s", text);
4234 setString(&ti->identifier, identifier);
4235 setString(&ti->name, name);
4236 setString(&ti->name_sorting, name);
4237 setString(&ti->infotext, "Game Speed");
4239 pushTreeInfo(&game_speeds, ti);
4242 /* sort game speed values to start with slowest game speed */
4243 sortTreeInfo(&game_speeds);
4245 /* set current game speed to configured game speed value */
4246 game_speed_current =
4247 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4249 /* if that fails, set current game speed to reliable default value */
4250 if (game_speed_current == NULL)
4251 game_speed_current =
4252 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4254 /* if that also fails, set current game speed to first available speed */
4255 if (game_speed_current == NULL)
4256 game_speed_current = game_speeds;
4259 setup.game_frame_delay = atoi(game_speed_current->identifier);
4261 /* needed for displaying game speed text instead of identifier */
4262 game_speed_text = game_speed_current->name;
4265 static void execSetupGame_setScrollDelays()
4267 if (scroll_delays == NULL)
4271 for (i = 0; scroll_delays_list[i].value != -1; i++)
4273 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4274 char identifier[32], name[32];
4275 int value = scroll_delays_list[i].value;
4276 char *text = scroll_delays_list[i].text;
4278 ti->node_top = &scroll_delays;
4279 ti->sort_priority = value;
4281 sprintf(identifier, "%d", value);
4282 sprintf(name, "%s", text);
4284 setString(&ti->identifier, identifier);
4285 setString(&ti->name, name);
4286 setString(&ti->name_sorting, name);
4287 setString(&ti->infotext, "Scaling Type");
4289 pushTreeInfo(&scroll_delays, ti);
4292 /* sort scaling type values to start with lowest scaling type value */
4293 sortTreeInfo(&scroll_delays);
4295 /* set current scaling type value to configured scaling type value */
4296 scroll_delay_current =
4297 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4299 /* if that fails, set current scaling type to reliable default value */
4300 if (scroll_delay_current == NULL)
4301 scroll_delay_current =
4302 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4304 /* if that also fails, set current scaling type to first available value */
4305 if (scroll_delay_current == NULL)
4306 scroll_delay_current = scroll_delays;
4309 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4311 /* needed for displaying scaling type text instead of identifier */
4312 scroll_delay_text = scroll_delay_current->name;
4315 static void execSetupGame_setSnapshotModes()
4317 if (snapshot_modes == NULL)
4321 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4323 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4324 char identifier[32], name[32];
4325 char *value = snapshot_modes_list[i].value;
4326 char *text = snapshot_modes_list[i].text;
4328 ti->node_top = &snapshot_modes;
4329 ti->sort_priority = i;
4331 sprintf(identifier, "%s", value);
4332 sprintf(name, "%s", text);
4334 setString(&ti->identifier, identifier);
4335 setString(&ti->name, name);
4336 setString(&ti->name_sorting, name);
4337 setString(&ti->infotext, "Snapshot Mode");
4339 pushTreeInfo(&snapshot_modes, ti);
4342 /* sort snapshot mode values to start with lowest snapshot mode value */
4343 sortTreeInfo(&snapshot_modes);
4345 /* set current snapshot mode value to configured snapshot mode value */
4346 snapshot_mode_current =
4347 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4349 /* if that fails, set current snapshot mode to reliable default value */
4350 if (snapshot_mode_current == NULL)
4351 snapshot_mode_current =
4352 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4354 /* if that also fails, set current snapshot mode to first available value */
4355 if (snapshot_mode_current == NULL)
4356 snapshot_mode_current = snapshot_modes;
4359 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4361 /* needed for displaying snapshot mode text instead of identifier */
4362 snapshot_mode_text = snapshot_mode_current->name;
4365 static void execSetupGame()
4367 execSetupGame_setGameSpeeds();
4368 execSetupGame_setScrollDelays();
4369 execSetupGame_setSnapshotModes();
4371 setup_mode = SETUP_MODE_GAME;
4376 static void execSetupChooseGameSpeed()
4378 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4383 static void execSetupChooseScrollDelay()
4385 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4390 static void execSetupChooseSnapshotMode()
4392 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4397 static void execSetupEditor()
4399 setup_mode = SETUP_MODE_EDITOR;
4404 static void execSetupGraphics_setWindowSizes(boolean update_list)
4406 if (window_sizes != NULL && update_list)
4408 freeTreeInfo(window_sizes);
4410 window_sizes = NULL;
4413 if (window_sizes == NULL)
4415 boolean current_window_size_found = FALSE;
4418 for (i = 0; window_sizes_list[i].value != -1; i++)
4420 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4421 char identifier[32], name[32];
4422 int value = window_sizes_list[i].value;
4423 char *text = window_sizes_list[i].text;
4425 ti->node_top = &window_sizes;
4426 ti->sort_priority = value;
4428 sprintf(identifier, "%d", value);
4429 sprintf(name, "%s", text);
4431 setString(&ti->identifier, identifier);
4432 setString(&ti->name, name);
4433 setString(&ti->name_sorting, name);
4434 setString(&ti->infotext, "Window Scaling");
4436 pushTreeInfo(&window_sizes, ti);
4438 if (value == setup.window_scaling_percent)
4439 current_window_size_found = TRUE;
4442 if (!current_window_size_found)
4444 // add entry for non-preset window scaling value
4446 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4447 char identifier[32], name[32];
4448 int value = setup.window_scaling_percent;
4450 ti->node_top = &window_sizes;
4451 ti->sort_priority = value;
4453 sprintf(identifier, "%d", value);
4454 sprintf(name, "%d %% (Current)", value);
4456 setString(&ti->identifier, identifier);
4457 setString(&ti->name, name);
4458 setString(&ti->name_sorting, name);
4459 setString(&ti->infotext, "Window Scaling");
4461 pushTreeInfo(&window_sizes, ti);
4464 /* sort window size values to start with lowest window size value */
4465 sortTreeInfo(&window_sizes);
4467 /* set current window size value to configured window size value */
4468 window_size_current =
4469 getTreeInfoFromIdentifier(window_sizes,
4470 i_to_a(setup.window_scaling_percent));
4472 /* if that fails, set current window size to reliable default value */
4473 if (window_size_current == NULL)
4474 window_size_current =
4475 getTreeInfoFromIdentifier(window_sizes,
4476 i_to_a(STD_WINDOW_SCALING_PERCENT));
4478 /* if that also fails, set current window size to first available value */
4479 if (window_size_current == NULL)
4480 window_size_current = window_sizes;
4483 setup.window_scaling_percent = atoi(window_size_current->identifier);
4485 /* needed for displaying window size text instead of identifier */
4486 window_size_text = window_size_current->name;
4489 static void execSetupGraphics_setScalingTypes()
4491 if (scaling_types == NULL)
4495 for (i = 0; scaling_types_list[i].value != NULL; i++)
4497 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4498 char identifier[32], name[32];
4499 char *value = scaling_types_list[i].value;
4500 char *text = scaling_types_list[i].text;
4502 ti->node_top = &scaling_types;
4503 ti->sort_priority = i;
4505 sprintf(identifier, "%s", value);
4506 sprintf(name, "%s", text);
4508 setString(&ti->identifier, identifier);
4509 setString(&ti->name, name);
4510 setString(&ti->name_sorting, name);
4511 setString(&ti->infotext, "Anti-Aliasing");
4513 pushTreeInfo(&scaling_types, ti);
4516 /* sort scaling type values to start with lowest scaling type value */
4517 sortTreeInfo(&scaling_types);
4519 /* set current scaling type value to configured scaling type value */
4520 scaling_type_current =
4521 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4523 /* if that fails, set current scaling type to reliable default value */
4524 if (scaling_type_current == NULL)
4525 scaling_type_current =
4526 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4528 /* if that also fails, set current scaling type to first available value */
4529 if (scaling_type_current == NULL)
4530 scaling_type_current = scaling_types;
4533 setup.window_scaling_quality = scaling_type_current->identifier;
4535 /* needed for displaying scaling type text instead of identifier */
4536 scaling_type_text = scaling_type_current->name;
4539 static void execSetupGraphics_setScreenModes()
4541 // if (screen_modes == NULL && video.fullscreen_available)
4542 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4546 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4548 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4549 char identifier[32], name[32];
4550 int x = video.fullscreen_modes[i].width;
4551 int y = video.fullscreen_modes[i].height;
4554 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4556 ti->node_top = &screen_modes;
4557 ti->sort_priority = x * 10000 + y;
4559 sprintf(identifier, "%dx%d", x, y);
4560 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4562 setString(&ti->identifier, identifier);
4563 setString(&ti->name, name);
4564 setString(&ti->name_sorting, name);
4565 setString(&ti->infotext, "Fullscreen Mode");
4567 pushTreeInfo(&screen_modes, ti);
4570 /* sort fullscreen modes to start with lowest available screen resolution */
4571 sortTreeInfo(&screen_modes);
4573 /* set current screen mode for fullscreen mode to configured setup value */
4574 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4575 setup.fullscreen_mode);
4577 /* if that fails, set current screen mode to reliable default value */
4578 if (screen_mode_current == NULL)
4579 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4580 DEFAULT_FULLSCREEN_MODE);
4582 /* if that also fails, set current screen mode to first available mode */
4583 if (screen_mode_current == NULL)
4584 screen_mode_current = screen_modes;
4586 if (screen_mode_current == NULL)
4587 video.fullscreen_available = FALSE;
4590 // if (video.fullscreen_available)
4591 if (screen_mode_current != NULL)
4593 setup.fullscreen_mode = screen_mode_current->identifier;
4595 /* needed for displaying screen mode name instead of identifier */
4596 screen_mode_text = screen_mode_current->name;
4600 static void execSetupGraphics()
4602 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4604 // update "setup.window_scaling_percent" from list selection
4605 execSetupGraphics_setWindowSizes(FALSE);
4609 // update list selection from "setup.window_scaling_percent"
4610 execSetupGraphics_setWindowSizes(TRUE);
4613 execSetupGraphics_setScalingTypes();
4614 execSetupGraphics_setScreenModes();
4616 setup_mode = SETUP_MODE_GRAPHICS;
4620 #if defined(TARGET_SDL2)
4621 // window scaling may have changed at this point
4622 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4624 // window scaling quality may have changed at this point
4625 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4626 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4630 #if !defined(PLATFORM_ANDROID)
4631 #if defined(TARGET_SDL2)
4632 static void execSetupChooseWindowSize()
4634 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4639 static void execSetupChooseScalingType()
4641 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4646 static void execSetupChooseScreenMode()
4648 if (!video.fullscreen_available)
4651 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4658 static void execSetupChooseVolumeSimple()
4660 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4665 static void execSetupChooseVolumeLoops()
4667 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4672 static void execSetupChooseVolumeMusic()
4674 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4679 static void execSetupSound()
4681 if (volumes_simple == NULL)
4683 boolean current_volume_simple_found = FALSE;
4686 for (i = 0; volumes_list[i].value != -1; i++)
4688 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4689 char identifier[32], name[32];
4690 int value = volumes_list[i].value;
4691 char *text = volumes_list[i].text;
4693 ti->node_top = &volumes_simple;
4694 ti->sort_priority = value;
4696 sprintf(identifier, "%d", value);
4697 sprintf(name, "%s", text);
4699 setString(&ti->identifier, identifier);
4700 setString(&ti->name, name);
4701 setString(&ti->name_sorting, name);
4702 setString(&ti->infotext, "Sound Volume");
4704 pushTreeInfo(&volumes_simple, ti);
4706 if (value == setup.volume_simple)
4707 current_volume_simple_found = TRUE;
4710 if (!current_volume_simple_found)
4712 // add entry for non-preset volume value
4714 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4715 char identifier[32], name[32];
4716 int value = setup.volume_simple;
4718 ti->node_top = &volumes_simple;
4719 ti->sort_priority = value;
4721 sprintf(identifier, "%d", value);
4722 sprintf(name, "%d %% (Current)", value);
4724 setString(&ti->identifier, identifier);
4725 setString(&ti->name, name);
4726 setString(&ti->name_sorting, name);
4727 setString(&ti->infotext, "Sound Volume");
4729 pushTreeInfo(&volumes_simple, ti);
4732 /* sort volume values to start with lowest volume value */
4733 sortTreeInfo(&volumes_simple);
4735 /* set current volume value to configured volume value */
4736 volume_simple_current =
4737 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4739 /* if that fails, set current volume to reliable default value */
4740 if (volume_simple_current == NULL)
4741 volume_simple_current =
4742 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4744 /* if that also fails, set current volume to first available value */
4745 if (volume_simple_current == NULL)
4746 volume_simple_current = volumes_simple;
4749 if (volumes_loops == NULL)
4751 boolean current_volume_loops_found = FALSE;
4754 for (i = 0; volumes_list[i].value != -1; i++)
4756 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4757 char identifier[32], name[32];
4758 int value = volumes_list[i].value;
4759 char *text = volumes_list[i].text;
4761 ti->node_top = &volumes_loops;
4762 ti->sort_priority = value;
4764 sprintf(identifier, "%d", value);
4765 sprintf(name, "%s", text);
4767 setString(&ti->identifier, identifier);
4768 setString(&ti->name, name);
4769 setString(&ti->name_sorting, name);
4770 setString(&ti->infotext, "Loops Volume");
4772 pushTreeInfo(&volumes_loops, ti);
4774 if (value == setup.volume_loops)
4775 current_volume_loops_found = TRUE;
4778 if (!current_volume_loops_found)
4780 // add entry for non-preset volume value
4782 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4783 char identifier[32], name[32];
4784 int value = setup.volume_loops;
4786 ti->node_top = &volumes_loops;
4787 ti->sort_priority = value;
4789 sprintf(identifier, "%d", value);
4790 sprintf(name, "%d %% (Current)", value);
4792 setString(&ti->identifier, identifier);
4793 setString(&ti->name, name);
4794 setString(&ti->name_sorting, name);
4795 setString(&ti->infotext, "Loops Volume");
4797 pushTreeInfo(&volumes_loops, ti);
4800 /* sort volume values to start with lowest volume value */
4801 sortTreeInfo(&volumes_loops);
4803 /* set current volume value to configured volume value */
4804 volume_loops_current =
4805 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4807 /* if that fails, set current volume to reliable default value */
4808 if (volume_loops_current == NULL)
4809 volume_loops_current =
4810 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4812 /* if that also fails, set current volume to first available value */
4813 if (volume_loops_current == NULL)
4814 volume_loops_current = volumes_loops;
4817 if (volumes_music == NULL)
4819 boolean current_volume_music_found = FALSE;
4822 for (i = 0; volumes_list[i].value != -1; i++)
4824 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4825 char identifier[32], name[32];
4826 int value = volumes_list[i].value;
4827 char *text = volumes_list[i].text;
4829 ti->node_top = &volumes_music;
4830 ti->sort_priority = value;
4832 sprintf(identifier, "%d", value);
4833 sprintf(name, "%s", text);
4835 setString(&ti->identifier, identifier);
4836 setString(&ti->name, name);
4837 setString(&ti->name_sorting, name);
4838 setString(&ti->infotext, "Music Volume");
4840 pushTreeInfo(&volumes_music, ti);
4842 if (value == setup.volume_music)
4843 current_volume_music_found = TRUE;
4846 if (!current_volume_music_found)
4848 // add entry for non-preset volume value
4850 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4851 char identifier[32], name[32];
4852 int value = setup.volume_music;
4854 ti->node_top = &volumes_music;
4855 ti->sort_priority = value;
4857 sprintf(identifier, "%d", value);
4858 sprintf(name, "%d %% (Current)", value);
4860 setString(&ti->identifier, identifier);
4861 setString(&ti->name, name);
4862 setString(&ti->name_sorting, name);
4863 setString(&ti->infotext, "Music Volume");
4865 pushTreeInfo(&volumes_music, ti);
4868 /* sort volume values to start with lowest volume value */
4869 sortTreeInfo(&volumes_music);
4871 /* set current volume value to configured volume value */
4872 volume_music_current =
4873 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4875 /* if that fails, set current volume to reliable default value */
4876 if (volume_music_current == NULL)
4877 volume_music_current =
4878 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4880 /* if that also fails, set current volume to first available value */
4881 if (volume_music_current == NULL)
4882 volume_music_current = volumes_music;
4885 setup.volume_simple = atoi(volume_simple_current->identifier);
4886 setup.volume_loops = atoi(volume_loops_current->identifier);
4887 setup.volume_music = atoi(volume_music_current->identifier);
4889 /* needed for displaying volume text instead of identifier */
4890 volume_simple_text = volume_simple_current->name;
4891 volume_loops_text = volume_loops_current->name;
4892 volume_music_text = volume_music_current->name;
4894 setup_mode = SETUP_MODE_SOUND;
4899 static void execSetupChooseTouchControls()
4901 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4906 static void execSetupChooseMoveDistance()
4908 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4913 static void execSetupChooseDropDistance()
4915 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4920 static void execSetupTouch()
4922 if (touch_controls == NULL)
4926 for (i = 0; touch_controls_list[i].value != NULL; i++)
4928 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4929 char identifier[32], name[32];
4930 char *value = touch_controls_list[i].value;
4931 char *text = touch_controls_list[i].text;
4933 ti->node_top = &touch_controls;
4934 ti->sort_priority = i;
4936 sprintf(identifier, "%s", value);
4937 sprintf(name, "%s", text);
4939 setString(&ti->identifier, identifier);
4940 setString(&ti->name, name);
4941 setString(&ti->name_sorting, name);
4942 setString(&ti->infotext, "Control Type");
4944 pushTreeInfo(&touch_controls, ti);
4947 /* sort touch control values to start with lowest touch control value */
4948 sortTreeInfo(&touch_controls);
4950 /* set current touch control value to configured touch control value */
4951 touch_control_current =
4952 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4954 /* if that fails, set current touch control to reliable default value */
4955 if (touch_control_current == NULL)
4956 touch_control_current =
4957 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4959 /* if that also fails, set current touch control to first available value */
4960 if (touch_control_current == NULL)
4961 touch_control_current = touch_controls;
4964 if (move_distances == NULL)
4968 for (i = 0; distances_list[i].value != -1; i++)
4970 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4971 char identifier[32], name[32];
4972 int value = distances_list[i].value;
4973 char *text = distances_list[i].text;
4975 ti->node_top = &move_distances;
4976 ti->sort_priority = value;
4978 sprintf(identifier, "%d", value);
4979 sprintf(name, "%s", text);
4981 setString(&ti->identifier, identifier);
4982 setString(&ti->name, name);
4983 setString(&ti->name_sorting, name);
4984 setString(&ti->infotext, "Move Distance");
4986 pushTreeInfo(&move_distances, ti);
4989 /* sort distance values to start with lowest distance value */
4990 sortTreeInfo(&move_distances);
4992 /* set current distance value to configured distance value */
4993 move_distance_current =
4994 getTreeInfoFromIdentifier(move_distances,
4995 i_to_a(setup.touch.move_distance));
4997 /* if that fails, set current distance to reliable default value */
4998 if (move_distance_current == NULL)
4999 move_distance_current =
5000 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5002 /* if that also fails, set current distance to first available value */
5003 if (move_distance_current == NULL)
5004 move_distance_current = move_distances;
5007 if (drop_distances == NULL)
5011 for (i = 0; distances_list[i].value != -1; i++)
5013 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5014 char identifier[32], name[32];
5015 int value = distances_list[i].value;
5016 char *text = distances_list[i].text;
5018 ti->node_top = &drop_distances;
5019 ti->sort_priority = value;
5021 sprintf(identifier, "%d", value);
5022 sprintf(name, "%s", text);
5024 setString(&ti->identifier, identifier);
5025 setString(&ti->name, name);
5026 setString(&ti->name_sorting, name);
5027 setString(&ti->infotext, "Drop Distance");
5029 pushTreeInfo(&drop_distances, ti);
5032 /* sort distance values to start with lowest distance value */
5033 sortTreeInfo(&drop_distances);
5035 /* set current distance value to configured distance value */
5036 drop_distance_current =
5037 getTreeInfoFromIdentifier(drop_distances,
5038 i_to_a(setup.touch.drop_distance));
5040 /* if that fails, set current distance to reliable default value */
5041 if (drop_distance_current == NULL)
5042 drop_distance_current =
5043 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5045 /* if that also fails, set current distance to first available value */
5046 if (drop_distance_current == NULL)
5047 drop_distance_current = drop_distances;
5050 setup.touch.control_type = touch_control_current->identifier;
5051 setup.touch.move_distance = atoi(move_distance_current->identifier);
5052 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5054 /* needed for displaying volume text instead of identifier */
5055 touch_controls_text = touch_control_current->name;
5056 move_distance_text = move_distance_current->name;
5057 drop_distance_text = drop_distance_current->name;
5059 setup_mode = SETUP_MODE_TOUCH;
5064 static void execSetupArtwork()
5067 printf("::: '%s', '%s', '%s'\n",
5068 artwork.gfx_current->subdir,
5069 artwork.gfx_current->fullpath,
5070 artwork.gfx_current->basepath);
5073 setup.graphics_set = artwork.gfx_current->identifier;
5074 setup.sounds_set = artwork.snd_current->identifier;
5075 setup.music_set = artwork.mus_current->identifier;
5077 /* needed if last screen (setup choice) changed graphics, sounds or music */
5078 ReloadCustomArtwork(0);
5080 /* needed for displaying artwork name instead of artwork identifier */
5081 graphics_set_name = artwork.gfx_current->name;
5082 sounds_set_name = artwork.snd_current->name;
5083 music_set_name = artwork.mus_current->name;
5085 setup_mode = SETUP_MODE_ARTWORK;
5090 static void execSetupChooseGraphics()
5092 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5097 static void execSetupChooseSounds()
5099 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5104 static void execSetupChooseMusic()
5106 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5111 #if !defined(PLATFORM_ANDROID)
5112 static void execSetupInput()
5114 setup_mode = SETUP_MODE_INPUT;
5120 static void execSetupShortcuts()
5122 setup_mode = SETUP_MODE_SHORTCUTS;
5127 static void execSetupShortcuts1()
5129 setup_mode = SETUP_MODE_SHORTCUTS_1;
5134 static void execSetupShortcuts2()
5136 setup_mode = SETUP_MODE_SHORTCUTS_2;
5141 static void execSetupShortcuts3()
5143 setup_mode = SETUP_MODE_SHORTCUTS_3;
5148 static void execSetupShortcuts4()
5150 setup_mode = SETUP_MODE_SHORTCUTS_4;
5155 static void execSetupShortcuts5()
5157 setup_mode = SETUP_MODE_SHORTCUTS_5;
5162 static void execExitSetup()
5164 game_status = GAME_MODE_MAIN;
5166 DrawMainMenuExt(REDRAW_FIELD, FALSE);
5169 static void execSaveAndExitSetup()
5175 static struct TokenInfo setup_info_main[] =
5177 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5178 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5179 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5180 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5181 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5182 #if !defined(PLATFORM_ANDROID)
5183 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5184 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5186 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5188 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5189 { TYPE_EMPTY, NULL, "" },
5190 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5191 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5196 static struct TokenInfo setup_info_game[] =
5198 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5199 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5200 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5201 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5202 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5203 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5204 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5205 { TYPE_STRING, &game_speed_text, "" },
5207 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5208 { TYPE_STRING, &scroll_delay_text, "" },
5210 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5211 { TYPE_STRING, &snapshot_mode_text, "" },
5212 { TYPE_EMPTY, NULL, "" },
5213 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5218 static struct TokenInfo setup_info_editor[] =
5221 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5222 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5223 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5224 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5225 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5226 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5227 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5228 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5230 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5231 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5232 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5234 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5236 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5237 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5238 { TYPE_EMPTY, NULL, "" },
5240 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5241 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5242 { TYPE_EMPTY, NULL, "" },
5244 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5245 { TYPE_EMPTY, NULL, "" },
5246 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5251 static struct TokenInfo setup_info_graphics[] =
5253 #if !defined(PLATFORM_ANDROID)
5254 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5255 #if defined(TARGET_SDL2)
5256 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5257 { TYPE_STRING, &window_size_text, "" },
5258 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5259 { TYPE_STRING, &scaling_type_text, "" },
5261 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5262 { TYPE_STRING, &screen_mode_text, "" },
5266 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5267 { TYPE_STRING, &scroll_delay_text, "" },
5269 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5270 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5271 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5272 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5273 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5274 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5275 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5276 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5277 { TYPE_EMPTY, NULL, "" },
5278 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5283 static struct TokenInfo setup_info_sound[] =
5285 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5286 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5287 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5288 { TYPE_EMPTY, NULL, "" },
5289 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5290 { TYPE_STRING, &volume_simple_text, "" },
5291 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5292 { TYPE_STRING, &volume_loops_text, "" },
5293 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5294 { TYPE_STRING, &volume_music_text, "" },
5295 { TYPE_EMPTY, NULL, "" },
5296 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5301 static struct TokenInfo setup_info_artwork[] =
5303 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5304 { TYPE_STRING, &graphics_set_name, "" },
5305 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5306 { TYPE_STRING, &sounds_set_name, "" },
5307 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5308 { TYPE_STRING, &music_set_name, "" },
5309 { TYPE_EMPTY, NULL, "" },
5310 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5311 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5312 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5313 { TYPE_EMPTY, NULL, "" },
5314 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5319 static struct TokenInfo setup_info_input[] =
5321 { TYPE_SWITCH, NULL, "Player:" },
5322 { TYPE_SWITCH, NULL, "Device:" },
5323 { TYPE_ENTER_MENU, NULL, "" },
5324 { TYPE_EMPTY, NULL, "" },
5325 { TYPE_EMPTY, NULL, "" },
5326 { TYPE_EMPTY, NULL, "" },
5327 { TYPE_EMPTY, NULL, "" },
5328 { TYPE_EMPTY, NULL, "" },
5329 { TYPE_EMPTY, NULL, "" },
5330 { TYPE_EMPTY, NULL, "" },
5331 { TYPE_EMPTY, NULL, "" },
5332 { TYPE_EMPTY, NULL, "" },
5333 { TYPE_EMPTY, NULL, "" },
5334 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5339 static struct TokenInfo setup_info_touch[] =
5341 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5342 { TYPE_STRING, &touch_controls_text, "" },
5343 { TYPE_EMPTY, NULL, "" },
5344 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5345 { TYPE_STRING, &move_distance_text, "" },
5346 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5347 { TYPE_STRING, &drop_distance_text, "" },
5348 { TYPE_EMPTY, NULL, "" },
5349 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5354 static struct TokenInfo setup_info_shortcuts[] =
5356 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5357 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5358 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5359 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5360 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5361 { TYPE_EMPTY, NULL, "" },
5362 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5367 static struct TokenInfo setup_info_shortcuts_1[] =
5369 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5370 { TYPE_KEY, &setup.shortcut.save_game, "" },
5371 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5372 { TYPE_KEY, &setup.shortcut.load_game, "" },
5373 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5374 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5375 { TYPE_EMPTY, NULL, "" },
5376 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5377 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5378 { TYPE_EMPTY, NULL, "" },
5379 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5384 static struct TokenInfo setup_info_shortcuts_2[] =
5386 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5387 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5388 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5389 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5390 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5391 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5392 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5393 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5394 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5395 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5396 { TYPE_EMPTY, NULL, "" },
5397 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5402 static struct TokenInfo setup_info_shortcuts_3[] =
5404 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5405 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5406 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5407 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5408 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5409 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5410 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5411 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5412 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5413 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5414 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5415 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5416 { TYPE_EMPTY, NULL, "" },
5417 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5422 static struct TokenInfo setup_info_shortcuts_4[] =
5424 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5425 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5426 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5427 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5428 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5429 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5430 { TYPE_EMPTY, NULL, "" },
5431 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5436 static struct TokenInfo setup_info_shortcuts_5[] =
5438 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5439 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5440 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5441 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5442 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5443 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5444 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5445 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5446 { TYPE_EMPTY, NULL, "" },
5447 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5452 static Key getSetupKey()
5454 Key key = KSYM_UNDEFINED;
5455 boolean got_key_event = FALSE;
5457 while (!got_key_event)
5459 if (PendingEvent()) /* got event */
5467 case EVENT_KEYPRESS:
5469 key = GetEventKey((KeyEvent *)&event, TRUE);
5471 /* press 'Escape' or 'Enter' to keep the existing key binding */
5472 if (key == KSYM_Escape || key == KSYM_Return)
5473 key = KSYM_UNDEFINED; /* keep old value */
5475 got_key_event = TRUE;
5479 case EVENT_KEYRELEASE:
5480 key_joystick_mapping = 0;
5484 HandleOtherEvents(&event);
5492 /* don't eat all CPU time */
5499 static int getSetupTextFont(int type)
5501 if (type & (TYPE_SWITCH |
5513 static int getSetupValueFont(int type, void *value)
5515 if (type & TYPE_KEY)
5516 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5517 else if (type & TYPE_STRING)
5518 return FONT_VALUE_2;
5519 else if (type & TYPE_ECS_AGA)
5520 return FONT_VALUE_1;
5521 else if (type & TYPE_BOOLEAN_STYLE)
5522 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5523 else if (type & TYPE_YES_NO_AUTO)
5524 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5525 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5527 return FONT_VALUE_1;
5530 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5532 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5533 struct TokenInfo *si = &setup_info[si_pos];
5534 boolean font_draw_xoffset_modified = FALSE;
5535 int font_draw_xoffset_old = -1;
5536 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5537 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5538 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5539 int xpos = menu_screen_value_xpos;
5540 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5541 int startx = mSX + xpos * 32;
5542 int starty = mSY + ypos * 32;
5543 int font_nr, font_width;
5544 int type = si->type;
5545 void *value = si->value;
5546 char *value_string = getSetupValue(type, value);
5549 if (value_string == NULL)
5552 if (type & TYPE_KEY)
5554 xpos = MENU_SCREEN_START_XPOS;
5556 if (type & TYPE_QUERY)
5557 value_string = "<press key>";
5559 else if (type & TYPE_STRING)
5561 int max_value_len = (SCR_FIELDX - 2) * 2;
5563 xpos = MENU_SCREEN_START_XPOS;
5565 if (strlen(value_string) > max_value_len)
5566 value_string[max_value_len] = '\0';
5568 else if (type & TYPE_YES_NO_AUTO)
5570 xpos = menu_screen_value_xpos - 1;
5573 startx = mSX + xpos * 32;
5574 starty = mSY + ypos * 32;
5575 font_nr = getSetupValueFont(type, value);
5576 font_width = getFontWidth(font_nr);
5578 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5579 if (setup_mode != SETUP_MODE_INPUT)
5581 int max_menu_text_length_big = (menu_screen_value_xpos -
5582 MENU_SCREEN_START_XPOS);
5583 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5584 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5585 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5586 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5587 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5588 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5589 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5590 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5591 boolean correct_font_draw_xoffset = FALSE;
5593 if (xpos == MENU_SCREEN_START_XPOS &&
5594 startx + font1_xoffset < text_startx + text_font_xoffset)
5595 correct_font_draw_xoffset = TRUE;
5597 if (xpos == menu_screen_value_xpos &&
5598 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5599 correct_font_draw_xoffset = TRUE;
5601 /* check if setup value would overlap with setup text when printed */
5602 /* (this can happen for extreme/wrong values for font draw offset) */
5603 if (correct_font_draw_xoffset)
5605 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5606 font_draw_xoffset_modified = TRUE;
5608 if (type & TYPE_KEY)
5609 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5610 else if (!(type & TYPE_STRING))
5611 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5612 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5616 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5617 DrawText(startx + i * font_width, starty, " ", font_nr);
5619 DrawText(startx, starty, value_string, font_nr);
5621 if (font_draw_xoffset_modified)
5622 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5625 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5627 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5628 struct TokenInfo *si = &setup_info[si_pos];
5630 if (si->type & TYPE_BOOLEAN_STYLE)
5632 *(boolean *)si->value ^= TRUE;
5634 else if (si->type & TYPE_YES_NO_AUTO)
5638 (*(int *)si->value == AUTO ? TRUE :
5639 *(int *)si->value == TRUE ? FALSE : AUTO) :
5640 (*(int *)si->value == TRUE ? AUTO :
5641 *(int *)si->value == AUTO ? FALSE : TRUE));
5643 else if (si->type & TYPE_KEY)
5647 si->type |= TYPE_QUERY;
5648 drawSetupValue(screen_pos, setup_info_pos_raw);
5649 si->type &= ~TYPE_QUERY;
5651 key = getSetupKey();
5652 if (key != KSYM_UNDEFINED)
5653 *(Key *)si->value = key;
5656 drawSetupValue(screen_pos, setup_info_pos_raw);
5658 // fullscreen state may have changed at this point
5659 if (si->value == &setup.fullscreen)
5660 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5663 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5666 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5667 struct TokenInfo *si = &setup_info[si_pos];
5668 int xpos = MENU_SCREEN_START_XPOS;
5669 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5670 int font_nr = getSetupTextFont(si->type);
5672 if (setup_info == setup_info_input)
5673 font_nr = FONT_MENU_1;
5676 font_nr = FONT_ACTIVE(font_nr);
5678 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5680 if (si->type & ~TYPE_SKIP_ENTRY)
5681 drawCursor(screen_pos, active);
5684 static void drawSetupInfoList(struct TokenInfo *setup_info,
5685 int first_entry, int num_page_entries)
5689 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5690 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5692 if (num_page_entries > max_setup_info)
5693 num_page_entries = max_setup_info;
5695 if (first_entry + num_page_entries > max_setup_info)
5698 clearMenuListArea();
5700 for (i = 0; i < num_page_entries; i++)
5702 int setup_info_pos = first_entry + i;
5703 struct TokenInfo *si = &setup_info[setup_info_pos];
5704 void *value_ptr = si->value;
5706 /* set some entries to "unchangeable" according to other variables */
5707 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5708 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5709 (value_ptr == &setup.sound_music && !audio.music_available) ||
5710 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5711 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5712 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5713 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5714 si->type |= TYPE_GHOSTED;
5716 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5717 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5718 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5719 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5720 else if (si->type & ~TYPE_SKIP_ENTRY)
5721 initCursor(i, IMG_MENU_BUTTON);
5723 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5725 if (si->type & TYPE_VALUE)
5726 drawSetupValue(i, setup_info_pos);
5730 static void DrawSetupScreen_Generic()
5732 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5733 boolean redraw_all = FALSE;
5734 char *title_string = NULL;
5739 FreeScreenGadgets();
5740 CreateScreenGadgets();
5742 CloseDoor(DOOR_CLOSE_2);
5744 if (redraw_mask & REDRAW_ALL)
5751 if (setup_mode == SETUP_MODE_MAIN)
5753 setup_info = setup_info_main;
5754 title_string = "Setup";
5756 else if (setup_mode == SETUP_MODE_GAME)
5758 setup_info = setup_info_game;
5759 title_string = "Setup Game";
5761 else if (setup_mode == SETUP_MODE_EDITOR)
5763 setup_info = setup_info_editor;
5764 title_string = "Setup Editor";
5766 else if (setup_mode == SETUP_MODE_GRAPHICS)
5768 setup_info = setup_info_graphics;
5769 title_string = "Setup Graphics";
5771 else if (setup_mode == SETUP_MODE_SOUND)
5773 setup_info = setup_info_sound;
5774 title_string = "Setup Sound";
5776 else if (setup_mode == SETUP_MODE_ARTWORK)
5778 setup_info = setup_info_artwork;
5779 title_string = "Custom Artwork";
5781 else if (setup_mode == SETUP_MODE_TOUCH)
5783 setup_info = setup_info_touch;
5784 title_string = "Setup Touch Ctrls";
5786 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5788 setup_info = setup_info_shortcuts;
5789 title_string = "Setup Shortcuts";
5791 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5793 setup_info = setup_info_shortcuts_1;
5794 title_string = "Setup Shortcuts";
5796 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5798 setup_info = setup_info_shortcuts_2;
5799 title_string = "Setup Shortcuts";
5801 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5803 setup_info = setup_info_shortcuts_3;
5804 title_string = "Setup Shortcuts";
5806 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5808 setup_info = setup_info_shortcuts_4;
5809 title_string = "Setup Shortcuts";
5811 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5813 setup_info = setup_info_shortcuts_5;
5814 title_string = "Setup Shortcuts";
5817 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5819 // determine maximal number of setup entries that can be displayed on screen
5821 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5824 // determine maximal number of setup entries available for this setup screen
5826 for (i = 0; setup_info[i].type != 0; i++)
5829 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5831 MapScreenGadgets(max_setup_info);
5834 redraw_mask = fade_mask = REDRAW_ALL;
5841 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5843 static int choice_store[MAX_SETUP_MODES];
5844 static int first_entry_store[MAX_SETUP_MODES];
5845 static int num_page_entries_last = 0;
5846 int choice = choice_store[setup_mode]; /* starts with 0 */
5847 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5849 int y = choice - first_entry;
5851 boolean position_set_by_scrollbar = (dx == 999);
5852 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5853 int num_page_entries;
5855 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5857 if (button == MB_MENU_INITIALIZE)
5859 // check if number of menu page entries has changed (may happen by change
5860 // of custom artwork definition value for 'list_size' for this menu screen)
5861 // (in this case, the last menu position most probably has to be corrected)
5862 if (num_page_entries != num_page_entries_last)
5866 for (i = 0; i < MAX_INFO_MODES; i++)
5867 choice_store[i] = first_entry_store[i] = 0;
5869 num_page_entries_last = num_page_entries;
5871 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5876 /* advance to first valid menu entry */
5877 while (choice < num_setup_info &&
5878 setup_info[choice].type & TYPE_SKIP_ENTRY)
5881 if (position_set_by_scrollbar)
5882 first_entry = first_entry_store[setup_mode] = dy;
5884 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5885 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5887 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5889 if (choice < first_entry)
5891 choice = first_entry;
5893 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5896 else if (choice > first_entry + num_page_entries - 1)
5898 choice = first_entry + num_page_entries - 1;
5900 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5904 choice_store[setup_mode] = choice;
5906 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5910 else if (button == MB_MENU_LEAVE)
5914 PlaySound(SND_MENU_ITEM_SELECTING);
5916 for (i = 0; setup_info[i].type != 0; i++)
5918 if (setup_info[i].type & TYPE_LEAVE_MENU)
5920 void (*menu_callback_function)(void) = setup_info[i].value;
5924 menu_callback_function();
5926 break; /* absolutely needed because function changes 'setup_info'! */
5933 if (mx || my) /* mouse input */
5935 x = (mx - mSX) / 32;
5936 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5938 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5940 /* move cursor instead of scrolling when already at start/end of list */
5941 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5943 else if (dy == +1 * SCROLL_LINE &&
5944 first_entry + num_page_entries == max_setup_info)
5947 /* handle scrolling screen one line or page */
5949 y + dy > num_page_entries - 1)
5951 boolean redraw = FALSE;
5953 if (ABS(dy) == SCROLL_PAGE)
5954 step = num_page_entries - 1;
5956 if (dy < 0 && first_entry > 0)
5958 /* scroll page/line up */
5960 first_entry -= step;
5961 if (first_entry < 0)
5966 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5968 /* scroll page/line down */
5970 first_entry += step;
5971 if (first_entry + num_page_entries > max_setup_info)
5972 first_entry = MAX(0, max_setup_info - num_page_entries);
5979 choice += first_entry - first_entry_store[setup_mode];
5981 if (choice < first_entry)
5983 choice = first_entry;
5985 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5988 else if (choice > first_entry + num_page_entries - 1)
5990 choice = first_entry + num_page_entries - 1;
5992 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5995 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5999 if (choice < first_entry ||
6000 choice > first_entry + num_page_entries - 1)
6001 first_entry += SIGN(dy);
6004 first_entry_store[setup_mode] = first_entry;
6005 choice_store[setup_mode] = choice;
6007 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6009 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6011 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6012 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6020 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
6022 if (setup_info[choice].type & menu_navigation_type ||
6023 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
6024 setup_info[choice].type & TYPE_YES_NO_AUTO)
6025 button = MB_MENU_CHOICE;
6030 /* jump to next non-empty menu entry (up or down) */
6031 while (first_entry + y > 0 &&
6032 first_entry + y < max_setup_info - 1 &&
6033 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6036 if (!IN_VIS_MENU(x, y))
6038 choice += y - y_old;
6040 if (choice < first_entry)
6041 first_entry = choice;
6042 else if (choice > first_entry + num_page_entries - 1)
6043 first_entry = choice - num_page_entries + 1;
6045 if (first_entry >= 0 &&
6046 first_entry + num_page_entries <= max_setup_info)
6048 first_entry_store[setup_mode] = first_entry;
6050 if (choice < first_entry)
6051 choice = first_entry;
6052 else if (choice > first_entry + num_page_entries - 1)
6053 choice = first_entry + num_page_entries - 1;
6055 choice_store[setup_mode] = choice;
6057 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6059 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6061 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6062 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6069 if (!anyScrollbarGadgetActive() &&
6070 IN_VIS_MENU(x, y) &&
6071 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
6072 y >= 0 && y < num_page_entries)
6076 if (first_entry + y != choice &&
6077 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
6079 PlaySound(SND_MENU_ITEM_ACTIVATING);
6081 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
6082 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
6084 choice = choice_store[setup_mode] = first_entry + y;
6087 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
6089 PlaySound(SND_MENU_ITEM_SELECTING);
6091 /* when selecting key headline, execute function for key value change */
6092 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
6093 setup_info[first_entry + y + 1].type & TYPE_KEY)
6096 /* when selecting string value, execute function for list selection */
6097 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
6098 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
6101 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
6103 void (*menu_callback_function)(void) =
6104 setup_info[first_entry + y].value;
6106 FadeSetFromType(setup_info[first_entry + y].type);
6108 menu_callback_function();
6112 if (setup_info[first_entry + y].type & TYPE_VALUE)
6113 changeSetupValue(y, first_entry + y, dx);
6119 void DrawSetupScreen_Input()
6123 FadeOut(REDRAW_FIELD);
6127 setup_info = setup_info_input;
6129 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
6131 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6132 "Joysticks deactivated on this screen");
6134 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6136 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6137 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6138 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6139 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6140 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6141 initCursor(i, IMG_MENU_BUTTON);
6143 DrawCursorAndText_Setup(i, -1, FALSE);
6146 /* create gadgets for setup input menu screen */
6147 FreeScreenGadgets();
6148 CreateScreenGadgets();
6150 /* map gadgets for setup input menu screen */
6151 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6153 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6155 FadeIn(REDRAW_FIELD);
6160 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6162 if (device_name == NULL)
6165 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6168 if (strlen(device_name) > 1)
6170 char c1 = device_name[strlen(device_name) - 1];
6171 char c2 = device_name[strlen(device_name) - 2];
6173 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6174 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6177 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6178 strlen(device_name));
6181 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6184 static struct SetupKeyboardInfo custom_key;
6191 { &custom_key.left, "Joystick Left" },
6192 { &custom_key.right, "Joystick Right" },
6193 { &custom_key.up, "Joystick Up" },
6194 { &custom_key.down, "Joystick Down" },
6195 { &custom_key.snap, "Button 1" },
6196 { &custom_key.drop, "Button 2" }
6198 static char *joystick_name[MAX_PLAYERS] =
6205 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6209 custom_key = setup.input[player_nr].key;
6211 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6212 FONT_INPUT_1_ACTIVE);
6214 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6216 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6217 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6219 if (setup.input[player_nr].use_joystick)
6221 char *device_name = setup.input[player_nr].joy.device_name;
6222 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6223 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6225 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6226 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6230 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6231 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6234 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6236 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6237 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6238 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6239 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6241 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6242 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6243 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6244 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6245 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6246 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6248 for (i = 0; i < 6; i++)
6250 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6252 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6254 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6255 (setup.input[player_nr].use_joystick ?
6257 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6261 static int input_player_nr = 0;
6263 void HandleSetupScreen_Input_Player(int step, int direction)
6265 int old_player_nr = input_player_nr;
6268 new_player_nr = old_player_nr + step * direction;
6269 if (new_player_nr < 0)
6271 if (new_player_nr > MAX_PLAYERS - 1)
6272 new_player_nr = MAX_PLAYERS - 1;
6274 if (new_player_nr != old_player_nr)
6276 input_player_nr = new_player_nr;
6278 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6282 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6284 static int choice = 0;
6287 int pos_start = SETUPINPUT_SCREEN_POS_START;
6288 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6289 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6290 int pos_end = SETUPINPUT_SCREEN_POS_END;
6292 if (button == MB_MENU_INITIALIZE)
6294 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6296 DrawCursorAndText_Setup(choice, -1, TRUE);
6300 else if (button == MB_MENU_LEAVE)
6302 setup_mode = SETUP_MODE_MAIN;
6309 if (mx || my) /* mouse input */
6311 x = (mx - mSX) / 32;
6312 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6314 else if (dx || dy) /* keyboard input */
6316 if (dx && choice == 0)
6317 x = (dx < 0 ? 10 : 12);
6318 else if ((dx && choice == 1) ||
6319 (dx == +1 && choice == 2) ||
6320 (dx == -1 && choice == pos_end))
6321 button = MB_MENU_CHOICE;
6325 if (y >= pos_empty1 && y <= pos_empty2)
6326 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6329 if (y == 0 && dx != 0 && button)
6331 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6333 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6334 y >= pos_start && y <= pos_end &&
6335 !(y >= pos_empty1 && y <= pos_empty2))
6341 DrawCursorAndText_Setup(choice, -1, FALSE);
6342 DrawCursorAndText_Setup(y, -1, TRUE);
6344 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6353 char *device_name = setup.input[input_player_nr].joy.device_name;
6355 if (!setup.input[input_player_nr].use_joystick)
6357 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6359 setJoystickDeviceToNr(device_name, new_device_nr);
6360 setup.input[input_player_nr].use_joystick = TRUE;
6364 int device_nr = getJoystickNrFromDeviceName(device_name);
6365 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6367 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6368 setup.input[input_player_nr].use_joystick = FALSE;
6370 setJoystickDeviceToNr(device_name, new_device_nr);
6373 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6377 if (setup.input[input_player_nr].use_joystick)
6380 CalibrateJoystick(input_player_nr);
6383 CustomizeKeyboard(input_player_nr);
6385 else if (y == pos_end)
6391 setup_mode = SETUP_MODE_MAIN;
6398 void CustomizeKeyboard(int player_nr)
6402 boolean finished = FALSE;
6403 static struct SetupKeyboardInfo custom_key;
6408 } customize_step[] =
6410 { &custom_key.left, "Move Left" },
6411 { &custom_key.right, "Move Right" },
6412 { &custom_key.up, "Move Up" },
6413 { &custom_key.down, "Move Down" },
6414 { &custom_key.snap, "Snap Field" },
6415 { &custom_key.drop, "Drop Element" }
6418 /* read existing key bindings from player setup */
6419 custom_key = setup.input[player_nr].key;
6422 FadeOut(REDRAW_FIELD);
6426 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6429 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6430 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6431 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6432 "Key:", FONT_INPUT_1_ACTIVE);
6433 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6434 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6436 FadeIn(REDRAW_FIELD);
6442 if (PendingEvent()) /* got event */
6450 case EVENT_KEYPRESS:
6452 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6454 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6456 if (key == KSYM_Escape)
6457 FadeSkipNextFadeIn();
6463 /* all keys configured -- wait for "Escape" or "Return" key */
6467 /* press 'Enter' to keep the existing key binding */
6468 if (key == KSYM_Return)
6469 key = *customize_step[step_nr].key;
6471 /* check if key already used */
6472 for (i = 0; i < step_nr; i++)
6473 if (*customize_step[i].key == key)
6478 /* got new key binding */
6479 *customize_step[step_nr].key = key;
6480 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6482 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6483 getKeyNameFromKey(key), FONT_VALUE_1);
6486 /* un-highlight last query */
6487 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6488 customize_step[step_nr - 1].text, FONT_MENU_1);
6489 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6490 "Key:", FONT_MENU_1);
6492 /* press 'Enter' to leave */
6495 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6496 "Press Enter", FONT_TITLE_1);
6500 /* query next key binding */
6501 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6502 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6503 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6504 "Key:", FONT_INPUT_1_ACTIVE);
6505 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6506 getKeyNameFromKey(*customize_step[step_nr].key),
6511 case EVENT_KEYRELEASE:
6512 key_joystick_mapping = 0;
6516 HandleOtherEvents(&event);
6524 /* don't eat all CPU time */
6528 /* write new key bindings back to player setup */
6529 setup.input[player_nr].key = custom_key;
6532 DrawSetupScreen_Input();
6535 static boolean CalibrateJoystickMain(int player_nr)
6537 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6538 int new_joystick_xright = JOYSTICK_XMIDDLE;
6539 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6540 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6541 int new_joystick_xmiddle, new_joystick_ymiddle;
6543 int joystick_fd = joystick.fd[player_nr];
6544 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6545 boolean check[3][3];
6546 int check_remaining = 3 * 3;
6551 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6554 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6558 FadeOut(REDRAW_FIELD);
6562 for (y = 0; y < 3; y++)
6564 for (x = 0; x < 3; x++)
6566 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6567 check[x][y] = FALSE;
6571 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6572 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6573 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6574 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6575 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6576 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6577 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6579 joy_value = Joystick(player_nr);
6580 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6581 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6583 /* eventually uncalibrated center position (joystick could be uncentered) */
6584 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6587 new_joystick_xmiddle = joy_x;
6588 new_joystick_ymiddle = joy_y;
6590 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6592 FadeIn(REDRAW_FIELD);
6594 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6599 if (PendingEvent()) /* got event */
6607 case EVENT_KEYPRESS:
6608 switch (GetEventKey((KeyEvent *)&event, TRUE))
6611 if (check_remaining == 0)
6616 FadeSkipNextFadeIn();
6625 case EVENT_KEYRELEASE:
6626 key_joystick_mapping = 0;
6630 HandleOtherEvents(&event);
6635 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6638 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6639 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6640 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6641 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6643 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6644 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6645 setup.input[player_nr].joy.xright = new_joystick_xright;
6646 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6647 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6648 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6650 CheckJoystickData();
6652 joy_value = Joystick(player_nr);
6654 if (joy_value & JOY_BUTTON && check_remaining == 0)
6657 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6658 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6660 if (x != last_x || y != last_y)
6662 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6663 IMG_MENU_CALIBRATE_YELLOW, 0);
6664 DrawFixedGraphic(xpos + x, ypos + y,
6665 IMG_MENU_CALIBRATE_RED, 0);
6670 if (check_remaining > 0 && !check[x+1][y+1])
6672 check[x+1][y+1] = TRUE;
6680 /* don't eat all CPU time */
6684 /* calibrated center position (joystick should now be centered) */
6685 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6688 new_joystick_xmiddle = joy_x;
6689 new_joystick_ymiddle = joy_y;
6693 /* wait until the last pressed button was released */
6694 while (Joystick(player_nr) & JOY_BUTTON)
6696 if (PendingEvent()) /* got event */
6701 HandleOtherEvents(&event);
6710 void CalibrateJoystick(int player_nr)
6712 if (!CalibrateJoystickMain(player_nr))
6714 char *device_name = setup.input[player_nr].joy.device_name;
6715 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6716 int xpos = mSX - SX;
6717 int ypos = mSY - SY;
6721 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6722 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6725 Delay(2000); /* show error message for a short time */
6730 DrawSetupScreen_Input();
6733 void DrawSetupScreen()
6735 DeactivateJoystick();
6737 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6739 if (setup_mode == SETUP_MODE_INPUT)
6740 DrawSetupScreen_Input();
6741 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6742 DrawChooseTree(&game_speed_current);
6743 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6744 DrawChooseTree(&scroll_delay_current);
6745 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6746 DrawChooseTree(&snapshot_mode_current);
6747 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6748 DrawChooseTree(&screen_mode_current);
6749 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6750 DrawChooseTree(&window_size_current);
6751 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6752 DrawChooseTree(&scaling_type_current);
6753 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6754 DrawChooseTree(&artwork.gfx_current);
6755 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6756 DrawChooseTree(&artwork.snd_current);
6757 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6758 DrawChooseTree(&artwork.mus_current);
6759 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6760 DrawChooseTree(&volume_simple_current);
6761 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6762 DrawChooseTree(&volume_loops_current);
6763 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6764 DrawChooseTree(&volume_music_current);
6765 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6766 DrawChooseTree(&touch_control_current);
6767 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6768 DrawChooseTree(&move_distance_current);
6769 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6770 DrawChooseTree(&drop_distance_current);
6772 DrawSetupScreen_Generic();
6778 void RedrawSetupScreenAfterFullscreenToggle()
6780 if (setup_mode == SETUP_MODE_GRAPHICS ||
6781 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6783 // update list selection from "setup.window_scaling_percent"
6784 execSetupGraphics_setWindowSizes(TRUE);
6790 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6792 if (setup_mode == SETUP_MODE_INPUT)
6793 HandleSetupScreen_Input(mx, my, dx, dy, button);
6794 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6795 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6796 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6797 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6798 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6799 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6800 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6801 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6802 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6803 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6804 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6805 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6806 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6807 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6808 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6809 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6810 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6811 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6812 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6813 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6814 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6815 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6816 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6817 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6818 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6819 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6820 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6821 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6822 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6823 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6825 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6828 void HandleGameActions()
6830 if (game_status != GAME_MODE_PLAYING)
6833 GameActions(); /* main game loop */
6835 if (tape.auto_play && !tape.playing)
6836 AutoPlayTape(); /* continue automatically playing next tape */
6840 /* ---------- new screen button stuff -------------------------------------- */
6842 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6846 case SCREEN_CTRL_ID_PREV_LEVEL:
6847 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6848 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6851 case SCREEN_CTRL_ID_NEXT_LEVEL:
6852 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6853 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6856 case SCREEN_CTRL_ID_PREV_PLAYER:
6857 *x = mSX + TILEX * 10;
6858 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6861 case SCREEN_CTRL_ID_NEXT_PLAYER:
6862 *x = mSX + TILEX * 12;
6863 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6867 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6873 int gfx_unpressed, gfx_pressed;
6874 void (*get_gadget_position)(int *, int *, int);
6878 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6881 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6882 getScreenMenuButtonPos,
6883 SCREEN_CTRL_ID_PREV_LEVEL,
6888 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6889 getScreenMenuButtonPos,
6890 SCREEN_CTRL_ID_NEXT_LEVEL,
6895 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6896 getScreenMenuButtonPos,
6897 SCREEN_CTRL_ID_PREV_PLAYER,
6902 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6903 getScreenMenuButtonPos,
6904 SCREEN_CTRL_ID_NEXT_PLAYER,
6912 int gfx_unpressed, gfx_pressed;
6916 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6919 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6920 -1, -1, /* these values are not constant, but can change at runtime */
6921 SCREEN_CTRL_ID_SCROLL_UP,
6925 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6926 -1, -1, /* these values are not constant, but can change at runtime */
6927 SCREEN_CTRL_ID_SCROLL_DOWN,
6934 int gfx_unpressed, gfx_pressed;
6940 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6943 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6944 -1, -1, /* these values are not constant, but can change at runtime */
6945 -1, -1, /* these values are not constant, but can change at runtime */
6946 GD_TYPE_SCROLLBAR_VERTICAL,
6947 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6948 "scroll level series vertically"
6952 static void CreateScreenMenubuttons()
6954 struct GadgetInfo *gi;
6955 unsigned int event_mask;
6958 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6960 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6961 int gfx_unpressed, gfx_pressed;
6962 int x, y, width, height;
6963 int gd_x1, gd_x2, gd_y1, gd_y2;
6964 int id = menubutton_info[i].gadget_id;
6966 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6968 menubutton_info[i].get_gadget_position(&x, &y, id);
6970 width = SC_MENUBUTTON_XSIZE;
6971 height = SC_MENUBUTTON_YSIZE;
6973 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6974 gfx_pressed = menubutton_info[i].gfx_pressed;
6975 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6976 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6977 gd_x1 = graphic_info[gfx_unpressed].src_x;
6978 gd_y1 = graphic_info[gfx_unpressed].src_y;
6979 gd_x2 = graphic_info[gfx_pressed].src_x;
6980 gd_y2 = graphic_info[gfx_pressed].src_y;
6982 gi = CreateGadget(GDI_CUSTOM_ID, id,
6983 GDI_CUSTOM_TYPE_ID, i,
6984 GDI_INFO_TEXT, menubutton_info[i].infotext,
6989 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6990 GDI_STATE, GD_BUTTON_UNPRESSED,
6991 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6992 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6993 GDI_DIRECT_DRAW, FALSE,
6994 GDI_EVENT_MASK, event_mask,
6995 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6999 Error(ERR_EXIT, "cannot create gadget");
7001 screen_gadget[id] = gi;
7005 static void CreateScreenScrollbuttons()
7007 struct GadgetInfo *gi;
7008 unsigned int event_mask;
7011 /* these values are not constant, but can change at runtime */
7012 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7013 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7014 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7015 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7017 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7019 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7020 int gfx_unpressed, gfx_pressed;
7021 int x, y, width, height;
7022 int gd_x1, gd_x2, gd_y1, gd_y2;
7023 int id = scrollbutton_info[i].gadget_id;
7025 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7027 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7028 y = mSY + scrollbutton_info[i].y;
7029 width = SC_SCROLLBUTTON_XSIZE;
7030 height = SC_SCROLLBUTTON_YSIZE;
7032 /* correct scrollbar position if placed outside menu (playfield) area */
7033 if (x > SX + SC_SCROLL_UP_XPOS)
7034 x = SX + SC_SCROLL_UP_XPOS;
7036 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7037 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7038 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7040 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7041 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7042 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7043 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7044 gd_x1 = graphic_info[gfx_unpressed].src_x;
7045 gd_y1 = graphic_info[gfx_unpressed].src_y;
7046 gd_x2 = graphic_info[gfx_pressed].src_x;
7047 gd_y2 = graphic_info[gfx_pressed].src_y;
7049 gi = CreateGadget(GDI_CUSTOM_ID, id,
7050 GDI_CUSTOM_TYPE_ID, i,
7051 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7056 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7057 GDI_STATE, GD_BUTTON_UNPRESSED,
7058 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7059 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7060 GDI_DIRECT_DRAW, FALSE,
7061 GDI_EVENT_MASK, event_mask,
7062 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7066 Error(ERR_EXIT, "cannot create gadget");
7068 screen_gadget[id] = gi;
7072 static void CreateScreenScrollbars()
7076 /* these values are not constant, but can change at runtime */
7077 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7078 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7079 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7080 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7082 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7084 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7085 int gfx_unpressed, gfx_pressed;
7086 int x, y, width, height;
7087 int gd_x1, gd_x2, gd_y1, gd_y2;
7088 struct GadgetInfo *gi;
7089 int items_max, items_visible, item_position;
7090 unsigned int event_mask;
7091 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7092 int id = scrollbar_info[i].gadget_id;
7094 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7096 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7097 y = mSY + scrollbar_info[i].y;
7098 width = scrollbar_info[i].width;
7099 height = scrollbar_info[i].height;
7101 /* correct scrollbar position if placed outside menu (playfield) area */
7102 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
7103 x = SX + SC_SCROLL_VERTICAL_XPOS;
7105 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7106 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7108 items_max = num_page_entries;
7109 items_visible = num_page_entries;
7112 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7113 gfx_pressed = scrollbar_info[i].gfx_pressed;
7114 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7115 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7116 gd_x1 = graphic_info[gfx_unpressed].src_x;
7117 gd_y1 = graphic_info[gfx_unpressed].src_y;
7118 gd_x2 = graphic_info[gfx_pressed].src_x;
7119 gd_y2 = graphic_info[gfx_pressed].src_y;
7121 gi = CreateGadget(GDI_CUSTOM_ID, id,
7122 GDI_CUSTOM_TYPE_ID, i,
7123 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7128 GDI_TYPE, scrollbar_info[i].type,
7129 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7130 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7131 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7132 GDI_WHEEL_AREA_X, SX,
7133 GDI_WHEEL_AREA_Y, SY,
7134 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7135 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7136 GDI_STATE, GD_BUTTON_UNPRESSED,
7137 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7138 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7139 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7140 GDI_DIRECT_DRAW, FALSE,
7141 GDI_EVENT_MASK, event_mask,
7142 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7146 Error(ERR_EXIT, "cannot create gadget");
7148 screen_gadget[id] = gi;
7152 void CreateScreenGadgets()
7154 int last_game_status = game_status; /* save current game status */
7156 CreateScreenMenubuttons();
7158 CreateScreenScrollbuttons();
7159 CreateScreenScrollbars();
7161 game_status = last_game_status; /* restore current game status */
7164 void FreeScreenGadgets()
7168 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7169 FreeGadget(screen_gadget[i]);
7172 void MapScreenMenuGadgets(int screen_mask)
7176 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7177 if (screen_mask & menubutton_info[i].screen_mask)
7178 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7181 void MapScreenGadgets(int num_entries)
7185 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7188 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7189 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7191 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7192 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7195 void MapScreenTreeGadgets(TreeInfo *ti)
7197 MapScreenGadgets(numTreeInfoInGroup(ti));
7200 static void HandleScreenGadgets(struct GadgetInfo *gi)
7202 int id = gi->custom_id;
7203 int button = gi->event.button;
7204 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7208 case SCREEN_CTRL_ID_PREV_LEVEL:
7209 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
7212 case SCREEN_CTRL_ID_NEXT_LEVEL:
7213 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
7216 case SCREEN_CTRL_ID_PREV_PLAYER:
7217 HandleSetupScreen_Input_Player(step, -1);
7220 case SCREEN_CTRL_ID_NEXT_PLAYER:
7221 HandleSetupScreen_Input_Player(step, +1);
7224 case SCREEN_CTRL_ID_SCROLL_UP:
7225 if (game_status == GAME_MODE_LEVELS)
7226 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7227 else if (game_status == GAME_MODE_LEVELNR)
7228 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7229 else if (game_status == GAME_MODE_SETUP)
7230 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7231 else if (game_status == GAME_MODE_INFO)
7232 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7235 case SCREEN_CTRL_ID_SCROLL_DOWN:
7236 if (game_status == GAME_MODE_LEVELS)
7237 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7238 else if (game_status == GAME_MODE_LEVELNR)
7239 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7240 else if (game_status == GAME_MODE_SETUP)
7241 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7242 else if (game_status == GAME_MODE_INFO)
7243 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7246 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7247 if (game_status == GAME_MODE_LEVELS)
7248 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7249 else if (game_status == GAME_MODE_LEVELNR)
7250 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7251 else if (game_status == GAME_MODE_SETUP)
7252 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7253 else if (game_status == GAME_MODE_INFO)
7254 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);