Files
itgmania212121/src/ScreenNameEntry.cpp
T

431 lines
14 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
#include "ScreenNameEntry.h"
#include "GameConstantsAndTypes.h"
#include "RageUtil.h"
#include "PrefsManager.h"
#include "GameManager.h"
#include "RageLog.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2006-10-20 07:45:36 +00:00
#include "GameState.h"
#include "ThemeManager.h"
2003-07-17 20:10:07 +00:00
#include "Course.h"
2003-11-01 07:25:22 +00:00
#include "AnnouncerManager.h"
#include "ProfileManager.h"
2005-07-01 05:07:22 +00:00
#include "Profile.h"
#include "StageStats.h"
#include "ScreenDimensions.h"
#include "PlayerState.h"
2005-01-15 02:01:26 +00:00
#include "Style.h"
#include "NoteSkinManager.h"
#include "InputEventPlus.h"
2006-10-20 07:45:36 +00:00
#include "InputMapper.h"
2006-10-20 04:32:46 +00:00
// used in TestScreen section
2006-10-21 06:02:22 +00:00
#include "SongManager.h"
#include "Song.h"
2006-10-21 06:02:22 +00:00
#include "StatsManager.h"
//
// Defines specific to ScreenNameEntry
//
2006-10-20 06:47:20 +00:00
#define CATEGORY_Y THEME->GetMetricF(m_sName,"CategoryY")
#define CATEGORY_ZOOM THEME->GetMetricF(m_sName,"CategoryZoom")
#define CHARS_ZOOM_SMALL THEME->GetMetricF(m_sName,"CharsZoomSmall")
#define CHARS_ZOOM_LARGE THEME->GetMetricF(m_sName,"CharsZoomLarge")
#define CHARS_SPACING_Y THEME->GetMetricF(m_sName,"CharsSpacingY")
#define SCROLLING_CHARS_COMMAND THEME->GetMetricA(m_sName,"ScrollingCharsCommand")
#define SELECTED_CHARS_COMMAND THEME->GetMetricA(m_sName,"SelectedCharsCommand")
#define GRAY_ARROWS_Y THEME->GetMetricF(m_sName,"ReceptorArrowsY")
#define NUM_CHARS_TO_DRAW_BEHIND THEME->GetMetricI(m_sName,"NumCharsToDrawBehind")
#define NUM_CHARS_TO_DRAW_TOTAL THEME->GetMetricI(m_sName,"NumCharsToDrawTotal")
#define FAKE_BEATS_PER_SEC THEME->GetMetricF(m_sName,"FakeBeatsPerSec")
2003-10-14 21:43:30 +00:00
#define MAX_RANKING_NAME_LENGTH THEME->GetMetricI(m_sName,"MaxRankingNameLength")
#define PLAYER_X( p, styleType ) THEME->GetMetricF(m_sName,ssprintf("PlayerP%d%sX",p+1,StyleTypeToString(styleType).c_str()))
2003-01-26 02:21:47 +00:00
// cache for frequently used metrics
2006-10-16 09:01:39 +00:00
static float g_fCharsZoomSmall;
static float g_fCharsZoomLarge;
static float g_fCharsSpacingY;
static float g_fReceptorArrowsY;
static int g_iNumCharsToDrawBehind;
static int g_iNumCharsToDrawTotal;
static float g_fFakeBeatsPerSec;
2003-01-26 02:21:47 +00:00
RString ScreenNameEntry::ScrollingText::g_sNameChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2003-01-26 02:21:47 +00:00
void ScreenNameEntry::ScrollingText::Init( const RString &sName, const vector<float> &xs )
2003-01-26 02:21:47 +00:00
{
SetName( sName );
m_Xs = xs;
m_bDone = false;
m_Stamp.LoadFromFont( THEME->GetPathF(sName, "letters") );
m_Stamp.RunCommands( THEME->GetMetricA(sName, "ScrollingCharsCommand") );
}
void ScreenNameEntry::ScrollingText::DrawPrimitives()
{
const float fFakeBeat = GAMESTATE->m_fSongBeat;
2007-01-03 05:05:28 +00:00
const size_t iClosestIndex = lrintf( fFakeBeat ) % g_sNameChars.size();
const float fClosestYOffset = GetClosestCharYOffset( fFakeBeat );
size_t iCharIndex = ( iClosestIndex - NUM_CHARS_TO_DRAW_BEHIND + g_sNameChars.size() ) % g_sNameChars.size();
float fY = GRAY_ARROWS_Y + ( fClosestYOffset - g_iNumCharsToDrawBehind ) * g_fCharsSpacingY;
for( int i = 0; i < NUM_CHARS_TO_DRAW_TOTAL; ++i )
{
const RString c = g_sNameChars.substr( iCharIndex, 1 );
float fZoom = g_fCharsZoomSmall;
float fAlpha = 1.f;
if( iCharIndex == iClosestIndex )
fZoom = SCALE( fabs(fClosestYOffset), 0, 0.5f, g_fCharsZoomLarge, g_fCharsZoomSmall );
if( i == 0 )
fAlpha *= SCALE( fClosestYOffset, -0.5f, 0.f, 0.f, 1.f );
if( i == g_iNumCharsToDrawTotal-1 )
fAlpha *= SCALE( fClosestYOffset, 0.f, 0.5f, 1.f, 0.f );
m_Stamp.SetZoom( fZoom );
m_Stamp.SetDiffuseAlpha( fAlpha );
m_Stamp.SetText( c );
m_Stamp.SetY( fY );
FOREACH_CONST( float, m_Xs, x )
{
m_Stamp.SetX( *x );
m_Stamp.Draw();
}
fY += g_fCharsSpacingY;
iCharIndex = (iCharIndex+1) % g_sNameChars.size();
}
}
char ScreenNameEntry::ScrollingText::GetClosestChar( float fFakeBeat ) const
2003-01-26 02:21:47 +00:00
{
ASSERT( fFakeBeat >= 0.f );
2007-01-03 05:05:28 +00:00
return g_sNameChars[lrintf(fFakeBeat) % g_sNameChars.size()];
}
2003-01-26 02:21:47 +00:00
// return value is relative to gray arrows
float ScreenNameEntry::ScrollingText::GetClosestCharYOffset( float fFakeBeat ) const
2003-01-26 02:21:47 +00:00
{
float f = fmodf(fFakeBeat, 1.0f);
if( f > 0.5f )
f -= 1;
2003-04-05 04:44:35 +00:00
ASSERT( f>-0.5f && f<=0.5f );
2003-01-26 02:21:47 +00:00
return -f;
}
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenNameEntry );
2006-10-21 06:02:22 +00:00
ScreenNameEntry::ScreenNameEntry()
{
if( PREFSMAN->m_sTestInitialScreen.Get() != "" )
2006-10-21 06:02:22 +00:00
{
GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
GAMESTATE->m_bSideIsJoined[PLAYER_2] = true;
GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
GAMESTATE->m_PlayMode.Set( PLAY_MODE_REGULAR );
GAMESTATE->SetCurrentStyle( GAMEMAN->GameAndStringToStyle( GAMEMAN->GetDefaultGame(),"versus") );
2006-10-21 06:02:22 +00:00
StageStats ss;
for( int z = 0; z < 3; ++z )
{
ss.m_vpPlayedSongs.push_back( SONGMAN->GetRandomSong() );
ss.m_vpPossibleSongs = ss.m_vpPlayedSongs;
ss.m_pStyle = GAMESTATE->GetCurrentStyle();
ss.m_playMode = GAMESTATE->m_PlayMode;
ASSERT( ss.m_vpPlayedSongs[0]->GetAllSteps().size() );
2006-10-21 06:02:22 +00:00
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
FOREACH_PlayerNumber( p )
{
Steps *pSteps = ss.m_vpPlayedSongs[0]->GetAllSteps()[0];
ss.m_player[p].m_iStepsPlayed = 1;
2006-10-21 06:02:22 +00:00
GAMESTATE->m_pCurSteps[p].Set( pSteps );
ss.m_player[p].m_iPossibleDancePoints = 100;
ss.m_player[p].m_iActualDancePoints = 100;
ss.m_player[p].m_iScore = 100;
ss.m_player[p].m_iPossibleDancePoints = 1000;
ss.m_player[p].m_iActualDancePoints = 985;
ss.m_player[p].m_vpPossibleSteps.push_back( pSteps );
2006-10-21 06:02:22 +00:00
HighScore hs;
hs.SetGrade( Grade_Tier03 );
hs.SetPercentDP( ss.m_player[p].GetPercentDancePoints() );
hs.SetScore( ss.m_player[p].m_iScore );
2006-10-21 06:02:22 +00:00
hs.SetDateTime( DateTime::GetNowDateTime() );
int a, b;
PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
2006-10-21 06:02:22 +00:00
PROFILEMAN->AddCategoryScore( st, RANKING_A, p, hs, a, b );
}
STATSMAN->m_vPlayedStageStats.push_back( ss );
}
}
}
2006-10-20 07:45:36 +00:00
void ScreenNameEntry::Init()
{
2006-10-20 07:27:19 +00:00
#if 0
2006-10-20 07:45:36 +00:00
// DEBUGGING STUFF
GAMESTATE->m_pCurGame.Set( GAMEMAN->GetDefaultGame() );
GAMESTATE->m_pCurStyle.Set( GAMEMAN->GetHowToPlayStyleForGame(GAMESTATE->m_pCurGame) );
2006-10-20 04:32:46 +00:00
GAMESTATE->m_PlayMode.Set( PLAY_MODE_REGULAR );
GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
#endif
2006-10-20 07:45:36 +00:00
2006-10-20 07:08:36 +00:00
ScreenWithMenuElements::Init();
2003-01-26 02:21:47 +00:00
2006-01-15 18:30:35 +00:00
// update cache
g_fCharsZoomSmall = CHARS_ZOOM_SMALL;
g_fCharsZoomLarge = CHARS_ZOOM_LARGE;
g_fCharsSpacingY = CHARS_SPACING_Y;
g_fReceptorArrowsY = GRAY_ARROWS_Y;
g_iNumCharsToDrawBehind = NUM_CHARS_TO_DRAW_BEHIND;
g_iNumCharsToDrawTotal = NUM_CHARS_TO_DRAW_TOTAL;
g_fFakeBeatsPerSec = FAKE_BEATS_PER_SEC;
2003-01-26 02:21:47 +00:00
2003-02-07 00:39:54 +00:00
// reset Player and Song Options
{
FOREACH_PlayerNumber( p )
PO_GROUP_CALL( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions, ModsLevel_Stage, Init );
SO_GROUP_CALL( GAMESTATE->m_SongOptions, ModsLevel_Stage, Init );
}
2003-01-27 02:00:38 +00:00
vector<GameState::RankingFeat> aFeats[NUM_PLAYERS];
// Find out if players deserve to enter their name
FOREACH_PlayerNumber( p )
{
2005-01-31 03:18:46 +00:00
GAMESTATE->GetRankingFeats( p, aFeats[p] );
2005-08-26 21:12:48 +00:00
GAMESTATE->JoinPlayer( p );
m_bStillEnteringName[p] = aFeats[p].size()>0;
2006-10-20 07:27:19 +00:00
#if 0 // Debugging.
2006-10-20 04:32:46 +00:00
m_bStillEnteringName[p] = p == PLAYER_1;
#endif
}
if( !AnyStillEntering() )
{
/* Nobody made a high score. */
2005-08-26 21:12:48 +00:00
PostScreenMessage( SM_GoToNextScreen, 0 );
return;
}
2003-01-27 02:00:38 +00:00
bool IsOnRanking = ( (GAMESTATE->m_PlayMode == PLAY_MODE_NONSTOP || GAMESTATE->m_PlayMode == PLAY_MODE_ONI)
&& !(GAMESTATE->m_pCurCourse->IsRanking()) );
2006-10-07 05:52:45 +00:00
if( PREFSMAN->m_GetRankingName == RANKING_OFF ||
(PREFSMAN->m_GetRankingName == RANKING_LIST && !IsOnRanking) )
{
// don't collect score due to ranking setting
2006-01-15 18:29:50 +00:00
PostScreenMessage( SM_GoToNextScreen, 0 );
return;
}
GAMESTATE->m_bGameplayLeadIn.Set( false ); // enable the gray arrows
2003-01-26 02:21:47 +00:00
FOREACH_PlayerNumber( p )
{
// load last used ranking name if any
2005-01-31 03:18:46 +00:00
Profile* pProfile = PROFILEMAN->GetProfile(p);
if( pProfile && !pProfile->m_sLastUsedHighScoreName.empty() )
m_sSelectedName[p] = pProfile->m_sLastUsedHighScoreName;
2003-01-26 02:21:47 +00:00
// resize string to MAX_RANKING_NAME_LENGTH
m_sSelectedName[p] = ssprintf( "%*.*s", MAX_RANKING_NAME_LENGTH, MAX_RANKING_NAME_LENGTH, m_sSelectedName[p].c_str() );
2003-11-12 01:28:47 +00:00
ASSERT( (int) m_sSelectedName[p].length() == MAX_RANKING_NAME_LENGTH );
// don't load player if they aren't going to enter their name
if( !m_bStillEnteringName[p] )
continue; // skip
// remove modifiers that may have been on the last song
PlayerOptions po;
GAMESTATE->GetDefaultPlayerOptions( po );
2006-08-05 04:47:01 +00:00
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.Assign( ModsLevel_Stage, po );
ASSERT( GAMESTATE->IsHumanPlayer(p) ); // they better be enabled if they made a high score!
const float fPlayerX = PLAYER_X( p, GAMESTATE->GetCurrentStyle()->m_StyleType );
{
LockNoteSkin l( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.GetCurrent().m_sNoteSkin );
m_ReceptorArrowRow[p].Load( GAMESTATE->m_pPlayerState[p], 0 );
m_ReceptorArrowRow[p].SetX( fPlayerX );
2006-10-16 08:42:54 +00:00
m_ReceptorArrowRow[p].SetY( GRAY_ARROWS_Y );
this->AddChild( &m_ReceptorArrowRow[p] );
}
2004-06-28 07:26:00 +00:00
const Style* pStyle = GAMESTATE->GetCurrentStyle();
const int iMaxCols = min( int(ABS_MAX_RANKING_NAME_LENGTH), pStyle->m_iColsPerPlayer );
2004-06-28 07:26:00 +00:00
m_ColToStringIndex[p].insert(m_ColToStringIndex[p].begin(), pStyle->m_iColsPerPlayer, -1);
int CurrentStringIndex = 0;
vector<float> xs;
for( int iCol=0; iCol<iMaxCols; ++iCol )
2003-01-26 02:21:47 +00:00
{
2006-10-16 07:18:03 +00:00
if( CurrentStringIndex == MAX_RANKING_NAME_LENGTH )
break; /* We have enough columns. */
/* Find out if this column is associated with the START menu button. */
2006-09-13 09:24:56 +00:00
GameInput gi = GAMESTATE->GetCurrentStyle()->StyleInputToGameInput( iCol, p );
2007-01-13 03:44:16 +00:00
GameButton mb = INPUTMAPPER->GameButtonToMenuButton( gi.button );
2008-05-21 05:36:09 +00:00
if( mb == GAME_BUTTON_START )
continue;
2006-09-13 09:24:56 +00:00
m_ColToStringIndex[p][iCol] = CurrentStringIndex++;
float ColX = fPlayerX + pStyle->m_ColumnInfo[p][iCol].fXOffset;
2006-10-20 06:47:20 +00:00
m_textSelectedChars[p][iCol].LoadFromFont( THEME->GetPathF(m_sName,"letters") );
2006-09-13 09:24:56 +00:00
m_textSelectedChars[p][iCol].SetX( ColX );
m_textSelectedChars[p][iCol].SetY( GRAY_ARROWS_Y );
m_textSelectedChars[p][iCol].RunCommands( SELECTED_CHARS_COMMAND );
m_textSelectedChars[p][iCol].SetZoom( CHARS_ZOOM_LARGE );
if( iCol < (int)m_sSelectedName[p].length() )
m_textSelectedChars[p][iCol].SetText( m_sSelectedName[p].substr(iCol,1) );
this->AddChild( &m_textSelectedChars[p][iCol] );
xs.push_back( ColX );
2003-01-26 02:21:47 +00:00
}
m_Text[p].Init( m_sName, xs );
this->AddChild( &m_Text[p] );
2003-01-26 02:21:47 +00:00
2006-10-20 06:47:20 +00:00
m_textCategory[p].LoadFromFont( THEME->GetPathF(m_sName,"category") );
m_textCategory[p].SetX( fPlayerX );
2003-01-26 02:21:47 +00:00
m_textCategory[p].SetY( CATEGORY_Y );
2003-10-19 21:38:11 +00:00
m_textCategory[p].SetZoom( CATEGORY_ZOOM );
2006-01-22 01:00:06 +00:00
RString joined;
for( unsigned j = 0; j < aFeats[p].size(); ++j )
{
if( j )
joined += "\n";
joined += aFeats[p][j].Feat;
}
m_textCategory[p].SetText( joined );
2003-01-26 02:21:47 +00:00
this->AddChild( &m_textCategory[p] );
}
2006-10-20 06:47:20 +00:00
m_soundStep.Load( THEME->GetPathS(m_sName,"step") );
2003-01-26 02:21:47 +00:00
m_fFakeBeat = 0;
}
bool ScreenNameEntry::AnyStillEntering() const
{
FOREACH_PlayerNumber( p )
if( m_bStillEnteringName[p] )
return true;
return false;
}
2003-01-26 02:21:47 +00:00
void ScreenNameEntry::Update( float fDelta )
{
2003-11-01 07:25:22 +00:00
if( m_bFirstUpdate )
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo("name entry") );
2003-01-26 02:21:47 +00:00
m_fFakeBeat += fDelta * FAKE_BEATS_PER_SEC;
GAMESTATE->m_fSongBeat = m_fFakeBeat;
2006-10-20 07:08:36 +00:00
ScreenWithMenuElements::Update(fDelta);
2003-01-26 02:21:47 +00:00
}
void ScreenNameEntry::Input( const InputEventPlus &input )
{
2006-10-20 07:08:36 +00:00
if( IsTransitioning() )
return;
2006-10-16 10:16:47 +00:00
if( input.type != IET_FIRST_PRESS || !input.GameI.IsValid() )
2003-01-26 02:21:47 +00:00
return; // ignore
2006-09-30 22:13:20 +00:00
const int iCol = GAMESTATE->GetCurrentStyle()->GameInputToColumn( input.GameI );
2006-10-07 04:25:28 +00:00
if( iCol != Column_Invalid && m_bStillEnteringName[input.pn] )
2003-01-26 02:21:47 +00:00
{
2006-09-13 10:11:36 +00:00
int iStringIndex = m_ColToStringIndex[input.pn][iCol];
if( iStringIndex != -1 )
2003-01-26 02:21:47 +00:00
{
2006-09-13 10:11:36 +00:00
m_ReceptorArrowRow[input.pn].Step( iCol, TNS_W1 );
2003-01-26 02:21:47 +00:00
m_soundStep.Play();
char c = m_Text[input.pn].GetClosestChar( m_fFakeBeat );
m_textSelectedChars[input.pn][iCol].SetText( RString(1, c) );
2006-09-13 10:11:36 +00:00
m_sSelectedName[input.pn][iStringIndex] = c;
2003-01-26 02:21:47 +00:00
}
}
2006-10-20 07:08:36 +00:00
ScreenWithMenuElements::Input( input );
}
void ScreenNameEntry::HandleScreenMessage( const ScreenMessage SM )
{
2006-02-24 00:20:41 +00:00
if( SM == SM_MenuTimer )
{
2006-10-20 07:08:36 +00:00
if( !IsTransitioning() )
2003-01-27 02:00:38 +00:00
{
2006-09-15 01:47:24 +00:00
InputEventPlus iep;
FOREACH_PlayerNumber( p )
2006-09-15 01:47:24 +00:00
{
iep.pn = p;
this->MenuStart( iep );
}
2003-01-27 02:00:38 +00:00
}
2006-02-24 00:20:41 +00:00
}
2005-07-12 05:38:13 +00:00
2006-10-20 07:08:36 +00:00
ScreenWithMenuElements::HandleScreenMessage( SM );
}
2003-01-27 02:00:38 +00:00
2006-09-15 01:47:24 +00:00
void ScreenNameEntry::MenuStart( const InputEventPlus &input )
2003-01-27 02:00:38 +00:00
{
2006-09-15 01:47:24 +00:00
PlayerNumber pn = input.pn;
if( !m_bStillEnteringName[pn] )
return;
m_bStillEnteringName[pn] = false;
m_Text[pn].SetDone();
2003-01-27 02:00:38 +00:00
m_soundStep.Play();
2003-01-27 02:00:38 +00:00
// save last used ranking name
Profile* pProfile = PROFILEMAN->GetProfile(pn);
pProfile->m_sLastUsedHighScoreName = m_sSelectedName[pn];
2007-12-01 23:33:38 +00:00
Trim( m_sSelectedName[pn], " " );
GAMESTATE->StoreRankingName( pn, m_sSelectedName[pn] );
if( !AnyStillEntering() && !m_Out.IsTransitioning() )
2006-10-20 07:08:36 +00:00
StartTransitioningScreen( SM_GoToNextScreen );
2003-01-27 02:00:38 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2001-2006 Chris Danford, Steve Checkoway
2004-06-08 05:22:33 +00:00
* 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.
*/