From ee4be22260469a982e4f16814993f2e93a434807 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 23 Mar 2005 04:08:27 +0000 Subject: [PATCH] add input length cap fix bogus s_bCancelled flag --- stepmania/src/ScreenEdit.cpp | 48 ++++++++++++++++++++------ stepmania/src/ScreenEditMenu.cpp | 8 ++++- stepmania/src/ScreenManager.cpp | 26 ++++++-------- stepmania/src/ScreenManager.h | 15 ++++++-- stepmania/src/ScreenNetRoom.cpp | 4 +-- stepmania/src/ScreenNetworkOptions.cpp | 2 +- stepmania/src/ScreenPackages.cpp | 2 +- stepmania/src/ScreenTestFonts.cpp | 2 +- stepmania/src/ScreenTextEntry.cpp | 37 +++++++++++++------- stepmania/src/ScreenTextEntry.h | 13 +++++-- 10 files changed, 106 insertions(+), 51 deletions(-) diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 74271e586c..5ab06b95f9 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -1805,7 +1805,12 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector &iAns } break; case edit_bpm: - SCREENMAN->TextEntry( SM_BackFromBPMChange, "Enter new BPM value.", ssprintf( "%.4f", m_pSong->GetBPMAtBeat( GAMESTATE->m_fSongBeat ) ) ); + SCREENMAN->TextEntry( + SM_BackFromBPMChange, + "Enter new BPM value.", + ssprintf( "%.4f", m_pSong->GetBPMAtBeat(GAMESTATE->m_fSongBeat) ), + 10 + ); break; case edit_stop: { @@ -1817,9 +1822,23 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector &iAns break; } if ( i == m_pSong->m_Timing.m_StopSegments.size() ) - SCREENMAN->TextEntry( SM_BackFromStopChange, "Enter new Stop value.", "0.00" ); + { + SCREENMAN->TextEntry( + SM_BackFromStopChange, + "Enter new Stop value.", + "0.00", + 10 + ); + } else - SCREENMAN->TextEntry( SM_BackFromStopChange, "Enter new Stop value.", ssprintf( "%.4f", m_pSong->m_Timing.m_StopSegments[i].m_fStopSeconds ) ); + { + SCREENMAN->TextEntry( + SM_BackFromStopChange, + "Enter new Stop value.", + ssprintf( "%.4f", m_pSong->m_Timing.m_StopSegments[i].m_fStopSeconds ), + 10 + ); + } break; } case edit_bg_change: @@ -2297,7 +2316,14 @@ void ScreenEdit::HandleStepsInformationChoice( StepsInformationChoice c, const v switch( c ) { case description: - SCREENMAN->TextEntry( SM_None, "Enter a description.\nPress Enter to confirm,\nEscape to cancel.", m_pSteps->GetDescription(), ChangeDescription, NULL ); + SCREENMAN->TextEntry( + SM_None, + "Enter a description.", + m_pSteps->GetDescription(), + MAX_DESCRIPTION_LENGTH, + ChangeDescription, + NULL + ); break; } } @@ -2309,25 +2335,25 @@ void ScreenEdit::HandleSongInformationChoice( SongInformationChoice c, const vec switch( c ) { case main_title: - SCREENMAN->TextEntry( SM_None, "Edit main title.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sMainTitle, ChangeMainTitle, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit main title.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sMainTitle, 100, ChangeMainTitle, NULL ); break; case sub_title: - SCREENMAN->TextEntry( SM_None, "Edit sub title.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sSubTitle, ChangeSubTitle, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit sub title.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sSubTitle, 100, ChangeSubTitle, NULL ); break; case artist: - SCREENMAN->TextEntry( SM_None, "Edit artist.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sArtist, ChangeArtist, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit artist.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sArtist, 100, ChangeArtist, NULL ); break; case credit: - SCREENMAN->TextEntry( SM_None, "Edit credit.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sCredit, ChangeCredit, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit credit.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sCredit, 100, ChangeCredit, NULL ); break; case main_title_transliteration: - SCREENMAN->TextEntry( SM_None, "Edit main title transliteration.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sMainTitleTranslit, ChangeMainTitleTranslit, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit main title transliteration.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sMainTitleTranslit, 100, ChangeMainTitleTranslit, NULL ); break; case sub_title_transliteration: - SCREENMAN->TextEntry( SM_None, "Edit sub title transliteration.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sSubTitleTranslit, ChangeSubTitleTranslit, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit sub title transliteration.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sSubTitleTranslit, 100, ChangeSubTitleTranslit, NULL ); break; case artist_transliteration: - SCREENMAN->TextEntry( SM_None, "Edit artist transliteration.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sArtistTranslit, ChangeArtistTranslit, NULL ); + SCREENMAN->TextEntry( SM_None, "Edit artist transliteration.\nPress Enter to confirm,\nEscape to cancel.", pSong->m_sArtistTranslit, 100, ChangeArtistTranslit, NULL ); break; default: ASSERT(0); diff --git a/stepmania/src/ScreenEditMenu.cpp b/stepmania/src/ScreenEditMenu.cpp index 8d30cf5de6..7c676d41b9 100644 --- a/stepmania/src/ScreenEditMenu.cpp +++ b/stepmania/src/ScreenEditMenu.cpp @@ -272,7 +272,13 @@ void ScreenEditMenu::MenuStart( PlayerNumber pn ) bool bPromptToNameSteps = (action != EDIT_MENU_ACTION_EDIT && dc == DIFFICULTY_EDIT); if( bPromptToNameSteps ) { - SCREENMAN->TextEntry( SM_BackFromEditDescription, "Name this new edit.", GAMESTATE->m_pCurSteps[0]->GetDescription(), SetCurrentStepsDescription, DeleteCurrentSteps ); + SCREENMAN->TextEntry( + SM_BackFromEditDescription, + "Name the new edit.", + GAMESTATE->m_pCurSteps[0]->GetDescription(), + MAX_DESCRIPTION_LENGTH, + SetCurrentStepsDescription, + DeleteCurrentSteps ); } else { diff --git a/stepmania/src/ScreenManager.cpp b/stepmania/src/ScreenManager.cpp index bd1fc0ee3f..a06def194e 100644 --- a/stepmania/src/ScreenManager.cpp +++ b/stepmania/src/ScreenManager.cpp @@ -495,27 +495,21 @@ void ScreenManager::Prompt( ScreenMessage SM_SendWhenDone, const CString &sText, m_MessageSendOnPop = SM_SendWhenDone; } -void ScreenManager::TextEntry( ScreenMessage SM_SendWhenDone, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer), void(*OnCancel)() ) +void ScreenManager::TextEntry( + ScreenMessage SM_SendWhenDone, + CString sQuestion, + CString sInitialAnswer, + int iMaxInputLength, + void(*OnOK)(CString sAnswer), + void(*OnCancel)(), + bool bPassword + ) { if( m_ScreenStack.size() ) m_ScreenStack.back()->HandleScreenMessage( SM_LoseFocus ); // add the new state onto the back of the array - Screen *pNewScreen = new ScreenTextEntry( "ScreenTextEntry", sQuestion, sInitialAnswer, OnOK, OnCancel ); - pNewScreen->Init(); - this->ZeroNextUpdate(); - SetFromNewScreen( pNewScreen, true ); - - m_MessageSendOnPop = SM_SendWhenDone; -} - -void ScreenManager::Password( ScreenMessage SM_SendWhenDone, const CString &sText, void(*OnOK)(CString sPassword), void(*OnCancel)() ) -{ - if( m_ScreenStack.size() ) - m_ScreenStack.back()->HandleScreenMessage( SM_LoseFocus ); - - // add the new state onto the back of the array - Screen *pNewScreen = new ScreenTextEntry( "ScreenTextEntry", sText, "", OnOK, OnCancel, true ); + Screen *pNewScreen = new ScreenTextEntry( "ScreenTextEntry", sQuestion, sInitialAnswer, iMaxInputLength, OnOK, OnCancel, bPassword ); pNewScreen->Init(); this->ZeroNextUpdate(); SetFromNewScreen( pNewScreen, true ); diff --git a/stepmania/src/ScreenManager.h b/stepmania/src/ScreenManager.h index 575b1b067e..8102bfae02 100644 --- a/stepmania/src/ScreenManager.h +++ b/stepmania/src/ScreenManager.h @@ -57,8 +57,19 @@ public: void SetNewScreen( const CString &sName ); void AddNewScreenToTop( const CString &sName, ScreenMessage messageSendOnPop ); void Prompt( ScreenMessage SM_SendWhenDone, const CString &sText, PromptType type = PROMPT_OK, PromptAnswer defaultAnswer = ANSWER_NO, void(*OnYes)(void*) = NULL, void(*OnNo)(void*) = NULL, void* pCallbackData = NULL ); - void Password( ScreenMessage SM_SendWhenDone, const CString &sText, void(*OnOK)(CString sPassword) = NULL, void(*OnCanel)() = NULL ); - void TextEntry( ScreenMessage SM_SendWhenDone, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer) = NULL, void(*OnCanel)() = NULL ); + void TextEntry( + ScreenMessage SM_SendWhenDone, + CString sQuestion, + CString sInitialAnswer, + int iMaxInputLength, + void(*OnOK)(CString sAnswer) = NULL, + void(*OnCanel)() = NULL, + bool bPassword = false + ); + void Password( ScreenMessage SM_SendWhenDone, const CString &sQuestion, void(*OnOK)(CString sPassword) = NULL, void(*OnCanel)() = NULL ) + { + TextEntry( SM_SendWhenDone, sQuestion, "", 255, OnOK, OnCanel, true ); + } void MiniMenu( Menu* pDef, ScreenMessage SM_SendOnOK, ScreenMessage SM_SendOnCancel = SM_None ); void PopTopScreen( ScreenMessage SM = SM_None ); void SystemMessage( const CString &sMessage ); diff --git a/stepmania/src/ScreenNetRoom.cpp b/stepmania/src/ScreenNetRoom.cpp index b9a344ae36..d61077a7bf 100644 --- a/stepmania/src/ScreenNetRoom.cpp +++ b/stepmania/src/ScreenNetRoom.cpp @@ -146,7 +146,7 @@ void ScreenNetRoom::HandleScreenMessage( const ScreenMessage SM ) if ( !ScreenTextEntry::s_bCancelledLast ) { m_newRoomName = ScreenTextEntry::s_sLastAnswer; - SCREENMAN->TextEntry( SM_BackFromRoomDesc, "Enter Room Description:", ""); + SCREENMAN->TextEntry( SM_BackFromRoomDesc, "Enter Room Description:", "", 255 ); } break; case SM_BackFromRoomDesc: @@ -192,7 +192,7 @@ void ScreenNetRoom::MenuStart( PlayerNumber pn ) } break; case SelectMakeRoom: - SCREENMAN->TextEntry( SM_BackFromRoomName, "Enter Room Name:", ""); + SCREENMAN->TextEntry( SM_BackFromRoomName, "Enter Room Name:", "", 255 ); break; }; } diff --git a/stepmania/src/ScreenNetworkOptions.cpp b/stepmania/src/ScreenNetworkOptions.cpp index 36755d9013..0c66e668a1 100644 --- a/stepmania/src/ScreenNetworkOptions.cpp +++ b/stepmania/src/ScreenNetworkOptions.cpp @@ -122,7 +122,7 @@ void ScreenNetworkOptions::MenuStart( PlayerNumber pn, const InputEventType type case PO_CONNECTION: if ( !NSMAN->useSMserver ) { - SCREENMAN->TextEntry( SM_DoneConnecting, "Enter a Network Address\n127.0.0.1 to connect to yourself", g_sLastServer ); + SCREENMAN->TextEntry( SM_DoneConnecting, "Enter a Network Address\n127.0.0.1 to connect to yourself", g_sLastServer, 15 ); } else { diff --git a/stepmania/src/ScreenPackages.cpp b/stepmania/src/ScreenPackages.cpp index b943d22bb0..0f6e31d86a 100644 --- a/stepmania/src/ScreenPackages.cpp +++ b/stepmania/src/ScreenPackages.cpp @@ -164,7 +164,7 @@ void ScreenPackages::MenuStart( PlayerNumber pn ) if ( m_iDLorLST == 1 ) { if ( m_iLinksPos == 0 ) - SCREENMAN->TextEntry( SM_BackFromURL, "Enter URL:", "http://" ); + SCREENMAN->TextEntry( SM_BackFromURL, "Enter URL:", "http://", 255 ); else EnterURL( m_Links[m_iLinksPos] ); } diff --git a/stepmania/src/ScreenTestFonts.cpp b/stepmania/src/ScreenTestFonts.cpp index 7f3a4c9a9d..e8753470e9 100644 --- a/stepmania/src/ScreenTestFonts.cpp +++ b/stepmania/src/ScreenTestFonts.cpp @@ -97,7 +97,7 @@ void ScreenTestFonts::Input( const DeviceInput& DeviceI, const InputEventType ty case '`': if(curtext != CustomText) SetText(CustomText); else - SCREENMAN->TextEntry( SM_ChangeText, "Edit text.", CustomText, ChangeText, NULL); + SCREENMAN->TextEntry( SM_ChangeText, "Edit text.", CustomText, 100, ChangeText, NULL); break; case '1': SetText("Waaai"); break; case '2': SetText("WAAI ☩"); break; diff --git a/stepmania/src/ScreenTextEntry.cpp b/stepmania/src/ScreenTextEntry.cpp index 5b16a670fd..9b89c672a5 100644 --- a/stepmania/src/ScreenTextEntry.cpp +++ b/stepmania/src/ScreenTextEntry.cpp @@ -46,21 +46,25 @@ bool ScreenTextEntry::s_bCancelledLast = false; */ //REGISTER_SCREEN_CLASS( ScreenTextEntry ); -ScreenTextEntry::ScreenTextEntry( CString sClassName, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer), void(*OnCancel)(), bool bPassword ) : - Screen( sClassName ) +ScreenTextEntry::ScreenTextEntry( + CString sClassName, + CString sQuestion, + CString sInitialAnswer, + int iMaxInputLength, + void(*OnOK)(CString sAnswer), + void(*OnCancel)(), + bool bPassword ) : + Screen( sClassName ) { - m_sName = "ScreenTextEntry"; - m_bIsTransparent = true; // draw screens below us - m_bPassword = bPassword; - - m_pOnOK = OnOK; - m_pOnCancel = OnCancel; - - m_sAnswer = CStringToWstring( sInitialAnswer ); m_bCancelled = false; m_sQuestion = sQuestion; + m_sAnswer = CStringToWstring( sInitialAnswer ); + m_iMaxInputLength = iMaxInputLength; + m_pOnOK = OnOK; + m_pOnCancel = OnCancel; + m_bPassword = bPassword; } void ScreenTextEntry::Init() @@ -247,7 +251,14 @@ void ScreenTextEntry::MoveY( int iDir ) void ScreenTextEntry::AppendToAnswer( CString s ) { - m_sAnswer += CStringToWstring( s ); + wstring sNewAnswer = m_sAnswer+CStringToWstring(s); + if( (int)sNewAnswer.length() > m_iMaxInputLength ) + { + SCREENMAN->PlayInvalidSound(); + return; + } + + m_sAnswer = sNewAnswer; m_sndType.Play(); UpdateAnswerText(); @@ -322,8 +333,8 @@ void ScreenTextEntry::End( bool bCancelled ) } } - s_bCancelledLast = m_bCancelled; - s_sLastAnswer = m_bCancelled ? CString("") : WStringToCString(m_sAnswer); + s_bCancelledLast = bCancelled; + s_sLastAnswer = bCancelled ? CString("") : WStringToCString(m_sAnswer); } void ScreenTextEntry::MenuBack( PlayerNumber pn ) diff --git a/stepmania/src/ScreenTextEntry.h b/stepmania/src/ScreenTextEntry.h index 22b5327827..718aa93376 100644 --- a/stepmania/src/ScreenTextEntry.h +++ b/stepmania/src/ScreenTextEntry.h @@ -27,7 +27,14 @@ enum KeyboardRowSpecialKey class ScreenTextEntry : public Screen { public: - ScreenTextEntry( CString sName, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer) = NULL, void(*OnCanel)() = NULL, bool bPassword = false ); + ScreenTextEntry( + CString sName, + CString sQuestion, + CString sInitialAnswer, + int iMaxInputLength, + void(*OnOK)(CString sAnswer) = NULL, + void(*OnCanel)() = NULL, + bool bPassword = false ); ~ScreenTextEntry(); virtual void Init(); @@ -59,6 +66,7 @@ protected: void UpdateAnswerText(); CString m_sQuestion; + int m_iMaxInputLength; bool m_bPassword; AutoActor m_Background; BitmapText m_textQuestion; @@ -67,8 +75,7 @@ protected: BitmapText m_textAnswer; void(*m_pOnOK)( CString sAnswer ); void(*m_pOnCancel)(); - bool m_bCancelled; - + AutoActor m_sprCursor; int m_iFocusX;