Files
itgmania212121/stepmania/src/FadingBanner.cpp
T

231 lines
6.0 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
#include "FadingBanner.h"
2003-06-04 22:44:37 +00:00
#include "RageTextureManager.h"
#include "BannerCache.h"
#include "song.h"
#include "RageLog.h"
#include "Course.h"
2003-06-15 02:07:31 +00:00
#include "PrefsManager.h"
#include "ThemeManager.h"
2003-06-30 06:22:18 +00:00
#include "SongManager.h"
#include "ThemeMetric.h"
#include "ActorUtil.h"
2003-06-04 22:44:37 +00:00
2005-02-23 17:52:28 +00:00
// lua start
LUA_REGISTER_CLASS( FadingBanner )
// lua end
REGISTER_ACTOR_CLASS( FadingBanner );
static ThemeMetric<float> FADE_SECONDS ("FadingBanner","FadeSeconds");
2004-10-23 04:04:09 +00:00
/*
* Allow fading from one banner to another. We can handle two fades at once;
* this is used to fade from an old banner to a low-quality banner to a high-
* quality banner smoothly.
*
* m_iIndexLatest is the latest banner loaded, and the one that we'll end up
* displaying when the fades stop.
*/
FadingBanner::FadingBanner()
{
m_bMovingFast = false;
2004-09-06 05:25:37 +00:00
m_bSkipNextBannerUpdate = false;
2004-10-23 04:04:09 +00:00
m_iIndexLatest = 0;
for( int i=0; i<3; i++ )
this->AddChild( &m_Banner[i] );
Banner::CacheGlobalBanners();
}
void FadingBanner::ScaleToClipped( float fWidth, float fHeight )
{
2004-10-23 04:04:09 +00:00
for( int i=0; i<3; i++ )
m_Banner[i].ScaleToClipped( fWidth, fHeight );
}
2005-02-02 05:19:10 +00:00
float FadingBanner::GetFadeSeconds() const
{
return FADE_SECONDS;
}
void FadingBanner::Update( float fDeltaTime )
{
2004-09-06 05:25:37 +00:00
// update children manually
// ActorFrame::Update( fDeltaTime );
Actor::Update( fDeltaTime );
if( !m_bSkipNextBannerUpdate )
{
m_Banner[0].Update( fDeltaTime );
m_Banner[1].Update( fDeltaTime );
2004-10-23 04:04:09 +00:00
m_Banner[2].Update( fDeltaTime );
2004-09-06 05:25:37 +00:00
}
m_bSkipNextBannerUpdate = false;
}
2003-01-02 02:59:35 +00:00
void FadingBanner::DrawPrimitives()
{
// draw manually
// ActorFrame::DrawPrimitives();
2004-10-23 04:04:09 +00:00
/* Render the latest banner first. */
for( int i = 0; i < 3; ++i )
{
int index = m_iIndexLatest - i;
wrap( index, 3 );
m_Banner[index].Draw();
}
}
2003-01-02 02:59:35 +00:00
bool FadingBanner::Load( RageTextureID ID )
{
BeforeChange();
2004-10-23 04:04:09 +00:00
bool bRet = m_Banner[m_iIndexLatest].Load(ID);
return bRet;
}
2003-01-02 02:59:35 +00:00
void FadingBanner::BeforeChange()
{
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].SetDiffuse( RageColor(1,1,1,1) );
m_Banner[m_iIndexLatest].StopTweening();
m_Banner[m_iIndexLatest].BeginTweening( FADE_SECONDS ); // fade out
m_Banner[m_iIndexLatest].SetDiffuse( RageColor(1,1,1,0) );
2004-10-23 04:04:09 +00:00
++m_iIndexLatest;
wrap( m_iIndexLatest, 3 );
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].SetDiffuse( RageColor(1,1,1,1) );
2003-06-04 22:44:37 +00:00
2004-09-06 05:25:37 +00:00
/* We're about to load a banner. It'll probably cause a frame skip or
* two. Skip an update, so the fade-in doesn't skip. */
m_bSkipNextBannerUpdate = true;
}
/* If this returns true, a low-resolution banner was loaded, and the full-res
* banner should be loaded later. */
bool FadingBanner::LoadFromCachedBanner( const CString &path )
{
/* If we're already on the given banner, don't fade again. */
2004-10-23 04:04:09 +00:00
if( path != "" && m_Banner[m_iIndexLatest].GetTexturePath() == path )
return false;
2003-08-03 05:40:13 +00:00
if( path == "" )
{
LoadFallback();
return false;
2003-08-03 05:40:13 +00:00
}
/* If we're currently fading to the given banner, go through this again,
* which will cause the fade-in to be further delayed. */
2003-11-25 22:56:48 +00:00
RageTextureID ID;
2004-12-04 10:35:50 +00:00
bool bLowRes = (PREFSMAN->m_iBannerCache != PrefsManager::BNCACHE_FULL);
if( !bLowRes )
2004-12-04 10:35:50 +00:00
{
2004-03-26 07:56:18 +00:00
ID = Sprite::SongBannerTexture( path );
2004-12-04 10:35:50 +00:00
}
2003-11-25 22:56:48 +00:00
else
2004-12-04 10:35:50 +00:00
{
2003-11-25 22:56:48 +00:00
/* Try to load the low quality version. */
ID = BANNERCACHE->LoadCachedBanner( path );
2004-12-04 10:35:50 +00:00
}
2003-11-25 22:56:48 +00:00
2003-06-04 22:44:37 +00:00
if( !TEXTUREMAN->IsTextureRegistered(ID) )
2003-06-15 01:53:51 +00:00
{
/* Oops. We couldn't load a banner quickly. We can load the actual
* banner, but that's slow, so we don't want to do that when we're moving
* fast on the music wheel. In that case, we should just keep the banner
* that's there (or load a "moving fast" banner). Once we settle down,
* we'll get called again and load the real banner. */
if( m_bMovingFast )
return false;
2003-06-15 01:53:51 +00:00
2003-06-16 07:54:17 +00:00
if( IsAFile(path) )
Load( path );
2003-06-15 01:53:51 +00:00
else
LoadFallback();
2003-06-15 01:53:51 +00:00
return false;
2003-06-15 01:53:51 +00:00
}
2003-06-04 22:44:37 +00:00
BeforeChange();
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].Load( ID );
return bLowRes;
2003-06-11 00:32:13 +00:00
}
2004-09-06 05:27:18 +00:00
void FadingBanner::LoadFromSong( const Song* pSong )
2003-06-11 00:32:13 +00:00
{
2003-07-14 22:23:35 +00:00
/* Don't call HasBanner. That'll do disk access and cause the music wheel
* to skip. */
2003-06-15 01:53:51 +00:00
LoadFromCachedBanner( pSong->GetBannerPath() );
}
void FadingBanner::LoadAllMusic()
{
BeforeChange();
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].LoadAllMusic();
}
2003-06-30 06:22:18 +00:00
void FadingBanner::LoadMode()
{
BeforeChange();
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].LoadMode();
}
void FadingBanner::LoadFromGroup( CString sGroupName )
{
2003-06-15 01:53:51 +00:00
const CString sGroupBannerPath = SONGMAN->GetGroupBannerPath( sGroupName );
LoadFromCachedBanner( sGroupBannerPath );
}
2004-09-06 05:27:18 +00:00
void FadingBanner::LoadFromCourse( const Course* pCourse )
{
2003-06-15 02:07:31 +00:00
LoadFromCachedBanner( pCourse->m_sBannerPath );
}
void FadingBanner::LoadRoulette()
{
BeforeChange();
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].LoadRoulette();
}
void FadingBanner::LoadRandom()
{
BeforeChange();
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].LoadRandom();
2002-08-21 07:59:04 +00:00
}
void FadingBanner::LoadFallback()
{
BeforeChange();
2004-10-23 04:04:09 +00:00
m_Banner[m_iIndexLatest].LoadFallback();
}
2004-06-07 21:14:03 +00:00
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/