rnd-20031121-1-src
authorHolger Schemel <info@artsoft.org>
Fri, 21 Nov 2003 02:02:53 +0000 (03:02 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:44:38 +0000 (10:44 +0200)
src/conftime.h
src/files.c
src/files.h
src/libgame/setup.h
src/libgame/sound.c
src/main.c
src/main.h
src/screens.c

index fb7ddff0a510af1a512ca29704e0c1d06cce4770..b4b0a87d72a1a189025af3b2c899e369af4fc442 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2003-11-18 22:35]"
+#define COMPILE_DATE_STRING "[2003-11-21 02:35]"
index f8b4983994e6549448e8ad9a577da8dddb5170ca..779a6751d92524be848de4f240098914ca2394e6 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <ctype.h>
 #include <sys/stat.h>
+#include <dirent.h>
 #include <math.h>
 
 #include "libgame/libgame.h"
@@ -2844,3 +2845,176 @@ void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
           element_info[(*elements)[i]].token_name, (*elements)[i]);
 #endif
 }
+
+static struct MusicFileInfo *get_music_file_info(char *basename)
+{
+  SetupFileHash *setup_file_hash = NULL;
+  struct MusicFileInfo tmp_music_file_info, *new_music_file_info;
+  char *filename_music = getCustomMusicFilename(basename);
+  char *filename_prefix, *filename_info;
+  struct
+  {
+    char *token;
+    char **value_ptr;
+  }
+  token_to_value_ptr[] =
+  {
+    { "title", &tmp_music_file_info.title      },
+    { "artist",        &tmp_music_file_info.artist     },
+    { "album", &tmp_music_file_info.album      },
+    { "year",  &tmp_music_file_info.year       },
+    { NULL,    NULL                            },
+  };
+  int i;
+
+  if (filename_music == NULL)
+    return NULL;
+
+  /* ---------- try to replace file extension ---------- */
+
+  filename_prefix = getStringCopy(filename_music);
+  if (strrchr(filename_prefix, '.') != NULL)
+    *strrchr(filename_prefix, '.') = '\0';
+  filename_info = getStringCat2(filename_prefix, ".txt");
+
+#if 0
+  printf("trying to load file '%s'...\n", filename_info);
+#endif
+
+  if (fileExists(filename_info))
+    setup_file_hash = loadSetupFileHash(filename_info);
+
+  free(filename_prefix);
+  free(filename_info);
+
+  if (setup_file_hash == NULL)
+  {
+    /* ---------- try to add file extension ---------- */
+
+    filename_prefix = getStringCopy(filename_music);
+    filename_info = getStringCat2(filename_prefix, ".txt");
+
+#if 0
+    printf("trying to load file '%s'...\n", filename_info);
+#endif
+
+    if (fileExists(filename_info))
+      setup_file_hash = loadSetupFileHash(filename_info);
+
+    free(filename_prefix);
+    free(filename_info);
+  }
+
+  if (setup_file_hash == NULL)
+    return NULL;
+
+  /* ---------- music file info found ---------- */
+
+  for (i = 0; token_to_value_ptr[i].token != NULL; i++)
+  {
+    char *value = getHashEntry(setup_file_hash, token_to_value_ptr[i].token);
+
+    if (value != NULL)
+      *token_to_value_ptr[i].value_ptr = getStringCopy(value);
+  }
+
+  new_music_file_info = checked_calloc(sizeof(struct MusicFileInfo));
+  *new_music_file_info = tmp_music_file_info;
+
+  return new_music_file_info;
+}
+
+void LoadMusicInfo()
+{
+  char *music_directory = getCustomMusicDirectory();
+  int num_music = getMusicListSize();
+  DIR *dir;
+  struct dirent *dir_entry;
+  struct FileInfo *music;
+  struct MusicFileInfo *next, **new;
+  int i;
+
+  while (music_file_info != NULL)
+  {
+    next = music_file_info->next;
+
+    if (music_file_info->context)
+      free(music_file_info->context);
+    if (music_file_info->title)
+      free(music_file_info->title);
+    if (music_file_info->artist)
+      free(music_file_info->artist);
+    if (music_file_info->album)
+      free(music_file_info->album);
+    if (music_file_info->year)
+      free(music_file_info->year);
+
+    free(music_file_info);
+
+    music_file_info = next;
+  }
+
+  new = &music_file_info;
+
+  for (i=0; i < num_music; i++)
+  {
+    music = getMusicListEntry(i);
+
+    if (strcmp(music->filename, UNDEFINED_FILENAME) == 0)
+      continue;
+
+#if 0
+    printf("::: -> '%s'\n", music->filename);
+#endif
+
+    *new = get_music_file_info(music->filename);
+    if (*new != NULL)
+      new = &(*new)->next;
+  }
+
+  if ((dir = opendir(music_directory)) == NULL)
+  {
+    Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+    return;
+  }
+
+  while ((dir_entry = readdir(dir)) != NULL)   /* loop until last dir entry */
+  {
+    char *basename = dir_entry->d_name;
+    boolean music_already_used = FALSE;
+    int i;
+
+    for (i=0; i < num_music; i++)
+    {
+      music = getMusicListEntry(i);
+
+      if (strcmp(basename, music->filename) == 0)
+      {
+       music_already_used = TRUE;
+       break;
+      }
+    }
+
+    if (music_already_used)
+      continue;
+
+    if (!FileIsSound(basename) && !FileIsMusic(basename))
+      continue;
+
+#if 0
+    printf("::: -> '%s'\n", basename);
+#endif
+
+    *new = get_music_file_info(basename);
+    if (*new != NULL)
+      new = &(*new)->next;
+  }
+
+  closedir(dir);
+
+#if 0
+  /* TEST-ONLY */
+  for (next = music_file_info; next != NULL; next = next->next)
+    printf("::: title == '%s'\n", next->title);
+#endif
+}
index 6ad50a6ce9ce24b73bfbc05bc1cc72c0f7785d6f..0da4cc2da6a76a3e0459469e4f920836d31886db 100644 (file)
@@ -41,5 +41,6 @@ void SaveSetup();
 void LoadCustomElementDescriptions();
 void LoadSpecialMenuDesignSettings();
 void LoadUserDefinedEditorElementList(int **, int *);
