From: Holger Schemel Date: Fri, 21 Nov 2003 02:02:53 +0000 (+0100) Subject: rnd-20031121-1-src X-Git-Tag: 3.0.8^2~21 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=983c38dbae8637ef26d8be356e04c9b64bf9fc1f;p=rocksndiamonds.git rnd-20031121-1-src --- diff --git a/src/conftime.h b/src/conftime.h index fb7ddff0..b4b0a87d 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-11-18 22:35]" +#define COMPILE_DATE_STRING "[2003-11-21 02:35]" diff --git a/src/files.c b/src/files.c index f8b49839..779a6751 100644 --- a/src/files.c +++ b/src/files.c @@ -13,6 +13,7 @@ #include #include +#include #include #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 +} diff --git a/src/files.h b/src/files.h index 6ad50a6c..0da4cc2d 100644 --- a/src/files.h +++ b/src/files.h @@ -41,5 +41,6 @@ void SaveSetup(); void LoadCustomElementDescriptions(); void LoadSpecialMenuDesignSettings(); void LoadUserDefinedEditorElementList(int **, int *); +void LoadMusicInfo(); #endif /* FILES_H */ diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 9bc5fd90..9939437a 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 0e38c419..26142811 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -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) diff --git a/src/main.c b/src/main.c index 83a9f6c6..d9319c5c 100644 --- a/src/main.c +++ b/src/main.c @@ -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; /* ------------------------------------------------------------------------- */ diff --git a/src/main.h b/src/main.h index b3a28ffa..3bbb2652 100644 --- a/src/main.h +++ b/src/main.h @@ -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[]; diff --git a/src/screens.c b/src/screens.c index 92e3838c..a6b259d9 100644 --- a/src/screens.c +++ b/src/screens.c @@ -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);