added support for multiple pages (files) for level set info
authorHolger Schemel <info@artsoft.org>
Thu, 17 Nov 2022 18:51:07 +0000 (19:51 +0100)
committerHolger Schemel <info@artsoft.org>
Thu, 17 Nov 2022 18:51:07 +0000 (19:51 +0100)
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.h
src/screens.c

index 6b10a51ec9d4d7248eb6ad54eee66a65433c9c6f..0cad9d8c4c0b087da76e21502c5c641c511158c1 100644 (file)
@@ -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",
index b06d5f87be8ead8cf7017fdf891a0e4c1a75edea..a2107cd4ebed82076c2409c7f009d63570b4cb34 100644 (file)
@@ -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);
index 34655d654e8e106ae0477e8e38f2c2905338472f..79eeb0b4b26ffe581e5528d628b28bf0c07bb5db 100644 (file)
 #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"
index 5a559b1444fd36189d967bd88554a9d0ae7859af..379a9eaaafc01022961a50eb94f13432f2616f08 100644 (file)
@@ -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);
 }