2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-09-29 05:06:18 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: BGAnimation
|
|
|
|
|
|
|
|
|
|
Desc: Particles used initially for background effects
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Ben Nordstrom
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BGAnimation.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "IniFile.h"
|
|
|
|
|
#include "BGAnimationLayer.h"
|
2003-03-05 02:52:40 +00:00
|
|
|
#include "RageUtil.h"
|
2003-03-10 05:07:00 +00:00
|
|
|
#include "song.h"
|
2003-03-10 02:46:01 +00:00
|
|
|
#include "ThemeManager.h"
|
2003-10-14 17:05:10 +00:00
|
|
|
#include "RageFile.h"
|
2003-10-31 01:55:17 +00:00
|
|
|
#include "ActorUtil.h"
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-10-24 07:24:12 +00:00
|
|
|
const int MAX_LAYERS = 1000;
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-11-05 03:56:37 +00:00
|
|
|
BGAnimation::BGAnimation( bool Generic )
|
2002-09-29 05:06:18 +00:00
|
|
|
{
|
2003-11-05 03:56:37 +00:00
|
|
|
/* See BGAnimationLayer::BGAnimationLayer for explanation. */
|
|
|
|
|
m_bGeneric = Generic;
|
2003-03-05 02:52:40 +00:00
|
|
|
m_fLengthSeconds = 10;
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BGAnimation::~BGAnimation()
|
|
|
|
|
{
|
|
|
|
|
Unload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BGAnimation::Unload()
|
|
|
|
|
{
|
2002-10-31 02:54:49 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2002-09-29 05:06:18 +00:00
|
|
|
delete m_Layers[i];
|
2002-10-24 20:15:24 +00:00
|
|
|
m_Layers.clear();
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BGAnimation::LoadFromStaticGraphic( CString sPath )
|
|
|
|
|
{
|
|
|
|
|
Unload();
|
|
|
|
|
|
2003-11-05 03:56:37 +00:00
|
|
|
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
|
2002-09-29 05:06:18 +00:00
|
|
|
pLayer->LoadFromStaticGraphic( sPath );
|
2002-10-31 04:23:39 +00:00
|
|
|
m_Layers.push_back( pLayer );
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-05 03:56:37 +00:00
|
|
|
void AddLayersFromAniDir( CString sAniDir, vector<BGAnimationLayer*> &layersAddTo, bool Generic )
|
2002-09-29 05:06:18 +00:00
|
|
|
{
|
2003-10-14 17:05:10 +00:00
|
|
|
if( sAniDir.empty() )
|
|
|
|
|
return;
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-12-10 09:44:16 +00:00
|
|
|
if( sAniDir.Right(1) != "/" )
|
|
|
|
|
sAniDir += "/";
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-09-03 18:10:26 +00:00
|
|
|
RAGE_ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" );
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-03-05 02:52:40 +00:00
|
|
|
CString sPathToIni = sAniDir + "BGAnimation.ini";
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-10-14 17:05:10 +00:00
|
|
|
IniFile ini(sPathToIni);
|
|
|
|
|
ini.ReadFile();
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
for( i=0; i<MAX_LAYERS; i++ )
|
2002-09-29 05:06:18 +00:00
|
|
|
{
|
2003-10-14 17:05:10 +00:00
|
|
|
CString sLayer = ssprintf("Layer%d",i+1);
|
|
|
|
|
const IniFile::key* pKey = ini.GetKey( sLayer );
|
|
|
|
|
if( pKey == NULL )
|
|
|
|
|
continue; // skip
|
2003-03-05 02:52:40 +00:00
|
|
|
|
2003-10-14 17:05:10 +00:00
|
|
|
CString sImportDir;
|
|
|
|
|
if( ini.GetValue(sLayer, "Import", sImportDir) )
|
2003-03-05 02:52:40 +00:00
|
|
|
{
|
2003-10-14 17:05:10 +00:00
|
|
|
// import a whole BGAnimation
|
|
|
|
|
sImportDir = sAniDir + sImportDir;
|
|
|
|
|
CollapsePath( sImportDir );
|
2003-11-05 03:56:37 +00:00
|
|
|
AddLayersFromAniDir( sImportDir, layersAddTo, Generic );
|
2003-10-14 17:05:10 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-01-26 02:32:09 +00:00
|
|
|
// import as a single layer
|
2003-11-05 03:56:37 +00:00
|
|
|
BGAnimationLayer* pLayer = new BGAnimationLayer( Generic );
|
2003-03-10 02:46:01 +00:00
|
|
|
pLayer->LoadFromIni( sAniDir, sLayer );
|
2003-10-14 17:05:10 +00:00
|
|
|
layersAddTo.push_back( pLayer );
|
2003-03-05 02:52:40 +00:00
|
|
|
}
|
2003-10-14 17:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2003-03-17 01:35:50 +00:00
|
|
|
|
2003-10-14 17:05:10 +00:00
|
|
|
void BGAnimation::LoadFromAniDir( CString sAniDir )
|
|
|
|
|
{
|
|
|
|
|
Unload();
|
|
|
|
|
|
|
|
|
|
if( sAniDir.empty() )
|
|
|
|
|
return;
|
|
|
|
|
|
2003-12-10 09:44:16 +00:00
|
|
|
if( sAniDir.Right(1) != "/" )
|
|
|
|
|
sAniDir += "/";
|
2003-10-14 17:05:10 +00:00
|
|
|
|
|
|
|
|
RAGE_ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" );
|
|
|
|
|
|
|
|
|
|
CString sPathToIni = sAniDir + "BGAnimation.ini";
|
|
|
|
|
|
|
|
|
|
if( DoesFileExist(sPathToIni) )
|
|
|
|
|
{
|
|
|
|
|
// This is a new style BGAnimation (using .ini)
|
2003-11-05 03:56:37 +00:00
|
|
|
AddLayersFromAniDir( sAniDir, m_Layers, m_bGeneric ); // TODO: Check for circular load
|
2003-10-14 17:05:10 +00:00
|
|
|
|
|
|
|
|
IniFile ini(sPathToIni);
|
|
|
|
|
ini.ReadFile();
|
2003-10-02 02:03:29 +00:00
|
|
|
if( !ini.GetValue( "BGAnimation", "LengthSeconds", m_fLengthSeconds ) )
|
2003-03-17 01:35:50 +00:00
|
|
|
{
|
|
|
|
|
m_fLengthSeconds = 0;
|
2003-10-14 17:05:10 +00:00
|
|
|
for( int i=0; (unsigned)i < m_Layers.size(); i++ )
|
2003-03-17 01:35:50 +00:00
|
|
|
m_fLengthSeconds = max(m_fLengthSeconds, m_Layers[i]->GetMaxTweenTimeLeft());
|
|
|
|
|
}
|
2004-01-07 00:13:59 +00:00
|
|
|
|
2004-01-25 22:22:40 +00:00
|
|
|
bool bUseScroller;
|
|
|
|
|
if( ini.GetValue( "BGAnimation", "UseScroller", bUseScroller ) && bUseScroller )
|
|
|
|
|
{
|
|
|
|
|
#define REQUIRED_GET_VALUE( szName, valueOut ) \
|
|
|
|
|
if( !ini.GetValue( "BGAnimation", szName, valueOut ) ) \
|
|
|
|
|
RageException::Throw( "File '%s' is missing the value BGAnimation::%s", sPathToIni.c_str(), szName );
|
|
|
|
|
|
2004-01-26 02:32:09 +00:00
|
|
|
float fScrollSecondsPerItem, fSpacingX, fSpacingY, fItemPaddingStart, fItemPaddingEnd;
|
2004-01-25 22:22:40 +00:00
|
|
|
REQUIRED_GET_VALUE( "ScrollSecondsPerItem", fScrollSecondsPerItem );
|
|
|
|
|
REQUIRED_GET_VALUE( "ScrollSpacingX", fSpacingX );
|
|
|
|
|
REQUIRED_GET_VALUE( "ScrollSpacingY", fSpacingY );
|
2004-01-26 02:32:09 +00:00
|
|
|
REQUIRED_GET_VALUE( "ItemPaddingStart", fItemPaddingStart );
|
|
|
|
|
REQUIRED_GET_VALUE( "ItemPaddingEnd", fItemPaddingEnd );
|
2004-01-25 22:22:40 +00:00
|
|
|
#undef REQUIRED_GET_VALUE
|
|
|
|
|
|
|
|
|
|
m_Scroller.Load( fScrollSecondsPerItem, fSpacingX, fSpacingY );
|
|
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
|
|
|
|
m_Scroller.AddChild( m_Layers[i] );
|
2004-01-26 02:32:09 +00:00
|
|
|
m_Scroller.SetCurrentAndDestinationItem( -fItemPaddingStart );
|
|
|
|
|
m_Scroller.SetDestinationItem( m_Layers.size()-1+fItemPaddingEnd );
|
2004-01-25 22:22:40 +00:00
|
|
|
this->AddChild( &m_Scroller );
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-07 00:13:59 +00:00
|
|
|
CString InitCommand;
|
|
|
|
|
if( ini.GetValue( "BGAnimation", "InitCommand", InitCommand ) )
|
|
|
|
|
{
|
|
|
|
|
/* There's an InitCommand. Run it now. This can be used to eg. change Z to
|
|
|
|
|
* modify draw order between BGAs in a Foreground. Most things should be done
|
|
|
|
|
* in metrics.ini commands, not here. */
|
|
|
|
|
this->Command( InitCommand );
|
|
|
|
|
}
|
2003-03-05 02:52:40 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// This is an old style BGAnimation (not using .ini)
|
|
|
|
|
|
|
|
|
|
// loading a directory of layers
|
|
|
|
|
CStringArray asImagePaths;
|
|
|
|
|
ASSERT( sAniDir != "" );
|
|
|
|
|
|
|
|
|
|
GetDirListing( sAniDir+"*.png", asImagePaths, false, true );
|
|
|
|
|
GetDirListing( sAniDir+"*.jpg", asImagePaths, false, true );
|
|
|
|
|
GetDirListing( sAniDir+"*.gif", asImagePaths, false, true );
|
|
|
|
|
GetDirListing( sAniDir+"*.avi", asImagePaths, false, true );
|
|
|
|
|
GetDirListing( sAniDir+"*.mpg", asImagePaths, false, true );
|
|
|
|
|
GetDirListing( sAniDir+"*.mpeg", asImagePaths, false, true );
|
|
|
|
|
GetDirListing( sAniDir+"*.sprite", asImagePaths, false, true );
|
|
|
|
|
|
|
|
|
|
SortCStringArray( asImagePaths );
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i<asImagePaths.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
const CString sPath = asImagePaths[i];
|
2003-10-29 20:32:29 +00:00
|
|
|
if( Basename(sPath).Left(1) == "_" )
|
2003-03-05 02:52:40 +00:00
|
|
|
continue; // don't directly load files starting with an underscore
|
2003-11-05 03:56:37 +00:00
|
|
|
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
|
2003-03-10 02:46:01 +00:00
|
|
|
pLayer->LoadFromAniLayerFile( asImagePaths[i] );
|
2003-03-05 02:52:40 +00:00
|
|
|
m_Layers.push_back( pLayer );
|
|
|
|
|
}
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 04:10:01 +00:00
|
|
|
void BGAnimation::LoadFromMovie( CString sMoviePath )
|
2002-09-29 05:06:18 +00:00
|
|
|
{
|
|
|
|
|
Unload();
|
|
|
|
|
|
2003-11-05 03:56:37 +00:00
|
|
|
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
|
2003-04-14 04:10:01 +00:00
|
|
|
pLayer->LoadFromMovie( sMoviePath );
|
2002-10-31 04:23:39 +00:00
|
|
|
m_Layers.push_back( pLayer );
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-10 02:46:01 +00:00
|
|
|
void BGAnimation::LoadFromVisualization( CString sVisPath )
|
2002-09-29 05:06:18 +00:00
|
|
|
{
|
|
|
|
|
Unload();
|
|
|
|
|
BGAnimationLayer* pLayer;
|
|
|
|
|
|
2003-10-30 20:50:31 +00:00
|
|
|
const Song* pSong = GAMESTATE->m_pCurSong;
|
2003-04-12 17:39:27 +00:00
|
|
|
CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathToG("Common fallback background");
|
2003-03-10 02:46:01 +00:00
|
|
|
|
2003-11-05 03:56:37 +00:00
|
|
|
pLayer = new BGAnimationLayer( m_bGeneric );
|
2002-09-29 05:06:18 +00:00
|
|
|
pLayer->LoadFromStaticGraphic( sSongBGPath );
|
2002-10-31 04:23:39 +00:00
|
|
|
m_Layers.push_back( pLayer );
|
2002-09-29 05:06:18 +00:00
|
|
|
|
2003-11-05 03:56:37 +00:00
|
|
|
pLayer = new BGAnimationLayer( m_bGeneric );
|
2002-09-29 05:06:18 +00:00
|
|
|
pLayer->LoadFromVisualization( sVisPath );
|
2002-10-31 04:23:39 +00:00
|
|
|
m_Layers.push_back( pLayer );
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BGAnimation::Update( float fDeltaTime )
|
|
|
|
|
{
|
2002-10-31 02:54:49 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2002-09-29 05:06:18 +00:00
|
|
|
m_Layers[i]->Update( fDeltaTime );
|
2003-11-05 06:41:57 +00:00
|
|
|
ActorFrame::Update( fDeltaTime );
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BGAnimation::DrawPrimitives()
|
|
|
|
|
{
|
2002-10-31 02:54:49 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2002-09-29 05:06:18 +00:00
|
|
|
m_Layers[i]->Draw();
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 04:10:01 +00:00
|
|
|
void BGAnimation::GainingFocus( float fRate, bool bRewindMovie, bool bLoop )
|
2002-09-29 05:06:18 +00:00
|
|
|
{
|
2002-10-31 02:54:49 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2003-04-14 04:10:01 +00:00
|
|
|
m_Layers[i]->GainingFocus( fRate, bRewindMovie, bLoop );
|
2002-10-10 04:11:30 +00:00
|
|
|
|
2002-10-28 05:30:45 +00:00
|
|
|
SetDiffuse( RageColor(1,1,1,1) );
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BGAnimation::LosingFocus()
|
|
|
|
|
{
|
2002-10-31 02:54:49 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2002-09-29 05:06:18 +00:00
|
|
|
m_Layers[i]->LosingFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-28 05:30:45 +00:00
|
|
|
void BGAnimation::SetDiffuse( const RageColor &c )
|
2002-10-10 04:11:30 +00:00
|
|
|
{
|
2002-10-31 02:54:49 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2002-10-10 04:11:30 +00:00
|
|
|
m_Layers[i]->SetDiffuse(c);
|
2003-11-05 06:41:57 +00:00
|
|
|
ActorFrame::SetDiffuse( c );
|
2003-07-10 03:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
2003-10-31 01:55:17 +00:00
|
|
|
float BGAnimation::GetTweenTimeLeft() const
|
|
|
|
|
{
|
2003-11-05 06:41:57 +00:00
|
|
|
float ret = 0;
|
2003-10-31 01:55:17 +00:00
|
|
|
|
2003-10-31 03:53:48 +00:00
|
|
|
for( unsigned i=0; i<m_Layers.size(); ++i )
|
2003-11-05 06:41:57 +00:00
|
|
|
ret = max( ret, m_Layers[i]->GetMaxTweenTimeLeft() );
|
2003-10-31 01:55:17 +00:00
|
|
|
|
2003-11-05 06:41:57 +00:00
|
|
|
return max( ret, Actor::GetTweenTimeLeft() );
|
2003-10-31 01:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-05 02:23:21 +00:00
|
|
|
void BGAnimation::FinishTweening()
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
|
|
|
|
m_Layers[i]->FinishTweening();
|
2003-11-05 06:41:57 +00:00
|
|
|
ActorFrame::FinishTweening();
|
2003-11-05 02:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
2003-10-31 01:55:17 +00:00
|
|
|
void BGAnimation::PlayCommand( const CString &cmd )
|
2003-07-10 03:37:13 +00:00
|
|
|
{
|
|
|
|
|
for( unsigned i=0; i<m_Layers.size(); i++ )
|
2003-10-31 01:55:17 +00:00
|
|
|
m_Layers[i]->PlayCommand( cmd );
|
2003-07-10 03:37:13 +00:00
|
|
|
}
|
2003-10-31 01:55:17 +00:00
|
|
|
|
2004-01-10 20:34:18 +00:00
|
|
|
void BGAnimation::HandleCommand( const ParsedCommand &command )
|
2003-10-31 01:55:17 +00:00
|
|
|
{
|
|
|
|
|
HandleParams;
|
|
|
|
|
|
2004-01-10 20:34:18 +00:00
|
|
|
if( sParam(0)=="playcommand" ) PlayCommand( sParam(1) );
|
2003-10-31 01:55:17 +00:00
|
|
|
else
|
|
|
|
|
{
|
2004-01-10 20:34:18 +00:00
|
|
|
Actor::HandleCommand( command );
|
2003-10-31 01:55:17 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckHandledParams;
|
|
|
|
|
}
|
|
|
|
|
|