Files
itgmania212121/stepmania/src/ScoreDisplayNormal.cpp
T

135 lines
4.1 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-07-23 01:41:40 +00:00
#include "ScoreDisplayNormal.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "PrefsManager.h"
#include "GameState.h"
#include "ThemeManager.h"
#include "PlayerState.h"
2005-01-09 07:47:38 +00:00
#include "StageStats.h"
2005-02-12 21:03:39 +00:00
#include "CommonMetrics.h"
2002-07-23 01:41:40 +00:00
const float SCORE_TWEEN_TIME = 0.2f;
2003-02-25 00:33:42 +00:00
const int NUM_SCORE_DIGITS = 9;
2002-07-23 01:41:40 +00:00
ScoreDisplayNormal::ScoreDisplayNormal()
{
LOG->Trace( "ScoreDisplayNormal::ScoreDisplayNormal()" );
2002-07-23 01:41:40 +00:00
m_sprFrame.Load( THEME->GetPathG("ScoreDisplayNormal","frame") );
2003-05-05 06:48:20 +00:00
this->AddChild( &m_sprFrame );
2002-07-23 01:41:40 +00:00
// init the text
m_text.LoadFromFont( THEME->GetPathF("ScoreDisplayNormal","numbers") );
m_text.SetShadowLength( 0 );
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
m_iScore = 0;
2005-01-09 07:47:38 +00:00
2003-06-18 20:08:39 +00:00
m_iTrailingScore = 0;
m_iScoreVelocity = 0;
2002-07-23 01:41:40 +00:00
CString s;
for( int i=0; i<NUM_SCORE_DIGITS; i++ )
s += ' ';
2003-02-25 00:33:42 +00:00
m_text.SetText( s );
this->AddChild( &m_text );
2002-07-23 01:41:40 +00:00
}
void ScoreDisplayNormal::Init( const PlayerState* pPlayerState )
2002-07-23 01:41:40 +00:00
{
ScoreDisplay::Init( pPlayerState );
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = pPlayerState->m_PlayerNumber;
2005-02-12 21:03:39 +00:00
m_text.SetDiffuse( PLAYER_COLOR.GetValue(pn) );
2002-07-23 01:41:40 +00:00
}
2003-06-18 20:08:39 +00:00
void ScoreDisplayNormal::SetScore( int iNewScore )
{
m_iScore = iNewScore;
2002-07-23 01:41:40 +00:00
2005-01-09 07:47:38 +00:00
// play some games to display the correct score -- the actual internal score does not change at all
// but the displayed one can (ie: displayed score for subtracrive is MaxScore - score)
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
if( m_pPlayerState->m_CurrentPlayerOptions.m_ScoreDisplay == PlayerOptions::SCORING_SUBTRACT )
2005-01-09 07:47:38 +00:00
{
2005-01-10 15:37:29 +00:00
m_iScore = g_CurStageStats.m_player[pn].iMaxScore - ( g_CurStageStats.m_player[pn].iCurMaxScore - iNewScore );
2005-01-09 07:47:38 +00:00
}
else if( m_pPlayerState->m_CurrentPlayerOptions.m_ScoreDisplay == PlayerOptions::SCORING_AVERAGE )
2005-01-09 07:47:38 +00:00
{
if( g_CurStageStats.m_player[pn].iCurMaxScore == 0 ) // don't divide by zero fats
2005-01-09 07:47:38 +00:00
m_iScore = 0;
else
{
float scoreRatio = (float) iNewScore / (float) g_CurStageStats.m_player[pn].iCurMaxScore;
2005-01-09 07:47:38 +00:00
m_iScore = (int) ( scoreRatio * g_CurStageStats.m_player[pn].iMaxScore );
}
}
2003-06-18 20:08:39 +00:00
int iDelta = m_iScore - m_iTrailingScore;
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
m_iScoreVelocity = int(float(iDelta) / SCORE_TWEEN_TIME); // in score units per second
2002-07-23 01:41:40 +00:00
}
2003-02-25 00:33:42 +00:00
void ScoreDisplayNormal::SetText( CString s )
{
m_text.SetText( s );
}
2002-07-23 01:41:40 +00:00
void ScoreDisplayNormal::Update( float fDeltaTime )
{
2003-02-25 00:33:42 +00:00
ScoreDisplay::Update( fDeltaTime );
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
if( m_iTrailingScore != m_iScore )
2002-07-23 01:41:40 +00:00
{
// adjust for when player fails
int increment = int(m_iScoreVelocity * fDeltaTime);
if (m_iScoreVelocity != 0 && increment == 0) increment = 1;
2003-06-18 20:08:39 +00:00
int iDeltaBefore = m_iScore - m_iTrailingScore;
m_iTrailingScore += increment;
2003-06-18 20:08:39 +00:00
int iDeltaAfter = m_iScore - m_iTrailingScore;
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
if( (iDeltaBefore < 0 && iDeltaAfter > 0) ||
(iDeltaBefore > 0 && iDeltaAfter < 0) ) // the sign changed
2002-07-28 20:28:37 +00:00
{
2003-06-18 20:08:39 +00:00
m_iTrailingScore = m_iScore;
m_iScoreVelocity = 0;
2002-07-28 20:28:37 +00:00
}
2002-07-23 01:41:40 +00:00
2003-06-18 20:08:39 +00:00
m_text.SetText( ssprintf("%*.0i", NUM_SCORE_DIGITS, m_iTrailingScore) );
2002-07-23 01:41:40 +00:00
}
}
2004-06-08 00:08:04 +00:00
/*
* (c) 2001-2004 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.
*/