From: Holger Schemel Date: Thu, 17 Nov 2022 18:51:07 +0000 (+0100) Subject: added support for multiple pages (files) for level set info X-Git-Tag: 4.3.3.0~14 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=df4dc8e0755fb2d7f651ce31aff28bc51cc8034a;p=rocksndiamonds.git added support for multiple pages (files) for level set info --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 6b10a51e..0cad9d8c 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -818,9 +818,34 @@ char *getHelpTextFilename(void) return filename; } -char *getLevelSetInfoFilename(void) +static char *getLevelSetInfoBasename(int nr) { + static char basename[32]; + + sprintf(basename, "levelset_%d.txt", nr + 1); + + return basename; +} + +char *getLevelSetInfoFilename(int nr) +{ + char *basename = getLevelSetInfoBasename(nr); + static char *info_subdir = NULL; static char *filename = NULL; + + if (info_subdir == NULL) + info_subdir = getPath2(DOCS_DIRECTORY, LEVELSET_INFO_DIRECTORY); + + checked_free(filename); + + // look for level set info file the current level set directory + filename = getPath3(getCurrentLevelDir(), info_subdir, basename); + if (fileExists(filename)) + return filename; + + if (nr > 0) + return NULL; + char *basenames[] = { "README", diff --git a/src/libgame/setup.h b/src/libgame/setup.h index b06d5f87..a2107cd4 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -279,7 +279,7 @@ char *getPlatformSetupFilename(void); char *getEditorSetupFilename(void); char *getHelpAnimFilename(void); char *getHelpTextFilename(void); -char *getLevelSetInfoFilename(void); +char *getLevelSetInfoFilename(int); char *getLevelSetTitleMessageFilename(int, boolean); char *getCreditsFilename(int, boolean); char *getProgramInfoFilename(int); diff --git a/src/libgame/system.h b/src/libgame/system.h index 34655d65..79eeb0b4 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -659,6 +659,7 @@ #define ELEMENTS_DIRECTORY "elements" #define CREDITS_DIRECTORY "credits" #define PROGRAM_INFO_DIRECTORY "program" +#define LEVELSET_INFO_DIRECTORY "levelset" #define CACHE_DIRECTORY "cache" #define CONF_DIRECTORY "conf" #define NETWORK_DIRECTORY "network" diff --git a/src/screens.c b/src/screens.c index 5a559b14..379a9eaa 100644 --- a/src/screens.c +++ b/src/screens.c @@ -288,6 +288,7 @@ static void HandleInfoScreen_Music(int, int, int); static void HandleInfoScreen_Credits(int, int, int); static void HandleInfoScreen_Program(int, int, int); static void HandleInfoScreen_Version(int); +static void HandleInfoScreen_LevelSet(int, int, int); static void ModifyGameSpeedIfNeeded(void); static void DisableVsyncIfNeeded(void); @@ -703,6 +704,11 @@ static boolean use_global_credits_screens = FALSE; static int num_program_info_screens = 0; +// level set info screens definitions + +static int num_levelset_info_screens = 0; + + // main menu display and control definitions #define MAIN_CONTROL_NAME 0 @@ -3869,30 +3875,19 @@ void HandleInfoScreen_Version(int button) } } -static void DrawInfoScreen_LevelSet(void) +static void DrawInfoScreen_LevelSetScreen(int screen_nr) { struct TitleMessageInfo *tmi = &readme; - char *filename = getLevelSetInfoFilename(); - char *title = "Level Set Information:"; - int font_foot = MENU_INFO_FONT_FOOT; + char *filename = getLevelSetInfoFilename(screen_nr); + int font_title = MENU_INFO_FONT_TITLE; + int font_foot = MENU_INFO_FONT_FOOT; int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1; int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM; - if (filename == NULL) - { - DrawInfoScreen_NotAvailable(title, "No information for this level set."); - - return; - } - - SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET); - - FadeOut(REDRAW_FIELD); - ClearField(); DrawHeadline(); - DrawTextSCentered(ystart, FONT_TEXT_1, title); + DrawTextSCentered(ystart, font_title, "Level Set Information:"); // if x position set to "-1", automatically determine by playfield width if (tmi->x == -1) @@ -3926,14 +3921,58 @@ static void DrawInfoScreen_LevelSet(void) filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1, tmi->autowrap, tmi->centered, tmi->parse_comments); - DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU); + boolean last_screen = (screen_nr == num_levelset_info_screens - 1); + char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE); + + DrawTextSCentered(ybottom, font_foot, text_foot); +} + +static void DrawInfoScreen_LevelSet(void) +{ + SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET); + + FadeMenuSoundsAndMusic(); + + FadeOut(REDRAW_FIELD); + + HandleInfoScreen_LevelSet(0, 0, MB_MENU_INITIALIZE); FadeIn(REDRAW_FIELD); } -static void HandleInfoScreen_LevelSet(int button) +void HandleInfoScreen_LevelSet(int dx, int dy, int button) { - if (button == MB_MENU_LEAVE) + static int screen_nr = 0; + + if (button == MB_MENU_INITIALIZE) + { + // determine number of levelset info screens + num_levelset_info_screens = 0; + + while (getLevelSetInfoFilename(num_levelset_info_screens) != NULL) + num_levelset_info_screens++; + + if (num_levelset_info_screens == 0) + { + int font_title = MENU_INFO_FONT_TITLE; + int font_foot = MENU_INFO_FONT_FOOT; + int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1; + int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM; + + ClearField(); + DrawHeadline(); + + DrawTextSCentered(ystart, font_title, "No level set info available."); + DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU); + + return; + } + + screen_nr = 0; + + DrawInfoScreen_LevelSetScreen(screen_nr); + } + else if (button == MB_MENU_LEAVE) { PlaySound(SND_MENU_ITEM_SELECTING); @@ -3942,14 +3981,29 @@ static void HandleInfoScreen_LevelSet(int button) return; } - else if (button == MB_MENU_CHOICE) + else if (button == MB_MENU_CHOICE || dx) { PlaySound(SND_MENU_ITEM_SELECTING); - FadeMenuSoundsAndMusic(); + screen_nr += (dx < 0 ? -1 : +1); - info_mode = INFO_MODE_MAIN; - DrawInfoScreen(); + if (screen_nr < 0 || screen_nr >= num_levelset_info_screens) + { + FadeMenuSoundsAndMusic(); + + info_mode = INFO_MODE_MAIN; + DrawInfoScreen(); + + return; + } + + FadeSetNextScreen(); + + FadeOut(REDRAW_FIELD); + + DrawInfoScreen_LevelSetScreen(screen_nr); + + FadeIn(REDRAW_FIELD); } else { @@ -3997,7 +4051,7 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button) else if (info_mode == INFO_MODE_VERSION) HandleInfoScreen_Version(button); else if (info_mode == INFO_MODE_LEVELSET) - HandleInfoScreen_LevelSet(button); + HandleInfoScreen_LevelSet(dx, dy, button); else HandleInfoScreen_Main(mx, my, dx, dy, button); }