Files
itgmania212121/stepmania/src/BGAnimation.cpp
T

264 lines
8.1 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
#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"
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-06-10 22:47:51 +00:00
#include "arch/Dialog/Dialog.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
BGAnimation::BGAnimation( bool Generic )
2002-09-29 05:06:18 +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();
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
2004-06-16 00:38:31 +00:00
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;
2004-05-29 20:18:51 +00:00
if( ini.GetValue( "BGAnimation", "Condition", expr ) || ini.GetValue( "BGAnimation", "Cond", expr ) )
2004-02-14 23:22:23 +00:00
{
if( !Lua::RunExpressionB( expr ) )
2004-02-14 23:22:23 +00:00
return;
}
}
2004-09-21 07:53:39 +00:00
for( int 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::RunExpressionB( expr ) )
2004-05-03 03:58:41 +00:00
continue;
}
2003-10-14 17:05:10 +00:00
// import a whole BGAnimation
sImportDir = sAniDir + sImportDir;
CollapsePath( sImportDir );
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
BGAnimationLayer* pLayer = new BGAnimationLayer( Generic );
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-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
2004-06-16 00:38:31 +00:00
ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" );
2003-10-14 17:05:10 +00:00
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 ) )
{
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();
}
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 ) ) \
2004-06-10 22:47:51 +00:00
Dialog::OK( ssprintf("File '%s' is missing the value Scroller::%s", sPathToIni.c_str(), szName) );
2004-02-01 03:14:37 +00:00
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
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
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
}
}
void BGAnimation::LoadFromMovie( CString sMoviePath )
2002-09-29 05:06:18 +00:00
{
Unload();
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
pLayer->LoadFromMovie( sMoviePath );
2004-02-01 03:14:37 +00:00
AddChild( 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;
2003-10-30 20:50:31 +00:00
const Song* pSong = GAMESTATE->m_pCurSong;
CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathToG("Common fallback background");
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
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
}
2004-06-01 00:53:06 +00:00
/*
* (c) 2001-2004 Ben Nordstrom, 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.
*/