From 1e4b73185ca47b4e48f05592041c3a8f7e8f4d31 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 11 Apr 2009 18:45:04 +0000 Subject: [PATCH] merge ManageWorkouts into ManageCourses --- stepmania/Themes/default/Languages/de.ini | 3 - stepmania/Themes/default/Languages/en.ini | 3 - stepmania/Themes/default/Languages/es.ini | 3 - stepmania/Themes/default/Languages/fr.ini | 3 - stepmania/Themes/default/Languages/it.ini | 3 - stepmania/src/CourseUtil.cpp | 24 -- stepmania/src/ScreenOptionsManageCourses.cpp | 391 +++++++------------ stepmania/src/ScreenOptionsManageCourses.h | 16 +- stepmania/src/WorkoutManager.cpp | 29 +- 9 files changed, 168 insertions(+), 307 deletions(-) diff --git a/stepmania/Themes/default/Languages/de.ini b/stepmania/Themes/default/Languages/de.ini index 5a33ece728..b19ae2fa14 100644 --- a/stepmania/Themes/default/Languages/de.ini +++ b/stepmania/Themes/default/Languages/de.ini @@ -1223,9 +1223,6 @@ You cannot delete the last entry in a course.=Sie können den letzten Eintrag in [ScreenOptionsEditCourseEntry] No songs loaded.=Keine Songs geladen. -[ScreenOptionsEditCourseSubMenu] -Failed to write course.=Kurs schreiben fehlgeschlagen. - [ScreenOptionsManageCourses] Continue with delete?=Mit Löschen fortfahren? Enter a name for the course.=Namen für Kurs eingeben. diff --git a/stepmania/Themes/default/Languages/en.ini b/stepmania/Themes/default/Languages/en.ini index a8bf45b328..b460113dc7 100644 --- a/stepmania/Themes/default/Languages/en.ini +++ b/stepmania/Themes/default/Languages/en.ini @@ -1213,9 +1213,6 @@ ScoreOff=Off HeaderText=Network Options HeaderSubText=Configure networked gameplay -[ScreenOptionsEditCourseSubMenu] -Failed to write course.=Failed to write course. - [ScreenOptionsEditCourse] The maximum number of entries per course is %d. This course already has %d entries.=The maximum number of entries per course is %d. This course already has %d entries. You cannot delete the last entry in a course.=You can not delete the last entry in a course. diff --git a/stepmania/Themes/default/Languages/es.ini b/stepmania/Themes/default/Languages/es.ini index 75f413593f..8d3e466fa4 100644 --- a/stepmania/Themes/default/Languages/es.ini +++ b/stepmania/Themes/default/Languages/es.ini @@ -1688,9 +1688,6 @@ Use 127.0.0.1 to connect to yourself.=Utiliza 127.0.0.1 para conectarte contigo HeaderText=Opciones de red HeaderSubText=Configurar juego en red -[ScreenOptionsEditCourseSubMenu] -Failed to write course.=Error al guardar el course. - [ScreenOptionsEditCourse] The maximum number of entries per course is %d. This course already has %d entries.=El número máximo de entradas por course es de %d. Este course tiene ya %d entradas. You cannot delete the last entry in a course.=No puedes eliminar la última entrada en un course. diff --git a/stepmania/Themes/default/Languages/fr.ini b/stepmania/Themes/default/Languages/fr.ini index cddf648692..4876250f5d 100644 --- a/stepmania/Themes/default/Languages/fr.ini +++ b/stepmania/Themes/default/Languages/fr.ini @@ -1199,9 +1199,6 @@ You cannot delete the last entry in a course.=Vous ne pouvez pas supprimer la de [ScreenOptionsEditCourseEntry] No songs loaded.=Aucune chanson chargée. -[ScreenOptionsEditCourseSubMenu] -Failed to write course.=Echec lors de l'écriture d'une course. - [ScreenOptionsManageCourses] Continue with delete?=Confirmer la suppression? Enter a name for the course.=Entrez un nom pour la course. diff --git a/stepmania/Themes/default/Languages/it.ini b/stepmania/Themes/default/Languages/it.ini index c26d4e601d..bee6b339f4 100644 --- a/stepmania/Themes/default/Languages/it.ini +++ b/stepmania/Themes/default/Languages/it.ini @@ -1193,9 +1193,6 @@ You cannot delete the last entry in a course.=Non si può eliminare l'ultima voc [ScreenOptionsEditCourseEntry] No songs loaded.=Non ci sono canzoni caricate. -[ScreenOptionsEditCourseSubMenu] -Failed to write course.=Errore nella scrittura del percorso. - [ScreenOptionsManageCourses] Continue with delete?=Continuare con cancella? Enter a name for the course.=Inserisci un nome per la corsa. diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 8eab98321c..9edd0eedc0 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -293,30 +293,6 @@ void CourseUtil::AutogenOniFromArtist( const RString &sArtistName, RString sArti } } -static LocalizedString EDIT_NAME_CONFLICTS ( "ScreenOptionsManageCourses", "The name you chose conflicts with another edit. Please use a different name." ); -bool CourseUtil::ValidateEditCourseName( const RString &sAnswer, RString &sErrorOut ) -{ - if( sAnswer.empty() ) - return false; - - // Course name must be unique - vector v; - SONGMAN->GetAllCourses( v, false ); - FOREACH_CONST( Course*, v, c ) - { - if( GAMESTATE->m_pCurCourse.Get() == *c ) - continue; // don't compare name against ourself - - if( (*c)->GetDisplayFullTitle() == sAnswer ) - { - sErrorOut = EDIT_NAME_CONFLICTS; - return false; - } - } - - return true; -} - void CourseUtil::WarnOnInvalidMods( RString sMods ) { PlayerOptions po; diff --git a/stepmania/src/ScreenOptionsManageCourses.cpp b/stepmania/src/ScreenOptionsManageCourses.cpp index c92d423a3c..4b4c96ffbf 100644 --- a/stepmania/src/ScreenOptionsManageCourses.cpp +++ b/stepmania/src/ScreenOptionsManageCourses.cpp @@ -17,19 +17,34 @@ #include "Profile.h" #include "CourseWriterCRS.h" #include "RageFileManager.h" +#include "PrefsManager.h" +#include "WorkoutManager.h" -static void RefreshTrail() +AutoScreenMessage( SM_BackFromRename ) +AutoScreenMessage( SM_BackFromDelete ) +AutoScreenMessage( SM_BackFromContextMenu ) + +enum CourseAction { - Course *pCourse = GAMESTATE->m_pCurCourse; - if( pCourse == NULL ) - { - GAMESTATE->m_pCurTrail[PLAYER_1].Set( NULL ); - return; - } - GAMESTATE->m_pCurCourse.Set( pCourse ); - Trail *pTrail = pCourse->GetTrail( GAMESTATE->m_stEdit, GAMESTATE->m_cdEdit ); - GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail ); -} + CourseAction_Edit, + CourseAction_Rename, + CourseAction_Delete, + NUM_CourseAction +}; +static const char *CourseActionNames[] = { + "Edit", + "Rename", + "Delete", +}; +XToString( CourseAction ); +#define FOREACH_CourseAction( i ) FOREACH_ENUM( CourseAction, i ) + +static MenuDef g_TempMenu( + "ScreenMiniMenuContext" +); + +REGISTER_SCREEN_CLASS( ScreenOptionsManageCourses ); + struct StepsTypeAndDifficulty { @@ -62,106 +77,19 @@ static void SetNextCombination() // XXX Testing. SCREENMAN->SystemMessage( ssprintf("%s, %s", GameManager::GetStepsTypeInfo(curVal.st).szName, DifficultyToString(curVal.cd).c_str()) ); - RefreshTrail(); + EditCourseUtil::UpdateAndSetTrail(); } -void ScreenOptionsEditCourseSubMenu::Init() -{ - m_soundDifficultyChanged.Load( THEME->GetPathS("ScreenEditCourseSubmenu", "difficulty changed") ); - ScreenOptions::Init(); -} - -void ScreenOptionsEditCourseSubMenu::MenuSelect( const InputEventPlus &input ) -{ - if( input.type != IET_FIRST_PRESS ) - return; - SetNextCombination(); - m_soundDifficultyChanged.Play(); - -} - -static LocalizedString FAILED_TO_WRITE_COURSE( "ScreenOptionsEditCourseSubMenu", "Failed to write course." ); -void ScreenOptionsEditCourseSubMenu::WriteCourse() -{ - Course *pCourse = GAMESTATE->m_pCurCourse; - - if( pCourse->m_sPath.empty() ) - { - // Write the course to the profile directory - const RString& dir = PROFILEMAN->GetProfileDir( pCourse->GetLoadedFromProfileSlot() ); - - ASSERT( !dir.empty() ); - pCourse->m_sPath = dir + EDIT_COURSES_SUBDIR + pCourse->m_sMainTitle + ".crs"; - } - if( !CourseWriterCRS::Write(*pCourse, pCourse->m_sPath, false) ) - { - ScreenPrompt::Prompt( SM_None, FAILED_TO_WRITE_COURSE ); - return; - } - - if( !pCourse->IsAnEdit() ) - CourseWriterCRS::Write( *pCourse, pCourse->GetCacheFilePath(), true ); -} - - -AutoScreenMessage( SM_BackFromEnterNameForNew ) -AutoScreenMessage( SM_BackFromRename ) -AutoScreenMessage( SM_BackFromContextMenu ) - -enum CourseAction -{ - CourseAction_Edit, - CourseAction_Rename, - CourseAction_Delete, - NUM_CourseAction -}; -static const char *CourseActionNames[] = { - "Edit", - "Rename", - "Delete", -}; -XToString( CourseAction ); -#define FOREACH_CourseAction( i ) FOREACH_ENUM( CourseAction, i ) - -static MenuDef g_TempMenu( - "ScreenMiniMenuContext" -); - - -static LocalizedString EDIT_NAME_CONFLICTS ( "ScreenOptionsManageCourses", "The name you chose conflicts with another edit. Please use a different name." ); -static bool ValidateEditCourseName( const RString &sAnswer, RString &sErrorOut ) -{ - if( sAnswer.empty() ) - return false; - - // Course name must be unique - vector v; - SONGMAN->GetAllCourses( v, false ); - FOREACH_CONST( Course*, v, c ) - { - if( GAMESTATE->m_pCurCourse.Get() == *c ) - continue; // don't compare name against ourself - - if( (*c)->GetDisplayFullTitle() == sAnswer ) - { - sErrorOut = EDIT_NAME_CONFLICTS; - return false; - } - } - - return true; -} - - -REGISTER_SCREEN_CLASS( ScreenOptionsManageCourses ); - void ScreenOptionsManageCourses::Init() { - ScreenOptionsEditCourseSubMenu::Init(); + if( PREFSMAN->m_iArcadeOptionsNavigation ) + SetNavigation( NAV_THREE_KEY_MENU ); + ScreenOptions::Init(); + + m_soundDifficultyChanged.Load( THEME->GetPathS("ScreenEditCourseSubmenu", "difficulty changed") ); EDIT_MODE.Load( m_sName,"EditMode" ); CREATE_NEW_SCREEN.Load( m_sName, "CreateNewScreen" ); - GAMESTATE->m_MasterPlayerNumber = GAMESTATE->GetFirstHumanPlayer(); } void ScreenOptionsManageCourses::BeginScreen() @@ -172,6 +100,16 @@ void ScreenOptionsManageCourses::BeginScreen() SetNextCombination(); } + vector vpStyles; + GameManager::GetStylesForGame( GAMESTATE->m_pCurGame, vpStyles ); + const Style *pStyle = vpStyles[0]; + GAMESTATE->SetCurrentStyle( pStyle ); + + + // Remember the current course. All Course pointers will be invalidated when we load the machine profile below. + CourseID cidLast; + cidLast.FromCourse( GAMESTATE->m_pCurCourse ); + vector vHands; int iIndex = 0; @@ -189,54 +127,32 @@ void ScreenOptionsManageCourses::BeginScreen() } m_vpCourses.clear(); - SONGMAN->GetAllCourses( m_vpCourses, false ); + FlushDirCache(); + PROFILEMAN->LoadMachineProfileEdits(); switch( EDIT_MODE.GetValue() ) { - default: - RageException::Throw( "ScreenOptionsManageCourses: Invalid edit mode: %s.", - EditModeToString(EDIT_MODE.GetValue()).c_str() ); - case EditMode_Practice: - case EditMode_Home: - // Strip out non-edits. - // VC6 is missing mem_fun for const members. Lame. Work around by not using mem_fun. */ - for( int i=m_vpCourses.size()-1; i>=0; i-- ) - { - if( m_vpCourses[i]->IsAnEdit() ) - m_vpCourses.erase( m_vpCourses.begin()+i ); - } - break; - case EditMode_Full: - break; + DEFAULT_FAIL( EDIT_MODE.GetValue() ); + case EditMode_Home: + EditCourseUtil::GetAllEditCourses( m_vpCourses ); + break; + case EditMode_Practice: + case EditMode_Full: + SONGMAN->GetAllCourses( m_vpCourses, false ); + break; } - FOREACH_CONST( Course*, m_vpCourses, c ) + FOREACH_CONST( Course*, m_vpCourses, p ) { vHands.push_back( OptionRowHandlerUtil::MakeNull() ); OptionRowDefinition &def = vHands.back()->m_Def; - switch( EDIT_MODE.GetValue() ) - { - default: - ASSERT(0); - case EditMode_Practice: - case EditMode_Home: - def.m_sName = CourseTypeToLocalizedString( (*c)->GetCourseType() ); - break; - case EditMode_Full: - if( (*c)->IsAnEdit() ) - def.m_sName = "Edit"; - else - def.m_sName = SONGMAN->ShortenGroupName( (*c)->m_sGroupName ); - break; - } - - def.m_sName = ssprintf( "%3d %s", iIndex, def.m_sName.c_str() ); - def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW; - def.m_bAllowThemeItems = false; - def.m_bAllowThemeTitle = false; - def.m_bOneChoiceForAllPlayers = true; - def.m_vsChoices.push_back( (*c)->GetDisplayFullTitle() ); + def.m_sName = (*p)->GetDisplayFullTitle(); + def.m_bAllowThemeTitle = false; // not themable + def.m_sExplanationName = "Select Workout"; + def.m_vsChoices.clear(); + def.m_vsChoices.push_back( "" ); + def.m_bAllowThemeItems = false; // already themed iIndex++; } @@ -245,8 +161,10 @@ void ScreenOptionsManageCourses::BeginScreen() ScreenOptions::BeginScreen(); // select the last chosen course + GAMESTATE->m_pCurCourse.Set( cidLast.ToCourse() ); if( GAMESTATE->m_pCurCourse ) { + EditCourseUtil::UpdateAndSetTrail(); vector::const_iterator iter = find( m_vpCourses.begin(), m_vpCourses.end(), GAMESTATE->m_pCurCourse ); if( iter != m_vpCourses.end() ) { @@ -258,96 +176,69 @@ void ScreenOptionsManageCourses::BeginScreen() AfterChangeRow( GAMESTATE->m_MasterPlayerNumber ); } +static LocalizedString ERROR_RENAMING ("ScreenOptionsManageCourses", "Error renaming file."); +static LocalizedString ERROR_DELETING_FILE ("ScreenOptionsManageWorkouts", "Error deleting the file '%s'."); static LocalizedString COURSE_WILL_BE_LOST ( "ScreenOptionsManageCourses", "This course will be lost permanently." ); static LocalizedString CONTINUE_WITH_DELETE ( "ScreenOptionsManageCourses", "Continue with delete?" ); static LocalizedString ENTER_COURSE_NAME ( "ScreenOptionsManageCourses", "Enter a name for the course." ); void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM ) { - if( SM == SM_Success ) - { - LOG->Trace( "Delete succeeded; deleting course." ); - Course *pCourse = GetCourseWithFocus(); - - GAMESTATE->m_pCurCourse.Set( NULL ); // Maybe I should just go to the next course - RefreshTrail(); - SONGMAN->DeleteCourse( pCourse ); - FILEMAN->Remove( pCourse->m_sPath ); - if( !pCourse->IsAnEdit() ) - FILEMAN->Remove( pCourse->GetCacheFilePath() ); - delete pCourse; - SCREENMAN->SetNewScreen( this->m_sName ); // reload - } - else if( SM == SM_Failure ) - { - LOG->Trace( "Delete failed; not deleting course." ); - } - else if( SM == SM_GoToNextScreen ) + if( SM == SM_GoToNextScreen ) { int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber]; - if( iCurRow == (int)m_pRows.size() - 1 ) + + if( iCurRow == 0 ) // "create new" + { + /* Allocate the Course now, but don't save the file until the user explicitly chooses Save */ + Course *pCourse = new Course; + EditCourseUtil::LoadDefaults( *pCourse ); + pCourse->m_LoadedFromProfile = ProfileSlot_Machine; + SONGMAN->AddCourse( pCourse ); + GAMESTATE->m_pCurCourse.Set( pCourse ); + EditCourseUtil::s_bNewCourseNeedsName = true; + EditCourseUtil::UpdateAndSetTrail(); + + SCREENMAN->SetNewScreen( CREATE_NEW_SCREEN ); + return; // don't call base + } + else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit ) { this->HandleScreenMessage( SM_GoToPrevScreen ); return; // don't call base } - } - else if( SM == SM_BackFromEnterNameForNew ) - { - if( !ScreenTextEntry::s_bCancelledLast ) + else { - ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this - - // create - Course *pCourse = new Course; - ProfileSlot slot; - - pCourse->m_sMainTitle = ScreenTextEntry::s_sLastAnswer; - - switch( EDIT_MODE.GetValue() ) - { - case EditMode_Practice: - case EditMode_Home: - slot = ProfileSlot_Machine; - break; - case EditMode_Full: - if( PROFILEMAN->IsPersistentProfile(GAMESTATE->m_MasterPlayerNumber) ) - slot = (ProfileSlot)GAMESTATE->m_MasterPlayerNumber; // XXX I don't like this - else - slot = ProfileSlot_Machine; - break; - default: - FAIL_M( "Invalid EditMode." ); - } - - pCourse->SetLoadedFromProfile( slot ); - CourseEntry ce; - CourseUtil::MakeDefaultEditCourseEntry( ce ); - pCourse->m_vEntries.push_back( ce ); - SONGMAN->AddCourse( pCourse ); - GAMESTATE->m_pCurCourse.Set( pCourse ); - WriteCourse(); - - RefreshTrail(); - this->HandleScreenMessage( SM_GoToNextScreen ); + // do base behavior } } else if( SM == SM_BackFromRename ) { if( !ScreenTextEntry::s_bCancelledLast ) { - Course *pCourse = GAMESTATE->m_pCurCourse; - const RString& sNewName = ScreenTextEntry::s_sLastAnswer; - RString sDir, sName, sExt; - ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this - ASSERT( !pCourse->m_sPath.empty() ); - FILEMAN->Remove( pCourse->m_sPath ); - if( !pCourse->IsAnEdit() ) - FILEMAN->Remove( pCourse->GetCacheFilePath() ); - - splitpath( pCourse->m_sPath, sDir, sName, sExt ); - pCourse->m_sPath = sDir + sNewName + sExt; - pCourse->m_sMainTitle = sNewName; - WriteCourse(); + + if( !EditCourseUtil::RenameAndSave(GAMESTATE->m_pCurCourse, ScreenTextEntry::s_sLastAnswer) ) + { + ScreenPrompt::Prompt( SM_None, ERROR_RENAMING ); + return; + } + + SCREENMAN->SetNewScreen( this->m_sName ); // reload + } + } + else if( SM == SM_BackFromDelete ) + { + if( ScreenPrompt::s_LastAnswer == ANSWER_YES ) + { + Course *pCourse = GetCourseWithFocus(); + if( !EditCourseUtil::RemoveAndDeleteFile( pCourse ) ) + { + ScreenPrompt::Prompt( SM_None, ssprintf(ERROR_DELETING_FILE.GetValue(),pCourse->m_sPath.c_str()) ); + return; + } + + GAMESTATE->m_pCurCourse.Set( NULL ); + GAMESTATE->m_pCurTrail[PLAYER_1].Set( NULL ); SCREENMAN->SetNewScreen( this->m_sName ); // reload } } @@ -358,21 +249,20 @@ void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM ) switch( ScreenMiniMenu::s_iLastRowCode ) { case CourseAction_Edit: - { - Course *pCourse = GetCourseWithFocus(); - Trail *pTrail = pCourse->GetTrail( GAMESTATE->m_stEdit, GAMESTATE->m_cdEdit ); - GAMESTATE->m_pCurCourse.Set( pCourse ); - GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail ); - - ScreenOptions::BeginFadingOut(); - break; - } + { + GAMESTATE->m_pCurCourse.Set( GetCourseWithFocus() ); + EditCourseUtil::UpdateAndSetTrail(); + EditCourseUtil::s_bNewCourseNeedsName = false; + ScreenOptions::BeginFadingOut(); + break; + } case CourseAction_Rename: - ScreenTextEntry::TextEntry( SM_BackFromRename, - ENTER_COURSE_NAME, - GAMESTATE->m_pCurCourse->GetDisplayFullTitle(), - MAX_EDIT_COURSE_TITLE_LENGTH, - ValidateEditCourseName ); + ScreenTextEntry::TextEntry( + SM_BackFromRename, + ENTER_COURSE_NAME, + GAMESTATE->m_pCurCourse->GetDisplayFullTitle(), + EditCourseUtil::MAX_NAME_LENGTH, + EditCourseUtil::ValidateEditCourseName ); break; case CourseAction_Delete: ScreenPrompt::Prompt( SM_None, COURSE_WILL_BE_LOST.GetValue()+"\n\n"+CONTINUE_WITH_DELETE.GetValue(), PROMPT_YES_NO, ANSWER_NO ); @@ -403,6 +293,17 @@ void ScreenOptionsManageCourses::AfterChangeRow( PlayerNumber pn ) ScreenOptions::AfterChangeRow( pn ); } +void ScreenOptionsManageCourses::MenuSelect( const InputEventPlus &input ) +{ + if( input.type != IET_FIRST_PRESS ) + return; + SetNextCombination(); + m_soundDifficultyChanged.Play(); + +} + +static LocalizedString YOU_HAVE_MAX( "ScreenOptionsManageCourses", "You have %d, the maximum number allowed." ); +static LocalizedString YOU_MUST_DELETE( "ScreenOptionsManageCourses", "You must delete an existing before creating a new." ); void ScreenOptionsManageCourses::ProcessMenuStart( const InputEventPlus &input ) { if( IsTransitioning() ) @@ -412,28 +313,18 @@ void ScreenOptionsManageCourses::ProcessMenuStart( const InputEventPlus &input ) if( iCurRow == 0 ) // "create new" { - if( !CREATE_NEW_SCREEN.GetValue().empty() ) + vector vpCourses; + EditCourseUtil::GetAllEditCourses( vpCourses ); + if( vpCourses.size() >= (size_t)EditCourseUtil::MAX_PER_PROFILE ) { - SCREENMAN->SetNewScreen( CREATE_NEW_SCREEN ); - } - else - { - RString sDefaultName; - RString sThrowAway; - for( int i=1; i<=9999; i++ ) - { - sDefaultName = ssprintf( "NewCourse%04d", i ); - if( ValidateEditCourseName(sDefaultName,sThrowAway) ) - break; - } - ScreenTextEntry::TextEntry( SM_BackFromEnterNameForNew, - ENTER_COURSE_NAME, - sDefaultName, - MAX_EDIT_COURSE_TITLE_LENGTH, - ValidateEditCourseName ); + RString s = ssprintf( YOU_HAVE_MAX.GetValue()+"\n\n"+YOU_MUST_DELETE.GetValue(), EditCourseUtil::MAX_PER_PROFILE ); + ScreenPrompt::Prompt( SM_None, s ); + return; } + SCREENMAN->PlayStartSound(); + this->BeginFadingOut(); } - else if( iCurRow == (int)m_pRows.size()-1 ) // "done" + else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit ) { SCREENMAN->PlayStartSound(); this->BeginFadingOut(); @@ -468,12 +359,12 @@ Course *ScreenOptionsManageCourses::GetCourseWithFocus() const int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber]; if( iCurRow == 0 ) return NULL; - else if( iCurRow == (int)m_pRows.size()-1 ) // "done" + else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit ) return NULL; // a course - int iCourseIndex = iCurRow - 1; - return m_vpCourses[iCourseIndex]; + int index = iCurRow - 1; + return m_vpCourses[index]; } /* diff --git a/stepmania/src/ScreenOptionsManageCourses.h b/stepmania/src/ScreenOptionsManageCourses.h index 1c1dcab71f..e16cc19904 100644 --- a/stepmania/src/ScreenOptionsManageCourses.h +++ b/stepmania/src/ScreenOptionsManageCourses.h @@ -7,24 +7,13 @@ class Course; -class ScreenOptionsEditCourseSubMenu : public ScreenOptions -{ - RageSound m_soundDifficultyChanged; - -public: - virtual void Init(); - -protected: - virtual void MenuSelect( const InputEventPlus &input ); - void WriteCourse(); -}; - -class ScreenOptionsManageCourses : public ScreenOptionsEditCourseSubMenu +class ScreenOptionsManageCourses : public ScreenOptions { public: void Init(); virtual void BeginScreen(); virtual void HandleScreenMessage( const ScreenMessage SM ); + virtual void MenuSelect( const InputEventPlus &input ); protected: virtual void ImportOptions( int iRow, const vector &vpns ); @@ -36,6 +25,7 @@ protected: private: Course *GetCourseWithFocus() const; + RageSound m_soundDifficultyChanged; vector m_vpCourses; ThemeMetric EDIT_MODE; ThemeMetric CREATE_NEW_SCREEN; diff --git a/stepmania/src/WorkoutManager.cpp b/stepmania/src/WorkoutManager.cpp index 446558abe7..5364ba832b 100644 --- a/stepmania/src/WorkoutManager.cpp +++ b/stepmania/src/WorkoutManager.cpp @@ -22,13 +22,23 @@ bool EditCourseUtil::Save( Course *pCourse ) return EditCourseUtil::RenameAndSave( pCourse, pCourse->GetDisplayFullTitle() ); } -bool EditCourseUtil::RenameAndSave( Course *pCourse, RString sName ) +bool EditCourseUtil::RenameAndSave( Course *pCourse, RString sNewName ) { - ASSERT( !sName.empty() ); + ASSERT( !sNewName.empty() ); EditCourseUtil::s_bNewCourseNeedsName = false; - RString sNewFilePath = PROFILEMAN->GetProfileDir(ProfileSlot_Machine) + EDIT_COURSES_SUBDIR + sName + ".crs"; + RString sNewFilePath; + if( pCourse->IsAnEdit() ) + { + sNewFilePath = PROFILEMAN->GetProfileDir(ProfileSlot_Machine) + EDIT_COURSES_SUBDIR + sNewName + ".crs"; + } + else + { + RString sDir, sName, sExt; + splitpath( pCourse->m_sPath, sDir, sName, sExt ); + sNewFilePath = sDir + sNewName + sExt; + } // remove the old file if the name is changing if( !pCourse->m_sPath.empty() && sNewFilePath != pCourse->m_sPath ) @@ -37,7 +47,7 @@ bool EditCourseUtil::RenameAndSave( Course *pCourse, RString sName ) FlushDirCache(); } - pCourse->m_sMainTitle = sName; + pCourse->m_sMainTitle = sNewName; pCourse->m_sPath = sNewFilePath; return CourseWriterCRS::Write( *pCourse, pCourse->m_sPath, false ); } @@ -46,8 +56,17 @@ bool EditCourseUtil::RemoveAndDeleteFile( Course *pCourse ) { if( !FILEMAN->Remove( pCourse->m_sPath ) ) return false; + FILEMAN->Remove( pCourse->GetCacheFilePath() ); FlushDirCache(); - PROFILEMAN->LoadMachineProfile(); + if( pCourse->IsAnEdit() ) + { + PROFILEMAN->LoadMachineProfile(); + } + else + { + SONGMAN->DeleteCourse( pCourse ); + delete pCourse; + } return true; }