+ /* if chars *and* width set to "-1", automatically determine width */
+ if (tmi->chars == -1 && tmi->width == -1)
+ tmi->width = viewport.window[game_status].width;
+
+ /* if lines *and* height set to "-1", automatically determine height */
+ if (tmi->lines == -1 && tmi->height == -1)
+ tmi->height = viewport.window[game_status].height;
+
+ /* if chars set to "-1", automatically determine by text and font width */
+ if (tmi->chars == -1)
+ tmi->chars = tmi->width / getFontWidth(tmi->font);
+ else
+ tmi->width = tmi->chars * getFontWidth(tmi->font);
+
+ /* if lines set to "-1", automatically determine by text and font height */
+ if (tmi->lines == -1)
+ tmi->lines = tmi->height / getFontHeight(tmi->font);
+ else
+ tmi->height = tmi->lines * getFontHeight(tmi->font);
+
+ /* if x set to "-1", automatically determine by width and alignment */
+ if (tmi->x == -1)
+ tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
+
+ /* if y set to "-1", automatically determine by height and alignment */
+ if (tmi->y == -1)
+ tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
+
+ SetDrawBackgroundMask(REDRAW_ALL);
+ SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
+
+ ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+ DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
+ filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
+ tmi->autowrap, tmi->centered, tmi->parse_comments);
+
+ SetGameStatus(last_game_status); /* restore current game status */
+}
+
+void DrawTitleScreen()
+{
+ KeyboardAutoRepeatOff();
+
+ HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
+
+ StopAnimation();
+}
+
+boolean CheckTitleScreen(boolean levelset_has_changed)
+{
+ static boolean show_title_initial = TRUE;
+ boolean show_titlescreen = FALSE;
+
+ /* needed to be able to skip title screen, if no image or message defined */
+ InitializeTitleControls(show_title_initial);
+
+ if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
+ show_titlescreen = TRUE;
+
+ /* show initial title images and messages only once at program start */
+ show_title_initial = FALSE;
+
+ return (show_titlescreen && num_title_screens > 0);
+}
+
+void DrawMainMenu()
+{
+ static LevelDirTree *leveldir_last_valid = NULL;
+ boolean levelset_has_changed = FALSE;
+ int fade_mask = REDRAW_FIELD;
+
+ LimitScreenUpdates(FALSE);
+
+ FadeSetLeaveScreen();
+
+ /* do not fade out here -- function may continue and fade on editor screen */
+
+ UnmapAllGadgets();
+ FadeSoundsAndMusic();
+
+ KeyboardAutoRepeatOn();
+ ActivateJoystick();
+
+ audio.sound_deactivated = FALSE;
+
+ GetPlayerConfig();
+
+ /* needed if last screen was the playing screen, invoked from level editor */
+ if (level_editor_test_game)
+ {
+ CloseDoor(DOOR_CLOSE_ALL);
+
+ SetGameStatus(GAME_MODE_EDITOR);
+
+ DrawLevelEd();
+
+ return;
+ }
+
+ /* needed if last screen was the setup screen and fullscreen state changed */
+ // (moved to "execSetupGraphics()" to change fullscreen state directly)
+ // ToggleFullscreenOrChangeWindowScalingIfNeeded();
+
+ /* 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;
+
+ init_last = init; /* switch to new busy animation */
+
+ /* needed if last screen (level choice) changed graphics, sounds or music */
+ ReloadCustomArtwork(0);
+
+ if (CheckTitleScreen(levelset_has_changed))
+ {
+ game_status_last_screen = GAME_MODE_MAIN;
+
+ SetGameStatus(GAME_MODE_TITLE);
+
+ DrawTitleScreen();
+
+ return;
+ }
+
+ /* needed if different viewport properties defined for menues */
+ ChangeViewportPropertiesIfNeeded();
+
+ if (redraw_mask & REDRAW_ALL)
+ fade_mask = REDRAW_ALL;
+
+ if (CheckIfGlobalBorderHasChanged())
+ fade_mask = REDRAW_ALL;
+
+ FadeOut(fade_mask);
+
+ /* needed if last screen was the editor screen */
+ UndrawSpecialEditorDoor();
+
+ SetDrawtoField(DRAW_BACKBUFFER);
+
+ /* 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);
+ LoadScore(level_nr);
+
+ // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
+ SetDrawDeactivationMask(REDRAW_NONE);
+ SetDrawBackgroundMask(REDRAW_FIELD);
+
+ SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
+
+#if 0
+ if (fade_mask == REDRAW_ALL)
+ RedrawGlobalBorder();
+#endif
+
+ ClearField();
+
+ InitializeMainControls();
+
+ DrawCursorAndText_Main(-1, FALSE, FALSE);
+ DrawPreviewLevelInitial();
+
+ 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);
+
+ /* copy actual game door content to door double buffer for OpenDoor() */
+ BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
+ BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
+
+ OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
+ DrawMaskedBorder(fade_mask);
+
+ FadeIn(fade_mask);
+ FadeSetEnterMenu();
+
+ /* update screen area with special editor door */
+ redraw_mask |= REDRAW_ALL;
+ BackToFront();
+
+ SetMouseCursor(CURSOR_DEFAULT);
+
+ InitAnimation();
+
+ OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
+}
+
+static void gotoTopLevelDir()
+{
+ /* move upwards until inside (but not above) top level directory */
+ while (leveldir_current->node_parent &&
+ !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
+ {
+ /* 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;
+ }
+}
+
+void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
+{
+ static unsigned int title_delay = 0;
+ static int title_screen_nr = 0;
+ static int last_sound = -1, last_music = -1;
+ boolean return_to_main_menu = FALSE;
+ struct TitleControlInfo *tci;
+ int sound, music;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ title_delay = 0;
+ title_screen_nr = 0;
+ tci = &title_controls[title_screen_nr];
+
+ last_sound = SND_UNDEFINED;
+ last_music = MUS_UNDEFINED;
+
+ if (num_title_screens != 0)
+ {
+ FadeSetEnterScreen();
+
+ /* use individual title fading instead of global "enter screen" fading */
+ fading = getTitleFading(tci);
+ }
+
+ if (game_status_last_screen == GAME_MODE_INFO)
+ {
+ if (num_title_screens == 0)
+ {
+ /* switch game mode from title screen mode back to info screen mode */
+ SetGameStatus(GAME_MODE_INFO);
+
+ DrawInfoScreen_NotAvailable("Title screen information:",
+ "No title screen for this level set.");
+
+ return;
+ }
+
+ FadeSoundsAndMusic();
+
+ FadeOut(REDRAW_ALL);
+ }
+
+ /* only required to update logic for redrawing global border */
+ ClearField();
+
+ /* title screens may have different window size */
+ ChangeViewportPropertiesIfNeeded();
+
+ if (tci->is_image)
+ DrawTitleScreenImage(tci->local_nr, tci->initial);
+ else
+ DrawTitleScreenMessage(tci->local_nr, tci->initial);
+
+ sound = getTitleSound(tci);
+ music = getTitleMusic(tci);
+
+ if (sound != last_sound)
+ PlayMenuSoundExt(sound);
+ if (music != last_music)
+ PlayMenuMusicExt(music);
+
+ last_sound = sound;
+ last_music = music;
+
+ SetMouseCursor(CURSOR_NONE);
+
+ FadeIn(REDRAW_ALL);
+
+ DelayReached(&title_delay, 0); /* reset delay counter */
+
+ return;
+ }
+
+ if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
+ button = MB_MENU_CHOICE;
+
+ if (button == MB_MENU_LEAVE)
+ {
+ return_to_main_menu = TRUE;
+ }
+ else if (button == MB_MENU_CHOICE)
+ {
+ if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
+ {
+ SetGameStatus(GAME_MODE_INFO);
+
+ info_mode = INFO_MODE_MAIN;
+
+ DrawInfoScreen();
+
+ return;
+ }
+
+ title_screen_nr++;
+ tci = &title_controls[title_screen_nr];
+
+ if (title_screen_nr < num_title_screens)
+ {
+ sound = getTitleSound(tci);
+ music = getTitleMusic(tci);
+
+ if (sound == SND_UNDEFINED || sound != last_sound)
+ FadeSounds();
+ if (music == MUS_UNDEFINED || music != last_music)
+ FadeMusic();
+
+ fading = getTitleFading(tci);
+
+ FadeOut(REDRAW_ALL);
+
+ if (tci->is_image)
+ DrawTitleScreenImage(tci->local_nr, tci->initial);
+ else
+ DrawTitleScreenMessage(tci->local_nr, tci->initial);
+
+ sound = getTitleSound(tci);
+ music = getTitleMusic(tci);
+
+ if (sound != last_sound)
+ PlayMenuSoundExt(sound);
+ if (music != last_music)
+ PlayMenuMusicExt(music);
+
+ last_sound = sound;
+ last_music = music;
+
+ FadeIn(REDRAW_ALL);
+
+ DelayReached(&title_delay, 0); /* reset delay counter */
+ }
+ else
+ {
+ FadeSoundsAndMusic();
+
+ return_to_main_menu = TRUE;
+ }
+ }
+
+ if (return_to_main_menu)
+ {
+ SetMouseCursor(CURSOR_DEFAULT);
+
+ /* force full menu screen redraw after displaying title screens */
+ redraw_mask = REDRAW_ALL;
+
+ if (game_status_last_screen == GAME_MODE_INFO)
+ {
+ SetGameStatus(GAME_MODE_INFO);
+
+ info_mode = INFO_MODE_MAIN;
+
+ DrawInfoScreen();
+ }
+ else /* default: return to main menu */
+ {
+ SetGameStatus(GAME_MODE_MAIN);
+
+ DrawMainMenu();
+ }
+ }
+}
+
+void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
+{
+ int old_level_nr = level_nr;
+ int new_level_nr;
+
+ if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
+ new_level_nr = selected_level_nr;
+ else
+ new_level_nr = old_level_nr + step * direction;
+
+ if (new_level_nr < leveldir_current->first_level)
+ new_level_nr = leveldir_current->first_level;
+ if (new_level_nr > leveldir_current->last_level)
+ new_level_nr = leveldir_current->last_level;
+
+ if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
+ {
+ /* skipping levels is only allowed when trying to skip single level */
+ if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
+ Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
+ {
+ leveldir_current->handicap_level++;
+ SaveLevelSetup_SeriesInfo();
+ }
+
+ new_level_nr = leveldir_current->handicap_level;
+ }
+
+ if (new_level_nr != old_level_nr)
+ {
+ struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
+
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ level_nr = new_level_nr;
+
+ DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
+ int2str(level_nr, menu.main.text.level_number.size),
+ mci->pos_text->font);
+
+ LoadLevel(level_nr);
+ DrawPreviewLevelInitial();
+
+ TapeErase();
+ LoadTape(level_nr);
+ DrawCompleteVideoDisplay();
+
+ /* needed because DrawPreviewLevelInitial() takes some time */
+ BackToFront();
+ /* SyncDisplay(); */
+ }
+}
+
+void HandleMainMenu(int mx, int my, int dx, int dy, int button)
+{
+ static int choice = MAIN_CONTROL_GAME;
+ static boolean button_pressed_last = FALSE;
+ boolean button_pressed = FALSE;
+ int pos = choice;
+ int i;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ DrawCursorAndText_Main(choice, TRUE, FALSE);
+
+ return;
+ }
+
+ if (mx || my) /* mouse input */
+ {
+ pos = -1;
+
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
+ insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
+ insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
+ {
+ pos = main_controls[i].nr;
+
+ break;
+ }
+ }
+
+ // handle pressed/unpressed state for active/inactive menu buttons
+ // (if pos != -1, "i" contains index position corresponding to "pos")
+ if (button &&
+ pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
+ insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
+ button_pressed = TRUE;
+
+ if (button_pressed != button_pressed_last)
+ {
+ DrawCursorAndText_Main(choice, TRUE, button_pressed);
+
+ if (button_pressed)
+ PlaySound(SND_MENU_BUTTON_PRESSING);
+ else
+ PlaySound(SND_MENU_BUTTON_RELEASING);
+ }
+ }
+ else if (dx || dy) /* keyboard input */
+ {
+ if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
+ choice == MAIN_CONTROL_SETUP))
+ button = MB_MENU_CHOICE;
+ else if (dy)
+ pos = choice + dy;
+ }
+
+ if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
+ {
+ HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
+ }
+ else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
+ {
+ HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
+ }
+ else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
+ {
+ HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
+ }
+ else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
+ {
+ StopAnimation();
+
+ CloseDoor(DOOR_CLOSE_2);
+
+ SetGameStatus(GAME_MODE_LEVELNR);
+
+ ChangeViewportPropertiesIfNeeded();
+
+ DrawChooseLevelNr();
+ }
+ else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
+ {
+ if (button)
+ {
+ if (pos != choice)
+ {
+ PlaySound(SND_MENU_ITEM_ACTIVATING);
+
+ DrawCursorAndText_Main(choice, FALSE, FALSE);
+ DrawCursorAndText_Main(pos, TRUE, button_pressed);
+
+ choice = pos;
+ }
+ }
+ else
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ if (pos == MAIN_CONTROL_NAME)
+ {
+ SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
+
+ HandleTypeName(strlen(setup.player_name), 0);
+ }
+ else if (pos == MAIN_CONTROL_LEVELS)
+ {
+ if (leveldir_first)
+ {
+ StopAnimation();
+
+ CloseDoor(DOOR_CLOSE_2);
+
+ SetGameStatus(GAME_MODE_LEVELS);
+
+ SaveLevelSetup_LastSeries();
+ SaveLevelSetup_SeriesInfo();
+
+ if (setup.internal.choose_from_top_leveldir)
+ gotoTopLevelDir();
+
+ ChangeViewportPropertiesIfNeeded();
+
+ DrawChooseLevelSet();
+ }
+ }
+ else if (pos == MAIN_CONTROL_SCORES)
+ {
+ StopAnimation();
+
+ CloseDoor(DOOR_CLOSE_2);
+
+ SetGameStatus(GAME_MODE_SCORES);
+
+ DrawHallOfFame(-1);
+ }
+ else if (pos == MAIN_CONTROL_EDITOR)
+ {
+ if (leveldir_current->readonly &&
+ !strEqual(setup.player_name, "Artsoft"))
+ Request("This level is read only!", REQ_CONFIRM);
+
+ StopAnimation();
+
+ CloseDoor(DOOR_CLOSE_2);
+
+ SetGameStatus(GAME_MODE_EDITOR);
+
+ FadeSetEnterScreen();
+
+ DrawLevelEd();
+ }
+ else if (pos == MAIN_CONTROL_INFO)
+ {
+ StopAnimation();
+
+ CloseDoor(DOOR_CLOSE_2);
+
+ SetGameStatus(GAME_MODE_INFO);
+
+ info_mode = INFO_MODE_MAIN;
+
+ ChangeViewportPropertiesIfNeeded();
+
+ DrawInfoScreen();
+ }
+ else if (pos == MAIN_CONTROL_GAME)
+ {
+ StopAnimation();
+
+ StartGameActions(options.network, setup.autorecord, level.random_seed);
+ }
+ else if (pos == MAIN_CONTROL_SETUP)
+ {
+ StopAnimation();
+
+ CloseDoor(DOOR_CLOSE_2);
+
+ SetGameStatus(GAME_MODE_SETUP);
+
+ setup_mode = SETUP_MODE_MAIN;
+
+ ChangeViewportPropertiesIfNeeded();
+
+ DrawSetupScreen();
+ }
+ else if (pos == MAIN_CONTROL_QUIT)
+ {
+ SaveLevelSetup_LastSeries();
+ SaveLevelSetup_SeriesInfo();
+
+ if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
+ SetGameStatus(GAME_MODE_QUIT);
+ }
+ }
+ }
+
+ button_pressed_last = button_pressed;
+}
+
+
+/* ========================================================================= */
+/* info screen functions */
+/* ========================================================================= */
+
+static struct TokenInfo *info_info;
+static int num_info_info; /* number of info entries shown on screen */
+static int max_info_info; /* total number of info entries in list */
+
+static void execInfoTitleScreen()
+{
+ info_mode = INFO_MODE_TITLE;
+
+ DrawInfoScreen();
+}
+
+static void execInfoElements()
+{
+ info_mode = INFO_MODE_ELEMENTS;
+
+ DrawInfoScreen();
+}
+
+static void execInfoMusic()
+{
+ info_mode = INFO_MODE_MUSIC;
+
+ DrawInfoScreen();
+}
+
+static void execInfoCredits()
+{
+ info_mode = INFO_MODE_CREDITS;
+
+ DrawInfoScreen();
+}
+
+static void execInfoProgram()
+{
+ info_mode = INFO_MODE_PROGRAM;
+
+ DrawInfoScreen();
+}
+
+static void execInfoVersion()
+{
+ info_mode = INFO_MODE_VERSION;
+
+ DrawInfoScreen();
+}
+
+static void execInfoLevelSet()
+{
+ info_mode = INFO_MODE_LEVELSET;
+
+ DrawInfoScreen();
+}
+
+static void execExitInfo()
+{
+ SetGameStatus(GAME_MODE_MAIN);
+
+ DrawMainMenu();
+}
+
+static struct TokenInfo info_info_main[] =
+{
+ { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
+ { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
+ { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
+ { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
+ { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
+ { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
+ { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
+ { TYPE_EMPTY, NULL, "" },
+ { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
+
+ { 0, NULL, NULL }
+};
+
+static int getMenuTextFont(int type)
+{
+ if (type & (TYPE_SWITCH |
+ TYPE_YES_NO |
+ TYPE_YES_NO_AUTO |
+ TYPE_STRING |
+ TYPE_ECS_AGA |
+ TYPE_KEYTEXT |
+ TYPE_ENTER_LIST))
+ return FONT_MENU_2;
+ else
+ return FONT_MENU_1;
+}
+
+static struct TokenInfo *setup_info;
+static struct TokenInfo setup_info_input[];
+
+static struct TokenInfo *menu_info;
+
+static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
+ int screen_pos, int menu_info_pos_raw,
+ boolean active)
+{
+ int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
+ struct TokenInfo *ti = &token_info[pos];
+ int xpos = MENU_SCREEN_START_XPOS;
+ int ypos = MENU_SCREEN_START_YPOS + screen_pos;
+ int font_nr = getMenuTextFont(ti->type);
+
+ if (token_info == setup_info_input)
+ font_nr = FONT_MENU_1;
+
+ if (active)
+ font_nr = FONT_ACTIVE(font_nr);
+
+ DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
+
+ if (ti->type & ~TYPE_SKIP_ENTRY)
+ drawCursor(screen_pos, active);
+}
+
+static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
+ boolean active)
+{
+ DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
+}
+
+static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
+ boolean active)
+{
+ DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
+}
+
+static char *screen_mode_text;
+static char *window_size_text;
+static char *scaling_type_text;
+
+static void drawSetupValue(int, int);
+
+static void drawMenuInfoList(int first_entry, int num_page_entries,
+ int max_page_entries)
+{
+ int i;
+
+ if (first_entry + num_page_entries > max_page_entries)
+ first_entry = 0;
+
+ clearMenuListArea();
+
+ for (i = 0; i < num_page_entries; i++)
+ {
+ int menu_info_pos = first_entry + i;
+ struct TokenInfo *si = &menu_info[menu_info_pos];
+ void *value_ptr = si->value;
+
+ /* set some entries to "unchangeable" according to other variables */
+ if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
+ (value_ptr == &setup.sound_loops && !audio.loops_available) ||
+ (value_ptr == &setup.sound_music && !audio.music_available) ||
+ (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
+ (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
+ (value_ptr == &window_size_text && !video.window_scaling_available) ||
+ (value_ptr == &scaling_type_text && !video.window_scaling_available))
+ si->type |= TYPE_GHOSTED;
+
+ if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
+ initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
+ else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
+ initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
+ else if (si->type & ~TYPE_SKIP_ENTRY)
+ initCursor(i, IMG_MENU_BUTTON);
+
+ DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
+
+ if (si->type & TYPE_VALUE &&
+ menu_info == setup_info)
+ drawSetupValue(i, menu_info_pos);
+ }
+}
+
+static void DrawInfoScreen_Main()
+{
+ int fade_mask = REDRAW_FIELD;
+ int i;
+
+ if (redraw_mask & REDRAW_ALL)
+ fade_mask = REDRAW_ALL;
+
+ if (CheckIfGlobalBorderHasChanged())
+ fade_mask = REDRAW_ALL;
+
+ UnmapAllGadgets();
+
+ FreeScreenGadgets();
+ CreateScreenGadgets();
+
+ /* (needed after displaying title screens which disable auto repeat) */
+ KeyboardAutoRepeatOn();
+
+ FadeSetLeaveScreen();
+
+ FadeOut(fade_mask);
+
+ ChangeViewportPropertiesIfNeeded();
+
+ ClearField();
+
+ OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
+ DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
+
+ info_info = info_info_main;
+
+ // determine maximal number of info entries that can be displayed on screen
+ num_info_info = 0;
+ for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
+ num_info_info++;
+
+ // determine maximal number of info entries available for menu of info screen
+ max_info_info = 0;
+ for (i = 0; info_info[i].type != 0; i++)
+ max_info_info++;
+
+ HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
+
+ MapScreenGadgets(max_info_info);
+
+ PlayMenuSound();
+ PlayMenuMusic();
+
+ DrawMaskedBorder(fade_mask);
+
+ FadeIn(fade_mask);
+
+ InitAnimation();
+}
+
+static void changeSetupValue(int, int, int);
+
+void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
+ int mode, int num_page_entries, int max_page_entries)
+{
+ static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
+ static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
+ static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
+ int *num_page_entries_last = num_page_entries_all_last[game_status];
+ int *choice_store = choice_stores[game_status];
+ int *first_entry_store = first_entry_stores[game_status];
+ int choice = choice_store[mode]; /* starts with 0 */
+ int first_entry = first_entry_store[mode]; /* starts with 0 */
+ int x = 0;
+ int y = choice - first_entry;
+ int y_old = y;
+ boolean position_set_by_scrollbar = (dx == 999);
+ int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
+ int i;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ // check if number of menu page entries has changed (may happen by change
+ // of custom artwork definition value for 'list_size' for this menu screen)
+ // (in this case, the last menu position most probably has to be corrected)
+ if (num_page_entries != num_page_entries_last[mode])
+ {
+ choice_store[mode] = first_entry_store[mode] = 0;
+
+ choice = first_entry = 0;
+ y = y_old = 0;
+
+ num_page_entries_last[mode] = num_page_entries;
+ }
+
+ /* advance to first valid menu entry */
+ while (choice < num_page_entries &&
+ menu_info[choice].type & TYPE_SKIP_ENTRY)
+ choice++;
+
+ if (position_set_by_scrollbar)
+ first_entry = first_entry_store[mode] = dy;
+ else
+ AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
+ NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
+
+ drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
+
+ if (choice < first_entry)
+ {
+ choice = first_entry;
+
+ if (menu_info[choice].type & TYPE_SKIP_ENTRY)
+ choice++;
+ }
+ else if (choice > first_entry + num_page_entries - 1)
+ {
+ choice = first_entry + num_page_entries - 1;
+
+ if (menu_info[choice].type & TYPE_SKIP_ENTRY)
+ choice--;
+ }
+
+ choice_store[mode] = choice;
+
+ DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
+
+ return;
+ }
+ else if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ for (i = 0; i < max_page_entries; i++)
+ {
+ if (menu_info[i].type & TYPE_LEAVE_MENU)
+ {
+ void (*menu_callback_function)(void) = menu_info[i].value;
+
+ FadeSetLeaveMenu();
+
+ menu_callback_function();
+
+ break; /* absolutely needed because function changes 'menu_info'! */
+ }
+ }
+
+ return;
+ }
+
+ if (mx || my) /* mouse input */
+ {
+ x = (mx - mSX) / 32;
+ y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
+ }
+ else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
+ {
+ /* move cursor instead of scrolling when already at start/end of list */
+ if (dy == -1 * SCROLL_LINE && first_entry == 0)
+ dy = -1;
+ else if (dy == +1 * SCROLL_LINE &&
+ first_entry + num_page_entries == max_page_entries)
+ dy = 1;
+
+ /* handle scrolling screen one line or page */
+ if (y + dy < 0 ||
+ y + dy > num_page_entries - 1)
+ {
+ boolean redraw = FALSE;
+
+ if (ABS(dy) == SCROLL_PAGE)
+ step = num_page_entries - 1;
+
+ if (dy < 0 && first_entry > 0)
+ {
+ /* scroll page/line up */
+
+ first_entry -= step;
+ if (first_entry < 0)
+ first_entry = 0;
+
+ redraw = TRUE;
+ }
+ else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
+ {
+ /* scroll page/line down */
+
+ first_entry += step;
+ if (first_entry + num_page_entries > max_page_entries)
+ first_entry = MAX(0, max_page_entries - num_page_entries);
+
+ redraw = TRUE;
+ }
+
+ if (redraw)
+ {
+ choice += first_entry - first_entry_store[mode];
+
+ if (choice < first_entry)
+ {
+ choice = first_entry;
+
+ if (menu_info[choice].type & TYPE_SKIP_ENTRY)
+ choice++;
+ }
+ else if (choice > first_entry + num_page_entries - 1)
+ {
+ choice = first_entry + num_page_entries - 1;
+
+ if (menu_info[choice].type & TYPE_SKIP_ENTRY)
+ choice--;
+ }
+ else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
+ {
+ choice += SIGN(dy);
+
+ if (choice < first_entry ||
+ choice > first_entry + num_page_entries - 1)
+ first_entry += SIGN(dy);
+ }
+
+ first_entry_store[mode] = first_entry;
+ choice_store[mode] = choice;
+
+ drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
+
+ DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
+
+ AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
+ NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
+ }
+
+ return;
+ }
+
+ if (dx)
+ {
+ int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
+
+ if (menu_info[choice].type & menu_navigation_type ||
+ menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
+ menu_info[choice].type & TYPE_YES_NO_AUTO)
+ button = MB_MENU_CHOICE;
+ }
+ else if (dy)
+ y += dy;
+
+ /* jump to next non-empty menu entry (up or down) */
+ while (first_entry + y > 0 &&
+ first_entry + y < max_page_entries - 1 &&
+ menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
+ y += dy;
+
+ if (!IN_VIS_MENU(x, y))
+ {
+ choice += y - y_old;
+
+ if (choice < first_entry)
+ first_entry = choice;
+ else if (choice > first_entry + num_page_entries - 1)
+ first_entry = choice - num_page_entries + 1;
+
+ if (first_entry >= 0 &&
+ first_entry + num_page_entries <= max_page_entries)
+ {
+ first_entry_store[mode] = first_entry;
+
+ if (choice < first_entry)
+ choice = first_entry;
+ else if (choice > first_entry + num_page_entries - 1)
+ choice = first_entry + num_page_entries - 1;
+
+ choice_store[mode] = choice;
+
+ drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
+
+ DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
+
+ AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
+ NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
+ }
+
+ return;
+ }
+ }
+
+ if (!anyScrollbarGadgetActive() &&
+ IN_VIS_MENU(x, y) &&
+ mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
+ y >= 0 && y < num_page_entries)
+ {
+ if (button)
+ {
+ if (first_entry + y != choice &&
+ menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
+ {
+ PlaySound(SND_MENU_ITEM_ACTIVATING);
+
+ DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
+ DrawCursorAndText_Menu(y, first_entry + y, TRUE);
+
+ choice = choice_store[mode] = first_entry + y;
+ }
+ }
+ else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ /* when selecting key headline, execute function for key value change */
+ if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
+ menu_info[first_entry + y + 1].type & TYPE_KEY)
+ y++;
+
+ /* when selecting string value, execute function for list selection */
+ if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
+ menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
+ y--;
+
+ if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
+ {
+ void (*menu_callback_function)(void) =
+ menu_info[first_entry + y].value;
+
+ FadeSetFromType(menu_info[first_entry + y].type);
+
+ menu_callback_function();
+ }
+ else if (menu_info[first_entry + y].type & TYPE_VALUE &&
+ menu_info == setup_info)
+ {
+ changeSetupValue(y, first_entry + y, dx);
+ }
+ }
+ }
+}
+
+void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
+{
+ menu_info = info_info;
+
+ HandleMenuScreen(mx, my, dx, dy, button,
+ info_mode, num_info_info, max_info_info);
+}
+
+void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
+{
+ int ystart1 = mSY - SY + 100;
+ int ystart2 = mSY - SY + 150;
+ int ybottom = mSY - SY + SYSIZE - 20;
+
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
+
+ FadeOut(REDRAW_FIELD);
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
+ DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for info menu");
+
+ FadeIn(REDRAW_FIELD);
+}
+
+void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
+{
+ static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
+ static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
+ int xstart = mSX + MENU_SCREEN_INFO_XSTART;
+ int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
+ int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
+ int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
+ int ystep = MENU_SCREEN_INFO_YSTEP;
+ int element, action, direction;
+ int graphic;
+ int delay;
+ int sync_frame;
+ int i, j;
+
+ if (init)
+ {
+ for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
+ infoscreen_step[i] = infoscreen_frame[i] = 0;
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for next page");
+
+ FrameCounter = 0;
+ }
+
+ i = j = 0;
+ while (helpanim_info[j].element != HELPANIM_LIST_END)
+ {
+ if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
+ i >= max_anims)
+ break;
+ else if (i < start)
+ {
+ while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
+ j++;
+
+ j++;
+ i++;
+
+ continue;
+ }
+
+ j += infoscreen_step[i - start];
+
+ element = helpanim_info[j].element;
+ action = helpanim_info[j].action;
+ direction = helpanim_info[j].direction;
+
+ if (element < 0)
+ element = EL_UNKNOWN;
+
+ if (action != -1 && direction != -1)
+ graphic = el_act_dir2img(element, action, direction);
+ else if (action != -1)
+ graphic = el_act2img(element, action);
+ else if (direction != -1)
+ graphic = el_dir2img(element, direction);
+ else
+ graphic = el2img(element);
+
+ delay = helpanim_info[j++].delay;
+
+ if (delay == -1)
+ delay = 1000000;
+
+ if (infoscreen_frame[i - start] == 0)
+ {
+ sync_frame = 0;
+ infoscreen_frame[i - start] = delay - 1;
+ }
+ else
+ {
+ sync_frame = delay - infoscreen_frame[i - start];
+ infoscreen_frame[i - start]--;
+ }
+
+ if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
+ {
+ if (!infoscreen_frame[i - start])
+ infoscreen_step[i - start] = 0;
+ }
+ else
+ {
+ if (!infoscreen_frame[i - start])
+ infoscreen_step[i - start]++;
+ while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
+ j++;
+ }
+
+ j++;
+
+ ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
+ TILEX, TILEY);
+ DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
+ graphic, sync_frame, USE_MASKING);
+
+ if (init)
+ DrawInfoScreen_HelpText(element, action, direction, i - start);
+
+ i++;
+ }
+
+ redraw_mask |= REDRAW_FIELD;
+
+ FrameCounter++;
+}
+
+static char *getHelpText(int element, int action, int direction)
+{
+ char token[MAX_LINE_LEN];
+
+ strcpy(token, element_info[element].token_name);
+
+ if (action != -1)
+ strcat(token, element_action_info[action].suffix);
+
+ if (direction != -1)
+ strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
+
+ return getHashEntry(helptext_info, token);
+}
+
+void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
+{
+ int font_nr = FONT_INFO_ELEMENTS;
+ int font_width = getFontWidth(font_nr);
+ int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
+ int sy = mSY + 65 + 2 * 32 + 1;
+ int ystep = TILEY + 4;
+ int pad_x = sx - SX;
+ int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
+ int max_lines_per_text = 2;
+ char *text = NULL;
+
+ if (action != -1 && direction != -1) /* element.action.direction */
+ text = getHelpText(element, action, direction);
+
+ if (text == NULL && action != -1) /* element.action */
+ text = getHelpText(element, action, -1);
+
+ if (text == NULL && direction != -1) /* element.direction */
+ text = getHelpText(element, -1, direction);
+
+ if (text == NULL) /* base element */
+ text = getHelpText(element, -1, -1);
+
+ if (text == NULL) /* not found */
+ text = "No description available";
+
+ if (strlen(text) <= max_chars_per_line) /* only one line of text */
+ sy += getFontHeight(font_nr) / 2;
+
+ DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
+ max_chars_per_line, -1, max_lines_per_text, 0, -1,
+ TRUE, FALSE, FALSE);
+}
+
+void DrawInfoScreen_TitleScreen()
+{
+ game_status_last_screen = GAME_MODE_INFO;
+
+ SetGameStatus(GAME_MODE_TITLE);
+
+ DrawTitleScreen();
+}
+
+void HandleInfoScreen_TitleScreen(int button)
+{
+ HandleTitleScreen(0, 0, 0, 0, button);
+}
+
+void DrawInfoScreen_Elements()
+{
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
+
+ FadeOut(REDRAW_FIELD);
+
+ LoadHelpAnimInfo();
+ LoadHelpTextInfo();
+
+ HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
+
+ FadeIn(REDRAW_FIELD);
+
+ InitAnimation();
+}
+
+void HandleInfoScreen_Elements(int button)
+{
+ static unsigned int info_delay = 0;
+ static int num_anims;
+ static int num_pages;
+ static int page;
+ int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
+ int i;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ boolean new_element = TRUE;
+
+ num_anims = 0;
+
+ for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
+ {
+ if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
+ new_element = TRUE;
+ else if (new_element)
+ {
+ num_anims++;
+ new_element = FALSE;
+ }
+ }
+
+ num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
+ page = 0;
+ }
+
+ if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+ else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
+ {
+ if (button != MB_MENU_INITIALIZE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ page++;
+ }
+
+ if (page >= num_pages)
+ {
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+
+ if (page > 0)
+ FadeSetNextScreen();
+
+ if (button != MB_MENU_INITIALIZE)
+ FadeOut(REDRAW_FIELD);
+
+ DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
+
+ if (button != MB_MENU_INITIALIZE)
+ FadeIn(REDRAW_FIELD);
+ }
+ else
+ {
+ if (DelayReached(&info_delay, GameFrameDelay))
+ if (page < num_pages)
+ DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
+
+ PlayMenuSoundIfLoop();
+ }
+}
+
+void DrawInfoScreen_Music()
+{
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
+
+ FadeOut(REDRAW_FIELD);
+
+ ClearField();
+ DrawHeadline();
+
+ LoadMusicInfo();
+
+ HandleInfoScreen_Music(MB_MENU_INITIALIZE);
+
+ FadeIn(REDRAW_FIELD);
+}
+
+void HandleInfoScreen_Music(int button)
+{
+ static struct MusicFileInfo *list = NULL;
+ int ystart1 = mSY - SY + 100;
+ int ystart2 = mSY - SY + 150;
+ int ybottom = mSY - SY + SYSIZE - 20;
+ int dy = 30;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ list = music_file_info;
+
+ if (list == NULL)
+ {
+ FadeSoundsAndMusic();
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1,
+ "No music info for this level set.");
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for info menu");
+
+ return;
+ }
+ }
+
+ if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+ else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
+ {
+ int y = 0;
+
+ if (button != MB_MENU_INITIALIZE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ if (list != NULL)
+ list = list->next;
+ }
+
+ if (list == NULL)
+ {
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+
+ FadeSoundsAndMusic();
+
+ if (list != music_file_info)
+ FadeSetNextScreen();
+
+ if (button != MB_MENU_INITIALIZE)
+ FadeOut(REDRAW_FIELD);
+
+ ClearField();
+ DrawHeadline();
+
+ if (list->is_sound)
+ {
+ int sound = list->music;
+
+ if (sound_info[sound].loop)
+ PlaySoundLoop(sound);
+ else
+ PlaySound(sound);
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
+ }
+ else
+ {
+ PlayMusic(list->music);
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
+ }
+
+ if (!strEqual(list->title, UNKNOWN_NAME))
+ {
+ if (!strEqual(list->title_header, UNKNOWN_NAME))
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
+
+ DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
+ }
+
+ if (!strEqual(list->artist, UNKNOWN_NAME))
+ {
+ if (!strEqual(list->artist_header, UNKNOWN_NAME))
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
+ else
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
+
+ DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
+ }
+
+ if (!strEqual(list->album, UNKNOWN_NAME))
+ {
+ if (!strEqual(list->album_header, UNKNOWN_NAME))
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
+ else
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
+
+ DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
+ }
+
+ if (!strEqual(list->year, UNKNOWN_NAME))
+ {
+ if (!strEqual(list->year_header, UNKNOWN_NAME))
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
+ else
+ DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
+
+ DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
+ }
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for next page");
+
+ if (button != MB_MENU_INITIALIZE)
+ FadeIn(REDRAW_FIELD);
+ }
+
+ if (list != NULL && list->is_sound && sound_info[list->music].loop)
+ PlaySoundLoop(list->music);
+}
+
+static void DrawInfoScreen_CreditsScreen(int screen_nr)
+{
+ int ystart1 = mSY - SY + 100;
+ int ystart2 = mSY - SY + 150;
+ int ybottom = mSY - SY + SYSIZE - 20;
+ int ystep = 30;
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
+
+ if (screen_nr == 0)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Special thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Peter Liepa");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for creating");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "\"Boulder Dash\"");
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "in the year");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+ "1984");
+ DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
+ "published by");
+ DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
+ "First Star Software");
+ }
+ else if (screen_nr == 1)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Special thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Klaus Heinz & Volker Wertich");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for creating");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "\"Emerald Mine\"");
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "in the year");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+ "1987");
+ DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
+ "published by");
+ DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
+ "Kingsoft");
+ }
+ else if (screen_nr == 2)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Special thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Michael Stopp & Philip Jespersen");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for creating");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "\"Supaplex\"");
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "in the year");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+ "1991");
+ DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
+ "published by");
+ DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
+ "Digital Integration");
+ }
+ else if (screen_nr == 3)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Special thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Hiroyuki Imabayashi");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for creating");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "\"Sokoban\"");
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "in the year");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+ "1982");
+ DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
+ "published by");
+ DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
+ "Thinking Rabbit");
+ }
+ else if (screen_nr == 4)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Special thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Alan Bond");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "and");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "J\xfcrgen Bonhagen");
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "for the continuous creation");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
+ "of outstanding level sets");
+ }
+ else if (screen_nr == 5)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Peter Elzner");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for ideas and inspiration by");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "Diamond Caves");
+
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
+ "Thanks to");
+ DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
+ "Steffest");
+ DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
+ "for ideas and inspiration by");
+ DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
+ "DX-Boulderdash");
+ }
+ else if (screen_nr == 6)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "David Tritscher");
+#if 1
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for the code base used for the");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
+ "native Emerald Mine engine");
+#else
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for the new Emerald Mine engine");
+#endif
+ }
+ else if (screen_nr == 7)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "Thanks to");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
+ "Guido Schulz");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
+ "for the initial DOS port");
+
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "Thanks to");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+ "Karl H\xf6rnell");
+ DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
+ "for some additional toons");
+ }
+ else if (screen_nr == 8)
+ {
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "And not to forget:");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
+ "Many thanks to");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
+ "All those who contributed");
+ DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
+ "levels to this game");
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
+ "since 1995");
+ }
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for next page");
+}
+
+void DrawInfoScreen_Credits()
+{
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
+
+ FadeSoundsAndMusic();
+
+ FadeOut(REDRAW_FIELD);
+
+ HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
+
+ FadeIn(REDRAW_FIELD);
+}
+
+void HandleInfoScreen_Credits(int button)
+{
+ static int screen_nr = 0;
+ int num_screens = 9;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ screen_nr = 0;
+
+ // DrawInfoScreen_CreditsScreen(screen_nr);
+ }
+
+ if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+ else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
+ {
+ if (button != MB_MENU_INITIALIZE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ screen_nr++;
+ }
+
+ if (screen_nr >= num_screens)
+ {
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+
+ if (screen_nr > 0)
+ FadeSetNextScreen();
+
+ if (button != MB_MENU_INITIALIZE)
+ FadeOut(REDRAW_FIELD);
+
+ DrawInfoScreen_CreditsScreen(screen_nr);
+
+ if (button != MB_MENU_INITIALIZE)
+ FadeIn(REDRAW_FIELD);
+ }
+ else
+ {
+ PlayMenuSoundIfLoop();
+ }
+}
+
+void DrawInfoScreen_Program()
+{
+ int ystart1 = mSY - SY + 100;
+ int ystart2 = mSY - SY + 150;
+ int ybottom = mSY - SY + SYSIZE - 20;
+ int ystep = 30;
+
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
+
+ FadeOut(REDRAW_FIELD);
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
+
+ DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
+ "This game is Freeware!");
+ DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
+ "If you like it, send e-mail to:");
+ DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
+ setup.internal.program_email);
+ DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+ "More information and levels:");
+ DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+ setup.internal.program_website);
+ DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
+ "If you have created new levels,");
+ DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
+ "send them to me to include them!");
+ DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
+ ":-)");
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for info menu");
+
+ FadeIn(REDRAW_FIELD);
+}
+
+void HandleInfoScreen_Program(int button)
+{
+ if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+ else if (button == MB_MENU_CHOICE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+ }
+ else
+ {
+ PlayMenuSoundIfLoop();
+ }
+}
+
+void DrawInfoScreen_Version()
+{
+ int font_header = FONT_TEXT_3;
+ int font_text = FONT_TEXT_2;
+ int xstep = getFontWidth(font_text);
+ int ystep = getFontHeight(font_text);
+ int ystart1 = mSY - SY + 100;
+ int ystart2 = mSY - SY + 150;
+ int ybottom = mSY - SY + SYSIZE - 20;
+ int xstart1 = mSX - SX + 2 * xstep;
+ int xstart2 = mSX - SX + 18 * xstep;
+ int xstart3 = mSX - SX + 28 * xstep;
+ SDL_version sdl_version_compiled;
+ const SDL_version *sdl_version_linked;
+ int driver_name_len = 10;
+#if defined(TARGET_SDL2)
+ SDL_version sdl_version_linked_ext;
+ const char *driver_name = NULL;
+#else
+ char driver_name[driver_name_len];
+#endif
+
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
+
+ FadeOut(REDRAW_FIELD);
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
+
+ DrawTextF(xstart1, ystart2, font_header, "Name");
+ DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_header, "Version");
+ DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_header, "Platform");
+ DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_header, "Target");
+ DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_header, "Compile time");
+ DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
+
+ ystart2 += 3 * ystep;
+ DrawTextF(xstart1, ystart2, font_header, "Library");
+ DrawTextF(xstart2, ystart2, font_header, "compiled");
+ DrawTextF(xstart3, ystart2, font_header, "linked");
+
+ SDL_VERSION(&sdl_version_compiled);
+#if defined(TARGET_SDL2)
+ SDL_GetVersion(&sdl_version_linked_ext);
+ sdl_version_linked = &sdl_version_linked_ext;
+#else
+ sdl_version_linked = SDL_Linked_Version();
+#endif
+
+ ystart2 += 2 * ystep;
+ DrawTextF(xstart1, ystart2, font_text, "SDL");
+ DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
+ sdl_version_compiled.major,
+ sdl_version_compiled.minor,
+ sdl_version_compiled.patch);
+ DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
+ sdl_version_linked->major,
+ sdl_version_linked->minor,
+ sdl_version_linked->patch);
+
+ SDL_IMAGE_VERSION(&sdl_version_compiled);
+ sdl_version_linked = IMG_Linked_Version();
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_text, "SDL_image");
+ DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
+ sdl_version_compiled.major,
+ sdl_version_compiled.minor,
+ sdl_version_compiled.patch);
+ DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
+ sdl_version_linked->major,
+ sdl_version_linked->minor,
+ sdl_version_linked->patch);
+
+ SDL_MIXER_VERSION(&sdl_version_compiled);
+ sdl_version_linked = Mix_Linked_Version();
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
+ DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
+ sdl_version_compiled.major,
+ sdl_version_compiled.minor,
+ sdl_version_compiled.patch);
+ DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
+ sdl_version_linked->major,
+ sdl_version_linked->minor,
+ sdl_version_linked->patch);
+
+ SDL_NET_VERSION(&sdl_version_compiled);
+ sdl_version_linked = SDLNet_Linked_Version();
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_text, "SDL_net");
+ DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
+ sdl_version_compiled.major,
+ sdl_version_compiled.minor,
+ sdl_version_compiled.patch);
+ DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
+ sdl_version_linked->major,
+ sdl_version_linked->minor,
+ sdl_version_linked->patch);
+
+ ystart2 += 3 * ystep;
+ DrawTextF(xstart1, ystart2, font_header, "Driver");
+ DrawTextF(xstart2, ystart2, font_header, "Requested");
+ DrawTextF(xstart3, ystart2, font_header, "Used");
+
+#if defined(TARGET_SDL2)
+ driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
+#else
+ SDL_VideoDriverName(driver_name, driver_name_len);
+#endif
+
+ ystart2 += 2 * ystep;
+ DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
+ DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
+ DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
+
+#if defined(TARGET_SDL2)
+ driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
+#else
+ SDL_AudioDriverName(driver_name, driver_name_len);
+#endif
+
+ ystart2 += ystep;
+ DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
+ DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
+ DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for info menu");
+
+ FadeIn(REDRAW_FIELD);
+}
+
+void HandleInfoScreen_Version(int button)
+{
+ if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+ else if (button == MB_MENU_CHOICE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+ }
+ else
+ {
+ PlayMenuSoundIfLoop();
+ }
+}
+
+void DrawInfoScreen_LevelSet()
+{
+ struct TitleMessageInfo *tmi = &readme;
+ char *filename = getLevelSetInfoFilename();
+ char *title = "Level Set Information:";
+ int ystart1 = mSY - SY + 100;
+ int ybottom = mSY - SY + SYSIZE - 20;
+
+ if (filename == NULL)
+ {
+ DrawInfoScreen_NotAvailable(title, "No information for this level set.");
+
+ return;
+ }
+
+ SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
+
+ FadeOut(REDRAW_FIELD);
+
+ ClearField();
+ DrawHeadline();
+
+ DrawTextSCentered(ystart1, FONT_TEXT_1, title);
+
+ /* if x position set to "-1", automatically determine by playfield width */
+ if (tmi->x == -1)
+ tmi->x = SXSIZE / 2;
+
+ /* if y position set to "-1", use static default value */
+ if (tmi->y == -1)
+ tmi->y = 150;
+
+ /* if width set to "-1", automatically determine by playfield width */
+ if (tmi->width == -1)
+ tmi->width = SXSIZE - 2 * TILEX;
+
+ /* if height set to "-1", automatically determine by playfield height */
+ if (tmi->height == -1)
+ tmi->height = SYSIZE - 20 - tmi->y - 10;
+
+ /* if chars set to "-1", automatically determine by text and font width */
+ if (tmi->chars == -1)
+ tmi->chars = tmi->width / getFontWidth(tmi->font);
+ else
+ tmi->width = tmi->chars * getFontWidth(tmi->font);
+
+ /* if lines set to "-1", automatically determine by text and font height */
+ if (tmi->lines == -1)
+ tmi->lines = tmi->height / getFontHeight(tmi->font);
+ else
+ tmi->height = tmi->lines * getFontHeight(tmi->font);
+
+ DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
+ filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
+ tmi->autowrap, tmi->centered, tmi->parse_comments);
+
+ DrawTextSCentered(ybottom, FONT_TEXT_4,
+ "Press any key or button for info menu");
+
+ FadeIn(REDRAW_FIELD);
+}
+
+void HandleInfoScreen_LevelSet(int button)
+{
+ if (button == MB_MENU_LEAVE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+
+ return;
+ }
+ else if (button == MB_MENU_CHOICE)
+ {
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ FadeSoundsAndMusic();
+
+ info_mode = INFO_MODE_MAIN;
+ DrawInfoScreen();
+ }
+ else
+ {
+ PlayMenuSoundIfLoop();
+ }
+}
+
+static void DrawInfoScreen()
+{
+ SetMainBackgroundImage(IMG_BACKGROUND_INFO);
+
+ if (info_mode == INFO_MODE_TITLE)
+ DrawInfoScreen_TitleScreen();
+ else if (info_mode == INFO_MODE_ELEMENTS)
+ DrawInfoScreen_Elements();
+ else if (info_mode == INFO_MODE_MUSIC)
+ DrawInfoScreen_Music();
+ else if (info_mode == INFO_MODE_CREDITS)
+ DrawInfoScreen_Credits();
+ else if (info_mode == INFO_MODE_PROGRAM)
+ DrawInfoScreen_Program();
+ else if (info_mode == INFO_MODE_VERSION)
+ DrawInfoScreen_Version();
+ else if (info_mode == INFO_MODE_LEVELSET)
+ DrawInfoScreen_LevelSet();
+ else
+ DrawInfoScreen_Main();
+
+ if (info_mode != INFO_MODE_MAIN &&
+ info_mode != INFO_MODE_TITLE &&
+ info_mode != INFO_MODE_MUSIC)
+ {
+ PlayMenuSound();
+ PlayMenuMusic();
+ }
+}
+
+void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
+{
+ if (info_mode == INFO_MODE_TITLE)
+ HandleInfoScreen_TitleScreen(button);
+ else if (info_mode == INFO_MODE_ELEMENTS)
+ HandleInfoScreen_Elements(button);
+ else if (info_mode == INFO_MODE_MUSIC)
+ HandleInfoScreen_Music(button);
+ else if (info_mode == INFO_MODE_CREDITS)
+ HandleInfoScreen_Credits(button);
+ else if (info_mode == INFO_MODE_PROGRAM)
+ HandleInfoScreen_Program(button);
+ else if (info_mode == INFO_MODE_VERSION)
+ HandleInfoScreen_Version(button);
+ else if (info_mode == INFO_MODE_LEVELSET)
+ HandleInfoScreen_LevelSet(button);
+ else
+ HandleInfoScreen_Main(mx, my, dx, dy, button);
+}
+
+
+/* ========================================================================= */
+/* type name functions */
+/* ========================================================================= */
+
+void HandleTypeName(int newxpos, Key key)
+{
+ static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
+ struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
+ struct TextPosInfo *pos = mci->pos_input;
+ int startx = mSX + ALIGNED_TEXT_XPOS(pos);
+ int starty = mSY + ALIGNED_TEXT_YPOS(pos);
+ static int xpos = 0;
+ int font_nr = pos->font;
+ int font_active_nr = FONT_ACTIVE(font_nr);
+ int font_width = getFontWidth(font_active_nr);
+ char key_char = getValidConfigValueChar(getCharFromKey(key));
+ boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
+ boolean is_active = TRUE;
+
+ DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
+
+ if (newxpos)
+ {
+ strcpy(last_player_name, setup.player_name);
+
+ xpos = newxpos;
+
+#if defined(TARGET_SDL2)
+ SDL_StartTextInput();
+#endif
+ }
+ else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
+ {
+ setup.player_name[xpos] = key_char;
+ setup.player_name[xpos + 1] = 0;
+
+ xpos++;
+ }
+ else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
+ {
+ xpos--;
+
+ setup.player_name[xpos] = 0;
+ }
+ else if (key == KSYM_Return && xpos > 0)
+ {
+ SaveSetup();
+
+ is_active = FALSE;
+
+ SetGameStatus(GAME_MODE_MAIN);
+ }
+ else if (key == KSYM_Escape)
+ {
+ strcpy(setup.player_name, last_player_name);
+
+ is_active = FALSE;
+
+ SetGameStatus(GAME_MODE_MAIN);
+ }
+
+ if (is_active)
+ {
+ pos->width = (strlen(setup.player_name) + 1) * font_width;
+ startx = mSX + ALIGNED_TEXT_XPOS(pos);
+
+ DrawText(startx, starty, setup.player_name, font_active_nr);
+ DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
+ }
+ else
+ {
+ pos->width = strlen(setup.player_name) * font_width;
+ startx = mSX + ALIGNED_TEXT_XPOS(pos);
+
+ DrawText(startx, starty, setup.player_name, font_nr);
+
+#if defined(TARGET_SDL2)
+ SDL_StopTextInput();
+#endif
+ }
+}
+
+
+/* ========================================================================= */
+/* tree menu functions */
+/* ========================================================================= */
+
+static void DrawChooseTree(TreeInfo **ti_ptr)
+{
+ int fade_mask = REDRAW_FIELD;
+
+ if (CheckIfGlobalBorderHasChanged())
+ fade_mask = REDRAW_ALL;
+
+ if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
+ {
+ SetGameStatus(GAME_MODE_MAIN);
+
+ DrawMainMenu();
+
+ return;
+ }
+
+ UnmapAllGadgets();
+
+ FreeScreenGadgets();
+ CreateScreenGadgets();
+
+ FadeOut(fade_mask);
+
+ ClearField();
+
+ OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
+ HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
+ MapScreenTreeGadgets(*ti_ptr);
+
+ DrawMaskedBorder(fade_mask);
+
+ FadeIn(fade_mask);
+
+ InitAnimation();
+}
+
+static void drawChooseTreeList(int first_entry, int num_page_entries,
+ TreeInfo *ti)
+{
+ int i;
+ char *title_string = NULL;
+ int yoffset_sets = MENU_TITLE1_YPOS;
+ int yoffset_setup = 16;
+ int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
+ ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
+ int last_game_status = game_status; /* save current game status */
+
+ title_string = ti->infotext;
+
+ DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
+
+ clearMenuListArea();
+
+ for (i = 0; i < num_page_entries; i++)
+ {
+ TreeInfo *node, *node_first;
+ int entry_pos = first_entry + i;
+ int xpos = MENU_SCREEN_START_XPOS;
+ int ypos = MENU_SCREEN_START_YPOS + i;
+ int startx = mSX + xpos * 32;
+ int starty = mSY + ypos * 32;
+ int font_nr = FONT_TEXT_1;
+ int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
+ int startx_text = startx + font_xoffset;
+ int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
+ int text_size = startx_scrollbar - startx_text;
+ int max_buffer_len = text_size / getFontWidth(font_nr);
+ char buffer[max_buffer_len + 1];
+
+ node_first = getTreeInfoFirstGroupEntry(ti);
+ node = getTreeInfoFromPos(node_first, entry_pos);
+
+ strncpy(buffer, node->name, max_buffer_len);
+ buffer[max_buffer_len] = '\0';
+
+ DrawText(startx, starty, buffer, font_nr + node->color);
+
+ if (node->parent_link)
+ initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
+ else if (node->level_group)
+ initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
+ else
+ initCursor(i, IMG_MENU_BUTTON);
+ }
+
+ SetGameStatus(last_game_status); /* restore current game status */
+
+ redraw_mask |= REDRAW_FIELD;
+}
+
+static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
+{
+ TreeInfo *node, *node_first;
+ int x, last_redraw_mask = redraw_mask;
+ int ypos = MENU_TITLE2_YPOS;
+ int font_nr = FONT_TITLE_2;
+
+ if (ti->type == TREE_TYPE_LEVEL_NR)
+ DrawTextFCentered(ypos, font_nr, leveldir_current->name);
+
+ if (ti->type != TREE_TYPE_LEVEL_DIR)
+ return;
+
+ node_first = getTreeInfoFirstGroupEntry(ti);
+ node = getTreeInfoFromPos(node_first, entry_pos);
+
+ DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
+
+ if (node->parent_link)
+ DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
+ node->node_parent->name);
+ else if (node->level_group)
+ DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
+ node->name);
+ else if (ti->type == TREE_TYPE_LEVEL_DIR)
+ DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
+ node->levels, (node->levels > 1 ? "levels" : "level"),
+ node->class_desc);
+
+ /* let BackToFront() redraw only what is needed */
+ redraw_mask = last_redraw_mask;
+ for (x = 0; x < SCR_FIELDX; x++)
+ MarkTileDirty(x, 1);
+}
+
+static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
+ TreeInfo **ti_ptr)
+{
+ TreeInfo *ti = *ti_ptr;
+ int x = 0;
+ int y = ti->cl_cursor;
+ int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
+ int num_entries = numTreeInfoInGroup(ti);
+ int num_page_entries;
+ int last_game_status = game_status; /* save current game status */
+ boolean position_set_by_scrollbar = (dx == 999);
+
+ if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
+ num_page_entries = num_entries;
+ else
+ num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
+
+ SetGameStatus(last_game_status); /* restore current game status */
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ int num_entries = numTreeInfoInGroup(ti);
+ int entry_pos = posTreeInfo(ti);
+
+ if (ti->cl_first == -1)
+ {
+ /* only on initialization */
+ ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
+ ti->cl_cursor = entry_pos - ti->cl_first;
+ }
+ else if (ti->cl_cursor >= num_page_entries ||
+ (num_entries > num_page_entries &&
+ num_entries - ti->cl_first < num_page_entries))
+ {
+ /* only after change of list size (by custom graphic configuration) */
+ ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
+ ti->cl_cursor = entry_pos - ti->cl_first;
+ }
+
+ if (position_set_by_scrollbar)
+ ti->cl_first = dy;
+ else
+ AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
+ ti->cl_first, ti);
+
+ drawChooseTreeList(ti->cl_first, num_page_entries, ti);
+ drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
+ drawChooseTreeCursor(ti->cl_cursor, TRUE);
+
+ return;
+ }
+ else if (button == MB_MENU_LEAVE)
+ {
+ FadeSetLeaveMenu();
+
+ PlaySound(SND_MENU_ITEM_SELECTING);
+
+ if (ti->node_parent)
+ {
+ *ti_ptr = ti->node_parent;
+ DrawChooseTree(ti_ptr);
+ }
+ else if (game_status == GAME_MODE_SETUP)
+ {
+ if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
+ setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
+ setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
+ execSetupGame();
+ else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
+ setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
+ setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
+ execSetupGraphics();
+ else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
+ setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
+ setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
+ execSetupSound();
+ else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
+ setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
+ setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+ execSetupTouch();
+ else
+ execSetupArtwork();
+ }
+ else
+ {
+ if (game_status == GAME_MODE_LEVELNR)
+ {
+ int new_level_nr = atoi(level_number_current->identifier);
+
+ HandleMainMenu_SelectLevel(0, 0, new_level_nr);
+ }
+
+ SetGameStatus(GAME_MODE_MAIN);
+
+ DrawMainMenu();
+ }
+
+ return;
+ }
+
+ if (mx || my) /* mouse input */
+ {
+ int last_game_status = game_status; /* save current game status */