From 7226e5a962b19970d3135befdeefbb9cc5b817f8 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 25 May 2007 22:26:43 +0000 Subject: [PATCH] #BANNER tag for course files --- stepmania/src/Banner.cpp | 2 +- stepmania/src/Course.cpp | 13 +++++++++++-- stepmania/src/Course.h | 1 + stepmania/src/CourseLoaderCRS.cpp | 30 ++++++++++++++++++----------- stepmania/src/CourseWriterCRS.cpp | 3 +++ stepmania/src/FadingBanner.cpp | 2 +- stepmania/src/GameState.cpp | 4 ++-- stepmania/src/ScreenSelectMusic.cpp | 2 +- stepmania/src/SongManager.cpp | 2 +- stepmania/src/UnlockManager.cpp | 2 +- 10 files changed, 41 insertions(+), 20 deletions(-) diff --git a/stepmania/src/Banner.cpp b/stepmania/src/Banner.cpp index e1e374bcf1..db94e2cf22 100644 --- a/stepmania/src/Banner.cpp +++ b/stepmania/src/Banner.cpp @@ -136,7 +136,7 @@ void Banner::LoadFromSongGroup( RString sSongGroup ) void Banner::LoadFromCourse( const Course *pCourse ) // NULL means no course { if( pCourse == NULL ) LoadFallback(); - else if( pCourse->m_sBannerPath != "" ) Load( pCourse->m_sBannerPath ); + else if( pCourse->GetBannerPath() != "" ) Load( pCourse->GetBannerPath() ); else LoadCourseFallback(); m_bScrolling = false; diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 643f896044..006d03498f 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -834,9 +834,18 @@ bool Course::CourseHasBestOrWorst() const return false; } +RString Course::GetBannerPath() const +{ + if( m_sBannerPath.empty() ) + return RString(); + if( m_sBannerPath[0] == '/' ) + return m_sBannerPath; + return Dirname(m_sPath) + m_sBannerPath; +} + bool Course::HasBanner() const { - return m_sBannerPath != "" && IsAFile(m_sBannerPath); + return GetBannerPath() != "" && IsAFile(GetBannerPath()); } void Course::UpdateCourseStats( StepsType st ) @@ -978,7 +987,7 @@ public: LuaHelpers::CreateTableFromArray( v, L ); return 1; } - static int GetBannerPath( T* p, lua_State *L ) { if( p->m_sBannerPath.empty() ) return 0; lua_pushstring(L, p->m_sBannerPath ); return 1; } + static int GetBannerPath( T* p, lua_State *L ) { RString s = p->GetBannerPath(); if( s.empty() ) return 0; LuaHelpers::Push(L, s); return 1; } static int GetGroupName( T* p, lua_State *L ) { lua_pushstring(L, p->m_sGroupName ); return 1; } static int IsAutogen( T* p, lua_State *L ) { lua_pushboolean(L, p->m_bIsAutogen ); return 1; } static int GetEstimatedNumStages( T* p, lua_State *L ) { lua_pushnumber(L, p->GetEstimatedNumStages() ); return 1; } diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 13511f146a..ac71c49642 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -101,6 +101,7 @@ class Course public: Course(); + RString GetBannerPath() const; bool HasBanner() const; /* If PREFSMAN->m_bShowNative is off, these are the same as GetTranslit* below. diff --git a/stepmania/src/CourseLoaderCRS.cpp b/stepmania/src/CourseLoaderCRS.cpp index 4d1c2a782c..f19a8331b1 100644 --- a/stepmania/src/CourseLoaderCRS.cpp +++ b/stepmania/src/CourseLoaderCRS.cpp @@ -45,16 +45,6 @@ bool CourseLoaderCRS::LoadFromBuffer( const RString &sPath, const RString &sBuff bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Course &out, bool bFromCache ) { - const RString sFName = SetExtension( out.m_sPath, "" ); - - vector arrayPossibleBanners; - GetDirListing( sFName + "*.png", arrayPossibleBanners, false, true ); - GetDirListing( sFName + "*.jpg", arrayPossibleBanners, false, true ); - GetDirListing( sFName + "*.bmp", arrayPossibleBanners, false, true ); - GetDirListing( sFName + "*.gif", arrayPossibleBanners, false, true ); - if( !arrayPossibleBanners.empty() ) - out.m_sBannerPath = arrayPossibleBanners[0]; - AttackArray attacks; float fGainSeconds = 0; for( unsigned i=0; iUserLog( "Course file", sPath, "contains an unexpected value named \"%s\"", sValueName.c_str() ); } } + + if( out.m_sBannerPath.empty() ) + { + const RString sFName = SetExtension( out.m_sPath, "" ); + + vector arrayPossibleBanners; + GetDirListing( sFName + "*.png", arrayPossibleBanners, false, false ); + GetDirListing( sFName + "*.jpg", arrayPossibleBanners, false, false ); + GetDirListing( sFName + "*.bmp", arrayPossibleBanners, false, false ); + GetDirListing( sFName + "*.gif", arrayPossibleBanners, false, false ); + if( !arrayPossibleBanners.empty() ) + out.m_sBannerPath = arrayPossibleBanners[0]; + } + static TitleSubst tsub("Courses"); TitleFields title; @@ -308,7 +316,7 @@ bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Cou /* Cache and load the course banner. Only bother doing this if at least one * song was found in the course. */ if( out.m_sBannerPath != "" && !out.m_vEntries.empty() ) - BANNERCACHE->CacheBanner( out.m_sBannerPath ); + BANNERCACHE->CacheBanner( out.GetBannerPath() ); /* Cache each trail RadarValues that's slow to load, so we * don't have to do it at runtime. */ diff --git a/stepmania/src/CourseWriterCRS.cpp b/stepmania/src/CourseWriterCRS.cpp index 3ff1eb9705..34159d7190 100644 --- a/stepmania/src/CourseWriterCRS.cpp +++ b/stepmania/src/CourseWriterCRS.cpp @@ -44,6 +44,9 @@ bool CourseWriterCRS::Write( const Course &course, RageFileBasic &f, bool bSavin f.PutLine( "#REPEAT:YES;" ); if( course.m_iLives != -1 ) f.PutLine( ssprintf("#LIVES:%i;", course.m_iLives) ); + if( !course.m_sBannerPath.empty() ) + f.PutLine( ssprintf("#BANNER:%s;", course.m_sBannerPath.c_str()) ); + if( !course.m_setStyles.empty() ) { vector asStyles; diff --git a/stepmania/src/FadingBanner.cpp b/stepmania/src/FadingBanner.cpp index f5d2c6252a..0d9295bd32 100644 --- a/stepmania/src/FadingBanner.cpp +++ b/stepmania/src/FadingBanner.cpp @@ -195,7 +195,7 @@ void FadingBanner::LoadFromCourse( const Course* pCourse ) /* Don't call HasBanner. That'll do disk access and cause the music wheel * to skip. */ - RString sPath = pCourse->m_sBannerPath; + RString sPath = pCourse->GetBannerPath(); if( sPath.empty() ) LoadCourseFallback(); else diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 3d2ad6753d..45ae4d6578 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1547,7 +1547,7 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu feat.iScore = hs.GetScore(); feat.fPercentDP = hs.GetPercentDP(); if( pCourse->HasBanner() ) - feat.Banner = pCourse->m_sBannerPath; + feat.Banner = pCourse->GetBannerPath(); asFeatsOut.push_back( feat ); } } @@ -1571,7 +1571,7 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu feat.iScore = hs.GetScore(); feat.fPercentDP = hs.GetPercentDP(); if( pCourse->HasBanner() ) - feat.Banner = pCourse->m_sBannerPath; + feat.Banner = pCourse->GetBannerPath(); asFeatsOut.push_back( feat ); } } diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index c71575718c..cc11ca8615 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -1218,7 +1218,7 @@ void ScreenSelectMusic::AfterMusicChange() m_fSampleStartSeconds = 0; m_fSampleLengthSeconds = -1; - g_sBannerPath = pCourse->m_sBannerPath; + g_sBannerPath = pCourse->GetBannerPath(); if( g_sBannerPath.empty() ) m_Banner.LoadFallback(); diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index f3ce9a2d1a..bfaabdab4e 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -324,7 +324,7 @@ void SongManager::PreloadSongImages() if( !courses[i]->HasBanner() ) continue; - const RageTextureID ID = Sprite::SongBannerTexture( courses[i]->m_sBannerPath ); + const RageTextureID ID = Sprite::SongBannerTexture( courses[i]->GetBannerPath() ); preload.Load( ID ); } diff --git a/stepmania/src/UnlockManager.cpp b/stepmania/src/UnlockManager.cpp index 600146cf0c..20670128f7 100644 --- a/stepmania/src/UnlockManager.cpp +++ b/stepmania/src/UnlockManager.cpp @@ -367,7 +367,7 @@ RString UnlockEntry::GetBannerFile() const case UnlockRewardType_Steps: return m_pSong ? m_pSong->GetBannerPath() : ""; case UnlockRewardType_Course: - return m_pCourse ? m_pCourse->m_sBannerPath : ""; + return m_pCourse ? m_pCourse->GetBannerPath() : ""; case UnlockRewardType_Modifier: return ""; }