Files
itgmania212121/stepmania/src/Background.cpp
T

185 lines
4.8 KiB
C++
Raw Normal View History

#include "stdafx.h"
/*
-----------------------------------------------------------------------------
File: Background.cpp
Desc: Background behind arrows while dancing
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
-----------------------------------------------------------------------------
*/
#include "Background.h"
#include "RageUtil.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
#include "ThemeManager.h"
#include "PrefsManager.h"
2002-02-05 05:33:33 +00:00
#include "RageBitmapTexture.h"
2002-06-27 17:49:10 +00:00
const CString MOVIE_VIS_DIR = "Visualizations\\";
const CString BG_ANIMS_DIR = "BGAnimations\\";
Background::Background()
{
2002-06-24 22:20:51 +00:00
m_fSongBeat = 0;
m_bShowDanger = false;
2002-01-20 23:29:03 +00:00
m_sprDanger.SetZoom( 2 );
m_sprDanger.SetEffectWagging();
2002-05-19 01:59:48 +00:00
m_sprDanger.Load( THEME->GetPathTo(GRAPHIC_GAMEPLAY_DANGER_TEXT) );
m_sprDanger.SetXY( CENTER_X, CENTER_Y );
2002-05-19 01:59:48 +00:00
m_sprDangerBackground.Load( THEME->GetPathTo(GRAPHIC_GAMEPLAY_DANGER_BACKGROUND) );
2002-02-24 01:43:11 +00:00
m_sprDangerBackground.StretchTo( CRect((int)SCREEN_LEFT, (int)SCREEN_TOP, (int)SCREEN_RIGHT, (int)SCREEN_BOTTOM) );
2002-06-24 22:20:51 +00:00
m_pCurBackgroundAnimation = NULL;
2002-06-23 02:57:51 +00:00
}
2002-02-11 04:46:31 +00:00
bool Background::LoadFromSong( Song* pSong, bool bDisableVisualizations )
{
2002-06-27 17:49:10 +00:00
//
// Load background animations
//
CStringArray asBGAnimNames;
GetDirListing( BG_ANIMS_DIR+"*.*", asBGAnimNames, true );
SortCStringArray( asBGAnimNames );
for( int i=0; i<asBGAnimNames.GetSize(); i++ )
{
if( stricmp(asBGAnimNames[i], "CVS") == 0 ) // if this directory is named CVS, skip it
continue; // skip
m_BackgroundAnimations.Add( new BackgroundAnimation(BG_ANIMS_DIR+asBGAnimNames[i], pSong) );
}
2002-06-24 22:20:51 +00:00
2002-06-27 17:49:10 +00:00
//
// load song background
//
2002-06-24 22:20:51 +00:00
CString sBackgroundMoviePath;
2002-02-11 04:46:31 +00:00
if( pSong->HasBackgroundMovie() )
{
2002-06-23 11:43:53 +00:00
m_sprSongBackground.Load( pSong->GetBackgroundMoviePath() );
2002-06-24 22:20:51 +00:00
m_sprSongBackground.SetZoomY( -1 ); // flip
}
else if( pSong->HasBackground() )
{
m_sprSongBackground.Load( pSong->GetBackgroundPath(), false, 2, 0, true );
}
else
{
2002-06-24 22:20:51 +00:00
m_sprSongBackground.Load( THEME->GetPathTo(GRAPHIC_FALLBACK_BACKGROUND), false, 2, 0, true );
}
m_sprSongBackground.StretchTo( CRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) );
m_sprSongBackground.SetDiffuseColor( D3DXCOLOR(0,0,0,1) );
2002-06-24 22:20:51 +00:00
if( PREFSMAN->m_visMode == VIS_MODE_MOVIE && !bDisableVisualizations )
{
// load a random visualization
CStringArray sVisualizationNames;
2002-06-27 17:49:10 +00:00
GetDirListing( MOVIE_VIS_DIR + "*.avi", sVisualizationNames );
GetDirListing( MOVIE_VIS_DIR + "*.mpg", sVisualizationNames );
GetDirListing( MOVIE_VIS_DIR + "*.mpeg", sVisualizationNames );
2002-06-24 22:20:51 +00:00
if( sVisualizationNames.GetSize() > 0 ) // there is at least one visualization
{
2002-06-24 22:20:51 +00:00
int iIndexRandom = rand() % sVisualizationNames.GetSize();
2002-06-27 17:49:10 +00:00
m_sprVisualizationOverlay.Load( MOVIE_VIS_DIR + sVisualizationNames[iIndexRandom] );
2002-06-24 22:20:51 +00:00
m_sprVisualizationOverlay.StretchTo( CRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) );
m_sprVisualizationOverlay.SetZoomY( m_sprVisualizationOverlay.GetZoomY()*-1 );
m_sprVisualizationOverlay.SetBlendModeAdd();
m_sprVisualizationOverlay.SetDiffuseColor( D3DXCOLOR(0,0,0,0) );
this->AddActor( &m_sprVisualizationOverlay );
}
}
return true;
}
void Background::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2002-06-24 22:20:51 +00:00
if( m_fSongBeat < 8 )
m_pCurBackgroundAnimation = NULL;
else
{
2002-06-27 17:49:10 +00:00
if( m_BackgroundAnimations.GetSize() > 0 )
{
int iIndexToSwitchTo = int(m_fSongBeat/BEATS_PER_MEASURE/4) % m_BackgroundAnimations.GetSize();
m_pCurBackgroundAnimation = m_BackgroundAnimations[ iIndexToSwitchTo ];
}
2002-06-24 22:20:51 +00:00
}
if( DangerVisible() )
{
m_sprDangerBackground.Update( fDeltaTime );
m_sprDanger.Update( fDeltaTime );
}
else
{
switch( PREFSMAN->m_visMode )
{
case VIS_MODE_ANIMATION:
2002-06-30 23:19:33 +00:00
if( m_pCurBackgroundAnimation && !m_bFreeze )
2002-06-24 22:20:51 +00:00
m_pCurBackgroundAnimation->Update( fDeltaTime, m_fSongBeat );
else
m_sprSongBackground.Update( fDeltaTime );
break;
case VIS_MODE_MOVIE:
m_sprVisualizationOverlay.Update( fDeltaTime );
// fall through and draw background
case VIS_MODE_NONE:
m_sprSongBackground.Update( fDeltaTime );
break;
}
}
m_sprVisualizationOverlay.Update( fDeltaTime );
2002-06-23 11:43:53 +00:00
m_sprSongBackground.Update( fDeltaTime );
m_sprDanger.Update( fDeltaTime );
m_sprDangerBackground.Update( fDeltaTime );
}
2002-05-19 01:59:48 +00:00
void Background::DrawPrimitives()
{
2002-05-19 01:59:48 +00:00
ActorFrame::DrawPrimitives();
2002-06-24 22:20:51 +00:00
if( DangerVisible() )
{
m_sprDangerBackground.Draw();
m_sprDanger.Draw();
}
else
{
2002-06-24 22:20:51 +00:00
switch( PREFSMAN->m_visMode )
{
case VIS_MODE_ANIMATION:
if( m_pCurBackgroundAnimation )
2002-06-27 17:49:10 +00:00
m_pCurBackgroundAnimation->Draw();
2002-06-24 22:20:51 +00:00
else
m_sprSongBackground.Draw();
break;
case VIS_MODE_MOVIE:
2002-06-27 17:49:10 +00:00
m_sprSongBackground.Draw();
2002-06-24 22:20:51 +00:00
m_sprVisualizationOverlay.Draw();
2002-06-27 17:49:10 +00:00
break;
2002-06-24 22:20:51 +00:00
case VIS_MODE_NONE:
m_sprSongBackground.Draw();
break;
}
}
}
2002-06-24 22:20:51 +00:00
bool Background::DangerVisible()
{
return m_bShowDanger && (TIMER->GetTimeSinceStart() - (int)TIMER->GetTimeSinceStart()) > 0.5f;
}