Files
itgmania212121/stepmania/src/ScreenNameEntry.cpp
T

433 lines
14 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
#include "ScreenNameEntry.h"
#include "SongManager.h"
#include "GameConstantsAndTypes.h"
#include "RageUtil.h"
#include "PrefsManager.h"
#include "GameManager.h"
#include "RageLog.h"
#include "GameState.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.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"
2004-07-25 17:07:32 +00:00
#include "Game.h"
#include "ScreenDimensions.h"
#include "PlayerState.h"
2005-01-15 02:01:26 +00:00
#include "Style.h"
#include "NoteSkinManager.h"
#include "InputEventPlus.h"
//
// Defines specific to ScreenNameEntry
//
2006-10-16 07:18:03 +00:00
#define TIMER_X THEME->GetMetricF("ScreenNameEntry","TimerX")
#define TIMER_Y THEME->GetMetricF("ScreenNameEntry","TimerY")
#define CATEGORY_Y THEME->GetMetricF("ScreenNameEntry","CategoryY")
#define CATEGORY_ZOOM THEME->GetMetricF("ScreenNameEntry","CategoryZoom")
#define CHARS_ZOOM_SMALL THEME->GetMetricF("ScreenNameEntry","CharsZoomSmall")
#define CHARS_ZOOM_LARGE THEME->GetMetricF("ScreenNameEntry","CharsZoomLarge")
#define CHARS_SPACING_Y THEME->GetMetricF("ScreenNameEntry","CharsSpacingY")
2005-08-26 21:12:48 +00:00
#define SCROLLING_CHARS_COMMAND THEME->GetMetricA("ScreenNameEntry","ScrollingCharsCommand")
#define SELECTED_CHARS_COMMAND THEME->GetMetricA("ScreenNameEntry","SelectedCharsCommand")
2006-10-16 07:18:03 +00:00
#define GRAY_ARROWS_Y THEME->GetMetricF("ScreenNameEntry","ReceptorArrowsY")
2003-01-26 02:21:47 +00:00
#define NUM_CHARS_TO_DRAW_BEHIND THEME->GetMetricI("ScreenNameEntry","NumCharsToDrawBehind")
#define NUM_CHARS_TO_DRAW_TOTAL THEME->GetMetricI("ScreenNameEntry","NumCharsToDrawTotal")
2006-10-16 07:18:03 +00:00
#define FAKE_BEATS_PER_SEC THEME->GetMetricF("ScreenNameEntry","FakeBeatsPerSec")
#define TIMER_SECONDS THEME->GetMetricF("ScreenNameEntry","TimerSeconds")
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
2006-10-16 09:01:39 +00:00
static const char NAME_CHARS[] =
2003-01-26 02:21:47 +00:00
{
' ',' ',' ',' ','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
};
2006-09-13 03:11:38 +00:00
#define NUM_NAME_CHARS (ARRAYLEN(NAME_CHARS))
2006-10-16 07:18:03 +00:00
#define HEIGHT_OF_ALL_CHARS (NUM_NAME_CHARS * g_fCharsSpacingY)
2006-10-16 07:30:25 +00:00
static int GetClosestCharIndex( float fFakeBeat )
2003-01-26 02:21:47 +00:00
{
int iCharIndex = (int)roundf(fFakeBeat) % NUM_NAME_CHARS;
ASSERT( iCharIndex >= 0 );
return iCharIndex;
}
2003-01-26 02:21:47 +00:00
// return value is relative to gray arrows
2006-10-16 07:30:25 +00:00
static float GetClosestCharYOffset( float fFakeBeat )
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;
}
// return value is relative to gray arrows
2006-10-16 07:30:25 +00:00
static float GetClosestCharYPos( float fFakeBeat )
2003-01-26 02:21:47 +00:00
{
2003-04-16 06:13:47 +00:00
return GetClosestCharYOffset(fFakeBeat)*g_fCharsSpacingY;
2003-01-26 02:21:47 +00:00
}
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenNameEntry );
2006-01-15 18:37:57 +00:00
ScreenNameEntry::ScreenNameEntry()
{
2003-01-27 02:00:38 +00:00
// DEBUGGING STUFF
2003-01-26 07:33:03 +00:00
// GAMESTATE->m_CurGame = GAME_DANCE;
// GAMESTATE->m_CurStyle = STYLE_DANCE_SINGLE;
// GAMESTATE->m_PlayMode = PLAY_MODE_REGULAR;
2003-01-26 07:33:03 +00:00
// GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
// GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
// GAMESTATE->m_RankingCategory[PLAYER_1] = RANKING_A;
// GAMESTATE->m_iRankingIndex[PLAYER_1] = 0;
2006-01-15 18:30:35 +00:00
}
void ScreenNameEntry::Init()
{
Screen::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;
}
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!
2006-10-16 10:16:47 +00:00
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();
2004-06-28 07:26:00 +00:00
m_ColToStringIndex[p].insert(m_ColToStringIndex[p].begin(), pStyle->m_iColsPerPlayer, -1);
int CurrentStringIndex = 0;
2006-09-13 09:24:56 +00:00
for( int iCol=0; iCol<pStyle->m_iColsPerPlayer; 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 );
2006-09-30 08:22:36 +00:00
MenuButton mb = INPUTMAPPER->GameToMenu( gi );
2006-09-14 04:11:29 +00:00
if( mb == MENU_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;
m_textSelectedChars[p][iCol].LoadFromFont( THEME->GetPathF("ScreenNameEntry","letters") );
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] ); // draw these manually
2003-01-26 02:21:47 +00:00
2006-09-13 09:24:56 +00:00
m_textScrollingChars[p][iCol].LoadFromFont( THEME->GetPathF("ScreenNameEntry","letters") );
m_textScrollingChars[p][iCol].SetX( ColX );
m_textScrollingChars[p][iCol].SetY( GRAY_ARROWS_Y );
m_textScrollingChars[p][iCol].RunCommands( SCROLLING_CHARS_COMMAND );
2006-10-16 10:16:47 +00:00
this->AddChild( &m_textScrollingChars[p][iCol] ); // draw these manually
2003-01-26 02:21:47 +00:00
}
2005-02-06 03:32:53 +00:00
m_textCategory[p].LoadFromFont( THEME->GetPathF("ScreenNameEntry","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] );
}
2003-01-27 02:00:38 +00:00
m_Timer.Load();
2003-02-10 22:13:31 +00:00
if( !PREFSMAN->m_bMenuTimer )
2003-03-11 21:33:11 +00:00
m_Timer.Disable();
2003-02-10 22:13:31 +00:00
else
2003-03-11 21:33:11 +00:00
m_Timer.SetSeconds(TIMER_SECONDS);
2003-01-26 02:21:47 +00:00
m_Timer.SetXY( TIMER_X, TIMER_Y );
this->AddChild( &m_Timer );
2005-02-06 03:32:53 +00:00
m_In.Load( THEME->GetPathB("ScreenNameEntry","in") );
m_In.StartTransitioning();
2005-07-11 22:25:29 +00:00
m_In.SetDrawOrder( DRAW_ORDER_TRANSITIONS );
this->AddChild( &m_In );
2005-02-06 03:32:53 +00:00
m_Out.Load( THEME->GetPathB("ScreenNameEntry","out") );
2005-07-11 22:25:29 +00:00
m_Out.SetDrawOrder( DRAW_ORDER_TRANSITIONS );
this->AddChild( &m_Out );
this->SortByDrawOrder();
2003-01-26 02:21:47 +00:00
2005-02-06 03:32:53 +00:00
m_soundStep.Load( THEME->GetPathS("ScreenNameEntry","step") );
2006-10-16 09:31:28 +00:00
m_sPathToMusic = THEME->GetPathS( m_sName, "music" );
2003-01-26 02:21:47 +00:00
m_fFakeBeat = 0;
}
2006-10-16 09:31:28 +00:00
void ScreenNameEntry::BeginScreen()
{
SOUND->PlayMusic( m_sPathToMusic );
}
void ScreenNameEntry::EndScreen()
{
SOUND->StopMusic();
}
bool ScreenNameEntry::AnyStillEntering() const
{
FOREACH_PlayerNumber( p )
if( m_bStillEnteringName[p] )
return true;
return false;
}
ScreenNameEntry::~ScreenNameEntry()
{
LOG->Trace( "ScreenNameEntry::~ScreenNameEntry()" );
}
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;
2005-07-11 22:25:29 +00:00
Screen::Update(fDelta);
2003-01-26 02:21:47 +00:00
}
void ScreenNameEntry::DrawPrimitives()
{
Screen::DrawPrimitives();
2003-01-26 02:21:47 +00:00
int iClosestIndex = GetClosestCharIndex( m_fFakeBeat );
int iStartDrawingIndex = iClosestIndex - NUM_CHARS_TO_DRAW_BEHIND;
iStartDrawingIndex += NUM_NAME_CHARS; // make positive
2004-06-28 07:26:00 +00:00
const Style* pStyle = GAMESTATE->GetCurrentStyle();
2003-01-26 02:21:47 +00:00
FOREACH_PlayerNumber( p )
2003-01-26 02:21:47 +00:00
{
2003-01-27 02:00:38 +00:00
if( !m_bStillEnteringName[p] )
continue; // don't draw scrolling arrows
2003-01-26 02:21:47 +00:00
float fY = GRAY_ARROWS_Y + GetClosestCharYPos(m_fFakeBeat) - g_iNumCharsToDrawBehind*g_fCharsSpacingY;
int iCharIndex = iStartDrawingIndex % NUM_NAME_CHARS;
2003-01-26 02:21:47 +00:00
for( int i=0; i<NUM_CHARS_TO_DRAW_TOTAL; i++ )
{
char c = NAME_CHARS[iCharIndex];
2004-06-28 07:26:00 +00:00
for( int t=0; t<pStyle->m_iColsPerPlayer; t++ )
2003-01-26 02:21:47 +00:00
{
2006-10-16 07:18:03 +00:00
if( m_ColToStringIndex[p][t] == -1 )
continue;
2006-10-16 08:44:12 +00:00
m_textScrollingChars[p][t].SetText( RString(1, c) );
2003-01-26 02:21:47 +00:00
m_textScrollingChars[p][t].SetY( fY );
float fZoom = g_fCharsZoomSmall;
if( iCharIndex==iClosestIndex )
fZoom = SCALE(fabsf(GetClosestCharYOffset(m_fFakeBeat)),0,0.5f,g_fCharsZoomLarge,g_fCharsZoomSmall);
m_textScrollingChars[p][t].SetZoom(fZoom);
2006-01-15 18:28:16 +00:00
float fAlpha = 1;
2003-01-26 02:21:47 +00:00
if( i==0 )
2005-08-26 21:12:48 +00:00
fAlpha *= SCALE(GetClosestCharYOffset(m_fFakeBeat),-0.5f,0.f,0.f,1.f);
2003-01-26 02:21:47 +00:00
if( i==g_iNumCharsToDrawTotal-1 )
2005-08-26 21:12:48 +00:00
fAlpha *= SCALE(GetClosestCharYOffset(m_fFakeBeat),0.f,0.5f,1.f,0.f);
m_textScrollingChars[p][t].SetDiffuseAlpha( fAlpha );
2006-10-16 10:16:47 +00:00
//m_textScrollingChars[p][t].Draw();
2003-01-26 02:21:47 +00:00
}
fY += g_fCharsSpacingY;
iCharIndex = (iCharIndex+1) % NUM_NAME_CHARS;
}
}
}
void ScreenNameEntry::Input( const InputEventPlus &input )
{
LOG->Trace( "ScreenNameEntry::Input()" );
if( m_In.IsTransitioning() || m_Out.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();
2003-01-27 02:00:38 +00:00
char c = NAME_CHARS[GetClosestCharIndex(m_fFakeBeat)];
2006-09-13 10:11:36 +00:00
m_textSelectedChars[input.pn][iCol].SetText( ssprintf("%c",c) );
m_sSelectedName[input.pn][iStringIndex] = c;
2003-01-26 02:21:47 +00:00
}
}
Screen::Input( input );
}
void ScreenNameEntry::HandleScreenMessage( const ScreenMessage SM )
{
2006-02-24 00:20:41 +00:00
if( SM == SM_MenuTimer )
{
if( !m_Out.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
Screen::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;
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];
TrimRight( m_sSelectedName[pn], " " );
TrimLeft( m_sSelectedName[pn], " " );
GAMESTATE->StoreRankingName( pn, m_sSelectedName[pn] );
if( !AnyStillEntering() && !m_Out.IsTransitioning() )
m_Out.StartTransitioning( SM_GoToNextScreen );
2003-01-27 02:00:38 +00:00
}
2004-06-08 05:22:33 +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.
*/