Files
itgmania212121/stepmania/src/BGAnimation.cpp
T

183 lines
4.4 KiB
C++
Raw Normal View History

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"
#include "ThemeManager.h"
2002-09-29 05:06:18 +00:00
const int MAX_LAYERS = 100;
2002-09-29 05:06:18 +00:00
BGAnimation::BGAnimation()
{
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()
{
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();
BGAnimationLayer* pLayer = new BGAnimationLayer;
pLayer->LoadFromStaticGraphic( sPath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::LoadFromAniDir( CString sAniDir )
2002-09-29 05:06:18 +00:00
{
Unload();
2003-07-22 07:47:27 +00:00
if( !sAniDir.empty() && sAniDir.Right(1) != SLASH )
sAniDir += SLASH;
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-03-05 02:52:40 +00:00
if( DoesFileExist(sPathToIni) )
2002-09-29 05:06:18 +00:00
{
2003-03-05 02:52:40 +00:00
// This is a new style BGAnimation (using .ini)
IniFile ini(sPathToIni);
ini.ReadFile();
2003-07-31 20:34:01 +00:00
int i;
for( i=0; i<MAX_LAYERS; i++ )
2003-03-05 02:52:40 +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
BGAnimationLayer* pLayer = new BGAnimationLayer;
pLayer->LoadFromIni( sAniDir, sLayer );
2003-03-05 02:52:40 +00:00
m_Layers.push_back( pLayer );
}
2003-10-02 02:03:29 +00:00
if( !ini.GetValue( "BGAnimation", "LengthSeconds", m_fLengthSeconds ) )
{
m_fLengthSeconds = 0;
2003-07-31 20:34:01 +00:00
for( i=0; (unsigned)i < m_Layers.size(); i++ )
m_fLengthSeconds = max(m_fLengthSeconds, m_Layers[i]->GetMaxTweenTimeLeft());
}
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];
CString sDir, sFName, sExt;
splitrelpath( sPath, sDir, sFName, sExt );
if( sFName.Left(1) == "_" )
continue; // don't directly load files starting with an underscore
BGAnimationLayer* pLayer = new BGAnimationLayer;
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
}
}
void BGAnimation::LoadFromMovie( CString sMoviePath )
2002-09-29 05:06:18 +00:00
{
Unload();
BGAnimationLayer* pLayer = new BGAnimationLayer;
pLayer->LoadFromMovie( sMoviePath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::LoadFromVisualization( CString sVisPath )
2002-09-29 05:06:18 +00:00
{
Unload();
BGAnimationLayer* pLayer;
Song* pSong = GAMESTATE->m_pCurSong;
CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathToG("Common fallback background");
2002-09-29 05:06:18 +00:00
pLayer = new BGAnimationLayer;
pLayer->LoadFromStaticGraphic( sSongBGPath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
pLayer = new BGAnimationLayer;
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 )
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
m_Layers[i]->Update( fDeltaTime );
}
void BGAnimation::DrawPrimitives()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
m_Layers[i]->Draw();
}
void BGAnimation::GainingFocus( float fRate, bool bRewindMovie, bool bLoop )
2002-09-29 05:06:18 +00:00
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->GainingFocus( fRate, bRewindMovie, bLoop );
SetDiffuse( RageColor(1,1,1,1) );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::LosingFocus()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
m_Layers[i]->LosingFocus();
}
void BGAnimation::SetDiffuse( const RageColor &c )
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->SetDiffuse(c);
2003-07-10 03:37:13 +00:00
}
void BGAnimation::PlayOffCommand()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->PlayOffCommand();
}