Files
itgmania212121/stepmania/src/GradeDisplay.cpp
T

164 lines
4.6 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-01-16 10:01:32 +00:00
/*
-----------------------------------------------------------------------------
2002-06-24 22:04:31 +00:00
Class: GradeDisplay
2002-01-16 10:01:32 +00:00
2002-06-24 22:04:31 +00:00
Desc: See header.
2002-01-16 10:01:32 +00:00
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-06-24 22:04:31 +00:00
Chris Danford
2002-01-16 10:01:32 +00:00
-----------------------------------------------------------------------------
*/
2002-05-01 19:14:55 +00:00
#include "GradeDisplay.h"
2002-01-16 10:01:32 +00:00
#include "RageUtil.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
#include "ThemeManager.h"
2002-01-16 10:01:32 +00:00
2002-05-01 19:14:55 +00:00
const float SCROLL_TIME = 5.0f;
2002-12-21 10:04:25 +00:00
const float QUICK_SCROLL_TIME = .25f;
const int NUM_GRADE_FRAMES = 8;
2002-05-28 20:01:22 +00:00
const float GRADE_FRAME_HEIGHT = 1/(float)NUM_GRADE_FRAMES;
const float GRADES_TO_SCROLL = NUM_GRADE_FRAMES*4;
2002-01-16 10:01:32 +00:00
2002-05-01 19:14:55 +00:00
GradeDisplay::GradeDisplay()
{
m_fTimeLeftInScroll = 0;
2002-12-21 10:04:25 +00:00
m_bDoScrolling = 0;
2002-05-01 19:14:55 +00:00
2002-08-22 09:31:32 +00:00
SetGrade( PLAYER_1, GRADE_NO_DATA );
2002-05-01 19:14:55 +00:00
}
2003-03-31 03:11:31 +00:00
bool GradeDisplay::Load( RageTextureID ID )
{
ID.bStretch = true;
Sprite::Load( ID );
Sprite::StopAnimating();
2003-03-31 18:29:25 +00:00
if( Sprite::GetNumStates() != 8 && Sprite::GetNumStates() != 16 )
2003-03-31 03:11:31 +00:00
RageException::Throw( "The grade graphic '%s' must have either 8 or 16 frames.", ID.filename.GetString() );
return true;
}
2002-05-01 19:14:55 +00:00
void GradeDisplay::Update( float fDeltaTime )
{
Sprite::Update( fDeltaTime );
2002-06-14 22:25:22 +00:00
if( m_bDoScrolling )
{
m_fTimeLeftInScroll -= fDeltaTime;
m_fTimeLeftInScroll = max( 0, m_fTimeLeftInScroll );
2002-12-21 10:04:25 +00:00
float fPercentIntoScrolling;
if( m_bDoScrolling == 1)
{
fPercentIntoScrolling = 1 - (m_fTimeLeftInScroll/SCROLL_TIME);
if( fPercentIntoScrolling < 0.75 )
fPercentIntoScrolling = (fPercentIntoScrolling/0.75f) * (1 + 1.0f/NUM_GRADE_FRAMES);
else if( fPercentIntoScrolling < 0.9 )
fPercentIntoScrolling = 1 + 1.0f/NUM_GRADE_FRAMES;
else
fPercentIntoScrolling = (1 + 1.0f/NUM_GRADE_FRAMES) - ((fPercentIntoScrolling-0.9f)/0.1f) * 1.0f/NUM_GRADE_FRAMES;
} else {
fPercentIntoScrolling = 1 - (m_fTimeLeftInScroll/QUICK_SCROLL_TIME);
}
m_frectCurTexCoords.left = m_frectStartTexCoords.left*(1-fPercentIntoScrolling) + m_frectDestTexCoords.left*fPercentIntoScrolling;
m_frectCurTexCoords.top = m_frectStartTexCoords.top*(1-fPercentIntoScrolling) + m_frectDestTexCoords.top*fPercentIntoScrolling;
m_frectCurTexCoords.right = m_frectStartTexCoords.right*(1-fPercentIntoScrolling) + m_frectDestTexCoords.right*fPercentIntoScrolling;
m_frectCurTexCoords.bottom = m_frectStartTexCoords.bottom*(1-fPercentIntoScrolling) + m_frectDestTexCoords.bottom*fPercentIntoScrolling;
this->SetCustomTextureRect( m_frectCurTexCoords );
2002-06-14 22:25:22 +00:00
}
2002-05-01 19:14:55 +00:00
}
2002-05-19 01:59:48 +00:00
void GradeDisplay::DrawPrimitives()
{
Sprite::DrawPrimitives();
}
2003-03-31 03:11:31 +00:00
int GradeDisplay::GetFrameNo( PlayerNumber pn, Grade g )
2002-05-01 19:14:55 +00:00
{
2003-03-31 03:11:31 +00:00
// either 8, or 16 states
int iNumCols = Sprite::GetNumStates()==8 ? 1 : 2;
2002-05-01 19:14:55 +00:00
switch( g )
{
2003-03-31 03:11:31 +00:00
case GRADE_AAAA: return 0*iNumCols+pn; break;
case GRADE_AAA: return 1*iNumCols+pn; break;
case GRADE_AA: return 2*iNumCols+pn; break;
case GRADE_A: return 3*iNumCols+pn; break;
case GRADE_B: return 4*iNumCols+pn; break;
case GRADE_C: return 5*iNumCols+pn; break;
case GRADE_D: return 6*iNumCols+pn; break;
case GRADE_E: return 7*iNumCols+pn; break;
case GRADE_NO_DATA: return 0; break;
default: ASSERT(0); return 0;
2002-05-01 19:14:55 +00:00
}
2003-03-31 03:11:31 +00:00
}
2002-05-01 19:14:55 +00:00
2003-03-31 03:11:31 +00:00
void GradeDisplay::SetGrade( PlayerNumber pn, Grade g )
2002-05-01 19:14:55 +00:00
{
2003-03-31 03:11:31 +00:00
m_PlayerNumber = pn;
2002-05-28 20:01:22 +00:00
m_Grade = g;
2003-03-31 03:11:31 +00:00
m_bDoScrolling = false;
StopUsingCustomCoords();
2002-06-14 22:25:22 +00:00
2003-03-31 18:29:25 +00:00
if(g != GRADE_NO_DATA)
{
SetState( GetFrameNo(pn,g) );
SetDiffuse( RageColor(1,1,1,1.0f) );
} else
SetDiffuse( RageColor(1,1,1,0) );
2003-03-31 03:11:31 +00:00
}
2002-06-14 22:25:22 +00:00
2003-03-31 03:11:31 +00:00
void GradeDisplay::Spin()
{
m_bDoScrolling = true;
2002-05-01 19:14:55 +00:00
2003-03-31 03:11:31 +00:00
int iFrameNo = GetFrameNo( m_PlayerNumber, m_Grade );
2002-05-28 20:01:22 +00:00
m_frectDestTexCoords = *m_pTexture->GetTextureCoordRect( iFrameNo );
m_frectStartTexCoords = m_frectDestTexCoords;
m_frectStartTexCoords.top += GRADES_TO_SCROLL * GRADE_FRAME_HEIGHT;
m_frectStartTexCoords.bottom += GRADES_TO_SCROLL * GRADE_FRAME_HEIGHT;
2002-05-01 19:14:55 +00:00
m_fTimeLeftInScroll = SCROLL_TIME;
2002-12-21 10:04:25 +00:00
/* Set the initial position. */
Update(0);
2002-05-01 19:14:55 +00:00
}
2002-08-20 08:30:30 +00:00
void GradeDisplay::SettleImmediately()
{
m_fTimeLeftInScroll = 0;
}
2002-12-21 10:04:25 +00:00
void GradeDisplay::SettleQuickly()
{
if(m_bDoScrolling != 1)
return;
/* If we're in the last phase of scrolling, don't do this. */
if( 1 - (m_fTimeLeftInScroll/SCROLL_TIME) >= 0.9 )
return;
2002-12-21 10:04:25 +00:00
/* m_frectDestTexCoords.top is between 0 and 1 (inclusive). m_frectCurTexCoords
* is somewhere above that. Shift m_frectCurTexCoords downwards so it's pointing
* at the same physical place (remember, the grade texture is tiled) but no more
* than one rotation away from the destination. */
while(m_frectCurTexCoords.top > m_frectDestTexCoords.top + 1.0f)
{
m_frectCurTexCoords.top -= 1.0f;
m_frectCurTexCoords.bottom -= 1.0f;
}
m_frectStartTexCoords = m_frectCurTexCoords;
m_bDoScrolling = 2;
m_fTimeLeftInScroll = QUICK_SCROLL_TIME;
}