Files
itgmania212121/stepmania/src/FadingBanner.cpp
T

313 lines
8.1 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
REGISTER_ACTOR_CLASS( FadingBanner )
2005-02-23 17:52:28 +00:00
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;
2005-04-23 10:19:47 +00:00
for( int i=0; i<NUM_BANNERS; i++ )
2005-04-23 06:52:07 +00:00
{
m_Banner[i].SetName( "Banner" );
ActorUtil::OnCommand( m_Banner[i], "FadingBanner" );
this->AddChild( &m_Banner[i] );
2005-04-23 06:52:07 +00:00
}
}
void FadingBanner::ScaleToClipped( float fWidth, float fHeight )
{
2005-04-23 10:19:47 +00:00
for( int i=0; i<NUM_BANNERS; i++ )
m_Banner[i].ScaleToClipped( fWidth, fHeight );
}
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 )
{
2005-04-23 10:19:47 +00:00
for( int i = 0; i < NUM_BANNERS; ++i )
m_Banner[i].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. */
2005-04-23 10:19:47 +00:00
for( int i = 0; i < NUM_BANNERS; ++i )
2004-10-23 04:04:09 +00:00
{
int index = m_iIndexLatest - i;
2005-04-23 10:19:47 +00:00
wrap( index, NUM_BANNERS );
2004-10-23 04:04:09 +00:00
m_Banner[index].Draw();
}
}
void FadingBanner::Load( RageTextureID ID, bool bLowResToHighRes )
{
2005-04-23 10:19:47 +00:00
BeforeChange( bLowResToHighRes );
m_Banner[m_iIndexLatest].Load(ID);
}
2005-04-24 01:36:50 +00:00
/* If bLowResToHighRes is true, we're fading from a low-res banner to the
* corresponding high-res banner. */
2005-04-23 10:19:47 +00:00
void FadingBanner::BeforeChange( bool bLowResToHighRes )
{
2006-01-22 01:00:06 +00:00
RString sCommand;
2005-04-23 10:19:47 +00:00
if( bLowResToHighRes )
sCommand = "FadeFromCached";
else
sCommand = "FadeOff";
m_Banner[m_iIndexLatest].PlayCommand( sCommand );
2004-10-23 04:04:09 +00:00
++m_iIndexLatest;
2005-04-23 10:19:47 +00:00
wrap( m_iIndexLatest, NUM_BANNERS );
2005-04-23 10:19:47 +00:00
m_Banner[m_iIndexLatest].PlayCommand( "ResetFade" );
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. */
2006-01-22 01:00:06 +00:00
bool FadingBanner::LoadFromCachedBanner( const RString &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;
2006-10-07 07:43:18 +00:00
bool bLowRes = (PREFSMAN->m_BannerCache != 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
{
2005-02-24 13:49:42 +00:00
if( pSong == NULL )
{
LoadFallback();
return;
}
2003-07-14 22:23:35 +00:00
/* Don't call HasBanner. That'll do disk access and cause the music wheel
* to skip. */
2006-01-22 01:00:06 +00:00
RString sPath = pSong->GetBannerPath();
if( sPath.empty() )
LoadFallback();
else
LoadFromCachedBanner( sPath );
}
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();
}
2006-01-22 01:00:06 +00:00
void FadingBanner::LoadFromSongGroup( RString sSongGroup )
{
2006-01-22 01:00:06 +00:00
const RString sGroupBannerPath = SONGMAN->GetSongGroupBannerPath( sSongGroup );
2003-06-15 01:53:51 +00:00
LoadFromCachedBanner( sGroupBannerPath );
}
2004-09-06 05:27:18 +00:00
void FadingBanner::LoadFromCourse( const Course* pCourse )
{
2005-07-29 22:59:11 +00:00
if( pCourse == NULL )
{
LoadFallback();
return;
}
/* Don't call HasBanner. That'll do disk access and cause the music wheel
* to skip. */
2006-01-22 01:00:06 +00:00
RString sPath = pCourse->m_sBannerPath;
if( sPath.empty() )
LoadCourseFallback();
else
LoadFromCachedBanner( sPath );
}
2005-08-03 03:27:43 +00:00
void FadingBanner::LoadIconFromCharacter( Character* pCharacter )
{
BeforeChange();
m_Banner[m_iIndexLatest].LoadIconFromCharacter( pCharacter );
}
2006-03-23 00:16:18 +00:00
void FadingBanner::LoadBannerFromUnlockEntry( const UnlockEntry* pUE )
{
BeforeChange();
m_Banner[m_iIndexLatest].LoadBannerFromUnlockEntry( pUE );
}
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
void FadingBanner::LoadCourseFallback()
{
BeforeChange();
m_Banner[m_iIndexLatest].LoadCourseFallback();
}
2005-06-20 04:17:02 +00:00
// lua start
#include "LuaBinding.h"
2005-06-20 05:02:03 +00:00
class LunaFadingBanner: public Luna<FadingBanner>
2005-06-20 04:17:02 +00:00
{
public:
2005-08-27 04:03:22 +00:00
static int scaletoclipped( T* p, lua_State *L ) { p->ScaleToClipped(FArg(1),FArg(2)); return 0; }
static int ScaleToClipped( T* p, lua_State *L ) { p->ScaleToClipped(FArg(1),FArg(2)); return 0; }
2005-06-20 04:17:02 +00:00
static int LoadFromSong( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadFromSong( NULL ); }
else { Song *pS = Luna<Song>::check(L,1); p->LoadFromSong( pS ); }
return 0;
}
2005-07-29 22:59:11 +00:00
static int LoadFromCourse( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadFromCourse( NULL ); }
else { Course *pC = Luna<Course>::check(L,1); p->LoadFromCourse( pC ); }
return 0;
}
2005-08-03 03:27:43 +00:00
static int LoadIconFromCharacter( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadIconFromCharacter( NULL ); }
else { Character *pC = Luna<Character>::check(L,1); p->LoadIconFromCharacter( pC ); }
return 0;
}
2005-08-15 07:51:39 +00:00
static int LoadCardFromCharacter( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadIconFromCharacter( NULL ); }
else { Character *pC = Luna<Character>::check(L,1); p->LoadIconFromCharacter( pC ); }
return 0;
}
2005-06-20 04:17:02 +00:00
2006-09-27 20:03:31 +00:00
LunaFadingBanner()
2005-06-20 04:17:02 +00:00
{
ADD_METHOD( scaletoclipped );
ADD_METHOD( ScaleToClipped );
ADD_METHOD( LoadFromSong );
ADD_METHOD( LoadFromCourse );
ADD_METHOD( LoadIconFromCharacter );
ADD_METHOD( LoadCardFromCharacter );
2005-06-20 04:17:02 +00:00
}
};
LUA_REGISTER_DERIVED_CLASS( FadingBanner, ActorFrame )
// lua end
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.
*/