diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 0da5765e66..a6b002668b 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -2435,9 +2435,44 @@ void ScreenEdit::OnSnapModeChange() static void ChangeDescription( const CString &sNew ) { Steps* pSteps = GAMESTATE->m_pCurSteps[PLAYER_1]; + + /* Don't erase edit descriptions. */ + if( sNew.empty() && pSteps->GetDifficulty() == DIFFICULTY_EDIT ) + return; + pSteps->SetDescription(sNew); } +static bool ValidateDescription( const CString &sAnswer, CString &sErrorOut ) +{ + if( sAnswer.empty() ) + return true; + + /* Don't allow duplicate edit names within the same StepsType; edit names uniquely + * identify the edit. */ + Steps *pSteps = GAMESTATE->m_pCurSteps[PLAYER_1]; + Song *pSong = GAMESTATE->m_pCurSong; + if( pSteps->GetDifficulty() != DIFFICULTY_EDIT ) + return true; + + /* If unchanged: */ + if( pSteps->GetDescription() == sAnswer ) + return true; + + vector apSteps; + pSong->GetSteps( apSteps, pSteps->m_StepsType, DIFFICULTY_EDIT, -1, -1, sAnswer ); + + if( apSteps.size() == 0 ) + return true; + + /* The name is already used, */ + if( apSteps.size() > 1 ) + LOG->Warn( "Multiple edits for song \"%s\" named \"%s\"", pSong->GetSongDir().c_str(), sAnswer.c_str() ); + + sErrorOut = "The supplied name supplied conflicts with another edit.\n\nPlease use a different name."; + return false; +} + static void ChangeMainTitle( const CString &sNew ) { Song* pSong = GAMESTATE->m_pCurSong; @@ -3031,7 +3066,7 @@ void ScreenEdit::HandleStepsInformationChoice( StepsInformationChoice c, const v ENTER_NEW_DESCRIPTION, m_pSteps->GetDescription(), (dc == DIFFICULTY_EDIT) ? MAX_EDIT_STEPS_DESCRIPTION_LENGTH : 255, - NULL, + ValidateDescription, ChangeDescription, NULL );