From 5884467e6ae8b1d5a47be590ef10b1a2e07b6a37 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 16 Mar 2007 21:14:00 +0000 Subject: [PATCH] major refactoring. Puts most control of actual input mechanics in Lua. --- stepmania/src/ScreenNameEntryTraditional.cpp | 794 +++++-------------- stepmania/src/ScreenNameEntryTraditional.h | 111 +-- 2 files changed, 218 insertions(+), 687 deletions(-) diff --git a/stepmania/src/ScreenNameEntryTraditional.cpp b/stepmania/src/ScreenNameEntryTraditional.cpp index e650be0245..2e01323e01 100644 --- a/stepmania/src/ScreenNameEntryTraditional.cpp +++ b/stepmania/src/ScreenNameEntryTraditional.cpp @@ -1,138 +1,24 @@ #include "global.h" #include "ScreenNameEntryTraditional.h" -#include "SongManager.h" -#include "GameConstantsAndTypes.h" -#include "RageUtil.h" #include "PrefsManager.h" -#include "GameManager.h" -#include "RageLog.h" #include "GameState.h" -#include "GameSoundManager.h" -#include "ThemeManager.h" -#include "Course.h" -#include "ActorUtil.h" -#include "FontCharAliases.h" -#include "AnnouncerManager.h" -#include "song.h" -#include "Steps.h" +#include "GameManager.h" +#include "StatsManager.h" +#include "SongManager.h" +#include "Song.h" +#include "Style.h" #include "ProfileManager.h" #include "Profile.h" -#include "StatsManager.h" -#include "Foreach.h" -#include "Style.h" -#include "ScreenDimensions.h" #include "InputEventPlus.h" #include "RageInput.h" - -// -// Defines specific to ScreenNameEntryTraditional -// - -#define COMMAND_OPTIONAL( actor, command_name ) \ - if( !(actor).GetName().empty() ) \ - COMMAND( (actor), command_name ); - -AutoScreenMessage( SM_ChangeDisplayedFeat ) - -static const int CHAR_OK = -1; -static const int CHAR_BACK = -2; - - -void HighScoreWheelItem::Load( int iRankIndex, const HighScore& hs ) -{ - SetName( "HighScoreWheelItem" ); - - m_textRank.SetName( "Rank" ); - m_textRank.LoadFromFont( THEME->GetPathF(m_sName,"rank") ); - m_textRank.SetText( ssprintf("%d", iRankIndex+1) ); - m_textRank.SetShadowLength( 2 ); - this->AddChild( &m_textRank ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_textRank ); - - m_textName.SetName( "Name" ); - m_textName.LoadFromFont( THEME->GetPathF(m_sName,"name") ); - m_textName.SetText( hs.GetDisplayName() ); - m_textName.SetShadowLength( 2 ); - this->AddChild( &m_textName ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_textName ); - - m_textScore.SetName( "Score" ); - m_textScore.LoadFromFont( THEME->GetPathF(m_sName,"score") ); - if( PREFSMAN->m_bPercentageScoring ) - m_textScore.SetText( PercentageDisplay::FormatPercentScore(hs.GetPercentDP()) ); - else - m_textScore.SetText( ssprintf("%i", hs.GetScore()) ); - m_textScore.SetShadowLength( 2 ); - this->AddChild( &m_textScore ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_textScore ); - - m_textDate.SetName( "Date" ); - m_textDate.LoadFromFont( THEME->GetPathF(m_sName,"date") ); - m_textDate.SetText( ssprintf("%02d/%02d", hs.GetDateTime().tm_mon+1, hs.GetDateTime().tm_mday) ); - m_textDate.SetShadowLength( 2 ); - this->AddChild( &m_textDate ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_textDate ); -} - -void HighScoreWheelItem::LoadBlank( int iRankIndex ) -{ - HighScore hs; - Load( iRankIndex, hs ); -} - -void HighScoreWheelItem::ShowFocus() -{ - apActorCommands c = ActorUtil::ParseActorCommands( "diffuseshift;EffectColor1,1,1,0,1;EffectColor2,0,1,1,1" ); - m_textRank.RunCommands( c ); - m_textName.RunCommands( c ); - m_textScore.RunCommands( c ); - m_textDate.RunCommands( c ); -} - -void HighScoreWheel::Load( const HighScoreList& hsl, int iIndexToFocus ) -{ - m_Items.resize( PREFSMAN->m_iMaxHighScoresPerListForMachine ); - for( int i=0; im_iMaxHighScoresPerListForMachine; i++ ) - { - if( unsigned(i) < hsl.vHighScores.size() ) - m_Items[i].Load( i, hsl.vHighScores[i] ); - else - m_Items[i].LoadBlank( i ); - this->AddChild( &m_Items[i] ); - } - m_iIndexToFocus = iIndexToFocus; - - if( m_iIndexToFocus >= 0 && m_iIndexToFocus < int(hsl.vHighScores.size()) ) - m_Items[m_iIndexToFocus].ShowFocus(); - - RString sTransformFunction = - "function(self,offset,itemIndex,numItems) " - " local degrees=18*offset; " - " local radians=degrees*math.pi/180; " - " self:rotationx(degrees); " - " self:y(math.sin(radians)*90); " - " self:z(math.cos(radians)*90); " - "end"; - LuaReference ref; - ref.SetFromExpression( sTransformFunction ); - - ActorScroller::SetNumItemsToDraw( 10.5f ); - ActorScroller::Load2(); - ActorScroller::SetTransformFromReference( ref ); - ActorScroller::SetSecondsPerItem( 0.2f ); - Scroll(); -} - -float HighScoreWheel::Scroll() -{ - SetCurrentAndDestinationItem( m_SubActors.size()+5.0f ); - int iIndexToFocus = max( m_iIndexToFocus, 3 ); - SetDestinationItem( (float)iIndexToFocus ); - return GetTweenTimeLeft(); -} +#include "RageLog.h" REGISTER_SCREEN_CLASS( ScreenNameEntryTraditional ); -ScreenNameEntryTraditional::ScreenNameEntryTraditional() + +#define CODE_NAMES THEME->GetMetric (m_sName,"CodeNames") +#define CODE( s ) THEME->GetMetric (m_sName,ssprintf("Code%s",s.c_str())) + +void ScreenNameEntryTraditional::Init() { if( PREFSMAN->m_bScreenTestMode ) { @@ -141,10 +27,11 @@ ScreenNameEntryTraditional::ScreenNameEntryTraditional() GAMESTATE->m_MasterPlayerNumber = PLAYER_1; GAMESTATE->m_PlayMode.Set( PLAY_MODE_REGULAR ); GAMESTATE->SetCurrentStyle( GAMEMAN->GameAndStringToStyle( GAMEMAN->GetDefaultGame(),"versus") ); - StageStats ss; for( int z = 0; z < 3; ++z ) { - ss.m_vpPlayedSongs.push_back( SONGMAN->GetRandomSong() ); + StageStats ss; + const vector &apSongs = SONGMAN->GetAllSongs(); + ss.m_vpPlayedSongs.push_back( apSongs[rand()%apSongs.size()] ); ss.m_vpPossibleSongs = ss.m_vpPlayedSongs; ss.m_pStyle = GAMESTATE->GetCurrentStyle(); ss.m_playMode = GAMESTATE->m_PlayMode; @@ -181,320 +68,99 @@ ScreenNameEntryTraditional::ScreenNameEntryTraditional() } } -} -void ScreenNameEntryTraditional::Init() -{ - ALPHABET_GAP_X.Load( m_sName, "AlphabetGapX" ); - NUM_ALPHABET_DISPLAYED.Load( m_sName, "NumAlphabetDisplayed" ); MAX_RANKING_NAME_LENGTH.Load( m_sName, "MaxRankingNameLength" ); - FEAT_INTERVAL.Load( m_sName, "FeatInterval" ); - KEYBOARD_LETTERS.Load( m_sName, "KeyboardLetters" ); + + // + // Load codes + // + { + split( CODE_NAMES, ",", m_asCodeNames, true ); + + for( unsigned c=0; c aFeats; - GAMESTATE->GetRankingFeats( p, aFeats ); - m_bStillEnteringName[p] = aFeats.size()>0; - m_CurFeat[p] = 0; + GAMESTATE->GetRankingFeats( pn, aFeats ); + m_bEnteringName[pn] = aFeats.size()>0; + for( int i = 0; i < (int) aFeats.size(); ++i ) + { + LOG->Trace( "%i: %i: %s", + pn, i, aFeats[i].Feat.c_str() ); + } + m_bFinalized[pn] = !m_bEnteringName[pn]; } - // - // init keyboards - // - FOREACH_HumanPlayer( p ) + FOREACH_HumanPlayer( pn ) { - // don't show keyboard if didn't make any high scores - if( !m_bStillEnteringName[p] ) - { - m_sprOutOfRanking[p].Load( THEME->GetPathG( m_sName,ssprintf("OutOfRankingP%i",p+1)) ); - m_sprOutOfRanking[p]->SetName( ssprintf("OutOfRankingP%i",p+1) ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_sprOutOfRanking[p] ); - this->AddChild( m_sprOutOfRanking[p] ); - + if( !m_bEnteringName[pn] ) continue; // skip - } - m_sprNameFrame[p].Load( THEME->GetPathG(m_sName,ssprintf("name frame p%i",p+1)) ); - m_sprNameFrame[p]->SetName( ssprintf("EntryFrameP%i",p+1) ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_sprNameFrame[p] ); - this->AddChild( m_sprNameFrame[p] ); - - m_Keyboard[p].SetName( ssprintf("KeyboardP%i",p+1) ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_Keyboard[p] ); - this->AddChild( &m_Keyboard[p] ); - - /* Add letters to m_Keyboard. */ - const RString sFontPath = THEME->GetPathF(m_sName,"letters"); - const wstring sChars = RStringToWstring(KEYBOARD_LETTERS); - - BitmapText *pLetterTemplate = new BitmapText; - pLetterTemplate->SetName( "Letter" ); - pLetterTemplate->LoadFromFont( sFontPath ); - ActorUtil::LoadAllCommands( *pLetterTemplate, m_sName ); - pLetterTemplate->PlayCommand( "AlphabetInit" ); - for( unsigned ch = 0; ch < sChars.size(); ++ch ) - { - BitmapText *pLetter = new BitmapText( *pLetterTemplate ); - pLetter->SetText( ssprintf("%lc", sChars[ch]) ); - m_textAlphabet[p].push_back( pLetter ); - m_Keyboard[p].AddChild( pLetter ); - - m_AlphabetLetter[p].push_back( sChars[ch] ); - } - delete pLetterTemplate; - - /* Add "<-". */ - { - BitmapText *pLetter = new BitmapText; - pLetter->SetName( ssprintf("LetterP%i",p+1) ); - ActorUtil::LoadAllCommands( *pLetter, m_sName ); - pLetter->LoadFromFont( sFontPath ); - RString sText = "←"; - FontCharAliases::ReplaceMarkers( sText ); - pLetter->SetText( sText ); - pLetter->PlayCommand( "OKInit" ); - m_textAlphabet[p].push_back( pLetter ); - m_Keyboard[p].AddChild( pLetter ); - - m_AlphabetLetter[p].push_back( CHAR_BACK ); - } - - /* Add "OK". */ - { - BitmapText *pLetter = new BitmapText; - pLetter->SetName( ssprintf("LetterP%i",p+1) ); - ActorUtil::LoadAllCommands( *pLetter, m_sName ); - pLetter->LoadFromFont( sFontPath ); - RString sText = "&ok;"; - FontCharAliases::ReplaceMarkers( sText ); - pLetter->SetText( sText ); - pLetter->PlayCommand( "OKInit" ); - m_textAlphabet[p].push_back( pLetter ); - m_Keyboard[p].AddChild( pLetter ); - - m_AlphabetLetter[p].push_back( CHAR_OK ); - } - - m_sprCursor[p].SetName( ssprintf("CursorP%i",p+1) ); - m_sprCursor[p].Load( THEME->GetPathG(m_sName,ssprintf("cursor p%i",p+1)) ); - m_Keyboard[p].AddChild( &m_sprCursor[p] ); - - m_textSelection[p].SetName( ssprintf("SelectionP%i",p+1) ); - m_textSelection[p].LoadFromFont( THEME->GetPathF(m_sName,"entry") ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_textSelection[p] ); - this->AddChild( &m_textSelection[p] ); - - m_SelectedChar[p] = 0; - PositionCharsAndCursor( p ); + m_sSelection[pn] = L""; // load last used ranking name if any - const Profile* pProfile = PROFILEMAN->GetProfile(p); + const Profile *pProfile = PROFILEMAN->GetProfile(pn); if( pProfile && !pProfile->m_sLastUsedHighScoreName.empty() ) { - m_sSelection[p] = RStringToWstring( pProfile->m_sLastUsedHighScoreName ); - if( (int) m_sSelection[p].size() > MAX_RANKING_NAME_LENGTH ) - m_sSelection[p].erase( MAX_RANKING_NAME_LENGTH ); - ASSERT( (int) m_sSelection[p].size() <= MAX_RANKING_NAME_LENGTH ); - if( m_sSelection[p].size() ) - SelectChar( p, CHAR_OK, false ); + m_sSelection[pn] = RStringToWstring( pProfile->m_sLastUsedHighScoreName ); + if( (int) m_sSelection[pn].size() > MAX_RANKING_NAME_LENGTH ) + m_sSelection[pn].erase( MAX_RANKING_NAME_LENGTH ); + if( m_sSelection[pn].size() ) + SelectChar( pn, "ENTER" ); } - UpdateSelectionText( p ); - - /* Don't tween to the initial position. */ - for( unsigned i = 0; i < m_textAlphabet[p].size(); ++i ) - m_textAlphabet[p][i]->FinishTweening(); + UpdateSelectionText( pn ); } - // - // init feat displays - // - FOREACH_HumanPlayer( p ) + ScreenWithMenuElements::BeginScreen(); +} + +void ScreenNameEntryTraditional::HandleScreenMessage( const ScreenMessage SM ) +{ + if( SM == SM_MenuTimer ) { - /* Show feat 0, hide others without tweening. Run the ON command for - * all actors, even if we're going to hide it anyway, so any style commands - * are run. */ -#define SET_ON( actor ) \ - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( actor ); \ - if( m_FeatDisplay[p].size()>1 ) \ - { \ - (actor).FinishTweening(); \ - COMMAND( actor, "Hide" ); \ - (actor).FinishTweening(); \ - } - - m_FeatDisplay[p].reserve( STATSMAN->m_vPlayedStageStats.size() ); - - for( unsigned i = 0; i < STATSMAN->m_vPlayedStageStats.size(); ++i ) + if( !m_Out.IsTransitioning() ) { - StageStats &ss = STATSMAN->m_vPlayedStageStats[i]; - Song* pSong = ss.m_vpPlayedSongs[0]; - Steps* pSteps = ss.m_player[p].m_vpPlayedSteps[0]; - Course* pCourse = GAMESTATE->m_pCurCourse; - Trail* pTrail = GAMESTATE->m_pCurTrail[p]; - - int iHighScoreIndex = -1; // -1 means "out of ranking" - Grade grade = ss.m_player[p].GetGrade(); - int iScore = ss.m_player[p].m_iScore; - float fPercentDP = ss.m_player[p].GetPercentDancePoints(); - - // If this is a SHOW_NEVER song, then it's probably a training. - // Don't show a high score - if( pSong->m_SelectionDisplay == Song::SHOW_NEVER ) - continue; // skip - - m_FeatDisplay[p].resize( m_FeatDisplay[p].size()+1 ); - FeatDisplay &display = m_FeatDisplay[p].back(); - - const HighScoreList& hsl = - GAMESTATE->IsCourseMode() ? - PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail) : - PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps); - - for( int h=0; h<(int)hsl.vHighScores.size() && hm_iMaxHighScoresPerListForMachine; h++ ) - { - const HighScore &hs = hsl.vHighScores[h]; - if( hs.GetName() == RANKING_TO_FILL_IN_MARKER[p] && - hs.GetPercentDP() == fPercentDP && - hs.GetScore() == iScore ) - { - iHighScoreIndex = h; - break; - } - } - - display.m_Wheel.SetName( ssprintf("WheelP%i",p+1) ); - display.m_Wheel.Load( hsl, iHighScoreIndex ); - SET_ON( display.m_Wheel ); - this->AddChild( &display.m_Wheel ); - - RString sBanner; - if( GAMESTATE->IsCourseMode() ) - sBanner = pCourse->m_sBannerPath; - else - sBanner = pSong->GetBannerPath(); - - if( !sBanner.empty() ) - { - display.m_sprBanner.SetName( ssprintf("BannerP%i",p+1) ); - display.m_sprBanner.Load( sBanner ); - SET_ON( display.m_sprBanner ); - this->AddChild( &display.m_sprBanner ); - } - - if( grade != Grade_NoData ) - { - display.m_Grade.SetName( ssprintf("GradeP%i",p+1) ); - display.m_Grade.Load( THEME->GetPathG(m_sName,"grades") ); - display.m_Grade.SetGrade( p, grade ); - SET_ON( display.m_Grade ); - this->AddChild( &display.m_Grade ); - } - - display.m_DifficultyIcon.Load( THEME->GetPathG(m_sName,"DifficultyIcon") ); - if( GAMESTATE->IsCourseMode() ) - display.m_DifficultyIcon.SetFromTrail( p, pTrail ); - else - display.m_DifficultyIcon.SetFromSteps( p, pSteps ); - display.m_DifficultyIcon.SetName( ssprintf("DifficultyIconP%i",p+1) ); - SET_ON( display.m_DifficultyIcon ); - this->AddChild( &display.m_DifficultyIcon ); - - display.m_DifficultyMeter.Load( m_sName+ssprintf(" DifficultyMeterP%d",p+1) ); - if( GAMESTATE->IsCourseMode() ) - display.m_DifficultyMeter.SetFromTrail( pTrail ); - else - display.m_DifficultyMeter.SetFromSteps( pSteps ); - display.m_DifficultyMeter.SetName( ssprintf("DifficultyMeterP%i",p+1) ); - SET_ON( display.m_DifficultyMeter ); - this->AddChild( &display.m_DifficultyMeter ); - - display.m_textScore.Load( GAMESTATE->m_pPlayerState[p], &ss.m_player[p], "ScreenNameEntryTraditional Percent", false ); - display.m_textScore.SetName( ssprintf("ScoreP%i",p+1) ); - SET_ON( display.m_textScore ); - this->AddChild( &display.m_textScore ); - - /* We always show the banner frame (if any), because fading from a graphic to - * itself is ugly. */ - display.m_sprBannerFrame.Load( THEME->GetPathG(m_sName,ssprintf("banner frame p%i",p+1)) ); - display.m_sprBannerFrame->SetName( ssprintf("BannerFrameP%i",p+1) ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( display.m_sprBannerFrame ); - this->AddChild( display.m_sprBannerFrame ); + Message msg("MenuTimerExpired"); + this->HandleMessage( msg ); } -#undef SET_ON + return; } - this->PostScreenMessage( SM_ChangeDisplayedFeat, FEAT_INTERVAL ); - - m_soundKey.Load( THEME->GetPathS(m_sName,"key") ); - m_soundChange.Load( THEME->GetPathS(m_sName,"change",true) ); - m_soundInvalid.Load( THEME->GetPathS(m_sName,"invalid",true) ); - - this->SortByDrawOrder(); -} - -static inline int wrapn( int x, int n ) -{ - wrap( x, n ); - return x; -} - -void ScreenNameEntryTraditional::PositionCharsAndCursor( int pn ) -{ - const int iSelected = m_SelectedChar[pn]; - const int iNumDisplayed = NUM_ALPHABET_DISPLAYED; - - const int iTotalDisplayed = (int)m_textAlphabet[pn].size(); - const int iStart = wrapn( iSelected - iTotalDisplayed/2, iTotalDisplayed ); - - const int iFirst = -iNumDisplayed/2; - const int iLast = iNumDisplayed/2; - for( int i = 0; i < (int)m_textAlphabet[pn].size(); ++i ) - { - const int iNum = wrapn( iStart+i, (int) m_textAlphabet[pn].size() ); - BitmapText *bt = m_textAlphabet[pn][iNum]; - - const int iPos = i - iTotalDisplayed/2; - const bool bHidden = ( iPos < iFirst || iPos > iLast ); - const int iActualPos = clamp( iPos, iFirst-1, iLast+1 ); - - bt->PlayCommand( "Change" ); - bt->SetX( iActualPos * ALPHABET_GAP_X ); - bt->SetDiffuseAlpha( bHidden? 0.0f:1.0f ); - } - - m_sprCursor[pn].SetXY( 0,0 ); + ScreenWithMenuElements::HandleScreenMessage( SM ); } bool ScreenNameEntryTraditional::AnyStillEntering() const { - FOREACH_PlayerNumber( p ) - if( m_bStillEnteringName[p] ) + FOREACH_PlayerNumber( pn ) + if( !m_bFinalized[pn] ) return true; return false; } -ScreenNameEntryTraditional::~ScreenNameEntryTraditional() +bool ScreenNameEntryTraditional::AnyEntering() const { - LOG->Trace( "ScreenNameEntryTraditional::~ScreenNameEntryTraditional()" ); - - for( int p=0; pPlayOnceFromDir( ANNOUNCER->GetPathTo("name entry") ); - - ScreenWithMenuElements::Update(fDelta); + FOREACH_PlayerNumber( pn ) + if( m_bEnteringName[pn] ) + return true; + return false; } void ScreenNameEntryTraditional::Input( const InputEventPlus &input ) @@ -502,102 +168,33 @@ void ScreenNameEntryTraditional::Input( const InputEventPlus &input ) if( IsTransitioning() ) return; - - if( input.type == IET_FIRST_PRESS ) + for( unsigned i = 0; i < m_aCodes.size(); ++i ) { - int c; - if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_BACK) ) - { - c = CHAR_BACK; - } - else - { - wchar_t ch = INPUTMAN->DeviceInputToChar(input.DeviceI,true); - MakeUpper( &ch, 1 ); - c = ch; - } + if( !m_aCodes[i].EnteredCode(input.GameI.controller) ) + continue; - if( c ) - { - PlayerNumber pn = GAMESTATE->m_MasterPlayerNumber; - bool bChanged = SelectChar( pn, c, true ); - if( bChanged ) - { - m_soundChange.Play(); - HandleStart( GAMESTATE->m_MasterPlayerNumber ); - } - return; - } + Message msg("Code"); + msg.SetParam( "PlayerNumber", input.pn ); + msg.SetParam( "Name", m_asCodeNames[i] ); + this->HandleMessage( msg ); } ScreenWithMenuElements::Input( input ); } -void ScreenNameEntryTraditional::ChangeDisplayedFeat() +bool ScreenNameEntryTraditional::Finish( PlayerNumber pn ) { - CHECKPOINT; - - LOG->Trace( "ScreenNameEntryTraditional::ChangeDisplayedFeat" ); - - FOREACH_HumanPlayer( pn ) + if( !AnyStillEntering() ) { - if( m_FeatDisplay[pn].size() < 2 ) - continue; - - int NewFeat = (m_CurFeat[pn]+1) % m_FeatDisplay[pn].size(); - int OldFeat = m_CurFeat[pn]; - m_CurFeat[pn] = NewFeat; - - - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_Wheel, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_Wheel, "Unhide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_Grade, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_Grade, "Unhide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_DifficultyIcon, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_DifficultyIcon, "Unhide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_DifficultyMeter, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_DifficultyMeter, "Unhide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_sprBanner, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_sprBanner, "Unhide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_textScore, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_textScore, "Unhide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][OldFeat].m_textCategory, "Hide" ); - COMMAND_OPTIONAL( m_FeatDisplay[pn][NewFeat].m_textCategory, "Unhide" ); - - m_FeatDisplay[pn][NewFeat].m_Wheel.Scroll(); - } -} - -void ScreenNameEntryTraditional::HandleScreenMessage( const ScreenMessage SM ) -{ - LOG->Trace( "ScreenNameEntryTraditional::HandleScreenMessage( %d )", SM ); - - if( SM == SM_MenuTimer ) - { - if( !m_Out.IsTransitioning() ) - { - FOREACH_PlayerNumber( p ) - Finish( p ); - HandleStart( PLAYER_INVALID ); - } - } - else if( SM == SM_ChangeDisplayedFeat ) - { - ChangeDisplayedFeat(); - this->PostScreenMessage( SM_ChangeDisplayedFeat, FEAT_INTERVAL ); + StartTransitioningScreen( SM_GoToNextScreen ); + return true; } - ScreenWithMenuElements::HandleScreenMessage( SM ); -} - -void ScreenNameEntryTraditional::Finish( PlayerNumber pn ) -{ - if( !m_bStillEnteringName[pn] ) - return; - m_bStillEnteringName[pn] = false; + if( m_bFinalized[pn] ) + return false; + m_bFinalized[pn] = true; UpdateSelectionText( pn ); /* hide NAME_ cursor */ - RString sSelection = WStringToRString( m_sSelection[pn] ); // save last used ranking name @@ -609,147 +206,146 @@ void ScreenNameEntryTraditional::Finish( PlayerNumber pn ) GAMESTATE->StoreRankingName( pn, sSelection ); - OFF_COMMAND( m_Keyboard[pn] ); - for( int i = 0; i < (int)m_textAlphabet[pn].size(); ++i ) - OFF_COMMAND( m_textAlphabet[pn][i] ); - OFF_COMMAND( m_sprCursor[pn] ); + { + Message msg("PlayerFinished"); + msg.SetParam( "PlayerNumber", pn ); + this->HandleMessage( msg ); + } if( !AnyStillEntering() ) - AllFinished(); + StartTransitioningScreen( SM_GoToNextScreen ); + + return true; } -void ScreenNameEntryTraditional::UpdateSelectionText( int pn ) +void ScreenNameEntryTraditional::UpdateSelectionText( PlayerNumber pn ) { - wstring text = m_sSelection[pn]; - if( m_bStillEnteringName[pn] && (int) text.size() < MAX_RANKING_NAME_LENGTH ) - text += L"_"; + wstring sText = m_sSelection[pn]; + if( !m_bFinalized[pn] && (int) sText.size() < MAX_RANKING_NAME_LENGTH ) + sText += L"_"; - m_textSelection[pn].SetText( WStringToRString(text) ); + Message msg("EntryChanged"); + msg.SetParam( "PlayerNumber", pn ); + msg.SetParam( "Text", WStringToRString(sText) ); + this->HandleMessage( msg ); } -void ScreenNameEntryTraditional::MenuStart( const InputEventPlus &input ) +bool ScreenNameEntryTraditional::EnterKey( PlayerNumber pn, wchar_t sLetter ) { - HandleStart( input.pn ); -} + if( m_bFinalized[pn] ) + return false; // ignore -void ScreenNameEntryTraditional::HandleStart( PlayerNumber pn ) -{ - /* The screen may have started out with nobody entering, in which case we're - * just showing scores and the first Start press moves on. */ - if( !AnyStillEntering() ) + /* If we have room, add a new character. */ + if( (int) m_sSelection[pn].size() == MAX_RANKING_NAME_LENGTH ) { - AllFinished(); - return; + SelectChar( pn, "BACK" ); + return false; } - if( !m_bStillEnteringName[pn] ) - return; // ignore + m_sSelection[pn] += sLetter; + UpdateSelectionText( pn ); - const int iCurrentSelection = m_SelectedChar[pn]; - const int iSelectedLetter = m_AlphabetLetter[pn][iCurrentSelection]; - switch( iSelectedLetter ) - { - case CHAR_OK: - m_soundKey.Play(); - Finish( pn ); - break; - - case CHAR_BACK: - Backspace( pn ); - break; - - default: - /* If we have room, add a new character. */ - if( (int) m_sSelection[pn].size() == MAX_RANKING_NAME_LENGTH ) - { - m_soundInvalid.Play(); - SelectChar( pn, CHAR_BACK, false ); - break; - } - m_sSelection[pn] += wchar_t(iSelectedLetter); - UpdateSelectionText( pn ); - m_soundKey.Play(); - - /* If that filled the string, set the cursor on OK. */ - if( (int) m_sSelection[pn].size() == MAX_RANKING_NAME_LENGTH ) - SelectChar( pn, CHAR_OK, false ); - } + /* If that filled the string, set the cursor on OK. */ + if( (int) m_sSelection[pn].size() == MAX_RANKING_NAME_LENGTH ) + SelectChar( pn, "ENTER" ); + return true; } -void ScreenNameEntryTraditional::MenuSelect( const InputEventPlus &input ) +void ScreenNameEntryTraditional::SelectChar( PlayerNumber pn, const RString &sKey ) { - if( !m_bStillEnteringName[input.pn] ) - return; // ignore - Backspace( input.pn ); + Message msg("SelectKey"); + msg.SetParam( "PlayerNumber", pn ); + msg.SetParam( "Key", sKey ); + this->HandleMessage( msg ); } -bool ScreenNameEntryTraditional::SelectChar( PlayerNumber pn, int c, bool bOptional ) +bool ScreenNameEntryTraditional::Backspace( PlayerNumber pn ) { - FOREACH( int, m_AlphabetLetter[pn], letter ) - { - if( *letter == c ) // character found - { - m_SelectedChar[pn] = letter - m_AlphabetLetter[pn].begin(); - PositionCharsAndCursor( pn ); - return true; - } - } - if( !bOptional ) - ASSERT( false ); // character not found - return false; -} + if( m_bFinalized[pn] ) + return false; // ignore -void ScreenNameEntryTraditional::Backspace( PlayerNumber pn ) -{ if( !m_sSelection[pn].size() ) - { - m_soundInvalid.Play(); - return; - } + return false; m_sSelection[pn].erase( m_sSelection[pn].size()-1, 1 ); UpdateSelectionText( pn ); - m_soundKey.Play(); + return true; } -void ScreenNameEntryTraditional::MenuLeft( const InputEventPlus &input ) +// lua start +#include "LuaBinding.h" + +class LunaScreenNameEntryTraditional: public Luna { - PlayerNumber pn = input.pn; - if( !m_bStillEnteringName[pn] || IsTransitioning() ) - return; - - --m_SelectedChar[pn]; - wrap( m_SelectedChar[pn], m_textAlphabet[pn].size() ); - PositionCharsAndCursor( pn ); - m_soundChange.Play(); -} - -void ScreenNameEntryTraditional::MenuRight( const InputEventPlus &input ) -{ - PlayerNumber pn = input.pn; - if( !m_bStillEnteringName[pn] || IsTransitioning() ) - return; - - ++m_SelectedChar[pn]; - wrap( m_SelectedChar[pn], m_textAlphabet[pn].size() ); - PositionCharsAndCursor( pn ); - m_soundChange.Play(); -} - -void ScreenNameEntryTraditional::AllFinished() -{ - StartTransitioningScreen( SM_GoToNextScreen ); - - FOREACH_HumanPlayer( pn ) +public: + static int EnterKey( T* p, lua_State *L ) { - OFF_COMMAND( m_sprOutOfRanking[pn] ); - OFF_COMMAND( m_sprNameFrame[pn] ); - OFF_COMMAND( m_textSelection[pn] ); + PlayerNumber pn = Enum::Check(L, 1); + RString sKey = SArg(2); + bool bRet = p->EnterKey( pn, utf8_get_char(sKey) ); + LuaHelpers::Push( L, bRet ); + return 1; } -} + + static int Finish( T* p, lua_State *L ) + { + PlayerNumber pn = Enum::Check(L, 1); + bool bRet = p->Finish( pn ); + LuaHelpers::Push( L, bRet ); + return 1; + } + + static int Backspace( T* p, lua_State *L ) + { + PlayerNumber pn = Enum::Check(L, 1); + bool bRet = p->Backspace( pn ); + LuaHelpers::Push( L, bRet ); + return 1; + } + + static int GetEnteringName( T* p, lua_State *L ) + { + PlayerNumber pn = Enum::Check(L, 1); + LuaHelpers::Push( L, p->m_bEnteringName[pn] ); + return 1; + } + + static int GetFinalized( T* p, lua_State *L ) + { + PlayerNumber pn = Enum::Check(L, 1); + LuaHelpers::Push( L, p->m_bFinalized[pn] ); + return 1; + } + + static int GetAnyEntering( T* p, lua_State *L ) + { + LuaHelpers::Push( L, p->AnyEntering() ); + return 1; + } + + static int GetAnyStillEntering( T* p, lua_State *L ) + { + LuaHelpers::Push( L, p->AnyStillEntering() ); + return 1; + } + + LunaScreenNameEntryTraditional() + { + ADD_METHOD( EnterKey ); + ADD_METHOD( Finish ); + ADD_METHOD( Backspace ); + ADD_METHOD( GetEnteringName ); + ADD_METHOD( GetAnyEntering ); + ADD_METHOD( GetFinalized ); + ADD_METHOD( GetAnyStillEntering ); + } +}; + +LUA_REGISTER_DERIVED_CLASS( ScreenNameEntryTraditional, ScreenWithMenuElements ) +// lua end /* - * (c) 2001-2004 Glenn Maynard, Chris Danford + * (c) 2001-2007 Glenn Maynard, Chris Danford * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/ScreenNameEntryTraditional.h b/stepmania/src/ScreenNameEntryTraditional.h index ffdae5da67..2134b03dec 100644 --- a/stepmania/src/ScreenNameEntryTraditional.h +++ b/stepmania/src/ScreenNameEntryTraditional.h @@ -4,112 +4,47 @@ #define SCREEN_NAME_ENTRY_TRADITIONAL_H #include "ScreenWithMenuElements.h" -#include "BitmapText.h" -#include "GradeDisplay.h" -#include "Banner.h" -#include "HighScore.h" -#include "DifficultyIcon.h" -#include "PercentageDisplay.h" -#include "ActorScroller.h" #include "ThemeMetric.h" -#include "DifficultyMeter.h" -#include "RageSound.h" #include "LocalizedString.h" +#include "InputQueue.h" - -class HighScoreWheelItem : public ActorFrame +class ScreenNameEntryTraditional: public ScreenWithMenuElements { public: - void Load( int iRankIndex, const HighScore& hs ); - void LoadBlank( int iRankIndex ); - void ShowFocus(); - - BitmapText m_textRank; - BitmapText m_textName; - BitmapText m_textScore; - BitmapText m_textDate; -}; - -class HighScoreWheel : public ActorScroller -{ -public: - void Load( const HighScoreList& hsl, int iIndexToFocus ); - float Scroll(); // return seconds until done scrolling - - vector m_Items; - int m_iIndexToFocus; -}; - -class ScreenNameEntryTraditional : public ScreenWithMenuElements -{ -public: - ScreenNameEntryTraditional(); virtual void Init(); - virtual ~ScreenNameEntryTraditional(); + virtual void BeginScreen(); - void Update( float fDeltaTime ); - void HandleScreenMessage( const ScreenMessage SM ); - void Input( const InputEventPlus &input ); + virtual void HandleScreenMessage( const ScreenMessage SM ); + virtual void Input( const InputEventPlus &input ); - void MenuStart( const InputEventPlus &input ); - void MenuSelect( const InputEventPlus &input ); - void MenuLeft( const InputEventPlus &input ); - void MenuRight( const InputEventPlus &input ); + virtual bool GenericTweenOn() const { return true; } + virtual bool GenericTweenOff() const { return true; } + + bool EnterKey( PlayerNumber pn, wchar_t sLetter ); + bool Backspace( PlayerNumber pn ); + + // Lua + void PushSelf( lua_State *L ); -private: bool AnyStillEntering() const; - void AllFinished(); - void PositionCharsAndCursor( int pn ); - void Finish( PlayerNumber pn ); - void UpdateSelectionText( int pn ); - void ChangeDisplayedFeat(); - bool SelectChar( PlayerNumber pn, int c, bool bOptional ); - void Backspace( PlayerNumber pn ); - void HandleStart( PlayerNumber pn ); + bool AnyEntering() const; + bool Finish( PlayerNumber pn ); + void UpdateSelectionText( PlayerNumber pn ); + void SelectChar( PlayerNumber pn, const RString &sKey ); - ThemeMetric ALPHABET_GAP_X; - ThemeMetric NUM_ALPHABET_DISPLAYED; - ThemeMetric MAX_RANKING_NAME_LENGTH; - ThemeMetric FEAT_INTERVAL; - LocalizedString KEYBOARD_LETTERS; - - ActorFrame m_Keyboard[NUM_PLAYERS]; - Sprite m_sprCursor[NUM_PLAYERS]; - vector m_textAlphabet[NUM_PLAYERS]; - vector m_AlphabetLetter[NUM_PLAYERS]; - int m_SelectedChar[NUM_PLAYERS]; - AutoActor m_sprOutOfRanking[NUM_PLAYERS]; // shown if didn't make any high scores - AutoActor m_sprNameFrame[NUM_PLAYERS]; - BitmapText m_textSelection[NUM_PLAYERS]; - - /* Feat display: */ - struct FeatDisplay - { - HighScoreWheel m_Wheel; - GradeDisplay m_Grade; - DifficultyIcon m_DifficultyIcon; - DifficultyMeter m_DifficultyMeter; - BitmapText m_textCategory; - PercentageDisplay m_textScore; - Banner m_sprBanner; - AutoActor m_sprBannerFrame; - }; - - vector m_FeatDisplay[NUM_PLAYERS]; - int m_CurFeat[NUM_PLAYERS]; - - RageSound m_soundChange; - RageSound m_soundKey; - RageSound m_soundInvalid; + ThemeMetric MAX_RANKING_NAME_LENGTH; + vector m_aCodes; + vector m_asCodeNames; wstring m_sSelection[NUM_PLAYERS]; - bool m_bStillEnteringName[NUM_PLAYERS]; + bool m_bEnteringName[NUM_PLAYERS]; + bool m_bFinalized[NUM_PLAYERS]; }; #endif /* - * (c) 2001-2004 Glenn Maynard, Chris Danford + * (c) 2001-2007 Glenn Maynard, Chris Danford * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a