Files
itgmania212121/stepmania/src/DifficultyMeter.cpp
T

251 lines
7.5 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2003-03-09 00:55:49 +00:00
#include "DifficultyMeter.h"
2002-01-16 10:01:32 +00:00
#include "RageUtil.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2003-07-21 22:38:41 +00:00
#include "GameState.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
#include "ThemeManager.h"
2003-08-03 00:13:55 +00:00
#include "Steps.h"
2003-07-21 22:38:41 +00:00
#include "Course.h"
#include "SongManager.h"
2003-11-14 23:05:03 +00:00
#include "ActorUtil.h"
2004-06-28 07:26:00 +00:00
#include "Style.h"
2002-01-16 10:01:32 +00:00
// lua start
LUA_REGISTER_CLASS( DifficultyMeter )
// lua end
REGISTER_ACTOR_CLASS( DifficultyMeter );
2002-01-16 10:01:32 +00:00
2003-03-09 00:55:49 +00:00
DifficultyMeter::DifficultyMeter()
2002-05-19 01:59:48 +00:00
{
2003-11-14 23:05:03 +00:00
}
2002-05-19 01:59:48 +00:00
2005-02-23 23:04:06 +00:00
static CString GetDifficultyCommandName( Difficulty d ) { return "Set"+DifficultyToString(d); }
static CString GetCourseDifficultyCommandName( CourseDifficulty d ) { return "Set"+CourseDifficultyToString(d)+"Course"; }
static const CString DIFFICULTY_COMMAND_NAME_NONE = "None";
2003-11-14 23:05:03 +00:00
/* sID experiment:
*
* Names of an actor, "Foo":
* [Foo]
* Metric=abc
*
* [ScreenSomething]
* FooP1X=20
* FooP2Y=30
*
* Graphics\Foo under p1
*
* We want to call it different things in different contexts: we may only want one
* set of internal metrics for a given use, but separate metrics for each player at
* the screen level, and we may or may not want separate names at the asset level.
*
* As is, we tend to end up having to either duplicate [Foo] to [FooP1] and [FooP2]
* or not use m_sName for [Foo], which limits its use. Let's try using a separate
* name for internal metrics. I'm not sure if this will cause more confusion than good,
* so I'm trying it first in only this object.
*/
void DifficultyMeter::Load( const CString &sType )
2003-11-14 23:05:03 +00:00
{
/* We can't use global ThemeMetric<CString>s, because we can have multiple
* DifficultyMeters on screen at once, with different names. */
2005-02-23 23:04:06 +00:00
m_iNumFeetInMeter = THEME->GetMetricI(sType,"NumFeetInMeter");
m_iMaxFeetInMeter = THEME->GetMetricI(sType,"MaxFeetInMeter");
m_iGlowIfMeterGreaterThan = THEME->GetMetricI(sType,"GlowIfMeterGreaterThan");
m_bShowFeet = THEME->GetMetricB(sType,"ShowFeet");
/* "easy", "hard" */
2005-02-23 23:04:06 +00:00
m_bShowDifficulty = THEME->GetMetricB(sType,"ShowDifficulty");
/* 3, 9 */
2005-02-23 23:04:06 +00:00
m_bShowMeter = THEME->GetMetricB(sType,"ShowMeter");
m_bFeetIsDifficultyColor = THEME->GetMetricB(sType,"FeetIsDifficultyColor");
m_bFeetPerDifficulty = THEME->GetMetricB(sType,"FeetPerDifficulty");
2004-10-03 13:52:07 +00:00
if( m_bShowFeet )
2003-11-15 00:26:30 +00:00
{
m_textFeet.SetName( "Feet" );
2003-11-17 18:38:02 +00:00
CString Feet;
2004-10-03 13:52:07 +00:00
if( m_bFeetPerDifficulty )
2003-11-17 18:38:02 +00:00
{
for( unsigned i = 0; i < NUM_DIFFICULTIES; ++i )
Feet += char(i + '0'); // 01234
Feet += 'X'; // Off
}
else
Feet = "0X";
2005-02-23 23:04:06 +00:00
m_textFeet.LoadFromTextureAndChars( THEME->GetPathG(sType,"bar"), Feet );
ActorUtil::SetXYAndOnCommand( m_textFeet, sType );
2003-11-15 00:26:30 +00:00
this->AddChild( &m_textFeet );
}
2004-10-03 13:52:07 +00:00
if( m_bShowDifficulty )
2003-11-15 00:26:30 +00:00
{
2005-02-23 23:04:06 +00:00
m_Difficulty.Load( THEME->GetPathG(sType,"difficulty") );
2003-11-15 00:26:30 +00:00
m_Difficulty->SetName( "Difficulty" );
2005-02-23 23:04:06 +00:00
ActorUtil::SetXYAndOnCommand( m_Difficulty, sType );
2003-11-15 00:26:30 +00:00
this->AddChild( m_Difficulty );
2005-02-23 23:04:06 +00:00
FOREACH_Difficulty( d )
ActorUtil::LoadCommand( *m_Difficulty, sType, GetDifficultyCommandName(d) );
FOREACH_CourseDifficulty( d )
ActorUtil::LoadCommand( *m_Difficulty, sType, GetCourseDifficultyCommandName(d) );
ActorUtil::LoadCommand( *m_Difficulty, sType, DIFFICULTY_COMMAND_NAME_NONE );
2003-11-15 00:26:30 +00:00
}
2004-10-03 13:52:07 +00:00
if( m_bShowMeter )
2003-11-15 00:26:30 +00:00
{
m_textMeter.SetName( "Meter" );
2005-02-23 23:04:06 +00:00
m_textMeter.LoadFromFont( THEME->GetPathF(sType,"meter") );
ActorUtil::SetXYAndOnCommand( m_textMeter, sType );
2003-11-15 00:26:30 +00:00
this->AddChild( &m_textMeter );
2005-02-23 23:04:06 +00:00
FOREACH_Difficulty( d )
ActorUtil::LoadCommand( m_textMeter, sType, GetDifficultyCommandName(d) );
FOREACH_CourseDifficulty( d )
ActorUtil::LoadCommand( m_textMeter, sType, GetCourseDifficultyCommandName(d) );
ActorUtil::LoadCommand( m_textMeter, sType, DIFFICULTY_COMMAND_NAME_NONE );
2003-11-15 00:26:30 +00:00
}
2003-07-21 22:38:41 +00:00
Unset();
2002-05-19 01:59:48 +00:00
}
2004-06-04 01:17:46 +00:00
void DifficultyMeter::SetFromGameState( PlayerNumber pn )
{
if( GAMESTATE->IsCourseMode() )
{
const Trail* pTrail = GAMESTATE->m_pCurTrail[pn];
if( pTrail )
SetFromTrail( pTrail );
else
SetFromCourseDifficulty( GAMESTATE->m_PreferredCourseDifficulty[pn] );
}
else
{
const Steps* pSteps = GAMESTATE->m_pCurSteps[pn];
if( pSteps )
SetFromSteps( pSteps );
else
SetFromDifficulty( GAMESTATE->m_PreferredDifficulty[pn] );
}
}
2004-05-29 04:50:47 +00:00
void DifficultyMeter::SetFromSteps( const Steps* pSteps )
2002-05-19 01:59:48 +00:00
{
2004-05-24 03:41:39 +00:00
if( pSteps == NULL )
2002-05-19 01:59:48 +00:00
{
2003-07-21 22:38:41 +00:00
Unset();
return;
2002-05-19 01:59:48 +00:00
}
2003-07-21 22:38:41 +00:00
SetFromMeterAndDifficulty( pSteps->GetMeter(), pSteps->GetDifficulty() );
2005-02-23 23:04:06 +00:00
PlayDifficultyCommand( GetDifficultyCommandName( pSteps->GetDifficulty() ) );
2003-07-21 22:38:41 +00:00
}
void DifficultyMeter::SetFromTrail( const Trail* pTrail )
{
if( pTrail == NULL )
{
Unset();
return;
}
2004-06-04 03:38:52 +00:00
SetFromMeterAndDifficulty( pTrail->GetMeter(), pTrail->m_CourseDifficulty );
2005-02-23 23:04:06 +00:00
PlayDifficultyCommand( GetCourseDifficultyCommandName( pTrail->m_CourseDifficulty ) );
2003-07-21 22:38:41 +00:00
}
void DifficultyMeter::Unset()
{
SetFromMeterAndDifficulty( 0, DIFFICULTY_BEGINNER );
2005-02-23 23:04:06 +00:00
PlayDifficultyCommand( DIFFICULTY_COMMAND_NAME_NONE );
2003-07-21 22:38:41 +00:00
}
void DifficultyMeter::SetFromDifficulty( Difficulty dc )
{
SetFromMeterAndDifficulty( 0, DIFFICULTY_BEGINNER );
2005-02-23 23:04:06 +00:00
PlayDifficultyCommand( GetDifficultyCommandName( dc ) );
}
2004-06-04 01:17:46 +00:00
void DifficultyMeter::SetFromCourseDifficulty( CourseDifficulty cd )
2003-07-21 22:38:41 +00:00
{
2004-06-04 01:17:46 +00:00
SetFromMeterAndDifficulty( 0, DIFFICULTY_BEGINNER );
2005-02-23 23:04:06 +00:00
PlayDifficultyCommand( GetCourseDifficultyCommandName( cd ) );
2002-05-19 01:59:48 +00:00
}
void DifficultyMeter::SetFromMeterAndDifficulty( int iMeter, Difficulty dc )
2002-05-19 01:59:48 +00:00
{
2004-10-03 13:52:07 +00:00
if( m_bShowFeet )
2003-11-15 00:26:30 +00:00
{
2004-10-03 13:52:07 +00:00
char on = '0';
char off = 'X';
if( m_bFeetPerDifficulty )
2003-11-17 18:38:02 +00:00
on = char(dc + '0');
2003-11-15 00:26:30 +00:00
CString sNewText;
2004-10-03 13:52:07 +00:00
int iNumOn = min( m_iMaxFeetInMeter, iMeter );
sNewText.insert( sNewText.end(), iNumOn, on );
int iNumOff = max( 0, m_iNumFeetInMeter-iNumOn );
sNewText.insert( sNewText.end(), iNumOff, off );
2003-11-15 00:26:30 +00:00
m_textFeet.SetText( sNewText );
2004-10-03 13:52:07 +00:00
if( iMeter > m_iGlowIfMeterGreaterThan )
2003-11-15 00:26:30 +00:00
m_textFeet.SetEffectGlowShift();
else
m_textFeet.SetEffectNone();
2003-11-16 22:34:03 +00:00
2004-10-03 13:52:07 +00:00
if( m_bFeetIsDifficultyColor )
2003-11-16 22:34:03 +00:00
m_textFeet.SetDiffuse( SONGMAN->GetDifficultyColor( dc ) );
2003-11-15 00:26:30 +00:00
}
2004-10-03 13:52:07 +00:00
if( m_bShowMeter )
2003-11-15 00:26:30 +00:00
{
if( iMeter == 0 ) // Unset calls with this
{
m_textMeter.SetText( "x" );
}
else
{
const CString sMeter = ssprintf( "%i", iMeter );
2003-11-15 00:26:30 +00:00
m_textMeter.SetText( sMeter );
}
2003-11-15 00:26:30 +00:00
}
}
2005-02-23 23:04:06 +00:00
void DifficultyMeter::PlayDifficultyCommand( CString sDifficultyCommand )
2003-11-15 00:26:30 +00:00
{
2005-02-23 23:04:06 +00:00
if( m_sCurDifficultyCommand == sDifficultyCommand )
2003-11-15 00:26:30 +00:00
return;
2005-02-23 23:04:06 +00:00
m_sCurDifficultyCommand = sDifficultyCommand;
2003-11-15 00:26:30 +00:00
2004-10-03 13:52:07 +00:00
if( m_bShowDifficulty )
2005-02-23 23:04:06 +00:00
m_Difficulty->PlayCommand( sDifficultyCommand );
2004-10-03 13:52:07 +00:00
if( m_bShowMeter )
2005-02-23 23:04:06 +00:00
m_textMeter.PlayCommand( sDifficultyCommand );
2002-11-16 08:54:15 +00:00
}
2004-06-07 21:14:03 +00:00
/*
* (c) 2001-2004 Chris Danford, 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.
*/