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_WINDOW_SIZE 19
65 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
66 #define SETUP_MODE_CHOOSE_GRAPHICS 21
67 #define SETUP_MODE_CHOOSE_SOUNDS 22
68 #define SETUP_MODE_CHOOSE_MUSIC 23
69 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 24
70 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 25
71 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 26
72 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 27
73 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 28
74 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 29
76 #define MAX_SETUP_MODES 30
78 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
80 /* for input setup functions */
81 #define SETUPINPUT_SCREEN_POS_START 0
82 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
83 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
84 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
86 /* for various menu stuff */
87 #define MENU_SCREEN_START_XPOS 1
88 #define MENU_SCREEN_START_YPOS 2
89 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
90 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
91 #define MENU_TITLE1_YPOS 8
92 #define MENU_TITLE2_YPOS 46
93 #define MENU_SCREEN_INFO_XSTART 16
94 #define MENU_SCREEN_INFO_YSTART1 100
95 #define MENU_SCREEN_INFO_YSTART2 128
96 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
97 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
98 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
99 MENU_SCREEN_INFO_YSTART2 - \
101 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
102 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
103 MENU_SCREEN_INFO_YSTEP)
104 #define NUM_INFO_ELEMENTS_FROM_CONF \
105 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
106 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
107 MAX_MENU_ENTRIES_ON_SCREEN)
108 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
109 MAX_INFO_ELEMENTS_ON_SCREEN), \
110 NUM_INFO_ELEMENTS_FROM_CONF)
111 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
112 #define MAX_MENU_TEXT_LENGTH_BIG 13
113 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
115 /* buttons and scrollbars identifiers */
116 #define SCREEN_CTRL_ID_PREV_LEVEL 0
117 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
118 #define SCREEN_CTRL_ID_PREV_PLAYER 2
119 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
120 #define SCREEN_CTRL_ID_SCROLL_UP 4
121 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
122 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
124 #define NUM_SCREEN_GADGETS 7
126 #define NUM_SCREEN_MENUBUTTONS 4
127 #define NUM_SCREEN_SCROLLBUTTONS 2
128 #define NUM_SCREEN_SCROLLBARS 1
130 #define SCREEN_MASK_MAIN (1 << 0)
131 #define SCREEN_MASK_INPUT (1 << 1)
133 /* graphic position and size values for buttons and scrollbars */
134 #define SC_MENUBUTTON_XSIZE TILEX
135 #define SC_MENUBUTTON_YSIZE TILEY
137 #define SC_SCROLLBUTTON_XSIZE TILEX
138 #define SC_SCROLLBUTTON_YSIZE TILEY
140 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
142 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
143 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
144 SC_SCROLLBUTTON_YSIZE)
146 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
147 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
149 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
150 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
151 SC_SCROLLBUTTON_YSIZE)
153 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
154 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
155 SC_SCROLL_VERTICAL_YSIZE)
157 #define SC_BORDER_SIZE 14
160 /* forward declarations of internal functions */
161 static void HandleScreenGadgets(struct GadgetInfo *);
162 static void HandleSetupScreen_Generic(int, int, int, int, int);
163 static void HandleSetupScreen_Input(int, int, int, int, int);
164 static void CustomizeKeyboard(int);
165 static void CalibrateJoystick(int);
166 static void execSetupGame(void);
167 static void execSetupGraphics(void);
168 static void execSetupSound(void);
169 static void execSetupTouch(void);
170 static void execSetupArtwork(void);
171 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
173 static void DrawChooseLevelSet(void);
174 static void DrawChooseLevelNr(void);
175 static void DrawInfoScreen(void);
176 static void DrawSetupScreen(void);
178 static void DrawInfoScreen_NotAvailable(char *, char *);
179 static void DrawInfoScreen_HelpAnim(int, int, boolean);
180 static void DrawInfoScreen_HelpText(int, int, int, int);
181 static void HandleInfoScreen_Main(int, int, int, int, int);
182 static void HandleInfoScreen_TitleScreen(int);
183 static void HandleInfoScreen_Elements(int);
184 static void HandleInfoScreen_Music(int);
185 static void HandleInfoScreen_Credits(int);
186 static void HandleInfoScreen_Program(int);
187 static void HandleInfoScreen_Version(int);
189 static void MapScreenMenuGadgets(int);
190 static void MapScreenGadgets(int);
191 static void MapScreenTreeGadgets(TreeInfo *);
193 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
195 static int info_mode = INFO_MODE_MAIN;
196 static int setup_mode = SETUP_MODE_MAIN;
198 static TreeInfo *window_sizes = NULL;
199 static TreeInfo *window_size_current = NULL;
201 static TreeInfo *scaling_types = NULL;
202 static TreeInfo *scaling_type_current = NULL;
204 static TreeInfo *scroll_delays = NULL;
205 static TreeInfo *scroll_delay_current = NULL;
207 static TreeInfo *snapshot_modes = NULL;
208 static TreeInfo *snapshot_mode_current = NULL;
210 static TreeInfo *game_speeds = NULL;
211 static TreeInfo *game_speed_current = NULL;
213 static TreeInfo *volumes_simple = NULL;
214 static TreeInfo *volume_simple_current = NULL;
216 static TreeInfo *volumes_loops = NULL;
217 static TreeInfo *volume_loops_current = NULL;
219 static TreeInfo *volumes_music = NULL;
220 static TreeInfo *volume_music_current = NULL;
222 static TreeInfo *touch_controls = NULL;
223 static TreeInfo *touch_control_current = NULL;
225 static TreeInfo *move_distances = NULL;
226 static TreeInfo *move_distance_current = NULL;
228 static TreeInfo *drop_distances = NULL;
229 static TreeInfo *drop_distance_current = NULL;
231 static TreeInfo *level_number = NULL;
232 static TreeInfo *level_number_current = NULL;
234 static unsigned int sync_frame_delay = 0;
235 static unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
241 } window_sizes_list[] =
246 { 100, "100 % (Default)" },
263 } scaling_types_list[] =
265 { SCALING_QUALITY_NEAREST, "None" },
266 { SCALING_QUALITY_LINEAR, "Linear" },
267 { SCALING_QUALITY_BEST, "Anisotropic" },
276 } game_speeds_list[] =
285 { 1000, "1/1s (Extremely Slow)" },
290 { 29, "1/35s (Original Supaplex)" },
292 { 20, "1/50s (Normal Speed)" },
293 { 14, "1/70s (Maximum Supaplex)" },
297 { 1, "1/1000s (Extremely Fast)" },
307 } scroll_delays_list[] =
309 { 0, "0 Tiles (No Scroll Delay)" },
312 { 3, "3 Tiles (Default)" },
317 { 8, "8 Tiles (Maximum Scroll Delay)"},
326 } snapshot_modes_list[] =
328 { STR_SNAPSHOT_MODE_OFF, "Off" },
329 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
330 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
331 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
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
463 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
465 /* main menu display and control definitions */
467 #define MAIN_CONTROL_NAME 0
468 #define MAIN_CONTROL_LEVELS 1
469 #define MAIN_CONTROL_SCORES 2
470 #define MAIN_CONTROL_EDITOR 3
471 #define MAIN_CONTROL_INFO 4
472 #define MAIN_CONTROL_GAME 5
473 #define MAIN_CONTROL_SETUP 6
474 #define MAIN_CONTROL_QUIT 7
475 #define MAIN_CONTROL_PREV_LEVEL 8
476 #define MAIN_CONTROL_NEXT_LEVEL 9
477 #define MAIN_CONTROL_FIRST_LEVEL 10
478 #define MAIN_CONTROL_LAST_LEVEL 11
479 #define MAIN_CONTROL_LEVEL_NUMBER 12
480 #define MAIN_CONTROL_LEVEL_INFO_1 13
481 #define MAIN_CONTROL_LEVEL_INFO_2 14
482 #define MAIN_CONTROL_LEVEL_NAME 15
483 #define MAIN_CONTROL_LEVEL_AUTHOR 16
484 #define MAIN_CONTROL_LEVEL_YEAR 17
485 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
486 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
487 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
488 #define MAIN_CONTROL_TITLE_1 21
489 #define MAIN_CONTROL_TITLE_2 22
490 #define MAIN_CONTROL_TITLE_3 23
492 static char str_main_text_name[10];
493 static char str_main_text_first_level[10];
494 static char str_main_text_last_level[10];
495 static char str_main_text_level_number[10];
497 static char *main_text_name = str_main_text_name;
498 static char *main_text_first_level = str_main_text_first_level;
499 static char *main_text_last_level = str_main_text_last_level;
500 static char *main_text_level_number = str_main_text_level_number;
501 static char *main_text_levels = "Levelset";
502 static char *main_text_scores = "Hall Of Fame";
503 static char *main_text_editor = "Level Creator";
504 static char *main_text_info = "Info Screen";
505 static char *main_text_game = "Start Game";
506 static char *main_text_setup = "Setup";
507 static char *main_text_quit = "Quit";
508 static char *main_text_level_name = level.name;
509 static char *main_text_level_author = level.author;
510 static char *main_text_level_year = NULL;
511 static char *main_text_level_imported_from = NULL;
512 static char *main_text_level_imported_by = NULL;
513 static char *main_text_level_tested_by = NULL;
515 struct MainControlInfo
519 struct MenuPosInfo *pos_button;
522 struct TextPosInfo *pos_text;
525 struct TextPosInfo *pos_input;
529 static struct MainControlInfo main_controls[] =
533 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
534 &menu.main.text.name, &main_text_name,
535 &menu.main.input.name, &setup.player_name,
539 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
540 &menu.main.text.levels, &main_text_levels,
545 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
546 &menu.main.text.scores, &main_text_scores,
551 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
552 &menu.main.text.editor, &main_text_editor,
557 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
558 &menu.main.text.info, &main_text_info,
563 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
564 &menu.main.text.game, &main_text_game,
569 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
570 &menu.main.text.setup, &main_text_setup,
575 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
576 &menu.main.text.quit, &main_text_quit,
580 /* (these two buttons are real gadgets) */
582 MAIN_CONTROL_PREV_LEVEL,
583 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
588 MAIN_CONTROL_NEXT_LEVEL,
589 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
595 MAIN_CONTROL_FIRST_LEVEL,
597 &menu.main.text.first_level, &main_text_first_level,
601 MAIN_CONTROL_LAST_LEVEL,
603 &menu.main.text.last_level, &main_text_last_level,
607 MAIN_CONTROL_LEVEL_NUMBER,
609 &menu.main.text.level_number, &main_text_level_number,
613 MAIN_CONTROL_LEVEL_INFO_1,
615 &menu.main.text.level_info_1, NULL,
619 MAIN_CONTROL_LEVEL_INFO_2,
621 &menu.main.text.level_info_2, NULL,
625 MAIN_CONTROL_LEVEL_NAME,
627 &menu.main.text.level_name, &main_text_level_name,
631 MAIN_CONTROL_LEVEL_AUTHOR,
633 &menu.main.text.level_author, &main_text_level_author,
637 MAIN_CONTROL_LEVEL_YEAR,
639 &menu.main.text.level_year, &main_text_level_year,
643 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
645 &menu.main.text.level_imported_from, &main_text_level_imported_from,
649 MAIN_CONTROL_LEVEL_IMPORTED_BY,
651 &menu.main.text.level_imported_by, &main_text_level_imported_by,
655 MAIN_CONTROL_LEVEL_TESTED_BY,
657 &menu.main.text.level_tested_by, &main_text_level_tested_by,
661 MAIN_CONTROL_TITLE_1,
663 &menu.main.text.title_1, &setup.internal.program_title,
667 MAIN_CONTROL_TITLE_2,
669 &menu.main.text.title_2, &setup.internal.program_copyright,
673 MAIN_CONTROL_TITLE_3,
675 &menu.main.text.title_3, &setup.internal.program_company,
688 static int getTitleScreenGraphic(int nr, boolean initial)
690 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
693 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
695 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
699 static int getTitleScreenGameMode(boolean initial)
701 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
705 static int getTitleMessageGameMode(boolean initial)
707 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
711 static int getTitleScreenBackground(boolean initial)
713 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
718 static int getTitleMessageBackground(int nr, boolean initial)
720 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
724 static int getTitleBackground(int nr, boolean initial, boolean is_image)
726 int base = (is_image ?
727 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
728 IMG_BACKGROUND_TITLESCREEN_1) :
729 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
730 IMG_BACKGROUND_TITLEMESSAGE_1));
731 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
732 IMG_BACKGROUND_TITLE);
733 int graphic_local = base + nr;
735 if (graphic_info[graphic_local].bitmap != NULL)
736 return graphic_local;
738 if (graphic_info[graphic_global].bitmap != NULL)
739 return graphic_global;
741 return IMG_UNDEFINED;
744 static int getTitleSound(struct TitleControlInfo *tci)
746 boolean is_image = tci->is_image;
747 int initial = tci->initial;
748 int nr = tci->local_nr;
749 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
750 int base = (is_image ?
751 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
752 SND_BACKGROUND_TITLESCREEN_1) :
753 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
754 SND_BACKGROUND_TITLEMESSAGE_1));
755 int sound_global = menu.sound[mode];
756 int sound_local = base + nr;
759 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
760 nr, initial, is_image,
761 sound_global, getSoundListEntry(sound_global)->filename,
762 sound_local, getSoundListEntry(sound_local)->filename);
765 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
768 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
771 return SND_UNDEFINED;
774 static int getTitleMusic(struct TitleControlInfo *tci)
776 boolean is_image = tci->is_image;
777 int initial = tci->initial;
778 int nr = tci->local_nr;
779 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
780 int base = (is_image ?
781 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
782 MUS_BACKGROUND_TITLESCREEN_1) :
783 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
784 MUS_BACKGROUND_TITLEMESSAGE_1));
785 int music_global = menu.music[mode];
786 int music_local = base + nr;
789 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
790 nr, initial, is_image,
791 music_global, getMusicListEntry(music_global)->filename,
792 music_local, getMusicListEntry(music_local)->filename);
795 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
798 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
801 return MUS_UNDEFINED;
804 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
806 boolean is_image = tci->is_image;
807 boolean initial = tci->initial;
808 boolean first = tci->first;
809 int nr = tci->local_nr;
810 struct TitleMessageInfo tmi;
811 struct TitleFadingInfo ti;
813 tmi = (is_image ? (initial ? (first ?
814 titlescreen_initial_first[nr] :
815 titlescreen_initial[nr])
817 titlescreen_first[nr] :
819 : (initial ? (first ?
820 titlemessage_initial_first[nr] :
821 titlemessage_initial[nr])
823 titlemessage_first[nr] :
826 ti.fade_mode = tmi.fade_mode;
827 ti.fade_delay = tmi.fade_delay;
828 ti.post_delay = tmi.post_delay;
829 ti.auto_delay = tmi.auto_delay;
834 static int compareTitleControlInfo(const void *object1, const void *object2)
836 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
837 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
840 if (tci1->initial != tci2->initial)
841 compare_result = (tci1->initial ? -1 : +1);
842 else if (tci1->sort_priority != tci2->sort_priority)
843 compare_result = tci1->sort_priority - tci2->sort_priority;
844 else if (tci1->is_image != tci2->is_image)
845 compare_result = (tci1->is_image ? -1 : +1);
847 compare_result = tci1->local_nr - tci2->local_nr;
849 return compare_result;
852 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
854 int nr, int sort_priority)
856 title_controls[num_title_screens].is_image = is_image;
857 title_controls[num_title_screens].initial = initial;
858 title_controls[num_title_screens].local_nr = nr;
859 title_controls[num_title_screens].sort_priority = sort_priority;
861 title_controls[num_title_screens].first = FALSE; /* will be set later */
866 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
870 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
872 int graphic = getTitleScreenGraphic(i, initial);
873 Bitmap *bitmap = graphic_info[graphic].bitmap;
874 int sort_priority = graphic_info[graphic].sort_priority;
877 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
880 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
882 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
883 char *filename = getLevelSetTitleMessageFilename(i, initial);
884 int sort_priority = tmi->sort_priority;
886 if (filename != NULL)
887 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
891 static void InitializeTitleControls(boolean show_title_initial)
893 num_title_screens = 0;
895 /* 1st step: initialize title screens for game start (only when starting) */
896 if (show_title_initial)
897 InitializeTitleControls_CheckTitleInfo(TRUE);
899 /* 2nd step: initialize title screens for current level set */
900 InitializeTitleControls_CheckTitleInfo(FALSE);
902 /* sort title screens according to sort_priority and title number */
903 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
904 compareTitleControlInfo);
906 /* mark first title screen */
907 title_controls[0].first = TRUE;
910 static boolean visibleMenuPos(struct MenuPosInfo *pos)
912 return (pos != NULL && pos->x != -1 && pos->y != -1);
915 static boolean visibleTextPos(struct TextPosInfo *pos)
917 return (pos != NULL && pos->x != -1 && pos->y != -1);
920 static void InitializeMainControls()
922 boolean local_team_mode = (!options.network && setup.team_mode);
925 /* set main control text values to dynamically determined values */
926 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
928 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
929 menu.main.text.first_level.size));
930 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
931 menu.main.text.last_level.size));
932 strcpy(main_text_level_number, int2str(level_nr,
933 menu.main.text.level_number.size));
935 main_text_level_year = leveldir_current->year;
936 main_text_level_imported_from = leveldir_current->imported_from;
937 main_text_level_imported_by = leveldir_current->imported_by;
938 main_text_level_tested_by = leveldir_current->tested_by;
940 /* set main control screen positions to dynamically determined values */
941 for (i = 0; main_controls[i].nr != -1; i++)
943 struct MainControlInfo *mci = &main_controls[i];
945 struct MenuPosInfo *pos_button = mci->pos_button;
946 struct TextPosInfo *pos_text = mci->pos_text;
947 struct TextPosInfo *pos_input = mci->pos_input;
948 char *text = (mci->text ? *mci->text : NULL);
949 char *input = (mci->input ? *mci->input : NULL);
950 int button_graphic = mci->button_graphic;
951 int font_text = (pos_text ? pos_text->font : -1);
952 int font_input = (pos_input ? pos_input->font : -1);
954 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
955 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
956 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
957 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
958 int text_chars = (text != NULL ? strlen(text) : 0);
959 int input_chars = (input != NULL ? strlen(input) : 0);
962 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
964 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
965 int text_width = font_text_width * text_chars;
966 int text_height = font_text_height;
967 int input_width = font_input_width * input_chars;
968 int input_height = font_input_height;
970 if (nr == MAIN_CONTROL_NAME)
972 menu.main.input.name.width = input_width;
973 menu.main.input.name.height = input_height;
976 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
978 pos_button->width = button_width;
979 pos_button->height = button_height;
982 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
984 /* calculate size for non-clickable text -- needed for text alignment */
985 boolean calculate_text_size = (pos_button == NULL && text != NULL);
987 if (pos_text->width == -1 || calculate_text_size)
988 pos_text->width = text_width;
989 if (pos_text->height == -1 || calculate_text_size)
990 pos_text->height = text_height;
992 if (visibleMenuPos(pos_button))
994 if (pos_text->x == -1)
995 pos_text->x = pos_button->x + pos_button->width;
996 if (pos_text->y == -1)
998 pos_button->y + (pos_button->height - pos_text->height) / 2;
1002 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1004 if (visibleTextPos(pos_text))
1006 if (pos_input->x == -1)
1007 pos_input->x = pos_text->x + pos_text->width;
1008 if (pos_input->y == -1)
1009 pos_input->y = pos_text->y;
1012 if (pos_input->width == -1)
1013 pos_input->width = input_width;
1014 if (pos_input->height == -1)
1015 pos_input->height = input_height;
1020 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1021 int graphic, boolean pressed)
1023 struct GraphicInfo *g = &graphic_info[graphic];
1026 int xoffset = (pressed ? g->pressed_xoffset : 0);
1027 int yoffset = (pressed ? g->pressed_yoffset : 0);
1029 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1031 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1032 g->width, g->height, dst_x, dst_y);
1035 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1036 boolean active_input,
1037 boolean pressed_button)
1041 for (i = 0; main_controls[i].nr != -1; i++)
1043 struct MainControlInfo *mci = &main_controls[i];
1045 if (mci->nr == nr || nr == -1)
1047 struct MenuPosInfo *pos_button = mci->pos_button;
1048 struct TextPosInfo *pos_text = mci->pos_text;
1049 struct TextPosInfo *pos_input = mci->pos_input;
1050 char *text = (mci->text ? *mci->text : NULL);
1051 char *input = (mci->input ? *mci->input : NULL);
1052 int button_graphic = mci->button_graphic;
1053 int font_text = (pos_text ? pos_text->font : -1);
1054 int font_input = (pos_input ? pos_input->font : -1);
1058 button_graphic = BUTTON_ACTIVE(button_graphic);
1059 font_text = FONT_ACTIVE(font_text);
1064 font_input = FONT_ACTIVE(font_input);
1067 if (visibleMenuPos(pos_button))
1069 struct MenuPosInfo *pos = pos_button;
1070 int x = mSX + pos->x;
1071 int y = mSY + pos->y;
1073 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1074 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1077 if (visibleTextPos(pos_text) && text != NULL)
1079 struct TextPosInfo *pos = pos_text;
1080 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1081 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1084 /* (check why/if this is needed) */
1085 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1087 DrawText(x, y, text, font_text);
1090 if (visibleTextPos(pos_input) && input != NULL)
1092 struct TextPosInfo *pos = pos_input;
1093 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1094 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1097 /* (check why/if this is needed) */
1098 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1100 DrawText(x, y, input, font_input);
1106 static void DrawCursorAndText_Main(int nr, boolean active_text,
1107 boolean pressed_button)
1109 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1113 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1114 boolean pressed_button)
1116 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1120 static struct MainControlInfo *getMainControlInfo(int nr)
1124 for (i = 0; main_controls[i].nr != -1; i++)
1125 if (main_controls[i].nr == nr)
1126 return &main_controls[i];
1131 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1136 int rect_x = ALIGNED_TEXT_XPOS(rect);
1137 int rect_y = ALIGNED_TEXT_YPOS(rect);
1139 return (x >= rect_x && x < rect_x + rect->width &&
1140 y >= rect_y && y < rect_y + rect->height);
1143 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1148 int rect_x = ALIGNED_TEXT_XPOS(rect);
1149 int rect_y = ALIGNED_TEXT_YPOS(rect);
1152 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1153 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1154 (x >= rect_x && x < rect_x + rect->width &&
1155 y >= rect_y && y < rect_y + rect->height));
1158 return (x >= rect_x && x < rect_x + rect->width &&
1159 y >= rect_y && y < rect_y + rect->height);
1162 static void AdjustScrollbar(int id, int items_max, int items_visible,
1165 struct GadgetInfo *gi = screen_gadget[id];
1167 if (item_position > items_max - items_visible)
1168 item_position = items_max - items_visible;
1170 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1171 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1172 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1175 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1177 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1181 static void clearMenuListArea()
1183 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1185 /* correct scrollbar position if placed outside menu (playfield) area */
1186 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1187 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1189 /* clear menu list area, but not title or scrollbar */
1190 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1191 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1194 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1196 static int cursor_array[MAX_LEV_FIELDY];
1197 int x = mSX + TILEX * xpos;
1198 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1203 cursor_array[ypos] = graphic;
1205 graphic = cursor_array[ypos];
1209 graphic = BUTTON_ACTIVE(graphic);
1211 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1212 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1215 static void initCursor(int ypos, int graphic)
1217 drawCursorExt(0, ypos, FALSE, graphic);
1220 static void drawCursor(int ypos, boolean active)
1222 drawCursorExt(0, ypos, active, -1);
1225 static void drawCursorXY(int xpos, int ypos, int graphic)
1227 drawCursorExt(xpos, ypos, FALSE, graphic);
1230 static void drawChooseTreeCursor(int ypos, boolean active)
1232 int last_game_status = game_status; /* save current game status */
1234 drawCursorExt(0, ypos, active, -1);
1236 SetGameStatus(last_game_status); /* restore current game status */
1241 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1242 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1243 setup.internal.program_copyright);
1246 void DrawTitleScreenImage(int nr, boolean initial)
1248 int graphic = getTitleScreenGraphic(nr, initial);
1249 Bitmap *bitmap = graphic_info[graphic].bitmap;
1250 int width = graphic_info[graphic].width;
1251 int height = graphic_info[graphic].height;
1252 int src_x = graphic_info[graphic].src_x;
1253 int src_y = graphic_info[graphic].src_y;
1259 if (width > WIN_XSIZE)
1261 /* image width too large for window => center image horizontally */
1262 src_x = (width - WIN_XSIZE) / 2;
1266 if (height > WIN_YSIZE)
1268 /* image height too large for window => center image vertically */
1269 src_y = (height - WIN_YSIZE) / 2;
1273 /* always display title screens centered */
1274 dst_x = (WIN_XSIZE - width) / 2;
1275 dst_y = (WIN_YSIZE - height) / 2;
1277 SetDrawBackgroundMask(REDRAW_ALL);
1278 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1280 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1282 if (DrawingOnBackground(dst_x, dst_y))
1283 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1285 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1287 redraw_mask = REDRAW_ALL;
1290 void DrawTitleScreenMessage(int nr, boolean initial)
1292 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1293 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1294 int last_game_status = game_status; /* save current game status */
1296 if (filename == NULL)
1299 /* force TITLE font on title message screen */
1300 SetGameStatus(getTitleMessageGameMode(initial));
1302 /* if chars *and* width set to "-1", automatically determine width */
1303 if (tmi->chars == -1 && tmi->width == -1)
1304 tmi->width = viewport.window[game_status].width;
1306 /* if lines *and* height set to "-1", automatically determine height */
1307 if (tmi->lines == -1 && tmi->height == -1)
1308 tmi->height = viewport.window[game_status].height;
1310 /* if chars set to "-1", automatically determine by text and font width */
1311 if (tmi->chars == -1)
1312 tmi->chars = tmi->width / getFontWidth(tmi->font);
1314 tmi->width = tmi->chars * getFontWidth(tmi->font);
1316 /* if lines set to "-1", automatically determine by text and font height */
1317 if (tmi->lines == -1)
1318 tmi->lines = tmi->height / getFontHeight(tmi->font);
1320 tmi->height = tmi->lines * getFontHeight(tmi->font);
1322 /* if x set to "-1", automatically determine by width and alignment */
1324 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1326 /* if y set to "-1", automatically determine by height and alignment */
1328 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1330 SetDrawBackgroundMask(REDRAW_ALL);
1331 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1333 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1335 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1336 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1337 tmi->autowrap, tmi->centered, tmi->parse_comments);
1339 SetGameStatus(last_game_status); /* restore current game status */
1342 void DrawTitleScreen()
1344 KeyboardAutoRepeatOff();
1346 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1351 boolean CheckTitleScreen(boolean levelset_has_changed)
1353 static boolean show_title_initial = TRUE;
1354 boolean show_titlescreen = FALSE;
1356 /* needed to be able to skip title screen, if no image or message defined */
1357 InitializeTitleControls(show_title_initial);
1359 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1360 show_titlescreen = TRUE;
1362 /* show initial title images and messages only once at program start */
1363 show_title_initial = FALSE;
1365 return (show_titlescreen && num_title_screens > 0);
1370 static LevelDirTree *leveldir_last_valid = NULL;
1371 boolean levelset_has_changed = FALSE;
1372 int fade_mask = REDRAW_FIELD;
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 CloseDoor(DOOR_CLOSE_ALL);
1395 SetGameStatus(GAME_MODE_EDITOR);
1402 /* needed if last screen was the setup screen and fullscreen state changed */
1403 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1404 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1406 /* leveldir_current may be invalid (level group, parent link) */
1407 if (!validLevelSeries(leveldir_current))
1408 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1410 if (leveldir_current != leveldir_last_valid)
1411 levelset_has_changed = TRUE;
1413 /* store valid level series information */
1414 leveldir_last_valid = leveldir_current;
1416 init_last = init; /* switch to new busy animation */
1418 /* needed if last screen (level choice) changed graphics, sounds or music */
1419 ReloadCustomArtwork(0);
1421 if (CheckTitleScreen(levelset_has_changed))
1423 game_status_last_screen = GAME_MODE_MAIN;
1425 SetGameStatus(GAME_MODE_TITLE);
1432 /* needed if different viewport properties defined for menues */
1433 ChangeViewportPropertiesIfNeeded();
1435 if (redraw_mask & REDRAW_ALL)
1436 fade_mask = REDRAW_ALL;
1438 if (CheckIfGlobalBorderHasChanged())
1439 fade_mask = REDRAW_ALL;
1443 SetDrawtoField(DRAW_BACKBUFFER);
1445 /* level_nr may have been set to value over handicap with level editor */
1446 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1447 level_nr = leveldir_current->handicap_level;
1449 LoadLevel(level_nr);
1450 LoadScore(level_nr);
1452 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1453 SetDrawDeactivationMask(REDRAW_NONE);
1454 SetDrawBackgroundMask(REDRAW_FIELD);
1456 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1459 if (fade_mask == REDRAW_ALL)
1460 RedrawGlobalBorder();
1465 InitializeMainControls();
1467 DrawCursorAndText_Main(-1, FALSE, FALSE);
1468 DrawPreviewLevelInitial();
1470 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1473 if (TAPE_IS_EMPTY(tape))
1475 DrawCompleteVideoDisplay();
1480 /* create gadgets for main menu screen */
1481 FreeScreenGadgets();
1482 CreateScreenGadgets();
1484 /* map gadgets for main menu screen */
1486 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1488 /* copy actual game door content to door double buffer for OpenDoor() */
1489 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1490 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1492 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1494 DrawMaskedBorder(fade_mask);
1499 /* update screen area with special editor door */
1500 redraw_mask |= REDRAW_ALL;
1503 SetMouseCursor(CURSOR_DEFAULT);
1507 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1510 static void gotoTopLevelDir()
1512 /* move upwards until inside (but not above) top level directory */
1513 while (leveldir_current->node_parent &&
1514 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1516 /* write a "path" into level tree for easy navigation to last level */
1517 if (leveldir_current->node_parent->node_group->cl_first == -1)
1519 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1520 int leveldir_pos = posTreeInfo(leveldir_current);
1521 int num_page_entries;
1522 int cl_first, cl_cursor;
1524 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1525 num_page_entries = num_leveldirs;
1527 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1529 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1530 cl_cursor = leveldir_pos - cl_first;
1532 leveldir_current->node_parent->node_group->cl_first = cl_first;
1533 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1536 leveldir_current = leveldir_current->node_parent;
1540 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1542 static unsigned int title_delay = 0;
1543 static int title_screen_nr = 0;
1544 static int last_sound = -1, last_music = -1;
1545 boolean return_to_main_menu = FALSE;
1546 struct TitleControlInfo *tci;
1549 if (button == MB_MENU_INITIALIZE)
1552 title_screen_nr = 0;
1553 tci = &title_controls[title_screen_nr];
1555 last_sound = SND_UNDEFINED;
1556 last_music = MUS_UNDEFINED;
1558 if (num_title_screens != 0)
1560 FadeSetEnterScreen();
1562 /* use individual title fading instead of global "enter screen" fading */
1563 fading = getTitleFading(tci);
1566 if (game_status_last_screen == GAME_MODE_INFO)
1568 if (num_title_screens == 0)
1570 /* switch game mode from title screen mode back to info screen mode */
1571 SetGameStatus(GAME_MODE_INFO);
1573 DrawInfoScreen_NotAvailable("Title screen information:",
1574 "No title screen for this level set.");
1579 FadeSoundsAndMusic();
1582 FadeOut(REDRAW_ALL);
1584 /* only required to update logic for redrawing global border */
1587 /* title screens may have different window size */
1588 ChangeViewportPropertiesIfNeeded();
1591 DrawTitleScreenImage(tci->local_nr, tci->initial);
1593 DrawTitleScreenMessage(tci->local_nr, tci->initial);
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 DelayReached(&title_delay, 0); /* reset delay counter */
1615 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1616 button = MB_MENU_CHOICE;
1618 if (button == MB_MENU_LEAVE)
1620 return_to_main_menu = TRUE;
1622 else if (button == MB_MENU_CHOICE)
1624 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1626 SetGameStatus(GAME_MODE_INFO);
1628 info_mode = INFO_MODE_MAIN;
1636 tci = &title_controls[title_screen_nr];
1638 if (title_screen_nr < num_title_screens)
1640 sound = getTitleSound(tci);
1641 music = getTitleMusic(tci);
1643 if (sound == SND_UNDEFINED || sound != last_sound)
1645 if (music == MUS_UNDEFINED || music != last_music)
1648 fading = getTitleFading(tci);
1650 FadeOut(REDRAW_ALL);
1653 DrawTitleScreenImage(tci->local_nr, tci->initial);
1655 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1657 sound = getTitleSound(tci);
1658 music = getTitleMusic(tci);
1660 if (sound != last_sound)
1661 PlayMenuSoundExt(sound);
1662 if (music != last_music)
1663 PlayMenuMusicExt(music);
1670 DelayReached(&title_delay, 0); /* reset delay counter */
1674 FadeSoundsAndMusic();
1676 return_to_main_menu = TRUE;
1680 if (return_to_main_menu)
1682 SetMouseCursor(CURSOR_DEFAULT);
1684 /* force full menu screen redraw after displaying title screens */
1685 redraw_mask = REDRAW_ALL;
1687 if (game_status_last_screen == GAME_MODE_INFO)
1689 SetGameStatus(GAME_MODE_INFO);
1691 info_mode = INFO_MODE_MAIN;
1695 else /* default: return to main menu */
1697 SetGameStatus(GAME_MODE_MAIN);
1704 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1706 int old_level_nr = level_nr;
1709 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1710 new_level_nr = selected_level_nr;
1712 new_level_nr = old_level_nr + step * direction;
1714 if (new_level_nr < leveldir_current->first_level)
1715 new_level_nr = leveldir_current->first_level;
1716 if (new_level_nr > leveldir_current->last_level)
1717 new_level_nr = leveldir_current->last_level;
1719 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1721 /* skipping levels is only allowed when trying to skip single level */
1722 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1723 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1725 leveldir_current->handicap_level++;
1726 SaveLevelSetup_SeriesInfo();
1729 new_level_nr = leveldir_current->handicap_level;
1732 if (new_level_nr != old_level_nr)
1734 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1736 PlaySound(SND_MENU_ITEM_SELECTING);
1738 level_nr = new_level_nr;
1740 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1741 int2str(level_nr, menu.main.text.level_number.size),
1742 mci->pos_text->font);
1744 LoadLevel(level_nr);
1745 DrawPreviewLevelInitial();
1749 DrawCompleteVideoDisplay();
1751 /* needed because DrawPreviewLevelInitial() takes some time */
1753 /* SyncDisplay(); */
1757 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1759 static int choice = MAIN_CONTROL_GAME;
1760 static boolean button_pressed_last = FALSE;
1761 boolean button_pressed = FALSE;
1765 if (button == MB_MENU_INITIALIZE)
1767 DrawCursorAndText_Main(choice, TRUE, FALSE);
1772 if (mx || my) /* mouse input */
1776 for (i = 0; main_controls[i].nr != -1; i++)
1778 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1779 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1780 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1782 pos = main_controls[i].nr;
1788 // handle pressed/unpressed state for active/inactive menu buttons
1789 // (if pos != -1, "i" contains index position corresponding to "pos")
1791 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1792 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1793 button_pressed = TRUE;
1795 if (button_pressed != button_pressed_last)
1797 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1800 PlaySound(SND_MENU_BUTTON_PRESSING);
1802 PlaySound(SND_MENU_BUTTON_RELEASING);
1805 else if (dx || dy) /* keyboard input */
1807 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1808 choice == MAIN_CONTROL_SETUP))
1809 button = MB_MENU_CHOICE;
1814 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1816 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1818 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1820 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1822 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1824 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1826 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1830 CloseDoor(DOOR_CLOSE_2);
1832 SetGameStatus(GAME_MODE_LEVELNR);
1834 ChangeViewportPropertiesIfNeeded();
1836 DrawChooseLevelNr();
1838 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1844 PlaySound(SND_MENU_ITEM_ACTIVATING);
1846 DrawCursorAndText_Main(choice, FALSE, FALSE);
1847 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1854 PlaySound(SND_MENU_ITEM_SELECTING);
1856 if (pos == MAIN_CONTROL_NAME)
1858 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1860 HandleTypeName(strlen(setup.player_name), 0);
1862 else if (pos == MAIN_CONTROL_LEVELS)
1868 CloseDoor(DOOR_CLOSE_2);
1870 SetGameStatus(GAME_MODE_LEVELS);
1872 SaveLevelSetup_LastSeries();
1873 SaveLevelSetup_SeriesInfo();
1875 if (setup.internal.choose_from_top_leveldir)
1878 ChangeViewportPropertiesIfNeeded();
1880 DrawChooseLevelSet();
1883 else if (pos == MAIN_CONTROL_SCORES)
1887 CloseDoor(DOOR_CLOSE_2);
1889 SetGameStatus(GAME_MODE_SCORES);
1893 else if (pos == MAIN_CONTROL_EDITOR)
1895 if (leveldir_current->readonly &&
1896 !strEqual(setup.player_name, "Artsoft"))
1897 Request("This level is read only!", REQ_CONFIRM);
1901 CloseDoor(DOOR_CLOSE_2);
1903 SetGameStatus(GAME_MODE_EDITOR);
1905 FadeSetEnterScreen();
1909 else if (pos == MAIN_CONTROL_INFO)
1913 CloseDoor(DOOR_CLOSE_2);
1915 SetGameStatus(GAME_MODE_INFO);
1917 info_mode = INFO_MODE_MAIN;
1919 ChangeViewportPropertiesIfNeeded();
1923 else if (pos == MAIN_CONTROL_GAME)
1927 StartGameActions(options.network, setup.autorecord, level.random_seed);
1929 else if (pos == MAIN_CONTROL_SETUP)
1933 CloseDoor(DOOR_CLOSE_2);
1935 SetGameStatus(GAME_MODE_SETUP);
1937 setup_mode = SETUP_MODE_MAIN;
1939 ChangeViewportPropertiesIfNeeded();
1943 else if (pos == MAIN_CONTROL_QUIT)
1945 SaveLevelSetup_LastSeries();
1946 SaveLevelSetup_SeriesInfo();
1948 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1949 SetGameStatus(GAME_MODE_QUIT);
1954 button_pressed_last = button_pressed;
1958 /* ========================================================================= */
1959 /* info screen functions */
1960 /* ========================================================================= */
1962 static struct TokenInfo *info_info;
1963 static int num_info_info; /* number of info entries shown on screen */
1964 static int max_info_info; /* total number of info entries in list */
1966 static void execInfoTitleScreen()
1968 info_mode = INFO_MODE_TITLE;
1973 static void execInfoElements()
1975 info_mode = INFO_MODE_ELEMENTS;
1980 static void execInfoMusic()
1982 info_mode = INFO_MODE_MUSIC;
1987 static void execInfoCredits()
1989 info_mode = INFO_MODE_CREDITS;
1994 static void execInfoProgram()
1996 info_mode = INFO_MODE_PROGRAM;
2001 static void execInfoVersion()
2003 info_mode = INFO_MODE_VERSION;
2008 static void execInfoLevelSet()
2010 info_mode = INFO_MODE_LEVELSET;
2015 static void execExitInfo()
2017 SetGameStatus(GAME_MODE_MAIN);
2022 static struct TokenInfo info_info_main[] =
2024 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2025 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2026 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2027 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2028 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2029 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2030 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2031 { TYPE_EMPTY, NULL, "" },
2032 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2037 static int getMenuTextFont(int type)
2039 if (type & (TYPE_SWITCH |
2051 static struct TokenInfo *setup_info;
2052 static struct TokenInfo setup_info_input[];
2054 static struct TokenInfo *menu_info;
2056 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2057 int screen_pos, int menu_info_pos_raw,
2060 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2061 struct TokenInfo *ti = &token_info[pos];
2062 int xpos = MENU_SCREEN_START_XPOS;
2063 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2064 int font_nr = getMenuTextFont(ti->type);
2066 if (token_info == setup_info_input)
2067 font_nr = FONT_MENU_1;
2070 font_nr = FONT_ACTIVE(font_nr);
2072 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2074 if (ti->type & ~TYPE_SKIP_ENTRY)
2075 drawCursor(screen_pos, active);
2078 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2081 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2084 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2087 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2090 static char *window_size_text;
2091 static char *scaling_type_text;
2093 static void drawSetupValue(int, int);
2095 static void drawMenuInfoList(int first_entry, int num_page_entries,
2096 int max_page_entries)
2100 if (first_entry + num_page_entries > max_page_entries)
2103 clearMenuListArea();
2105 for (i = 0; i < num_page_entries; i++)
2107 int menu_info_pos = first_entry + i;
2108 struct TokenInfo *si = &menu_info[menu_info_pos];
2109 void *value_ptr = si->value;
2111 /* set some entries to "unchangeable" according to other variables */
2112 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2113 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2114 (value_ptr == &setup.sound_music && !audio.music_available) ||
2115 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2116 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2117 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2118 si->type |= TYPE_GHOSTED;
2120 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2121 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2122 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2123 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2124 else if (si->type & ~TYPE_SKIP_ENTRY)
2125 initCursor(i, IMG_MENU_BUTTON);
2127 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2129 if (si->type & TYPE_VALUE &&
2130 menu_info == setup_info)
2131 drawSetupValue(i, menu_info_pos);
2135 static void DrawInfoScreen_Main()
2137 int fade_mask = REDRAW_FIELD;
2140 if (redraw_mask & REDRAW_ALL)
2141 fade_mask = REDRAW_ALL;
2143 if (CheckIfGlobalBorderHasChanged())
2144 fade_mask = REDRAW_ALL;
2148 FreeScreenGadgets();
2149 CreateScreenGadgets();
2151 /* (needed after displaying title screens which disable auto repeat) */
2152 KeyboardAutoRepeatOn();
2154 FadeSetLeaveScreen();
2158 ChangeViewportPropertiesIfNeeded();
2162 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2164 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2166 info_info = info_info_main;
2168 // determine maximal number of info entries that can be displayed on screen
2170 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2173 // determine maximal number of info entries available for menu of info screen
2175 for (i = 0; info_info[i].type != 0; i++)
2178 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2180 MapScreenGadgets(max_info_info);
2185 DrawMaskedBorder(fade_mask);
2192 static void changeSetupValue(int, int, int);
2194 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2195 int mode, int num_page_entries, int max_page_entries)
2197 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2198 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2199 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2200 int *num_page_entries_last = num_page_entries_all_last[game_status];
2201 int *choice_store = choice_stores[game_status];
2202 int *first_entry_store = first_entry_stores[game_status];
2203 int choice = choice_store[mode]; /* starts with 0 */
2204 int first_entry = first_entry_store[mode]; /* starts with 0 */
2206 int y = choice - first_entry;
2208 boolean position_set_by_scrollbar = (dx == 999);
2209 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2212 if (button == MB_MENU_INITIALIZE)
2214 // check if number of menu page entries has changed (may happen by change
2215 // of custom artwork definition value for 'list_size' for this menu screen)
2216 // (in this case, the last menu position most probably has to be corrected)
2217 if (num_page_entries != num_page_entries_last[mode])
2219 choice_store[mode] = first_entry_store[mode] = 0;
2221 choice = first_entry = 0;
2224 num_page_entries_last[mode] = num_page_entries;
2227 /* advance to first valid menu entry */
2228 while (choice < num_page_entries &&
2229 menu_info[choice].type & TYPE_SKIP_ENTRY)
2232 if (position_set_by_scrollbar)
2233 first_entry = first_entry_store[mode] = dy;
2235 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2236 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2238 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2240 if (choice < first_entry)
2242 choice = first_entry;
2244 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2247 else if (choice > first_entry + num_page_entries - 1)
2249 choice = first_entry + num_page_entries - 1;
2251 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2255 choice_store[mode] = choice;
2257 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2261 else if (button == MB_MENU_LEAVE)
2263 PlaySound(SND_MENU_ITEM_SELECTING);
2265 for (i = 0; i < max_page_entries; i++)
2267 if (menu_info[i].type & TYPE_LEAVE_MENU)
2269 void (*menu_callback_function)(void) = menu_info[i].value;
2273 menu_callback_function();
2275 break; /* absolutely needed because function changes 'menu_info'! */
2282 if (mx || my) /* mouse input */
2284 x = (mx - mSX) / 32;
2285 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2287 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2289 /* move cursor instead of scrolling when already at start/end of list */
2290 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2292 else if (dy == +1 * SCROLL_LINE &&
2293 first_entry + num_page_entries == max_page_entries)
2296 /* handle scrolling screen one line or page */
2298 y + dy > num_page_entries - 1)
2300 boolean redraw = FALSE;
2302 if (ABS(dy) == SCROLL_PAGE)
2303 step = num_page_entries - 1;
2305 if (dy < 0 && first_entry > 0)
2307 /* scroll page/line up */
2309 first_entry -= step;
2310 if (first_entry < 0)
2315 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2317 /* scroll page/line down */
2319 first_entry += step;
2320 if (first_entry + num_page_entries > max_page_entries)
2321 first_entry = MAX(0, max_page_entries - num_page_entries);
2328 choice += first_entry - first_entry_store[mode];
2330 if (choice < first_entry)
2332 choice = first_entry;
2334 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2337 else if (choice > first_entry + num_page_entries - 1)
2339 choice = first_entry + num_page_entries - 1;
2341 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2344 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2348 if (choice < first_entry ||
2349 choice > first_entry + num_page_entries - 1)
2350 first_entry += SIGN(dy);
2353 first_entry_store[mode] = first_entry;
2354 choice_store[mode] = choice;
2356 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2358 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2360 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2361 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2369 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2371 if (menu_info[choice].type & menu_navigation_type ||
2372 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2373 menu_info[choice].type & TYPE_YES_NO_AUTO)
2374 button = MB_MENU_CHOICE;
2379 /* jump to next non-empty menu entry (up or down) */
2380 while (first_entry + y > 0 &&
2381 first_entry + y < max_page_entries - 1 &&
2382 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2385 if (!IN_VIS_MENU(x, y))
2387 choice += y - y_old;
2389 if (choice < first_entry)
2390 first_entry = choice;
2391 else if (choice > first_entry + num_page_entries - 1)
2392 first_entry = choice - num_page_entries + 1;
2394 if (first_entry >= 0 &&
2395 first_entry + num_page_entries <= max_page_entries)
2397 first_entry_store[mode] = first_entry;
2399 if (choice < first_entry)
2400 choice = first_entry;
2401 else if (choice > first_entry + num_page_entries - 1)
2402 choice = first_entry + num_page_entries - 1;
2404 choice_store[mode] = choice;
2406 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2408 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2410 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2411 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2418 if (!anyScrollbarGadgetActive() &&
2419 IN_VIS_MENU(x, y) &&
2420 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2421 y >= 0 && y < num_page_entries)
2425 if (first_entry + y != choice &&
2426 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2428 PlaySound(SND_MENU_ITEM_ACTIVATING);
2430 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2431 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2433 choice = choice_store[mode] = first_entry + y;
2436 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2438 PlaySound(SND_MENU_ITEM_SELECTING);
2440 /* when selecting key headline, execute function for key value change */
2441 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2442 menu_info[first_entry + y + 1].type & TYPE_KEY)
2445 /* when selecting string value, execute function for list selection */
2446 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2447 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2450 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2452 void (*menu_callback_function)(void) =
2453 menu_info[first_entry + y].value;
2455 FadeSetFromType(menu_info[first_entry + y].type);
2457 menu_callback_function();
2459 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2460 menu_info == setup_info)
2462 changeSetupValue(y, first_entry + y, dx);
2468 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2470 menu_info = info_info;
2472 HandleMenuScreen(mx, my, dx, dy, button,
2473 info_mode, num_info_info, max_info_info);
2476 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2478 int ystart1 = mSY - SY + 100;
2479 int ystart2 = mSY - SY + 150;
2480 int ybottom = mSY - SY + SYSIZE - 20;
2482 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2484 FadeOut(REDRAW_FIELD);
2489 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2490 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2492 DrawTextSCentered(ybottom, FONT_TEXT_4,
2493 "Press any key or button for info menu");
2495 FadeIn(REDRAW_FIELD);
2498 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2500 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2501 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2502 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2503 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2504 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2505 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2506 int ystep = MENU_SCREEN_INFO_YSTEP;
2507 int element, action, direction;
2515 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2516 infoscreen_step[i] = infoscreen_frame[i] = 0;
2521 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2523 DrawTextSCentered(ybottom, FONT_TEXT_4,
2524 "Press any key or button for next page");
2530 while (helpanim_info[j].element != HELPANIM_LIST_END)
2532 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2537 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2546 j += infoscreen_step[i - start];
2548 element = helpanim_info[j].element;
2549 action = helpanim_info[j].action;
2550 direction = helpanim_info[j].direction;
2553 element = EL_UNKNOWN;
2555 if (action != -1 && direction != -1)
2556 graphic = el_act_dir2img(element, action, direction);
2557 else if (action != -1)
2558 graphic = el_act2img(element, action);
2559 else if (direction != -1)
2560 graphic = el_dir2img(element, direction);
2562 graphic = el2img(element);
2564 delay = helpanim_info[j++].delay;
2569 if (infoscreen_frame[i - start] == 0)
2572 infoscreen_frame[i - start] = delay - 1;
2576 sync_frame = delay - infoscreen_frame[i - start];
2577 infoscreen_frame[i - start]--;
2580 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2582 if (!infoscreen_frame[i - start])
2583 infoscreen_step[i - start] = 0;
2587 if (!infoscreen_frame[i - start])
2588 infoscreen_step[i - start]++;
2589 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2595 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2597 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2598 graphic, sync_frame, USE_MASKING);
2601 DrawInfoScreen_HelpText(element, action, direction, i - start);
2606 redraw_mask |= REDRAW_FIELD;
2611 static char *getHelpText(int element, int action, int direction)
2613 char token[MAX_LINE_LEN];
2615 strcpy(token, element_info[element].token_name);
2618 strcat(token, element_action_info[action].suffix);
2620 if (direction != -1)
2621 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2623 return getHashEntry(helptext_info, token);
2626 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2628 int font_nr = FONT_INFO_ELEMENTS;
2629 int font_width = getFontWidth(font_nr);
2630 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2631 int sy = mSY + 65 + 2 * 32 + 1;
2632 int ystep = TILEY + 4;
2633 int pad_x = sx - SX;
2634 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2635 int max_lines_per_text = 2;
2638 if (action != -1 && direction != -1) /* element.action.direction */
2639 text = getHelpText(element, action, direction);
2641 if (text == NULL && action != -1) /* element.action */
2642 text = getHelpText(element, action, -1);
2644 if (text == NULL && direction != -1) /* element.direction */
2645 text = getHelpText(element, -1, direction);
2647 if (text == NULL) /* base element */
2648 text = getHelpText(element, -1, -1);
2650 if (text == NULL) /* not found */
2651 text = "No description available";
2653 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2654 sy += getFontHeight(font_nr) / 2;
2656 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2657 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2658 TRUE, FALSE, FALSE);
2661 void DrawInfoScreen_TitleScreen()
2663 game_status_last_screen = GAME_MODE_INFO;
2665 SetGameStatus(GAME_MODE_TITLE);
2670 void HandleInfoScreen_TitleScreen(int button)
2672 HandleTitleScreen(0, 0, 0, 0, button);
2675 void DrawInfoScreen_Elements()
2677 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2679 FadeOut(REDRAW_FIELD);
2684 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2686 FadeIn(REDRAW_FIELD);
2691 void HandleInfoScreen_Elements(int button)
2693 static unsigned int info_delay = 0;
2694 static int num_anims;
2695 static int num_pages;
2697 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2700 if (button == MB_MENU_INITIALIZE)
2702 boolean new_element = TRUE;
2706 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2708 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2710 else if (new_element)
2713 new_element = FALSE;
2717 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2721 if (button == MB_MENU_LEAVE)
2723 PlaySound(SND_MENU_ITEM_SELECTING);
2725 info_mode = INFO_MODE_MAIN;
2730 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2732 if (button != MB_MENU_INITIALIZE)
2734 PlaySound(SND_MENU_ITEM_SELECTING);
2739 if (page >= num_pages)
2741 FadeSoundsAndMusic();
2743 info_mode = INFO_MODE_MAIN;
2750 FadeSetNextScreen();
2752 if (button != MB_MENU_INITIALIZE)
2753 FadeOut(REDRAW_FIELD);
2755 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2757 if (button != MB_MENU_INITIALIZE)
2758 FadeIn(REDRAW_FIELD);
2762 if (DelayReached(&info_delay, GameFrameDelay))
2763 if (page < num_pages)
2764 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2766 PlayMenuSoundIfLoop();
2770 void DrawInfoScreen_Music()
2772 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2774 FadeOut(REDRAW_FIELD);
2781 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2783 FadeIn(REDRAW_FIELD);
2786 void HandleInfoScreen_Music(int button)
2788 static struct MusicFileInfo *list = NULL;
2789 int ystart1 = mSY - SY + 100;
2790 int ystart2 = mSY - SY + 150;
2791 int ybottom = mSY - SY + SYSIZE - 20;
2794 if (button == MB_MENU_INITIALIZE)
2796 list = music_file_info;
2800 FadeSoundsAndMusic();
2805 DrawTextSCentered(ystart1, FONT_TEXT_1,
2806 "No music info for this level set.");
2808 DrawTextSCentered(ybottom, FONT_TEXT_4,
2809 "Press any key or button for info menu");
2815 if (button == MB_MENU_LEAVE)
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2819 FadeSoundsAndMusic();
2821 info_mode = INFO_MODE_MAIN;
2826 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2830 if (button != MB_MENU_INITIALIZE)
2832 PlaySound(SND_MENU_ITEM_SELECTING);
2840 FadeSoundsAndMusic();
2842 info_mode = INFO_MODE_MAIN;
2848 FadeSoundsAndMusic();
2850 if (list != music_file_info)
2851 FadeSetNextScreen();
2853 if (button != MB_MENU_INITIALIZE)
2854 FadeOut(REDRAW_FIELD);
2861 int sound = list->music;
2863 if (sound_info[sound].loop)
2864 PlaySoundLoop(sound);
2868 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2872 PlayMusic(list->music);
2874 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2877 if (!strEqual(list->title, UNKNOWN_NAME))
2879 if (!strEqual(list->title_header, UNKNOWN_NAME))
2880 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2882 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2885 if (!strEqual(list->artist, UNKNOWN_NAME))
2887 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2888 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2890 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2892 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2895 if (!strEqual(list->album, UNKNOWN_NAME))
2897 if (!strEqual(list->album_header, UNKNOWN_NAME))
2898 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2900 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2902 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2905 if (!strEqual(list->year, UNKNOWN_NAME))
2907 if (!strEqual(list->year_header, UNKNOWN_NAME))
2908 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2910 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2912 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2915 DrawTextSCentered(ybottom, FONT_TEXT_4,
2916 "Press any key or button for next page");
2918 if (button != MB_MENU_INITIALIZE)
2919 FadeIn(REDRAW_FIELD);
2922 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2923 PlaySoundLoop(list->music);
2926 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2928 int ystart1 = mSY - SY + 100;
2929 int ystart2 = mSY - SY + 150;
2930 int ybottom = mSY - SY + SYSIZE - 20;
2936 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2940 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2941 "Special thanks to");
2942 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2944 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2946 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2947 "\"Boulder Dash\"");
2948 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2950 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2952 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2954 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2955 "First Star Software");
2957 else if (screen_nr == 1)
2959 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2960 "Special thanks to");
2961 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2962 "Klaus Heinz & Volker Wertich");
2963 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2965 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2966 "\"Emerald Mine\"");
2967 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2969 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2971 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2973 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2976 else if (screen_nr == 2)
2978 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2979 "Special thanks to");
2980 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2981 "Michael Stopp & Philip Jespersen");
2982 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2984 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2986 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2988 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2990 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2992 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2993 "Digital Integration");
2995 else if (screen_nr == 3)
2997 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2998 "Special thanks to");
2999 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3000 "Hiroyuki Imabayashi");
3001 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3003 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3005 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3007 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3009 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3011 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3014 else if (screen_nr == 4)
3016 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3017 "Special thanks to");
3018 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3020 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3022 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3023 "J\xfcrgen Bonhagen");
3024 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3025 "for the continuous creation");
3026 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3027 "of outstanding level sets");
3029 else if (screen_nr == 5)
3031 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3033 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3035 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3036 "for ideas and inspiration by");
3037 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3040 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3042 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3044 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3045 "for ideas and inspiration by");
3046 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3049 else if (screen_nr == 6)
3051 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3053 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3056 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3057 "for the code base used for the");
3058 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3059 "native Emerald Mine engine");
3061 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3062 "for the new Emerald Mine engine");
3065 else if (screen_nr == 7)
3067 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3069 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3071 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3072 "for the initial DOS port");
3074 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3076 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3078 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3079 "for some additional toons");
3081 else if (screen_nr == 8)
3083 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3084 "And not to forget:");
3085 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3087 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3088 "All those who contributed");
3089 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3090 "levels to this game");
3091 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3095 DrawTextSCentered(ybottom, FONT_TEXT_4,
3096 "Press any key or button for next page");
3099 void DrawInfoScreen_Credits()
3101 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3103 FadeSoundsAndMusic();
3105 FadeOut(REDRAW_FIELD);
3107 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3109 FadeIn(REDRAW_FIELD);
3112 void HandleInfoScreen_Credits(int button)
3114 static int screen_nr = 0;
3115 int num_screens = 9;
3117 if (button == MB_MENU_INITIALIZE)
3121 // DrawInfoScreen_CreditsScreen(screen_nr);
3124 if (button == MB_MENU_LEAVE)
3126 PlaySound(SND_MENU_ITEM_SELECTING);
3128 info_mode = INFO_MODE_MAIN;
3133 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3135 if (button != MB_MENU_INITIALIZE)
3137 PlaySound(SND_MENU_ITEM_SELECTING);
3142 if (screen_nr >= num_screens)
3144 FadeSoundsAndMusic();
3146 info_mode = INFO_MODE_MAIN;
3153 FadeSetNextScreen();
3155 if (button != MB_MENU_INITIALIZE)
3156 FadeOut(REDRAW_FIELD);
3158 DrawInfoScreen_CreditsScreen(screen_nr);
3160 if (button != MB_MENU_INITIALIZE)
3161 FadeIn(REDRAW_FIELD);
3165 PlayMenuSoundIfLoop();
3169 void DrawInfoScreen_Program()
3171 int ystart1 = mSY - SY + 100;
3172 int ystart2 = mSY - SY + 150;
3173 int ybottom = mSY - SY + SYSIZE - 20;
3176 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3178 FadeOut(REDRAW_FIELD);
3183 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3185 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3186 "This game is Freeware!");
3187 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3188 "If you like it, send e-mail to:");
3189 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3190 setup.internal.program_email);
3191 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3192 "More information and levels:");
3193 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3194 setup.internal.program_website);
3195 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3196 "If you have created new levels,");
3197 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3198 "send them to me to include them!");
3199 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3202 DrawTextSCentered(ybottom, FONT_TEXT_4,
3203 "Press any key or button for info menu");
3205 FadeIn(REDRAW_FIELD);
3208 void HandleInfoScreen_Program(int button)
3210 if (button == MB_MENU_LEAVE)
3212 PlaySound(SND_MENU_ITEM_SELECTING);
3214 info_mode = INFO_MODE_MAIN;
3219 else if (button == MB_MENU_CHOICE)
3221 PlaySound(SND_MENU_ITEM_SELECTING);
3223 FadeSoundsAndMusic();
3225 info_mode = INFO_MODE_MAIN;
3230 PlayMenuSoundIfLoop();
3234 void DrawInfoScreen_Version()
3236 int font_header = FONT_TEXT_3;
3237 int font_text = FONT_TEXT_2;
3238 int xstep = getFontWidth(font_text);
3239 int ystep = getFontHeight(font_text);
3240 int ystart1 = mSY - SY + 100;
3241 int ystart2 = mSY - SY + 150;
3242 int ybottom = mSY - SY + SYSIZE - 20;
3243 int xstart1 = mSX - SX + 2 * xstep;
3244 int xstart2 = mSX - SX + 18 * xstep;
3245 int xstart3 = mSX - SX + 28 * xstep;
3246 SDL_version sdl_version_compiled;
3247 const SDL_version *sdl_version_linked;
3248 int driver_name_len = 10;
3249 #if defined(TARGET_SDL2)
3250 SDL_version sdl_version_linked_ext;
3251 const char *driver_name = NULL;
3253 char driver_name[driver_name_len];
3256 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3258 FadeOut(REDRAW_FIELD);
3263 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3265 DrawTextF(xstart1, ystart2, font_header, "Name");
3266 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3269 DrawTextF(xstart1, ystart2, font_header, "Version");
3270 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3273 DrawTextF(xstart1, ystart2, font_header, "Platform");
3274 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3277 DrawTextF(xstart1, ystart2, font_header, "Target");
3278 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3281 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3282 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3284 ystart2 += 3 * ystep;
3285 DrawTextF(xstart1, ystart2, font_header, "Library");
3286 DrawTextF(xstart2, ystart2, font_header, "compiled");
3287 DrawTextF(xstart3, ystart2, font_header, "linked");
3289 SDL_VERSION(&sdl_version_compiled);
3290 #if defined(TARGET_SDL2)
3291 SDL_GetVersion(&sdl_version_linked_ext);
3292 sdl_version_linked = &sdl_version_linked_ext;
3294 sdl_version_linked = SDL_Linked_Version();
3297 ystart2 += 2 * ystep;
3298 DrawTextF(xstart1, ystart2, font_text, "SDL");
3299 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3300 sdl_version_compiled.major,
3301 sdl_version_compiled.minor,
3302 sdl_version_compiled.patch);
3303 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3304 sdl_version_linked->major,
3305 sdl_version_linked->minor,
3306 sdl_version_linked->patch);
3308 SDL_IMAGE_VERSION(&sdl_version_compiled);
3309 sdl_version_linked = IMG_Linked_Version();
3312 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3313 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3314 sdl_version_compiled.major,
3315 sdl_version_compiled.minor,
3316 sdl_version_compiled.patch);
3317 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3318 sdl_version_linked->major,
3319 sdl_version_linked->minor,
3320 sdl_version_linked->patch);
3322 SDL_MIXER_VERSION(&sdl_version_compiled);
3323 sdl_version_linked = Mix_Linked_Version();
3326 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3327 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3328 sdl_version_compiled.major,
3329 sdl_version_compiled.minor,
3330 sdl_version_compiled.patch);
3331 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3332 sdl_version_linked->major,
3333 sdl_version_linked->minor,
3334 sdl_version_linked->patch);
3336 SDL_NET_VERSION(&sdl_version_compiled);
3337 sdl_version_linked = SDLNet_Linked_Version();
3340 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3341 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3342 sdl_version_compiled.major,
3343 sdl_version_compiled.minor,
3344 sdl_version_compiled.patch);
3345 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3346 sdl_version_linked->major,
3347 sdl_version_linked->minor,
3348 sdl_version_linked->patch);
3350 ystart2 += 3 * ystep;
3351 DrawTextF(xstart1, ystart2, font_header, "Driver");
3352 DrawTextF(xstart2, ystart2, font_header, "Requested");
3353 DrawTextF(xstart3, ystart2, font_header, "Used");
3355 #if defined(TARGET_SDL2)
3356 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3358 SDL_VideoDriverName(driver_name, driver_name_len);
3361 ystart2 += 2 * ystep;
3362 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3363 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3364 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3366 #if defined(TARGET_SDL2)
3367 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3369 SDL_AudioDriverName(driver_name, driver_name_len);
3373 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3374 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3375 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3377 DrawTextSCentered(ybottom, FONT_TEXT_4,
3378 "Press any key or button for info menu");
3380 FadeIn(REDRAW_FIELD);
3383 void HandleInfoScreen_Version(int button)
3385 if (button == MB_MENU_LEAVE)
3387 PlaySound(SND_MENU_ITEM_SELECTING);
3389 info_mode = INFO_MODE_MAIN;
3394 else if (button == MB_MENU_CHOICE)
3396 PlaySound(SND_MENU_ITEM_SELECTING);
3398 FadeSoundsAndMusic();
3400 info_mode = INFO_MODE_MAIN;
3405 PlayMenuSoundIfLoop();
3409 void DrawInfoScreen_LevelSet()
3411 struct TitleMessageInfo *tmi = &readme;
3412 char *filename = getLevelSetInfoFilename();
3413 char *title = "Level Set Information:";
3414 int ystart1 = mSY - SY + 100;
3415 int ybottom = mSY - SY + SYSIZE - 20;
3417 if (filename == NULL)
3419 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3424 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3426 FadeOut(REDRAW_FIELD);
3431 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3433 /* if x position set to "-1", automatically determine by playfield width */
3435 tmi->x = SXSIZE / 2;
3437 /* if y position set to "-1", use static default value */
3441 /* if width set to "-1", automatically determine by playfield width */
3442 if (tmi->width == -1)
3443 tmi->width = SXSIZE - 2 * TILEX;
3445 /* if height set to "-1", automatically determine by playfield height */
3446 if (tmi->height == -1)
3447 tmi->height = SYSIZE - 20 - tmi->y - 10;
3449 /* if chars set to "-1", automatically determine by text and font width */
3450 if (tmi->chars == -1)
3451 tmi->chars = tmi->width / getFontWidth(tmi->font);
3453 tmi->width = tmi->chars * getFontWidth(tmi->font);
3455 /* if lines set to "-1", automatically determine by text and font height */
3456 if (tmi->lines == -1)
3457 tmi->lines = tmi->height / getFontHeight(tmi->font);
3459 tmi->height = tmi->lines * getFontHeight(tmi->font);
3461 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3462 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3463 tmi->autowrap, tmi->centered, tmi->parse_comments);
3465 DrawTextSCentered(ybottom, FONT_TEXT_4,
3466 "Press any key or button for info menu");
3468 FadeIn(REDRAW_FIELD);
3471 void HandleInfoScreen_LevelSet(int button)
3473 if (button == MB_MENU_LEAVE)
3475 PlaySound(SND_MENU_ITEM_SELECTING);
3477 info_mode = INFO_MODE_MAIN;
3482 else if (button == MB_MENU_CHOICE)
3484 PlaySound(SND_MENU_ITEM_SELECTING);
3486 FadeSoundsAndMusic();
3488 info_mode = INFO_MODE_MAIN;
3493 PlayMenuSoundIfLoop();
3497 static void DrawInfoScreen()
3499 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3501 if (info_mode == INFO_MODE_TITLE)
3502 DrawInfoScreen_TitleScreen();
3503 else if (info_mode == INFO_MODE_ELEMENTS)
3504 DrawInfoScreen_Elements();
3505 else if (info_mode == INFO_MODE_MUSIC)
3506 DrawInfoScreen_Music();
3507 else if (info_mode == INFO_MODE_CREDITS)
3508 DrawInfoScreen_Credits();
3509 else if (info_mode == INFO_MODE_PROGRAM)
3510 DrawInfoScreen_Program();
3511 else if (info_mode == INFO_MODE_VERSION)
3512 DrawInfoScreen_Version();
3513 else if (info_mode == INFO_MODE_LEVELSET)
3514 DrawInfoScreen_LevelSet();
3516 DrawInfoScreen_Main();
3518 if (info_mode != INFO_MODE_MAIN &&
3519 info_mode != INFO_MODE_TITLE &&
3520 info_mode != INFO_MODE_MUSIC)
3527 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3529 if (info_mode == INFO_MODE_TITLE)
3530 HandleInfoScreen_TitleScreen(button);
3531 else if (info_mode == INFO_MODE_ELEMENTS)
3532 HandleInfoScreen_Elements(button);
3533 else if (info_mode == INFO_MODE_MUSIC)
3534 HandleInfoScreen_Music(button);
3535 else if (info_mode == INFO_MODE_CREDITS)
3536 HandleInfoScreen_Credits(button);
3537 else if (info_mode == INFO_MODE_PROGRAM)
3538 HandleInfoScreen_Program(button);
3539 else if (info_mode == INFO_MODE_VERSION)
3540 HandleInfoScreen_Version(button);
3541 else if (info_mode == INFO_MODE_LEVELSET)
3542 HandleInfoScreen_LevelSet(button);
3544 HandleInfoScreen_Main(mx, my, dx, dy, button);
3548 /* ========================================================================= */
3549 /* type name functions */
3550 /* ========================================================================= */
3552 void HandleTypeName(int newxpos, Key key)
3554 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3555 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3556 struct TextPosInfo *pos = mci->pos_input;
3557 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3558 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3559 static int xpos = 0;
3560 int font_nr = pos->font;
3561 int font_active_nr = FONT_ACTIVE(font_nr);
3562 int font_width = getFontWidth(font_active_nr);
3563 char key_char = getValidConfigValueChar(getCharFromKey(key));
3564 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3565 boolean is_active = TRUE;
3567 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3571 strcpy(last_player_name, setup.player_name);
3575 #if defined(TARGET_SDL2)
3576 SDL_StartTextInput();
3579 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3581 setup.player_name[xpos] = key_char;
3582 setup.player_name[xpos + 1] = 0;
3586 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3590 setup.player_name[xpos] = 0;
3592 else if (key == KSYM_Return && xpos > 0)
3598 SetGameStatus(GAME_MODE_MAIN);
3600 else if (key == KSYM_Escape)
3602 strcpy(setup.player_name, last_player_name);
3606 SetGameStatus(GAME_MODE_MAIN);
3611 pos->width = (strlen(setup.player_name) + 1) * font_width;
3612 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3614 DrawText(startx, starty, setup.player_name, font_active_nr);
3615 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3619 pos->width = strlen(setup.player_name) * font_width;
3620 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3622 DrawText(startx, starty, setup.player_name, font_nr);
3624 #if defined(TARGET_SDL2)
3625 SDL_StopTextInput();
3631 /* ========================================================================= */
3632 /* tree menu functions */
3633 /* ========================================================================= */
3635 static void DrawChooseTree(TreeInfo **ti_ptr)
3637 int fade_mask = REDRAW_FIELD;
3639 if (CheckIfGlobalBorderHasChanged())
3640 fade_mask = REDRAW_ALL;
3642 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3644 SetGameStatus(GAME_MODE_MAIN);
3653 FreeScreenGadgets();
3654 CreateScreenGadgets();
3660 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3662 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3663 MapScreenTreeGadgets(*ti_ptr);
3665 DrawMaskedBorder(fade_mask);
3672 static void drawChooseTreeList(int first_entry, int num_page_entries,
3676 char *title_string = NULL;
3677 int yoffset_sets = MENU_TITLE1_YPOS;
3678 int yoffset_setup = 16;
3679 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3680 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3681 int last_game_status = game_status; /* save current game status */
3683 title_string = ti->infotext;
3685 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3687 clearMenuListArea();
3689 for (i = 0; i < num_page_entries; i++)
3691 TreeInfo *node, *node_first;
3692 int entry_pos = first_entry + i;
3693 int xpos = MENU_SCREEN_START_XPOS;
3694 int ypos = MENU_SCREEN_START_YPOS + i;
3695 int startx = mSX + xpos * 32;
3696 int starty = mSY + ypos * 32;
3697 int font_nr = FONT_TEXT_1;
3698 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3699 int startx_text = startx + font_xoffset;
3700 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3701 int text_size = startx_scrollbar - startx_text;
3702 int max_buffer_len = text_size / getFontWidth(font_nr);
3703 char buffer[max_buffer_len + 1];
3705 node_first = getTreeInfoFirstGroupEntry(ti);
3706 node = getTreeInfoFromPos(node_first, entry_pos);
3708 strncpy(buffer, node->name, max_buffer_len);
3709 buffer[max_buffer_len] = '\0';
3711 DrawText(startx, starty, buffer, font_nr + node->color);
3713 if (node->parent_link)
3714 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3715 else if (node->level_group)
3716 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3718 initCursor(i, IMG_MENU_BUTTON);
3721 SetGameStatus(last_game_status); /* restore current game status */
3723 redraw_mask |= REDRAW_FIELD;
3726 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3728 TreeInfo *node, *node_first;
3729 int x, last_redraw_mask = redraw_mask;
3730 int ypos = MENU_TITLE2_YPOS;
3731 int font_nr = FONT_TITLE_2;
3733 if (ti->type == TREE_TYPE_LEVEL_NR)
3734 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3736 if (ti->type != TREE_TYPE_LEVEL_DIR)
3739 node_first = getTreeInfoFirstGroupEntry(ti);
3740 node = getTreeInfoFromPos(node_first, entry_pos);
3742 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3744 if (node->parent_link)
3745 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3746 node->node_parent->name);
3747 else if (node->level_group)
3748 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3750 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3751 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3752 node->levels, (node->levels > 1 ? "levels" : "level"),
3755 /* let BackToFront() redraw only what is needed */
3756 redraw_mask = last_redraw_mask;
3757 for (x = 0; x < SCR_FIELDX; x++)
3758 MarkTileDirty(x, 1);
3761 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3764 TreeInfo *ti = *ti_ptr;
3766 int y = ti->cl_cursor;
3767 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3768 int num_entries = numTreeInfoInGroup(ti);
3769 int num_page_entries;
3770 int last_game_status = game_status; /* save current game status */
3771 boolean position_set_by_scrollbar = (dx == 999);
3773 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3774 num_page_entries = num_entries;
3776 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3778 SetGameStatus(last_game_status); /* restore current game status */
3780 if (button == MB_MENU_INITIALIZE)
3782 int num_entries = numTreeInfoInGroup(ti);
3783 int entry_pos = posTreeInfo(ti);
3785 if (ti->cl_first == -1)
3787 /* only on initialization */
3788 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3789 ti->cl_cursor = entry_pos - ti->cl_first;
3791 else if (ti->cl_cursor >= num_page_entries ||
3792 (num_entries > num_page_entries &&
3793 num_entries - ti->cl_first < num_page_entries))
3795 /* only after change of list size (by custom graphic configuration) */
3796 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3797 ti->cl_cursor = entry_pos - ti->cl_first;
3800 if (position_set_by_scrollbar)
3803 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3806 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3807 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3808 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3812 else if (button == MB_MENU_LEAVE)
3816 PlaySound(SND_MENU_ITEM_SELECTING);
3818 if (ti->node_parent)
3820 *ti_ptr = ti->node_parent;
3821 DrawChooseTree(ti_ptr);
3823 else if (game_status == GAME_MODE_SETUP)
3825 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3826 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3827 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3829 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3830 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3831 execSetupGraphics();
3832 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3833 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3834 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3836 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3837 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3838 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3845 if (game_status == GAME_MODE_LEVELNR)
3847 int new_level_nr = atoi(level_number_current->identifier);
3849 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3852 SetGameStatus(GAME_MODE_MAIN);
3860 if (mx || my) /* mouse input */
3862 int last_game_status = game_status; /* save current game status */
3864 x = (mx - mSX) / 32;
3865 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3867 SetGameStatus(last_game_status); /* restore current game status */
3869 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3871 /* move cursor instead of scrolling when already at start/end of list */
3872 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3874 else if (dy == +1 * SCROLL_LINE &&
3875 ti->cl_first + num_page_entries == num_entries)
3878 /* handle scrolling screen one line or page */
3879 if (ti->cl_cursor + dy < 0 ||
3880 ti->cl_cursor + dy > num_page_entries - 1)
3882 boolean redraw = FALSE;
3884 if (ABS(dy) == SCROLL_PAGE)
3885 step = num_page_entries - 1;
3887 if (dy < 0 && ti->cl_first > 0)
3889 /* scroll page/line up */
3891 ti->cl_first -= step;
3892 if (ti->cl_first < 0)
3897 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3899 /* scroll page/line down */
3901 ti->cl_first += step;
3902 if (ti->cl_first + num_page_entries > num_entries)
3903 ti->cl_first = MAX(0, num_entries - num_page_entries);
3910 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3911 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3912 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3914 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3921 /* handle moving cursor one line */
3922 y = ti->cl_cursor + dy;
3927 TreeInfo *node_first, *node_cursor;
3928 int entry_pos = ti->cl_first + y;
3930 node_first = getTreeInfoFirstGroupEntry(ti);
3931 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3933 if (node_cursor->node_group)
3937 PlaySound(SND_MENU_ITEM_SELECTING);
3939 node_cursor->cl_first = ti->cl_first;
3940 node_cursor->cl_cursor = ti->cl_cursor;
3941 *ti_ptr = node_cursor->node_group;
3942 DrawChooseTree(ti_ptr);
3947 else if (dx == -1 && ti->node_parent)
3951 PlaySound(SND_MENU_ITEM_SELECTING);
3953 *ti_ptr = ti->node_parent;
3954 DrawChooseTree(ti_ptr);
3959 if (!anyScrollbarGadgetActive() &&
3960 IN_VIS_MENU(x, y) &&
3961 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3962 y >= 0 && y < num_page_entries)
3966 if (y != ti->cl_cursor)
3968 PlaySound(SND_MENU_ITEM_ACTIVATING);
3970 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3971 drawChooseTreeCursor(y, TRUE);
3972 drawChooseTreeInfo(ti->cl_first + y, ti);
3979 TreeInfo *node_first, *node_cursor;
3980 int entry_pos = ti->cl_first + y;
3982 PlaySound(SND_MENU_ITEM_SELECTING);
3984 node_first = getTreeInfoFirstGroupEntry(ti);
3985 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3987 if (node_cursor->node_group)
3991 node_cursor->cl_first = ti->cl_first;
3992 node_cursor->cl_cursor = ti->cl_cursor;
3993 *ti_ptr = node_cursor->node_group;
3994 DrawChooseTree(ti_ptr);
3996 else if (node_cursor->parent_link)
4000 *ti_ptr = node_cursor->node_parent;
4001 DrawChooseTree(ti_ptr);
4007 node_cursor->cl_first = ti->cl_first;
4008 node_cursor->cl_cursor = ti->cl_cursor;
4009 *ti_ptr = node_cursor;
4011 if (ti->type == TREE_TYPE_LEVEL_DIR)
4013 LoadLevelSetup_SeriesInfo();
4015 SaveLevelSetup_LastSeries();
4016 SaveLevelSetup_SeriesInfo();
4020 if (game_status == GAME_MODE_SETUP)
4022 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4023 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4024 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4026 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4027 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4028 execSetupGraphics();
4029 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4030 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4031 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4033 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4034 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4035 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4042 if (game_status == GAME_MODE_LEVELNR)
4044 int new_level_nr = atoi(level_number_current->identifier);
4046 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4049 SetGameStatus(GAME_MODE_MAIN);
4058 void DrawChooseLevelSet()
4060 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4062 DrawChooseTree(&leveldir_current);
4068 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4070 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4073 void DrawChooseLevelNr()
4077 if (level_number != NULL)
4079 freeTreeInfo(level_number);
4081 level_number = NULL;
4084 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4086 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4087 char identifier[32], name[32];
4090 /* temporarily load level info to get level name */
4091 LoadLevelInfoOnly(i);
4093 ti->node_top = &level_number;
4094 ti->sort_priority = 10000 + value;
4095 ti->color = (level.no_valid_file ? FC_BLUE :
4096 LevelStats_getSolved(i) ? FC_GREEN :
4097 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4099 sprintf(identifier, "%d", value);
4100 sprintf(name, "%03d: %s", value,
4101 (level.no_valid_file ? "(no file)" : level.name));
4103 setString(&ti->identifier, identifier);
4104 setString(&ti->name, name);
4105 setString(&ti->name_sorting, name);
4107 pushTreeInfo(&level_number, ti);
4110 /* sort level number values to start with lowest level number */
4111 sortTreeInfo(&level_number);
4113 /* set current level number to current level number */
4114 level_number_current =
4115 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4117 /* if that also fails, set current level number to first available level */
4118 if (level_number_current == NULL)
4119 level_number_current = level_number;
4121 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4123 DrawChooseTree(&level_number_current);
4129 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4131 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4134 void DrawHallOfFame(int highlight_position)
4136 int fade_mask = REDRAW_FIELD;
4138 /* needed if different viewport properties defined for scores */
4139 ChangeViewportPropertiesIfNeeded();
4141 if (CheckIfGlobalBorderHasChanged())
4142 fade_mask = REDRAW_ALL;
4145 FadeSoundsAndMusic();
4147 /* (this is needed when called from GameEnd() after winning a game) */
4148 KeyboardAutoRepeatOn();
4151 /* (this is needed when called from GameEnd() after winning a game) */
4152 SetDrawDeactivationMask(REDRAW_NONE);
4153 SetDrawBackgroundMask(REDRAW_FIELD);
4155 if (highlight_position < 0)
4156 LoadScore(level_nr);
4158 FadeSetEnterScreen();
4167 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4169 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4171 DrawMaskedBorder(fade_mask);
4176 static void drawHallOfFameList(int first_entry, int highlight_position)
4180 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4183 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4184 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4185 "HighScores of Level %d", level_nr);
4187 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4189 int entry = first_entry + i;
4190 boolean active = (entry == highlight_position);
4191 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4192 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4193 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4194 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4195 int dx1 = 3 * getFontWidth(font_nr1);
4196 int dx2 = dx1 + getFontWidth(font_nr1);
4197 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4198 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4199 int sy = mSY + 64 + i * 32;
4201 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4202 DrawText(mSX + dx1, sy, ".", font_nr1);
4204 for (j = 0; j < num_dots; j++)
4205 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4207 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4208 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4210 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4213 redraw_mask |= REDRAW_FIELD;
4216 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4218 static int first_entry = 0;
4219 static int highlight_position = 0;
4220 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4222 if (button == MB_MENU_INITIALIZE)
4225 highlight_position = mx;
4226 drawHallOfFameList(first_entry, highlight_position);
4231 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4232 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4236 if (first_entry > 0)
4238 first_entry -= step;
4239 if (first_entry < 0)
4242 drawHallOfFameList(first_entry, highlight_position);
4247 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4249 first_entry += step;
4250 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4251 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4253 drawHallOfFameList(first_entry, highlight_position);
4256 else if (button == MB_MENU_LEAVE)
4258 PlaySound(SND_MENU_ITEM_SELECTING);
4260 FadeSound(SND_BACKGROUND_SCORES);
4262 SetGameStatus(GAME_MODE_MAIN);
4266 else if (button == MB_MENU_CHOICE)
4268 PlaySound(SND_MENU_ITEM_SELECTING);
4270 FadeSound(SND_BACKGROUND_SCORES);
4272 SetGameStatus(GAME_MODE_MAIN);
4277 if (game_status == GAME_MODE_SCORES)
4278 PlayMenuSoundIfLoop();
4282 /* ========================================================================= */
4283 /* setup screen functions */
4284 /* ========================================================================= */
4286 static struct TokenInfo *setup_info;
4287 static int num_setup_info; /* number of setup entries shown on screen */
4288 static int max_setup_info; /* total number of setup entries in list */
4290 static char *window_size_text;
4291 static char *scaling_type_text;
4292 static char *scroll_delay_text;
4293 static char *snapshot_mode_text;
4294 static char *game_speed_text;
4295 static char *graphics_set_name;
4296 static char *sounds_set_name;
4297 static char *music_set_name;
4298 static char *volume_simple_text;
4299 static char *volume_loops_text;
4300 static char *volume_music_text;
4301 static char *touch_controls_text;
4302 static char *move_distance_text;
4303 static char *drop_distance_text;
4305 static void execSetupMain()
4307 setup_mode = SETUP_MODE_MAIN;
4312 static void execSetupGame_setGameSpeeds()
4314 if (game_speeds == NULL)
4318 for (i = 0; game_speeds_list[i].value != -1; i++)
4320 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4321 char identifier[32], name[32];
4322 int value = game_speeds_list[i].value;
4323 char *text = game_speeds_list[i].text;
4325 ti->node_top = &game_speeds;
4326 ti->sort_priority = 10000 - value;
4328 sprintf(identifier, "%d", value);
4329 sprintf(name, "%s", text);
4331 setString(&ti->identifier, identifier);
4332 setString(&ti->name, name);
4333 setString(&ti->name_sorting, name);
4334 setString(&ti->infotext, "Game Speed");
4336 pushTreeInfo(&game_speeds, ti);
4339 /* sort game speed values to start with slowest game speed */
4340 sortTreeInfo(&game_speeds);
4342 /* set current game speed to configured game speed value */
4343 game_speed_current =
4344 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4346 /* if that fails, set current game speed to reliable default value */
4347 if (game_speed_current == NULL)
4348 game_speed_current =
4349 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4351 /* if that also fails, set current game speed to first available speed */
4352 if (game_speed_current == NULL)
4353 game_speed_current = game_speeds;
4356 setup.game_frame_delay = atoi(game_speed_current->identifier);
4358 /* needed for displaying game speed text instead of identifier */
4359 game_speed_text = game_speed_current->name;
4362 static void execSetupGame_setScrollDelays()
4364 if (scroll_delays == NULL)
4368 for (i = 0; scroll_delays_list[i].value != -1; i++)
4370 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4371 char identifier[32], name[32];
4372 int value = scroll_delays_list[i].value;
4373 char *text = scroll_delays_list[i].text;
4375 ti->node_top = &scroll_delays;
4376 ti->sort_priority = value;
4378 sprintf(identifier, "%d", value);
4379 sprintf(name, "%s", text);
4381 setString(&ti->identifier, identifier);
4382 setString(&ti->name, name);
4383 setString(&ti->name_sorting, name);
4384 setString(&ti->infotext, "Scroll Delay");
4386 pushTreeInfo(&scroll_delays, ti);
4389 /* sort scroll delay values to start with lowest scroll delay value */
4390 sortTreeInfo(&scroll_delays);
4392 /* set current scroll delay value to configured scroll delay value */
4393 scroll_delay_current =
4394 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4396 /* if that fails, set current scroll delay to reliable default value */
4397 if (scroll_delay_current == NULL)
4398 scroll_delay_current =
4399 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4401 /* if that also fails, set current scroll delay to first available value */
4402 if (scroll_delay_current == NULL)
4403 scroll_delay_current = scroll_delays;
4406 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4408 /* needed for displaying scroll delay text instead of identifier */
4409 scroll_delay_text = scroll_delay_current->name;
4412 static void execSetupGame_setSnapshotModes()
4414 if (snapshot_modes == NULL)
4418 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4420 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4421 char identifier[32], name[32];
4422 char *value = snapshot_modes_list[i].value;
4423 char *text = snapshot_modes_list[i].text;
4425 ti->node_top = &snapshot_modes;
4426 ti->sort_priority = i;
4428 sprintf(identifier, "%s", 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, "Snapshot Mode");
4436 pushTreeInfo(&snapshot_modes, ti);
4439 /* sort snapshot mode values to start with lowest snapshot mode value */
4440 sortTreeInfo(&snapshot_modes);
4442 /* set current snapshot mode value to configured snapshot mode value */
4443 snapshot_mode_current =
4444 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4446 /* if that fails, set current snapshot mode to reliable default value */
4447 if (snapshot_mode_current == NULL)
4448 snapshot_mode_current =
4449 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4451 /* if that also fails, set current snapshot mode to first available value */
4452 if (snapshot_mode_current == NULL)
4453 snapshot_mode_current = snapshot_modes;
4456 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4458 /* needed for displaying snapshot mode text instead of identifier */
4459 snapshot_mode_text = snapshot_mode_current->name;
4462 static void execSetupGame()
4464 execSetupGame_setGameSpeeds();
4465 execSetupGame_setScrollDelays();
4466 execSetupGame_setSnapshotModes();
4468 setup_mode = SETUP_MODE_GAME;
4473 static void execSetupChooseGameSpeed()
4475 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4480 static void execSetupChooseScrollDelay()
4482 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4487 static void execSetupChooseSnapshotMode()
4489 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4494 static void execSetupEditor()
4496 setup_mode = SETUP_MODE_EDITOR;
4501 static void execSetupGraphics_setWindowSizes(boolean update_list)
4503 if (window_sizes != NULL && update_list)
4505 freeTreeInfo(window_sizes);
4507 window_sizes = NULL;
4510 if (window_sizes == NULL)
4512 boolean current_window_size_found = FALSE;
4515 for (i = 0; window_sizes_list[i].value != -1; i++)
4517 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4518 char identifier[32], name[32];
4519 int value = window_sizes_list[i].value;
4520 char *text = window_sizes_list[i].text;
4522 ti->node_top = &window_sizes;
4523 ti->sort_priority = value;
4525 sprintf(identifier, "%d", value);
4526 sprintf(name, "%s", text);
4528 setString(&ti->identifier, identifier);
4529 setString(&ti->name, name);
4530 setString(&ti->name_sorting, name);
4531 setString(&ti->infotext, "Window Scaling");
4533 pushTreeInfo(&window_sizes, ti);
4535 if (value == setup.window_scaling_percent)
4536 current_window_size_found = TRUE;
4539 if (!current_window_size_found)
4541 // add entry for non-preset window scaling value
4543 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4544 char identifier[32], name[32];
4545 int value = setup.window_scaling_percent;
4547 ti->node_top = &window_sizes;
4548 ti->sort_priority = value;
4550 sprintf(identifier, "%d", value);
4551 sprintf(name, "%d %% (Current)", value);
4553 setString(&ti->identifier, identifier);
4554 setString(&ti->name, name);
4555 setString(&ti->name_sorting, name);
4556 setString(&ti->infotext, "Window Scaling");
4558 pushTreeInfo(&window_sizes, ti);
4561 /* sort window size values to start with lowest window size value */
4562 sortTreeInfo(&window_sizes);
4564 /* set current window size value to configured window size value */
4565 window_size_current =
4566 getTreeInfoFromIdentifier(window_sizes,
4567 i_to_a(setup.window_scaling_percent));
4569 /* if that fails, set current window size to reliable default value */
4570 if (window_size_current == NULL)
4571 window_size_current =
4572 getTreeInfoFromIdentifier(window_sizes,
4573 i_to_a(STD_WINDOW_SCALING_PERCENT));
4575 /* if that also fails, set current window size to first available value */
4576 if (window_size_current == NULL)
4577 window_size_current = window_sizes;
4580 setup.window_scaling_percent = atoi(window_size_current->identifier);
4582 /* needed for displaying window size text instead of identifier */
4583 window_size_text = window_size_current->name;
4586 static void execSetupGraphics_setScalingTypes()
4588 if (scaling_types == NULL)
4592 for (i = 0; scaling_types_list[i].value != NULL; i++)
4594 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4595 char identifier[32], name[32];
4596 char *value = scaling_types_list[i].value;
4597 char *text = scaling_types_list[i].text;
4599 ti->node_top = &scaling_types;
4600 ti->sort_priority = i;
4602 sprintf(identifier, "%s", value);
4603 sprintf(name, "%s", text);
4605 setString(&ti->identifier, identifier);
4606 setString(&ti->name, name);
4607 setString(&ti->name_sorting, name);
4608 setString(&ti->infotext, "Anti-Aliasing");
4610 pushTreeInfo(&scaling_types, ti);
4613 /* sort scaling type values to start with lowest scaling type value */
4614 sortTreeInfo(&scaling_types);
4616 /* set current scaling type value to configured scaling type value */
4617 scaling_type_current =
4618 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4620 /* if that fails, set current scaling type to reliable default value */
4621 if (scaling_type_current == NULL)
4622 scaling_type_current =
4623 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4625 /* if that also fails, set current scaling type to first available value */
4626 if (scaling_type_current == NULL)
4627 scaling_type_current = scaling_types;
4630 setup.window_scaling_quality = scaling_type_current->identifier;
4632 /* needed for displaying scaling type text instead of identifier */
4633 scaling_type_text = scaling_type_current->name;
4636 static void execSetupGraphics()
4638 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4640 // update "setup.window_scaling_percent" from list selection
4641 execSetupGraphics_setWindowSizes(FALSE);
4645 // update list selection from "setup.window_scaling_percent"
4646 execSetupGraphics_setWindowSizes(TRUE);
4649 execSetupGraphics_setScalingTypes();
4651 setup_mode = SETUP_MODE_GRAPHICS;
4655 #if defined(TARGET_SDL2)
4656 // window scaling may have changed at this point
4657 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4659 // window scaling quality may have changed at this point
4660 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4661 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4665 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4666 static void execSetupChooseWindowSize()
4668 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4673 static void execSetupChooseScalingType()
4675 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4681 static void execSetupChooseVolumeSimple()
4683 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4688 static void execSetupChooseVolumeLoops()
4690 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4695 static void execSetupChooseVolumeMusic()
4697 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4702 static void execSetupSound()
4704 if (volumes_simple == NULL)
4706 boolean current_volume_simple_found = FALSE;
4709 for (i = 0; volumes_list[i].value != -1; i++)
4711 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4712 char identifier[32], name[32];
4713 int value = volumes_list[i].value;
4714 char *text = volumes_list[i].text;
4716 ti->node_top = &volumes_simple;
4717 ti->sort_priority = value;
4719 sprintf(identifier, "%d", value);
4720 sprintf(name, "%s", text);
4722 setString(&ti->identifier, identifier);
4723 setString(&ti->name, name);
4724 setString(&ti->name_sorting, name);
4725 setString(&ti->infotext, "Sound Volume");
4727 pushTreeInfo(&volumes_simple, ti);
4729 if (value == setup.volume_simple)
4730 current_volume_simple_found = TRUE;
4733 if (!current_volume_simple_found)
4735 // add entry for non-preset volume value
4737 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4738 char identifier[32], name[32];
4739 int value = setup.volume_simple;
4741 ti->node_top = &volumes_simple;
4742 ti->sort_priority = value;
4744 sprintf(identifier, "%d", value);
4745 sprintf(name, "%d %% (Current)", value);
4747 setString(&ti->identifier, identifier);
4748 setString(&ti->name, name);
4749 setString(&ti->name_sorting, name);
4750 setString(&ti->infotext, "Sound Volume");
4752 pushTreeInfo(&volumes_simple, ti);
4755 /* sort volume values to start with lowest volume value */
4756 sortTreeInfo(&volumes_simple);
4758 /* set current volume value to configured volume value */
4759 volume_simple_current =
4760 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4762 /* if that fails, set current volume to reliable default value */
4763 if (volume_simple_current == NULL)
4764 volume_simple_current =
4765 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4767 /* if that also fails, set current volume to first available value */
4768 if (volume_simple_current == NULL)
4769 volume_simple_current = volumes_simple;
4772 if (volumes_loops == NULL)
4774 boolean current_volume_loops_found = FALSE;
4777 for (i = 0; volumes_list[i].value != -1; i++)
4779 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4780 char identifier[32], name[32];
4781 int value = volumes_list[i].value;
4782 char *text = volumes_list[i].text;
4784 ti->node_top = &volumes_loops;
4785 ti->sort_priority = value;
4787 sprintf(identifier, "%d", value);
4788 sprintf(name, "%s", text);
4790 setString(&ti->identifier, identifier);
4791 setString(&ti->name, name);
4792 setString(&ti->name_sorting, name);
4793 setString(&ti->infotext, "Loops Volume");
4795 pushTreeInfo(&volumes_loops, ti);
4797 if (value == setup.volume_loops)
4798 current_volume_loops_found = TRUE;
4801 if (!current_volume_loops_found)
4803 // add entry for non-preset volume value
4805 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4806 char identifier[32], name[32];
4807 int value = setup.volume_loops;
4809 ti->node_top = &volumes_loops;
4810 ti->sort_priority = value;
4812 sprintf(identifier, "%d", value);
4813 sprintf(name, "%d %% (Current)", value);
4815 setString(&ti->identifier, identifier);
4816 setString(&ti->name, name);
4817 setString(&ti->name_sorting, name);
4818 setString(&ti->infotext, "Loops Volume");
4820 pushTreeInfo(&volumes_loops, ti);
4823 /* sort volume values to start with lowest volume value */
4824 sortTreeInfo(&volumes_loops);
4826 /* set current volume value to configured volume value */
4827 volume_loops_current =
4828 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4830 /* if that fails, set current volume to reliable default value */
4831 if (volume_loops_current == NULL)
4832 volume_loops_current =
4833 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4835 /* if that also fails, set current volume to first available value */
4836 if (volume_loops_current == NULL)
4837 volume_loops_current = volumes_loops;
4840 if (volumes_music == NULL)
4842 boolean current_volume_music_found = FALSE;
4845 for (i = 0; volumes_list[i].value != -1; i++)
4847 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4848 char identifier[32], name[32];
4849 int value = volumes_list[i].value;
4850 char *text = volumes_list[i].text;
4852 ti->node_top = &volumes_music;
4853 ti->sort_priority = value;
4855 sprintf(identifier, "%d", value);
4856 sprintf(name, "%s", text);
4858 setString(&ti->identifier, identifier);
4859 setString(&ti->name, name);
4860 setString(&ti->name_sorting, name);
4861 setString(&ti->infotext, "Music Volume");
4863 pushTreeInfo(&volumes_music, ti);
4865 if (value == setup.volume_music)
4866 current_volume_music_found = TRUE;
4869 if (!current_volume_music_found)
4871 // add entry for non-preset volume value
4873 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4874 char identifier[32], name[32];
4875 int value = setup.volume_music;
4877 ti->node_top = &volumes_music;
4878 ti->sort_priority = value;
4880 sprintf(identifier, "%d", value);
4881 sprintf(name, "%d %% (Current)", value);
4883 setString(&ti->identifier, identifier);
4884 setString(&ti->name, name);
4885 setString(&ti->name_sorting, name);
4886 setString(&ti->infotext, "Music Volume");
4888 pushTreeInfo(&volumes_music, ti);
4891 /* sort volume values to start with lowest volume value */
4892 sortTreeInfo(&volumes_music);
4894 /* set current volume value to configured volume value */
4895 volume_music_current =
4896 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4898 /* if that fails, set current volume to reliable default value */
4899 if (volume_music_current == NULL)
4900 volume_music_current =
4901 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4903 /* if that also fails, set current volume to first available value */
4904 if (volume_music_current == NULL)
4905 volume_music_current = volumes_music;
4908 setup.volume_simple = atoi(volume_simple_current->identifier);
4909 setup.volume_loops = atoi(volume_loops_current->identifier);
4910 setup.volume_music = atoi(volume_music_current->identifier);
4912 /* needed for displaying volume text instead of identifier */
4913 volume_simple_text = volume_simple_current->name;
4914 volume_loops_text = volume_loops_current->name;
4915 volume_music_text = volume_music_current->name;
4917 setup_mode = SETUP_MODE_SOUND;
4922 static void execSetupChooseTouchControls()
4924 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4929 static void execSetupChooseMoveDistance()
4931 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4936 static void execSetupChooseDropDistance()
4938 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4943 static void execSetupTouch()
4945 if (touch_controls == NULL)
4949 for (i = 0; touch_controls_list[i].value != NULL; i++)
4951 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4952 char identifier[32], name[32];
4953 char *value = touch_controls_list[i].value;
4954 char *text = touch_controls_list[i].text;
4956 ti->node_top = &touch_controls;
4957 ti->sort_priority = i;
4959 sprintf(identifier, "%s", value);
4960 sprintf(name, "%s", text);
4962 setString(&ti->identifier, identifier);
4963 setString(&ti->name, name);
4964 setString(&ti->name_sorting, name);
4965 setString(&ti->infotext, "Control Type");
4967 pushTreeInfo(&touch_controls, ti);
4970 /* sort touch control values to start with lowest touch control value */
4971 sortTreeInfo(&touch_controls);
4973 /* set current touch control value to configured touch control value */
4974 touch_control_current =
4975 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4977 /* if that fails, set current touch control to reliable default value */
4978 if (touch_control_current == NULL)
4979 touch_control_current =
4980 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4982 /* if that also fails, set current touch control to first available value */
4983 if (touch_control_current == NULL)
4984 touch_control_current = touch_controls;
4987 if (move_distances == NULL)
4991 for (i = 0; distances_list[i].value != -1; i++)
4993 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4994 char identifier[32], name[32];
4995 int value = distances_list[i].value;
4996 char *text = distances_list[i].text;
4998 ti->node_top = &move_distances;
4999 ti->sort_priority = value;
5001 sprintf(identifier, "%d", value);
5002 sprintf(name, "%s", text);
5004 setString(&ti->identifier, identifier);
5005 setString(&ti->name, name);
5006 setString(&ti->name_sorting, name);
5007 setString(&ti->infotext, "Move Distance");
5009 pushTreeInfo(&move_distances, ti);
5012 /* sort distance values to start with lowest distance value */
5013 sortTreeInfo(&move_distances);
5015 /* set current distance value to configured distance value */
5016 move_distance_current =
5017 getTreeInfoFromIdentifier(move_distances,
5018 i_to_a(setup.touch.move_distance));
5020 /* if that fails, set current distance to reliable default value */
5021 if (move_distance_current == NULL)
5022 move_distance_current =
5023 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5025 /* if that also fails, set current distance to first available value */
5026 if (move_distance_current == NULL)
5027 move_distance_current = move_distances;
5030 if (drop_distances == NULL)
5034 for (i = 0; distances_list[i].value != -1; i++)
5036 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5037 char identifier[32], name[32];
5038 int value = distances_list[i].value;
5039 char *text = distances_list[i].text;
5041 ti->node_top = &drop_distances;
5042 ti->sort_priority = value;
5044 sprintf(identifier, "%d", value);
5045 sprintf(name, "%s", text);
5047 setString(&ti->identifier, identifier);
5048 setString(&ti->name, name);
5049 setString(&ti->name_sorting, name);
5050 setString(&ti->infotext, "Drop Distance");
5052 pushTreeInfo(&drop_distances, ti);
5055 /* sort distance values to start with lowest distance value */
5056 sortTreeInfo(&drop_distances);
5058 /* set current distance value to configured distance value */
5059 drop_distance_current =
5060 getTreeInfoFromIdentifier(drop_distances,
5061 i_to_a(setup.touch.drop_distance));
5063 /* if that fails, set current distance to reliable default value */
5064 if (drop_distance_current == NULL)
5065 drop_distance_current =
5066 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5068 /* if that also fails, set current distance to first available value */
5069 if (drop_distance_current == NULL)
5070 drop_distance_current = drop_distances;
5073 setup.touch.control_type = touch_control_current->identifier;
5074 setup.touch.move_distance = atoi(move_distance_current->identifier);
5075 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5077 /* needed for displaying volume text instead of identifier */
5078 touch_controls_text = touch_control_current->name;
5079 move_distance_text = move_distance_current->name;
5080 drop_distance_text = drop_distance_current->name;
5082 setup_mode = SETUP_MODE_TOUCH;
5087 static void execSetupArtwork()
5090 printf("::: '%s', '%s', '%s'\n",
5091 artwork.gfx_current->subdir,
5092 artwork.gfx_current->fullpath,
5093 artwork.gfx_current->basepath);
5096 setup.graphics_set = artwork.gfx_current->identifier;
5097 setup.sounds_set = artwork.snd_current->identifier;
5098 setup.music_set = artwork.mus_current->identifier;
5100 /* needed if last screen (setup choice) changed graphics, sounds or music */
5101 ReloadCustomArtwork(0);
5103 /* needed for displaying artwork name instead of artwork identifier */
5104 graphics_set_name = artwork.gfx_current->name;
5105 sounds_set_name = artwork.snd_current->name;
5106 music_set_name = artwork.mus_current->name;
5108 setup_mode = SETUP_MODE_ARTWORK;
5113 static void execSetupChooseGraphics()
5115 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5120 static void execSetupChooseSounds()
5122 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5127 static void execSetupChooseMusic()
5129 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5134 #if !defined(PLATFORM_ANDROID)
5135 static void execSetupInput()
5137 setup_mode = SETUP_MODE_INPUT;
5143 static void execSetupShortcuts()
5145 setup_mode = SETUP_MODE_SHORTCUTS;
5150 static void execSetupShortcuts1()
5152 setup_mode = SETUP_MODE_SHORTCUTS_1;
5157 static void execSetupShortcuts2()
5159 setup_mode = SETUP_MODE_SHORTCUTS_2;
5164 static void execSetupShortcuts3()
5166 setup_mode = SETUP_MODE_SHORTCUTS_3;
5171 static void execSetupShortcuts4()
5173 setup_mode = SETUP_MODE_SHORTCUTS_4;
5178 static void execSetupShortcuts5()
5180 setup_mode = SETUP_MODE_SHORTCUTS_5;
5185 static void execExitSetup()
5187 SetGameStatus(GAME_MODE_MAIN);
5192 static void execSaveAndExitSetup()
5198 static struct TokenInfo setup_info_main[] =
5200 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5201 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5202 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5203 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5204 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5205 #if !defined(PLATFORM_ANDROID)
5206 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5207 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5209 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5211 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5212 { TYPE_EMPTY, NULL, "" },
5213 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5214 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5219 static struct TokenInfo setup_info_game[] =
5221 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5222 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5223 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5224 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5225 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5226 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5227 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5228 { TYPE_STRING, &game_speed_text, "" },
5230 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5231 { TYPE_STRING, &scroll_delay_text, "" },
5233 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5234 { TYPE_STRING, &snapshot_mode_text, "" },
5235 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5236 { TYPE_EMPTY, NULL, "" },
5237 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5242 static struct TokenInfo setup_info_editor[] =
5245 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5246 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5247 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5248 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5249 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5250 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5251 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5252 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5254 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5255 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5256 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5258 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5260 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5261 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5262 { TYPE_EMPTY, NULL, "" },
5264 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5265 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5266 { TYPE_EMPTY, NULL, "" },
5268 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5269 { TYPE_EMPTY, NULL, "" },
5270 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5275 static struct TokenInfo setup_info_graphics[] =
5277 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5278 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5279 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5280 { TYPE_STRING, &window_size_text, "" },
5281 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5282 { TYPE_STRING, &scaling_type_text, "" },
5285 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5286 { TYPE_STRING, &scroll_delay_text, "" },
5288 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5289 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5290 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5291 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5292 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5293 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5294 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5295 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5296 { TYPE_EMPTY, NULL, "" },
5297 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5302 static struct TokenInfo setup_info_sound[] =
5304 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5305 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5306 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5307 { TYPE_EMPTY, NULL, "" },
5308 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5309 { TYPE_STRING, &volume_simple_text, "" },
5310 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5311 { TYPE_STRING, &volume_loops_text, "" },
5312 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5313 { TYPE_STRING, &volume_music_text, "" },
5314 { TYPE_EMPTY, NULL, "" },
5315 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5320 static struct TokenInfo setup_info_artwork[] =
5322 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5323 { TYPE_STRING, &graphics_set_name, "" },
5324 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5325 { TYPE_STRING, &sounds_set_name, "" },
5326 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5327 { TYPE_STRING, &music_set_name, "" },
5328 { TYPE_EMPTY, NULL, "" },
5329 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5330 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5331 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5332 { TYPE_EMPTY, NULL, "" },
5333 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5338 static struct TokenInfo setup_info_input[] =
5340 { TYPE_SWITCH, NULL, "Player:" },
5341 { TYPE_SWITCH, NULL, "Device:" },
5342 { TYPE_ENTER_MENU, NULL, "" },
5343 { TYPE_EMPTY, NULL, "" },
5344 { TYPE_EMPTY, NULL, "" },
5345 { TYPE_EMPTY, NULL, "" },
5346 { TYPE_EMPTY, NULL, "" },
5347 { TYPE_EMPTY, NULL, "" },
5348 { TYPE_EMPTY, NULL, "" },
5349 { TYPE_EMPTY, NULL, "" },
5350 { TYPE_EMPTY, NULL, "" },
5351 { TYPE_EMPTY, NULL, "" },
5352 { TYPE_EMPTY, NULL, "" },
5353 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5358 static struct TokenInfo setup_info_touch[] =
5360 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5361 { TYPE_STRING, &touch_controls_text, "" },
5362 { TYPE_EMPTY, NULL, "" },
5363 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5364 { TYPE_STRING, &move_distance_text, "" },
5365 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5366 { TYPE_STRING, &drop_distance_text, "" },
5367 { TYPE_EMPTY, NULL, "" },
5368 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5373 static struct TokenInfo setup_info_shortcuts[] =
5375 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5376 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5377 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5378 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5379 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5380 { TYPE_EMPTY, NULL, "" },
5381 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5386 static struct TokenInfo setup_info_shortcuts_1[] =
5388 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5389 { TYPE_KEY, &setup.shortcut.save_game, "" },
5390 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5391 { TYPE_KEY, &setup.shortcut.load_game, "" },
5392 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5393 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5394 { TYPE_EMPTY, NULL, "" },
5395 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5396 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5397 { TYPE_EMPTY, NULL, "" },
5398 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5403 static struct TokenInfo setup_info_shortcuts_2[] =
5405 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5406 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5407 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5408 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5409 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5410 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5411 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5412 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5413 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5414 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5415 { TYPE_EMPTY, NULL, "" },
5416 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5421 static struct TokenInfo setup_info_shortcuts_3[] =
5423 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5424 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5425 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5426 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5427 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5428 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5429 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5430 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5431 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5432 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5433 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5434 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5441 static struct TokenInfo setup_info_shortcuts_4[] =
5443 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5444 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5445 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5446 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5447 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5448 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5449 { TYPE_EMPTY, NULL, "" },
5450 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5455 static struct TokenInfo setup_info_shortcuts_5[] =
5457 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5458 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5459 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5460 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5461 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5462 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5463 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5464 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5465 { TYPE_EMPTY, NULL, "" },
5466 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5471 static Key getSetupKey()
5473 Key key = KSYM_UNDEFINED;
5474 boolean got_key_event = FALSE;
5476 while (!got_key_event)
5478 if (PendingEvent()) /* got event */
5486 case EVENT_KEYPRESS:
5488 key = GetEventKey((KeyEvent *)&event, TRUE);
5490 /* press 'Escape' or 'Enter' to keep the existing key binding */
5491 if (key == KSYM_Escape || key == KSYM_Return)
5492 key = KSYM_UNDEFINED; /* keep old value */
5494 got_key_event = TRUE;
5498 case EVENT_KEYRELEASE:
5499 key_joystick_mapping = 0;
5503 HandleOtherEvents(&event);
5511 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
5517 static int getSetupValueFont(int type, void *value)
5519 if (type & TYPE_KEY)
5520 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5521 else if (type & TYPE_STRING)
5522 return FONT_VALUE_2;
5523 else if (type & TYPE_ECS_AGA)
5524 return FONT_VALUE_1;
5525 else if (type & TYPE_BOOLEAN_STYLE)
5526 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5527 else if (type & TYPE_YES_NO_AUTO)
5528 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5529 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5531 return FONT_VALUE_1;
5534 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5536 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5537 struct TokenInfo *si = &setup_info[si_pos];
5538 boolean font_draw_xoffset_modified = FALSE;
5539 int font_draw_xoffset_old = -1;
5540 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5541 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5542 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5543 int xpos = menu_screen_value_xpos;
5544 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5545 int startx = mSX + xpos * 32;
5546 int starty = mSY + ypos * 32;
5547 int font_nr, font_width;
5548 int type = si->type;
5549 void *value = si->value;
5550 char *value_string = getSetupValue(type, value);
5553 if (value_string == NULL)
5556 if (type & TYPE_KEY)
5558 xpos = MENU_SCREEN_START_XPOS;
5560 if (type & TYPE_QUERY)
5561 value_string = "<press key>";
5563 else if (type & TYPE_STRING)
5565 int max_value_len = (SCR_FIELDX - 2) * 2;
5567 xpos = MENU_SCREEN_START_XPOS;
5569 if (strlen(value_string) > max_value_len)
5570 value_string[max_value_len] = '\0';
5572 else if (type & TYPE_YES_NO_AUTO)
5574 xpos = menu_screen_value_xpos - 1;
5577 startx = mSX + xpos * 32;
5578 starty = mSY + ypos * 32;
5579 font_nr = getSetupValueFont(type, value);
5580 font_width = getFontWidth(font_nr);
5582 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5583 if (setup_mode != SETUP_MODE_INPUT)
5585 int max_menu_text_length_big = (menu_screen_value_xpos -
5586 MENU_SCREEN_START_XPOS);
5587 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5588 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5589 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5590 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5591 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5592 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5593 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5594 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5595 boolean correct_font_draw_xoffset = FALSE;
5597 if (xpos == MENU_SCREEN_START_XPOS &&
5598 startx + font1_xoffset < text_startx + text_font_xoffset)
5599 correct_font_draw_xoffset = TRUE;
5601 if (xpos == menu_screen_value_xpos &&
5602 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5603 correct_font_draw_xoffset = TRUE;
5605 /* check if setup value would overlap with setup text when printed */
5606 /* (this can happen for extreme/wrong values for font draw offset) */
5607 if (correct_font_draw_xoffset)
5609 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5610 font_draw_xoffset_modified = TRUE;
5612 if (type & TYPE_KEY)
5613 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5614 else if (!(type & TYPE_STRING))
5615 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5616 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5620 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5621 DrawText(startx + i * font_width, starty, " ", font_nr);
5623 DrawText(startx, starty, value_string, font_nr);
5625 if (font_draw_xoffset_modified)
5626 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5629 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5631 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5632 struct TokenInfo *si = &setup_info[si_pos];
5634 if (si->type & TYPE_BOOLEAN_STYLE)
5636 *(boolean *)si->value ^= TRUE;
5638 else if (si->type & TYPE_YES_NO_AUTO)
5642 (*(int *)si->value == AUTO ? TRUE :
5643 *(int *)si->value == TRUE ? FALSE : AUTO) :
5644 (*(int *)si->value == TRUE ? AUTO :
5645 *(int *)si->value == AUTO ? FALSE : TRUE));
5647 else if (si->type & TYPE_KEY)
5651 si->type |= TYPE_QUERY;
5652 drawSetupValue(screen_pos, setup_info_pos_raw);
5653 si->type &= ~TYPE_QUERY;
5655 key = getSetupKey();
5656 if (key != KSYM_UNDEFINED)
5657 *(Key *)si->value = key;
5660 drawSetupValue(screen_pos, setup_info_pos_raw);
5662 // fullscreen state may have changed at this point
5663 if (si->value == &setup.fullscreen)
5664 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5667 static void DrawSetupScreen_Generic()
5669 int fade_mask = REDRAW_FIELD;
5670 boolean redraw_all = FALSE;
5671 char *title_string = NULL;
5674 if (CheckIfGlobalBorderHasChanged())
5675 fade_mask = REDRAW_ALL;
5679 FreeScreenGadgets();
5680 CreateScreenGadgets();
5682 if (redraw_mask & REDRAW_ALL)
5689 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5691 if (setup_mode == SETUP_MODE_MAIN)
5693 setup_info = setup_info_main;
5694 title_string = "Setup";
5696 else if (setup_mode == SETUP_MODE_GAME)
5698 setup_info = setup_info_game;
5699 title_string = "Setup Game";
5701 else if (setup_mode == SETUP_MODE_EDITOR)
5703 setup_info = setup_info_editor;
5704 title_string = "Setup Editor";
5706 else if (setup_mode == SETUP_MODE_GRAPHICS)
5708 setup_info = setup_info_graphics;
5709 title_string = "Setup Graphics";
5711 else if (setup_mode == SETUP_MODE_SOUND)
5713 setup_info = setup_info_sound;
5714 title_string = "Setup Sound";
5716 else if (setup_mode == SETUP_MODE_ARTWORK)
5718 setup_info = setup_info_artwork;
5719 title_string = "Custom Artwork";
5721 else if (setup_mode == SETUP_MODE_TOUCH)
5723 setup_info = setup_info_touch;
5724 title_string = "Setup Touch Ctrls";
5726 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5728 setup_info = setup_info_shortcuts;
5729 title_string = "Setup Shortcuts";
5731 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5733 setup_info = setup_info_shortcuts_1;
5734 title_string = "Setup Shortcuts";
5736 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5738 setup_info = setup_info_shortcuts_2;
5739 title_string = "Setup Shortcuts";
5741 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5743 setup_info = setup_info_shortcuts_3;
5744 title_string = "Setup Shortcuts";
5746 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5748 setup_info = setup_info_shortcuts_4;
5749 title_string = "Setup Shortcuts";
5751 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5753 setup_info = setup_info_shortcuts_5;
5754 title_string = "Setup Shortcuts";
5757 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5759 // determine maximal number of setup entries that can be displayed on screen
5761 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5764 // determine maximal number of setup entries available for this setup screen
5766 for (i = 0; setup_info[i].type != 0; i++)
5769 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5771 MapScreenGadgets(max_setup_info);
5774 redraw_mask = fade_mask = REDRAW_ALL;
5776 DrawMaskedBorder(fade_mask);
5783 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5785 menu_info = setup_info;
5787 HandleMenuScreen(mx, my, dx, dy, button,
5788 setup_mode, num_setup_info, max_setup_info);
5791 void DrawSetupScreen_Input()
5795 FadeOut(REDRAW_FIELD);
5799 setup_info = setup_info_input;
5801 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5803 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5804 "Joysticks deactivated on this screen");
5806 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5808 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5809 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5810 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5811 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5812 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5813 initCursor(i, IMG_MENU_BUTTON);
5815 DrawCursorAndText_Setup(i, -1, FALSE);
5818 /* create gadgets for setup input menu screen */
5819 FreeScreenGadgets();
5820 CreateScreenGadgets();
5822 /* map gadgets for setup input menu screen */
5823 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5825 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5827 FadeIn(REDRAW_FIELD);
5832 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5834 if (device_name == NULL)
5837 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5840 if (strlen(device_name) > 1)
5842 char c1 = device_name[strlen(device_name) - 1];
5843 char c2 = device_name[strlen(device_name) - 2];
5845 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5846 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5849 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5850 strlen(device_name));
5853 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5856 static struct SetupKeyboardInfo custom_key;
5863 { &custom_key.left, "Joystick Left" },
5864 { &custom_key.right, "Joystick Right" },
5865 { &custom_key.up, "Joystick Up" },
5866 { &custom_key.down, "Joystick Down" },
5867 { &custom_key.snap, "Button 1" },
5868 { &custom_key.drop, "Button 2" }
5870 static char *joystick_name[MAX_PLAYERS] =
5877 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5881 custom_key = setup.input[player_nr].key;
5883 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5884 FONT_INPUT_1_ACTIVE);
5886 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5888 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5889 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5891 if (setup.input[player_nr].use_joystick)
5893 char *device_name = setup.input[player_nr].joy.device_name;
5894 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5895 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5897 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5898 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5902 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5903 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5906 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5908 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5909 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5910 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5911 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5913 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5914 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5915 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5916 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5917 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5918 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5920 for (i = 0; i < 6; i++)
5922 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5924 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5926 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5927 (setup.input[player_nr].use_joystick ?
5929 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5933 static int input_player_nr = 0;
5935 void HandleSetupScreen_Input_Player(int step, int direction)
5937 int old_player_nr = input_player_nr;
5940 new_player_nr = old_player_nr + step * direction;
5941 if (new_player_nr < 0)
5943 if (new_player_nr > MAX_PLAYERS - 1)
5944 new_player_nr = MAX_PLAYERS - 1;
5946 if (new_player_nr != old_player_nr)
5948 input_player_nr = new_player_nr;
5950 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5954 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5956 static int choice = 0;
5959 int pos_start = SETUPINPUT_SCREEN_POS_START;
5960 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5961 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5962 int pos_end = SETUPINPUT_SCREEN_POS_END;
5964 if (button == MB_MENU_INITIALIZE)
5966 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5968 DrawCursorAndText_Setup(choice, -1, TRUE);
5972 else if (button == MB_MENU_LEAVE)
5974 setup_mode = SETUP_MODE_MAIN;
5981 if (mx || my) /* mouse input */
5983 x = (mx - mSX) / 32;
5984 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5986 else if (dx || dy) /* keyboard input */
5988 if (dx && choice == 0)
5989 x = (dx < 0 ? 10 : 12);
5990 else if ((dx && choice == 1) ||
5991 (dx == +1 && choice == 2) ||
5992 (dx == -1 && choice == pos_end))
5993 button = MB_MENU_CHOICE;
5997 if (y >= pos_empty1 && y <= pos_empty2)
5998 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6001 if (y == 0 && dx != 0 && button)
6003 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6005 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6006 y >= pos_start && y <= pos_end &&
6007 !(y >= pos_empty1 && y <= pos_empty2))
6013 DrawCursorAndText_Setup(choice, -1, FALSE);
6014 DrawCursorAndText_Setup(y, -1, TRUE);
6016 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6025 char *device_name = setup.input[input_player_nr].joy.device_name;
6027 if (!setup.input[input_player_nr].use_joystick)
6029 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6031 setJoystickDeviceToNr(device_name, new_device_nr);
6032 setup.input[input_player_nr].use_joystick = TRUE;
6036 int device_nr = getJoystickNrFromDeviceName(device_name);
6037 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6039 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6040 setup.input[input_player_nr].use_joystick = FALSE;
6042 setJoystickDeviceToNr(device_name, new_device_nr);
6045 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6049 if (setup.input[input_player_nr].use_joystick)
6052 CalibrateJoystick(input_player_nr);
6055 CustomizeKeyboard(input_player_nr);
6057 else if (y == pos_end)
6063 setup_mode = SETUP_MODE_MAIN;
6070 void CustomizeKeyboard(int player_nr)
6074 boolean finished = FALSE;
6075 static struct SetupKeyboardInfo custom_key;
6080 } customize_step[] =
6082 { &custom_key.left, "Move Left" },
6083 { &custom_key.right, "Move Right" },
6084 { &custom_key.up, "Move Up" },
6085 { &custom_key.down, "Move Down" },
6086 { &custom_key.snap, "Snap Field" },
6087 { &custom_key.drop, "Drop Element" }
6090 /* read existing key bindings from player setup */
6091 custom_key = setup.input[player_nr].key;
6094 FadeOut(REDRAW_FIELD);
6098 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6101 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6102 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6103 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6104 "Key:", FONT_INPUT_1_ACTIVE);
6105 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6106 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6108 FadeIn(REDRAW_FIELD);
6114 if (PendingEvent()) /* got event */
6122 case EVENT_KEYPRESS:
6124 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6126 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6128 if (key == KSYM_Escape)
6129 FadeSkipNextFadeIn();
6135 /* all keys configured -- wait for "Escape" or "Return" key */
6139 /* press 'Enter' to keep the existing key binding */
6140 if (key == KSYM_Return)
6141 key = *customize_step[step_nr].key;
6143 /* check if key already used */
6144 for (i = 0; i < step_nr; i++)
6145 if (*customize_step[i].key == key)
6150 /* got new key binding */
6151 *customize_step[step_nr].key = key;
6152 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6154 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6155 getKeyNameFromKey(key), FONT_VALUE_1);
6158 /* un-highlight last query */
6159 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6160 customize_step[step_nr - 1].text, FONT_MENU_1);
6161 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6162 "Key:", FONT_MENU_1);
6164 /* press 'Enter' to leave */
6167 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6168 "Press Enter", FONT_TITLE_1);
6172 /* query next key binding */
6173 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6174 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6175 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6176 "Key:", FONT_INPUT_1_ACTIVE);
6177 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6178 getKeyNameFromKey(*customize_step[step_nr].key),
6183 case EVENT_KEYRELEASE:
6184 key_joystick_mapping = 0;
6188 HandleOtherEvents(&event);
6196 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6199 /* write new key bindings back to player setup */
6200 setup.input[player_nr].key = custom_key;
6203 DrawSetupScreen_Input();
6206 static boolean CalibrateJoystickMain(int player_nr)
6208 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6209 int new_joystick_xright = JOYSTICK_XMIDDLE;
6210 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6211 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6212 int new_joystick_xmiddle, new_joystick_ymiddle;
6214 int joystick_fd = joystick.fd[player_nr];
6215 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6216 boolean check[3][3];
6217 int check_remaining = 3 * 3;
6222 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6225 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6229 FadeOut(REDRAW_FIELD);
6233 for (y = 0; y < 3; y++)
6235 for (x = 0; x < 3; x++)
6237 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6238 check[x][y] = FALSE;
6242 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6243 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6244 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6245 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6246 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6247 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6248 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6250 joy_value = Joystick(player_nr);
6251 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6252 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6254 /* eventually uncalibrated center position (joystick could be uncentered) */
6255 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6258 new_joystick_xmiddle = joy_x;
6259 new_joystick_ymiddle = joy_y;
6261 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6263 FadeIn(REDRAW_FIELD);
6265 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6270 if (PendingEvent()) /* got event */
6278 case EVENT_KEYPRESS:
6279 switch (GetEventKey((KeyEvent *)&event, TRUE))
6282 if (check_remaining == 0)
6287 FadeSkipNextFadeIn();
6296 case EVENT_KEYRELEASE:
6297 key_joystick_mapping = 0;
6301 HandleOtherEvents(&event);
6306 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6309 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6310 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6311 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6312 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6314 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6315 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6316 setup.input[player_nr].joy.xright = new_joystick_xright;
6317 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6318 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6319 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6321 CheckJoystickData();
6323 joy_value = Joystick(player_nr);
6325 if (joy_value & JOY_BUTTON && check_remaining == 0)
6328 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6329 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6331 if (x != last_x || y != last_y)
6333 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6334 IMG_MENU_CALIBRATE_YELLOW, 0);
6335 DrawFixedGraphic(xpos + x, ypos + y,
6336 IMG_MENU_CALIBRATE_RED, 0);
6341 if (check_remaining > 0 && !check[x+1][y+1])
6343 check[x+1][y+1] = TRUE;
6351 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6354 /* calibrated center position (joystick should now be centered) */
6355 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6358 new_joystick_xmiddle = joy_x;
6359 new_joystick_ymiddle = joy_y;
6363 /* wait until the last pressed button was released */
6364 while (Joystick(player_nr) & JOY_BUTTON)
6366 if (PendingEvent()) /* got event */
6371 HandleOtherEvents(&event);
6373 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6380 void CalibrateJoystick(int player_nr)
6382 if (!CalibrateJoystickMain(player_nr))
6384 char *device_name = setup.input[player_nr].joy.device_name;
6385 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6386 int xpos = mSX - SX;
6387 int ypos = mSY - SY;
6391 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6392 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6395 Delay(2000); /* show error message for a short time */
6400 DrawSetupScreen_Input();
6403 void DrawSetupScreen()
6405 DeactivateJoystick();
6407 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6409 if (setup_mode == SETUP_MODE_INPUT)
6410 DrawSetupScreen_Input();
6411 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6412 DrawChooseTree(&game_speed_current);
6413 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6414 DrawChooseTree(&scroll_delay_current);
6415 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6416 DrawChooseTree(&snapshot_mode_current);
6417 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6418 DrawChooseTree(&window_size_current);
6419 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6420 DrawChooseTree(&scaling_type_current);
6421 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6422 DrawChooseTree(&artwork.gfx_current);
6423 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6424 DrawChooseTree(&artwork.snd_current);
6425 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6426 DrawChooseTree(&artwork.mus_current);
6427 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6428 DrawChooseTree(&volume_simple_current);
6429 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6430 DrawChooseTree(&volume_loops_current);
6431 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6432 DrawChooseTree(&volume_music_current);
6433 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6434 DrawChooseTree(&touch_control_current);
6435 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6436 DrawChooseTree(&move_distance_current);
6437 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6438 DrawChooseTree(&drop_distance_current);
6440 DrawSetupScreen_Generic();
6446 void RedrawSetupScreenAfterFullscreenToggle()
6448 if (setup_mode == SETUP_MODE_GRAPHICS ||
6449 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6451 // update list selection from "setup.window_scaling_percent"
6452 execSetupGraphics_setWindowSizes(TRUE);
6458 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6460 if (setup_mode == SETUP_MODE_INPUT)
6461 HandleSetupScreen_Input(mx, my, dx, dy, button);
6462 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6463 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6464 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6465 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6466 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6467 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6468 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6469 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6470 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6471 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6472 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6473 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6474 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6475 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6476 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6477 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6478 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6479 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6480 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6481 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6482 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6483 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6484 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6485 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6486 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6487 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6488 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6489 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6491 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6494 void HandleGameActions()
6496 if (game_status != GAME_MODE_PLAYING)
6499 GameActions(); /* main game loop */
6501 if (tape.auto_play && !tape.playing)
6502 AutoPlayTape(); /* continue automatically playing next tape */
6506 /* ---------- new screen button stuff -------------------------------------- */
6508 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6512 case SCREEN_CTRL_ID_PREV_LEVEL:
6513 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6514 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6517 case SCREEN_CTRL_ID_NEXT_LEVEL:
6518 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6519 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6522 case SCREEN_CTRL_ID_PREV_PLAYER:
6523 *x = mSX + TILEX * 10;
6524 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6527 case SCREEN_CTRL_ID_NEXT_PLAYER:
6528 *x = mSX + TILEX * 12;
6529 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6533 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6539 int gfx_unpressed, gfx_pressed;
6540 void (*get_gadget_position)(int *, int *, int);
6544 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6547 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6548 getScreenMenuButtonPos,
6549 SCREEN_CTRL_ID_PREV_LEVEL,
6554 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6555 getScreenMenuButtonPos,
6556 SCREEN_CTRL_ID_NEXT_LEVEL,
6561 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6562 getScreenMenuButtonPos,
6563 SCREEN_CTRL_ID_PREV_PLAYER,
6568 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6569 getScreenMenuButtonPos,
6570 SCREEN_CTRL_ID_NEXT_PLAYER,
6578 int gfx_unpressed, gfx_pressed;
6582 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6585 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6586 -1, -1, /* these values are not constant, but can change at runtime */
6587 SCREEN_CTRL_ID_SCROLL_UP,
6591 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6592 -1, -1, /* these values are not constant, but can change at runtime */
6593 SCREEN_CTRL_ID_SCROLL_DOWN,
6600 int gfx_unpressed, gfx_pressed;
6606 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6609 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6610 -1, -1, /* these values are not constant, but can change at runtime */
6611 -1, -1, /* these values are not constant, but can change at runtime */
6612 GD_TYPE_SCROLLBAR_VERTICAL,
6613 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6614 "scroll level series vertically"
6618 static void CreateScreenMenubuttons()
6620 struct GadgetInfo *gi;
6621 unsigned int event_mask;
6624 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6626 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6627 int gfx_unpressed, gfx_pressed;
6628 int x, y, width, height;
6629 int gd_x1, gd_x2, gd_y1, gd_y2;
6630 int id = menubutton_info[i].gadget_id;
6632 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6634 menubutton_info[i].get_gadget_position(&x, &y, id);
6636 width = SC_MENUBUTTON_XSIZE;
6637 height = SC_MENUBUTTON_YSIZE;
6639 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6640 gfx_pressed = menubutton_info[i].gfx_pressed;
6641 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6642 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6643 gd_x1 = graphic_info[gfx_unpressed].src_x;
6644 gd_y1 = graphic_info[gfx_unpressed].src_y;
6645 gd_x2 = graphic_info[gfx_pressed].src_x;
6646 gd_y2 = graphic_info[gfx_pressed].src_y;
6648 gi = CreateGadget(GDI_CUSTOM_ID, id,
6649 GDI_CUSTOM_TYPE_ID, i,
6650 GDI_INFO_TEXT, menubutton_info[i].infotext,
6655 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6656 GDI_STATE, GD_BUTTON_UNPRESSED,
6657 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6658 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6659 GDI_DIRECT_DRAW, FALSE,
6660 GDI_EVENT_MASK, event_mask,
6661 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6665 Error(ERR_EXIT, "cannot create gadget");
6667 screen_gadget[id] = gi;
6671 static void CreateScreenScrollbuttons()
6673 struct GadgetInfo *gi;
6674 unsigned int event_mask;
6677 /* these values are not constant, but can change at runtime */
6678 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6679 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6680 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6681 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6683 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6685 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6686 int gfx_unpressed, gfx_pressed;
6687 int x, y, width, height;
6688 int gd_x1, gd_x2, gd_y1, gd_y2;
6689 int id = scrollbutton_info[i].gadget_id;
6691 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6693 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6694 y = mSY + scrollbutton_info[i].y;
6695 width = SC_SCROLLBUTTON_XSIZE;
6696 height = SC_SCROLLBUTTON_YSIZE;
6698 /* correct scrollbar position if placed outside menu (playfield) area */
6699 if (x > SX + SC_SCROLL_UP_XPOS)
6700 x = SX + SC_SCROLL_UP_XPOS;
6702 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6703 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6704 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6706 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6707 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6708 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6709 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6710 gd_x1 = graphic_info[gfx_unpressed].src_x;
6711 gd_y1 = graphic_info[gfx_unpressed].src_y;
6712 gd_x2 = graphic_info[gfx_pressed].src_x;
6713 gd_y2 = graphic_info[gfx_pressed].src_y;
6715 gi = CreateGadget(GDI_CUSTOM_ID, id,
6716 GDI_CUSTOM_TYPE_ID, i,
6717 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6722 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6723 GDI_STATE, GD_BUTTON_UNPRESSED,
6724 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6725 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6726 GDI_DIRECT_DRAW, FALSE,
6727 GDI_EVENT_MASK, event_mask,
6728 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6732 Error(ERR_EXIT, "cannot create gadget");
6734 screen_gadget[id] = gi;
6738 static void CreateScreenScrollbars()
6742 /* these values are not constant, but can change at runtime */
6743 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6744 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6745 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6746 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6748 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6750 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6751 int gfx_unpressed, gfx_pressed;
6752 int x, y, width, height;
6753 int gd_x1, gd_x2, gd_y1, gd_y2;
6754 struct GadgetInfo *gi;
6755 int items_max, items_visible, item_position;
6756 unsigned int event_mask;
6757 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6758 int id = scrollbar_info[i].gadget_id;
6760 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6762 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6763 y = mSY + scrollbar_info[i].y;
6764 width = scrollbar_info[i].width;
6765 height = scrollbar_info[i].height;
6767 /* correct scrollbar position if placed outside menu (playfield) area */
6768 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6769 x = SX + SC_SCROLL_VERTICAL_XPOS;
6771 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6772 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6774 items_max = num_page_entries;
6775 items_visible = num_page_entries;
6778 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6779 gfx_pressed = scrollbar_info[i].gfx_pressed;
6780 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6781 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6782 gd_x1 = graphic_info[gfx_unpressed].src_x;
6783 gd_y1 = graphic_info[gfx_unpressed].src_y;
6784 gd_x2 = graphic_info[gfx_pressed].src_x;
6785 gd_y2 = graphic_info[gfx_pressed].src_y;
6787 gi = CreateGadget(GDI_CUSTOM_ID, id,
6788 GDI_CUSTOM_TYPE_ID, i,
6789 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6794 GDI_TYPE, scrollbar_info[i].type,
6795 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6796 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6797 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6798 GDI_WHEEL_AREA_X, SX,
6799 GDI_WHEEL_AREA_Y, SY,
6800 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6801 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6802 GDI_STATE, GD_BUTTON_UNPRESSED,
6803 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6804 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6805 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6806 GDI_DIRECT_DRAW, FALSE,
6807 GDI_EVENT_MASK, event_mask,
6808 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6812 Error(ERR_EXIT, "cannot create gadget");
6814 screen_gadget[id] = gi;
6818 void CreateScreenGadgets()
6820 int last_game_status = game_status; /* save current game status */
6822 CreateScreenMenubuttons();
6824 CreateScreenScrollbuttons();
6825 CreateScreenScrollbars();
6827 SetGameStatus(last_game_status); /* restore current game status */
6830 void FreeScreenGadgets()
6834 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6835 FreeGadget(screen_gadget[i]);
6838 void MapScreenMenuGadgets(int screen_mask)
6842 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6843 if (screen_mask & menubutton_info[i].screen_mask)
6844 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6847 void MapScreenGadgets(int num_entries)
6851 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6854 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6855 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6857 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6858 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6861 void MapScreenTreeGadgets(TreeInfo *ti)
6863 MapScreenGadgets(numTreeInfoInGroup(ti));
6866 static void HandleScreenGadgets(struct GadgetInfo *gi)
6868 int id = gi->custom_id;
6869 int button = gi->event.button;
6870 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6874 case SCREEN_CTRL_ID_PREV_LEVEL:
6875 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6878 case SCREEN_CTRL_ID_NEXT_LEVEL:
6879 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6882 case SCREEN_CTRL_ID_PREV_PLAYER:
6883 HandleSetupScreen_Input_Player(step, -1);
6886 case SCREEN_CTRL_ID_NEXT_PLAYER:
6887 HandleSetupScreen_Input_Player(step, +1);
6890 case SCREEN_CTRL_ID_SCROLL_UP:
6891 if (game_status == GAME_MODE_LEVELS)
6892 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6893 else if (game_status == GAME_MODE_LEVELNR)
6894 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6895 else if (game_status == GAME_MODE_SETUP)
6896 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6897 else if (game_status == GAME_MODE_INFO)
6898 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6901 case SCREEN_CTRL_ID_SCROLL_DOWN:
6902 if (game_status == GAME_MODE_LEVELS)
6903 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6904 else if (game_status == GAME_MODE_LEVELNR)
6905 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6906 else if (game_status == GAME_MODE_SETUP)
6907 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6908 else if (game_status == GAME_MODE_INFO)
6909 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6912 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6913 if (game_status == GAME_MODE_LEVELS)
6914 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6915 else if (game_status == GAME_MODE_LEVELNR)
6916 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6917 else if (game_status == GAME_MODE_SETUP)
6918 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6919 else if (game_status == GAME_MODE_INFO)
6920 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);