]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Show music credits during start of a level and when showing the map.
authorGuus Sliepen <guus@sliepen.eu.org>
Sat, 3 Jul 2010 16:29:40 +0000 (18:29 +0200)
committerGuus Sliepen <guus@sliepen.eu.org>
Sat, 3 Jul 2010 16:29:40 +0000 (18:29 +0200)
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
src/CAudio.h
src/CGraphics.cpp
src/CGraphics.h
src/game.cpp
src/game.h
src/info.cpp
src/init.cpp
src/main.cpp
src/map.cpp
src/map.h

index bac32efe78f571410c6cfc8c650ce4a02f1d43d3..e4ee1501818e1efed162c6ce99eac3a3ddb146f2 100644 (file)
@@ -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;
index 6fe391fca961789df47627639195ad8ba48a9eee..85f62e5540103f33a6a31a22328b9daf065be7d4 100755 (executable)
@@ -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;
index 8393e6921b40de23b1415df7f1bc58f64357a8a9..f69dcc4108c58a1c2867a1e26a1413abad2ddd86 100644 (file)
@@ -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;
 }
index 5b1a5b5ac088d1e6e4452dae67b1486878a329ee..be8a21a815c397e0cf4bc30cdfd30edf0247e393 100755 (executable)
@@ -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);
index b0fb01e374d656f4cf3b39a955cff94b047c6165..c6e4e430ccd0a62714267a8ce985f87a95a65790 100644 (file)
@@ -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))
                {
index 787e23b830ed2ab08ece9775af3d65a360f30bb8..6b9f6db959ba6d4c8c18380cc12bab631f21871c 100755 (executable)
@@ -28,6 +28,7 @@ extern void doWind();
 
 extern void doTimeRemaining();
 extern void doStatusBar();
+extern void doMusicInfo(unsigned int);
 extern void doPauseInfo();
 
 extern void doItems();
index 0ccb0615445a373dcdab029efc245a928a6acb41..73be58dfcf3af0dffe479bf2e880d83a62b18d7e 100644 (file)
@@ -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);
+       }
+}
+
index f0a140c0b771c04deb4515031b263ce9667f94f5..7fe79c0717e1e2e7388ea3b9898ab424601b0ce5 100644 (file)
@@ -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
index 231f643a6670558641c2d0f6defda9efa6f8af71..6d4e99f5c799b192e4de1aea73ad6f4f901148b9 100644 (file)
@@ -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
        }
        
index 0360b61f1d5606143f0ba7b35275af2fa033e477..8e1e7beec022104d7b0e4a6e906f24c9e6ef17fc 100644 (file)
@@ -400,6 +400,8 @@ void showMap(int centerX, int centerY)
        engine.flushInput();
        engine.clearInput();
 
+       doMusicInfo(-1);
+
        while (true)
        {
                engine.getInput();
index caf1459fcb577fa2535a4e2f128aee062a3580a7..2a93ce0706581cb72f8f424638359c6c6ea53701 100755 (executable)
--- 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;