Files
itgmania212121/stepmania/src/DifficultyMeter.cpp
T

238 lines
6.1 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
/*
-----------------------------------------------------------------------------
2003-03-09 00:55:49 +00:00
Class: DifficultyMeter
2002-01-16 10:01:32 +00:00
2002-05-27 08:23:27 +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-05-27 08:23:27 +00:00
Chris Danford
2002-01-16 10:01:32 +00:00
-----------------------------------------------------------------------------
*/
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"
#include "StyleDef.h"
2002-01-16 10:01:32 +00:00
2003-11-14 23:05:03 +00:00
#define NUM_FEET_IN_METER THEME->GetMetricI(m_sName,"NumFeetInMeter")
#define MAX_FEET_IN_METER THEME->GetMetricI(m_sName,"MaxFeetInMeter")
#define GLOW_IF_METER_GREATER_THAN THEME->GetMetricI(m_sName,"GlowIfMeterGreaterThan")
2003-11-15 00:26:30 +00:00
#define SHOW_FEET THEME->GetMetricB(m_sName,"ShowFeet")
/* "easy", "hard" */
#define SHOW_DIFFICULTY THEME->GetMetricB(m_sName,"ShowDifficulty")
/* 3, 9 */
#define SHOW_METER THEME->GetMetricB(m_sName,"ShowMeter")
2003-11-16 22:34:03 +00:00
#define FEET_IS_DIFFICULTY_COLOR THEME->GetMetricB(m_sName,"FeetIsDifficultyColor")
2003-11-17 18:38:02 +00:00
#define FEET_PER_DIFFICULTY THEME->GetMetricB(m_sName,"FeetPerDifficulty")
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
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()
{
2003-11-15 00:26:30 +00:00
if( SHOW_FEET )
{
m_textFeet.SetName( "Feet" );
2003-11-17 18:38:02 +00:00
CString Feet;
if( FEET_PER_DIFFICULTY )
{
for( unsigned i = 0; i < NUM_DIFFICULTIES; ++i )
Feet += char(i + '0'); // 01234
Feet += 'X'; // Off
}
else
Feet = "0X";
m_textFeet.LoadFromTextureAndChars( THEME->GetPathG(m_sName,"bar"), Feet );
2003-11-15 00:26:30 +00:00
SET_XY_AND_ON_COMMAND( &m_textFeet );
this->AddChild( &m_textFeet );
}
if( SHOW_DIFFICULTY )
{
m_Difficulty.Load( THEME->GetPathG(m_sName,"difficulty") );
2003-11-15 00:26:30 +00:00
m_Difficulty->SetName( "Difficulty" );
SET_XY_AND_ON_COMMAND( m_Difficulty );
this->AddChild( m_Difficulty );
}
if( SHOW_METER )
{
m_textMeter.SetName( "Meter" );
m_textMeter.LoadFromFont( THEME->GetPathN(m_sName,"meter") );
2003-11-15 00:26:30 +00:00
SET_XY_AND_ON_COMMAND( m_textMeter );
this->AddChild( &m_textMeter );
}
2003-07-21 22:38:41 +00:00
Unset();
2002-05-19 01:59:48 +00:00
}
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() );
2004-05-24 03:41:39 +00:00
SetDifficulty( DifficultyToString( pSteps->GetDifficulty() ) );
2003-07-21 22:38:41 +00:00
}
void DifficultyMeter::SetFromCourse( const Course* pCourse, PlayerNumber pn )
2003-07-21 22:38:41 +00:00
{
if( pCourse == 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
StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
CourseDifficulty cd = GAMESTATE->m_PreferredCourseDifficulty[pn];
const int meter = (int) roundf( pCourse->GetMeter(st,cd) );
2003-07-21 22:38:41 +00:00
2003-11-18 00:51:40 +00:00
// XXX metrics
2003-11-15 00:26:30 +00:00
Difficulty FakeDifficulty;
switch( cd )
{
case COURSE_DIFFICULTY_EASY: FakeDifficulty = DIFFICULTY_EASY; break;
case COURSE_DIFFICULTY_REGULAR: FakeDifficulty = DIFFICULTY_MEDIUM; break;
case COURSE_DIFFICULTY_DIFFICULT: FakeDifficulty = DIFFICULTY_HARD; break;
default: ASSERT(0);
}
2003-11-15 00:26:30 +00:00
SetFromMeterAndDifficulty( meter, FakeDifficulty );
2003-11-15 00:26:30 +00:00
SetDifficulty( DifficultyToString(FakeDifficulty) + "Course" );
2003-07-21 22:38:41 +00:00
}
void DifficultyMeter::Unset()
{
2003-11-14 23:05:03 +00:00
m_textFeet.SetEffectNone();
2003-11-17 18:38:02 +00:00
if( FEET_IS_DIFFICULTY_COLOR )
m_textFeet.SetDiffuse( RageColor(0.8f,0.8f,0.8f,1) );
SetFromMeterAndDifficulty( 0, DIFFICULTY_BEGINNER );
2003-11-15 00:26:30 +00:00
SetDifficulty( "None" );
2003-07-21 22:38:41 +00:00
}
void DifficultyMeter::SetFromDifficulty( Difficulty dc )
{
m_textFeet.SetEffectNone();
if( FEET_IS_DIFFICULTY_COLOR )
m_textFeet.SetDiffuse( RageColor(0.8f,0.8f,0.8f,1) );
SetFromMeterAndDifficulty( 0, DIFFICULTY_BEGINNER );
SetDifficulty( DifficultyToString( dc ) );
}
void DifficultyMeter::SetFromCourseDifficulty( CourseDifficulty cd )
{
m_textFeet.SetEffectNone();
if( FEET_IS_DIFFICULTY_COLOR )
m_textFeet.SetDiffuse( RageColor(0.8f,0.8f,0.8f,1) );
SetFromMeterAndDifficulty( 0, DIFFICULTY_BEGINNER );
SetDifficulty( CourseDifficultyToString( cd ) );
}
2003-07-21 22:38:41 +00:00
void DifficultyMeter::SetFromGameState( PlayerNumber pn )
{
if( GAMESTATE->IsCourseMode() )
{
Course* pCourse = GAMESTATE->m_pCurCourse;
if( pCourse )
SetFromCourse( pCourse, pn );
else
SetFromCourseDifficulty( GAMESTATE->m_PreferredCourseDifficulty[pn] );
}
2003-07-21 22:38:41 +00:00
else
{
2004-05-24 06:12:17 +00:00
Steps* pSteps = GAMESTATE->m_pCurSteps[pn];
if( pSteps )
2004-05-29 04:50:47 +00:00
SetFromSteps( pSteps );
else
SetFromDifficulty( GAMESTATE->m_PreferredDifficulty[pn] );
}
2002-05-19 01:59:48 +00:00
}
void DifficultyMeter::SetFromMeterAndDifficulty( int iMeter, Difficulty dc )
2002-05-19 01:59:48 +00:00
{
2003-11-15 00:26:30 +00:00
if( SHOW_FEET )
{
2003-11-17 18:38:02 +00:00
CString on = "0";
CString off = "X";
if( FEET_PER_DIFFICULTY )
on = char(dc + '0');
2003-11-15 00:26:30 +00:00
CString sNewText;
int f;
for( f=0; f<NUM_FEET_IN_METER; f++ )
2003-11-17 18:38:02 +00:00
sNewText += (f<iMeter) ? on : off;
for( f=NUM_FEET_IN_METER; f<MAX_FEET_IN_METER && f<iMeter; f++ )
sNewText += on;
2003-11-15 00:26:30 +00:00
m_textFeet.SetText( sNewText );
if( iMeter > GLOW_IF_METER_GREATER_THAN )
m_textFeet.SetEffectGlowShift();
else
m_textFeet.SetEffectNone();
2003-11-16 22:34:03 +00:00
if( FEET_IS_DIFFICULTY_COLOR )
m_textFeet.SetDiffuse( SONGMAN->GetDifficultyColor( dc ) );
2003-11-15 00:26:30 +00:00
}
if( SHOW_METER )
{
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
}
}
void DifficultyMeter::SetDifficulty( CString diff )
{
if( m_CurDifficulty == diff )
return;
m_CurDifficulty = diff;
if( SHOW_DIFFICULTY )
COMMAND( m_Difficulty, "Set" + Capitalize(diff) );
if( SHOW_METER )
COMMAND( m_textMeter, "Set" + Capitalize(diff) );
2002-11-16 08:54:15 +00:00
}