Files
itgmania212121/stepmania/src/LyricDisplay.cpp
T

150 lines
5.0 KiB
C++
Raw Normal View History

2003-03-19 19:57:52 +00:00
#include "global.h"
#include "LyricDisplay.h"
#include "ScreenDimensions.h"
2003-03-19 19:57:52 +00:00
#include "GameState.h"
#include "ThemeMetric.h"
2003-03-19 19:57:52 +00:00
2005-01-26 11:21:43 +00:00
static ThemeMetric<apActorCommands> IN_COMMAND ("LyricDisplay","InCommand");
static ThemeMetric<apActorCommands> OUT_COMMAND ("LyricDisplay","OutCommand");
static ThemeMetric<RageColor> WIPE_DIM_FACTOR ("LyricDisplay","WipeDimFactor");
2003-03-19 19:57:52 +00:00
2005-06-08 21:50:55 +00:00
static float g_fTweenInTime, g_fTweenOutTime;
2003-03-19 19:57:52 +00:00
LyricDisplay::LyricDisplay()
{
2003-09-13 20:18:43 +00:00
for( int i=0; i<2; i++ )
{
2005-02-06 03:32:53 +00:00
m_textLyrics[i].LoadFromFont( THEME->GetPathF("LyricDisplay","text") );
2003-09-13 20:18:43 +00:00
m_textLyrics[i].SetDiffuse( RageColor(1,1,1,1) );
2005-06-08 21:50:55 +00:00
this->AddChild( &m_textLyrics[i] );
2003-09-13 20:18:43 +00:00
}
2003-03-19 19:57:52 +00:00
Init();
}
void LyricDisplay::Init()
{
2003-09-13 20:18:43 +00:00
for( int i=0; i<2; i++ )
m_textLyrics[i].SetText("");
2003-03-19 19:57:52 +00:00
m_iCurLyricNumber = 0;
/* Update global cache: */
2005-06-08 21:50:55 +00:00
g_fTweenInTime = Actor::GetCommandsLengthSeconds( IN_COMMAND );
g_fTweenOutTime = Actor::GetCommandsLengthSeconds( OUT_COMMAND );
2003-05-18 22:37:20 +00:00
m_fLastSecond = -500;
2003-03-19 19:57:52 +00:00
}
void LyricDisplay::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2003-05-28 03:32:07 +00:00
if( GAMESTATE->m_pCurSong == NULL )
return;
2003-05-18 22:37:20 +00:00
/* If the song has changed (in a course), reset. */
if( GAMESTATE->m_fMusicSeconds < m_fLastSecond )
Init();
m_fLastSecond = GAMESTATE->m_fMusicSeconds;
2003-03-19 19:57:52 +00:00
if( m_iCurLyricNumber >= GAMESTATE->m_pCurSong->m_LyricSegments.size() )
return;
2005-06-08 21:50:55 +00:00
const Song *pSong = GAMESTATE->m_pCurSong;
const float fStartTime = (pSong->m_LyricSegments[m_iCurLyricNumber].m_fStartTime) - g_fTweenInTime;
2003-03-19 19:57:52 +00:00
2005-06-08 21:50:55 +00:00
if( GAMESTATE->m_fMusicSeconds < fStartTime )
2003-03-19 19:57:52 +00:00
return;
const float MaxDisplayTime = 10;
float fShowLength = MaxDisplayTime;
2003-05-18 22:37:20 +00:00
/* Clamp this lyric to the beginning of the next, the end of the music,
* or 5 seconds. */
2005-06-08 21:50:55 +00:00
float fEndTime;
if( m_iCurLyricNumber+1 < GAMESTATE->m_pCurSong->m_LyricSegments.size() )
fEndTime = pSong->m_LyricSegments[m_iCurLyricNumber+1].m_fStartTime;
2003-05-18 22:37:20 +00:00
else
2005-06-08 21:50:55 +00:00
fEndTime = pSong->GetElapsedTimeFromBeat( pSong->m_fLastBeat );
2003-05-18 22:37:20 +00:00
2005-06-08 21:50:55 +00:00
const float fDistance = fEndTime - pSong->m_LyricSegments[m_iCurLyricNumber].m_fStartTime;
const float fTweenBufferTime = g_fTweenInTime + g_fTweenOutTime;
2003-05-18 22:37:20 +00:00
2005-06-08 21:50:55 +00:00
fShowLength = min( fShowLength, fDistance - fTweenBufferTime );
fShowLength = min( fShowLength, 3 );
2003-05-18 22:37:20 +00:00
/* If it's negative, two lyrics are so close together that there's no time
* to tween properly. Lyrics should never be this brief, anyway, so just
* skip it. */
2005-06-08 21:50:55 +00:00
fShowLength = max( fShowLength, 0 );
2003-03-19 19:57:52 +00:00
2003-11-01 19:36:30 +00:00
// make lyrics show faster a larger song rates.
fShowLength /= GAMESTATE->m_SongOptions.m_fMusicRate;
2003-09-13 20:18:43 +00:00
for( int i=0; i<2; i++ )
{
m_textLyrics[i].SetText( GAMESTATE->m_pCurSong->m_LyricSegments[m_iCurLyricNumber].m_sLyric );
/*
* This really needs a way to define a custom theme command here, so themes
* can do things like:
*
* "Diffuse=1,1,1,0;linear,.2;Diffuse=1,1,1,1;linear,.2;LyricDiffuse"
*/
2003-11-24 02:49:30 +00:00
const float fZoom = min( 1.0f, float(SCREEN_WIDTH)/(m_textLyrics[i].GetZoomedWidth()+1) );
2003-09-13 20:18:43 +00:00
m_textLyrics[i].StopTweening();
2005-06-08 21:50:55 +00:00
m_textLyrics[i].SetZoomX( fZoom );
2003-09-13 20:18:43 +00:00
RageColor color = GAMESTATE->m_pCurSong->m_LyricSegments[m_iCurLyricNumber].m_Color;
2003-09-13 20:18:43 +00:00
if( i==0 )
2003-10-03 06:34:34 +00:00
color *= WIPE_DIM_FACTOR;
2005-06-08 21:50:55 +00:00
m_textLyrics[i].SetDiffuse( color );
2003-09-13 20:18:43 +00:00
2003-09-15 19:57:27 +00:00
/* Crop the bottom layer of text away as we crop the top layer on. That
* prevents overdraw, which reduces AA quality. */
if( i==0 )
m_textLyrics[i].SetCropLeft(0);
2003-09-13 20:18:43 +00:00
if( i==1 )
m_textLyrics[i].SetCropRight(1);
2005-01-26 11:21:43 +00:00
m_textLyrics[i].RunCommands( IN_COMMAND );
m_textLyrics[i].BeginTweening( fShowLength * 0.75f ); /* sleep */
2003-09-15 19:57:27 +00:00
if( i==0 )
m_textLyrics[i].SetCropLeft(1);
2003-09-13 20:18:43 +00:00
if( i==1 )
m_textLyrics[i].SetCropRight(0);
m_textLyrics[i].BeginTweening( fShowLength * 0.25f ); /* sleep */
2005-01-26 11:21:43 +00:00
m_textLyrics[i].RunCommands( OUT_COMMAND );
2003-09-13 20:18:43 +00:00
}
2003-03-19 19:57:52 +00:00
m_iCurLyricNumber++;
}
2003-03-19 20:00:19 +00:00
/*
2004-06-08 00:08:04 +00:00
* (c) 2003-2004 Kevin Slaughter, Glenn Maynard
* 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.
*/