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"
|
2004-02-14 23:22:23 +00:00
|
|
|
#include "LuaHelpers.h"
|
2004-02-01 03:14:37 +00:00
|
|
|
#include "arch/ArchHooks/ArchHooks.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()
|
|
|
|
|
{
|
2004-02-01 03:14:37 +00:00
|
|
|
DeleteAllChildren();
|
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 );
|
2004-02-01 03:14:37 +00:00
|
|
|
AddChild( pLayer );
|
2002-09-29 05:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
2004-02-01 03:14:37 +00:00
|
|
|
void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &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
|
|
|
|
2004-05-23 02:27:51 +00:00
|
|
|
IniFile ini;
|
|
|
|
|
ini.ReadFile( sPathToIni );
|
2003-10-14 17:05:10 +00:00
|
|
|
|
2004-02-14 23:22:23 +00:00
|
|
|
{
|
|
|
|
|
CString expr;
|
|
|
|
|
if( ini.GetValue( "BGAnimation", "Cond", expr ) )
|
|
|
|
|
{
|
|
|
|
|
if( !Lua::RunExpression( expr ) )
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-14 17:05:10 +00:00
|
|
|
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
|
|
|
{
|
2004-05-03 03:58:41 +00:00
|
|
|
CString expr;
|
|
|
|
|
if( ini.GetValue(sLayer,"Condition",expr) )
|
|
|
|
|
{
|
|
|
|
|
if( !Lua::RunExpression( expr ) )
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
2004-02-01 03:14:37 +00:00
|
|
|
AddLayersFromAniDir( sAniDir, m_SubActors, m_bGeneric ); // TODO: Check for circular load
|
2003-10-14 17:05:10 +00:00
|
|
|
|
2004-05-23 02:27:51 +00:00
|
|
|
IniFile ini;
|
|
|
|
|
ini.ReadFile( sPathToIni );
|
2003-10-02 02:03:29 +00:00
|
|
|
if( !ini.GetValue( "BGAnimation", "LengthSeconds", m_fLengthSeconds ) )
|
2003-03-17 01:35:50 +00:00
|
|
|
{
|
2004-01-29 05:23:31 +00:00
|
|
|
/* XXX: if m_bGeneric, simply constructing the BG layer won't run "On",
|
|
|
|
|
* so at this point GetMaxTweenTimeLeft is probably 0 */
|
2004-02-01 03:14:37 +00:00
|
|
|
m_fLengthSeconds = this->GetTweenTimeLeft();
|
2003-03-17 01:35:50 +00:00
|
|
|
}
|
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 )
|
|
|
|
|
{
|
2004-02-01 03:14:37 +00:00
|
|
|
// TODO: Move this into ActorScroller
|
|
|
|
|
|
2004-01-25 22:22:40 +00:00
|
|
|
#define REQUIRED_GET_VALUE( szName, valueOut ) \
|
2004-02-01 03:14:37 +00:00
|
|
|
if( !ini.GetValue( "Scroller", szName, valueOut ) ) \
|
|
|
|
|
HOOKS->MessageBoxOK( ssprintf("File '%s' is missing the value Scroller::%s", sPathToIni.c_str(), szName) );
|
|
|
|
|
|
|
|
|
|
float fSecondsPerItem = 1;
|
|
|
|
|
int iNumItemsToDraw = 7;
|
|
|
|
|
RageVector3 vRotationDegrees = RageVector3(0,0,0);
|
|
|
|
|
RageVector3 vTranslateTerm0 = RageVector3(0,0,0);
|
|
|
|
|
RageVector3 vTranslateTerm1 = RageVector3(0,0,0);
|
|
|
|
|
RageVector3 vTranslateTerm2 = RageVector3(0,0,0);
|
|
|
|
|
float fItemPaddingStart = 0;
|
|
|
|
|
float fItemPaddingEnd = 0;
|
|
|
|
|
|
|
|
|
|
REQUIRED_GET_VALUE( "SecondsPerItem", fSecondsPerItem );
|
|
|
|
|
REQUIRED_GET_VALUE( "NumItemsToDraw", iNumItemsToDraw );
|
|
|
|
|
REQUIRED_GET_VALUE( "RotationDegreesX", vRotationDegrees[0] );
|
|
|
|
|
REQUIRED_GET_VALUE( "RotationDegreesY", vRotationDegrees[1] );
|
|
|
|
|
REQUIRED_GET_VALUE( "RotationDegreesZ", vRotationDegrees[2] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm0X", vTranslateTerm0[0] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm0Y", vTranslateTerm0[1] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm0Z", vTranslateTerm0[2] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm1X", vTranslateTerm1[0] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm1Y", vTranslateTerm1[1] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm1Z", vTranslateTerm1[2] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm2X", vTranslateTerm2[0] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm2Y", vTranslateTerm2[1] );
|
|
|
|
|
REQUIRED_GET_VALUE( "TranslateTerm2Z", vTranslateTerm2[2] );
|
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
|
|
|
|
|
|
2004-02-01 03:14:37 +00:00
|
|
|
ActorScroller::Load(
|
|
|
|
|
fSecondsPerItem,
|
|
|
|
|
iNumItemsToDraw,
|
|
|
|
|
vRotationDegrees,
|
|
|
|
|
vTranslateTerm0,
|
|
|
|
|
vTranslateTerm1,
|
|
|
|
|
vTranslateTerm2 );
|
|
|
|
|
ActorScroller::SetCurrentAndDestinationItem( int(-fItemPaddingStart) );
|
|
|
|
|
ActorScroller::SetDestinationItem( int(m_SubActors.size()-1+fItemPaddingEnd) );
|
2004-01-25 22:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
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] );
|
2004-02-01 03:14:37 +00:00
|
|
|
AddChild( pLayer );
|
2003-03-05 02:52:40 +00:00
|
|
|
}
|
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 );
|
2004-02-01 03:14:37 +00:00
|
|
|
AddChild( 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 );
|
2004-02-01 03:14:37 +00:00
|
|
|
AddChild( 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 );
|
2004-02-01 03:14:37 +00:00
|
|
|
AddChild( pLayer );
|
2003-10-31 01:55:17 +00:00
|
|
|
}
|
|
|
|
|
|