+ /* needed if last screen was the editor screen */
+ UndrawSpecialEditorDoor();
+
+ /* needed if last screen was the setup screen and fullscreen state changed */
+ ToggleFullscreenIfNeeded();
+
+ /* leveldir_current may be invalid (level group, parent link) */
+ if (!validLevelSeries(leveldir_current))
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
+
+ if (leveldir_current != leveldir_last_valid)
+ levelset_has_changed = TRUE;
+
+ /* store valid level series information */
+ leveldir_last_valid = leveldir_current;
+
+ /* needed if last screen (level choice) changed graphics, sounds or music */
+ ReloadCustomArtwork(0);
+
+#if defined(TARGET_SDL)
+ SetDrawtoField(DRAW_BACKBUFFER);
+#endif
+
+#if 1
+ if (CheckTitleScreen(levelset_has_changed))
+ {
+ game_status = GAME_MODE_TITLE;
+
+ DrawTitleScreen();
+
+ return;
+ }
+
+#else
+
+ if (setup.show_titlescreen &&
+ ((levelset_has_changed &&
+ (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
+ getLevelSetMessageFilename(1, FALSE) != NULL)) ||
+ (show_title_initial &&
+ (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
+ getLevelSetMessageFilename(1, TRUE) != NULL))))
+ {
+ game_status = GAME_MODE_TITLE;
+
+ DrawTitleScreen();
+
+ return;
+ }
+#endif
+
+ /* 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);
+ ClearWindow();
+
+#if 1
+ InitializeMainControls();
+
+#if 1
+ DrawCursorAndText_Main(-1, FALSE);
+#else
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ struct MenuPosInfo *pos_button = main_controls[i].pos_button;
+ struct MenuPosInfo *pos_text = main_controls[i].pos_text;
+ struct MenuPosInfo *pos_input = main_controls[i].pos_input;
+ char *text = main_controls[i].text;
+ char *input = main_controls[i].input;
+ int button_graphic = main_controls[i].button_graphic;
+ int font_text = main_controls[i].font_text;
+ int font_input = main_controls[i].font_input;
+
+ if (pos_button != NULL)
+ DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
+ button_graphic, 0);
+
+ if (pos_text != NULL && text != NULL)
+ DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
+
+ if (pos_input != NULL && input != NULL)
+ DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
+ }
+#endif
+
+#else
+
+ DrawHeadline();
+
+ DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
+ DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
+
+ /* calculated after (possible) reload of custom artwork */
+ name_width = getTextWidth(name_text, FONT_MENU_1);
+ level_width = 9 * 32;
+
+ DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
+ FONT_INPUT_1);
+
+ DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
+ int2str(level_nr, 3), FONT_VALUE_1);
+
+ {
+ int text_height = getFontHeight(FONT_TEXT_3);
+ int xpos = getLevelRangeTextPos() * 32 + 8;
+ int ypos2 = 3 * 32 + 16;
+ int ypos1 = ypos2 - text_height;
+
+ DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
+ "%03d", leveldir_current->first_level);
+ DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
+ "%03d", leveldir_current->last_level);
+ }
+
+ for (i = 0; i < 8; i++)
+ initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
+ IMG_MENU_BUTTON));
+
+ DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
+#endif
+
+ 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);
+
+ DrawMaskedBorder(REDRAW_ALL);
+
+ if (do_fading)
+ FadeIn(redraw_mask);
+ else
+ BackToFront();
+
+ 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
+
+#if 1
+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 1
+ boolean use_cross_fading = FALSE;
+#else
+ boolean use_cross_fading = !show_title_initial; /* default */
+#endif
+ struct TitleControlInfo *tci;
+ int sound, music;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+#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.");
+
+ title.auto_delay_final = -1;
+
+ return;
+ }
+
+ FadeSoundsAndMusic();
+
+ FadeOut(REDRAW_ALL);
+ }
+
+ if (tci->is_image)
+ {
+ DrawTitleScreenImage(tci->local_nr, tci->initial);
+ }
+ else
+ {
+ DrawTitleScreenMessage(tci->local_nr, tci->initial);
+
+ title.fade_delay_final = title.fade_delay;
+ title.post_delay_final = title.post_delay;
+ title.auto_delay_final = -1;
+ }
+
+#if 1
+ sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
+ music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
+
+ if (sound != last_sound)
+ PlayMenuSoundExt(sound);
+ if (music != last_music)
+ PlayMenuMusicExt(music);
+
+ last_sound = sound;
+ last_music = music;
+#endif
+
+ SetMouseCursor(CURSOR_NONE);
+
+ FadeIn(REDRAW_ALL);
+
+ DelayReached(&title_delay, 0); /* reset delay counter */
+
+ return;
+ }
+
+ if (title.auto_delay_final > -1 &&
+ DelayReached(&title_delay, title.auto_delay_final))
+ button = MB_MENU_CHOICE;
+
+ if (button == MB_MENU_LEAVE)
+ {
+ return_to_main_menu = TRUE;
+ use_fading_main_menu = FALSE;
+ }
+ else if (button == MB_MENU_CHOICE)
+ {
+ int anim_mode;
+
+ if (game_status == GAME_MODE_INFO && num_title_screens == 0)
+ {
+ FadeOut(REDRAW_FIELD);
+
+ info_mode = INFO_MODE_MAIN;
+ DrawAndFadeInInfoScreen(REDRAW_FIELD);
+
+ return;
+ }
+
+ title_screen_nr++;
+ tci = &title_controls[title_screen_nr];
+
+ 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);
+
+ if (title_screen_nr < num_title_screens)
+ {
+ sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
+ music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
+
+ if (sound == SND_UNDEFINED || sound != last_sound)
+ FadeSounds();
+ if (music == MUS_UNDEFINED || music != last_music)
+ FadeMusic();
+
+ if (use_cross_fading)
+ FadeCrossSaveBackbuffer();
+ else
+ FadeOut(REDRAW_ALL);
+
+ if (tci->is_image)
+ DrawTitleScreenImage(tci->local_nr, tci->initial);
+ else
+ DrawTitleScreenMessage(tci->local_nr, tci->initial);
+
+#if 1
+ sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
+ music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);