From 28a1bafc7ff5a1e3dfd9d3f403b0569cbae5a818 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 3 Jul 2010 18:29:40 +0200 Subject: [PATCH] Show music credits during start of a level and when showing the map. The title, album and artist are shown briefly in the lower right corner of the screen 5 seconds after a level has been started, along with an icon representing the license under which the level music is available. The same information is also shown when the level map is viewed. --- src/CAudio.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- src/CAudio.h | 4 ++++ src/CGraphics.cpp | 7 +++++-- src/CGraphics.h | 3 ++- src/game.cpp | 5 ++++- src/game.h | 1 + src/info.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/init.cpp | 3 +++ src/main.cpp | 2 +- src/map.cpp | 2 ++ src/map.h | 1 + 11 files changed, 109 insertions(+), 6 deletions(-) diff --git a/src/CAudio.cpp b/src/CAudio.cpp index bac32ef..e4ee150 100644 --- a/src/CAudio.cpp +++ b/src/CAudio.cpp @@ -35,6 +35,10 @@ Audio::Audio() quickSound = NULL; levelMusicName[0] = 0; + songtitle[0] = 0; + songalbum[0] = 0; + songartist[0] = 0; + songlicense = -1; } void Audio::setSoundVolume(int soundVolume) @@ -123,12 +127,47 @@ bool Audio::loadMusic(const char *filename) music = Mix_LoadMUS(filename); #endif + songtitle[0] = 0; + songalbum[0] = 0; + songartist[0] = 0; + songlicense = -1; + if (!music) { debug(("WARNING - Failed to load %s\n", filename)); return false; } - + + snprintf(tempPath, sizeof tempPath, "%s.tags", filename); + FILE *fp = fopen(tempPath, "r"); + char line[1024]; + + while(fp && fgets(line, sizeof line, fp)) + { + int l = strlen(line); + if(line[l - 1] == '\n') + line[l - 1] = 0; + + if(!strncasecmp(line, "title=", 6)) + strncpy(songtitle, line + 6, sizeof songtitle); + else if(!strncasecmp(line, "album=", 6)) + strncpy(songalbum, line + 6, sizeof songalbum); + else if(!strncasecmp(line, "artist=", 7)) + strncpy(songartist, line + 7, sizeof songartist); + else if(!strncasecmp(line, "license=", 8)) + { + if(!strncasecmp(line + 8, "CC-BY ", 6)) + songlicense = 0; + else if(!strncasecmp(line + 8, "CC-BY-SA ", 9)) + songlicense = 1; + } + } + + fprintf(stderr, "%s\n%s\n\"%s\"\n%d\n", songartist, songalbum, songtitle, songlicense); + + if(fp) + fclose(fp); + strncpy(levelMusicName, filename, sizeof levelMusicName); return true; diff --git a/src/CAudio.h b/src/CAudio.h index 6fe391f..85f62e5 100755 --- a/src/CAudio.h +++ b/src/CAudio.h @@ -35,6 +35,10 @@ class Audio { Mix_Music *music; public: + char songtitle[128]; + char songalbum[128]; + char songartist[128]; + int songlicense; int output; bool useSound, useMusic; diff --git a/src/CGraphics.cpp b/src/CGraphics.cpp index 8393e69..f69dcc4 100644 --- a/src/CGraphics.cpp +++ b/src/CGraphics.cpp @@ -343,7 +343,7 @@ void Graphics::HSVtoRGB(float *r, float *g, float *b, float h, float s, float v) } } -SDL_Surface *Graphics::loadImage(const char *filename) +SDL_Surface *Graphics::loadImage(const char *filename, bool srcalpha) { SDL_Surface *image, *newImage; @@ -370,7 +370,10 @@ SDL_Surface *Graphics::loadImage(const char *filename) newImage = image; } - setTransparent(newImage); + if(srcalpha) + SDL_SetAlpha(newImage, SDL_SRCALPHA, 255); + else + setTransparent(newImage); return newImage; } diff --git a/src/CGraphics.h b/src/CGraphics.h index 5b1a5b5..be8a21a 100755 --- a/src/CGraphics.h +++ b/src/CGraphics.h @@ -56,6 +56,7 @@ class Graphics { SDL_Surface *tile[MAX_TILES]; SDL_Surface *medal[4]; + SDL_Surface *license[2]; SDL_Surface *infoBar; @@ -73,7 +74,7 @@ class Graphics { void delay(int time); void RGBtoHSV(float r, float g, float b, float *h, float *s, float *v); void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v); - SDL_Surface *loadImage(const char *filename); + SDL_Surface *loadImage(const char *filename, bool srcalpha = false); SDL_Surface *loadImage(const char *filename, int hue, int sat, int value); SDL_Surface *quickSprite(const char *name, SDL_Surface *image); void fade(int amount); diff --git a/src/game.cpp b/src/game.cpp index b0fb01e..c6e4e43 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -570,6 +570,7 @@ int doGame() graphics.delay(1000); Uint32 then, frames, frameLimit, millis, frameCounter; + Uint32 start, cur; #if DEBUG Uint32 now; @@ -617,7 +618,7 @@ int doGame() frameLimit = SDL_GetTicks() + 16; frames = millis = 0; - then = SDL_GetTicks(); + start = then = SDL_GetTicks(); frameCounter = SDL_GetTicks(); if ((strcmp(map.name, "Space Station") == 0) && (!game.continueFromCheckPoint)) @@ -642,6 +643,7 @@ int doGame() { ++frames; ++millis; + cur = SDL_GetTicks(); if (game.missionOverReason != MIS_PLAYEROUT) { @@ -683,6 +685,7 @@ int doGame() drawMapTopLayer(); doStatusBar(); + doMusicInfo(cur - start); if ((engine.keyState[SDLK_ESCAPE]) && (game.missionOver == 0)) { diff --git a/src/game.h b/src/game.h index 787e23b..6b9f6db 100755 --- a/src/game.h +++ b/src/game.h @@ -28,6 +28,7 @@ extern void doWind(); extern void doTimeRemaining(); extern void doStatusBar(); +extern void doMusicInfo(unsigned int); extern void doPauseInfo(); extern void doItems(); diff --git a/src/info.cpp b/src/info.cpp index 0ccb061..73be58d 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -320,3 +320,49 @@ void doPauseInfo() snprintf(string, sizeof string, "%s - %.2d:%.2d:%.2d", _("Mission Time"), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds); graphics.drawString(string, 320, 430, TXT_CENTERED, graphics.screen); } + +void doMusicInfo(unsigned int ticks) +{ + if(!audio.songtitle[0]) + return; + + if(ticks != (unsigned int)-1) { + if(ticks > 12000 || ticks < 5000) + return; + + unsigned int r = rand() & 0x3ff; + + if(ticks - 5000 < r || 12000 - ticks < r) + return; + } + + graphics.setFontSize(0); + graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00); + + const int x = 620; + int y = 420; + + graphics.drawString(audio.songtitle, x, y, TXT_RIGHT, graphics.screen); + y -= 16; + + if(audio.songalbum[0]) + { + graphics.setFontColor(0x80, 0xc0, 0xff, 0x00, 0x00, 0x00); + graphics.drawString(audio.songalbum, x, y, TXT_RIGHT, graphics.screen); + y -= 16; + } + + if(audio.songartist[0]) + { + graphics.setFontColor(0xff, 0xc0, 0x80, 0x00, 0x00, 0x00); + graphics.drawString(audio.songartist, x, y, TXT_RIGHT, graphics.screen); + y -= 16; + } + + if(audio.songlicense >= 0) + { + SDL_Surface *icon = graphics.license[audio.songlicense]; + graphics.blit(icon, x - icon->w, y - icon->h, graphics.screen, false); + } +} + diff --git a/src/init.cpp b/src/init.cpp index f0a140c..7fe79c0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -368,6 +368,9 @@ void initSystem() graphics.medal[2] = graphics.loadImage("gfx/main/shield.png"); graphics.medal[3] = graphics.loadImage("gfx/main/ruby.png"); + graphics.license[0] = graphics.loadImage("gfx/main/cc-by.png", true); + graphics.license[1] = graphics.loadImage("gfx/main/cc-by-sa.png", true); + SDL_Surface *device = graphics.loadImage("gfx/main/alienDevice.png"); #ifndef SDL_FRAMEWORK diff --git a/src/main.cpp b/src/main.cpp index 231f643..6d4e99f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,13 +130,13 @@ int main(int argc, char *argv[]) else if (strcmp(argv[i], "-playback") == 0) {recordMode = REPLAY_MODE::PLAYBACK; strncpy(replayData.filename, argv[++i], sizeof replayData.filename);} else if (strcmp(argv[i], "-map") == 0) {game.setMapName(argv[++i]); requiredSection = SECTION_GAME;} else if (strcmp(argv[i], "-listmaps") == 0) listMaps(); + else if (strcmp(argv[i], "-credits") == 0) requiredSection = SECTION_CREDITS; #if DEBUG else if (strcmp(argv[i], "-showsprites") == 0) showSprites = true; else if (strcmp(argv[i], "-hub") == 0) hub = true; else if (strcmp(argv[i], "-randomscreens") == 0) graphics.takeRandomScreenShots = true; else if (strcmp(argv[i], "-nomonsters") == 0) engine.devNoMonsters = true; - else if (strcmp(argv[i], "-credits") == 0) requiredSection = SECTION_CREDITS; #endif } diff --git a/src/map.cpp b/src/map.cpp index 0360b61..8e1e7be 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -400,6 +400,8 @@ void showMap(int centerX, int centerY) engine.flushInput(); engine.clearInput(); + doMusicInfo(-1); + while (true) { engine.getInput(); diff --git a/src/map.h b/src/map.h index caf1459..2a93ce0 100755 --- a/src/map.h +++ b/src/map.h @@ -26,6 +26,7 @@ extern void adjustObjectives(); extern void initMIAPhrases(); extern void addWindParticles(); extern void getMapTokens(); +extern void doMusicInfo(unsigned int); extern Audio audio; extern Config config; -- 2.39.5