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"
27 #define DEBUG_JOYSTICKS 0
30 /* screens on the info screen */
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 /* screens on the setup screen */
43 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
44 /* (should also match corresponding entries in src/conf_gfx.c) */
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_EDITOR 2
48 #define SETUP_MODE_GRAPHICS 3
49 #define SETUP_MODE_SOUND 4
50 #define SETUP_MODE_ARTWORK 5
51 #define SETUP_MODE_INPUT 6
52 #define SETUP_MODE_TOUCH 7
53 #define SETUP_MODE_SHORTCUTS 8
54 #define SETUP_MODE_SHORTCUTS_1 9
55 #define SETUP_MODE_SHORTCUTS_2 10
56 #define SETUP_MODE_SHORTCUTS_3 11
57 #define SETUP_MODE_SHORTCUTS_4 12
58 #define SETUP_MODE_SHORTCUTS_5 13
60 /* sub-screens on the setup screen (generic) */
61 #define SETUP_MODE_CHOOSE_ARTWORK 14
62 #define SETUP_MODE_CHOOSE_OTHER 15
64 /* sub-screens on the setup screen (specific) */
65 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
70 #define SETUP_MODE_CHOOSE_RENDERING 21
71 #define SETUP_MODE_CHOOSE_GRAPHICS 22
72 #define SETUP_MODE_CHOOSE_SOUNDS 23
73 #define SETUP_MODE_CHOOSE_MUSIC 24
74 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
75 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
76 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
77 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
78 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
79 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
81 #define MAX_SETUP_MODES 31
83 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
85 /* for input setup functions */
86 #define SETUPINPUT_SCREEN_POS_START 0
87 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
88 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
89 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
91 /* for various menu stuff */
92 #define MENU_SCREEN_START_XPOS 1
93 #define MENU_SCREEN_START_YPOS 2
94 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
95 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
96 #define MENU_TITLE1_YPOS 8
97 #define MENU_TITLE2_YPOS 46
98 #define MENU_SCREEN_INFO_XSTART 16
99 #define MENU_SCREEN_INFO_YSTART1 100
100 #define MENU_SCREEN_INFO_YSTART2 128
101 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
102 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
103 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
104 MENU_SCREEN_INFO_YSTART2 - \
106 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
107 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
108 MENU_SCREEN_INFO_YSTEP)
109 #define NUM_INFO_ELEMENTS_FROM_CONF \
110 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
111 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
112 MAX_MENU_ENTRIES_ON_SCREEN)
113 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
114 MAX_INFO_ELEMENTS_ON_SCREEN), \
115 NUM_INFO_ELEMENTS_FROM_CONF)
116 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
117 #define MAX_MENU_TEXT_LENGTH_BIG 13
118 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
120 /* buttons and scrollbars identifiers */
121 #define SCREEN_CTRL_ID_PREV_LEVEL 0
122 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
123 #define SCREEN_CTRL_ID_PREV_PLAYER 2
124 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
125 #define SCREEN_CTRL_ID_SCROLL_UP 4
126 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
127 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
129 #define NUM_SCREEN_GADGETS 7
131 #define NUM_SCREEN_MENUBUTTONS 4
132 #define NUM_SCREEN_SCROLLBUTTONS 2
133 #define NUM_SCREEN_SCROLLBARS 1
135 #define SCREEN_MASK_MAIN (1 << 0)
136 #define SCREEN_MASK_INPUT (1 << 1)
138 /* graphic position and size values for buttons and scrollbars */
139 #define SC_MENUBUTTON_XSIZE TILEX
140 #define SC_MENUBUTTON_YSIZE TILEY
142 #define SC_SCROLLBUTTON_XSIZE TILEX
143 #define SC_SCROLLBUTTON_YSIZE TILEY
145 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
147 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
148 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
149 SC_SCROLLBUTTON_YSIZE)
151 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
152 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
156 SC_SCROLLBUTTON_YSIZE)
158 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
159 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
160 SC_SCROLL_VERTICAL_YSIZE)
162 #define SC_BORDER_SIZE 14
165 /* forward declarations of internal functions */
166 static void HandleScreenGadgets(struct GadgetInfo *);
167 static void HandleSetupScreen_Generic(int, int, int, int, int);
168 static void HandleSetupScreen_Input(int, int, int, int, int);
169 static void CustomizeKeyboard(int);
170 static void ConfigureJoystick(int);
171 static void execSetupGame(void);
172 static void execSetupGraphics(void);
173 static void execSetupSound(void);
174 static void execSetupTouch(void);
175 static void execSetupArtwork(void);
176 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
178 static void DrawChooseLevelSet(void);
179 static void DrawChooseLevelNr(void);
180 static void DrawInfoScreen(void);
181 static void DrawSetupScreen(void);
183 static void DrawInfoScreen_NotAvailable(char *, char *);
184 static void DrawInfoScreen_HelpAnim(int, int, boolean);
185 static void DrawInfoScreen_HelpText(int, int, int, int);
186 static void HandleInfoScreen_Main(int, int, int, int, int);
187 static void HandleInfoScreen_TitleScreen(int);
188 static void HandleInfoScreen_Elements(int);
189 static void HandleInfoScreen_Music(int);
190 static void HandleInfoScreen_Credits(int);
191 static void HandleInfoScreen_Program(int);
192 static void HandleInfoScreen_Version(int);
194 static void MapScreenMenuGadgets(int);
195 static void MapScreenGadgets(int);
196 static void MapScreenTreeGadgets(TreeInfo *);
198 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
200 static int info_mode = INFO_MODE_MAIN;
201 static int setup_mode = SETUP_MODE_MAIN;
203 static TreeInfo *window_sizes = NULL;
204 static TreeInfo *window_size_current = NULL;
206 static TreeInfo *scaling_types = NULL;
207 static TreeInfo *scaling_type_current = NULL;
209 static TreeInfo *rendering_modes = NULL;
210 static TreeInfo *rendering_mode_current = NULL;
212 static TreeInfo *scroll_delays = NULL;
213 static TreeInfo *scroll_delay_current = NULL;
215 static TreeInfo *snapshot_modes = NULL;
216 static TreeInfo *snapshot_mode_current = NULL;
218 static TreeInfo *game_speeds = NULL;
219 static TreeInfo *game_speed_current = NULL;
221 static TreeInfo *volumes_simple = NULL;
222 static TreeInfo *volume_simple_current = NULL;
224 static TreeInfo *volumes_loops = NULL;
225 static TreeInfo *volume_loops_current = NULL;
227 static TreeInfo *volumes_music = NULL;
228 static TreeInfo *volume_music_current = NULL;
230 static TreeInfo *touch_controls = NULL;
231 static TreeInfo *touch_control_current = NULL;
233 static TreeInfo *move_distances = NULL;
234 static TreeInfo *move_distance_current = NULL;
236 static TreeInfo *drop_distances = NULL;
237 static TreeInfo *drop_distance_current = NULL;
239 static TreeInfo *level_number = NULL;
240 static TreeInfo *level_number_current = NULL;
246 } window_sizes_list[] =
251 { 100, "100 % (Default)" },
268 } scaling_types_list[] =
270 { SCALING_QUALITY_NEAREST, "None" },
271 { SCALING_QUALITY_LINEAR, "Linear" },
272 { SCALING_QUALITY_BEST, "Anisotropic" },
281 } rendering_modes_list[] =
283 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
284 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
286 // this mode may work under certain conditions, but does not work on Windows
287 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
289 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
298 } game_speeds_list[] =
307 { 1000, "1/1s (Extremely Slow)" },
312 { 29, "1/35s (Original Supaplex)" },
314 { 20, "1/50s (Normal Speed)" },
315 { 14, "1/70s (Maximum Supaplex)" },
319 { 1, "1/1000s (Extremely Fast)" },
329 } scroll_delays_list[] =
331 { 0, "0 Tiles (No Scroll Delay)" },
334 { 3, "3 Tiles (Default)" },
339 { 8, "8 Tiles (Maximum Scroll Delay)"},
348 } snapshot_modes_list[] =
350 { STR_SNAPSHOT_MODE_OFF, "Off" },
351 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
352 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
353 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
386 } touch_controls_list[] =
388 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
389 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
390 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
414 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
415 (s) <= GAME_MODE_SETUP ? (s) : \
416 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
417 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
419 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
420 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
421 (i) <= INFO_MODE_LEVELSET ? (i) : \
424 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
425 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
426 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
427 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
428 SETUP_MODE_CHOOSE_ARTWORK : \
429 SETUP_MODE_CHOOSE_OTHER)
431 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
432 menu.draw_xoffset[GAME_MODE_INFO] : \
433 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
434 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
435 menu.draw_yoffset[GAME_MODE_INFO] : \
436 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
438 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
439 menu.draw_xoffset[GAME_MODE_SETUP] : \
440 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
441 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
442 menu.draw_yoffset[GAME_MODE_SETUP] : \
443 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
445 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
446 DRAW_XOFFSET_INFO(info_mode) : \
447 (s) == GAME_MODE_SETUP ? \
448 DRAW_XOFFSET_SETUP(setup_mode) : \
449 menu.draw_xoffset[DRAW_MODE(s)])
450 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
451 DRAW_YOFFSET_INFO(info_mode) : \
452 (s) == GAME_MODE_SETUP ? \
453 DRAW_YOFFSET_SETUP(setup_mode) : \
454 menu.draw_yoffset[DRAW_MODE(s)])
456 #define mSX (SX + DRAW_XOFFSET(game_status))
457 #define mSY (SY + DRAW_YOFFSET(game_status))
459 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
460 menu.list_size[game_status] : \
461 MAX_MENU_ENTRIES_ON_SCREEN)
463 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
464 NUM_MENU_ENTRIES_ON_SCREEN)
467 /* title display and control definitions */
469 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
470 2 * MAX_NUM_TITLE_MESSAGES)
472 #define NO_DIRECT_LEVEL_SELECT (-1)
475 static int num_title_screens = 0;
477 struct TitleControlInfo
486 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
488 /* main menu display and control definitions */
490 #define MAIN_CONTROL_NAME 0
491 #define MAIN_CONTROL_LEVELS 1
492 #define MAIN_CONTROL_SCORES 2
493 #define MAIN_CONTROL_EDITOR 3
494 #define MAIN_CONTROL_INFO 4
495 #define MAIN_CONTROL_GAME 5
496 #define MAIN_CONTROL_SETUP 6
497 #define MAIN_CONTROL_QUIT 7
498 #define MAIN_CONTROL_PREV_LEVEL 8
499 #define MAIN_CONTROL_NEXT_LEVEL 9
500 #define MAIN_CONTROL_FIRST_LEVEL 10
501 #define MAIN_CONTROL_LAST_LEVEL 11
502 #define MAIN_CONTROL_LEVEL_NUMBER 12
503 #define MAIN_CONTROL_LEVEL_INFO_1 13
504 #define MAIN_CONTROL_LEVEL_INFO_2 14
505 #define MAIN_CONTROL_LEVEL_NAME 15
506 #define MAIN_CONTROL_LEVEL_AUTHOR 16
507 #define MAIN_CONTROL_LEVEL_YEAR 17
508 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
509 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
510 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
511 #define MAIN_CONTROL_TITLE_1 21
512 #define MAIN_CONTROL_TITLE_2 22
513 #define MAIN_CONTROL_TITLE_3 23
515 static char str_main_text_name[10];
516 static char str_main_text_first_level[10];
517 static char str_main_text_last_level[10];
518 static char str_main_text_level_number[10];
520 static char *main_text_name = str_main_text_name;
521 static char *main_text_first_level = str_main_text_first_level;
522 static char *main_text_last_level = str_main_text_last_level;
523 static char *main_text_level_number = str_main_text_level_number;
524 static char *main_text_levels = "Levelset";
525 static char *main_text_scores = "Hall Of Fame";
526 static char *main_text_editor = "Level Creator";
527 static char *main_text_info = "Info Screen";
528 static char *main_text_game = "Start Game";
529 static char *main_text_setup = "Setup";
530 static char *main_text_quit = "Quit";
531 static char *main_text_level_name = level.name;
532 static char *main_text_level_author = level.author;
533 static char *main_text_level_year = NULL;
534 static char *main_text_level_imported_from = NULL;
535 static char *main_text_level_imported_by = NULL;
536 static char *main_text_level_tested_by = NULL;
538 struct MainControlInfo
542 struct MenuPosInfo *pos_button;
545 struct TextPosInfo *pos_text;
548 struct TextPosInfo *pos_input;
552 static struct MainControlInfo main_controls[] =
556 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
557 &menu.main.text.name, &main_text_name,
558 &menu.main.input.name, &setup.player_name,
562 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
563 &menu.main.text.levels, &main_text_levels,
568 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
569 &menu.main.text.scores, &main_text_scores,
574 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
575 &menu.main.text.editor, &main_text_editor,
580 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
581 &menu.main.text.info, &main_text_info,
586 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
587 &menu.main.text.game, &main_text_game,
592 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
593 &menu.main.text.setup, &main_text_setup,
598 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
599 &menu.main.text.quit, &main_text_quit,
603 /* (these two buttons are real gadgets) */
605 MAIN_CONTROL_PREV_LEVEL,
606 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
611 MAIN_CONTROL_NEXT_LEVEL,
612 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
618 MAIN_CONTROL_FIRST_LEVEL,
620 &menu.main.text.first_level, &main_text_first_level,
624 MAIN_CONTROL_LAST_LEVEL,
626 &menu.main.text.last_level, &main_text_last_level,
630 MAIN_CONTROL_LEVEL_NUMBER,
632 &menu.main.text.level_number, &main_text_level_number,
636 MAIN_CONTROL_LEVEL_INFO_1,
638 &menu.main.text.level_info_1, NULL,
642 MAIN_CONTROL_LEVEL_INFO_2,
644 &menu.main.text.level_info_2, NULL,
648 MAIN_CONTROL_LEVEL_NAME,
650 &menu.main.text.level_name, &main_text_level_name,
654 MAIN_CONTROL_LEVEL_AUTHOR,
656 &menu.main.text.level_author, &main_text_level_author,
660 MAIN_CONTROL_LEVEL_YEAR,
662 &menu.main.text.level_year, &main_text_level_year,
666 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
668 &menu.main.text.level_imported_from, &main_text_level_imported_from,
672 MAIN_CONTROL_LEVEL_IMPORTED_BY,
674 &menu.main.text.level_imported_by, &main_text_level_imported_by,
678 MAIN_CONTROL_LEVEL_TESTED_BY,
680 &menu.main.text.level_tested_by, &main_text_level_tested_by,
684 MAIN_CONTROL_TITLE_1,
686 &menu.main.text.title_1, &setup.internal.program_title,
690 MAIN_CONTROL_TITLE_2,
692 &menu.main.text.title_2, &setup.internal.program_copyright,
696 MAIN_CONTROL_TITLE_3,
698 &menu.main.text.title_3, &setup.internal.program_company,
711 static int getTitleScreenGraphic(int nr, boolean initial)
713 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
716 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
718 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
722 static int getTitleScreenGameMode(boolean initial)
724 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
728 static int getTitleMessageGameMode(boolean initial)
730 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
733 static int getTitleAnimMode(struct TitleControlInfo *tci)
735 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
737 return base + tci->local_nr;
741 static int getTitleScreenBackground(boolean initial)
743 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
748 static int getTitleMessageBackground(int nr, boolean initial)
750 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
754 static int getTitleBackground(int nr, boolean initial, boolean is_image)
756 int base = (is_image ?
757 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
758 IMG_BACKGROUND_TITLESCREEN_1) :
759 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
760 IMG_BACKGROUND_TITLEMESSAGE_1));
761 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
762 IMG_BACKGROUND_TITLE);
763 int graphic_local = base + nr;
765 if (graphic_info[graphic_local].bitmap != NULL)
766 return graphic_local;
768 if (graphic_info[graphic_global].bitmap != NULL)
769 return graphic_global;
771 return IMG_UNDEFINED;
774 static int getTitleSound(struct TitleControlInfo *tci)
776 boolean is_image = tci->is_image;
777 int initial = tci->initial;
778 int nr = tci->local_nr;
779 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
780 int base = (is_image ?
781 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
782 SND_BACKGROUND_TITLESCREEN_1) :
783 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
784 SND_BACKGROUND_TITLEMESSAGE_1));
785 int sound_global = menu.sound[mode];
786 int sound_local = base + nr;
789 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
790 nr, initial, is_image,
791 sound_global, getSoundListEntry(sound_global)->filename,
792 sound_local, getSoundListEntry(sound_local)->filename);
795 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
798 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
801 return SND_UNDEFINED;
804 static int getTitleMusic(struct TitleControlInfo *tci)
806 boolean is_image = tci->is_image;
807 int initial = tci->initial;
808 int nr = tci->local_nr;
809 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
810 int base = (is_image ?
811 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
812 MUS_BACKGROUND_TITLESCREEN_1) :
813 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
814 MUS_BACKGROUND_TITLEMESSAGE_1));
815 int music_global = menu.music[mode];
816 int music_local = base + nr;
819 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
820 nr, initial, is_image,
821 music_global, getMusicListEntry(music_global)->filename,
822 music_local, getMusicListEntry(music_local)->filename);
825 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
828 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
831 return MUS_UNDEFINED;
834 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
836 boolean is_image = tci->is_image;
837 boolean initial = tci->initial;
838 boolean first = tci->first;
839 int nr = tci->local_nr;
840 struct TitleMessageInfo tmi;
841 struct TitleFadingInfo ti;
843 tmi = (is_image ? (initial ? (first ?
844 titlescreen_initial_first[nr] :
845 titlescreen_initial[nr])
847 titlescreen_first[nr] :
849 : (initial ? (first ?
850 titlemessage_initial_first[nr] :
851 titlemessage_initial[nr])
853 titlemessage_first[nr] :
856 ti.fade_mode = tmi.fade_mode;
857 ti.fade_delay = tmi.fade_delay;
858 ti.post_delay = tmi.post_delay;
859 ti.auto_delay = tmi.auto_delay;
864 static int compareTitleControlInfo(const void *object1, const void *object2)
866 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
867 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
870 if (tci1->initial != tci2->initial)
871 compare_result = (tci1->initial ? -1 : +1);
872 else if (tci1->sort_priority != tci2->sort_priority)
873 compare_result = tci1->sort_priority - tci2->sort_priority;
874 else if (tci1->is_image != tci2->is_image)
875 compare_result = (tci1->is_image ? -1 : +1);
877 compare_result = tci1->local_nr - tci2->local_nr;
879 return compare_result;
882 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
884 int nr, int sort_priority)
886 title_controls[num_title_screens].is_image = is_image;
887 title_controls[num_title_screens].initial = initial;
888 title_controls[num_title_screens].local_nr = nr;
889 title_controls[num_title_screens].sort_priority = sort_priority;
891 title_controls[num_title_screens].first = FALSE; /* will be set later */
896 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
900 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
902 int graphic = getTitleScreenGraphic(i, initial);
903 Bitmap *bitmap = graphic_info[graphic].bitmap;
904 int sort_priority = graphic_info[graphic].sort_priority;
907 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
910 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
912 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
913 char *filename = getLevelSetTitleMessageFilename(i, initial);
914 int sort_priority = tmi->sort_priority;
916 if (filename != NULL)
917 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
921 static void InitializeTitleControls(boolean show_title_initial)
923 num_title_screens = 0;
925 /* 1st step: initialize title screens for game start (only when starting) */
926 if (show_title_initial)
927 InitializeTitleControls_CheckTitleInfo(TRUE);
929 /* 2nd step: initialize title screens for current level set */
930 InitializeTitleControls_CheckTitleInfo(FALSE);
932 /* sort title screens according to sort_priority and title number */
933 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
934 compareTitleControlInfo);
936 /* mark first title screen */
937 title_controls[0].first = TRUE;
940 static boolean visibleMenuPos(struct MenuPosInfo *pos)
942 return (pos != NULL && pos->x != -1 && pos->y != -1);
945 static boolean visibleTextPos(struct TextPosInfo *pos)
947 return (pos != NULL && pos->x != -1 && pos->y != -1);
950 static void InitializeMainControls()
952 boolean local_team_mode = (!options.network && setup.team_mode);
955 /* set main control text values to dynamically determined values */
956 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
958 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
959 menu.main.text.first_level.size));
960 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
961 menu.main.text.last_level.size));
962 strcpy(main_text_level_number, int2str(level_nr,
963 menu.main.text.level_number.size));
965 main_text_level_year = leveldir_current->year;
966 main_text_level_imported_from = leveldir_current->imported_from;
967 main_text_level_imported_by = leveldir_current->imported_by;
968 main_text_level_tested_by = leveldir_current->tested_by;
970 /* set main control screen positions to dynamically determined values */
971 for (i = 0; main_controls[i].nr != -1; i++)
973 struct MainControlInfo *mci = &main_controls[i];
975 struct MenuPosInfo *pos_button = mci->pos_button;
976 struct TextPosInfo *pos_text = mci->pos_text;
977 struct TextPosInfo *pos_input = mci->pos_input;
978 char *text = (mci->text ? *mci->text : NULL);
979 char *input = (mci->input ? *mci->input : NULL);
980 int button_graphic = mci->button_graphic;
981 int font_text = (pos_text ? pos_text->font : -1);
982 int font_input = (pos_input ? pos_input->font : -1);
984 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
985 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
986 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
987 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
988 int text_chars = (text != NULL ? strlen(text) : 0);
989 int input_chars = (input != NULL ? strlen(input) : 0);
992 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
994 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
995 int text_width = font_text_width * text_chars;
996 int text_height = font_text_height;
997 int input_width = font_input_width * input_chars;
998 int input_height = font_input_height;
1000 if (nr == MAIN_CONTROL_NAME)
1002 menu.main.input.name.width = input_width;
1003 menu.main.input.name.height = input_height;
1006 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1008 pos_button->width = button_width;
1009 pos_button->height = button_height;
1012 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1014 /* calculate size for non-clickable text -- needed for text alignment */
1015 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1017 if (pos_text->width == -1 || calculate_text_size)
1018 pos_text->width = text_width;
1019 if (pos_text->height == -1 || calculate_text_size)
1020 pos_text->height = text_height;
1022 if (visibleMenuPos(pos_button))
1024 if (pos_text->x == -1)
1025 pos_text->x = pos_button->x + pos_button->width;
1026 if (pos_text->y == -1)
1028 pos_button->y + (pos_button->height - pos_text->height) / 2;
1032 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1034 if (visibleTextPos(pos_text))
1036 if (pos_input->x == -1)
1037 pos_input->x = pos_text->x + pos_text->width;
1038 if (pos_input->y == -1)
1039 pos_input->y = pos_text->y;
1042 if (pos_input->width == -1)
1043 pos_input->width = input_width;
1044 if (pos_input->height == -1)
1045 pos_input->height = input_height;
1050 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1051 int graphic, boolean pressed)
1053 struct GraphicInfo *g = &graphic_info[graphic];
1056 int xoffset = (pressed ? g->pressed_xoffset : 0);
1057 int yoffset = (pressed ? g->pressed_yoffset : 0);
1059 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1061 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1062 g->width, g->height, dst_x, dst_y);
1065 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1066 boolean active_input,
1067 boolean pressed_button)
1071 for (i = 0; main_controls[i].nr != -1; i++)
1073 struct MainControlInfo *mci = &main_controls[i];
1075 if (mci->nr == nr || nr == -1)
1077 struct MenuPosInfo *pos_button = mci->pos_button;
1078 struct TextPosInfo *pos_text = mci->pos_text;
1079 struct TextPosInfo *pos_input = mci->pos_input;
1080 char *text = (mci->text ? *mci->text : NULL);
1081 char *input = (mci->input ? *mci->input : NULL);
1082 int button_graphic = mci->button_graphic;
1083 int font_text = (pos_text ? pos_text->font : -1);
1084 int font_input = (pos_input ? pos_input->font : -1);
1088 button_graphic = BUTTON_ACTIVE(button_graphic);
1089 font_text = FONT_ACTIVE(font_text);
1094 font_input = FONT_ACTIVE(font_input);
1097 if (visibleMenuPos(pos_button))
1099 struct MenuPosInfo *pos = pos_button;
1100 int x = mSX + pos->x;
1101 int y = mSY + pos->y;
1103 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1104 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1107 if (visibleTextPos(pos_text) && text != NULL)
1109 struct TextPosInfo *pos = pos_text;
1110 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1111 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1114 /* (check why/if this is needed) */
1115 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1117 DrawText(x, y, text, font_text);
1120 if (visibleTextPos(pos_input) && input != NULL)
1122 struct TextPosInfo *pos = pos_input;
1123 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1124 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1127 /* (check why/if this is needed) */
1128 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1130 DrawText(x, y, input, font_input);
1136 static void DrawCursorAndText_Main(int nr, boolean active_text,
1137 boolean pressed_button)
1139 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1143 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1144 boolean pressed_button)
1146 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1150 static struct MainControlInfo *getMainControlInfo(int nr)
1154 for (i = 0; main_controls[i].nr != -1; i++)
1155 if (main_controls[i].nr == nr)
1156 return &main_controls[i];
1161 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1166 int rect_x = ALIGNED_TEXT_XPOS(rect);
1167 int rect_y = ALIGNED_TEXT_YPOS(rect);
1169 return (x >= rect_x && x < rect_x + rect->width &&
1170 y >= rect_y && y < rect_y + rect->height);
1173 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1178 int rect_x = ALIGNED_TEXT_XPOS(rect);
1179 int rect_y = ALIGNED_TEXT_YPOS(rect);
1182 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1183 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1184 (x >= rect_x && x < rect_x + rect->width &&
1185 y >= rect_y && y < rect_y + rect->height));
1188 return (x >= rect_x && x < rect_x + rect->width &&
1189 y >= rect_y && y < rect_y + rect->height);
1192 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1194 int rect_width = preview->xsize * preview->tile_size;
1195 int rect_height = preview->ysize * preview->tile_size;
1196 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1197 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1199 return (x >= rect_x && x < rect_x + rect_width &&
1200 y >= rect_y && y < rect_y + rect_height);
1203 static void AdjustScrollbar(int id, int items_max, int items_visible,
1206 struct GadgetInfo *gi = screen_gadget[id];
1208 if (item_position > items_max - items_visible)
1209 item_position = items_max - items_visible;
1211 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1212 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1213 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1216 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1218 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1222 static void clearMenuListArea()
1224 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1226 /* correct scrollbar position if placed outside menu (playfield) area */
1227 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1228 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1230 /* clear menu list area, but not title or scrollbar */
1231 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1232 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1235 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1237 static int cursor_array[MAX_LEV_FIELDY];
1238 int x = mSX + TILEX * xpos;
1239 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1244 cursor_array[ypos] = graphic;
1246 graphic = cursor_array[ypos];
1250 graphic = BUTTON_ACTIVE(graphic);
1252 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1253 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1256 static void initCursor(int ypos, int graphic)
1258 drawCursorExt(0, ypos, FALSE, graphic);
1261 static void drawCursor(int ypos, boolean active)
1263 drawCursorExt(0, ypos, active, -1);
1266 static void drawCursorXY(int xpos, int ypos, int graphic)
1268 drawCursorExt(xpos, ypos, FALSE, graphic);
1271 static void drawChooseTreeCursor(int ypos, boolean active)
1273 drawCursorExt(0, ypos, active, -1);
1278 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1279 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1280 setup.internal.program_copyright);
1283 void DrawTitleScreenImage(int nr, boolean initial)
1285 int graphic = getTitleScreenGraphic(nr, initial);
1286 Bitmap *bitmap = graphic_info[graphic].bitmap;
1287 int width = graphic_info[graphic].width;
1288 int height = graphic_info[graphic].height;
1289 int src_x = graphic_info[graphic].src_x;
1290 int src_y = graphic_info[graphic].src_y;
1296 if (width > WIN_XSIZE)
1298 /* image width too large for window => center image horizontally */
1299 src_x = (width - WIN_XSIZE) / 2;
1303 if (height > WIN_YSIZE)
1305 /* image height too large for window => center image vertically */
1306 src_y = (height - WIN_YSIZE) / 2;
1310 /* always display title screens centered */
1311 dst_x = (WIN_XSIZE - width) / 2;
1312 dst_y = (WIN_YSIZE - height) / 2;
1314 SetDrawBackgroundMask(REDRAW_ALL);
1315 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1317 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1319 if (DrawingOnBackground(dst_x, dst_y))
1320 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1322 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1324 redraw_mask = REDRAW_ALL;
1327 void DrawTitleScreenMessage(int nr, boolean initial)
1329 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1330 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1332 if (filename == NULL)
1335 /* force TITLE font on title message screen */
1336 SetFontStatus(getTitleMessageGameMode(initial));
1338 /* if chars *and* width set to "-1", automatically determine width */
1339 if (tmi->chars == -1 && tmi->width == -1)
1340 tmi->width = viewport.window[game_status].width;
1342 /* if lines *and* height set to "-1", automatically determine height */
1343 if (tmi->lines == -1 && tmi->height == -1)
1344 tmi->height = viewport.window[game_status].height;
1346 /* if chars set to "-1", automatically determine by text and font width */
1347 if (tmi->chars == -1)
1348 tmi->chars = tmi->width / getFontWidth(tmi->font);
1350 tmi->width = tmi->chars * getFontWidth(tmi->font);
1352 /* if lines set to "-1", automatically determine by text and font height */
1353 if (tmi->lines == -1)
1354 tmi->lines = tmi->height / getFontHeight(tmi->font);
1356 tmi->height = tmi->lines * getFontHeight(tmi->font);
1358 /* if x set to "-1", automatically determine by width and alignment */
1360 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1362 /* if y set to "-1", automatically determine by height and alignment */
1364 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1366 SetDrawBackgroundMask(REDRAW_ALL);
1367 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1369 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1371 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1372 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1373 tmi->autowrap, tmi->centered, tmi->parse_comments);
1378 void DrawTitleScreen()
1380 KeyboardAutoRepeatOff();
1382 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1385 boolean CheckTitleScreen(boolean levelset_has_changed)
1387 static boolean show_title_initial = TRUE;
1388 boolean show_titlescreen = FALSE;
1390 /* needed to be able to skip title screen, if no image or message defined */
1391 InitializeTitleControls(show_title_initial);
1393 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1394 show_titlescreen = TRUE;
1396 /* show initial title images and messages only once at program start */
1397 show_title_initial = FALSE;
1399 return (show_titlescreen && num_title_screens > 0);
1404 static LevelDirTree *leveldir_last_valid = NULL;
1405 boolean levelset_has_changed = FALSE;
1406 int fade_mask = REDRAW_FIELD;
1408 LimitScreenUpdates(FALSE);
1410 FadeSetLeaveScreen();
1412 /* do not fade out here -- function may continue and fade on editor screen */
1415 FadeMenuSoundsAndMusic();
1417 ExpireSoundLoops(FALSE);
1419 KeyboardAutoRepeatOn();
1421 audio.sound_deactivated = FALSE;
1425 /* needed if last screen was the playing screen, invoked from level editor */
1426 if (level_editor_test_game)
1428 CloseDoor(DOOR_CLOSE_ALL);
1430 SetGameStatus(GAME_MODE_EDITOR);
1437 /* needed if last screen was the setup screen and fullscreen state changed */
1438 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1439 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1441 /* leveldir_current may be invalid (level group, parent link) */
1442 if (!validLevelSeries(leveldir_current))
1443 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1445 if (leveldir_current != leveldir_last_valid)
1446 levelset_has_changed = TRUE;
1448 /* store valid level series information */
1449 leveldir_last_valid = leveldir_current;
1451 init_last = init; /* switch to new busy animation */
1453 /* needed if last screen (level choice) changed graphics, sounds or music */
1454 ReloadCustomArtwork(0);
1456 if (CheckTitleScreen(levelset_has_changed))
1458 SetGameStatus(GAME_MODE_TITLE);
1465 if (redraw_mask & REDRAW_ALL)
1466 fade_mask = REDRAW_ALL;
1468 if (CheckIfGlobalBorderHasChanged())
1469 fade_mask = REDRAW_ALL;
1473 /* needed if different viewport properties defined for menues */
1474 ChangeViewportPropertiesIfNeeded();
1476 SetDrawtoField(DRAW_TO_BACKBUFFER);
1478 /* level_nr may have been set to value over handicap with level editor */
1479 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1480 level_nr = leveldir_current->handicap_level;
1482 LoadLevel(level_nr);
1483 LoadScore(level_nr);
1485 SaveLevelSetup_SeriesInfo();
1487 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1488 SetDrawDeactivationMask(REDRAW_NONE);
1489 SetDrawBackgroundMask(REDRAW_FIELD);
1491 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1494 if (fade_mask == REDRAW_ALL)
1495 RedrawGlobalBorder();
1500 InitializeMainControls();
1502 DrawCursorAndText_Main(-1, FALSE, FALSE);
1503 DrawPreviewLevelInitial();
1505 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1508 if (TAPE_IS_EMPTY(tape))
1510 DrawCompleteVideoDisplay();
1512 PlayMenuSoundsAndMusic();
1514 /* create gadgets for main menu screen */
1515 FreeScreenGadgets();
1516 CreateScreenGadgets();
1518 /* map gadgets for main menu screen */
1520 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1522 /* copy actual game door content to door double buffer for OpenDoor() */
1523 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1524 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1526 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1528 DrawMaskedBorder(fade_mask);
1533 /* update screen area with special editor door */
1534 redraw_mask |= REDRAW_ALL;
1537 SetMouseCursor(CURSOR_DEFAULT);
1539 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1542 static void gotoTopLevelDir()
1544 /* move upwards until inside (but not above) top level directory */
1545 while (leveldir_current->node_parent &&
1546 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1548 /* write a "path" into level tree for easy navigation to last level */
1549 if (leveldir_current->node_parent->node_group->cl_first == -1)
1551 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1552 int leveldir_pos = posTreeInfo(leveldir_current);
1553 int num_page_entries;
1554 int cl_first, cl_cursor;
1556 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1557 num_page_entries = num_leveldirs;
1559 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1561 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1562 cl_cursor = leveldir_pos - cl_first;
1564 leveldir_current->node_parent->node_group->cl_first = cl_first;
1565 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1568 leveldir_current = leveldir_current->node_parent;
1572 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1574 static unsigned int title_delay = 0;
1575 static int title_screen_nr = 0;
1576 static int last_sound = -1, last_music = -1;
1577 boolean return_to_main_menu = FALSE;
1578 struct TitleControlInfo *tci;
1581 if (button == MB_MENU_INITIALIZE)
1584 title_screen_nr = 0;
1585 tci = &title_controls[title_screen_nr];
1587 SetAnimStatus(getTitleAnimMode(tci));
1589 last_sound = SND_UNDEFINED;
1590 last_music = MUS_UNDEFINED;
1592 if (num_title_screens != 0)
1594 FadeSetEnterScreen();
1596 /* use individual title fading instead of global "enter screen" fading */
1597 fading = getTitleFading(tci);
1600 if (game_status_last_screen == GAME_MODE_INFO)
1602 if (num_title_screens == 0)
1604 /* switch game mode from title screen mode back to info screen mode */
1605 SetGameStatus(GAME_MODE_INFO);
1607 /* store that last screen was info screen, not main menu screen */
1608 game_status_last_screen = GAME_MODE_INFO;
1610 DrawInfoScreen_NotAvailable("Title screen information:",
1611 "No title screen for this level set.");
1615 FadeMenuSoundsAndMusic();
1618 FadeOut(REDRAW_ALL);
1620 /* title screens may have different window size */
1621 ChangeViewportPropertiesIfNeeded();
1623 /* only required to update logic for redrawing global border */
1627 DrawTitleScreenImage(tci->local_nr, tci->initial);
1629 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1631 sound = getTitleSound(tci);
1632 music = getTitleMusic(tci);
1634 if (sound != last_sound)
1635 PlayMenuSoundExt(sound);
1636 if (music != last_music)
1637 PlayMenuMusicExt(music);
1642 SetMouseCursor(CURSOR_NONE);
1646 DelayReached(&title_delay, 0); /* reset delay counter */
1651 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1652 button = MB_MENU_CHOICE;
1654 if (button == MB_MENU_LEAVE)
1656 return_to_main_menu = TRUE;
1658 else if (button == MB_MENU_CHOICE)
1660 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1662 SetGameStatus(GAME_MODE_INFO);
1664 info_mode = INFO_MODE_MAIN;
1673 if (title_screen_nr < num_title_screens)
1675 tci = &title_controls[title_screen_nr];
1677 SetAnimStatus(getTitleAnimMode(tci));
1679 sound = getTitleSound(tci);
1680 music = getTitleMusic(tci);
1682 if (last_sound != SND_UNDEFINED && sound != last_sound)
1683 FadeSound(last_sound);
1684 if (last_music != MUS_UNDEFINED && music != last_music)
1687 fading = getTitleFading(tci);
1689 FadeOut(REDRAW_ALL);
1692 DrawTitleScreenImage(tci->local_nr, tci->initial);
1694 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1696 sound = getTitleSound(tci);
1697 music = getTitleMusic(tci);
1699 if (sound != last_sound)
1700 PlayMenuSoundExt(sound);
1701 if (music != last_music)
1702 PlayMenuMusicExt(music);
1709 DelayReached(&title_delay, 0); /* reset delay counter */
1713 FadeMenuSoundsAndMusic();
1715 return_to_main_menu = TRUE;
1719 if (return_to_main_menu)
1721 SetMouseCursor(CURSOR_DEFAULT);
1723 /* force full menu screen redraw after displaying title screens */
1724 redraw_mask = REDRAW_ALL;
1726 if (game_status_last_screen == GAME_MODE_INFO)
1728 SetGameStatus(GAME_MODE_INFO);
1730 info_mode = INFO_MODE_MAIN;
1734 else /* default: return to main menu */
1736 SetGameStatus(GAME_MODE_MAIN);
1743 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1745 int old_level_nr = level_nr;
1748 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1749 new_level_nr = selected_level_nr;
1751 new_level_nr = old_level_nr + step * direction;
1753 if (new_level_nr < leveldir_current->first_level)
1754 new_level_nr = leveldir_current->first_level;
1755 if (new_level_nr > leveldir_current->last_level)
1756 new_level_nr = leveldir_current->last_level;
1758 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1760 /* skipping levels is only allowed when trying to skip single level */
1761 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1762 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1764 leveldir_current->handicap_level++;
1765 SaveLevelSetup_SeriesInfo();
1768 new_level_nr = leveldir_current->handicap_level;
1771 if (new_level_nr != old_level_nr)
1773 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1775 PlaySound(SND_MENU_ITEM_SELECTING);
1777 level_nr = new_level_nr;
1779 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1780 int2str(level_nr, menu.main.text.level_number.size),
1781 mci->pos_text->font);
1783 LoadLevel(level_nr);
1784 DrawPreviewLevelInitial();
1788 DrawCompleteVideoDisplay();
1790 SaveLevelSetup_SeriesInfo();
1792 /* needed because DrawPreviewLevelInitial() takes some time */
1794 /* SyncDisplay(); */
1798 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1800 static int choice = MAIN_CONTROL_GAME;
1801 static boolean button_pressed_last = FALSE;
1802 boolean button_pressed = FALSE;
1806 if (button == MB_MENU_INITIALIZE)
1808 DrawCursorAndText_Main(choice, TRUE, FALSE);
1813 if (mx || my) /* mouse input */
1817 for (i = 0; main_controls[i].nr != -1; i++)
1819 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1820 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1821 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1823 pos = main_controls[i].nr;
1829 /* check if level preview was clicked */
1830 if (insidePreviewRect(&preview, mx - SX, my - SY))
1831 pos = MAIN_CONTROL_GAME;
1833 // handle pressed/unpressed state for active/inactive menu buttons
1834 // (if pos != -1, "i" contains index position corresponding to "pos")
1836 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1837 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1838 button_pressed = TRUE;
1840 if (button_pressed != button_pressed_last)
1842 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1845 PlaySound(SND_MENU_BUTTON_PRESSING);
1847 PlaySound(SND_MENU_BUTTON_RELEASING);
1850 else if (dx || dy) /* keyboard input */
1852 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1853 choice == MAIN_CONTROL_SETUP))
1854 button = MB_MENU_CHOICE;
1859 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1861 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1863 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1865 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1867 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1869 CloseDoor(DOOR_CLOSE_2);
1871 SetGameStatus(GAME_MODE_LEVELNR);
1873 DrawChooseLevelNr();
1875 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1881 PlaySound(SND_MENU_ITEM_ACTIVATING);
1883 DrawCursorAndText_Main(choice, FALSE, FALSE);
1884 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1890 if (choice != MAIN_CONTROL_INFO &&
1891 choice != MAIN_CONTROL_SETUP)
1892 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
1897 PlaySound(SND_MENU_ITEM_SELECTING);
1899 if (pos == MAIN_CONTROL_NAME)
1901 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1903 HandleTypeName(strlen(setup.player_name), 0);
1905 else if (pos == MAIN_CONTROL_LEVELS)
1909 CloseDoor(DOOR_CLOSE_2);
1911 SetGameStatus(GAME_MODE_LEVELS);
1913 SaveLevelSetup_LastSeries();
1914 SaveLevelSetup_SeriesInfo();
1916 if (setup.internal.choose_from_top_leveldir)
1919 DrawChooseLevelSet();
1922 else if (pos == MAIN_CONTROL_SCORES)
1924 CloseDoor(DOOR_CLOSE_2);
1926 SetGameStatus(GAME_MODE_SCORES);
1930 else if (pos == MAIN_CONTROL_EDITOR)
1932 if (leveldir_current->readonly &&
1933 !strEqual(setup.player_name, "Artsoft"))
1934 Request("This level is read only!", REQ_CONFIRM);
1936 CloseDoor(DOOR_CLOSE_2);
1938 SetGameStatus(GAME_MODE_EDITOR);
1940 FadeSetEnterScreen();
1944 else if (pos == MAIN_CONTROL_INFO)
1946 CloseDoor(DOOR_CLOSE_2);
1948 SetGameStatus(GAME_MODE_INFO);
1950 info_mode = INFO_MODE_MAIN;
1954 else if (pos == MAIN_CONTROL_GAME)
1956 StartGameActions(options.network, setup.autorecord, level.random_seed);
1958 else if (pos == MAIN_CONTROL_SETUP)
1960 CloseDoor(DOOR_CLOSE_2);
1962 SetGameStatus(GAME_MODE_SETUP);
1964 setup_mode = SETUP_MODE_MAIN;
1968 else if (pos == MAIN_CONTROL_QUIT)
1970 SaveLevelSetup_LastSeries();
1971 SaveLevelSetup_SeriesInfo();
1973 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1974 SetGameStatus(GAME_MODE_QUIT);
1979 button_pressed_last = button_pressed;
1983 /* ========================================================================= */
1984 /* info screen functions */
1985 /* ========================================================================= */
1987 static struct TokenInfo *info_info;
1988 static int num_info_info; /* number of info entries shown on screen */
1989 static int max_info_info; /* total number of info entries in list */
1991 static void execInfoTitleScreen()
1993 info_mode = INFO_MODE_TITLE;
1998 static void execInfoElements()
2000 info_mode = INFO_MODE_ELEMENTS;
2005 static void execInfoMusic()
2007 info_mode = INFO_MODE_MUSIC;
2012 static void execInfoCredits()
2014 info_mode = INFO_MODE_CREDITS;
2019 static void execInfoProgram()
2021 info_mode = INFO_MODE_PROGRAM;
2026 static void execInfoVersion()
2028 info_mode = INFO_MODE_VERSION;
2033 static void execInfoLevelSet()
2035 info_mode = INFO_MODE_LEVELSET;
2040 static void execExitInfo()
2042 SetGameStatus(GAME_MODE_MAIN);
2047 static struct TokenInfo info_info_main[] =
2049 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2050 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2051 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2052 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2053 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2054 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2055 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2056 { TYPE_EMPTY, NULL, "" },
2057 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2062 static int getMenuTextFont(int type)
2064 if (type & (TYPE_SWITCH |
2076 static struct TokenInfo *setup_info;
2077 static struct TokenInfo setup_info_input[];
2079 static struct TokenInfo *menu_info;
2081 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2082 int screen_pos, int menu_info_pos_raw,
2085 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2086 struct TokenInfo *ti = &token_info[pos];
2087 int xpos = MENU_SCREEN_START_XPOS;
2088 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2089 int font_nr = getMenuTextFont(ti->type);
2091 if (token_info == setup_info_input)
2092 font_nr = FONT_MENU_1;
2095 font_nr = FONT_ACTIVE(font_nr);
2097 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2099 if (ti->type & ~TYPE_SKIP_ENTRY)
2100 drawCursor(screen_pos, active);
2103 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2106 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2109 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2112 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2115 static char *window_size_text;
2116 static char *scaling_type_text;
2118 static void drawSetupValue(int, int);
2120 static void drawMenuInfoList(int first_entry, int num_page_entries,
2121 int max_page_entries)
2125 if (first_entry + num_page_entries > max_page_entries)
2128 clearMenuListArea();
2130 for (i = 0; i < num_page_entries; i++)
2132 int menu_info_pos = first_entry + i;
2133 struct TokenInfo *si = &menu_info[menu_info_pos];
2134 void *value_ptr = si->value;
2136 /* set some entries to "unchangeable" according to other variables */
2137 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2138 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2139 (value_ptr == &setup.sound_music && !audio.music_available) ||
2140 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2141 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2142 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2143 si->type |= TYPE_GHOSTED;
2145 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2146 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2147 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2148 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2149 else if (si->type & ~TYPE_SKIP_ENTRY)
2150 initCursor(i, IMG_MENU_BUTTON);
2152 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2154 if (si->type & TYPE_VALUE &&
2155 menu_info == setup_info)
2156 drawSetupValue(i, menu_info_pos);
2160 static void DrawInfoScreen_Main()
2162 int fade_mask = REDRAW_FIELD;
2165 if (redraw_mask & REDRAW_ALL)
2166 fade_mask = REDRAW_ALL;
2168 if (CheckIfGlobalBorderHasChanged())
2169 fade_mask = REDRAW_ALL;
2172 FadeMenuSoundsAndMusic();
2174 FreeScreenGadgets();
2175 CreateScreenGadgets();
2177 /* (needed after displaying title screens which disable auto repeat) */
2178 KeyboardAutoRepeatOn();
2180 FadeSetLeaveScreen();
2184 /* needed if different viewport properties defined for info screen */
2185 ChangeViewportPropertiesIfNeeded();
2187 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2191 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2193 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2195 info_info = info_info_main;
2197 // determine maximal number of info entries that can be displayed on screen
2199 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2202 // determine maximal number of info entries available for menu of info screen
2204 for (i = 0; info_info[i].type != 0; i++)
2207 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2209 MapScreenGadgets(max_info_info);
2211 PlayMenuSoundsAndMusic();
2213 DrawMaskedBorder(fade_mask);
2218 static void changeSetupValue(int, int, int);
2220 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2221 int mode, int num_page_entries, int max_page_entries)
2223 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2224 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2225 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2226 int *num_page_entries_last = num_page_entries_all_last[game_status];
2227 int *choice_store = choice_stores[game_status];
2228 int *first_entry_store = first_entry_stores[game_status];
2229 int choice = choice_store[mode]; /* starts with 0 */
2230 int first_entry = first_entry_store[mode]; /* starts with 0 */
2232 int y = choice - first_entry;
2234 boolean position_set_by_scrollbar = (dx == 999);
2235 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2238 if (button == MB_MENU_INITIALIZE)
2240 // check if number of menu page entries has changed (may happen by change
2241 // of custom artwork definition value for 'list_size' for this menu screen)
2242 // (in this case, the last menu position most probably has to be corrected)
2243 if (num_page_entries != num_page_entries_last[mode])
2245 choice_store[mode] = first_entry_store[mode] = 0;
2247 choice = first_entry = 0;
2250 num_page_entries_last[mode] = num_page_entries;
2253 /* advance to first valid menu entry */
2254 while (choice < num_page_entries &&
2255 menu_info[choice].type & TYPE_SKIP_ENTRY)
2258 if (position_set_by_scrollbar)
2259 first_entry = first_entry_store[mode] = dy;
2261 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2262 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2264 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2266 if (choice < first_entry)
2268 choice = first_entry;
2270 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2273 else if (choice > first_entry + num_page_entries - 1)
2275 choice = first_entry + num_page_entries - 1;
2277 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2281 choice_store[mode] = choice;
2283 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2287 else if (button == MB_MENU_LEAVE)
2289 PlaySound(SND_MENU_ITEM_SELECTING);
2291 for (i = 0; i < max_page_entries; i++)
2293 if (menu_info[i].type & TYPE_LEAVE_MENU)
2295 void (*menu_callback_function)(void) = menu_info[i].value;
2299 menu_callback_function();
2301 break; /* absolutely needed because function changes 'menu_info'! */
2308 if (mx || my) /* mouse input */
2310 x = (mx - mSX) / 32;
2311 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2313 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2315 /* move cursor instead of scrolling when already at start/end of list */
2316 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2318 else if (dy == +1 * SCROLL_LINE &&
2319 first_entry + num_page_entries == max_page_entries)
2322 /* handle scrolling screen one line or page */
2324 y + dy > num_page_entries - 1)
2326 boolean redraw = FALSE;
2328 if (ABS(dy) == SCROLL_PAGE)
2329 step = num_page_entries - 1;
2331 if (dy < 0 && first_entry > 0)
2333 /* scroll page/line up */
2335 first_entry -= step;
2336 if (first_entry < 0)
2341 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2343 /* scroll page/line down */
2345 first_entry += step;
2346 if (first_entry + num_page_entries > max_page_entries)
2347 first_entry = MAX(0, max_page_entries - num_page_entries);
2354 choice += first_entry - first_entry_store[mode];
2356 if (choice < first_entry)
2358 choice = first_entry;
2360 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2363 else if (choice > first_entry + num_page_entries - 1)
2365 choice = first_entry + num_page_entries - 1;
2367 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2370 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2374 if (choice < first_entry ||
2375 choice > first_entry + num_page_entries - 1)
2376 first_entry += SIGN(dy);
2379 first_entry_store[mode] = first_entry;
2380 choice_store[mode] = choice;
2382 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2384 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2386 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2387 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2395 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2397 if (menu_info[choice].type & menu_navigation_type ||
2398 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2399 menu_info[choice].type & TYPE_YES_NO_AUTO)
2400 button = MB_MENU_CHOICE;
2405 /* jump to next non-empty menu entry (up or down) */
2406 while (first_entry + y > 0 &&
2407 first_entry + y < max_page_entries - 1 &&
2408 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2411 if (!IN_VIS_MENU(x, y))
2413 choice += y - y_old;
2415 if (choice < first_entry)
2416 first_entry = choice;
2417 else if (choice > first_entry + num_page_entries - 1)
2418 first_entry = choice - num_page_entries + 1;
2420 if (first_entry >= 0 &&
2421 first_entry + num_page_entries <= max_page_entries)
2423 first_entry_store[mode] = first_entry;
2425 if (choice < first_entry)
2426 choice = first_entry;
2427 else if (choice > first_entry + num_page_entries - 1)
2428 choice = first_entry + num_page_entries - 1;
2430 choice_store[mode] = choice;
2432 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2434 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2436 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2437 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2444 if (!anyScrollbarGadgetActive() &&
2445 IN_VIS_MENU(x, y) &&
2446 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2447 y >= 0 && y < num_page_entries)
2451 if (first_entry + y != choice &&
2452 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2454 PlaySound(SND_MENU_ITEM_ACTIVATING);
2456 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2457 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2459 choice = choice_store[mode] = first_entry + y;
2463 PlaySound(SND_MENU_ITEM_SELECTING);
2465 for (i = 0; menu_info[i].type != 0; i++)
2467 if (menu_info[i].type & TYPE_LEAVE_MENU)
2469 void (*menu_callback_function)(void) = menu_info[i].value;
2473 menu_callback_function();
2475 /* absolutely needed because function changes 'menu_info'! */
2483 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2485 PlaySound(SND_MENU_ITEM_SELECTING);
2487 /* when selecting key headline, execute function for key value change */
2488 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2489 menu_info[first_entry + y + 1].type & TYPE_KEY)
2492 /* when selecting string value, execute function for list selection */
2493 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2494 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2497 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2499 void (*menu_callback_function)(void) =
2500 menu_info[first_entry + y].value;
2502 FadeSetFromType(menu_info[first_entry + y].type);
2504 menu_callback_function();
2506 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2507 menu_info == setup_info)
2509 changeSetupValue(y, first_entry + y, dx);
2515 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2517 menu_info = info_info;
2519 HandleMenuScreen(mx, my, dx, dy, button,
2520 info_mode, num_info_info, max_info_info);
2523 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2525 int ystart1 = mSY - SY + 100;
2526 int ystart2 = mSY - SY + 150;
2527 int ybottom = mSY - SY + SYSIZE - 20;
2529 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2531 FadeOut(REDRAW_FIELD);
2536 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2537 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2539 DrawTextSCentered(ybottom, FONT_TEXT_4,
2540 "Press any key or button for info menu");
2542 FadeIn(REDRAW_FIELD);
2545 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2547 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2548 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2549 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2550 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2551 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2552 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2553 int ystep = MENU_SCREEN_INFO_YSTEP;
2554 int element, action, direction;
2562 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2563 infoscreen_step[i] = infoscreen_frame[i] = 0;
2568 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2570 DrawTextSCentered(ybottom, FONT_TEXT_4,
2571 "Press any key or button for next page");
2577 while (helpanim_info[j].element != HELPANIM_LIST_END)
2579 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2584 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2593 j += infoscreen_step[i - start];
2595 element = helpanim_info[j].element;
2596 action = helpanim_info[j].action;
2597 direction = helpanim_info[j].direction;
2600 element = EL_UNKNOWN;
2602 if (action != -1 && direction != -1)
2603 graphic = el_act_dir2img(element, action, direction);
2604 else if (action != -1)
2605 graphic = el_act2img(element, action);
2606 else if (direction != -1)
2607 graphic = el_dir2img(element, direction);
2609 graphic = el2img(element);
2611 delay = helpanim_info[j++].delay;
2616 if (infoscreen_frame[i - start] == 0)
2619 infoscreen_frame[i - start] = delay - 1;
2623 sync_frame = delay - infoscreen_frame[i - start];
2624 infoscreen_frame[i - start]--;
2627 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2629 if (!infoscreen_frame[i - start])
2630 infoscreen_step[i - start] = 0;
2634 if (!infoscreen_frame[i - start])
2635 infoscreen_step[i - start]++;
2636 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2642 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2644 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2645 graphic, sync_frame, USE_MASKING);
2648 DrawInfoScreen_HelpText(element, action, direction, i - start);
2653 redraw_mask |= REDRAW_FIELD;
2658 static char *getHelpText(int element, int action, int direction)
2660 char token[MAX_LINE_LEN];
2662 strcpy(token, element_info[element].token_name);
2665 strcat(token, element_action_info[action].suffix);
2667 if (direction != -1)
2668 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2670 return getHashEntry(helptext_info, token);
2673 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2675 int font_nr = FONT_INFO_ELEMENTS;
2676 int font_width = getFontWidth(font_nr);
2677 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2678 int sy = mSY + 65 + 2 * 32 + 1;
2679 int ystep = TILEY + 4;
2680 int pad_x = sx - SX;
2681 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2682 int max_lines_per_text = 2;
2685 if (action != -1 && direction != -1) /* element.action.direction */
2686 text = getHelpText(element, action, direction);
2688 if (text == NULL && action != -1) /* element.action */
2689 text = getHelpText(element, action, -1);
2691 if (text == NULL && direction != -1) /* element.direction */
2692 text = getHelpText(element, -1, direction);
2694 if (text == NULL) /* base element */
2695 text = getHelpText(element, -1, -1);
2697 if (text == NULL) /* not found */
2698 text = "No description available";
2700 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2701 sy += getFontHeight(font_nr) / 2;
2703 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2704 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2705 TRUE, FALSE, FALSE);
2708 void DrawInfoScreen_TitleScreen()
2710 SetGameStatus(GAME_MODE_TITLE);
2715 void HandleInfoScreen_TitleScreen(int button)
2717 HandleTitleScreen(0, 0, 0, 0, button);
2720 void DrawInfoScreen_Elements()
2722 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2724 FadeOut(REDRAW_FIELD);
2729 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2731 FadeIn(REDRAW_FIELD);
2734 void HandleInfoScreen_Elements(int button)
2736 static unsigned int info_delay = 0;
2737 static int num_anims;
2738 static int num_pages;
2740 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2743 if (button == MB_MENU_INITIALIZE)
2745 boolean new_element = TRUE;
2749 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2751 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2753 else if (new_element)
2756 new_element = FALSE;
2760 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2764 if (button == MB_MENU_LEAVE)
2766 PlaySound(SND_MENU_ITEM_SELECTING);
2768 info_mode = INFO_MODE_MAIN;
2773 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2775 if (button != MB_MENU_INITIALIZE)
2777 PlaySound(SND_MENU_ITEM_SELECTING);
2782 if (page >= num_pages)
2784 FadeMenuSoundsAndMusic();
2786 info_mode = INFO_MODE_MAIN;
2793 FadeSetNextScreen();
2795 if (button != MB_MENU_INITIALIZE)
2796 FadeOut(REDRAW_FIELD);
2798 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2800 if (button != MB_MENU_INITIALIZE)
2801 FadeIn(REDRAW_FIELD);
2805 if (DelayReached(&info_delay, GameFrameDelay))
2806 if (page < num_pages)
2807 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2809 PlayMenuSoundIfLoop();
2813 void DrawInfoScreen_Music()
2815 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2817 FadeOut(REDRAW_FIELD);
2824 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2826 FadeIn(REDRAW_FIELD);
2829 void HandleInfoScreen_Music(int button)
2831 static struct MusicFileInfo *list = NULL;
2832 int ystart1 = mSY - SY + 100;
2833 int ystart2 = mSY - SY + 150;
2834 int ybottom = mSY - SY + SYSIZE - 20;
2837 if (button == MB_MENU_INITIALIZE)
2839 list = music_file_info;
2843 FadeMenuSoundsAndMusic();
2848 DrawTextSCentered(ystart1, FONT_TEXT_1,
2849 "No music info for this level set.");
2851 DrawTextSCentered(ybottom, FONT_TEXT_4,
2852 "Press any key or button for info menu");
2858 if (button == MB_MENU_LEAVE)
2860 PlaySound(SND_MENU_ITEM_SELECTING);
2862 FadeMenuSoundsAndMusic();
2864 info_mode = INFO_MODE_MAIN;
2869 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2873 if (button != MB_MENU_INITIALIZE)
2875 PlaySound(SND_MENU_ITEM_SELECTING);
2883 FadeMenuSoundsAndMusic();
2885 info_mode = INFO_MODE_MAIN;
2891 FadeMenuSoundsAndMusic();
2893 if (list != music_file_info)
2894 FadeSetNextScreen();
2896 if (button != MB_MENU_INITIALIZE)
2897 FadeOut(REDRAW_FIELD);
2904 int sound = list->music;
2906 if (sound_info[sound].loop)
2907 PlaySoundLoop(sound);
2911 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2915 PlayMusic(list->music);
2917 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2920 if (!strEqual(list->title, UNKNOWN_NAME))
2922 if (!strEqual(list->title_header, UNKNOWN_NAME))
2923 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2925 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2928 if (!strEqual(list->artist, UNKNOWN_NAME))
2930 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2931 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2933 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2935 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2938 if (!strEqual(list->album, UNKNOWN_NAME))
2940 if (!strEqual(list->album_header, UNKNOWN_NAME))
2941 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2943 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2945 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2948 if (!strEqual(list->year, UNKNOWN_NAME))
2950 if (!strEqual(list->year_header, UNKNOWN_NAME))
2951 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2953 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2955 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2958 DrawTextSCentered(ybottom, FONT_TEXT_4,
2959 "Press any key or button for next page");
2961 if (button != MB_MENU_INITIALIZE)
2962 FadeIn(REDRAW_FIELD);
2965 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2966 PlaySoundLoop(list->music);
2969 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2971 int ystart1 = mSY - SY + 100;
2972 int ystart2 = mSY - SY + 150;
2973 int ybottom = mSY - SY + SYSIZE - 20;
2979 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2983 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2984 "Special thanks to");
2985 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2987 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2989 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2990 "\"Boulder Dash\"");
2991 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2993 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2995 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2997 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2998 "First Star Software");
3000 else if (screen_nr == 1)
3002 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3003 "Special thanks to");
3004 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3005 "Klaus Heinz & Volker Wertich");
3006 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3008 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3009 "\"Emerald Mine\"");
3010 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3012 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3016 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3019 else if (screen_nr == 2)
3021 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3022 "Special thanks to");
3023 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3024 "Michael Stopp & Philip Jespersen");
3025 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3027 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3029 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3031 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3033 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3035 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3036 "Digital Integration");
3038 else if (screen_nr == 3)
3040 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3041 "Special thanks to");
3042 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3043 "Hiroyuki Imabayashi");
3044 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3046 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3048 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3050 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3052 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3054 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3057 else if (screen_nr == 4)
3059 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3060 "Special thanks to");
3061 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3063 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3065 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3066 "J\xfcrgen Bonhagen");
3067 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3068 "for the continuous creation");
3069 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3070 "of outstanding level sets");
3072 else if (screen_nr == 5)
3074 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3076 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3078 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3079 "for ideas and inspiration by");
3080 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3083 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3085 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3087 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3088 "for ideas and inspiration by");
3089 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3092 else if (screen_nr == 6)
3094 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3096 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3099 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3100 "for the code base used for the");
3101 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3102 "native Emerald Mine engine");
3104 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3105 "for the new Emerald Mine engine");
3108 else if (screen_nr == 7)
3110 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3112 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3114 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3115 "for the initial DOS port");
3117 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3119 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3121 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3122 "for some additional toons");
3124 else if (screen_nr == 8)
3126 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3127 "And not to forget:");
3128 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3130 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3131 "All those who contributed");
3132 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3133 "levels to this game");
3134 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3138 DrawTextSCentered(ybottom, FONT_TEXT_4,
3139 "Press any key or button for next page");
3142 void DrawInfoScreen_Credits()
3144 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3146 FadeMenuSoundsAndMusic();
3148 FadeOut(REDRAW_FIELD);
3150 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3152 FadeIn(REDRAW_FIELD);
3155 void HandleInfoScreen_Credits(int button)
3157 static int screen_nr = 0;
3158 int num_screens = 9;
3160 if (button == MB_MENU_INITIALIZE)
3164 // DrawInfoScreen_CreditsScreen(screen_nr);
3167 if (button == MB_MENU_LEAVE)
3169 PlaySound(SND_MENU_ITEM_SELECTING);
3171 info_mode = INFO_MODE_MAIN;
3176 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3178 if (button != MB_MENU_INITIALIZE)
3180 PlaySound(SND_MENU_ITEM_SELECTING);
3185 if (screen_nr >= num_screens)
3187 FadeMenuSoundsAndMusic();
3189 info_mode = INFO_MODE_MAIN;
3196 FadeSetNextScreen();
3198 if (button != MB_MENU_INITIALIZE)
3199 FadeOut(REDRAW_FIELD);
3201 DrawInfoScreen_CreditsScreen(screen_nr);
3203 if (button != MB_MENU_INITIALIZE)
3204 FadeIn(REDRAW_FIELD);
3208 PlayMenuSoundIfLoop();
3212 void DrawInfoScreen_Program()
3214 int ystart1 = mSY - SY + 100;
3215 int ystart2 = mSY - SY + 150;
3216 int ybottom = mSY - SY + SYSIZE - 20;
3219 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3221 FadeOut(REDRAW_FIELD);
3226 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3228 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3229 "This game is Freeware!");
3230 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3231 "If you like it, send e-mail to:");
3232 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3233 setup.internal.program_email);
3234 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3235 "More information and levels:");
3236 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3237 setup.internal.program_website);
3238 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3239 "If you have created new levels,");
3240 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3241 "send them to me to include them!");
3242 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3245 DrawTextSCentered(ybottom, FONT_TEXT_4,
3246 "Press any key or button for info menu");
3248 FadeIn(REDRAW_FIELD);
3251 void HandleInfoScreen_Program(int button)
3253 if (button == MB_MENU_LEAVE)
3255 PlaySound(SND_MENU_ITEM_SELECTING);
3257 info_mode = INFO_MODE_MAIN;
3262 else if (button == MB_MENU_CHOICE)
3264 PlaySound(SND_MENU_ITEM_SELECTING);
3266 FadeMenuSoundsAndMusic();
3268 info_mode = INFO_MODE_MAIN;
3273 PlayMenuSoundIfLoop();
3277 void DrawInfoScreen_Version()
3279 int font_header = FONT_TEXT_3;
3280 int font_text = FONT_TEXT_2;
3281 int xstep = getFontWidth(font_text);
3282 int ystep = getFontHeight(font_text);
3283 int ystart1 = mSY - SY + 100;
3284 int ystart2 = mSY - SY + 150;
3285 int ybottom = mSY - SY + SYSIZE - 20;
3286 int xstart1 = mSX - SX + 2 * xstep;
3287 int xstart2 = mSX - SX + 18 * xstep;
3288 int xstart3 = mSX - SX + 28 * xstep;
3289 SDL_version sdl_version_compiled;
3290 const SDL_version *sdl_version_linked;
3291 int driver_name_len = 10;
3292 #if defined(TARGET_SDL2)
3293 SDL_version sdl_version_linked_ext;
3294 const char *driver_name = NULL;
3296 char driver_name[driver_name_len];
3299 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3301 FadeOut(REDRAW_FIELD);
3306 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3308 DrawTextF(xstart1, ystart2, font_header, "Name");
3309 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3312 DrawTextF(xstart1, ystart2, font_header, "Version");
3313 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3315 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3318 DrawTextF(xstart1, ystart2, font_header, "Version (real)");
3319 DrawTextF(xstart2, ystart2, font_text, getProgramRealVersionString());
3323 DrawTextF(xstart1, ystart2, font_header, "Platform");
3324 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3327 DrawTextF(xstart1, ystart2, font_header, "Target");
3328 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3331 DrawTextF(xstart1, ystart2, font_header, "Source date");
3332 DrawTextF(xstart2, ystart2, font_text, getSourceDateString());
3334 ystart2 += 3 * ystep;
3335 DrawTextF(xstart1, ystart2, font_header, "Library");
3336 DrawTextF(xstart2, ystart2, font_header, "compiled");
3337 DrawTextF(xstart3, ystart2, font_header, "linked");
3339 SDL_VERSION(&sdl_version_compiled);
3340 #if defined(TARGET_SDL2)
3341 SDL_GetVersion(&sdl_version_linked_ext);
3342 sdl_version_linked = &sdl_version_linked_ext;
3344 sdl_version_linked = SDL_Linked_Version();
3347 ystart2 += 2 * ystep;
3348 DrawTextF(xstart1, ystart2, font_text, "SDL");
3349 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3350 sdl_version_compiled.major,
3351 sdl_version_compiled.minor,
3352 sdl_version_compiled.patch);
3353 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3354 sdl_version_linked->major,
3355 sdl_version_linked->minor,
3356 sdl_version_linked->patch);
3358 SDL_IMAGE_VERSION(&sdl_version_compiled);
3359 sdl_version_linked = IMG_Linked_Version();
3362 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3363 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3364 sdl_version_compiled.major,
3365 sdl_version_compiled.minor,
3366 sdl_version_compiled.patch);
3367 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3368 sdl_version_linked->major,
3369 sdl_version_linked->minor,
3370 sdl_version_linked->patch);
3372 SDL_MIXER_VERSION(&sdl_version_compiled);
3373 sdl_version_linked = Mix_Linked_Version();
3376 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3377 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3378 sdl_version_compiled.major,
3379 sdl_version_compiled.minor,
3380 sdl_version_compiled.patch);
3381 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3382 sdl_version_linked->major,
3383 sdl_version_linked->minor,
3384 sdl_version_linked->patch);
3386 SDL_NET_VERSION(&sdl_version_compiled);
3387 sdl_version_linked = SDLNet_Linked_Version();
3390 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3391 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3392 sdl_version_compiled.major,
3393 sdl_version_compiled.minor,
3394 sdl_version_compiled.patch);
3395 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3396 sdl_version_linked->major,
3397 sdl_version_linked->minor,
3398 sdl_version_linked->patch);
3400 ystart2 += 3 * ystep;
3401 DrawTextF(xstart1, ystart2, font_header, "Driver");
3402 DrawTextF(xstart2, ystart2, font_header, "Requested");
3403 DrawTextF(xstart3, ystart2, font_header, "Used");
3405 #if defined(TARGET_SDL2)
3406 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3408 SDL_VideoDriverName(driver_name, driver_name_len);
3411 ystart2 += 2 * ystep;
3412 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3413 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3414 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3416 #if defined(TARGET_SDL2)
3417 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3419 SDL_AudioDriverName(driver_name, driver_name_len);
3423 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3424 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3425 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3427 DrawTextSCentered(ybottom, FONT_TEXT_4,
3428 "Press any key or button for info menu");
3430 FadeIn(REDRAW_FIELD);
3433 void HandleInfoScreen_Version(int button)
3435 if (button == MB_MENU_LEAVE)
3437 PlaySound(SND_MENU_ITEM_SELECTING);
3439 info_mode = INFO_MODE_MAIN;
3444 else if (button == MB_MENU_CHOICE)
3446 PlaySound(SND_MENU_ITEM_SELECTING);
3448 FadeMenuSoundsAndMusic();
3450 info_mode = INFO_MODE_MAIN;
3455 PlayMenuSoundIfLoop();
3459 void DrawInfoScreen_LevelSet()
3461 struct TitleMessageInfo *tmi = &readme;
3462 char *filename = getLevelSetInfoFilename();
3463 char *title = "Level Set Information:";
3464 int ystart1 = mSY - SY + 100;
3465 int ybottom = mSY - SY + SYSIZE - 20;
3467 if (filename == NULL)
3469 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3474 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3476 FadeOut(REDRAW_FIELD);
3481 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3483 /* if x position set to "-1", automatically determine by playfield width */
3485 tmi->x = SXSIZE / 2;
3487 /* if y position set to "-1", use static default value */
3491 /* if width set to "-1", automatically determine by playfield width */
3492 if (tmi->width == -1)
3493 tmi->width = SXSIZE - 2 * TILEX;
3495 /* if height set to "-1", automatically determine by playfield height */
3496 if (tmi->height == -1)
3497 tmi->height = SYSIZE - 20 - tmi->y - 10;
3499 /* if chars set to "-1", automatically determine by text and font width */
3500 if (tmi->chars == -1)
3501 tmi->chars = tmi->width / getFontWidth(tmi->font);
3503 tmi->width = tmi->chars * getFontWidth(tmi->font);
3505 /* if lines set to "-1", automatically determine by text and font height */
3506 if (tmi->lines == -1)
3507 tmi->lines = tmi->height / getFontHeight(tmi->font);
3509 tmi->height = tmi->lines * getFontHeight(tmi->font);
3511 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3512 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3513 tmi->autowrap, tmi->centered, tmi->parse_comments);
3515 DrawTextSCentered(ybottom, FONT_TEXT_4,
3516 "Press any key or button for info menu");
3518 FadeIn(REDRAW_FIELD);
3521 void HandleInfoScreen_LevelSet(int button)
3523 if (button == MB_MENU_LEAVE)
3525 PlaySound(SND_MENU_ITEM_SELECTING);
3527 info_mode = INFO_MODE_MAIN;
3532 else if (button == MB_MENU_CHOICE)
3534 PlaySound(SND_MENU_ITEM_SELECTING);
3536 FadeMenuSoundsAndMusic();
3538 info_mode = INFO_MODE_MAIN;
3543 PlayMenuSoundIfLoop();
3547 static void DrawInfoScreen()
3549 if (info_mode == INFO_MODE_TITLE)
3550 DrawInfoScreen_TitleScreen();
3551 else if (info_mode == INFO_MODE_ELEMENTS)
3552 DrawInfoScreen_Elements();
3553 else if (info_mode == INFO_MODE_MUSIC)
3554 DrawInfoScreen_Music();
3555 else if (info_mode == INFO_MODE_CREDITS)
3556 DrawInfoScreen_Credits();
3557 else if (info_mode == INFO_MODE_PROGRAM)
3558 DrawInfoScreen_Program();
3559 else if (info_mode == INFO_MODE_VERSION)
3560 DrawInfoScreen_Version();
3561 else if (info_mode == INFO_MODE_LEVELSET)
3562 DrawInfoScreen_LevelSet();
3564 DrawInfoScreen_Main();
3566 if (info_mode != INFO_MODE_MAIN &&
3567 info_mode != INFO_MODE_TITLE &&
3568 info_mode != INFO_MODE_MUSIC)
3569 PlayMenuSoundsAndMusic();
3572 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3574 if (info_mode == INFO_MODE_TITLE)
3575 HandleInfoScreen_TitleScreen(button);
3576 else if (info_mode == INFO_MODE_ELEMENTS)
3577 HandleInfoScreen_Elements(button);
3578 else if (info_mode == INFO_MODE_MUSIC)
3579 HandleInfoScreen_Music(button);
3580 else if (info_mode == INFO_MODE_CREDITS)
3581 HandleInfoScreen_Credits(button);
3582 else if (info_mode == INFO_MODE_PROGRAM)
3583 HandleInfoScreen_Program(button);
3584 else if (info_mode == INFO_MODE_VERSION)
3585 HandleInfoScreen_Version(button);
3586 else if (info_mode == INFO_MODE_LEVELSET)
3587 HandleInfoScreen_LevelSet(button);
3589 HandleInfoScreen_Main(mx, my, dx, dy, button);
3593 /* ========================================================================= */
3594 /* type name functions */
3595 /* ========================================================================= */
3597 void HandleTypeName(int newxpos, Key key)
3599 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3600 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3601 struct TextPosInfo *pos = mci->pos_input;
3602 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3603 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3604 static int xpos = 0;
3605 int font_nr = pos->font;
3606 int font_active_nr = FONT_ACTIVE(font_nr);
3607 int font_width = getFontWidth(font_active_nr);
3608 char key_char = getValidConfigValueChar(getCharFromKey(key));
3609 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3610 boolean is_active = TRUE;
3612 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3616 strcpy(last_player_name, setup.player_name);
3620 StartTextInput(startx, starty, pos->width, pos->height);
3622 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3624 setup.player_name[xpos] = key_char;
3625 setup.player_name[xpos + 1] = 0;
3629 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3633 setup.player_name[xpos] = 0;
3635 else if (key == KSYM_Return && xpos > 0)
3641 SetGameStatus(GAME_MODE_MAIN);
3643 else if (key == KSYM_Escape)
3645 strcpy(setup.player_name, last_player_name);
3649 SetGameStatus(GAME_MODE_MAIN);
3654 pos->width = (strlen(setup.player_name) + 1) * font_width;
3655 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3657 DrawText(startx, starty, setup.player_name, font_active_nr);
3658 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3662 pos->width = strlen(setup.player_name) * font_width;
3663 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3665 DrawText(startx, starty, setup.player_name, font_nr);
3672 /* ========================================================================= */
3673 /* tree menu functions */
3674 /* ========================================================================= */
3676 static void DrawChooseTree(TreeInfo **ti_ptr)
3678 int fade_mask = REDRAW_FIELD;
3680 if (CheckIfGlobalBorderHasChanged())
3681 fade_mask = REDRAW_ALL;
3683 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3685 SetGameStatus(GAME_MODE_MAIN);
3694 FreeScreenGadgets();
3695 CreateScreenGadgets();
3699 /* needed if different viewport properties defined for choosing level (set) */
3700 ChangeViewportPropertiesIfNeeded();
3702 if (game_status == GAME_MODE_LEVELNR)
3703 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3704 else if (game_status == GAME_MODE_LEVELS)
3705 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3709 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3711 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3712 MapScreenTreeGadgets(*ti_ptr);
3714 DrawMaskedBorder(fade_mask);
3719 static void drawChooseTreeList(int first_entry, int num_page_entries,
3723 char *title_string = NULL;
3724 int yoffset_sets = MENU_TITLE1_YPOS;
3725 int yoffset_setup = 16;
3726 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3727 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3729 title_string = ti->infotext;
3731 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3733 clearMenuListArea();
3735 for (i = 0; i < num_page_entries; i++)
3737 TreeInfo *node, *node_first;
3738 int entry_pos = first_entry + i;
3739 int xpos = MENU_SCREEN_START_XPOS;
3740 int ypos = MENU_SCREEN_START_YPOS + i;
3741 int startx = mSX + xpos * 32;
3742 int starty = mSY + ypos * 32;
3743 int font_nr = FONT_TEXT_1;
3744 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3745 int startx_text = startx + font_xoffset;
3746 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3747 int text_size = startx_scrollbar - startx_text;
3748 int max_buffer_len = text_size / getFontWidth(font_nr);
3749 char buffer[max_buffer_len + 1];
3751 node_first = getTreeInfoFirstGroupEntry(ti);
3752 node = getTreeInfoFromPos(node_first, entry_pos);
3754 strncpy(buffer, node->name, max_buffer_len);
3755 buffer[max_buffer_len] = '\0';
3757 DrawText(startx, starty, buffer, font_nr + node->color);
3759 if (node->parent_link)
3760 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3761 else if (node->level_group)
3762 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3764 initCursor(i, IMG_MENU_BUTTON);
3767 redraw_mask |= REDRAW_FIELD;
3770 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3772 TreeInfo *node, *node_first;
3773 int x, last_redraw_mask = redraw_mask;
3774 int ypos = MENU_TITLE2_YPOS;
3775 int font_nr = FONT_TITLE_2;
3777 if (ti->type == TREE_TYPE_LEVEL_NR)
3778 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3780 if (ti->type != TREE_TYPE_LEVEL_DIR)
3783 node_first = getTreeInfoFirstGroupEntry(ti);
3784 node = getTreeInfoFromPos(node_first, entry_pos);
3786 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3788 if (node->parent_link)
3789 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3790 node->node_parent->name);
3791 else if (node->level_group)
3792 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3794 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3795 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3796 node->levels, (node->levels > 1 ? "levels" : "level"),
3799 /* let BackToFront() redraw only what is needed */
3800 redraw_mask = last_redraw_mask;
3801 for (x = 0; x < SCR_FIELDX; x++)
3802 MarkTileDirty(x, 1);
3805 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3808 TreeInfo *ti = *ti_ptr;
3810 int y = ti->cl_cursor;
3811 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3812 int num_entries = numTreeInfoInGroup(ti);
3813 int num_page_entries;
3814 boolean position_set_by_scrollbar = (dx == 999);
3816 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3817 num_page_entries = num_entries;
3819 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3821 if (button == MB_MENU_INITIALIZE)
3823 int num_entries = numTreeInfoInGroup(ti);
3824 int entry_pos = posTreeInfo(ti);
3826 if (ti->cl_first == -1)
3828 /* only on initialization */
3829 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3830 ti->cl_cursor = entry_pos - ti->cl_first;
3832 else if (ti->cl_cursor >= num_page_entries ||
3833 (num_entries > num_page_entries &&
3834 num_entries - ti->cl_first < num_page_entries))
3836 /* only after change of list size (by custom graphic configuration) */
3837 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3838 ti->cl_cursor = entry_pos - ti->cl_first;
3841 if (position_set_by_scrollbar)
3844 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3847 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3848 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3849 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3853 else if (button == MB_MENU_LEAVE)
3857 PlaySound(SND_MENU_ITEM_SELECTING);
3859 if (ti->node_parent)
3861 *ti_ptr = ti->node_parent;
3862 DrawChooseTree(ti_ptr);
3864 else if (game_status == GAME_MODE_SETUP)
3866 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3867 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3868 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3870 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3871 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
3872 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
3873 execSetupGraphics();
3874 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3875 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3876 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3878 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3879 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3880 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3887 if (game_status == GAME_MODE_LEVELNR)
3889 int new_level_nr = atoi(level_number_current->identifier);
3891 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3894 SetGameStatus(GAME_MODE_MAIN);
3902 if (mx || my) /* mouse input */
3904 x = (mx - mSX) / 32;
3905 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3907 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3909 /* move cursor instead of scrolling when already at start/end of list */
3910 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3912 else if (dy == +1 * SCROLL_LINE &&
3913 ti->cl_first + num_page_entries == num_entries)
3916 /* handle scrolling screen one line or page */
3917 if (ti->cl_cursor + dy < 0 ||
3918 ti->cl_cursor + dy > num_page_entries - 1)
3920 boolean redraw = FALSE;
3922 if (ABS(dy) == SCROLL_PAGE)
3923 step = num_page_entries - 1;
3925 if (dy < 0 && ti->cl_first > 0)
3927 /* scroll page/line up */
3929 ti->cl_first -= step;
3930 if (ti->cl_first < 0)
3935 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3937 /* scroll page/line down */
3939 ti->cl_first += step;
3940 if (ti->cl_first + num_page_entries > num_entries)
3941 ti->cl_first = MAX(0, num_entries - num_page_entries);
3948 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3949 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3950 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3952 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3959 /* handle moving cursor one line */
3960 y = ti->cl_cursor + dy;
3965 TreeInfo *node_first, *node_cursor;
3966 int entry_pos = ti->cl_first + y;
3968 node_first = getTreeInfoFirstGroupEntry(ti);
3969 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3971 if (node_cursor->node_group)
3975 PlaySound(SND_MENU_ITEM_SELECTING);
3977 node_cursor->cl_first = ti->cl_first;
3978 node_cursor->cl_cursor = ti->cl_cursor;
3979 *ti_ptr = node_cursor->node_group;
3980 DrawChooseTree(ti_ptr);
3985 else if (dx == -1 && ti->node_parent)
3989 PlaySound(SND_MENU_ITEM_SELECTING);
3991 *ti_ptr = ti->node_parent;
3992 DrawChooseTree(ti_ptr);
3997 if (!anyScrollbarGadgetActive() &&
3998 IN_VIS_MENU(x, y) &&
3999 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4000 y >= 0 && y < num_page_entries)
4004 if (y != ti->cl_cursor)
4006 PlaySound(SND_MENU_ITEM_ACTIVATING);
4008 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4009 drawChooseTreeCursor(y, TRUE);
4010 drawChooseTreeInfo(ti->cl_first + y, ti);
4016 if (game_status == GAME_MODE_SETUP)
4018 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4019 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4020 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4022 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4023 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4024 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4025 execSetupGraphics();
4026 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4027 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4028 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4030 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4031 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4032 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4041 TreeInfo *node_first, *node_cursor;
4042 int entry_pos = ti->cl_first + y;
4044 PlaySound(SND_MENU_ITEM_SELECTING);
4046 node_first = getTreeInfoFirstGroupEntry(ti);
4047 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4049 if (node_cursor->node_group)
4053 node_cursor->cl_first = ti->cl_first;
4054 node_cursor->cl_cursor = ti->cl_cursor;
4055 *ti_ptr = node_cursor->node_group;
4056 DrawChooseTree(ti_ptr);
4058 else if (node_cursor->parent_link)
4062 *ti_ptr = node_cursor->node_parent;
4063 DrawChooseTree(ti_ptr);
4069 node_cursor->cl_first = ti->cl_first;
4070 node_cursor->cl_cursor = ti->cl_cursor;
4071 *ti_ptr = node_cursor;
4073 if (ti->type == TREE_TYPE_LEVEL_DIR)
4075 LoadLevelSetup_SeriesInfo();
4077 SaveLevelSetup_LastSeries();
4078 SaveLevelSetup_SeriesInfo();
4082 if (game_status == GAME_MODE_SETUP)
4084 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4085 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4086 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4088 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4089 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4090 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4091 execSetupGraphics();
4092 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4093 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4094 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4096 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4097 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4098 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4105 if (game_status == GAME_MODE_LEVELNR)
4107 int new_level_nr = atoi(level_number_current->identifier);
4109 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4112 SetGameStatus(GAME_MODE_MAIN);
4121 void DrawChooseLevelSet()
4123 FadeMenuSoundsAndMusic();
4125 DrawChooseTree(&leveldir_current);
4127 PlayMenuSoundsAndMusic();
4130 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4132 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4135 void DrawChooseLevelNr()
4139 FadeMenuSoundsAndMusic();
4141 if (level_number != NULL)
4143 freeTreeInfo(level_number);
4145 level_number = NULL;
4148 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4150 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4151 char identifier[32], name[32];
4154 /* temporarily load level info to get level name */
4155 LoadLevelInfoOnly(i);
4157 ti->node_top = &level_number;
4158 ti->sort_priority = 10000 + value;
4159 ti->color = (level.no_level_file ? FC_BLUE :
4160 LevelStats_getSolved(i) ? FC_GREEN :
4161 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4163 snprintf(identifier, sizeof(identifier), "%d", value);
4164 snprintf(name, sizeof(name), "%03d: %s", value,
4165 (level.no_level_file ? "(no file)" : level.name));
4167 setString(&ti->identifier, identifier);
4168 setString(&ti->name, name);
4169 setString(&ti->name_sorting, name);
4171 pushTreeInfo(&level_number, ti);
4174 /* sort level number values to start with lowest level number */
4175 sortTreeInfo(&level_number);
4177 /* set current level number to current level number */
4178 level_number_current =
4179 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4181 /* if that also fails, set current level number to first available level */
4182 if (level_number_current == NULL)
4183 level_number_current = level_number;
4185 DrawChooseTree(&level_number_current);
4187 PlayMenuSoundsAndMusic();
4190 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4192 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4195 void DrawHallOfFame(int highlight_position)
4197 int fade_mask = REDRAW_FIELD;
4199 if (CheckIfGlobalBorderHasChanged())
4200 fade_mask = REDRAW_ALL;
4203 FadeMenuSoundsAndMusic();
4205 /* (this is needed when called from GameEnd() after winning a game) */
4206 KeyboardAutoRepeatOn();
4208 /* (this is needed when called from GameEnd() after winning a game) */
4209 SetDrawDeactivationMask(REDRAW_NONE);
4210 SetDrawBackgroundMask(REDRAW_FIELD);
4212 if (highlight_position < 0)
4213 LoadScore(level_nr);
4215 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4217 FadeSetEnterScreen();
4221 /* needed if different viewport properties defined for scores */
4222 ChangeViewportPropertiesIfNeeded();
4224 PlayMenuSoundsAndMusic();
4226 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4228 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4230 DrawMaskedBorder(fade_mask);
4235 static void drawHallOfFameList(int first_entry, int highlight_position)
4239 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4242 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4243 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4244 "HighScores of Level %d", level_nr);
4246 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4248 int entry = first_entry + i;
4249 boolean active = (entry == highlight_position);
4250 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4251 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4252 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4253 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4254 int dxoff = getFontDrawOffsetX(font_nr1);
4255 int dx1 = 3 * getFontWidth(font_nr1);
4256 int dx2 = dx1 + getFontWidth(font_nr1);
4257 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4258 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4259 int sy = mSY + 64 + i * 32;
4261 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4262 DrawText(mSX + dx1, sy, ".", font_nr1);
4264 for (j = 0; j < num_dots; j++)
4265 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4267 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4268 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4270 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4273 redraw_mask |= REDRAW_FIELD;
4276 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4278 static int first_entry = 0;
4279 static int highlight_position = 0;
4280 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4282 if (button == MB_MENU_INITIALIZE)
4285 highlight_position = mx;
4286 drawHallOfFameList(first_entry, highlight_position);
4291 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4292 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4296 if (first_entry > 0)
4298 first_entry -= step;
4299 if (first_entry < 0)
4302 drawHallOfFameList(first_entry, highlight_position);
4307 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4309 first_entry += step;
4310 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4311 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4313 drawHallOfFameList(first_entry, highlight_position);
4316 else if (button == MB_MENU_LEAVE)
4318 PlaySound(SND_MENU_ITEM_SELECTING);
4320 FadeSound(SND_BACKGROUND_SCORES);
4322 SetGameStatus(GAME_MODE_MAIN);
4326 else if (button == MB_MENU_CHOICE)
4328 PlaySound(SND_MENU_ITEM_SELECTING);
4330 FadeSound(SND_BACKGROUND_SCORES);
4332 SetGameStatus(GAME_MODE_MAIN);
4337 if (game_status == GAME_MODE_SCORES)
4338 PlayMenuSoundIfLoop();
4342 /* ========================================================================= */
4343 /* setup screen functions */
4344 /* ========================================================================= */
4346 static struct TokenInfo *setup_info;
4347 static int num_setup_info; /* number of setup entries shown on screen */
4348 static int max_setup_info; /* total number of setup entries in list */
4350 static char *window_size_text;
4351 static char *scaling_type_text;
4352 static char *rendering_mode_text;
4353 static char *scroll_delay_text;
4354 static char *snapshot_mode_text;
4355 static char *game_speed_text;
4356 static char *graphics_set_name;
4357 static char *sounds_set_name;
4358 static char *music_set_name;
4359 static char *volume_simple_text;
4360 static char *volume_loops_text;
4361 static char *volume_music_text;
4362 static char *touch_controls_text;
4363 static char *move_distance_text;
4364 static char *drop_distance_text;
4366 static void execSetupMain()
4368 setup_mode = SETUP_MODE_MAIN;
4373 static void execSetupGame_setGameSpeeds()
4375 if (game_speeds == NULL)
4379 for (i = 0; game_speeds_list[i].value != -1; i++)
4381 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4382 char identifier[32], name[32];
4383 int value = game_speeds_list[i].value;
4384 char *text = game_speeds_list[i].text;
4386 ti->node_top = &game_speeds;
4387 ti->sort_priority = 10000 - value;
4389 sprintf(identifier, "%d", value);
4390 sprintf(name, "%s", text);
4392 setString(&ti->identifier, identifier);
4393 setString(&ti->name, name);
4394 setString(&ti->name_sorting, name);
4395 setString(&ti->infotext, "Game Speed");
4397 pushTreeInfo(&game_speeds, ti);
4400 /* sort game speed values to start with slowest game speed */
4401 sortTreeInfo(&game_speeds);
4403 /* set current game speed to configured game speed value */
4404 game_speed_current =
4405 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4407 /* if that fails, set current game speed to reliable default value */
4408 if (game_speed_current == NULL)
4409 game_speed_current =
4410 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4412 /* if that also fails, set current game speed to first available speed */
4413 if (game_speed_current == NULL)
4414 game_speed_current = game_speeds;
4417 setup.game_frame_delay = atoi(game_speed_current->identifier);
4419 /* needed for displaying game speed text instead of identifier */
4420 game_speed_text = game_speed_current->name;
4423 static void execSetupGame_setScrollDelays()
4425 if (scroll_delays == NULL)
4429 for (i = 0; scroll_delays_list[i].value != -1; i++)
4431 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4432 char identifier[32], name[32];
4433 int value = scroll_delays_list[i].value;
4434 char *text = scroll_delays_list[i].text;
4436 ti->node_top = &scroll_delays;
4437 ti->sort_priority = value;
4439 sprintf(identifier, "%d", value);
4440 sprintf(name, "%s", text);
4442 setString(&ti->identifier, identifier);
4443 setString(&ti->name, name);
4444 setString(&ti->name_sorting, name);
4445 setString(&ti->infotext, "Scroll Delay");
4447 pushTreeInfo(&scroll_delays, ti);
4450 /* sort scroll delay values to start with lowest scroll delay value */
4451 sortTreeInfo(&scroll_delays);
4453 /* set current scroll delay value to configured scroll delay value */
4454 scroll_delay_current =
4455 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4457 /* if that fails, set current scroll delay to reliable default value */
4458 if (scroll_delay_current == NULL)
4459 scroll_delay_current =
4460 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4462 /* if that also fails, set current scroll delay to first available value */
4463 if (scroll_delay_current == NULL)
4464 scroll_delay_current = scroll_delays;
4467 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4469 /* needed for displaying scroll delay text instead of identifier */
4470 scroll_delay_text = scroll_delay_current->name;
4473 static void execSetupGame_setSnapshotModes()
4475 if (snapshot_modes == NULL)
4479 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4481 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4482 char identifier[32], name[32];
4483 char *value = snapshot_modes_list[i].value;
4484 char *text = snapshot_modes_list[i].text;
4486 ti->node_top = &snapshot_modes;
4487 ti->sort_priority = i;
4489 sprintf(identifier, "%s", value);
4490 sprintf(name, "%s", text);
4492 setString(&ti->identifier, identifier);
4493 setString(&ti->name, name);
4494 setString(&ti->name_sorting, name);
4495 setString(&ti->infotext, "Snapshot Mode");
4497 pushTreeInfo(&snapshot_modes, ti);
4500 /* sort snapshot mode values to start with lowest snapshot mode value */
4501 sortTreeInfo(&snapshot_modes);
4503 /* set current snapshot mode value to configured snapshot mode value */
4504 snapshot_mode_current =
4505 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4507 /* if that fails, set current snapshot mode to reliable default value */
4508 if (snapshot_mode_current == NULL)
4509 snapshot_mode_current =
4510 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4512 /* if that also fails, set current snapshot mode to first available value */
4513 if (snapshot_mode_current == NULL)
4514 snapshot_mode_current = snapshot_modes;
4517 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4519 /* needed for displaying snapshot mode text instead of identifier */
4520 snapshot_mode_text = snapshot_mode_current->name;
4523 static void execSetupGame()
4525 execSetupGame_setGameSpeeds();
4526 execSetupGame_setScrollDelays();
4527 execSetupGame_setSnapshotModes();
4529 setup_mode = SETUP_MODE_GAME;
4534 static void execSetupChooseGameSpeed()
4536 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4541 static void execSetupChooseScrollDelay()
4543 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4548 static void execSetupChooseSnapshotMode()
4550 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4555 static void execSetupEditor()
4557 setup_mode = SETUP_MODE_EDITOR;
4562 static void execSetupGraphics_setWindowSizes(boolean update_list)
4564 if (window_sizes != NULL && update_list)
4566 freeTreeInfo(window_sizes);
4568 window_sizes = NULL;
4571 if (window_sizes == NULL)
4573 boolean current_window_size_found = FALSE;
4576 for (i = 0; window_sizes_list[i].value != -1; i++)
4578 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4579 char identifier[32], name[32];
4580 int value = window_sizes_list[i].value;
4581 char *text = window_sizes_list[i].text;
4583 ti->node_top = &window_sizes;
4584 ti->sort_priority = value;
4586 sprintf(identifier, "%d", value);
4587 sprintf(name, "%s", text);
4589 setString(&ti->identifier, identifier);
4590 setString(&ti->name, name);
4591 setString(&ti->name_sorting, name);
4592 setString(&ti->infotext, "Window Scaling");
4594 pushTreeInfo(&window_sizes, ti);
4596 if (value == setup.window_scaling_percent)
4597 current_window_size_found = TRUE;
4600 if (!current_window_size_found)
4602 // add entry for non-preset window scaling value
4604 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4605 char identifier[32], name[32];
4606 int value = setup.window_scaling_percent;
4608 ti->node_top = &window_sizes;
4609 ti->sort_priority = value;
4611 sprintf(identifier, "%d", value);
4612 sprintf(name, "%d %% (Current)", value);
4614 setString(&ti->identifier, identifier);
4615 setString(&ti->name, name);
4616 setString(&ti->name_sorting, name);
4617 setString(&ti->infotext, "Window Scaling");
4619 pushTreeInfo(&window_sizes, ti);
4622 /* sort window size values to start with lowest window size value */
4623 sortTreeInfo(&window_sizes);
4625 /* set current window size value to configured window size value */
4626 window_size_current =
4627 getTreeInfoFromIdentifier(window_sizes,
4628 i_to_a(setup.window_scaling_percent));
4630 /* if that fails, set current window size to reliable default value */
4631 if (window_size_current == NULL)
4632 window_size_current =
4633 getTreeInfoFromIdentifier(window_sizes,
4634 i_to_a(STD_WINDOW_SCALING_PERCENT));
4636 /* if that also fails, set current window size to first available value */
4637 if (window_size_current == NULL)
4638 window_size_current = window_sizes;
4641 setup.window_scaling_percent = atoi(window_size_current->identifier);
4643 /* needed for displaying window size text instead of identifier */
4644 window_size_text = window_size_current->name;
4647 static void execSetupGraphics_setScalingTypes()
4649 if (scaling_types == NULL)
4653 for (i = 0; scaling_types_list[i].value != NULL; i++)
4655 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4656 char identifier[32], name[32];
4657 char *value = scaling_types_list[i].value;
4658 char *text = scaling_types_list[i].text;
4660 ti->node_top = &scaling_types;
4661 ti->sort_priority = i;
4663 sprintf(identifier, "%s", value);
4664 sprintf(name, "%s", text);
4666 setString(&ti->identifier, identifier);
4667 setString(&ti->name, name);
4668 setString(&ti->name_sorting, name);
4669 setString(&ti->infotext, "Anti-Aliasing");
4671 pushTreeInfo(&scaling_types, ti);
4674 /* sort scaling type values to start with lowest scaling type value */
4675 sortTreeInfo(&scaling_types);
4677 /* set current scaling type value to configured scaling type value */
4678 scaling_type_current =
4679 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4681 /* if that fails, set current scaling type to reliable default value */
4682 if (scaling_type_current == NULL)
4683 scaling_type_current =
4684 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4686 /* if that also fails, set current scaling type to first available value */
4687 if (scaling_type_current == NULL)
4688 scaling_type_current = scaling_types;
4691 setup.window_scaling_quality = scaling_type_current->identifier;
4693 /* needed for displaying scaling type text instead of identifier */
4694 scaling_type_text = scaling_type_current->name;
4697 static void execSetupGraphics_setRenderingModes()
4699 if (rendering_modes == NULL)
4703 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4705 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4706 char identifier[32], name[32];
4707 char *value = rendering_modes_list[i].value;
4708 char *text = rendering_modes_list[i].text;
4710 ti->node_top = &rendering_modes;
4711 ti->sort_priority = i;
4713 sprintf(identifier, "%s", value);
4714 sprintf(name, "%s", text);
4716 setString(&ti->identifier, identifier);
4717 setString(&ti->name, name);
4718 setString(&ti->name_sorting, name);
4719 setString(&ti->infotext, "Special Rendering");
4721 pushTreeInfo(&rendering_modes, ti);
4724 /* sort rendering mode values to start with lowest rendering mode value */
4725 sortTreeInfo(&rendering_modes);
4727 /* set current rendering mode value to configured rendering mode value */
4728 rendering_mode_current =
4729 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4731 /* if that fails, set current rendering mode to reliable default value */
4732 if (rendering_mode_current == NULL)
4733 rendering_mode_current =
4734 getTreeInfoFromIdentifier(rendering_modes,
4735 STR_SPECIAL_RENDERING_DEFAULT);
4737 /* if that also fails, set current rendering mode to first available one */
4738 if (rendering_mode_current == NULL)
4739 rendering_mode_current = rendering_modes;
4742 setup.screen_rendering_mode = rendering_mode_current->identifier;
4744 /* needed for displaying rendering mode text instead of identifier */
4745 rendering_mode_text = rendering_mode_current->name;
4748 static void execSetupGraphics()
4750 // update "setup.window_scaling_percent" from list selection
4751 // (in this case, window scaling was changed on setup screen)
4752 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4753 execSetupGraphics_setWindowSizes(FALSE);
4755 // update list selection from "setup.window_scaling_percent"
4756 // (window scaling may have changed by resizing the window)
4757 execSetupGraphics_setWindowSizes(TRUE);
4759 execSetupGraphics_setScalingTypes();
4760 execSetupGraphics_setRenderingModes();
4762 setup_mode = SETUP_MODE_GRAPHICS;
4766 #if defined(TARGET_SDL2)
4767 // window scaling may have changed at this point
4768 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4770 // window scaling quality may have changed at this point
4771 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4772 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4774 // screen rendering mode may have changed at this point
4775 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4779 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4780 static void execSetupChooseWindowSize()
4782 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4787 static void execSetupChooseScalingType()
4789 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4794 static void execSetupChooseRenderingMode()
4796 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4802 static void execSetupChooseVolumeSimple()
4804 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4809 static void execSetupChooseVolumeLoops()
4811 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4816 static void execSetupChooseVolumeMusic()
4818 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4823 static void execSetupSound()
4825 if (volumes_simple == NULL)
4827 boolean current_volume_simple_found = FALSE;
4830 for (i = 0; volumes_list[i].value != -1; i++)
4832 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4833 char identifier[32], name[32];
4834 int value = volumes_list[i].value;
4835 char *text = volumes_list[i].text;
4837 ti->node_top = &volumes_simple;
4838 ti->sort_priority = value;
4840 sprintf(identifier, "%d", value);
4841 sprintf(name, "%s", text);
4843 setString(&ti->identifier, identifier);
4844 setString(&ti->name, name);
4845 setString(&ti->name_sorting, name);
4846 setString(&ti->infotext, "Sound Volume");
4848 pushTreeInfo(&volumes_simple, ti);
4850 if (value == setup.volume_simple)
4851 current_volume_simple_found = TRUE;
4854 if (!current_volume_simple_found)
4856 // add entry for non-preset volume value
4858 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4859 char identifier[32], name[32];
4860 int value = setup.volume_simple;
4862 ti->node_top = &volumes_simple;
4863 ti->sort_priority = value;
4865 sprintf(identifier, "%d", value);
4866 sprintf(name, "%d %% (Current)", value);
4868 setString(&ti->identifier, identifier);
4869 setString(&ti->name, name);
4870 setString(&ti->name_sorting, name);
4871 setString(&ti->infotext, "Sound Volume");
4873 pushTreeInfo(&volumes_simple, ti);
4876 /* sort volume values to start with lowest volume value */
4877 sortTreeInfo(&volumes_simple);
4879 /* set current volume value to configured volume value */
4880 volume_simple_current =
4881 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4883 /* if that fails, set current volume to reliable default value */
4884 if (volume_simple_current == NULL)
4885 volume_simple_current =
4886 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4888 /* if that also fails, set current volume to first available value */
4889 if (volume_simple_current == NULL)
4890 volume_simple_current = volumes_simple;
4893 if (volumes_loops == NULL)
4895 boolean current_volume_loops_found = FALSE;
4898 for (i = 0; volumes_list[i].value != -1; i++)
4900 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4901 char identifier[32], name[32];
4902 int value = volumes_list[i].value;
4903 char *text = volumes_list[i].text;
4905 ti->node_top = &volumes_loops;
4906 ti->sort_priority = value;
4908 sprintf(identifier, "%d", value);
4909 sprintf(name, "%s", text);
4911 setString(&ti->identifier, identifier);
4912 setString(&ti->name, name);
4913 setString(&ti->name_sorting, name);
4914 setString(&ti->infotext, "Loops Volume");
4916 pushTreeInfo(&volumes_loops, ti);
4918 if (value == setup.volume_loops)
4919 current_volume_loops_found = TRUE;
4922 if (!current_volume_loops_found)
4924 // add entry for non-preset volume value
4926 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4927 char identifier[32], name[32];
4928 int value = setup.volume_loops;
4930 ti->node_top = &volumes_loops;
4931 ti->sort_priority = value;
4933 sprintf(identifier, "%d", value);
4934 sprintf(name, "%d %% (Current)", value);
4936 setString(&ti->identifier, identifier);
4937 setString(&ti->name, name);
4938 setString(&ti->name_sorting, name);
4939 setString(&ti->infotext, "Loops Volume");
4941 pushTreeInfo(&volumes_loops, ti);
4944 /* sort volume values to start with lowest volume value */
4945 sortTreeInfo(&volumes_loops);
4947 /* set current volume value to configured volume value */
4948 volume_loops_current =
4949 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4951 /* if that fails, set current volume to reliable default value */
4952 if (volume_loops_current == NULL)
4953 volume_loops_current =
4954 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4956 /* if that also fails, set current volume to first available value */
4957 if (volume_loops_current == NULL)
4958 volume_loops_current = volumes_loops;
4961 if (volumes_music == NULL)
4963 boolean current_volume_music_found = FALSE;
4966 for (i = 0; volumes_list[i].value != -1; i++)
4968 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4969 char identifier[32], name[32];
4970 int value = volumes_list[i].value;
4971 char *text = volumes_list[i].text;
4973 ti->node_top = &volumes_music;
4974 ti->sort_priority = value;
4976 sprintf(identifier, "%d", value);
4977 sprintf(name, "%s", text);
4979 setString(&ti->identifier, identifier);
4980 setString(&ti->name, name);
4981 setString(&ti->name_sorting, name);
4982 setString(&ti->infotext, "Music Volume");
4984 pushTreeInfo(&volumes_music, ti);
4986 if (value == setup.volume_music)
4987 current_volume_music_found = TRUE;
4990 if (!current_volume_music_found)
4992 // add entry for non-preset volume value
4994 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4995 char identifier[32], name[32];
4996 int value = setup.volume_music;
4998 ti->node_top = &volumes_music;
4999 ti->sort_priority = value;
5001 sprintf(identifier, "%d", value);
5002 sprintf(name, "%d %% (Current)", value);
5004 setString(&ti->identifier, identifier);
5005 setString(&ti->name, name);
5006 setString(&ti->name_sorting, name);
5007 setString(&ti->infotext, "Music Volume");
5009 pushTreeInfo(&volumes_music, ti);
5012 /* sort volume values to start with lowest volume value */
5013 sortTreeInfo(&volumes_music);
5015 /* set current volume value to configured volume value */
5016 volume_music_current =
5017 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5019 /* if that fails, set current volume to reliable default value */
5020 if (volume_music_current == NULL)
5021 volume_music_current =
5022 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5024 /* if that also fails, set current volume to first available value */
5025 if (volume_music_current == NULL)
5026 volume_music_current = volumes_music;
5029 setup.volume_simple = atoi(volume_simple_current->identifier);
5030 setup.volume_loops = atoi(volume_loops_current->identifier);
5031 setup.volume_music = atoi(volume_music_current->identifier);
5033 /* needed for displaying volume text instead of identifier */
5034 volume_simple_text = volume_simple_current->name;
5035 volume_loops_text = volume_loops_current->name;
5036 volume_music_text = volume_music_current->name;
5038 setup_mode = SETUP_MODE_SOUND;
5043 static void execSetupChooseTouchControls()
5045 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5050 static void execSetupChooseMoveDistance()
5052 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5057 static void execSetupChooseDropDistance()
5059 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5064 static void execSetupTouch()
5066 if (touch_controls == NULL)
5070 for (i = 0; touch_controls_list[i].value != NULL; i++)
5072 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5073 char identifier[32], name[32];
5074 char *value = touch_controls_list[i].value;
5075 char *text = touch_controls_list[i].text;
5077 ti->node_top = &touch_controls;
5078 ti->sort_priority = i;
5080 sprintf(identifier, "%s", value);
5081 sprintf(name, "%s", text);
5083 setString(&ti->identifier, identifier);
5084 setString(&ti->name, name);
5085 setString(&ti->name_sorting, name);
5086 setString(&ti->infotext, "Control Type");
5088 pushTreeInfo(&touch_controls, ti);
5091 /* sort touch control values to start with lowest touch control value */
5092 sortTreeInfo(&touch_controls);
5094 /* set current touch control value to configured touch control value */
5095 touch_control_current =
5096 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5098 /* if that fails, set current touch control to reliable default value */
5099 if (touch_control_current == NULL)
5100 touch_control_current =
5101 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5103 /* if that also fails, set current touch control to first available value */
5104 if (touch_control_current == NULL)
5105 touch_control_current = touch_controls;
5108 if (move_distances == NULL)
5112 for (i = 0; distances_list[i].value != -1; i++)
5114 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5115 char identifier[32], name[32];
5116 int value = distances_list[i].value;
5117 char *text = distances_list[i].text;
5119 ti->node_top = &move_distances;
5120 ti->sort_priority = value;
5122 sprintf(identifier, "%d", value);
5123 sprintf(name, "%s", text);
5125 setString(&ti->identifier, identifier);
5126 setString(&ti->name, name);
5127 setString(&ti->name_sorting, name);
5128 setString(&ti->infotext, "Move Distance");
5130 pushTreeInfo(&move_distances, ti);
5133 /* sort distance values to start with lowest distance value */
5134 sortTreeInfo(&move_distances);
5136 /* set current distance value to configured distance value */
5137 move_distance_current =
5138 getTreeInfoFromIdentifier(move_distances,
5139 i_to_a(setup.touch.move_distance));
5141 /* if that fails, set current distance to reliable default value */
5142 if (move_distance_current == NULL)
5143 move_distance_current =
5144 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5146 /* if that also fails, set current distance to first available value */
5147 if (move_distance_current == NULL)
5148 move_distance_current = move_distances;
5151 if (drop_distances == NULL)
5155 for (i = 0; distances_list[i].value != -1; i++)
5157 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5158 char identifier[32], name[32];
5159 int value = distances_list[i].value;
5160 char *text = distances_list[i].text;
5162 ti->node_top = &drop_distances;
5163 ti->sort_priority = value;
5165 sprintf(identifier, "%d", value);
5166 sprintf(name, "%s", text);
5168 setString(&ti->identifier, identifier);
5169 setString(&ti->name, name);
5170 setString(&ti->name_sorting, name);
5171 setString(&ti->infotext, "Drop Distance");
5173 pushTreeInfo(&drop_distances, ti);
5176 /* sort distance values to start with lowest distance value */
5177 sortTreeInfo(&drop_distances);
5179 /* set current distance value to configured distance value */
5180 drop_distance_current =
5181 getTreeInfoFromIdentifier(drop_distances,
5182 i_to_a(setup.touch.drop_distance));
5184 /* if that fails, set current distance to reliable default value */
5185 if (drop_distance_current == NULL)
5186 drop_distance_current =
5187 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5189 /* if that also fails, set current distance to first available value */
5190 if (drop_distance_current == NULL)
5191 drop_distance_current = drop_distances;
5194 setup.touch.control_type = touch_control_current->identifier;
5195 setup.touch.move_distance = atoi(move_distance_current->identifier);
5196 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5198 /* needed for displaying volume text instead of identifier */
5199 touch_controls_text = touch_control_current->name;
5200 move_distance_text = move_distance_current->name;
5201 drop_distance_text = drop_distance_current->name;
5203 setup_mode = SETUP_MODE_TOUCH;
5208 static void execSetupArtwork()
5211 printf("::: '%s', '%s', '%s'\n",
5212 artwork.gfx_current->subdir,
5213 artwork.gfx_current->fullpath,
5214 artwork.gfx_current->basepath);
5217 setup.graphics_set = artwork.gfx_current->identifier;
5218 setup.sounds_set = artwork.snd_current->identifier;
5219 setup.music_set = artwork.mus_current->identifier;
5221 /* needed if last screen (setup choice) changed graphics, sounds or music */
5222 ReloadCustomArtwork(0);
5224 /* needed for displaying artwork name instead of artwork identifier */
5225 graphics_set_name = artwork.gfx_current->name;
5226 sounds_set_name = artwork.snd_current->name;
5227 music_set_name = artwork.mus_current->name;
5229 setup_mode = SETUP_MODE_ARTWORK;
5234 static void execSetupChooseGraphics()
5236 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5241 static void execSetupChooseSounds()
5243 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5248 static void execSetupChooseMusic()
5250 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5255 static void execSetupInput()
5257 setup_mode = SETUP_MODE_INPUT;
5262 static void execSetupShortcuts()
5264 setup_mode = SETUP_MODE_SHORTCUTS;
5269 static void execSetupShortcuts1()
5271 setup_mode = SETUP_MODE_SHORTCUTS_1;
5276 static void execSetupShortcuts2()
5278 setup_mode = SETUP_MODE_SHORTCUTS_2;
5283 static void execSetupShortcuts3()
5285 setup_mode = SETUP_MODE_SHORTCUTS_3;
5290 static void execSetupShortcuts4()
5292 setup_mode = SETUP_MODE_SHORTCUTS_4;
5297 static void execSetupShortcuts5()
5299 setup_mode = SETUP_MODE_SHORTCUTS_5;
5304 static void execExitSetup()
5306 SetGameStatus(GAME_MODE_MAIN);
5311 static void execSaveAndExitSetup()
5317 static struct TokenInfo setup_info_main[] =
5319 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5320 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5321 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5322 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5323 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5324 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5325 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5326 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5327 { TYPE_EMPTY, NULL, "" },
5328 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5329 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5334 static struct TokenInfo setup_info_game[] =
5336 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5337 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5338 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5339 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5340 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5341 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5342 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5343 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5344 { TYPE_STRING, &game_speed_text, "" },
5346 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5347 { TYPE_STRING, &scroll_delay_text, "" },
5349 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5350 { TYPE_STRING, &snapshot_mode_text, "" },
5351 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5352 { TYPE_EMPTY, NULL, "" },
5353 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5358 static struct TokenInfo setup_info_editor[] =
5361 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5362 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5363 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5364 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5365 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5366 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5367 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5368 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5369 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5370 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5372 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5373 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5375 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5377 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5378 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5379 { TYPE_EMPTY, NULL, "" },
5381 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5382 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5383 { TYPE_EMPTY, NULL, "" },
5385 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5386 { TYPE_EMPTY, NULL, "" },
5387 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5392 static struct TokenInfo setup_info_graphics[] =
5394 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5395 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5396 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5397 { TYPE_STRING, &window_size_text, "" },
5398 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5399 { TYPE_STRING, &scaling_type_text, "" },
5400 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5401 { TYPE_STRING, &rendering_mode_text, "" },
5404 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5405 { TYPE_STRING, &scroll_delay_text, "" },
5407 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5408 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5409 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5410 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5411 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5412 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5413 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5414 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5415 { TYPE_EMPTY, NULL, "" },
5416 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5421 static struct TokenInfo setup_info_sound[] =
5423 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5424 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5425 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5426 { TYPE_EMPTY, NULL, "" },
5427 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5428 { TYPE_STRING, &volume_simple_text, "" },
5429 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5430 { TYPE_STRING, &volume_loops_text, "" },
5431 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5432 { TYPE_STRING, &volume_music_text, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5439 static struct TokenInfo setup_info_artwork[] =
5441 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5442 { TYPE_STRING, &graphics_set_name, "" },
5443 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5444 { TYPE_STRING, &sounds_set_name, "" },
5445 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5446 { TYPE_STRING, &music_set_name, "" },
5447 { TYPE_EMPTY, NULL, "" },
5448 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5449 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5450 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5451 { TYPE_EMPTY, NULL, "" },
5452 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5457 static struct TokenInfo setup_info_input[] =
5459 { TYPE_SWITCH, NULL, "Player:" },
5460 { TYPE_SWITCH, NULL, "Device:" },
5461 { TYPE_SWITCH, NULL, "" },
5462 { TYPE_EMPTY, NULL, "" },
5463 { TYPE_EMPTY, NULL, "" },
5464 { TYPE_EMPTY, NULL, "" },
5465 { TYPE_EMPTY, NULL, "" },
5466 { TYPE_EMPTY, NULL, "" },
5467 { TYPE_EMPTY, NULL, "" },
5468 { TYPE_EMPTY, NULL, "" },
5469 { TYPE_EMPTY, NULL, "" },
5470 { TYPE_EMPTY, NULL, "" },
5471 { TYPE_EMPTY, NULL, "" },
5472 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5477 static struct TokenInfo setup_info_touch[] =
5479 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5480 { TYPE_STRING, &touch_controls_text, "" },
5481 { TYPE_EMPTY, NULL, "" },
5482 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5487 static struct TokenInfo setup_info_touch_wipe_gestures[] =
5489 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5490 { TYPE_STRING, &touch_controls_text, "" },
5491 { TYPE_EMPTY, NULL, "" },
5492 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5493 { TYPE_STRING, &move_distance_text, "" },
5494 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5495 { TYPE_STRING, &drop_distance_text, "" },
5496 { TYPE_EMPTY, NULL, "" },
5497 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5502 static struct TokenInfo setup_info_shortcuts[] =
5504 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5505 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5506 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5507 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5508 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5509 { TYPE_EMPTY, NULL, "" },
5510 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5515 static struct TokenInfo setup_info_shortcuts_1[] =
5517 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5518 { TYPE_KEY, &setup.shortcut.save_game, "" },
5519 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5520 { TYPE_KEY, &setup.shortcut.load_game, "" },
5521 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5522 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5523 { TYPE_EMPTY, NULL, "" },
5524 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5525 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5526 { TYPE_EMPTY, NULL, "" },
5527 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5532 static struct TokenInfo setup_info_shortcuts_2[] =
5534 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5535 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5536 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5537 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5538 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5539 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5540 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5541 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5542 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5543 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5544 { TYPE_EMPTY, NULL, "" },
5545 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5550 static struct TokenInfo setup_info_shortcuts_3[] =
5552 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5553 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5554 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5555 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5556 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5557 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5558 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5559 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5560 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5561 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5562 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5563 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5564 { TYPE_EMPTY, NULL, "" },
5565 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5570 static struct TokenInfo setup_info_shortcuts_4[] =
5572 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5573 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5574 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5575 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5576 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5577 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5578 { TYPE_EMPTY, NULL, "" },
5579 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5584 static struct TokenInfo setup_info_shortcuts_5[] =
5586 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5587 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5588 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5589 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5590 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5591 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5592 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5593 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5594 { TYPE_EMPTY, NULL, "" },
5595 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5600 static Key getSetupKey()
5602 Key key = KSYM_UNDEFINED;
5603 boolean got_key_event = FALSE;
5605 while (!got_key_event)
5609 if (NextValidEvent(&event))
5613 case EVENT_KEYPRESS:
5615 key = GetEventKey((KeyEvent *)&event, TRUE);
5617 /* press 'Escape' or 'Enter' to keep the existing key binding */
5618 if (key == KSYM_Escape || key == KSYM_Return)
5619 key = KSYM_UNDEFINED; /* keep old value */
5621 got_key_event = TRUE;
5625 case EVENT_KEYRELEASE:
5626 key_joystick_mapping = 0;
5630 HandleOtherEvents(&event);
5641 static int getSetupValueFont(int type, void *value)
5643 if (type & TYPE_GHOSTED)
5644 return FONT_OPTION_OFF;
5645 else if (type & TYPE_KEY)
5646 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5647 else if (type & TYPE_STRING)
5648 return FONT_VALUE_2;
5649 else if (type & TYPE_ECS_AGA)
5650 return FONT_VALUE_1;
5651 else if (type & TYPE_BOOLEAN_STYLE)
5652 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5653 else if (type & TYPE_YES_NO_AUTO)
5654 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5655 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5657 return FONT_VALUE_1;
5660 static int getSetupValueFontNarrow(int type, int font_nr)
5662 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5663 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5664 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5668 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5670 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5671 struct TokenInfo *si = &setup_info[si_pos];
5672 boolean font_draw_xoffset_modified = FALSE;
5673 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5674 int font_draw_xoffset_old = -1;
5675 int xoffset = (scrollbar_needed ? -1 : 0);
5676 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5677 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5678 int xpos = menu_screen_value_xpos;
5679 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5680 int startx = mSX + xpos * 32;
5681 int starty = mSY + ypos * 32;
5682 int font_nr, font_nr_default, font_width_default;
5683 int type = si->type;
5684 void *value = si->value;
5685 char *value_string = getSetupValue(type, value);
5688 if (value_string == NULL)
5691 if (type & TYPE_KEY)
5693 xpos = MENU_SCREEN_START_XPOS;
5695 if (type & TYPE_QUERY)
5696 value_string = "<press key>";
5698 else if (type & TYPE_STRING)
5700 int max_value_len = (SCR_FIELDX - 2) * 2;
5702 xpos = MENU_SCREEN_START_XPOS;
5704 if (strlen(value_string) > max_value_len)
5705 value_string[max_value_len] = '\0';
5707 else if (type & TYPE_YES_NO_AUTO)
5709 xpos = menu_screen_value_xpos - 1;
5712 startx = mSX + xpos * 32;
5713 starty = mSY + ypos * 32;
5714 font_nr_default = getSetupValueFont(type, value);
5715 font_width_default = getFontWidth(font_nr_default);
5717 font_nr = font_nr_default;
5719 // special check if right-side setup values moved left due to scrollbar
5720 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5722 int max_menu_text_length = 26; // maximum text length for classic menu
5723 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5724 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5725 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5726 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5727 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5729 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5732 startx = mSX + xpos * 32;
5734 font_nr = getSetupValueFontNarrow(type, font_nr);
5738 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5739 if (setup_mode != SETUP_MODE_INPUT)
5741 int max_menu_text_length_big = (menu_screen_value_xpos -
5742 MENU_SCREEN_START_XPOS);
5743 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5744 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5745 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5746 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5747 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5748 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5749 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5750 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5751 boolean correct_font_draw_xoffset = FALSE;
5753 if (xpos == MENU_SCREEN_START_XPOS &&
5754 startx + font1_xoffset < text_startx + text_font_xoffset)
5755 correct_font_draw_xoffset = TRUE;
5757 if (xpos == menu_screen_value_xpos &&
5758 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5759 correct_font_draw_xoffset = TRUE;
5761 /* check if setup value would overlap with setup text when printed */
5762 /* (this can happen for extreme/wrong values for font draw offset) */
5763 if (correct_font_draw_xoffset)
5765 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5766 font_draw_xoffset_modified = TRUE;
5768 if (type & TYPE_KEY)
5769 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5770 else if (!(type & TYPE_STRING))
5771 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5772 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5776 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5777 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
5779 DrawText(startx, starty, value_string, font_nr);
5781 if (font_draw_xoffset_modified)
5782 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5785 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5787 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5788 struct TokenInfo *si = &setup_info[si_pos];
5790 if (si->type & TYPE_BOOLEAN_STYLE)
5792 *(boolean *)si->value ^= TRUE;
5794 else if (si->type & TYPE_YES_NO_AUTO)
5798 (*(int *)si->value == AUTO ? TRUE :
5799 *(int *)si->value == TRUE ? FALSE : AUTO) :
5800 (*(int *)si->value == TRUE ? AUTO :
5801 *(int *)si->value == AUTO ? FALSE : TRUE));
5803 else if (si->type & TYPE_KEY)
5807 si->type |= TYPE_QUERY;
5808 drawSetupValue(screen_pos, setup_info_pos_raw);
5809 si->type &= ~TYPE_QUERY;
5811 key = getSetupKey();
5812 if (key != KSYM_UNDEFINED)
5813 *(Key *)si->value = key;
5816 drawSetupValue(screen_pos, setup_info_pos_raw);
5818 // fullscreen state may have changed at this point
5819 if (si->value == &setup.fullscreen)
5820 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5823 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
5825 static struct TokenInfo *setup_info_hide = NULL;
5830 /* determine maximum list size of target list */
5831 while (setup_info_orig[list_size++].type != 0);
5833 /* free, allocate and clear memory for target list */
5834 checked_free(setup_info_hide);
5835 setup_info_hide = checked_calloc(list_size * sizeof(struct TokenInfo));
5837 /* copy setup info list without setup entries marked as hidden */
5838 for (i = 0; setup_info_orig[i].type != 0; i++)
5839 if (!hideSetupEntry(setup_info_orig[i].value))
5840 setup_info_hide[list_pos++] = setup_info_orig[i];
5842 return setup_info_hide;
5845 static void DrawSetupScreen_Generic()
5847 int fade_mask = REDRAW_FIELD;
5848 boolean redraw_all = FALSE;
5849 char *title_string = NULL;
5852 if (CheckIfGlobalBorderHasChanged())
5853 fade_mask = REDRAW_ALL;
5856 FadeMenuSoundsAndMusic();
5858 FreeScreenGadgets();
5859 CreateScreenGadgets();
5861 if (redraw_mask & REDRAW_ALL)
5866 /* needed if different viewport properties defined for setup screen */
5867 ChangeViewportPropertiesIfNeeded();
5869 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5873 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5875 if (setup_mode == SETUP_MODE_MAIN)
5877 setup_info = setup_info_main;
5878 title_string = "Setup";
5880 else if (setup_mode == SETUP_MODE_GAME)
5882 setup_info = setup_info_game;
5883 title_string = "Setup Game";
5885 else if (setup_mode == SETUP_MODE_EDITOR)
5887 setup_info = setup_info_editor;
5888 title_string = "Setup Editor";
5890 else if (setup_mode == SETUP_MODE_GRAPHICS)
5892 setup_info = setup_info_graphics;
5893 title_string = "Setup Graphics";
5895 else if (setup_mode == SETUP_MODE_SOUND)
5897 setup_info = setup_info_sound;
5898 title_string = "Setup Sound";
5900 else if (setup_mode == SETUP_MODE_ARTWORK)
5902 setup_info = setup_info_artwork;
5903 title_string = "Custom Artwork";
5905 else if (setup_mode == SETUP_MODE_TOUCH)
5907 setup_info = setup_info_touch;
5908 title_string = "Setup Touch Ctrls";
5910 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
5911 setup_info = setup_info_touch_wipe_gestures;
5913 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5915 setup_info = setup_info_shortcuts;
5916 title_string = "Setup Shortcuts";
5918 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5920 setup_info = setup_info_shortcuts_1;
5921 title_string = "Setup Shortcuts";
5923 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5925 setup_info = setup_info_shortcuts_2;
5926 title_string = "Setup Shortcuts";
5928 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5930 setup_info = setup_info_shortcuts_3;
5931 title_string = "Setup Shortcuts";
5933 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5935 setup_info = setup_info_shortcuts_4;
5936 title_string = "Setup Shortcuts";
5938 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5940 setup_info = setup_info_shortcuts_5;
5941 title_string = "Setup Shortcuts";
5944 /* use modified setup info without setup entries marked as hidden */
5945 setup_info = getSetupInfoFinal(setup_info);
5947 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5949 // determine maximal number of setup entries that can be displayed on screen
5951 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5954 // determine maximal number of setup entries available for this setup screen
5956 for (i = 0; setup_info[i].type != 0; i++)
5959 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5961 MapScreenGadgets(max_setup_info);
5964 redraw_mask = fade_mask = REDRAW_ALL;
5966 DrawMaskedBorder(fade_mask);
5971 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5973 menu_info = setup_info;
5975 HandleMenuScreen(mx, my, dx, dy, button,
5976 setup_mode, num_setup_info, max_setup_info);
5979 void DrawSetupScreen_Input()
5983 FadeOut(REDRAW_FIELD);
5987 setup_info = setup_info_input;
5989 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5991 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5993 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5994 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5995 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5996 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5997 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5998 initCursor(i, IMG_MENU_BUTTON);
6000 DrawCursorAndText_Setup(i, -1, FALSE);
6003 /* create gadgets for setup input menu screen */
6004 FreeScreenGadgets();
6005 CreateScreenGadgets();
6007 /* map gadgets for setup input menu screen */
6008 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6010 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6012 FadeIn(REDRAW_FIELD);
6015 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6017 if (device_name == NULL)
6020 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6023 if (strlen(device_name) > 1)
6025 char c1 = device_name[strlen(device_name) - 1];
6026 char c2 = device_name[strlen(device_name) - 2];
6028 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6029 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6032 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6033 strlen(device_name));
6036 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6039 static struct SetupKeyboardInfo custom_key;
6046 { &custom_key.left, "Axis/Pad Left" },
6047 { &custom_key.right, "Axis/Pad Right" },
6048 { &custom_key.up, "Axis/Pad Up" },
6049 { &custom_key.down, "Axis/Pad Down" },
6050 { &custom_key.snap, "Button 1/A/X" },
6051 { &custom_key.drop, "Button 2/B/Y" }
6053 static char *joystick_name[MAX_PLAYERS] =
6060 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6062 custom_key = setup.input[player_nr].key;
6064 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6065 FONT_INPUT_1_ACTIVE);
6067 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6069 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6070 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6072 if (setup.input[player_nr].use_joystick)
6074 char *device_name = setup.input[player_nr].joy.device_name;
6075 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6076 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6077 char *text = joystick_name[joystick_nr];
6078 int font_nr = (joystick_active ? FONT_VALUE_1 : FONT_VALUE_OLD);
6080 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6081 DrawText(mSX + 32, mSY + 4 * 32, "Configure", text_font_nr);
6085 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6086 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6089 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6091 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6092 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6093 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6094 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6096 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6097 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6098 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6099 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6100 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6101 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6103 for (i = 0; i < 6; i++)
6105 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6107 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6109 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6110 (setup.input[player_nr].use_joystick ?
6112 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6116 static int input_player_nr = 0;
6118 void HandleSetupScreen_Input_Player(int step, int direction)
6120 int old_player_nr = input_player_nr;
6123 new_player_nr = old_player_nr + step * direction;
6124 if (new_player_nr < 0)
6126 if (new_player_nr > MAX_PLAYERS - 1)
6127 new_player_nr = MAX_PLAYERS - 1;
6129 if (new_player_nr != old_player_nr)
6131 input_player_nr = new_player_nr;
6133 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6137 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6139 static int choice = 0;
6142 int pos_start = SETUPINPUT_SCREEN_POS_START;
6143 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6144 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6145 int pos_end = SETUPINPUT_SCREEN_POS_END;
6147 if (button == MB_MENU_INITIALIZE)
6149 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6151 DrawCursorAndText_Setup(choice, -1, TRUE);
6155 else if (button == MB_MENU_LEAVE)
6157 setup_mode = SETUP_MODE_MAIN;
6164 if (mx || my) /* mouse input */
6166 x = (mx - mSX) / 32;
6167 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6169 else if (dx || dy) /* keyboard input */
6171 if (dx && choice == 0)
6172 x = (dx < 0 ? 10 : 12);
6173 else if ((dx && choice == 1) ||
6174 (dx == -1 && choice == pos_end))
6175 button = MB_MENU_CHOICE;
6179 if (y >= pos_empty1 && y <= pos_empty2)
6180 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6183 if (y == 0 && dx != 0 && button)
6185 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6187 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6188 y >= pos_start && y <= pos_end &&
6189 !(y >= pos_empty1 && y <= pos_empty2))
6195 DrawCursorAndText_Setup(choice, -1, FALSE);
6196 DrawCursorAndText_Setup(y, -1, TRUE);
6198 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6207 char *device_name = setup.input[input_player_nr].joy.device_name;
6209 if (!setup.input[input_player_nr].use_joystick)
6211 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6213 setJoystickDeviceToNr(device_name, new_device_nr);
6214 setup.input[input_player_nr].use_joystick = TRUE;
6218 int device_nr = getJoystickNrFromDeviceName(device_name);
6219 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6221 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6222 setup.input[input_player_nr].use_joystick = FALSE;
6224 setJoystickDeviceToNr(device_name, new_device_nr);
6227 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6231 if (setup.input[input_player_nr].use_joystick)
6232 ConfigureJoystick(input_player_nr);
6234 CustomizeKeyboard(input_player_nr);
6236 else if (y == pos_end)
6242 setup_mode = SETUP_MODE_MAIN;
6249 void CustomizeKeyboard(int player_nr)
6253 boolean finished = FALSE;
6254 static struct SetupKeyboardInfo custom_key;
6259 } customize_step[] =
6261 { &custom_key.left, "Move Left" },
6262 { &custom_key.right, "Move Right" },
6263 { &custom_key.up, "Move Up" },
6264 { &custom_key.down, "Move Down" },
6265 { &custom_key.snap, "Snap Field" },
6266 { &custom_key.drop, "Drop Element" }
6269 /* read existing key bindings from player setup */
6270 custom_key = setup.input[player_nr].key;
6273 FadeOut(REDRAW_FIELD);
6277 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6280 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6281 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6282 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6283 "Key:", FONT_INPUT_1_ACTIVE);
6284 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6285 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6287 FadeIn(REDRAW_FIELD);
6293 if (NextValidEvent(&event))
6297 case EVENT_KEYPRESS:
6299 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6301 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6303 if (key == KSYM_Escape)
6304 FadeSkipNextFadeIn();
6310 /* all keys configured -- wait for "Escape" or "Return" key */
6314 /* press 'Enter' to keep the existing key binding */
6315 if (key == KSYM_Return)
6316 key = *customize_step[step_nr].key;
6318 /* check if key already used */
6319 for (i = 0; i < step_nr; i++)
6320 if (*customize_step[i].key == key)
6325 /* got new key binding */
6326 *customize_step[step_nr].key = key;
6327 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6329 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6330 getKeyNameFromKey(key), FONT_VALUE_1);
6333 /* un-highlight last query */
6334 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6335 customize_step[step_nr - 1].text, FONT_MENU_1);
6336 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6337 "Key:", FONT_MENU_1);
6339 /* press 'Enter' to leave */
6342 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6343 "Press Enter", FONT_TITLE_1);
6347 /* query next key binding */
6348 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6349 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6350 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6351 "Key:", FONT_INPUT_1_ACTIVE);
6352 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6353 getKeyNameFromKey(*customize_step[step_nr].key),
6358 case EVENT_KEYRELEASE:
6359 key_joystick_mapping = 0;
6363 HandleOtherEvents(&event);
6371 /* write new key bindings back to player setup */
6372 setup.input[player_nr].key = custom_key;
6374 DrawSetupScreen_Input();
6377 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
6379 #define MARKER_BUTTON 1
6380 #define MARKER_AXIS_X 2
6381 #define MARKER_AXIS_Y 3
6383 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
6385 #if defined(TARGET_SDL2)
6386 static boolean bitmaps_initialized = FALSE;
6387 boolean screen_initialized = FALSE;
6388 static Bitmap *controller, *button, *axis_x, *axis_y;
6390 boolean success = TRUE;
6391 boolean done = FALSE, next = FALSE;
6393 int alpha = 200, alpha_step = -1;
6394 int alpha_ticks = 0;
6395 char mapping[4096], temp[4096];
6396 int font_name = FONT_TEXT_1;
6397 int font_info = FONT_REQUEST;
6398 int ystep1 = getFontHeight(font_name) + 2;
6399 int ystep2 = getFontHeight(font_info) + 2;
6407 int axis, button, hat, hat_value;
6410 *step, *prev_step, steps[] =
6412 { 356, 155, MARKER_BUTTON, "a", },
6413 { 396, 122, MARKER_BUTTON, "b", },
6414 { 320, 125, MARKER_BUTTON, "x", },
6415 { 358, 95, MARKER_BUTTON, "y", },
6416 { 162, 125, MARKER_BUTTON, "back", },
6417 { 216, 125, MARKER_BUTTON, "guide", },
6418 { 271, 125, MARKER_BUTTON, "start", },
6419 { 110, 200, MARKER_BUTTON, "dpleft", },
6420 { 146, 228, MARKER_BUTTON, "dpdown", },
6421 { 178, 200, MARKER_BUTTON, "dpright", },
6422 { 146, 172, MARKER_BUTTON, "dpup", },
6423 { 50, 40, MARKER_BUTTON, "leftshoulder", },
6424 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
6425 { 382, 40, MARKER_BUTTON, "rightshoulder", },
6426 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
6427 { 73, 141, MARKER_BUTTON, "leftstick", },
6428 { 282, 210, MARKER_BUTTON, "rightstick", },
6429 { 73, 141, MARKER_AXIS_X, "leftx", },
6430 { 73, 141, MARKER_AXIS_Y, "lefty", },
6431 { 282, 210, MARKER_AXIS_X, "rightx", },
6432 { 282, 210, MARKER_AXIS_Y, "righty", },
6435 unsigned int event_frame_delay = 0;
6436 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
6438 ResetDelayCounter(&event_frame_delay);
6440 if (!bitmaps_initialized)
6442 controller = LoadCustomImage("joystick/controller.png");
6443 button = LoadCustomImage("joystick/button.png");
6444 axis_x = LoadCustomImage("joystick/axis_x.png");
6445 axis_y = LoadCustomImage("joystick/axis_y.png");
6447 bitmaps_initialized = TRUE;
6450 name = getFormattedJoystickName(SDL_JoystickName(joystick));
6453 /* print info about the joystick we are watching */
6454 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
6455 SDL_JoystickInstanceID(joystick), name);
6456 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
6457 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
6458 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
6461 /* initialize mapping with GUID and name */
6462 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
6464 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
6465 temp, name, SDL_GetPlatform());
6467 /* loop through all steps (buttons and axes), getting joystick events */
6468 for (i = 0; i < SDL_arraysize(steps) && !done;)
6470 Bitmap *marker = button; /* initialize with reliable default value */
6473 strcpy(step->mapping, mapping);
6477 step->hat_value = -1;
6479 marker = (step->marker == MARKER_BUTTON ? button :
6480 step->marker == MARKER_AXIS_X ? axis_x :
6481 step->marker == MARKER_AXIS_Y ? axis_y : marker);
6485 while (!done && !next)
6487 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
6488 alpha_ticks = SDL_GetTicks();
6495 else if (alpha < 128)
6501 int controller_x = SX + (SXSIZE - controller->width) / 2;
6502 int controller_y = SY + ystep2;
6504 int marker_x = controller_x + step->x;
6505 int marker_y = controller_y + step->y;
6507 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
6508 int ystart2 = ystart1 + ystep1 + ystep2;
6512 DrawTextSCentered(ystart1, font_name, name);
6514 DrawTextSCentered(ystart2 + 0 * ystep2, font_info,
6515 "Press buttons and move axes on");
6516 DrawTextSCentered(ystart2 + 1 * ystep2, font_info,
6517 "your controller when indicated.");
6518 DrawTextSCentered(ystart2 + 2 * ystep2, font_info,
6519 "(Your controller may look different.)");
6521 #if defined(PLATFORM_ANDROID)
6522 DrawTextSCentered(ystart2 + 4 * ystep2, font_info,
6523 "To correct a mistake,");
6524 DrawTextSCentered(ystart2 + 5 * ystep2, font_info,
6525 "press the 'back' button.");
6526 DrawTextSCentered(ystart2 + 6 * ystep2, font_info,
6527 "To skip a button or axis,");
6528 DrawTextSCentered(ystart2 + 7 * ystep2, font_info,
6529 "press the 'menu' button.");
6531 DrawTextSCentered(ystart2 + 4 * ystep2, font_info,
6532 "To correct a mistake,");
6533 DrawTextSCentered(ystart2 + 5 * ystep2, font_info,
6534 "press the 'backspace' key.");
6535 DrawTextSCentered(ystart2 + 6 * ystep2, font_info,
6536 "To skip a button or axis,");
6537 DrawTextSCentered(ystart2 + 7 * ystep2, font_info,
6538 "press the 'return' key.");
6540 DrawTextSCentered(ystart2 + 8 * ystep2, font_info,
6541 "To exit, press the 'escape' key.");
6544 BlitBitmapMasked(controller, drawto, 0, 0,
6545 controller->width, controller->height,
6546 controller_x, controller_y);
6548 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
6550 BlitBitmapMasked(marker, drawto, 0, 0,
6551 marker->width, marker->height,
6552 marker_x, marker_y);
6554 if (!screen_initialized)
6555 FadeIn(REDRAW_FIELD);
6559 screen_initialized = TRUE;
6561 while (NextValidEvent(&event))
6565 case SDL_JOYAXISMOTION:
6566 if (event.jaxis.value > 20000 ||
6567 event.jaxis.value < -20000)
6569 for (j = 0; j < i; j++)
6570 if (steps[j].axis == event.jaxis.axis)
6575 if (step->marker != MARKER_AXIS_X &&
6576 step->marker != MARKER_AXIS_Y)
6579 step->axis = event.jaxis.axis;
6580 strcat(mapping, step->field);
6581 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
6582 strcat(mapping, temp);
6590 case SDL_JOYHATMOTION:
6591 /* ignore centering; we're probably just coming back
6592 to the center from the previous item we set */
6593 if (event.jhat.value == SDL_HAT_CENTERED)
6596 for (j = 0; j < i; j++)
6597 if (steps[j].hat == event.jhat.hat &&
6598 steps[j].hat_value == event.jhat.value)
6603 step->hat = event.jhat.hat;
6604 step->hat_value = event.jhat.value;
6605 strcat(mapping, step->field);
6606 snprintf(temp, sizeof(temp), ":h%u.%u,",
6607 event.jhat.hat, event.jhat.value );
6608 strcat(mapping, temp);
6615 case SDL_JOYBALLMOTION:
6618 case SDL_JOYBUTTONUP:
6619 for (j = 0; j < i; j++)
6620 if (steps[j].button == event.jbutton.button)
6625 step->button = event.jbutton.button;
6626 strcat(mapping, step->field);
6627 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
6628 strcat(mapping, temp);
6635 case SDL_FINGERDOWN:
6636 case SDL_MOUSEBUTTONDOWN:
6637 /* skip this step */
6644 if (event.key.keysym.sym == KSYM_BackSpace ||
6645 event.key.keysym.sym == KSYM_Back)
6654 /* undo this step */
6655 prev_step = &steps[i - 1];
6656 strcpy(mapping, prev_step->mapping);
6663 if (event.key.keysym.sym == KSYM_space ||
6664 event.key.keysym.sym == KSYM_Return ||
6665 event.key.keysym.sym == KSYM_Menu)
6667 /* skip this step */
6674 if (event.key.keysym.sym == KSYM_Escape)
6684 program.exit_function(0);
6691 // do not handle events for longer than standard frame delay period
6692 if (DelayReached(&event_frame_delay, event_frame_delay_value))
6701 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
6704 // activate mapping for this game
6705 SDL_GameControllerAddMapping(mapping);
6707 // save mapping to personal mappings
6708 SaveSetup_AddGameControllerMapping(mapping);
6711 /* wait until the last pending event was removed from event queue */
6712 while (NextValidEvent(&event));
6720 static int ConfigureJoystickMain(int player_nr)
6722 char *device_name = setup.input[player_nr].joy.device_name;
6723 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6724 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6725 int success = FALSE;
6728 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6729 return JOYSTICK_NOT_AVAILABLE;
6731 if (!joystick_active || !setup.input[player_nr].use_joystick)
6732 return JOYSTICK_NOT_AVAILABLE;
6735 FadeOut(REDRAW_FIELD);
6737 // close all joystick devices (potentially opened as game controllers)
6738 for (i = 0; i < SDL_NumJoysticks(); i++)
6739 SDLCloseJoystick(i);
6741 // open joystick device as plain joystick to configure as game controller
6742 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
6744 // as the joystick was successfully opened before, this should not happen
6745 if (joystick == NULL)
6748 // create new game controller mapping (buttons and axes) for joystick device
6749 success = ConfigureJoystickMapButtonsAndAxes(joystick);
6751 // close joystick (and maybe re-open as configured game controller later)
6752 SDL_JoystickClose(joystick);
6754 // re-open all joystick devices (potentially as game controllers)
6755 for (i = 0; i < SDL_NumJoysticks(); i++)
6758 // clear all joystick input actions for all joystick devices
6759 SDLClearJoystickState();
6761 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
6764 void ConfigureJoystick(int player_nr)
6766 boolean state = ConfigureJoystickMain(player_nr);
6768 if (state != JOYSTICK_NOT_CONFIGURED)
6770 boolean success = (state == JOYSTICK_CONFIGURED);
6771 char *message = (success ? " IS CONFIGURED! " : " NOT AVAILABLE! ");
6772 char *device_name = setup.input[player_nr].joy.device_name;
6773 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6774 int xpos = mSX - SX;
6775 int ypos = mSY - SY;
6776 unsigned int wait_frame_delay = 0;
6777 unsigned int wait_frame_delay_value = 2000;
6779 ResetDelayCounter(&wait_frame_delay);
6783 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6784 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, message);
6786 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
6792 DrawSetupScreen_Input();
6795 void DrawSetupScreen()
6797 if (setup_mode == SETUP_MODE_INPUT)
6798 DrawSetupScreen_Input();
6799 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6800 DrawChooseTree(&game_speed_current);
6801 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6802 DrawChooseTree(&scroll_delay_current);
6803 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6804 DrawChooseTree(&snapshot_mode_current);
6805 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6806 DrawChooseTree(&window_size_current);
6807 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6808 DrawChooseTree(&scaling_type_current);
6809 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6810 DrawChooseTree(&rendering_mode_current);
6811 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6812 DrawChooseTree(&artwork.gfx_current);
6813 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6814 DrawChooseTree(&artwork.snd_current);
6815 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6816 DrawChooseTree(&artwork.mus_current);
6817 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6818 DrawChooseTree(&volume_simple_current);
6819 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6820 DrawChooseTree(&volume_loops_current);
6821 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6822 DrawChooseTree(&volume_music_current);
6823 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6824 DrawChooseTree(&touch_control_current);
6825 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6826 DrawChooseTree(&move_distance_current);
6827 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6828 DrawChooseTree(&drop_distance_current);
6830 DrawSetupScreen_Generic();
6832 PlayMenuSoundsAndMusic();
6835 void RedrawSetupScreenAfterFullscreenToggle()
6837 if (setup_mode == SETUP_MODE_GRAPHICS ||
6838 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6840 // update list selection from "setup.window_scaling_percent"
6841 execSetupGraphics_setWindowSizes(TRUE);
6847 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6849 if (setup_mode == SETUP_MODE_INPUT)
6850 HandleSetupScreen_Input(mx, my, dx, dy, button);
6851 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6852 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6853 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6854 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6855 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6856 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6857 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6858 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6859 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6860 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6861 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6862 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
6863 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6864 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6865 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6866 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6867 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6868 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6869 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6870 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6871 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6872 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6873 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6874 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6875 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6876 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6877 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6878 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6879 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6880 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6882 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6885 void HandleGameActions()
6887 if (game_status != GAME_MODE_PLAYING)
6890 GameActions(); /* main game loop */
6892 if (tape.auto_play && !tape.playing)
6893 AutoPlayTape(); /* continue automatically playing next tape */
6897 /* ---------- new screen button stuff -------------------------------------- */
6899 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6903 case SCREEN_CTRL_ID_PREV_LEVEL:
6904 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6905 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6908 case SCREEN_CTRL_ID_NEXT_LEVEL:
6909 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6910 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6913 case SCREEN_CTRL_ID_PREV_PLAYER:
6914 *x = mSX + TILEX * 10;
6915 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6918 case SCREEN_CTRL_ID_NEXT_PLAYER:
6919 *x = mSX + TILEX * 12;
6920 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6924 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6930 int gfx_unpressed, gfx_pressed;
6931 void (*get_gadget_position)(int *, int *, int);
6935 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6938 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6939 getScreenMenuButtonPos,
6940 SCREEN_CTRL_ID_PREV_LEVEL,
6945 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6946 getScreenMenuButtonPos,
6947 SCREEN_CTRL_ID_NEXT_LEVEL,
6952 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6953 getScreenMenuButtonPos,
6954 SCREEN_CTRL_ID_PREV_PLAYER,
6959 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6960 getScreenMenuButtonPos,
6961 SCREEN_CTRL_ID_NEXT_PLAYER,
6969 int gfx_unpressed, gfx_pressed;
6973 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6976 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6977 -1, -1, /* these values are not constant, but can change at runtime */
6978 SCREEN_CTRL_ID_SCROLL_UP,
6982 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6983 -1, -1, /* these values are not constant, but can change at runtime */
6984 SCREEN_CTRL_ID_SCROLL_DOWN,
6991 int gfx_unpressed, gfx_pressed;
6997 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7000 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7001 -1, -1, /* these values are not constant, but can change at runtime */
7002 -1, -1, /* these values are not constant, but can change at runtime */
7003 GD_TYPE_SCROLLBAR_VERTICAL,
7004 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7005 "scroll level series vertically"
7009 static void CreateScreenMenubuttons()
7011 struct GadgetInfo *gi;
7012 unsigned int event_mask;
7015 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7017 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7018 int gfx_unpressed, gfx_pressed;
7019 int x, y, width, height;
7020 int gd_x1, gd_x2, gd_y1, gd_y2;
7021 int id = menubutton_info[i].gadget_id;
7023 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7025 menubutton_info[i].get_gadget_position(&x, &y, id);
7027 width = SC_MENUBUTTON_XSIZE;
7028 height = SC_MENUBUTTON_YSIZE;
7030 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7031 gfx_pressed = menubutton_info[i].gfx_pressed;
7032 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7033 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7034 gd_x1 = graphic_info[gfx_unpressed].src_x;
7035 gd_y1 = graphic_info[gfx_unpressed].src_y;
7036 gd_x2 = graphic_info[gfx_pressed].src_x;
7037 gd_y2 = graphic_info[gfx_pressed].src_y;
7039 gi = CreateGadget(GDI_CUSTOM_ID, id,
7040 GDI_CUSTOM_TYPE_ID, i,
7041 GDI_INFO_TEXT, menubutton_info[i].infotext,
7046 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7047 GDI_STATE, GD_BUTTON_UNPRESSED,
7048 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7049 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7050 GDI_DIRECT_DRAW, FALSE,
7051 GDI_EVENT_MASK, event_mask,
7052 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7056 Error(ERR_EXIT, "cannot create gadget");
7058 screen_gadget[id] = gi;
7062 static void CreateScreenScrollbuttons()
7064 struct GadgetInfo *gi;
7065 unsigned int event_mask;
7068 /* these values are not constant, but can change at runtime */
7069 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7070 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7071 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7072 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7074 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7076 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7077 int gfx_unpressed, gfx_pressed;
7078 int x, y, width, height;
7079 int gd_x1, gd_x2, gd_y1, gd_y2;
7080 int id = scrollbutton_info[i].gadget_id;
7082 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7084 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7085 y = mSY + scrollbutton_info[i].y;
7086 width = SC_SCROLLBUTTON_XSIZE;
7087 height = SC_SCROLLBUTTON_YSIZE;
7089 /* correct scrollbar position if placed outside menu (playfield) area */
7090 if (x > SX + SC_SCROLL_UP_XPOS)
7091 x = SX + SC_SCROLL_UP_XPOS;
7093 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7094 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7095 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7097 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7098 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7099 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7100 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7101 gd_x1 = graphic_info[gfx_unpressed].src_x;
7102 gd_y1 = graphic_info[gfx_unpressed].src_y;
7103 gd_x2 = graphic_info[gfx_pressed].src_x;
7104 gd_y2 = graphic_info[gfx_pressed].src_y;
7106 gi = CreateGadget(GDI_CUSTOM_ID, id,
7107 GDI_CUSTOM_TYPE_ID, i,
7108 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7113 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7114 GDI_STATE, GD_BUTTON_UNPRESSED,
7115 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7116 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7117 GDI_DIRECT_DRAW, FALSE,
7118 GDI_EVENT_MASK, event_mask,
7119 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7123 Error(ERR_EXIT, "cannot create gadget");
7125 screen_gadget[id] = gi;
7129 static void CreateScreenScrollbars()
7133 /* these values are not constant, but can change at runtime */
7134 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7135 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7136 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7137 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7139 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7141 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7142 int gfx_unpressed, gfx_pressed;
7143 int x, y, width, height;
7144 int gd_x1, gd_x2, gd_y1, gd_y2;
7145 struct GadgetInfo *gi;
7146 int items_max, items_visible, item_position;
7147 unsigned int event_mask;
7148 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7149 int id = scrollbar_info[i].gadget_id;
7151 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7153 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7154 y = mSY + scrollbar_info[i].y;
7155 width = scrollbar_info[i].width;
7156 height = scrollbar_info[i].height;
7158 /* correct scrollbar position if placed outside menu (playfield) area */
7159 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
7160 x = SX + SC_SCROLL_VERTICAL_XPOS;
7162 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7163 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7165 items_max = num_page_entries;
7166 items_visible = num_page_entries;
7169 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7170 gfx_pressed = scrollbar_info[i].gfx_pressed;
7171 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7172 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7173 gd_x1 = graphic_info[gfx_unpressed].src_x;
7174 gd_y1 = graphic_info[gfx_unpressed].src_y;
7175 gd_x2 = graphic_info[gfx_pressed].src_x;
7176 gd_y2 = graphic_info[gfx_pressed].src_y;
7178 gi = CreateGadget(GDI_CUSTOM_ID, id,
7179 GDI_CUSTOM_TYPE_ID, i,
7180 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7185 GDI_TYPE, scrollbar_info[i].type,
7186 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7187 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7188 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7189 GDI_WHEEL_AREA_X, SX,
7190 GDI_WHEEL_AREA_Y, SY,
7191 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7192 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7193 GDI_STATE, GD_BUTTON_UNPRESSED,
7194 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7195 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7196 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7197 GDI_DIRECT_DRAW, FALSE,
7198 GDI_EVENT_MASK, event_mask,
7199 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7203 Error(ERR_EXIT, "cannot create gadget");
7205 screen_gadget[id] = gi;
7209 void CreateScreenGadgets()
7211 CreateScreenMenubuttons();
7213 CreateScreenScrollbuttons();
7214 CreateScreenScrollbars();
7217 void FreeScreenGadgets()
7221 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7222 FreeGadget(screen_gadget[i]);
7225 void MapScreenMenuGadgets(int screen_mask)
7229 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7230 if (screen_mask & menubutton_info[i].screen_mask)
7231 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7234 void MapScreenGadgets(int num_entries)
7238 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7241 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7242 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7244 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7245 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7248 void MapScreenTreeGadgets(TreeInfo *ti)
7250 MapScreenGadgets(numTreeInfoInGroup(ti));
7253 static void HandleScreenGadgets(struct GadgetInfo *gi)
7255 int id = gi->custom_id;
7256 int button = gi->event.button;
7257 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7261 case SCREEN_CTRL_ID_PREV_LEVEL:
7262 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
7265 case SCREEN_CTRL_ID_NEXT_LEVEL:
7266 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
7269 case SCREEN_CTRL_ID_PREV_PLAYER:
7270 HandleSetupScreen_Input_Player(step, -1);
7273 case SCREEN_CTRL_ID_NEXT_PLAYER:
7274 HandleSetupScreen_Input_Player(step, +1);
7277 case SCREEN_CTRL_ID_SCROLL_UP:
7278 if (game_status == GAME_MODE_LEVELS)
7279 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7280 else if (game_status == GAME_MODE_LEVELNR)
7281 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7282 else if (game_status == GAME_MODE_SETUP)
7283 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7284 else if (game_status == GAME_MODE_INFO)
7285 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7288 case SCREEN_CTRL_ID_SCROLL_DOWN:
7289 if (game_status == GAME_MODE_LEVELS)
7290 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7291 else if (game_status == GAME_MODE_LEVELNR)
7292 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7293 else if (game_status == GAME_MODE_SETUP)
7294 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7295 else if (game_status == GAME_MODE_INFO)
7296 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7299 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7300 if (game_status == GAME_MODE_LEVELS)
7301 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7302 else if (game_status == GAME_MODE_LEVELNR)
7303 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7304 else if (game_status == GAME_MODE_SETUP)
7305 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7306 else if (game_status == GAME_MODE_INFO)
7307 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);