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_SCREEN_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 /* for input setup functions */
79 #define SETUPINPUT_SCREEN_POS_START 0
80 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
81 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
82 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
84 /* for various menu stuff */
85 #define MENU_SCREEN_START_XPOS 1
86 #define MENU_SCREEN_START_YPOS 2
87 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
88 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
89 #define MENU_TITLE1_YPOS 8
90 #define MENU_TITLE2_YPOS 46
91 #define MENU_SCREEN_INFO_XSTART 16
92 #define MENU_SCREEN_INFO_YSTART1 100
93 #define MENU_SCREEN_INFO_YSTART2 128
94 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
95 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
96 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
97 MENU_SCREEN_INFO_YSTART2 - \
99 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
100 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
101 MENU_SCREEN_INFO_YSTEP, \
102 MAX_INFO_ELEMENTS_ON_SCREEN)
103 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
104 #define MAX_MENU_TEXT_LENGTH_BIG 13
105 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
107 /* buttons and scrollbars identifiers */
108 #define SCREEN_CTRL_ID_PREV_LEVEL 0
109 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
110 #define SCREEN_CTRL_ID_PREV_PLAYER 2
111 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
112 #define SCREEN_CTRL_ID_SCROLL_UP 4
113 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
114 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
116 #define NUM_SCREEN_GADGETS 7
118 #define NUM_SCREEN_MENUBUTTONS 4
119 #define NUM_SCREEN_SCROLLBUTTONS 2
120 #define NUM_SCREEN_SCROLLBARS 1
122 #define SCREEN_MASK_MAIN (1 << 0)
123 #define SCREEN_MASK_INPUT (1 << 1)
125 /* graphic position and size values for buttons and scrollbars */
126 #define SC_MENUBUTTON_XSIZE TILEX
127 #define SC_MENUBUTTON_YSIZE TILEY
129 #define SC_SCROLLBUTTON_XSIZE TILEX
130 #define SC_SCROLLBUTTON_YSIZE TILEY
132 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
134 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
135 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
136 SC_SCROLLBUTTON_YSIZE)
138 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
139 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
141 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
142 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
143 SC_SCROLLBUTTON_YSIZE)
145 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
146 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
147 SC_SCROLL_VERTICAL_YSIZE)
149 #define SC_BORDER_SIZE 14
152 /* forward declarations of internal functions */
153 static void HandleScreenGadgets(struct GadgetInfo *);
154 static void HandleSetupScreen_Generic(int, int, int, int, int);
155 static void HandleSetupScreen_Input(int, int, int, int, int);
156 static void CustomizeKeyboard(int);
157 static void CalibrateJoystick(int);
158 static void execSetupGame(void);
159 static void execSetupGraphics(void);
160 static void execSetupSound(void);
161 static void execSetupTouch(void);
162 static void execSetupArtwork(void);
163 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
165 static void DrawChooseLevelSet(void);
166 static void DrawChooseLevelNr(void);
167 static void DrawInfoScreen(void);
168 static void DrawAndFadeInInfoScreen(int);
169 static void DrawSetupScreen(void);
171 static void DrawInfoScreenExt(int, int);
172 static void DrawInfoScreen_NotAvailable(char *, char *);
173 static void DrawInfoScreen_HelpAnim(int, int, boolean);
174 static void DrawInfoScreen_HelpText(int, int, int, int);
175 static void HandleInfoScreen_Main(int, int, int, int, int);
176 static void HandleInfoScreen_TitleScreen(int);
177 static void HandleInfoScreen_Elements(int);
178 static void HandleInfoScreen_Music(int);
179 static void HandleInfoScreen_Credits(int);
180 static void HandleInfoScreen_Program(int);
181 static void HandleInfoScreen_Version(int);
183 static void MapScreenMenuGadgets(int);
184 static void MapScreenGadgets(int);
185 static void MapScreenTreeGadgets(TreeInfo *);
187 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
189 static int info_mode = INFO_MODE_MAIN;
190 static int setup_mode = SETUP_MODE_MAIN;
192 static TreeInfo *screen_modes = NULL;
193 static TreeInfo *screen_mode_current = NULL;
195 static TreeInfo *window_sizes = NULL;
196 static TreeInfo *window_size_current = NULL;
198 static TreeInfo *scaling_types = NULL;
199 static TreeInfo *scaling_type_current = NULL;
201 static TreeInfo *scroll_delays = NULL;
202 static TreeInfo *scroll_delay_current = NULL;
204 static TreeInfo *game_speeds = NULL;
205 static TreeInfo *game_speed_current = NULL;
207 static TreeInfo *volumes_simple = NULL;
208 static TreeInfo *volume_simple_current = NULL;
210 static TreeInfo *volumes_loops = NULL;
211 static TreeInfo *volume_loops_current = NULL;
213 static TreeInfo *volumes_music = NULL;
214 static TreeInfo *volume_music_current = NULL;
216 static TreeInfo *touch_controls = NULL;
217 static TreeInfo *touch_control_current = NULL;
219 static TreeInfo *move_distances = NULL;
220 static TreeInfo *move_distance_current = NULL;
222 static TreeInfo *drop_distances = NULL;
223 static TreeInfo *drop_distance_current = NULL;
225 static TreeInfo *level_number = NULL;
226 static TreeInfo *level_number_current = NULL;
232 } window_sizes_list[] =
237 { 100, "100 % (Default)" },
254 } scaling_types_list[] =
256 { SCALING_QUALITY_NEAREST, "None" },
257 { SCALING_QUALITY_LINEAR, "Linear" },
258 { SCALING_QUALITY_BEST, "Anisotropic" },
267 } game_speeds_list[] =
276 { 1000, "1/1s (Extremely Slow)" },
281 { 29, "1/35s (Original Supaplex)" },
283 { 20, "1/50s (Normal Speed)" },
284 { 14, "1/70s (Maximum Supaplex)" },
288 { 1, "1/1000s (Extremely Fast)" },
298 } scroll_delays_list[] =
300 { 0, "0 Tiles (No Scroll Delay)" },
303 { 3, "3 Tiles (Default)" },
308 { 8, "8 Tiles (Maximum Scroll Delay)"},
341 } touch_controls_list[] =
343 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
344 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
368 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
369 (s) <= GAME_MODE_SETUP ? (s) : \
370 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
371 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
373 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
374 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
375 (i) <= INFO_MODE_LEVELSET ? (i) : \
378 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
379 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
380 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
381 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
382 SETUP_MODE_CHOOSE_ARTWORK : \
383 SETUP_MODE_CHOOSE_OTHER)
385 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
386 menu.draw_xoffset[GAME_MODE_INFO] : \
387 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
388 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
389 menu.draw_yoffset[GAME_MODE_INFO] : \
390 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
392 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
393 menu.draw_xoffset[GAME_MODE_SETUP] : \
394 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
395 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
396 menu.draw_yoffset[GAME_MODE_SETUP] : \
397 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
399 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
400 DRAW_XOFFSET_INFO(info_mode) : \
401 (s) == GAME_MODE_SETUP ? \
402 DRAW_XOFFSET_SETUP(setup_mode) : \
403 menu.draw_xoffset[DRAW_MODE(s)])
404 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
405 DRAW_YOFFSET_INFO(info_mode) : \
406 (s) == GAME_MODE_SETUP ? \
407 DRAW_YOFFSET_SETUP(setup_mode) : \
408 menu.draw_yoffset[DRAW_MODE(s)])
410 #define mSX (SX + DRAW_XOFFSET(game_status))
411 #define mSY (SY + DRAW_YOFFSET(game_status))
413 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
414 menu.list_size[game_status] : \
415 MAX_MENU_ENTRIES_ON_SCREEN)
417 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
418 NUM_MENU_ENTRIES_ON_SCREEN)
421 /* title display and control definitions */
423 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
424 2 * MAX_NUM_TITLE_MESSAGES)
426 #define NO_DIRECT_LEVEL_SELECT (-1)
429 static int num_title_screens = 0;
431 struct TitleControlInfo
439 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
441 /* main menu display and control definitions */
443 #define MAIN_CONTROL_NAME 0
444 #define MAIN_CONTROL_LEVELS 1
445 #define MAIN_CONTROL_SCORES 2
446 #define MAIN_CONTROL_EDITOR 3
447 #define MAIN_CONTROL_INFO 4
448 #define MAIN_CONTROL_GAME 5
449 #define MAIN_CONTROL_SETUP 6
450 #define MAIN_CONTROL_QUIT 7
451 #define MAIN_CONTROL_PREV_LEVEL 8
452 #define MAIN_CONTROL_NEXT_LEVEL 9
453 #define MAIN_CONTROL_FIRST_LEVEL 10
454 #define MAIN_CONTROL_LAST_LEVEL 11
455 #define MAIN_CONTROL_LEVEL_NUMBER 12
456 #define MAIN_CONTROL_LEVEL_INFO_1 13
457 #define MAIN_CONTROL_LEVEL_INFO_2 14
458 #define MAIN_CONTROL_LEVEL_NAME 15
459 #define MAIN_CONTROL_LEVEL_AUTHOR 16
460 #define MAIN_CONTROL_LEVEL_YEAR 17
461 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
462 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
463 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
464 #define MAIN_CONTROL_TITLE_1 21
465 #define MAIN_CONTROL_TITLE_2 22
466 #define MAIN_CONTROL_TITLE_3 23
468 static char str_main_text_name[10];
469 static char str_main_text_first_level[10];
470 static char str_main_text_last_level[10];
471 static char str_main_text_level_number[10];
473 static char *main_text_name = str_main_text_name;
474 static char *main_text_first_level = str_main_text_first_level;
475 static char *main_text_last_level = str_main_text_last_level;
476 static char *main_text_level_number = str_main_text_level_number;
477 static char *main_text_levels = "Levelset";
478 static char *main_text_scores = "Hall Of Fame";
479 static char *main_text_editor = "Level Creator";
480 static char *main_text_info = "Info Screen";
481 static char *main_text_game = "Start Game";
482 static char *main_text_setup = "Setup";
483 static char *main_text_quit = "Quit";
484 static char *main_text_level_name = level.name;
485 static char *main_text_level_author = level.author;
486 static char *main_text_level_year = NULL;
487 static char *main_text_level_imported_from = NULL;
488 static char *main_text_level_imported_by = NULL;
489 static char *main_text_level_tested_by = NULL;
490 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
491 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
492 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
494 struct MainControlInfo
498 struct MenuPosInfo *pos_button;
501 struct TextPosInfo *pos_text;
504 struct TextPosInfo *pos_input;
508 static struct MainControlInfo main_controls[] =
512 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
513 &menu.main.text.name, &main_text_name,
514 &menu.main.input.name, &setup.player_name,
518 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
519 &menu.main.text.levels, &main_text_levels,
524 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
525 &menu.main.text.scores, &main_text_scores,
530 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
531 &menu.main.text.editor, &main_text_editor,
536 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
537 &menu.main.text.info, &main_text_info,
542 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
543 &menu.main.text.game, &main_text_game,
548 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
549 &menu.main.text.setup, &main_text_setup,
554 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
555 &menu.main.text.quit, &main_text_quit,
559 /* (these two buttons are real gadgets) */
561 MAIN_CONTROL_PREV_LEVEL,
562 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
567 MAIN_CONTROL_NEXT_LEVEL,
568 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
574 MAIN_CONTROL_FIRST_LEVEL,
576 &menu.main.text.first_level, &main_text_first_level,
580 MAIN_CONTROL_LAST_LEVEL,
582 &menu.main.text.last_level, &main_text_last_level,
586 MAIN_CONTROL_LEVEL_NUMBER,
588 &menu.main.text.level_number, &main_text_level_number,
592 MAIN_CONTROL_LEVEL_INFO_1,
594 &menu.main.text.level_info_1, NULL,
598 MAIN_CONTROL_LEVEL_INFO_2,
600 &menu.main.text.level_info_2, NULL,
604 MAIN_CONTROL_LEVEL_NAME,
606 &menu.main.text.level_name, &main_text_level_name,
610 MAIN_CONTROL_LEVEL_AUTHOR,
612 &menu.main.text.level_author, &main_text_level_author,
616 MAIN_CONTROL_LEVEL_YEAR,
618 &menu.main.text.level_year, &main_text_level_year,
622 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
624 &menu.main.text.level_imported_from, &main_text_level_imported_from,
628 MAIN_CONTROL_LEVEL_IMPORTED_BY,
630 &menu.main.text.level_imported_by, &main_text_level_imported_by,
634 MAIN_CONTROL_LEVEL_TESTED_BY,
636 &menu.main.text.level_tested_by, &main_text_level_tested_by,
640 MAIN_CONTROL_TITLE_1,
642 &menu.main.text.title_1, &main_text_title_1,
646 MAIN_CONTROL_TITLE_2,
648 &menu.main.text.title_2, &main_text_title_2,
652 MAIN_CONTROL_TITLE_3,
654 &menu.main.text.title_3, &main_text_title_3,
667 static int getTitleScreenGraphic(int nr, boolean initial)
669 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
672 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
674 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
678 static int getTitleScreenGameMode(boolean initial)
680 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
684 static int getTitleMessageGameMode(boolean initial)
686 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
690 static int getTitleScreenBackground(boolean initial)
692 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
697 static int getTitleMessageBackground(int nr, boolean initial)
699 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
703 static int getTitleBackground(int nr, boolean initial, boolean is_image)
705 int base = (is_image ?
706 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
707 IMG_BACKGROUND_TITLESCREEN_1) :
708 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
709 IMG_BACKGROUND_TITLEMESSAGE_1));
710 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
711 IMG_BACKGROUND_TITLE);
712 int graphic_local = base + nr;
714 if (graphic_info[graphic_local].bitmap != NULL)
715 return graphic_local;
717 if (graphic_info[graphic_global].bitmap != NULL)
718 return graphic_global;
720 return IMG_UNDEFINED;
723 static int getTitleSound(struct TitleControlInfo *tci)
725 boolean is_image = tci->is_image;
726 int initial = tci->initial;
727 int nr = tci->local_nr;
728 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
729 int base = (is_image ?
730 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
731 SND_BACKGROUND_TITLESCREEN_1) :
732 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
733 SND_BACKGROUND_TITLEMESSAGE_1));
734 int sound_global = menu.sound[mode];
735 int sound_local = base + nr;
738 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
739 nr, initial, is_image,
740 sound_global, getSoundListEntry(sound_global)->filename,
741 sound_local, getSoundListEntry(sound_local)->filename);
744 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
747 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
750 return SND_UNDEFINED;
753 static int getTitleMusic(struct TitleControlInfo *tci)
755 boolean is_image = tci->is_image;
756 int initial = tci->initial;
757 int nr = tci->local_nr;
758 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
759 int base = (is_image ?
760 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
761 MUS_BACKGROUND_TITLESCREEN_1) :
762 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
763 MUS_BACKGROUND_TITLEMESSAGE_1));
764 int music_global = menu.music[mode];
765 int music_local = base + nr;
768 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
769 nr, initial, is_image,
770 music_global, getMusicListEntry(music_global)->filename,
771 music_local, getMusicListEntry(music_local)->filename);
774 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
777 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
780 return MUS_UNDEFINED;
783 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
785 boolean is_image = tci->is_image;
786 int initial = tci->initial;
787 int nr = tci->local_nr;
788 struct TitleFadingInfo ti;
792 int graphic = getTitleScreenGraphic(nr, initial);
794 /* initialize fading control values to default title config settings */
795 ti = (initial ? title_initial_default : title_default);
797 /* override default settings with image config settings, if defined */
798 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
799 ti.fade_mode = graphic_info[graphic].fade_mode;
800 if (graphic_info[graphic].fade_delay > -1)
801 ti.fade_delay = graphic_info[graphic].fade_delay;
802 if (graphic_info[graphic].post_delay > -1)
803 ti.post_delay = graphic_info[graphic].post_delay;
804 if (graphic_info[graphic].auto_delay > -1)
805 ti.auto_delay = graphic_info[graphic].auto_delay;
811 ti.fade_mode = titlemessage_initial[nr].fade_mode;
812 ti.fade_delay = titlemessage_initial[nr].fade_delay;
813 ti.post_delay = titlemessage_initial[nr].post_delay;
814 ti.auto_delay = titlemessage_initial[nr].auto_delay;
818 ti.fade_mode = titlemessage[nr].fade_mode;
819 ti.fade_delay = titlemessage[nr].fade_delay;
820 ti.post_delay = titlemessage[nr].post_delay;
821 ti.auto_delay = titlemessage[nr].auto_delay;
828 static int compareTitleControlInfo(const void *object1, const void *object2)
830 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
831 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
834 if (tci1->initial != tci2->initial)
835 compare_result = (tci1->initial ? -1 : +1);
836 else if (tci1->sort_priority != tci2->sort_priority)
837 compare_result = tci1->sort_priority - tci2->sort_priority;
838 else if (tci1->is_image != tci2->is_image)
839 compare_result = (tci1->is_image ? -1 : +1);
841 compare_result = tci1->local_nr - tci2->local_nr;
843 return compare_result;
846 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
848 int nr, int sort_priority)
850 title_controls[num_title_screens].is_image = is_image;
851 title_controls[num_title_screens].initial = initial;
852 title_controls[num_title_screens].local_nr = nr;
853 title_controls[num_title_screens].sort_priority = sort_priority;
858 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
862 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
864 int graphic = getTitleScreenGraphic(i, initial);
865 Bitmap *bitmap = graphic_info[graphic].bitmap;
866 int sort_priority = graphic_info[graphic].sort_priority;
869 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
872 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
874 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
875 char *filename = getLevelSetTitleMessageFilename(i, initial);
876 int sort_priority = tmi->sort_priority;
878 if (filename != NULL)
879 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
883 static void InitializeTitleControls(boolean show_title_initial)
885 num_title_screens = 0;
887 /* 1st step: initialize title screens for game start (only when starting) */
888 if (show_title_initial)
889 InitializeTitleControls_CheckTitleInfo(TRUE);
891 /* 2nd step: initialize title screens for current level set */
892 InitializeTitleControls_CheckTitleInfo(FALSE);
894 /* sort title screens according to sort_priority and title number */
895 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
896 compareTitleControlInfo);
899 static boolean visibleMenuPos(struct MenuPosInfo *pos)
901 return (pos != NULL && pos->x != -1 && pos->y != -1);
904 static boolean visibleTextPos(struct TextPosInfo *pos)
906 return (pos != NULL && pos->x != -1 && pos->y != -1);
909 static void InitializeMainControls()
911 boolean local_team_mode = (!options.network && setup.team_mode);
914 /* set main control text values to dynamically determined values */
915 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
917 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
918 menu.main.text.first_level.size));
919 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
920 menu.main.text.last_level.size));
921 strcpy(main_text_level_number, int2str(level_nr,
922 menu.main.text.level_number.size));
924 main_text_level_year = leveldir_current->year;
925 main_text_level_imported_from = leveldir_current->imported_from;
926 main_text_level_imported_by = leveldir_current->imported_by;
927 main_text_level_tested_by = leveldir_current->tested_by;
929 /* set main control screen positions to dynamically determined values */
930 for (i = 0; main_controls[i].nr != -1; i++)
932 struct MainControlInfo *mci = &main_controls[i];
934 struct MenuPosInfo *pos_button = mci->pos_button;
935 struct TextPosInfo *pos_text = mci->pos_text;
936 struct TextPosInfo *pos_input = mci->pos_input;
937 char *text = (mci->text ? *mci->text : NULL);
938 char *input = (mci->input ? *mci->input : NULL);
939 int button_graphic = mci->button_graphic;
940 int font_text = (pos_text ? pos_text->font : -1);
941 int font_input = (pos_input ? pos_input->font : -1);
943 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
944 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
945 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
946 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
947 int text_chars = (text != NULL ? strlen(text) : 0);
948 int input_chars = (input != NULL ? strlen(input) : 0);
951 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
953 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
954 int text_width = font_text_width * text_chars;
955 int text_height = font_text_height;
956 int input_width = font_input_width * input_chars;
957 int input_height = font_input_height;
959 if (nr == MAIN_CONTROL_NAME)
961 menu.main.input.name.width = input_width;
962 menu.main.input.name.height = input_height;
965 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
967 pos_button->width = button_width;
968 pos_button->height = button_height;
971 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
973 /* calculate size for non-clickable text -- needed for text alignment */
974 boolean calculate_text_size = (pos_button == NULL && text != NULL);
976 if (pos_text->width == -1 || calculate_text_size)
977 pos_text->width = text_width;
978 if (pos_text->height == -1 || calculate_text_size)
979 pos_text->height = text_height;
981 if (visibleMenuPos(pos_button))
983 if (pos_text->x == -1)
984 pos_text->x = pos_button->x + pos_button->width;
985 if (pos_text->y == -1)
987 pos_button->y + (pos_button->height - pos_text->height) / 2;
991 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
993 if (visibleTextPos(pos_text))
995 if (pos_input->x == -1)
996 pos_input->x = pos_text->x + pos_text->width;
997 if (pos_input->y == -1)
998 pos_input->y = pos_text->y;
1001 if (pos_input->width == -1)
1002 pos_input->width = input_width;
1003 if (pos_input->height == -1)
1004 pos_input->height = input_height;
1009 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1010 boolean active_input)
1014 for (i = 0; main_controls[i].nr != -1; i++)
1016 struct MainControlInfo *mci = &main_controls[i];
1018 if (mci->nr == nr || nr == -1)
1020 struct MenuPosInfo *pos_button = mci->pos_button;
1021 struct TextPosInfo *pos_text = mci->pos_text;
1022 struct TextPosInfo *pos_input = mci->pos_input;
1023 char *text = (mci->text ? *mci->text : NULL);
1024 char *input = (mci->input ? *mci->input : NULL);
1025 int button_graphic = mci->button_graphic;
1026 int font_text = (pos_text ? pos_text->font : -1);
1027 int font_input = (pos_input ? pos_input->font : -1);
1031 button_graphic = BUTTON_ACTIVE(button_graphic);
1032 font_text = FONT_ACTIVE(font_text);
1037 font_input = FONT_ACTIVE(font_input);
1040 if (visibleMenuPos(pos_button))
1042 struct MenuPosInfo *pos = pos_button;
1043 int x = mSX + pos->x;
1044 int y = mSY + pos->y;
1046 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1047 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1050 if (visibleTextPos(pos_text) && text != NULL)
1052 struct TextPosInfo *pos = pos_text;
1053 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1054 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1057 /* (check why/if this is needed) */
1058 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1060 DrawText(x, y, text, font_text);
1063 if (visibleTextPos(pos_input) && input != NULL)
1065 struct TextPosInfo *pos = pos_input;
1066 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1067 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1070 /* (check why/if this is needed) */
1071 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1073 DrawText(x, y, input, font_input);
1079 static void DrawCursorAndText_Main(int nr, boolean active_text)
1081 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1085 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1087 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1091 static struct MainControlInfo *getMainControlInfo(int nr)
1095 for (i = 0; main_controls[i].nr != -1; i++)
1096 if (main_controls[i].nr == nr)
1097 return &main_controls[i];
1102 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1107 int rect_x = ALIGNED_TEXT_XPOS(rect);
1108 int rect_y = ALIGNED_TEXT_YPOS(rect);
1110 return (x >= rect_x && x < rect_x + rect->width &&
1111 y >= rect_y && y < rect_y + rect->height);
1114 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1119 int rect_x = ALIGNED_TEXT_XPOS(rect);
1120 int rect_y = ALIGNED_TEXT_YPOS(rect);
1123 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1124 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1125 (x >= rect_x && x < rect_x + rect->width &&
1126 y >= rect_y && y < rect_y + rect->height));
1129 return (x >= rect_x && x < rect_x + rect->width &&
1130 y >= rect_y && y < rect_y + rect->height);
1133 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1135 static int cursor_array[MAX_LEV_FIELDY];
1136 int x = mSX + TILEX * xpos;
1137 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1142 cursor_array[ypos] = graphic;
1144 graphic = cursor_array[ypos];
1148 graphic = BUTTON_ACTIVE(graphic);
1150 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1151 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1154 static void initCursor(int ypos, int graphic)
1156 drawCursorExt(0, ypos, FALSE, graphic);
1159 static void drawCursor(int ypos, boolean active)
1161 drawCursorExt(0, ypos, active, -1);
1164 static void drawCursorXY(int xpos, int ypos, int graphic)
1166 drawCursorExt(xpos, ypos, FALSE, graphic);
1169 static void drawChooseTreeCursor(int ypos, boolean active)
1171 int last_game_status = game_status; /* save current game status */
1173 drawCursorExt(0, ypos, active, -1);
1175 game_status = last_game_status; /* restore current game status */
1180 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1181 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1184 int effectiveGameStatus()
1186 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1187 return GAME_MODE_TITLE;
1192 void DrawTitleScreenImage(int nr, boolean initial)
1194 int graphic = getTitleScreenGraphic(nr, initial);
1195 Bitmap *bitmap = graphic_info[graphic].bitmap;
1196 int width = graphic_info[graphic].width;
1197 int height = graphic_info[graphic].height;
1198 int src_x = graphic_info[graphic].src_x;
1199 int src_y = graphic_info[graphic].src_y;
1205 if (width > WIN_XSIZE)
1207 /* image width too large for window => center image horizontally */
1208 src_x = (width - WIN_XSIZE) / 2;
1212 if (height > WIN_YSIZE)
1214 /* image height too large for window => center image vertically */
1215 src_y = (height - WIN_YSIZE) / 2;
1219 /* always display title screens centered */
1220 dst_x = (WIN_XSIZE - width) / 2;
1221 dst_y = (WIN_YSIZE - height) / 2;
1223 SetDrawBackgroundMask(REDRAW_ALL);
1224 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1226 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1228 if (DrawingOnBackground(dst_x, dst_y))
1229 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1231 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1233 redraw_mask = REDRAW_ALL;
1236 void DrawTitleScreenMessage(int nr, boolean initial)
1238 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1239 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1240 int last_game_status = game_status; /* save current game status */
1242 if (filename == NULL)
1245 /* force TITLE font on title message screen */
1246 game_status = getTitleMessageGameMode(initial);
1248 /* if chars set to "-1", automatically determine by text and font width */
1249 if (tmi->chars == -1)
1250 tmi->chars = tmi->width / getFontWidth(tmi->font);
1252 tmi->width = tmi->chars * getFontWidth(tmi->font);
1254 /* if lines set to "-1", automatically determine by text and font height */
1255 if (tmi->lines == -1)
1256 tmi->lines = tmi->height / getFontHeight(tmi->font);
1258 tmi->height = tmi->lines * getFontHeight(tmi->font);
1260 SetDrawBackgroundMask(REDRAW_ALL);
1261 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1263 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1265 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1266 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1267 tmi->autowrap, tmi->centered, tmi->parse_comments);
1269 game_status = last_game_status; /* restore current game status */
1272 void DrawTitleScreen()
1274 KeyboardAutoRepeatOff();
1276 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1281 boolean CheckTitleScreen(boolean levelset_has_changed)
1283 static boolean show_title_initial = TRUE;
1284 boolean show_titlescreen = FALSE;
1286 /* needed to be able to skip title screen, if no image or message defined */
1287 InitializeTitleControls(show_title_initial);
1289 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1290 show_titlescreen = TRUE;
1292 /* show initial title images and messages only once at program start */
1293 show_title_initial = FALSE;
1295 return (show_titlescreen && num_title_screens > 0);
1298 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1300 static LevelDirTree *leveldir_last_valid = NULL;
1301 boolean levelset_has_changed = FALSE;
1303 LimitScreenUpdates(FALSE);
1305 FadeSetLeaveScreen();
1307 /* do not fade out here -- function may continue and fade on editor screen */
1310 FadeSoundsAndMusic();
1312 KeyboardAutoRepeatOn();
1315 audio.sound_deactivated = FALSE;
1319 /* needed if last screen was the playing screen, invoked from level editor */
1320 if (level_editor_test_game)
1322 game_status = GAME_MODE_EDITOR;
1328 /* needed if last screen was the setup screen and fullscreen state changed */
1329 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1330 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1332 /* leveldir_current may be invalid (level group, parent link) */
1333 if (!validLevelSeries(leveldir_current))
1334 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1336 if (leveldir_current != leveldir_last_valid)
1337 levelset_has_changed = TRUE;
1339 /* store valid level series information */
1340 leveldir_last_valid = leveldir_current;
1342 init_last = init; /* switch to new busy animation */
1344 /* needed if last screen (level choice) changed graphics, sounds or music */
1345 ReloadCustomArtwork(0);
1347 if (redraw_mask & REDRAW_ALL)
1348 fade_mask = REDRAW_ALL;
1352 /* needed if different viewport properties defined for menues */
1353 ChangeViewportPropertiesIfNeeded();
1355 /* needed if last screen was the editor screen */
1356 UndrawSpecialEditorDoor();
1358 SetDrawtoField(DRAW_BACKBUFFER);
1360 if (CheckTitleScreen(levelset_has_changed))
1362 game_status = GAME_MODE_TITLE;
1369 /* level_nr may have been set to value over handicap with level editor */
1370 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1371 level_nr = leveldir_current->handicap_level;
1373 LoadLevel(level_nr);
1374 LoadScore(level_nr);
1376 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1377 SetDrawDeactivationMask(REDRAW_NONE);
1378 SetDrawBackgroundMask(REDRAW_FIELD);
1380 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1382 if (fade_mask == REDRAW_ALL)
1383 RedrawGlobalBorder();
1387 InitializeMainControls();
1389 DrawCursorAndText_Main(-1, FALSE);
1390 DrawPreviewLevelInitial();
1392 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1395 if (TAPE_IS_EMPTY(tape))
1397 DrawCompleteVideoDisplay();
1402 /* create gadgets for main menu screen */
1403 FreeScreenGadgets();
1404 CreateScreenGadgets();
1406 /* map gadgets for main menu screen */
1408 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1410 /* copy actual game door content to door double buffer for OpenDoor() */
1411 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1413 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1415 DrawMaskedBorder(REDRAW_ALL);
1420 /* update screen area with special editor door */
1421 redraw_mask |= REDRAW_ALL;
1424 SetMouseCursor(CURSOR_DEFAULT);
1428 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1431 void DrawAndFadeInMainMenu(int fade_mask)
1433 DrawMainMenuExt(fade_mask, TRUE);
1438 DrawMainMenuExt(REDRAW_ALL, FALSE);
1441 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1442 static void gotoTopLevelDir()
1444 /* move upwards to top level directory */
1445 while (leveldir_current->node_parent)
1447 /* write a "path" into level tree for easy navigation to last level */
1448 if (leveldir_current->node_parent->node_group->cl_first == -1)
1450 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1451 int leveldir_pos = posTreeInfo(leveldir_current);
1452 int num_page_entries;
1453 int cl_first, cl_cursor;
1455 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1456 num_page_entries = num_leveldirs;
1458 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1460 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1461 cl_cursor = leveldir_pos - cl_first;
1463 leveldir_current->node_parent->node_group->cl_first = cl_first;
1464 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1467 leveldir_current = leveldir_current->node_parent;
1472 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1474 static unsigned int title_delay = 0;
1475 static int title_screen_nr = 0;
1476 static int last_sound = -1, last_music = -1;
1477 boolean return_to_main_menu = FALSE;
1478 boolean use_fading_main_menu = TRUE;
1479 struct TitleControlInfo *tci;
1480 struct TitleFadingInfo fading_default;
1481 struct TitleFadingInfo fading_last = fading;
1482 struct TitleFadingInfo fading_next;
1485 if (button == MB_MENU_INITIALIZE)
1488 title_screen_nr = 0;
1489 tci = &title_controls[title_screen_nr];
1491 last_sound = SND_UNDEFINED;
1492 last_music = MUS_UNDEFINED;
1494 if (game_status == GAME_MODE_INFO)
1496 if (num_title_screens == 0)
1498 DrawInfoScreen_NotAvailable("Title screen information:",
1499 "No title screen for this level set.");
1504 FadeSoundsAndMusic();
1506 FadeOut(REDRAW_ALL);
1510 DrawTitleScreenImage(tci->local_nr, tci->initial);
1512 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1514 fading_default = (tci->initial ? title_initial_default : title_default);
1516 fading = fading_next = getTitleFading(tci);
1518 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1519 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1521 fading.fade_mode = FADE_MODE_FADE;
1522 fading.fade_delay = fading_default.fade_delay;
1525 sound = getTitleSound(tci);
1526 music = getTitleMusic(tci);
1528 if (sound != last_sound)
1529 PlayMenuSoundExt(sound);
1530 if (music != last_music)
1531 PlayMenuMusicExt(music);
1536 SetMouseCursor(CURSOR_NONE);
1540 fading = fading_next;
1542 DelayReached(&title_delay, 0); /* reset delay counter */
1547 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1548 button = MB_MENU_CHOICE;
1550 if (button == MB_MENU_LEAVE)
1552 return_to_main_menu = TRUE;
1553 use_fading_main_menu = FALSE;
1555 else if (button == MB_MENU_CHOICE)
1557 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1559 FadeSetEnterScreen();
1561 info_mode = INFO_MODE_MAIN;
1562 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1568 tci = &title_controls[title_screen_nr];
1570 if (title_screen_nr < num_title_screens)
1572 sound = getTitleSound(tci);
1573 music = getTitleMusic(tci);
1575 if (sound == SND_UNDEFINED || sound != last_sound)
1577 if (music == MUS_UNDEFINED || music != last_music)
1580 FadeOut(REDRAW_ALL);
1583 DrawTitleScreenImage(tci->local_nr, tci->initial);
1585 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1587 fading_next = getTitleFading(tci);
1589 sound = getTitleSound(tci);
1590 music = getTitleMusic(tci);
1592 if (sound != last_sound)
1593 PlayMenuSoundExt(sound);
1594 if (music != last_music)
1595 PlayMenuMusicExt(music);
1600 /* last screen already faded out, next screen has no animation */
1601 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1602 fading_next.fade_mode == FADE_MODE_NONE)
1603 fading = fading_next;
1607 fading = fading_next;
1609 DelayReached(&title_delay, 0); /* reset delay counter */
1613 FadeSoundsAndMusic();
1615 return_to_main_menu = TRUE;
1619 if (return_to_main_menu)
1621 SetMouseCursor(CURSOR_DEFAULT);
1623 if (game_status == GAME_MODE_INFO)
1625 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1627 info_mode = INFO_MODE_MAIN;
1629 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1631 else /* default: return to main menu */
1633 game_status = GAME_MODE_MAIN;
1635 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1640 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1642 int old_level_nr = level_nr;
1645 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1646 new_level_nr = selected_level_nr;
1648 new_level_nr = old_level_nr + step * direction;
1650 if (new_level_nr < leveldir_current->first_level)
1651 new_level_nr = leveldir_current->first_level;
1652 if (new_level_nr > leveldir_current->last_level)
1653 new_level_nr = leveldir_current->last_level;
1655 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1657 /* skipping levels is only allowed when trying to skip single level */
1658 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1659 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1661 leveldir_current->handicap_level++;
1662 SaveLevelSetup_SeriesInfo();
1665 new_level_nr = leveldir_current->handicap_level;
1668 if (new_level_nr != old_level_nr)
1670 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1672 PlaySound(SND_MENU_ITEM_SELECTING);
1674 level_nr = new_level_nr;
1676 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1677 int2str(level_nr, menu.main.text.level_number.size),
1678 mci->pos_text->font);
1680 LoadLevel(level_nr);
1681 DrawPreviewLevelInitial();
1685 DrawCompleteVideoDisplay();
1687 /* needed because DrawPreviewLevelInitial() takes some time */
1689 /* SyncDisplay(); */
1693 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1695 static int choice = MAIN_CONTROL_GAME;
1699 if (button == MB_MENU_INITIALIZE)
1701 DrawCursorAndText_Main(choice, TRUE);
1706 if (mx || my) /* mouse input */
1710 for (i = 0; main_controls[i].nr != -1; i++)
1712 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1713 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1714 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1716 pos = main_controls[i].nr;
1722 else if (dx || dy) /* keyboard input */
1724 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1725 choice == MAIN_CONTROL_SETUP))
1726 button = MB_MENU_CHOICE;
1731 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1733 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1735 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1737 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1739 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1741 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1743 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1745 game_status = GAME_MODE_LEVELNR;
1747 ChangeViewportPropertiesIfNeeded();
1749 DrawChooseLevelNr();
1751 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1757 PlaySound(SND_MENU_ITEM_ACTIVATING);
1759 DrawCursorAndText_Main(choice, FALSE);
1760 DrawCursorAndText_Main(pos, TRUE);
1767 PlaySound(SND_MENU_ITEM_SELECTING);
1769 if (pos == MAIN_CONTROL_NAME)
1771 game_status = GAME_MODE_PSEUDO_TYPENAME;
1773 HandleTypeName(strlen(setup.player_name), 0);
1775 else if (pos == MAIN_CONTROL_LEVELS)
1779 game_status = GAME_MODE_LEVELS;
1781 SaveLevelSetup_LastSeries();
1782 SaveLevelSetup_SeriesInfo();
1784 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1788 ChangeViewportPropertiesIfNeeded();
1790 DrawChooseLevelSet();
1793 else if (pos == MAIN_CONTROL_SCORES)
1795 game_status = GAME_MODE_SCORES;
1797 ChangeViewportPropertiesIfNeeded();
1801 else if (pos == MAIN_CONTROL_EDITOR)
1803 if (leveldir_current->readonly &&
1804 !strEqual(setup.player_name, "Artsoft"))
1805 Request("This level is read only!", REQ_CONFIRM);
1807 CloseDoor(DOOR_CLOSE_2);
1809 game_status = GAME_MODE_EDITOR;
1811 FadeSetEnterScreen();
1815 else if (pos == MAIN_CONTROL_INFO)
1817 game_status = GAME_MODE_INFO;
1818 info_mode = INFO_MODE_MAIN;
1820 ChangeViewportPropertiesIfNeeded();
1824 else if (pos == MAIN_CONTROL_GAME)
1826 StartGameActions(options.network, setup.autorecord, level.random_seed);
1828 else if (pos == MAIN_CONTROL_SETUP)
1830 game_status = GAME_MODE_SETUP;
1831 setup_mode = SETUP_MODE_MAIN;
1833 ChangeViewportPropertiesIfNeeded();
1837 else if (pos == MAIN_CONTROL_QUIT)
1839 SaveLevelSetup_LastSeries();
1840 SaveLevelSetup_SeriesInfo();
1842 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1843 game_status = GAME_MODE_QUIT;
1850 /* ========================================================================= */
1851 /* info screen functions */
1852 /* ========================================================================= */
1854 static struct TokenInfo *info_info;
1855 static int num_info_info;
1857 static void execInfoTitleScreen()
1859 info_mode = INFO_MODE_TITLE;
1864 static void execInfoElements()
1866 info_mode = INFO_MODE_ELEMENTS;
1871 static void execInfoMusic()
1873 info_mode = INFO_MODE_MUSIC;
1878 static void execInfoCredits()
1880 info_mode = INFO_MODE_CREDITS;
1885 static void execInfoProgram()
1887 info_mode = INFO_MODE_PROGRAM;
1892 static void execInfoVersion()
1894 info_mode = INFO_MODE_VERSION;
1899 static void execInfoLevelSet()
1901 info_mode = INFO_MODE_LEVELSET;
1906 static void execExitInfo()
1908 game_status = GAME_MODE_MAIN;
1910 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1913 static struct TokenInfo info_info_main[] =
1915 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1916 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1917 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1918 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1919 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1920 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1921 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1922 { TYPE_EMPTY, NULL, "" },
1923 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1928 static void DrawCursorAndText_Info(int pos, boolean active)
1930 int xpos = MENU_SCREEN_START_XPOS;
1931 int ypos = MENU_SCREEN_START_YPOS + pos;
1932 int font_nr = FONT_MENU_1;
1935 font_nr = FONT_ACTIVE(font_nr);
1937 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1939 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1940 drawCursor(pos, active);
1943 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1948 CloseDoor(DOOR_CLOSE_2);
1950 /* (needed after displaying title screens which disable auto repeat) */
1951 KeyboardAutoRepeatOn();
1953 FadeSetLeaveScreen();
1957 if (fade_mask == REDRAW_ALL)
1959 RedrawGlobalBorder();
1961 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1966 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1968 info_info = info_info_main;
1971 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1973 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1974 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1975 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1976 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1977 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1978 initCursor(i, IMG_MENU_BUTTON);
1980 DrawCursorAndText_Info(i, FALSE);
1985 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1990 DrawMaskedBorder(fade_mask);
1997 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1999 static int choice_store[MAX_INFO_MODES];
2000 int choice = choice_store[info_mode]; /* always starts with 0 */
2004 if (button == MB_MENU_INITIALIZE)
2006 /* advance to first valid menu entry */
2007 while (choice < num_info_info &&
2008 info_info[choice].type & TYPE_SKIP_ENTRY)
2010 choice_store[info_mode] = choice;
2012 DrawCursorAndText_Info(choice, TRUE);
2016 else if (button == MB_MENU_LEAVE)
2018 for (y = 0; y < num_info_info; y++)
2020 if (info_info[y].type & TYPE_LEAVE_MENU)
2022 void (*menu_callback_function)(void) = info_info[y].value;
2026 menu_callback_function();
2028 break; /* absolutely needed because function changes 'info_info'! */
2035 if (mx || my) /* mouse input */
2037 x = (mx - mSX) / 32;
2038 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2040 else if (dx || dy) /* keyboard input */
2044 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2046 if (info_info[choice].type & menu_navigation_type ||
2047 info_info[choice].type & TYPE_ENTER_SCREEN ||
2048 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2049 info_info[choice].type & TYPE_YES_NO_AUTO)
2050 button = MB_MENU_CHOICE;
2055 /* jump to next non-empty menu entry (up or down) */
2056 while (y > 0 && y < num_info_info - 1 &&
2057 info_info[y].type & TYPE_SKIP_ENTRY)
2061 if (IN_VIS_MENU(x, y) &&
2062 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2068 PlaySound(SND_MENU_ITEM_ACTIVATING);
2070 DrawCursorAndText_Info(choice, FALSE);
2071 DrawCursorAndText_Info(y, TRUE);
2073 choice = choice_store[info_mode] = y;
2076 else if (!(info_info[y].type & TYPE_GHOSTED))
2078 PlaySound(SND_MENU_ITEM_SELECTING);
2080 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2082 void (*menu_callback_function)(void) = info_info[choice].value;
2084 FadeSetFromType(info_info[y].type);
2086 menu_callback_function();
2092 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2094 int ystart1 = mSY - SY + 100;
2095 int ystart2 = mSY - SY + 150;
2096 int ybottom = mSY - SY + SYSIZE - 20;
2098 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2100 FadeOut(REDRAW_FIELD);
2105 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2106 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2108 DrawTextSCentered(ybottom, FONT_TEXT_4,
2109 "Press any key or button for info menu");
2111 FadeIn(REDRAW_FIELD);
2114 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2116 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2117 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2118 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2119 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2120 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2121 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2122 int ystep = MENU_SCREEN_INFO_YSTEP;
2123 int element, action, direction;
2131 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2132 infoscreen_step[i] = infoscreen_frame[i] = 0;
2137 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2139 DrawTextSCentered(ybottom, FONT_TEXT_4,
2140 "Press any key or button for next page");
2146 while (helpanim_info[j].element != HELPANIM_LIST_END)
2148 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2153 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2162 j += infoscreen_step[i - start];
2164 element = helpanim_info[j].element;
2165 action = helpanim_info[j].action;
2166 direction = helpanim_info[j].direction;
2169 element = EL_UNKNOWN;
2171 if (action != -1 && direction != -1)
2172 graphic = el_act_dir2img(element, action, direction);
2173 else if (action != -1)
2174 graphic = el_act2img(element, action);
2175 else if (direction != -1)
2176 graphic = el_dir2img(element, direction);
2178 graphic = el2img(element);
2180 delay = helpanim_info[j++].delay;
2185 if (infoscreen_frame[i - start] == 0)
2188 infoscreen_frame[i - start] = delay - 1;
2192 sync_frame = delay - infoscreen_frame[i - start];
2193 infoscreen_frame[i - start]--;
2196 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2198 if (!infoscreen_frame[i - start])
2199 infoscreen_step[i - start] = 0;
2203 if (!infoscreen_frame[i - start])
2204 infoscreen_step[i - start]++;
2205 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2211 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2213 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2214 graphic, sync_frame, USE_MASKING);
2217 DrawInfoScreen_HelpText(element, action, direction, i - start);
2222 redraw_mask |= REDRAW_FIELD;
2227 static char *getHelpText(int element, int action, int direction)
2229 char token[MAX_LINE_LEN];
2231 strcpy(token, element_info[element].token_name);
2234 strcat(token, element_action_info[action].suffix);
2236 if (direction != -1)
2237 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2239 return getHashEntry(helptext_info, token);
2242 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2244 int font_nr = FONT_INFO_ELEMENTS;
2245 int font_width = getFontWidth(font_nr);
2246 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2247 int sy = mSY + 65 + 2 * 32 + 1;
2248 int ystep = TILEY + 4;
2249 int pad_x = sx - SX;
2250 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2251 int max_lines_per_text = 2;
2254 if (action != -1 && direction != -1) /* element.action.direction */
2255 text = getHelpText(element, action, direction);
2257 if (text == NULL && action != -1) /* element.action */
2258 text = getHelpText(element, action, -1);
2260 if (text == NULL && direction != -1) /* element.direction */
2261 text = getHelpText(element, -1, direction);
2263 if (text == NULL) /* base element */
2264 text = getHelpText(element, -1, -1);
2266 if (text == NULL) /* not found */
2267 text = "No description available";
2269 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2270 sy += getFontHeight(font_nr) / 2;
2272 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2273 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2274 TRUE, FALSE, FALSE);
2277 void DrawInfoScreen_TitleScreen()
2282 void HandleInfoScreen_TitleScreen(int button)
2284 HandleTitleScreen(0, 0, 0, 0, button);
2287 void DrawInfoScreen_Elements()
2289 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2291 FadeOut(REDRAW_FIELD);
2296 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2298 FadeIn(REDRAW_FIELD);
2303 void HandleInfoScreen_Elements(int button)
2305 static unsigned int info_delay = 0;
2306 static int num_anims;
2307 static int num_pages;
2309 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2312 if (button == MB_MENU_INITIALIZE)
2314 boolean new_element = TRUE;
2318 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2320 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2322 else if (new_element)
2325 new_element = FALSE;
2329 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2333 if (button == MB_MENU_LEAVE)
2335 PlaySound(SND_MENU_ITEM_SELECTING);
2337 info_mode = INFO_MODE_MAIN;
2342 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2344 if (button != MB_MENU_INITIALIZE)
2346 PlaySound(SND_MENU_ITEM_SELECTING);
2351 if (page >= num_pages)
2353 FadeSoundsAndMusic();
2355 info_mode = INFO_MODE_MAIN;
2356 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2362 FadeSetNextScreen();
2364 if (button != MB_MENU_INITIALIZE)
2365 FadeOut(REDRAW_FIELD);
2367 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2369 if (button != MB_MENU_INITIALIZE)
2370 FadeIn(REDRAW_FIELD);
2374 if (DelayReached(&info_delay, GameFrameDelay))
2375 if (page < num_pages)
2376 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2378 PlayMenuSoundIfLoop();
2382 void DrawInfoScreen_Music()
2384 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2386 FadeOut(REDRAW_FIELD);
2393 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2395 FadeIn(REDRAW_FIELD);
2398 void HandleInfoScreen_Music(int button)
2400 static struct MusicFileInfo *list = NULL;
2401 int ystart1 = mSY - SY + 100;
2402 int ystart2 = mSY - SY + 150;
2403 int ybottom = mSY - SY + SYSIZE - 20;
2406 if (button == MB_MENU_INITIALIZE)
2408 list = music_file_info;
2412 FadeSoundsAndMusic();
2417 DrawTextSCentered(ystart1, FONT_TEXT_1,
2418 "No music info for this level set.");
2420 DrawTextSCentered(ybottom, FONT_TEXT_4,
2421 "Press any key or button for info menu");
2427 if (button == MB_MENU_LEAVE)
2429 PlaySound(SND_MENU_ITEM_SELECTING);
2431 FadeSoundsAndMusic();
2433 info_mode = INFO_MODE_MAIN;
2438 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2442 if (button != MB_MENU_INITIALIZE)
2444 PlaySound(SND_MENU_ITEM_SELECTING);
2452 FadeSoundsAndMusic();
2454 info_mode = INFO_MODE_MAIN;
2455 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2460 FadeSoundsAndMusic();
2462 if (list != music_file_info)
2463 FadeSetNextScreen();
2465 if (button != MB_MENU_INITIALIZE)
2466 FadeOut(REDRAW_FIELD);
2473 int sound = list->music;
2475 if (sound_info[sound].loop)
2476 PlaySoundLoop(sound);
2480 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2484 PlayMusic(list->music);
2486 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2489 if (!strEqual(list->title, UNKNOWN_NAME))
2491 if (!strEqual(list->title_header, UNKNOWN_NAME))
2492 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2494 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2497 if (!strEqual(list->artist, UNKNOWN_NAME))
2499 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2500 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2502 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2504 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2507 if (!strEqual(list->album, UNKNOWN_NAME))
2509 if (!strEqual(list->album_header, UNKNOWN_NAME))
2510 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2512 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2514 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2517 if (!strEqual(list->year, UNKNOWN_NAME))
2519 if (!strEqual(list->year_header, UNKNOWN_NAME))
2520 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2522 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2524 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2527 DrawTextSCentered(ybottom, FONT_TEXT_4,
2528 "Press any key or button for next page");
2530 if (button != MB_MENU_INITIALIZE)
2531 FadeIn(REDRAW_FIELD);
2534 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2535 PlaySoundLoop(list->music);
2538 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2540 int ystart1 = mSY - SY + 100;
2541 int ystart2 = mSY - SY + 150;
2542 int ybottom = mSY - SY + SYSIZE - 20;
2548 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2552 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2553 "Special thanks to");
2554 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2556 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2558 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2559 "\"Boulder Dash\"");
2560 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2562 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2564 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2566 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2567 "First Star Software");
2569 else if (screen_nr == 1)
2571 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2572 "Special thanks to");
2573 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2574 "Klaus Heinz & Volker Wertich");
2575 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2577 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2578 "\"Emerald Mine\"");
2579 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2581 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2583 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2585 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2588 else if (screen_nr == 2)
2590 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2591 "Special thanks to");
2592 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2593 "Michael Stopp & Philip Jespersen");
2594 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2596 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2598 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2600 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2602 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2604 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2605 "Digital Integration");
2607 else if (screen_nr == 3)
2609 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2610 "Special thanks to");
2611 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2612 "Hiroyuki Imabayashi");
2613 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2615 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2617 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2619 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2621 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2623 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2626 else if (screen_nr == 4)
2628 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2629 "Special thanks to");
2630 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2632 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2634 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2635 "J\xfcrgen Bonhagen");
2636 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2637 "for the continuous creation");
2638 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2639 "of outstanding level sets");
2641 else if (screen_nr == 5)
2643 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2645 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2647 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2648 "for ideas and inspiration by");
2649 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2652 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2654 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2656 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2657 "for ideas and inspiration by");
2658 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2661 else if (screen_nr == 6)
2663 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2665 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2668 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2669 "for the code base used for the");
2670 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2671 "native Emerald Mine engine");
2673 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2674 "for the new Emerald Mine engine");
2677 else if (screen_nr == 7)
2679 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2681 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2683 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2684 "for the initial DOS port");
2686 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2688 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2690 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2691 "for some additional toons");
2693 else if (screen_nr == 8)
2695 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2696 "And not to forget:");
2697 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2699 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2700 "All those who contributed");
2701 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2702 "levels to this game");
2703 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2707 DrawTextSCentered(ybottom, FONT_TEXT_4,
2708 "Press any key or button for next page");
2711 void DrawInfoScreen_Credits()
2713 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2715 FadeSoundsAndMusic();
2717 FadeOut(REDRAW_FIELD);
2719 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2721 FadeIn(REDRAW_FIELD);
2724 void HandleInfoScreen_Credits(int button)
2726 static int screen_nr = 0;
2727 int num_screens = 9;
2729 if (button == MB_MENU_INITIALIZE)
2733 // DrawInfoScreen_CreditsScreen(screen_nr);
2736 if (button == MB_MENU_LEAVE)
2738 PlaySound(SND_MENU_ITEM_SELECTING);
2740 info_mode = INFO_MODE_MAIN;
2745 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2747 if (button != MB_MENU_INITIALIZE)
2749 PlaySound(SND_MENU_ITEM_SELECTING);
2754 if (screen_nr >= num_screens)
2756 FadeSoundsAndMusic();
2758 info_mode = INFO_MODE_MAIN;
2759 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2765 FadeSetNextScreen();
2767 if (button != MB_MENU_INITIALIZE)
2768 FadeOut(REDRAW_FIELD);
2770 DrawInfoScreen_CreditsScreen(screen_nr);
2772 if (button != MB_MENU_INITIALIZE)
2773 FadeIn(REDRAW_FIELD);
2777 PlayMenuSoundIfLoop();
2781 void DrawInfoScreen_Program()
2783 int ystart1 = mSY - SY + 100;
2784 int ystart2 = mSY - SY + 150;
2785 int ybottom = mSY - SY + SYSIZE - 20;
2788 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2790 FadeOut(REDRAW_FIELD);
2795 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2797 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2798 "This game is Freeware!");
2799 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2800 "If you like it, send e-mail to:");
2801 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2802 PROGRAM_EMAIL_STRING);
2803 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2804 "More information and levels:");
2805 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2806 PROGRAM_WEBSITE_STRING);
2807 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2808 "If you have created new levels,");
2809 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2810 "send them to me to include them!");
2811 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2814 DrawTextSCentered(ybottom, FONT_TEXT_4,
2815 "Press any key or button for info menu");
2817 FadeIn(REDRAW_FIELD);
2820 void HandleInfoScreen_Program(int button)
2822 if (button == MB_MENU_LEAVE)
2824 PlaySound(SND_MENU_ITEM_SELECTING);
2826 info_mode = INFO_MODE_MAIN;
2831 else if (button == MB_MENU_CHOICE)
2833 PlaySound(SND_MENU_ITEM_SELECTING);
2835 FadeSoundsAndMusic();
2837 info_mode = INFO_MODE_MAIN;
2838 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2842 PlayMenuSoundIfLoop();
2846 void DrawInfoScreen_Version()
2848 int font_header = FONT_TEXT_3;
2849 int font_text = FONT_TEXT_2;
2850 int xstep = getFontWidth(font_text);
2851 int ystep = getFontHeight(font_text);
2852 int ystart1 = mSY - SY + 100;
2853 int ystart2 = mSY - SY + 150;
2854 int ybottom = mSY - SY + SYSIZE - 20;
2855 int xstart1 = mSX - SX + 2 * xstep;
2856 int xstart2 = mSX - SX + 18 * xstep;
2857 int xstart3 = mSX - SX + 28 * xstep;
2858 SDL_version sdl_version_compiled;
2859 const SDL_version *sdl_version_linked;
2860 int driver_name_len = 10;
2861 #if defined(TARGET_SDL2)
2862 SDL_version sdl_version_linked_ext;
2863 const char *driver_name = NULL;
2865 char driver_name[driver_name_len];
2868 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2870 FadeOut(REDRAW_FIELD);
2875 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2877 DrawTextF(xstart1, ystart2, font_header, "Name");
2878 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2881 DrawTextF(xstart1, ystart2, font_header, "Version");
2882 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
2885 DrawTextF(xstart1, ystart2, font_header, "Platform");
2886 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2889 DrawTextF(xstart1, ystart2, font_header, "Target");
2890 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2893 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2894 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2896 ystart2 += 3 * ystep;
2897 DrawTextF(xstart1, ystart2, font_header, "Library");
2898 DrawTextF(xstart2, ystart2, font_header, "compiled");
2899 DrawTextF(xstart3, ystart2, font_header, "linked");
2901 SDL_VERSION(&sdl_version_compiled);
2902 #if defined(TARGET_SDL2)
2903 SDL_GetVersion(&sdl_version_linked_ext);
2904 sdl_version_linked = &sdl_version_linked_ext;
2906 sdl_version_linked = SDL_Linked_Version();
2909 ystart2 += 2 * ystep;
2910 DrawTextF(xstart1, ystart2, font_text, "SDL");
2911 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2912 sdl_version_compiled.major,
2913 sdl_version_compiled.minor,
2914 sdl_version_compiled.patch);
2915 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2916 sdl_version_linked->major,
2917 sdl_version_linked->minor,
2918 sdl_version_linked->patch);
2920 SDL_IMAGE_VERSION(&sdl_version_compiled);
2921 sdl_version_linked = IMG_Linked_Version();
2924 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2925 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2926 sdl_version_compiled.major,
2927 sdl_version_compiled.minor,
2928 sdl_version_compiled.patch);
2929 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2930 sdl_version_linked->major,
2931 sdl_version_linked->minor,
2932 sdl_version_linked->patch);
2934 SDL_MIXER_VERSION(&sdl_version_compiled);
2935 sdl_version_linked = Mix_Linked_Version();
2938 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2939 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2940 sdl_version_compiled.major,
2941 sdl_version_compiled.minor,
2942 sdl_version_compiled.patch);
2943 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2944 sdl_version_linked->major,
2945 sdl_version_linked->minor,
2946 sdl_version_linked->patch);
2948 SDL_NET_VERSION(&sdl_version_compiled);
2949 sdl_version_linked = SDLNet_Linked_Version();
2952 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2953 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2954 sdl_version_compiled.major,
2955 sdl_version_compiled.minor,
2956 sdl_version_compiled.patch);
2957 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2958 sdl_version_linked->major,
2959 sdl_version_linked->minor,
2960 sdl_version_linked->patch);
2962 ystart2 += 3 * ystep;
2963 DrawTextF(xstart1, ystart2, font_header, "Driver");
2964 DrawTextF(xstart2, ystart2, font_header, "Requested");
2965 DrawTextF(xstart3, ystart2, font_header, "Used");
2967 #if defined(TARGET_SDL2)
2968 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
2970 SDL_VideoDriverName(driver_name, driver_name_len);
2973 ystart2 += 2 * ystep;
2974 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2975 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2976 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2978 #if defined(TARGET_SDL2)
2979 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
2981 SDL_AudioDriverName(driver_name, driver_name_len);
2985 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2986 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2987 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2989 DrawTextSCentered(ybottom, FONT_TEXT_4,
2990 "Press any key or button for info menu");
2992 FadeIn(REDRAW_FIELD);
2995 void HandleInfoScreen_Version(int button)
2997 if (button == MB_MENU_LEAVE)
2999 PlaySound(SND_MENU_ITEM_SELECTING);
3001 info_mode = INFO_MODE_MAIN;
3006 else if (button == MB_MENU_CHOICE)
3008 PlaySound(SND_MENU_ITEM_SELECTING);
3010 FadeSoundsAndMusic();
3012 info_mode = INFO_MODE_MAIN;
3013 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3017 PlayMenuSoundIfLoop();
3021 void DrawInfoScreen_LevelSet()
3023 struct TitleMessageInfo *tmi = &readme;
3024 char *filename = getLevelSetInfoFilename();
3025 char *title = "Level Set Information:";
3026 int ystart1 = mSY - SY + 100;
3027 int ybottom = mSY - SY + SYSIZE - 20;
3029 if (filename == NULL)
3031 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3036 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3038 FadeOut(REDRAW_FIELD);
3043 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3045 /* if x position set to "-1", automatically determine by playfield width */
3047 tmi->x = SXSIZE / 2;
3049 /* if y position set to "-1", use static default value */
3053 /* if width set to "-1", automatically determine by playfield width */
3054 if (tmi->width == -1)
3055 tmi->width = SXSIZE - 2 * TILEX;
3057 /* if height set to "-1", automatically determine by playfield height */
3058 if (tmi->height == -1)
3059 tmi->height = SYSIZE - 20 - tmi->y - 10;
3061 /* if chars set to "-1", automatically determine by text and font width */
3062 if (tmi->chars == -1)
3063 tmi->chars = tmi->width / getFontWidth(tmi->font);
3065 tmi->width = tmi->chars * getFontWidth(tmi->font);
3067 /* if lines set to "-1", automatically determine by text and font height */
3068 if (tmi->lines == -1)
3069 tmi->lines = tmi->height / getFontHeight(tmi->font);
3071 tmi->height = tmi->lines * getFontHeight(tmi->font);
3073 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3074 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3075 tmi->autowrap, tmi->centered, tmi->parse_comments);
3077 DrawTextSCentered(ybottom, FONT_TEXT_4,
3078 "Press any key or button for info menu");
3080 FadeIn(REDRAW_FIELD);
3083 void HandleInfoScreen_LevelSet(int button)
3085 if (button == MB_MENU_LEAVE)
3087 PlaySound(SND_MENU_ITEM_SELECTING);
3089 info_mode = INFO_MODE_MAIN;
3094 else if (button == MB_MENU_CHOICE)
3096 PlaySound(SND_MENU_ITEM_SELECTING);
3098 FadeSoundsAndMusic();
3100 info_mode = INFO_MODE_MAIN;
3101 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3105 PlayMenuSoundIfLoop();
3109 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3111 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3113 if (info_mode == INFO_MODE_TITLE)
3114 DrawInfoScreen_TitleScreen();
3115 else if (info_mode == INFO_MODE_ELEMENTS)
3116 DrawInfoScreen_Elements();
3117 else if (info_mode == INFO_MODE_MUSIC)
3118 DrawInfoScreen_Music();
3119 else if (info_mode == INFO_MODE_CREDITS)
3120 DrawInfoScreen_Credits();
3121 else if (info_mode == INFO_MODE_PROGRAM)
3122 DrawInfoScreen_Program();
3123 else if (info_mode == INFO_MODE_VERSION)
3124 DrawInfoScreen_Version();
3125 else if (info_mode == INFO_MODE_LEVELSET)
3126 DrawInfoScreen_LevelSet();
3128 DrawInfoScreen_Main(fade_mask, do_fading);
3130 if (info_mode != INFO_MODE_MAIN &&
3131 info_mode != INFO_MODE_TITLE &&
3132 info_mode != INFO_MODE_MUSIC)
3139 void DrawAndFadeInInfoScreen(int fade_mask)
3141 DrawInfoScreenExt(fade_mask, TRUE);
3144 void DrawInfoScreen()
3146 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3149 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3151 if (info_mode == INFO_MODE_TITLE)
3152 HandleInfoScreen_TitleScreen(button);
3153 else if (info_mode == INFO_MODE_ELEMENTS)
3154 HandleInfoScreen_Elements(button);
3155 else if (info_mode == INFO_MODE_MUSIC)
3156 HandleInfoScreen_Music(button);
3157 else if (info_mode == INFO_MODE_CREDITS)
3158 HandleInfoScreen_Credits(button);
3159 else if (info_mode == INFO_MODE_PROGRAM)
3160 HandleInfoScreen_Program(button);
3161 else if (info_mode == INFO_MODE_VERSION)
3162 HandleInfoScreen_Version(button);
3163 else if (info_mode == INFO_MODE_LEVELSET)
3164 HandleInfoScreen_LevelSet(button);
3166 HandleInfoScreen_Main(mx, my, dx, dy, button);
3170 /* ========================================================================= */
3171 /* type name functions */
3172 /* ========================================================================= */
3174 void HandleTypeName(int newxpos, Key key)
3176 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3177 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3178 struct TextPosInfo *pos = mci->pos_input;
3179 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3180 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3181 static int xpos = 0;
3182 int font_nr = pos->font;
3183 int font_active_nr = FONT_ACTIVE(font_nr);
3184 int font_width = getFontWidth(font_active_nr);
3185 char key_char = getValidConfigValueChar(getCharFromKey(key));
3186 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3187 boolean is_active = TRUE;
3189 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3193 strcpy(last_player_name, setup.player_name);
3197 #if defined(TARGET_SDL2)
3198 SDL_StartTextInput();
3201 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3203 setup.player_name[xpos] = key_char;
3204 setup.player_name[xpos + 1] = 0;
3208 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3212 setup.player_name[xpos] = 0;
3214 else if (key == KSYM_Return && xpos > 0)
3220 game_status = GAME_MODE_MAIN;
3222 else if (key == KSYM_Escape)
3224 strcpy(setup.player_name, last_player_name);
3228 game_status = GAME_MODE_MAIN;
3233 pos->width = (strlen(setup.player_name) + 1) * font_width;
3234 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3236 DrawText(startx, starty, setup.player_name, font_active_nr);
3237 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3241 pos->width = strlen(setup.player_name) * font_width;
3242 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3244 DrawText(startx, starty, setup.player_name, font_nr);
3246 #if defined(TARGET_SDL2)
3247 SDL_StopTextInput();
3253 /* ========================================================================= */
3254 /* tree menu functions */
3255 /* ========================================================================= */
3257 static void DrawChooseTree(TreeInfo **ti_ptr)
3259 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3263 FreeScreenGadgets();
3264 CreateScreenGadgets();
3266 CloseDoor(DOOR_CLOSE_2);
3272 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3273 MapScreenTreeGadgets(*ti_ptr);
3280 static void AdjustScrollbar(int id, int items_max, int items_visible,
3283 struct GadgetInfo *gi = screen_gadget[id];
3285 if (item_position > items_max - items_visible)
3286 item_position = items_max - items_visible;
3288 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3289 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3290 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3293 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3295 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3299 static void clearMenuListArea()
3301 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3303 /* correct scrollbar position if placed outside menu (playfield) area */
3304 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
3305 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
3307 /* clear menu list area, but not title or scrollbar */
3308 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3309 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
3312 static void drawChooseTreeList(int first_entry, int num_page_entries,
3316 char *title_string = NULL;
3317 int yoffset_sets = MENU_TITLE1_YPOS;
3318 int yoffset_setup = 16;
3319 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3320 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3321 int last_game_status = game_status; /* save current game status */
3323 title_string = ti->infotext;
3325 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3327 clearMenuListArea();
3329 for (i = 0; i < num_page_entries; i++)
3331 TreeInfo *node, *node_first;
3332 int entry_pos = first_entry + i;
3333 int xpos = MENU_SCREEN_START_XPOS;
3334 int ypos = MENU_SCREEN_START_YPOS + i;
3335 int startx = mSX + xpos * 32;
3336 int starty = mSY + ypos * 32;
3337 int font_nr = FONT_TEXT_1;
3338 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3339 int startx_text = startx + font_xoffset;
3340 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3341 int text_size = startx_scrollbar - startx_text;
3342 int max_buffer_len = text_size / getFontWidth(font_nr);
3343 char buffer[max_buffer_len + 1];
3345 node_first = getTreeInfoFirstGroupEntry(ti);
3346 node = getTreeInfoFromPos(node_first, entry_pos);
3348 strncpy(buffer, node->name, max_buffer_len);
3349 buffer[max_buffer_len] = '\0';
3351 DrawText(startx, starty, buffer, font_nr + node->color);
3353 if (node->parent_link)
3354 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3355 else if (node->level_group)
3356 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3358 initCursor(i, IMG_MENU_BUTTON);
3361 game_status = last_game_status; /* restore current game status */
3363 redraw_mask |= REDRAW_FIELD;
3366 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3368 TreeInfo *node, *node_first;
3369 int x, last_redraw_mask = redraw_mask;
3370 int ypos = MENU_TITLE2_YPOS;
3371 int font_nr = FONT_TITLE_2;
3373 if (ti->type == TREE_TYPE_LEVEL_NR)
3374 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3376 if (ti->type != TREE_TYPE_LEVEL_DIR)
3379 node_first = getTreeInfoFirstGroupEntry(ti);
3380 node = getTreeInfoFromPos(node_first, entry_pos);
3382 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3384 if (node->parent_link)
3385 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3386 node->node_parent->name);
3387 else if (node->level_group)
3388 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3390 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3391 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3392 node->levels, (node->levels > 1 ? "levels" : "level"),
3395 /* let BackToFront() redraw only what is needed */
3396 redraw_mask = last_redraw_mask | REDRAW_TILES;
3397 for (x = 0; x < SCR_FIELDX; x++)
3398 MarkTileDirty(x, 1);
3401 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3404 TreeInfo *ti = *ti_ptr;
3406 int y = ti->cl_cursor;
3407 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3408 int num_entries = numTreeInfoInGroup(ti);
3409 int num_page_entries;
3410 int last_game_status = game_status; /* save current game status */
3411 boolean position_set_by_scrollbar = (dx == 999);
3413 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3414 num_page_entries = num_entries;
3416 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3418 game_status = last_game_status; /* restore current game status */
3420 if (button == MB_MENU_INITIALIZE)
3422 int num_entries = numTreeInfoInGroup(ti);
3423 int entry_pos = posTreeInfo(ti);
3425 if (ti->cl_first == -1)
3427 /* only on initialization */
3428 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3429 ti->cl_cursor = entry_pos - ti->cl_first;
3431 else if (ti->cl_cursor >= num_page_entries ||
3432 (num_entries > num_page_entries &&
3433 num_entries - ti->cl_first < num_page_entries))
3435 /* only after change of list size (by custom graphic configuration) */
3436 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3437 ti->cl_cursor = entry_pos - ti->cl_first;
3440 if (position_set_by_scrollbar)
3443 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3446 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3447 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3448 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3452 else if (button == MB_MENU_LEAVE)
3456 PlaySound(SND_MENU_ITEM_SELECTING);
3458 if (ti->node_parent)
3460 *ti_ptr = ti->node_parent;
3461 DrawChooseTree(ti_ptr);
3463 else if (game_status == GAME_MODE_SETUP)
3465 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3466 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3468 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3469 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3470 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3471 execSetupGraphics();
3472 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3473 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3474 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3476 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3477 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3478 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3485 if (game_status == GAME_MODE_LEVELNR)
3487 int new_level_nr = atoi(level_number_current->identifier);
3489 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3492 game_status = GAME_MODE_MAIN;
3494 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3500 if (mx || my) /* mouse input */
3502 int last_game_status = game_status; /* save current game status */
3504 x = (mx - mSX) / 32;
3505 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3507 game_status = last_game_status; /* restore current game status */
3509 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3511 /* move cursor instead of scrolling when already at start/end of list */
3512 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3514 else if (dy == +1 * SCROLL_LINE &&
3515 ti->cl_first + num_page_entries == num_entries)
3518 /* handle scrolling screen one line or page */
3519 if (ti->cl_cursor + dy < 0 ||
3520 ti->cl_cursor + dy > num_page_entries - 1)
3522 boolean redraw = FALSE;
3524 if (ABS(dy) == SCROLL_PAGE)
3525 step = num_page_entries - 1;
3527 if (dy < 0 && ti->cl_first > 0)
3529 /* scroll page/line up */
3531 ti->cl_first -= step;
3532 if (ti->cl_first < 0)
3537 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3539 /* scroll page/line down */
3541 ti->cl_first += step;
3542 if (ti->cl_first + num_page_entries > num_entries)
3543 ti->cl_first = MAX(0, num_entries - num_page_entries);
3550 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3551 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3552 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3554 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3562 /* handle moving cursor one line */
3563 y = ti->cl_cursor + dy;
3568 TreeInfo *node_first, *node_cursor;
3569 int entry_pos = ti->cl_first + y;
3571 node_first = getTreeInfoFirstGroupEntry(ti);
3572 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3574 if (node_cursor->node_group)
3578 PlaySound(SND_MENU_ITEM_SELECTING);
3580 node_cursor->cl_first = ti->cl_first;
3581 node_cursor->cl_cursor = ti->cl_cursor;
3582 *ti_ptr = node_cursor->node_group;
3583 DrawChooseTree(ti_ptr);
3588 else if (dx == -1 && ti->node_parent)
3592 PlaySound(SND_MENU_ITEM_SELECTING);
3594 *ti_ptr = ti->node_parent;
3595 DrawChooseTree(ti_ptr);
3600 if (!anyScrollbarGadgetActive() &&
3601 IN_VIS_MENU(x, y) &&
3602 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3603 y >= 0 && y < num_page_entries)
3607 if (y != ti->cl_cursor)
3609 PlaySound(SND_MENU_ITEM_ACTIVATING);
3611 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3612 drawChooseTreeCursor(y, TRUE);
3613 drawChooseTreeInfo(ti->cl_first + y, ti);
3620 TreeInfo *node_first, *node_cursor;
3621 int entry_pos = ti->cl_first + y;
3623 PlaySound(SND_MENU_ITEM_SELECTING);
3625 node_first = getTreeInfoFirstGroupEntry(ti);
3626 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3628 if (node_cursor->node_group)
3632 node_cursor->cl_first = ti->cl_first;
3633 node_cursor->cl_cursor = ti->cl_cursor;
3634 *ti_ptr = node_cursor->node_group;
3635 DrawChooseTree(ti_ptr);
3637 else if (node_cursor->parent_link)
3641 *ti_ptr = node_cursor->node_parent;
3642 DrawChooseTree(ti_ptr);
3648 node_cursor->cl_first = ti->cl_first;
3649 node_cursor->cl_cursor = ti->cl_cursor;
3650 *ti_ptr = node_cursor;
3652 if (ti->type == TREE_TYPE_LEVEL_DIR)
3654 LoadLevelSetup_SeriesInfo();
3656 SaveLevelSetup_LastSeries();
3657 SaveLevelSetup_SeriesInfo();
3661 if (game_status == GAME_MODE_SETUP)
3663 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3664 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3666 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3667 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3668 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3669 execSetupGraphics();
3670 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3671 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3672 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3674 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3675 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3676 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3683 if (game_status == GAME_MODE_LEVELNR)
3685 int new_level_nr = atoi(level_number_current->identifier);
3687 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3690 game_status = GAME_MODE_MAIN;
3699 void DrawChooseLevelSet()
3701 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3703 DrawChooseTree(&leveldir_current);
3709 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3711 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3714 void DrawChooseLevelNr()
3718 if (level_number != NULL)
3720 freeTreeInfo(level_number);
3722 level_number = NULL;
3725 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3727 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3728 char identifier[32], name[32];
3731 /* temporarily load level info to get level name */
3732 LoadLevelInfoOnly(i);
3734 ti->node_top = &level_number;
3735 ti->sort_priority = 10000 + value;
3736 ti->color = (level.no_valid_file ? FC_BLUE :
3737 LevelStats_getSolved(i) ? FC_GREEN :
3738 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3740 sprintf(identifier, "%d", value);
3741 sprintf(name, "%03d: %s", value,
3742 (level.no_valid_file ? "(no file)" : level.name));
3744 setString(&ti->identifier, identifier);
3745 setString(&ti->name, name);
3746 setString(&ti->name_sorting, name);
3748 pushTreeInfo(&level_number, ti);
3751 /* sort level number values to start with lowest level number */
3752 sortTreeInfo(&level_number);
3754 /* set current level number to current level number */
3755 level_number_current =
3756 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3758 /* if that also fails, set current level number to first available level */
3759 if (level_number_current == NULL)
3760 level_number_current = level_number;
3762 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3764 DrawChooseTree(&level_number_current);
3770 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3772 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3775 void DrawHallOfFame(int highlight_position)
3777 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3780 FadeSoundsAndMusic();
3782 /* (this is needed when called from GameEnd() after winning a game) */
3783 KeyboardAutoRepeatOn();
3786 /* (this is needed when called from GameEnd() after winning a game) */
3787 SetDrawDeactivationMask(REDRAW_NONE);
3788 SetDrawBackgroundMask(REDRAW_FIELD);
3790 CloseDoor(DOOR_CLOSE_2);
3792 if (highlight_position < 0)
3793 LoadScore(level_nr);
3795 FadeSetEnterScreen();
3804 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3809 static void drawHallOfFameList(int first_entry, int highlight_position)
3813 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3816 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3817 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3818 "HighScores of Level %d", level_nr);
3820 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3822 int entry = first_entry + i;
3823 boolean active = (entry == highlight_position);
3824 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3825 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3826 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3827 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3828 int dx1 = 3 * getFontWidth(font_nr1);
3829 int dx2 = dx1 + getFontWidth(font_nr1);
3830 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
3831 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
3832 int sy = mSY + 64 + i * 32;
3834 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3835 DrawText(mSX + dx1, sy, ".", font_nr1);
3837 for (j = 0; j < num_dots; j++)
3838 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
3840 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3841 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3843 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3846 redraw_mask |= REDRAW_FIELD;
3849 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3851 static int first_entry = 0;
3852 static int highlight_position = 0;
3853 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3855 if (button == MB_MENU_INITIALIZE)
3858 highlight_position = mx;
3859 drawHallOfFameList(first_entry, highlight_position);
3864 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3865 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3869 if (first_entry > 0)
3871 first_entry -= step;
3872 if (first_entry < 0)
3875 drawHallOfFameList(first_entry, highlight_position);
3880 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3882 first_entry += step;
3883 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3884 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3886 drawHallOfFameList(first_entry, highlight_position);
3889 else if (button == MB_MENU_LEAVE)
3891 PlaySound(SND_MENU_ITEM_SELECTING);
3893 FadeSound(SND_BACKGROUND_SCORES);
3895 game_status = GAME_MODE_MAIN;
3899 else if (button == MB_MENU_CHOICE)
3901 PlaySound(SND_MENU_ITEM_SELECTING);
3903 FadeSound(SND_BACKGROUND_SCORES);
3905 game_status = GAME_MODE_MAIN;
3907 DrawAndFadeInMainMenu(REDRAW_FIELD);
3910 if (game_status == GAME_MODE_SCORES)
3911 PlayMenuSoundIfLoop();
3915 /* ========================================================================= */
3916 /* setup screen functions */
3917 /* ========================================================================= */
3919 static struct TokenInfo *setup_info;
3920 static int num_setup_info; /* number of setup entries shown on screen */
3921 static int max_setup_info; /* total number of setup entries in list */
3923 static char *screen_mode_text;
3924 static char *window_size_text;
3925 static char *scaling_type_text;
3926 static char *scroll_delay_text;
3927 static char *game_speed_text;
3928 static char *graphics_set_name;
3929 static char *sounds_set_name;
3930 static char *music_set_name;
3931 static char *volume_simple_text;
3932 static char *volume_loops_text;
3933 static char *volume_music_text;
3934 static char *touch_controls_text;
3935 static char *move_distance_text;
3936 static char *drop_distance_text;
3938 static void execSetupMain()
3940 setup_mode = SETUP_MODE_MAIN;
3945 static void execSetupGame_setGameSpeeds()
3947 if (game_speeds == NULL)
3951 for (i = 0; game_speeds_list[i].value != -1; i++)
3953 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3954 char identifier[32], name[32];
3955 int value = game_speeds_list[i].value;
3956 char *text = game_speeds_list[i].text;
3958 ti->node_top = &game_speeds;
3959 ti->sort_priority = 10000 - value;
3961 sprintf(identifier, "%d", value);
3962 sprintf(name, "%s", text);
3964 setString(&ti->identifier, identifier);
3965 setString(&ti->name, name);
3966 setString(&ti->name_sorting, name);
3967 setString(&ti->infotext, "Game Speed");
3969 pushTreeInfo(&game_speeds, ti);
3972 /* sort game speed values to start with slowest game speed */
3973 sortTreeInfo(&game_speeds);
3975 /* set current game speed to configured game speed value */
3976 game_speed_current =
3977 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3979 /* if that fails, set current game speed to reliable default value */
3980 if (game_speed_current == NULL)
3981 game_speed_current =
3982 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3984 /* if that also fails, set current game speed to first available speed */
3985 if (game_speed_current == NULL)
3986 game_speed_current = game_speeds;
3989 setup.game_frame_delay = atoi(game_speed_current->identifier);
3991 /* needed for displaying game speed text instead of identifier */
3992 game_speed_text = game_speed_current->name;
3995 static void execSetupGame_setScrollDelays()
3997 if (scroll_delays == NULL)
4001 for (i = 0; scroll_delays_list[i].value != -1; i++)
4003 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4004 char identifier[32], name[32];
4005 int value = scroll_delays_list[i].value;
4006 char *text = scroll_delays_list[i].text;
4008 ti->node_top = &scroll_delays;
4009 ti->sort_priority = value;
4011 sprintf(identifier, "%d", value);
4012 sprintf(name, "%s", text);
4014 setString(&ti->identifier, identifier);
4015 setString(&ti->name, name);
4016 setString(&ti->name_sorting, name);
4017 setString(&ti->infotext, "Scaling Type");
4019 pushTreeInfo(&scroll_delays, ti);
4022 /* sort scaling type values to start with lowest scaling type value */
4023 sortTreeInfo(&scroll_delays);
4025 /* set current scaling type value to configured scaling type value */
4026 scroll_delay_current =
4027 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4029 /* if that fails, set current scaling type to reliable default value */
4030 if (scroll_delay_current == NULL)
4031 scroll_delay_current =
4032 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4034 /* if that also fails, set current scaling type to first available value */
4035 if (scroll_delay_current == NULL)
4036 scroll_delay_current = scroll_delays;
4039 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4041 /* needed for displaying scaling type text instead of identifier */
4042 scroll_delay_text = scroll_delay_current->name;
4045 static void execSetupGame()
4047 execSetupGame_setGameSpeeds();
4048 execSetupGame_setScrollDelays();
4050 setup_mode = SETUP_MODE_GAME;
4055 static void execSetupChooseGameSpeed()
4057 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4062 static void execSetupChooseScrollDelay()
4064 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4069 static void execSetupEditor()
4071 setup_mode = SETUP_MODE_EDITOR;
4076 static void execSetupGraphics_setWindowSizes(boolean update_list)
4078 if (window_sizes != NULL && update_list)
4080 freeTreeInfo(window_sizes);
4082 window_sizes = NULL;
4085 if (window_sizes == NULL)
4087 boolean current_window_size_found = FALSE;
4090 for (i = 0; window_sizes_list[i].value != -1; i++)
4092 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4093 char identifier[32], name[32];
4094 int value = window_sizes_list[i].value;
4095 char *text = window_sizes_list[i].text;
4097 ti->node_top = &window_sizes;
4098 ti->sort_priority = value;
4100 sprintf(identifier, "%d", value);
4101 sprintf(name, "%s", text);
4103 setString(&ti->identifier, identifier);
4104 setString(&ti->name, name);
4105 setString(&ti->name_sorting, name);
4106 setString(&ti->infotext, "Window Scaling");
4108 pushTreeInfo(&window_sizes, ti);
4110 if (value == setup.window_scaling_percent)
4111 current_window_size_found = TRUE;
4114 if (!current_window_size_found)
4116 // add entry for non-preset window scaling value
4118 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4119 char identifier[32], name[32];
4120 int value = setup.window_scaling_percent;
4122 ti->node_top = &window_sizes;
4123 ti->sort_priority = value;
4125 sprintf(identifier, "%d", value);
4126 sprintf(name, "%d %% (Current)", value);
4128 setString(&ti->identifier, identifier);
4129 setString(&ti->name, name);
4130 setString(&ti->name_sorting, name);
4131 setString(&ti->infotext, "Window Scaling");
4133 pushTreeInfo(&window_sizes, ti);
4136 /* sort window size values to start with lowest window size value */
4137 sortTreeInfo(&window_sizes);
4139 /* set current window size value to configured window size value */
4140 window_size_current =
4141 getTreeInfoFromIdentifier(window_sizes,
4142 i_to_a(setup.window_scaling_percent));
4144 /* if that fails, set current window size to reliable default value */
4145 if (window_size_current == NULL)
4146 window_size_current =
4147 getTreeInfoFromIdentifier(window_sizes,
4148 i_to_a(STD_WINDOW_SCALING_PERCENT));
4150 /* if that also fails, set current window size to first available value */
4151 if (window_size_current == NULL)
4152 window_size_current = window_sizes;
4155 setup.window_scaling_percent = atoi(window_size_current->identifier);
4157 /* needed for displaying window size text instead of identifier */
4158 window_size_text = window_size_current->name;
4161 static void execSetupGraphics_setScalingTypes()
4163 if (scaling_types == NULL)
4167 for (i = 0; scaling_types_list[i].value != NULL; i++)
4169 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4170 char identifier[32], name[32];
4171 char *value = scaling_types_list[i].value;
4172 char *text = scaling_types_list[i].text;
4174 ti->node_top = &scaling_types;
4175 ti->sort_priority = i;
4177 sprintf(identifier, "%s", value);
4178 sprintf(name, "%s", text);
4180 setString(&ti->identifier, identifier);
4181 setString(&ti->name, name);
4182 setString(&ti->name_sorting, name);
4183 setString(&ti->infotext, "Anti-Aliasing");
4185 pushTreeInfo(&scaling_types, ti);
4188 /* sort scaling type values to start with lowest scaling type value */
4189 sortTreeInfo(&scaling_types);
4191 /* set current scaling type value to configured scaling type value */
4192 scaling_type_current =
4193 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4195 /* if that fails, set current scaling type to reliable default value */
4196 if (scaling_type_current == NULL)
4197 scaling_type_current =
4198 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4200 /* if that also fails, set current scaling type to first available value */
4201 if (scaling_type_current == NULL)
4202 scaling_type_current = scaling_types;
4205 setup.window_scaling_quality = scaling_type_current->identifier;
4207 /* needed for displaying scaling type text instead of identifier */
4208 scaling_type_text = scaling_type_current->name;
4211 static void execSetupGraphics_setScreenModes()
4213 // if (screen_modes == NULL && video.fullscreen_available)
4214 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4218 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4220 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4221 char identifier[32], name[32];
4222 int x = video.fullscreen_modes[i].width;
4223 int y = video.fullscreen_modes[i].height;
4226 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4228 ti->node_top = &screen_modes;
4229 ti->sort_priority = x * 10000 + y;
4231 sprintf(identifier, "%dx%d", x, y);
4232 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4234 setString(&ti->identifier, identifier);
4235 setString(&ti->name, name);
4236 setString(&ti->name_sorting, name);
4237 setString(&ti->infotext, "Fullscreen Mode");
4239 pushTreeInfo(&screen_modes, ti);
4242 /* sort fullscreen modes to start with lowest available screen resolution */
4243 sortTreeInfo(&screen_modes);
4245 /* set current screen mode for fullscreen mode to configured setup value */
4246 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4247 setup.fullscreen_mode);
4249 /* if that fails, set current screen mode to reliable default value */
4250 if (screen_mode_current == NULL)
4251 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4252 DEFAULT_FULLSCREEN_MODE);
4254 /* if that also fails, set current screen mode to first available mode */
4255 if (screen_mode_current == NULL)
4256 screen_mode_current = screen_modes;
4258 if (screen_mode_current == NULL)
4259 video.fullscreen_available = FALSE;
4262 // if (video.fullscreen_available)
4263 if (screen_mode_current != NULL)
4265 setup.fullscreen_mode = screen_mode_current->identifier;
4267 /* needed for displaying screen mode name instead of identifier */
4268 screen_mode_text = screen_mode_current->name;
4272 static void execSetupGraphics()
4274 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4276 // update "setup.window_scaling_percent" from list selection
4277 execSetupGraphics_setWindowSizes(FALSE);
4281 // update list selection from "setup.window_scaling_percent"
4282 execSetupGraphics_setWindowSizes(TRUE);
4285 execSetupGraphics_setScalingTypes();
4286 execSetupGraphics_setScreenModes();
4288 setup_mode = SETUP_MODE_GRAPHICS;
4292 #if defined(TARGET_SDL2)
4293 // window scaling may have changed at this point
4294 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4296 // window scaling quality may have changed at this point
4297 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4298 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4302 #if !defined(PLATFORM_ANDROID)
4303 #if defined(TARGET_SDL2)
4304 static void execSetupChooseWindowSize()
4306 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4311 static void execSetupChooseScalingType()
4313 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4318 static void execSetupChooseScreenMode()
4320 if (!video.fullscreen_available)
4323 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4330 static void execSetupChooseVolumeSimple()
4332 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4337 static void execSetupChooseVolumeLoops()
4339 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4344 static void execSetupChooseVolumeMusic()
4346 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4351 static void execSetupSound()
4353 if (volumes_simple == NULL)
4355 boolean current_volume_simple_found = FALSE;
4358 for (i = 0; volumes_list[i].value != -1; i++)
4360 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4361 char identifier[32], name[32];
4362 int value = volumes_list[i].value;
4363 char *text = volumes_list[i].text;
4365 ti->node_top = &volumes_simple;
4366 ti->sort_priority = value;
4368 sprintf(identifier, "%d", value);
4369 sprintf(name, "%s", text);
4371 setString(&ti->identifier, identifier);
4372 setString(&ti->name, name);
4373 setString(&ti->name_sorting, name);
4374 setString(&ti->infotext, "Sound Volume");
4376 pushTreeInfo(&volumes_simple, ti);
4378 if (value == setup.volume_simple)
4379 current_volume_simple_found = TRUE;
4382 if (!current_volume_simple_found)
4384 // add entry for non-preset volume value
4386 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4387 char identifier[32], name[32];
4388 int value = setup.volume_simple;
4390 ti->node_top = &volumes_simple;
4391 ti->sort_priority = value;
4393 sprintf(identifier, "%d", value);
4394 sprintf(name, "%d %% (Current)", value);
4396 setString(&ti->identifier, identifier);
4397 setString(&ti->name, name);
4398 setString(&ti->name_sorting, name);
4399 setString(&ti->infotext, "Sound Volume");
4401 pushTreeInfo(&volumes_simple, ti);
4404 /* sort volume values to start with lowest volume value */
4405 sortTreeInfo(&volumes_simple);
4407 /* set current volume value to configured volume value */
4408 volume_simple_current =
4409 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4411 /* if that fails, set current volume to reliable default value */
4412 if (volume_simple_current == NULL)
4413 volume_simple_current =
4414 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4416 /* if that also fails, set current volume to first available value */
4417 if (volume_simple_current == NULL)
4418 volume_simple_current = volumes_simple;
4421 if (volumes_loops == NULL)
4423 boolean current_volume_loops_found = FALSE;
4426 for (i = 0; volumes_list[i].value != -1; i++)
4428 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4429 char identifier[32], name[32];
4430 int value = volumes_list[i].value;
4431 char *text = volumes_list[i].text;
4433 ti->node_top = &volumes_loops;
4434 ti->sort_priority = value;
4436 sprintf(identifier, "%d", value);
4437 sprintf(name, "%s", text);
4439 setString(&ti->identifier, identifier);
4440 setString(&ti->name, name);
4441 setString(&ti->name_sorting, name);
4442 setString(&ti->infotext, "Loops Volume");
4444 pushTreeInfo(&volumes_loops, ti);
4446 if (value == setup.volume_loops)
4447 current_volume_loops_found = TRUE;
4450 if (!current_volume_loops_found)
4452 // add entry for non-preset volume value
4454 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4455 char identifier[32], name[32];
4456 int value = setup.volume_loops;
4458 ti->node_top = &volumes_loops;
4459 ti->sort_priority = value;
4461 sprintf(identifier, "%d", value);
4462 sprintf(name, "%d %% (Current)", value);
4464 setString(&ti->identifier, identifier);
4465 setString(&ti->name, name);
4466 setString(&ti->name_sorting, name);
4467 setString(&ti->infotext, "Loops Volume");
4469 pushTreeInfo(&volumes_loops, ti);
4472 /* sort volume values to start with lowest volume value */
4473 sortTreeInfo(&volumes_loops);
4475 /* set current volume value to configured volume value */
4476 volume_loops_current =
4477 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4479 /* if that fails, set current volume to reliable default value */
4480 if (volume_loops_current == NULL)
4481 volume_loops_current =
4482 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4484 /* if that also fails, set current volume to first available value */
4485 if (volume_loops_current == NULL)
4486 volume_loops_current = volumes_loops;
4489 if (volumes_music == NULL)
4491 boolean current_volume_music_found = FALSE;
4494 for (i = 0; volumes_list[i].value != -1; i++)
4496 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4497 char identifier[32], name[32];
4498 int value = volumes_list[i].value;
4499 char *text = volumes_list[i].text;
4501 ti->node_top = &volumes_music;
4502 ti->sort_priority = value;
4504 sprintf(identifier, "%d", value);
4505 sprintf(name, "%s", text);
4507 setString(&ti->identifier, identifier);
4508 setString(&ti->name, name);
4509 setString(&ti->name_sorting, name);
4510 setString(&ti->infotext, "Music Volume");
4512 pushTreeInfo(&volumes_music, ti);
4514 if (value == setup.volume_music)
4515 current_volume_music_found = TRUE;
4518 if (!current_volume_music_found)
4520 // add entry for non-preset volume value
4522 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4523 char identifier[32], name[32];
4524 int value = setup.volume_music;
4526 ti->node_top = &volumes_music;
4527 ti->sort_priority = value;
4529 sprintf(identifier, "%d", value);
4530 sprintf(name, "%d %% (Current)", value);
4532 setString(&ti->identifier, identifier);
4533 setString(&ti->name, name);
4534 setString(&ti->name_sorting, name);
4535 setString(&ti->infotext, "Music Volume");
4537 pushTreeInfo(&volumes_music, ti);
4540 /* sort volume values to start with lowest volume value */
4541 sortTreeInfo(&volumes_music);
4543 /* set current volume value to configured volume value */
4544 volume_music_current =
4545 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4547 /* if that fails, set current volume to reliable default value */
4548 if (volume_music_current == NULL)
4549 volume_music_current =
4550 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4552 /* if that also fails, set current volume to first available value */
4553 if (volume_music_current == NULL)
4554 volume_music_current = volumes_music;
4557 setup.volume_simple = atoi(volume_simple_current->identifier);
4558 setup.volume_loops = atoi(volume_loops_current->identifier);
4559 setup.volume_music = atoi(volume_music_current->identifier);
4561 /* needed for displaying volume text instead of identifier */
4562 volume_simple_text = volume_simple_current->name;
4563 volume_loops_text = volume_loops_current->name;
4564 volume_music_text = volume_music_current->name;
4566 setup_mode = SETUP_MODE_SOUND;
4571 static void execSetupChooseTouchControls()
4573 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4578 static void execSetupChooseMoveDistance()
4580 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4585 static void execSetupChooseDropDistance()
4587 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4592 static void execSetupTouch()
4594 if (touch_controls == NULL)
4598 for (i = 0; touch_controls_list[i].value != NULL; i++)
4600 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4601 char identifier[32], name[32];
4602 char *value = touch_controls_list[i].value;
4603 char *text = touch_controls_list[i].text;
4605 ti->node_top = &touch_controls;
4606 ti->sort_priority = i;
4608 sprintf(identifier, "%s", value);
4609 sprintf(name, "%s", text);
4611 setString(&ti->identifier, identifier);
4612 setString(&ti->name, name);
4613 setString(&ti->name_sorting, name);
4614 setString(&ti->infotext, "Control Type");
4616 pushTreeInfo(&touch_controls, ti);
4619 /* sort touch control values to start with lowest touch control value */
4620 sortTreeInfo(&touch_controls);
4622 /* set current touch control value to configured touch control value */
4623 touch_control_current =
4624 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4626 /* if that fails, set current touch control to reliable default value */
4627 if (touch_control_current == NULL)
4628 touch_control_current =
4629 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4631 /* if that also fails, set current touch control to first available value */
4632 if (touch_control_current == NULL)
4633 touch_control_current = touch_controls;
4636 if (move_distances == NULL)
4640 for (i = 0; distances_list[i].value != -1; i++)
4642 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4643 char identifier[32], name[32];
4644 int value = distances_list[i].value;
4645 char *text = distances_list[i].text;
4647 ti->node_top = &move_distances;
4648 ti->sort_priority = value;
4650 sprintf(identifier, "%d", value);
4651 sprintf(name, "%s", text);
4653 setString(&ti->identifier, identifier);
4654 setString(&ti->name, name);
4655 setString(&ti->name_sorting, name);
4656 setString(&ti->infotext, "Move Distance");
4658 pushTreeInfo(&move_distances, ti);
4661 /* sort distance values to start with lowest distance value */
4662 sortTreeInfo(&move_distances);
4664 /* set current distance value to configured distance value */
4665 move_distance_current =
4666 getTreeInfoFromIdentifier(move_distances,
4667 i_to_a(setup.touch.move_distance));
4669 /* if that fails, set current distance to reliable default value */
4670 if (move_distance_current == NULL)
4671 move_distance_current =
4672 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4674 /* if that also fails, set current distance to first available value */
4675 if (move_distance_current == NULL)
4676 move_distance_current = move_distances;
4679 if (drop_distances == NULL)
4683 for (i = 0; distances_list[i].value != -1; i++)
4685 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4686 char identifier[32], name[32];
4687 int value = distances_list[i].value;
4688 char *text = distances_list[i].text;
4690 ti->node_top = &drop_distances;
4691 ti->sort_priority = value;
4693 sprintf(identifier, "%d", value);
4694 sprintf(name, "%s", text);
4696 setString(&ti->identifier, identifier);
4697 setString(&ti->name, name);
4698 setString(&ti->name_sorting, name);
4699 setString(&ti->infotext, "Drop Distance");
4701 pushTreeInfo(&drop_distances, ti);
4704 /* sort distance values to start with lowest distance value */
4705 sortTreeInfo(&drop_distances);
4707 /* set current distance value to configured distance value */
4708 drop_distance_current =
4709 getTreeInfoFromIdentifier(drop_distances,
4710 i_to_a(setup.touch.drop_distance));
4712 /* if that fails, set current distance to reliable default value */
4713 if (drop_distance_current == NULL)
4714 drop_distance_current =
4715 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
4717 /* if that also fails, set current distance to first available value */
4718 if (drop_distance_current == NULL)
4719 drop_distance_current = drop_distances;
4722 setup.touch.control_type = touch_control_current->identifier;
4723 setup.touch.move_distance = atoi(move_distance_current->identifier);
4724 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
4726 /* needed for displaying volume text instead of identifier */
4727 touch_controls_text = touch_control_current->name;
4728 move_distance_text = move_distance_current->name;
4729 drop_distance_text = drop_distance_current->name;
4731 setup_mode = SETUP_MODE_TOUCH;
4736 static void execSetupArtwork()
4739 printf("::: '%s', '%s', '%s'\n",
4740 artwork.gfx_current->subdir,
4741 artwork.gfx_current->fullpath,
4742 artwork.gfx_current->basepath);
4745 setup.graphics_set = artwork.gfx_current->identifier;
4746 setup.sounds_set = artwork.snd_current->identifier;
4747 setup.music_set = artwork.mus_current->identifier;
4749 /* needed if last screen (setup choice) changed graphics, sounds or music */
4750 ReloadCustomArtwork(0);
4752 /* needed for displaying artwork name instead of artwork identifier */
4753 graphics_set_name = artwork.gfx_current->name;
4754 sounds_set_name = artwork.snd_current->name;
4755 music_set_name = artwork.mus_current->name;
4757 setup_mode = SETUP_MODE_ARTWORK;
4762 static void execSetupChooseGraphics()
4764 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4769 static void execSetupChooseSounds()
4771 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4776 static void execSetupChooseMusic()
4778 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4783 #if !defined(PLATFORM_ANDROID)
4784 static void execSetupInput()
4786 setup_mode = SETUP_MODE_INPUT;
4792 static void execSetupShortcuts()
4794 setup_mode = SETUP_MODE_SHORTCUTS;
4799 static void execSetupShortcuts1()
4801 setup_mode = SETUP_MODE_SHORTCUTS_1;
4806 static void execSetupShortcuts2()
4808 setup_mode = SETUP_MODE_SHORTCUTS_2;
4813 static void execSetupShortcuts3()
4815 setup_mode = SETUP_MODE_SHORTCUTS_3;
4820 static void execSetupShortcuts4()
4822 setup_mode = SETUP_MODE_SHORTCUTS_4;
4827 static void execSetupShortcuts5()
4829 setup_mode = SETUP_MODE_SHORTCUTS_5;
4834 static void execExitSetup()
4836 game_status = GAME_MODE_MAIN;
4838 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4841 static void execSaveAndExitSetup()
4847 static struct TokenInfo setup_info_main[] =
4849 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4850 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4851 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4852 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4853 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4854 #if !defined(PLATFORM_ANDROID)
4855 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4856 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4858 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4860 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4861 { TYPE_EMPTY, NULL, "" },
4862 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4863 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4868 static struct TokenInfo setup_info_game[] =
4870 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4871 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4872 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4873 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4874 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4875 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4876 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4877 { TYPE_STRING, &game_speed_text, "" },
4879 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4880 { TYPE_STRING, &scroll_delay_text, "" },
4882 { TYPE_EMPTY, NULL, "" },
4883 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4888 static struct TokenInfo setup_info_editor[] =
4891 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4892 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4893 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4894 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4895 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4896 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4897 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4898 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4900 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4901 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4902 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4904 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4906 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4907 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4908 { TYPE_EMPTY, NULL, "" },
4910 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4911 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4912 { TYPE_EMPTY, NULL, "" },
4914 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4915 { TYPE_EMPTY, NULL, "" },
4916 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4921 static struct TokenInfo setup_info_graphics[] =
4923 #if !defined(PLATFORM_ANDROID)
4924 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4925 #if defined(TARGET_SDL2)
4926 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4927 { TYPE_STRING, &window_size_text, "" },
4928 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4929 { TYPE_STRING, &scaling_type_text, "" },
4931 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4932 { TYPE_STRING, &screen_mode_text, "" },
4936 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4937 { TYPE_STRING, &scroll_delay_text, "" },
4939 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4940 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4941 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4942 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4943 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4944 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4945 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4946 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4947 { TYPE_EMPTY, NULL, "" },
4948 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4953 static struct TokenInfo setup_info_sound[] =
4955 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4956 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4957 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4958 { TYPE_EMPTY, NULL, "" },
4959 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4960 { TYPE_STRING, &volume_simple_text, "" },
4961 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4962 { TYPE_STRING, &volume_loops_text, "" },
4963 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4964 { TYPE_STRING, &volume_music_text, "" },
4965 { TYPE_EMPTY, NULL, "" },
4966 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4971 static struct TokenInfo setup_info_artwork[] =
4973 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4974 { TYPE_STRING, &graphics_set_name, "" },
4975 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4976 { TYPE_STRING, &sounds_set_name, "" },
4977 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4978 { TYPE_STRING, &music_set_name, "" },
4979 { TYPE_EMPTY, NULL, "" },
4980 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4981 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4982 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4983 { TYPE_EMPTY, NULL, "" },
4984 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4989 static struct TokenInfo setup_info_input[] =
4991 { TYPE_SWITCH, NULL, "Player:" },
4992 { TYPE_SWITCH, NULL, "Device:" },
4993 { TYPE_ENTER_MENU, NULL, "" },
4994 { TYPE_EMPTY, NULL, "" },
4995 { TYPE_EMPTY, NULL, "" },
4996 { TYPE_EMPTY, NULL, "" },
4997 { TYPE_EMPTY, NULL, "" },
4998 { TYPE_EMPTY, NULL, "" },
4999 { TYPE_EMPTY, NULL, "" },
5000 { TYPE_EMPTY, NULL, "" },
5001 { TYPE_EMPTY, NULL, "" },
5002 { TYPE_EMPTY, NULL, "" },
5003 { TYPE_EMPTY, NULL, "" },
5004 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5009 static struct TokenInfo setup_info_touch[] =
5011 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5012 { TYPE_STRING, &touch_controls_text, "" },
5013 { TYPE_EMPTY, NULL, "" },
5014 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5015 { TYPE_STRING, &move_distance_text, "" },
5016 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5017 { TYPE_STRING, &drop_distance_text, "" },
5018 { TYPE_EMPTY, NULL, "" },
5019 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5024 static struct TokenInfo setup_info_shortcuts[] =
5026 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5027 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5028 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5029 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5030 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5031 { TYPE_EMPTY, NULL, "" },
5032 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5037 static struct TokenInfo setup_info_shortcuts_1[] =
5039 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5040 { TYPE_KEY, &setup.shortcut.save_game, "" },
5041 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5042 { TYPE_KEY, &setup.shortcut.load_game, "" },
5043 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5044 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5045 { TYPE_EMPTY, NULL, "" },
5046 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5047 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5048 { TYPE_EMPTY, NULL, "" },
5049 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5054 static struct TokenInfo setup_info_shortcuts_2[] =
5056 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5057 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5058 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5059 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5060 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5061 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5062 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5063 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5064 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5065 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5066 { TYPE_EMPTY, NULL, "" },
5067 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5072 static struct TokenInfo setup_info_shortcuts_3[] =
5074 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5075 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5076 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5077 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5078 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5079 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5080 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5081 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5082 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5083 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5084 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5085 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5086 { TYPE_EMPTY, NULL, "" },
5087 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5092 static struct TokenInfo setup_info_shortcuts_4[] =
5094 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5095 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5096 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5097 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5098 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5099 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5100 { TYPE_EMPTY, NULL, "" },
5101 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5106 static struct TokenInfo setup_info_shortcuts_5[] =
5108 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5109 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5110 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5111 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5112 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5113 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5114 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5115 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5116 { TYPE_EMPTY, NULL, "" },
5117 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5122 static Key getSetupKey()
5124 Key key = KSYM_UNDEFINED;
5125 boolean got_key_event = FALSE;
5127 while (!got_key_event)
5129 if (PendingEvent()) /* got event */
5137 case EVENT_KEYPRESS:
5139 key = GetEventKey((KeyEvent *)&event, TRUE);
5141 /* press 'Escape' or 'Enter' to keep the existing key binding */
5142 if (key == KSYM_Escape || key == KSYM_Return)
5143 key = KSYM_UNDEFINED; /* keep old value */
5145 got_key_event = TRUE;
5149 case EVENT_KEYRELEASE:
5150 key_joystick_mapping = 0;
5154 HandleOtherEvents(&event);
5162 /* don't eat all CPU time */
5169 static int getSetupTextFont(int type)
5171 if (type & (TYPE_SWITCH |
5183 static int getSetupValueFont(int type, void *value)
5185 if (type & TYPE_KEY)
5186 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5187 else if (type & TYPE_STRING)
5188 return FONT_VALUE_2;
5189 else if (type & TYPE_ECS_AGA)
5190 return FONT_VALUE_1;
5191 else if (type & TYPE_BOOLEAN_STYLE)
5192 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5193 else if (type & TYPE_YES_NO_AUTO)
5194 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5195 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5197 return FONT_VALUE_1;
5200 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5202 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5203 struct TokenInfo *si = &setup_info[si_pos];
5204 boolean font_draw_xoffset_modified = FALSE;
5205 int font_draw_xoffset_old = -1;
5206 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5207 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5208 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5209 int xpos = menu_screen_value_xpos;
5210 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5211 int startx = mSX + xpos * 32;
5212 int starty = mSY + ypos * 32;
5213 int font_nr, font_width;
5214 int type = si->type;
5215 void *value = si->value;
5216 char *value_string = getSetupValue(type, value);
5219 if (value_string == NULL)
5222 if (type & TYPE_KEY)
5224 xpos = MENU_SCREEN_START_XPOS;
5226 if (type & TYPE_QUERY)
5227 value_string = "<press key>";
5229 else if (type & TYPE_STRING)
5231 int max_value_len = (SCR_FIELDX - 2) * 2;
5233 xpos = MENU_SCREEN_START_XPOS;
5235 if (strlen(value_string) > max_value_len)
5236 value_string[max_value_len] = '\0';
5238 else if (type & TYPE_YES_NO_AUTO)
5240 xpos = menu_screen_value_xpos - 1;
5243 startx = mSX + xpos * 32;
5244 starty = mSY + ypos * 32;
5245 font_nr = getSetupValueFont(type, value);
5246 font_width = getFontWidth(font_nr);
5248 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5249 if (setup_mode != SETUP_MODE_INPUT)
5251 int max_menu_text_length_big = (menu_screen_value_xpos -
5252 MENU_SCREEN_START_XPOS);
5253 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5254 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5255 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5256 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5257 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5258 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5259 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5260 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5261 boolean correct_font_draw_xoffset = FALSE;
5263 if (xpos == MENU_SCREEN_START_XPOS &&
5264 startx + font1_xoffset < text_startx + text_font_xoffset)
5265 correct_font_draw_xoffset = TRUE;
5267 if (xpos == menu_screen_value_xpos &&
5268 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5269 correct_font_draw_xoffset = TRUE;
5271 /* check if setup value would overlap with setup text when printed */
5272 /* (this can happen for extreme/wrong values for font draw offset) */
5273 if (correct_font_draw_xoffset)
5275 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5276 font_draw_xoffset_modified = TRUE;
5278 if (type & TYPE_KEY)
5279 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5280 else if (!(type & TYPE_STRING))
5281 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5282 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5286 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5287 DrawText(startx + i * font_width, starty, " ", font_nr);
5289 DrawText(startx, starty, value_string, font_nr);
5291 if (font_draw_xoffset_modified)
5292 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5295 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5297 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5298 struct TokenInfo *si = &setup_info[si_pos];
5300 if (si->type & TYPE_BOOLEAN_STYLE)
5302 *(boolean *)si->value ^= TRUE;
5304 else if (si->type & TYPE_YES_NO_AUTO)
5308 (*(int *)si->value == AUTO ? TRUE :
5309 *(int *)si->value == TRUE ? FALSE : AUTO) :
5310 (*(int *)si->value == TRUE ? AUTO :
5311 *(int *)si->value == AUTO ? FALSE : TRUE));
5313 else if (si->type & TYPE_KEY)
5317 si->type |= TYPE_QUERY;
5318 drawSetupValue(screen_pos, setup_info_pos_raw);
5319 si->type &= ~TYPE_QUERY;
5321 key = getSetupKey();
5322 if (key != KSYM_UNDEFINED)
5323 *(Key *)si->value = key;
5326 drawSetupValue(screen_pos, setup_info_pos_raw);
5328 // fullscreen state may have changed at this point
5329 if (si->value == &setup.fullscreen)
5330 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5333 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5336 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5337 struct TokenInfo *si = &setup_info[si_pos];
5338 int xpos = MENU_SCREEN_START_XPOS;
5339 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5340 int font_nr = getSetupTextFont(si->type);
5342 if (setup_info == setup_info_input)
5343 font_nr = FONT_MENU_1;
5346 font_nr = FONT_ACTIVE(font_nr);
5348 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5350 if (si->type & ~TYPE_SKIP_ENTRY)
5351 drawCursor(screen_pos, active);
5354 static void drawSetupInfoList(struct TokenInfo *setup_info,
5355 int first_entry, int num_page_entries)
5359 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5360 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5362 if (num_page_entries > max_setup_info)
5363 num_page_entries = max_setup_info;
5365 if (first_entry + num_page_entries > max_setup_info)
5368 clearMenuListArea();
5370 for (i = 0; i < num_page_entries; i++)
5372 int setup_info_pos = first_entry + i;
5373 struct TokenInfo *si = &setup_info[setup_info_pos];
5374 void *value_ptr = si->value;
5376 /* set some entries to "unchangeable" according to other variables */
5377 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5378 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5379 (value_ptr == &setup.sound_music && !audio.music_available) ||
5380 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5381 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5382 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5383 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5384 si->type |= TYPE_GHOSTED;
5386 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5387 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5388 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5389 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5390 else if (si->type & ~TYPE_SKIP_ENTRY)
5391 initCursor(i, IMG_MENU_BUTTON);
5393 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5395 if (si->type & TYPE_VALUE)
5396 drawSetupValue(i, setup_info_pos);
5400 static void DrawSetupScreen_Generic()
5402 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5403 boolean redraw_all = FALSE;
5404 char *title_string = NULL;
5409 FreeScreenGadgets();
5410 CreateScreenGadgets();
5412 CloseDoor(DOOR_CLOSE_2);
5414 if (redraw_mask & REDRAW_ALL)
5421 if (setup_mode == SETUP_MODE_MAIN)
5423 setup_info = setup_info_main;
5424 title_string = "Setup";
5426 else if (setup_mode == SETUP_MODE_GAME)
5428 setup_info = setup_info_game;
5429 title_string = "Setup Game";
5431 else if (setup_mode == SETUP_MODE_EDITOR)
5433 setup_info = setup_info_editor;
5434 title_string = "Setup Editor";
5436 else if (setup_mode == SETUP_MODE_GRAPHICS)
5438 setup_info = setup_info_graphics;
5439 title_string = "Setup Graphics";
5441 else if (setup_mode == SETUP_MODE_SOUND)
5443 setup_info = setup_info_sound;
5444 title_string = "Setup Sound";
5446 else if (setup_mode == SETUP_MODE_ARTWORK)
5448 setup_info = setup_info_artwork;
5449 title_string = "Custom Artwork";
5451 else if (setup_mode == SETUP_MODE_TOUCH)
5453 setup_info = setup_info_touch;
5454 title_string = "Setup Touch Ctrls";
5456 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5458 setup_info = setup_info_shortcuts;
5459 title_string = "Setup Shortcuts";
5461 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5463 setup_info = setup_info_shortcuts_1;
5464 title_string = "Setup Shortcuts";
5466 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5468 setup_info = setup_info_shortcuts_2;
5469 title_string = "Setup Shortcuts";
5471 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5473 setup_info = setup_info_shortcuts_3;
5474 title_string = "Setup Shortcuts";
5476 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5478 setup_info = setup_info_shortcuts_4;
5479 title_string = "Setup Shortcuts";
5481 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5483 setup_info = setup_info_shortcuts_5;
5484 title_string = "Setup Shortcuts";
5487 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5489 // determine maximal number of setup entries that can be displayed on screen
5491 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5494 // determine maximal number of setup entries available for this setup screen
5496 for (i = 0; setup_info[i].type != 0; i++)
5499 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5501 MapScreenGadgets(max_setup_info);
5504 redraw_mask = fade_mask = REDRAW_ALL;
5511 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5513 static int choice_store[MAX_SETUP_MODES];
5514 static int first_entry_store[MAX_SETUP_MODES];
5515 int choice = choice_store[setup_mode]; /* starts with 0 */
5516 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5518 int y = choice - first_entry;
5520 boolean position_set_by_scrollbar = (dx == 999);
5521 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5522 int num_page_entries;
5524 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5526 if (button == MB_MENU_INITIALIZE)
5528 /* advance to first valid menu entry */
5529 while (choice < num_setup_info &&
5530 setup_info[choice].type & TYPE_SKIP_ENTRY)
5533 if (position_set_by_scrollbar)
5534 first_entry = first_entry_store[setup_mode] = dy;
5536 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5537 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5539 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5541 if (choice < first_entry)
5543 choice = first_entry;
5545 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5548 else if (choice > first_entry + num_page_entries - 1)
5550 choice = first_entry + num_page_entries - 1;
5552 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5556 choice_store[setup_mode] = choice;
5558 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5562 else if (button == MB_MENU_LEAVE)
5566 PlaySound(SND_MENU_ITEM_SELECTING);
5568 for (i = 0; setup_info[i].type != 0; i++)
5570 if (setup_info[i].type & TYPE_LEAVE_MENU)
5572 void (*menu_callback_function)(void) = setup_info[i].value;
5576 menu_callback_function();
5578 break; /* absolutely needed because function changes 'setup_info'! */
5585 if (mx || my) /* mouse input */
5587 x = (mx - mSX) / 32;
5588 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5590 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5592 /* move cursor instead of scrolling when already at start/end of list */
5593 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5595 else if (dy == +1 * SCROLL_LINE &&
5596 first_entry + num_page_entries == max_setup_info)
5599 /* handle scrolling screen one line or page */
5601 y + dy > num_page_entries - 1)
5603 boolean redraw = FALSE;
5605 if (ABS(dy) == SCROLL_PAGE)
5606 step = num_page_entries - 1;
5608 if (dy < 0 && first_entry > 0)
5610 /* scroll page/line up */
5612 first_entry -= step;
5613 if (first_entry < 0)
5618 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5620 /* scroll page/line down */
5622 first_entry += step;
5623 if (first_entry + num_page_entries > max_setup_info)
5624 first_entry = MAX(0, max_setup_info - num_page_entries);
5631 choice += first_entry - first_entry_store[setup_mode];
5633 if (choice < first_entry)
5635 choice = first_entry;
5637 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5640 else if (choice > first_entry + num_page_entries - 1)
5642 choice = first_entry + num_page_entries - 1;
5644 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5647 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5651 if (choice < first_entry ||
5652 choice > first_entry + num_page_entries - 1)
5653 first_entry += SIGN(dy);
5656 first_entry_store[setup_mode] = first_entry;
5657 choice_store[setup_mode] = choice;
5659 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5661 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5663 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5664 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5672 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5674 if (setup_info[choice].type & menu_navigation_type ||
5675 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5676 setup_info[choice].type & TYPE_YES_NO_AUTO)
5677 button = MB_MENU_CHOICE;
5682 /* jump to next non-empty menu entry (up or down) */
5683 while (first_entry + y > 0 &&
5684 first_entry + y < max_setup_info - 1 &&
5685 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
5688 if (!IN_VIS_MENU(x, y))
5690 choice += y - y_old;
5692 if (choice < first_entry)
5693 first_entry = choice;
5694 else if (choice > first_entry + num_page_entries - 1)
5695 first_entry = choice - num_page_entries + 1;
5697 if (first_entry >= 0 &&
5698 first_entry + num_page_entries <= max_setup_info)
5700 first_entry_store[setup_mode] = first_entry;
5702 if (choice < first_entry)
5703 choice = first_entry;
5704 else if (choice > first_entry + num_page_entries - 1)
5705 choice = first_entry + num_page_entries - 1;
5707 choice_store[setup_mode] = choice;
5709 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5711 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5713 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5714 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5721 if (!anyScrollbarGadgetActive() &&
5722 IN_VIS_MENU(x, y) &&
5723 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
5724 y >= 0 && y < num_page_entries)
5728 if (first_entry + y != choice &&
5729 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
5731 PlaySound(SND_MENU_ITEM_ACTIVATING);
5733 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
5734 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
5736 choice = choice_store[setup_mode] = first_entry + y;
5739 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
5741 PlaySound(SND_MENU_ITEM_SELECTING);
5743 /* when selecting key headline, execute function for key value change */
5744 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
5745 setup_info[first_entry + y + 1].type & TYPE_KEY)
5748 /* when selecting string value, execute function for list selection */
5749 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
5750 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
5753 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
5755 void (*menu_callback_function)(void) =
5756 setup_info[first_entry + y].value;
5758 FadeSetFromType(setup_info[first_entry + y].type);
5760 menu_callback_function();
5764 if (setup_info[first_entry + y].type & TYPE_VALUE)
5765 changeSetupValue(y, first_entry + y, dx);
5771 void DrawSetupScreen_Input()
5775 FadeOut(REDRAW_FIELD);
5779 setup_info = setup_info_input;
5781 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5783 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5784 "Joysticks deactivated on this screen");
5786 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5788 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5789 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5790 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5791 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5792 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5793 initCursor(i, IMG_MENU_BUTTON);
5795 DrawCursorAndText_Setup(i, -1, FALSE);
5798 /* create gadgets for setup input menu screen */
5799 FreeScreenGadgets();
5800 CreateScreenGadgets();
5802 /* map gadgets for setup input menu screen */
5803 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5805 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5807 FadeIn(REDRAW_FIELD);
5812 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5814 if (device_name == NULL)
5817 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5820 if (strlen(device_name) > 1)
5822 char c1 = device_name[strlen(device_name) - 1];
5823 char c2 = device_name[strlen(device_name) - 2];
5825 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5826 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5829 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5830 strlen(device_name));
5833 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5836 static struct SetupKeyboardInfo custom_key;
5843 { &custom_key.left, "Joystick Left" },
5844 { &custom_key.right, "Joystick Right" },
5845 { &custom_key.up, "Joystick Up" },
5846 { &custom_key.down, "Joystick Down" },
5847 { &custom_key.snap, "Button 1" },
5848 { &custom_key.drop, "Button 2" }
5850 static char *joystick_name[MAX_PLAYERS] =
5857 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5861 custom_key = setup.input[player_nr].key;
5863 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5864 FONT_INPUT_1_ACTIVE);
5866 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5868 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5869 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5871 if (setup.input[player_nr].use_joystick)
5873 char *device_name = setup.input[player_nr].joy.device_name;
5874 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5875 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5877 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5878 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5882 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5883 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5886 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5888 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5889 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5890 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5891 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5893 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5894 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5895 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5896 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5897 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5898 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5900 for (i = 0; i < 6; i++)
5902 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5904 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5906 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5907 (setup.input[player_nr].use_joystick ?
5909 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5913 static int input_player_nr = 0;
5915 void HandleSetupScreen_Input_Player(int step, int direction)
5917 int old_player_nr = input_player_nr;
5920 new_player_nr = old_player_nr + step * direction;
5921 if (new_player_nr < 0)
5923 if (new_player_nr > MAX_PLAYERS - 1)
5924 new_player_nr = MAX_PLAYERS - 1;
5926 if (new_player_nr != old_player_nr)
5928 input_player_nr = new_player_nr;
5930 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5934 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5936 static int choice = 0;
5939 int pos_start = SETUPINPUT_SCREEN_POS_START;
5940 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5941 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5942 int pos_end = SETUPINPUT_SCREEN_POS_END;
5944 if (button == MB_MENU_INITIALIZE)
5946 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5948 DrawCursorAndText_Setup(choice, -1, TRUE);
5952 else if (button == MB_MENU_LEAVE)
5954 setup_mode = SETUP_MODE_MAIN;
5961 if (mx || my) /* mouse input */
5963 x = (mx - mSX) / 32;
5964 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5966 else if (dx || dy) /* keyboard input */
5968 if (dx && choice == 0)
5969 x = (dx < 0 ? 10 : 12);
5970 else if ((dx && choice == 1) ||
5971 (dx == +1 && choice == 2) ||
5972 (dx == -1 && choice == pos_end))
5973 button = MB_MENU_CHOICE;
5977 if (y >= pos_empty1 && y <= pos_empty2)
5978 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5981 if (y == 0 && dx != 0 && button)
5983 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5985 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
5986 y >= pos_start && y <= pos_end &&
5987 !(y >= pos_empty1 && y <= pos_empty2))
5993 DrawCursorAndText_Setup(choice, -1, FALSE);
5994 DrawCursorAndText_Setup(y, -1, TRUE);
5996 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6005 char *device_name = setup.input[input_player_nr].joy.device_name;
6007 if (!setup.input[input_player_nr].use_joystick)
6009 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6011 setJoystickDeviceToNr(device_name, new_device_nr);
6012 setup.input[input_player_nr].use_joystick = TRUE;
6016 int device_nr = getJoystickNrFromDeviceName(device_name);
6017 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6019 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6020 setup.input[input_player_nr].use_joystick = FALSE;
6022 setJoystickDeviceToNr(device_name, new_device_nr);
6025 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6029 if (setup.input[input_player_nr].use_joystick)
6032 CalibrateJoystick(input_player_nr);
6035 CustomizeKeyboard(input_player_nr);
6037 else if (y == pos_end)
6043 setup_mode = SETUP_MODE_MAIN;
6050 void CustomizeKeyboard(int player_nr)
6054 boolean finished = FALSE;
6055 static struct SetupKeyboardInfo custom_key;
6060 } customize_step[] =
6062 { &custom_key.left, "Move Left" },
6063 { &custom_key.right, "Move Right" },
6064 { &custom_key.up, "Move Up" },
6065 { &custom_key.down, "Move Down" },
6066 { &custom_key.snap, "Snap Field" },
6067 { &custom_key.drop, "Drop Element" }
6070 /* read existing key bindings from player setup */
6071 custom_key = setup.input[player_nr].key;
6074 FadeOut(REDRAW_FIELD);
6078 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6081 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6082 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6083 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6084 "Key:", FONT_INPUT_1_ACTIVE);
6085 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6086 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6088 FadeIn(REDRAW_FIELD);
6094 if (PendingEvent()) /* got event */
6102 case EVENT_KEYPRESS:
6104 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6106 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6108 if (key == KSYM_Escape)
6109 FadeSkipNextFadeIn();
6115 /* all keys configured -- wait for "Escape" or "Return" key */
6119 /* press 'Enter' to keep the existing key binding */
6120 if (key == KSYM_Return)
6121 key = *customize_step[step_nr].key;
6123 /* check if key already used */
6124 for (i = 0; i < step_nr; i++)
6125 if (*customize_step[i].key == key)
6130 /* got new key binding */
6131 *customize_step[step_nr].key = key;
6132 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6134 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6135 getKeyNameFromKey(key), FONT_VALUE_1);
6138 /* un-highlight last query */
6139 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6140 customize_step[step_nr - 1].text, FONT_MENU_1);
6141 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6142 "Key:", FONT_MENU_1);
6144 /* press 'Enter' to leave */
6147 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6148 "Press Enter", FONT_TITLE_1);
6152 /* query next key binding */
6153 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6154 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6155 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6156 "Key:", FONT_INPUT_1_ACTIVE);
6157 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6158 getKeyNameFromKey(*customize_step[step_nr].key),
6163 case EVENT_KEYRELEASE:
6164 key_joystick_mapping = 0;
6168 HandleOtherEvents(&event);
6176 /* don't eat all CPU time */
6180 /* write new key bindings back to player setup */
6181 setup.input[player_nr].key = custom_key;
6184 DrawSetupScreen_Input();
6187 static boolean CalibrateJoystickMain(int player_nr)
6189 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6190 int new_joystick_xright = JOYSTICK_XMIDDLE;
6191 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6192 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6193 int new_joystick_xmiddle, new_joystick_ymiddle;
6195 int joystick_fd = joystick.fd[player_nr];
6196 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6197 boolean check[3][3];
6198 int check_remaining = 3 * 3;
6203 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6206 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6210 FadeOut(REDRAW_FIELD);
6214 for (y = 0; y < 3; y++)
6216 for (x = 0; x < 3; x++)
6218 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6219 check[x][y] = FALSE;
6223 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6224 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6225 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6226 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6227 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6228 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6229 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6231 joy_value = Joystick(player_nr);
6232 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6233 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6235 /* eventually uncalibrated center position (joystick could be uncentered) */
6236 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6239 new_joystick_xmiddle = joy_x;
6240 new_joystick_ymiddle = joy_y;
6242 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6244 FadeIn(REDRAW_FIELD);
6246 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6251 if (PendingEvent()) /* got event */
6259 case EVENT_KEYPRESS:
6260 switch (GetEventKey((KeyEvent *)&event, TRUE))
6263 if (check_remaining == 0)
6268 FadeSkipNextFadeIn();
6277 case EVENT_KEYRELEASE:
6278 key_joystick_mapping = 0;
6282 HandleOtherEvents(&event);
6287 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6290 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6291 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6292 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6293 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6295 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6296 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6297 setup.input[player_nr].joy.xright = new_joystick_xright;
6298 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6299 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6300 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6302 CheckJoystickData();
6304 joy_value = Joystick(player_nr);
6306 if (joy_value & JOY_BUTTON && check_remaining == 0)
6309 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6310 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6312 if (x != last_x || y != last_y)
6314 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6315 IMG_MENU_CALIBRATE_YELLOW, 0);
6316 DrawFixedGraphic(xpos + x, ypos + y,
6317 IMG_MENU_CALIBRATE_RED, 0);
6322 if (check_remaining > 0 && !check[x+1][y+1])
6324 check[x+1][y+1] = TRUE;
6332 /* don't eat all CPU time */
6336 /* calibrated center position (joystick should now be centered) */
6337 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6340 new_joystick_xmiddle = joy_x;
6341 new_joystick_ymiddle = joy_y;
6345 /* wait until the last pressed button was released */
6346 while (Joystick(player_nr) & JOY_BUTTON)
6348 if (PendingEvent()) /* got event */
6353 HandleOtherEvents(&event);
6362 void CalibrateJoystick(int player_nr)
6364 if (!CalibrateJoystickMain(player_nr))
6366 char *device_name = setup.input[player_nr].joy.device_name;
6367 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6368 int xpos = mSX - SX;
6369 int ypos = mSY - SY;
6373 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6374 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6377 Delay(2000); /* show error message for a short time */
6382 DrawSetupScreen_Input();
6385 void DrawSetupScreen()
6387 DeactivateJoystick();
6389 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6391 if (setup_mode == SETUP_MODE_INPUT)
6392 DrawSetupScreen_Input();
6393 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6394 DrawChooseTree(&game_speed_current);
6395 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6396 DrawChooseTree(&scroll_delay_current);
6397 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6398 DrawChooseTree(&screen_mode_current);
6399 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6400 DrawChooseTree(&window_size_current);
6401 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6402 DrawChooseTree(&scaling_type_current);
6403 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6404 DrawChooseTree(&artwork.gfx_current);
6405 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6406 DrawChooseTree(&artwork.snd_current);
6407 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6408 DrawChooseTree(&artwork.mus_current);
6409 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6410 DrawChooseTree(&volume_simple_current);
6411 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6412 DrawChooseTree(&volume_loops_current);
6413 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6414 DrawChooseTree(&volume_music_current);
6415 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6416 DrawChooseTree(&touch_control_current);
6417 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6418 DrawChooseTree(&move_distance_current);
6419 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6420 DrawChooseTree(&drop_distance_current);
6422 DrawSetupScreen_Generic();
6428 void RedrawSetupScreenAfterFullscreenToggle()
6430 if (setup_mode == SETUP_MODE_GRAPHICS ||
6431 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6433 // update list selection from "setup.window_scaling_percent"
6434 execSetupGraphics_setWindowSizes(TRUE);
6440 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6442 if (setup_mode == SETUP_MODE_INPUT)
6443 HandleSetupScreen_Input(mx, my, dx, dy, button);
6444 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6445 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6446 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6447 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6448 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6449 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6450 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6451 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6452 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6453 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6454 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6455 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6456 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6457 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6458 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6459 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6460 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6461 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6462 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6463 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6464 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6465 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6466 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6467 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6468 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6469 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6470 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6471 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6473 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6476 void HandleGameActions()
6478 if (game_status != GAME_MODE_PLAYING)
6481 GameActions(); /* main game loop */
6483 if (tape.auto_play && !tape.playing)
6484 AutoPlayTape(); /* continue automatically playing next tape */
6488 /* ---------- new screen button stuff -------------------------------------- */
6490 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6494 case SCREEN_CTRL_ID_PREV_LEVEL:
6495 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6496 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6499 case SCREEN_CTRL_ID_NEXT_LEVEL:
6500 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6501 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6504 case SCREEN_CTRL_ID_PREV_PLAYER:
6505 *x = mSX + TILEX * 10;
6506 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6509 case SCREEN_CTRL_ID_NEXT_PLAYER:
6510 *x = mSX + TILEX * 12;
6511 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6515 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6521 int gfx_unpressed, gfx_pressed;
6522 void (*get_gadget_position)(int *, int *, int);
6526 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6529 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6530 getScreenMenuButtonPos,
6531 SCREEN_CTRL_ID_PREV_LEVEL,
6536 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6537 getScreenMenuButtonPos,
6538 SCREEN_CTRL_ID_NEXT_LEVEL,
6543 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6544 getScreenMenuButtonPos,
6545 SCREEN_CTRL_ID_PREV_PLAYER,
6550 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6551 getScreenMenuButtonPos,
6552 SCREEN_CTRL_ID_NEXT_PLAYER,
6560 int gfx_unpressed, gfx_pressed;
6564 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6567 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6568 -1, -1, /* these values are not constant, but can change at runtime */
6569 SCREEN_CTRL_ID_SCROLL_UP,
6573 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6574 -1, -1, /* these values are not constant, but can change at runtime */
6575 SCREEN_CTRL_ID_SCROLL_DOWN,
6582 int gfx_unpressed, gfx_pressed;
6588 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6591 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6592 -1, -1, /* these values are not constant, but can change at runtime */
6593 -1, -1, /* these values are not constant, but can change at runtime */
6594 GD_TYPE_SCROLLBAR_VERTICAL,
6595 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6596 "scroll level series vertically"
6600 static void CreateScreenMenubuttons()
6602 struct GadgetInfo *gi;
6603 unsigned int event_mask;
6606 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6608 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6609 int gfx_unpressed, gfx_pressed;
6610 int x, y, width, height;
6611 int gd_x1, gd_x2, gd_y1, gd_y2;
6612 int id = menubutton_info[i].gadget_id;
6614 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6616 menubutton_info[i].get_gadget_position(&x, &y, id);
6618 width = SC_MENUBUTTON_XSIZE;
6619 height = SC_MENUBUTTON_YSIZE;
6621 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6622 gfx_pressed = menubutton_info[i].gfx_pressed;
6623 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6624 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6625 gd_x1 = graphic_info[gfx_unpressed].src_x;
6626 gd_y1 = graphic_info[gfx_unpressed].src_y;
6627 gd_x2 = graphic_info[gfx_pressed].src_x;
6628 gd_y2 = graphic_info[gfx_pressed].src_y;
6630 gi = CreateGadget(GDI_CUSTOM_ID, id,
6631 GDI_CUSTOM_TYPE_ID, i,
6632 GDI_INFO_TEXT, menubutton_info[i].infotext,
6637 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6638 GDI_STATE, GD_BUTTON_UNPRESSED,
6639 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6640 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6641 GDI_DIRECT_DRAW, FALSE,
6642 GDI_EVENT_MASK, event_mask,
6643 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6647 Error(ERR_EXIT, "cannot create gadget");
6649 screen_gadget[id] = gi;
6653 static void CreateScreenScrollbuttons()
6655 struct GadgetInfo *gi;
6656 unsigned int event_mask;
6659 /* these values are not constant, but can change at runtime */
6660 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6661 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6662 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6663 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6665 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6667 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6668 int gfx_unpressed, gfx_pressed;
6669 int x, y, width, height;
6670 int gd_x1, gd_x2, gd_y1, gd_y2;
6671 int id = scrollbutton_info[i].gadget_id;
6673 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6675 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6676 y = mSY + scrollbutton_info[i].y;
6677 width = SC_SCROLLBUTTON_XSIZE;
6678 height = SC_SCROLLBUTTON_YSIZE;
6680 /* correct scrollbar position if placed outside menu (playfield) area */
6681 if (x > SX + SC_SCROLL_UP_XPOS)
6682 x = SX + SC_SCROLL_UP_XPOS;
6684 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6685 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6686 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6688 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6689 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6690 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6691 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6692 gd_x1 = graphic_info[gfx_unpressed].src_x;
6693 gd_y1 = graphic_info[gfx_unpressed].src_y;
6694 gd_x2 = graphic_info[gfx_pressed].src_x;
6695 gd_y2 = graphic_info[gfx_pressed].src_y;
6697 gi = CreateGadget(GDI_CUSTOM_ID, id,
6698 GDI_CUSTOM_TYPE_ID, i,
6699 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6704 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6705 GDI_STATE, GD_BUTTON_UNPRESSED,
6706 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6707 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6708 GDI_DIRECT_DRAW, FALSE,
6709 GDI_EVENT_MASK, event_mask,
6710 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6714 Error(ERR_EXIT, "cannot create gadget");
6716 screen_gadget[id] = gi;
6720 static void CreateScreenScrollbars()
6724 /* these values are not constant, but can change at runtime */
6725 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6726 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6727 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6728 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6730 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6732 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6733 int gfx_unpressed, gfx_pressed;
6734 int x, y, width, height;
6735 int gd_x1, gd_x2, gd_y1, gd_y2;
6736 struct GadgetInfo *gi;
6737 int items_max, items_visible, item_position;
6738 unsigned int event_mask;
6739 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6740 int id = scrollbar_info[i].gadget_id;
6742 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6744 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6745 y = mSY + scrollbar_info[i].y;
6746 width = scrollbar_info[i].width;
6747 height = scrollbar_info[i].height;
6749 /* correct scrollbar position if placed outside menu (playfield) area */
6750 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6751 x = SX + SC_SCROLL_VERTICAL_XPOS;
6753 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6754 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6756 items_max = num_page_entries;
6757 items_visible = num_page_entries;
6760 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6761 gfx_pressed = scrollbar_info[i].gfx_pressed;
6762 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6763 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6764 gd_x1 = graphic_info[gfx_unpressed].src_x;
6765 gd_y1 = graphic_info[gfx_unpressed].src_y;
6766 gd_x2 = graphic_info[gfx_pressed].src_x;
6767 gd_y2 = graphic_info[gfx_pressed].src_y;
6769 gi = CreateGadget(GDI_CUSTOM_ID, id,
6770 GDI_CUSTOM_TYPE_ID, i,
6771 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6776 GDI_TYPE, scrollbar_info[i].type,
6777 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6778 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6779 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6780 GDI_WHEEL_AREA_X, SX,
6781 GDI_WHEEL_AREA_Y, SY,
6782 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6783 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6784 GDI_STATE, GD_BUTTON_UNPRESSED,
6785 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6786 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6787 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6788 GDI_DIRECT_DRAW, FALSE,
6789 GDI_EVENT_MASK, event_mask,
6790 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6794 Error(ERR_EXIT, "cannot create gadget");
6796 screen_gadget[id] = gi;
6800 void CreateScreenGadgets()
6802 int last_game_status = game_status; /* save current game status */
6804 CreateScreenMenubuttons();
6806 CreateScreenScrollbuttons();
6807 CreateScreenScrollbars();
6809 game_status = last_game_status; /* restore current game status */
6812 void FreeScreenGadgets()
6816 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6817 FreeGadget(screen_gadget[i]);
6820 void MapScreenMenuGadgets(int screen_mask)
6824 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6825 if (screen_mask & menubutton_info[i].screen_mask)
6826 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6829 void MapScreenGadgets(int num_entries)
6833 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6836 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6837 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6839 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6840 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6843 void MapScreenTreeGadgets(TreeInfo *ti)
6845 MapScreenGadgets(numTreeInfoInGroup(ti));
6848 static void HandleScreenGadgets(struct GadgetInfo *gi)
6850 int id = gi->custom_id;
6851 int button = gi->event.button;
6852 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6856 case SCREEN_CTRL_ID_PREV_LEVEL:
6857 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6860 case SCREEN_CTRL_ID_NEXT_LEVEL:
6861 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6864 case SCREEN_CTRL_ID_PREV_PLAYER:
6865 HandleSetupScreen_Input_Player(step, -1);
6868 case SCREEN_CTRL_ID_NEXT_PLAYER:
6869 HandleSetupScreen_Input_Player(step, +1);
6872 case SCREEN_CTRL_ID_SCROLL_UP:
6873 if (game_status == GAME_MODE_LEVELS)
6874 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6875 else if (game_status == GAME_MODE_LEVELNR)
6876 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6877 else if (game_status == GAME_MODE_SETUP)
6878 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6881 case SCREEN_CTRL_ID_SCROLL_DOWN:
6882 if (game_status == GAME_MODE_LEVELS)
6883 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6884 else if (game_status == GAME_MODE_LEVELNR)
6885 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6886 else if (game_status == GAME_MODE_SETUP)
6887 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6890 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6891 if (game_status == GAME_MODE_LEVELS)
6892 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6893 else if (game_status == GAME_MODE_LEVELNR)
6894 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6895 else if (game_status == GAME_MODE_SETUP)
6896 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);