+ printf("::: FadeOut @ DrawMainMenuExt ...\n");
+ FadeOut(redraw_mask);
+ printf("::: FadeOut @ DrawMainMenuExt done\n");
+
+ /* needed if last screen was the editor screen */
+ UndrawSpecialEditorDoor();
+#endif
+
+#if defined(TARGET_SDL)
+ SetDrawtoField(DRAW_BACKBUFFER);
+#endif
+
+ if (CheckTitleScreen(levelset_has_changed))
+ {
+ game_status = GAME_MODE_TITLE;
+
+ DrawTitleScreen();
+
+ return;
+ }
+
+ /* level_nr may have been set to value over handicap with level editor */
+ if (setup.handicap && level_nr > leveldir_current->handicap_level)
+ level_nr = leveldir_current->handicap_level;
+
+ LoadLevel(level_nr);
+
+ SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
+
+#if 0
+ FadeOut(redraw_mask);
+#endif
+
+#if 1
+ if (redraw_mask == REDRAW_ALL)
+ {
+ // int door_state = GetDoorState();
+
+ RedrawBackground();
+
+ // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+ }
+#endif
+
+ ClearWindow();
+
+ InitializeMainControls();
+
+ DrawCursorAndText_Main(-1, FALSE);
+ DrawPreviewLevel(TRUE);
+
+ HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
+
+ TapeStop();
+ if (TAPE_IS_EMPTY(tape))
+ LoadTape(level_nr);
+ DrawCompleteVideoDisplay();
+
+ PlayMenuSound();
+ PlayMenuMusic();
+
+ /* create gadgets for main menu screen */
+ FreeScreenGadgets();
+ CreateScreenGadgets();
+
+ /* map gadgets for main menu screen */
+ MapTapeButtons();
+ MapScreenMenuGadgets(SCREEN_MASK_MAIN);
+
+#if 1
+ DrawMaskedBorder(REDRAW_ALL);
+#endif
+
+#if 1
+ if (redraw_mask == REDRAW_ALL)
+ {
+ int door_state = GetDoorState();
+
+ // RedrawBackground();
+
+ OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+ }
+#endif
+
+ FadeIn(redraw_mask);
+
+ FadeSetEnterMenu();
+
+ SetMouseCursor(CURSOR_DEFAULT);
+
+ InitAnimation();
+
+ OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
+}
+
+void DrawAndFadeInMainMenu(int redraw_mask)
+{
+ DrawMainMenuExt(redraw_mask, TRUE);
+}
+
+void DrawMainMenu()
+{
+ DrawMainMenuExt(REDRAW_ALL, FALSE);
+}
+
+#if 0
+static void gotoTopLevelDir()
+{
+ /* move upwards to top level directory */
+ while (leveldir_current->node_parent)
+ {
+ /* write a "path" into level tree for easy navigation to last level */
+ if (leveldir_current->node_parent->node_group->cl_first == -1)
+ {
+ int num_leveldirs = numTreeInfoInGroup(leveldir_current);
+ int leveldir_pos = posTreeInfo(leveldir_current);
+ int num_page_entries;
+ int cl_first, cl_cursor;
+
+ if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
+ num_page_entries = num_leveldirs;
+ else
+ num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
+
+ cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
+ cl_cursor = leveldir_pos - cl_first;
+
+ leveldir_current->node_parent->node_group->cl_first = cl_first;
+ leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
+ }
+
+ leveldir_current = leveldir_current->node_parent;
+ }
+}
+#endif
+
+void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
+{
+ static unsigned long title_delay = 0;
+ static int title_screen_nr = 0;
+ static int last_sound = -1, last_music = -1;
+ boolean return_to_main_menu = FALSE;
+ boolean use_fading_main_menu = TRUE;
+#if 0
+#if 1
+ boolean use_cross_fading = FALSE;
+#else
+ boolean use_cross_fading = !show_title_initial; /* default */
+#endif
+#endif
+ struct TitleControlInfo *tci;
+ struct TitleFadingInfo fading_default;
+ struct TitleFadingInfo fading_last = fading;
+ struct TitleFadingInfo fading_next;
+ int sound, music;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+#if 0
+ boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
+#endif
+
+#if 0
+ int last_game_status = game_status; /* save current game status */
+#endif
+
+ title_delay = 0;
+ title_screen_nr = 0;
+ tci = &title_controls[title_screen_nr];
+
+ last_sound = SND_UNDEFINED;
+ last_music = MUS_UNDEFINED;
+
+#if 0
+ /* determine number of title screens to display (images and messages) */
+ InitializeTitleControls();
+#endif
+
+ if (game_status == GAME_MODE_INFO)
+ {
+ if (num_title_screens == 0)
+ {
+ DrawInfoScreen_NotAvailable("Title screen information:",
+ "No title screen for this level set.");
+
+#if 0
+ /* use default settings for fading, but always disable auto delay */
+ fading = title_default;
+ fading.auto_delay = -1;
+#endif
+
+ return;
+ }
+
+ FadeSoundsAndMusic();
+
+#if 1
+ FadeOut(REDRAW_ALL);
+#endif
+ }
+
+ if (tci->is_image)
+ DrawTitleScreenImage(tci->local_nr, tci->initial);
+ else
+ DrawTitleScreenMessage(tci->local_nr, tci->initial);
+
+ fading_default = (tci->initial ? title_initial_default : title_default);
+
+ fading = fading_next = getTitleFading(tci);
+
+#if 1
+#if 1
+ if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
+ fading_next.fade_mode & FADE_TYPE_TRANSFORM)
+ {
+ fading.fade_mode = FADE_MODE_FADE;
+ fading.fade_delay = fading_default.fade_delay;
+ }
+#else
+ if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
+ fading_next.fade_mode == FADE_MODE_CROSSFADE)
+ fading.fade_mode = FADE_MODE_FADE;
+#endif
+#endif
+
+#if 1
+ sound = getTitleSound(tci);
+ music = getTitleMusic(tci);
+
+ if (sound != last_sound)
+ PlayMenuSoundExt(sound);
+ if (music != last_music)
+ PlayMenuMusicExt(music);
+
+ last_sound = sound;
+ last_music = music;
+#endif
+
+ SetMouseCursor(CURSOR_NONE);
+
+ // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
+
+#if 1
+ FadeIn(REDRAW_ALL);
+#endif
+
+ fading = fading_next;
+
+ DelayReached(&title_delay, 0); /* reset delay counter */
+
+ return;
+ }
+
+#if 1
+ if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
+ button = MB_MENU_CHOICE;
+#else
+ if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
+ button = MB_MENU_CHOICE;
+#endif
+
+ if (button == MB_MENU_LEAVE)
+ {
+ return_to_main_menu = TRUE;
+ use_fading_main_menu = FALSE;
+ }
+ else if (button == MB_MENU_CHOICE)
+ {
+#if 0
+ boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
+#endif
+
+ if (game_status == GAME_MODE_INFO && num_title_screens == 0)
+ {
+#if 0
+ FadeOut(REDRAW_FIELD);
+#endif
+
+ FadeSetEnterScreen();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawAndFadeInInfoScreen(REDRAW_FIELD);
+
+ return;
+ }
+
+ title_screen_nr++;
+ tci = &title_controls[title_screen_nr];
+
+ if (title_screen_nr < num_title_screens)
+ {
+#if 1
+#if 0
+ boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
+#endif
+#else
+ int anim_mode;
+
+ if (tci->is_image)
+ anim_mode =
+ graphic_info[getTitleScreenGraphic(tci->local_nr,
+ tci->initial)].anim_mode;
+ else
+ anim_mode = ANIM_FADE; /* ??? */
+
+ use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
+ anim_mode == ANIM_CROSSFADE ? TRUE :
+ use_cross_fading);
+#endif
+
+ sound = getTitleSound(tci);
+ music = getTitleMusic(tci);
+
+ if (sound == SND_UNDEFINED || sound != last_sound)
+ FadeSounds();
+ if (music == MUS_UNDEFINED || music != last_music)
+ FadeMusic();
+
+#if 1
+ FadeOut(REDRAW_ALL);
+#endif
+
+ if (tci->is_image)
+ DrawTitleScreenImage(tci->local_nr, tci->initial);
+ else
+ DrawTitleScreenMessage(tci->local_nr, tci->initial);
+
+ fading_next = getTitleFading(tci);
+
+#if 1
+ sound = getTitleSound(tci);
+ music = getTitleMusic(tci);
+
+ if (sound != last_sound)
+ PlayMenuSoundExt(sound);
+ if (music != last_music)
+ PlayMenuMusicExt(music);
+
+ last_sound = sound;
+ last_music = music;
+#endif
+
+#if 0
+ printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
+#endif
+
+#if 1
+ /* last screen already faded out, next screen has no animation */
+ if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
+ fading_next.fade_mode == FADE_MODE_NONE)
+ fading = fading_next;
+#else
+ /* last screen already faded out, next screen has no animation */
+ if (fading.fade_mode != FADE_MODE_CROSSFADE &&
+ fading_next.fade_mode == FADE_MODE_NONE)
+ fading = fading_next;
+#endif
+
+#if 1
+ FadeIn(REDRAW_ALL);
+#endif
+
+ fading = fading_next;
+
+ DelayReached(&title_delay, 0); /* reset delay counter */
+ }
+ else
+ {
+ FadeSoundsAndMusic();
+
+#if 0
+#if 1
+ {
+#if 0
+ boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
+#endif
+
+#if 1
+ FadeOut(REDRAW_ALL);
+#endif
+ }