+void LoadMusicInfo();
 
 #endif /* FILES_H */
index 9bc5fd907bf90f325866b6af37a64cba95a7a947..9939437ab1c0cc962e2c108571027850a552c00d 100644 (file)
@@ -200,6 +200,7 @@ char *getEditorSetupFilename(void);
 char *getImageFilename(char *);
 char *getCustomImageFilename(char *);
 char *getCustomSoundFilename(char *);
+char *getCustomMusicFilename(char *);
 char *getCustomArtworkFilename(char *, int);
 char *getCustomArtworkConfigFilename(int);
 char *getCustomArtworkLevelConfigFilename(int);
index 0e38c41961ad1fb4831d02eda3c3b1c8a45256f4..261428116aa7166ec5bea8e6d9af4b88c07b6e59 100644 (file)
@@ -1924,10 +1924,6 @@ void LoadCustomMusic_NoConf(void)
     {
       struct FileInfo *music = getMusicListEntry(i);
 
-#if 0
-      printf("::: -> '%s'\n", music->filename);
-#endif
-
       if (strcmp(basename, music->filename) == 0)
       {
        music_already_used = TRUE;
@@ -1938,10 +1934,9 @@ void LoadCustomMusic_NoConf(void)
     if (music_already_used)
       continue;
 
-#if 0
+#if 1
     if (FileIsSound(basename) || FileIsMusic(basename))
-      printf("DEBUG: loading music '%s' ... [%d]\n",
-            basename, music_already_used);
+      printf("DEBUG: loading music '%s' ...\n", basename);
 #endif
 
     if (draw_init_text)
index 83a9f6c60b3444692e1b4b1177e2a620d24afc60..d9319c5c35757089f610a256b4550f0d8e99bcf3 100644 (file)
@@ -104,6 +104,7 @@ struct DoorInfo             door_1, door_2;
 struct GraphicInfo     *graphic_info = NULL;
 struct SoundInfo       *sound_info = NULL;
 struct MusicInfo       *music_info = NULL;
+struct MusicFileInfo   *music_file_info = NULL;
 
 
 /* ------------------------------------------------------------------------- */
index b3a28ffa772454a7ed0e0add2e10873d2a4b1260..3bbb26522d686210c7f47d135fd364e3e35a7e82 100644 (file)
@@ -1483,6 +1483,18 @@ struct MusicPrefixInfo
   boolean is_loop_music;
 };
 
+struct MusicFileInfo
+{
+  char *context;
+
+  char *title;
+  char *artist;
+  char *album;
+  char *year;
+
+  struct MusicFileInfo *next;
+};
+
 struct ElementActionInfo
 {
   char *suffix;
@@ -1595,6 +1607,7 @@ extern struct MusicPrefixInfo     music_prefix_info[];
 extern struct GraphicInfo      *graphic_info;
 extern struct SoundInfo               *sound_info;
 extern struct MusicInfo               *music_info;
+extern struct MusicFileInfo    *music_file_info;
 extern struct ConfigInfo       image_config[];
 extern struct ConfigInfo       sound_config[];
 extern struct ConfigInfo       music_config[];
index 92e3838cba5226ffe8946fb0cc30122ca51d0471..a6b259d9eb7a065b4a04917fdaaef5143a98d09c 100644 (file)
@@ -981,8 +981,13 @@ void DrawHelpScreenElText(int start)
 
 void DrawHelpScreenMusicText(int num)
 {
+  struct MusicFileInfo *list = music_file_info;
   int ystart = 150, ystep = 30;
   int ybottom = SYSIZE - 20;
+  int i;
+
+  for (i=0; i < num && list; i++)
+    list = list->next;
 
   FadeSoundsAndMusic();
   ClearWindow();
@@ -990,6 +995,14 @@ void DrawHelpScreenMusicText(int num)
 
   DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
 
+#if 1
+  DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
+  DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "\"%s\"", list->title);
+  DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
+  DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "%s", list->artist);
+  DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
+  DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3, "\"%s\"", list->album);
+#else
   DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
   DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
                    "\"%s\"", helpscreen_music[num][0]);
@@ -999,6 +1012,7 @@ void DrawHelpScreenMusicText(int num)
   DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
   DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
                    "\"%s\"", helpscreen_music[num][2]);
+#endif
 
   DrawTextFCentered(ybottom, FONT_TEXT_4,
                    "Press any key or button for next page");
@@ -1070,6 +1084,7 @@ void DrawHelpScreenContactText()
 
 void DrawHelpScreen()
 {
+  struct MusicFileInfo *list;
   int i;
 
   UnmapAllGadgets();
@@ -1080,6 +1095,12 @@ void DrawHelpScreen()
   helpscreen_musicpos = 0;
   helpscreen_state = 0;
 
+  LoadMusicInfo();
+
+  num_helpscreen_music = 0;
+  for (list = music_file_info; list != NULL; list = list->next)
+    num_helpscreen_music++;
+
   DrawHelpScreenElText(0);
   DrawHelpScreenElAction(0);