From fcae1e142ca02c4d57f8b348bac99505ac008df8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 3 Aug 2005 03:28:13 +0000 Subject: [PATCH] more work on course editor --- stepmania/src/CourseUtil.cpp | 6 ++ stepmania/src/CourseUtil.h | 3 + stepmania/src/GameState.cpp | 2 +- stepmania/src/GameState.h | 1 + stepmania/src/ScreenOptionsEditCourse.cpp | 9 ++- stepmania/src/ScreenOptionsManageCourses.cpp | 68 ++++++++++++++++---- 6 files changed, 73 insertions(+), 16 deletions(-) diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 4514b14742..12946713a3 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -9,6 +9,7 @@ #include "GameState.h" #include "Style.h" #include "Foreach.h" +#include "GameState.h" // @@ -188,6 +189,11 @@ void CourseUtil::SortByMostRecentlyPlayedForMachine( vector &vpCoursesI course_sort_val.clear(); } +void CourseUtil::MakeDefaultEditCourseEntry( CourseEntry& out ) +{ + out.pSong = GAMESTATE->GetDefaultSong(); + out.baseDifficulty = DIFFICULTY_MEDIUM; +} ////////////////////////////////// diff --git a/stepmania/src/CourseUtil.h b/stepmania/src/CourseUtil.h index f5f7877918..c8e6e9875d 100644 --- a/stepmania/src/CourseUtil.h +++ b/stepmania/src/CourseUtil.h @@ -8,6 +8,7 @@ class Course; class Profile; struct XNode; +class CourseEntry; namespace CourseUtil { @@ -22,6 +23,8 @@ namespace CourseUtil void SortByMostRecentlyPlayedForMachine( vector &vpCoursesInOut ); void MoveRandomToEnd( vector &vpCoursesInOut ); + + void MakeDefaultEditCourseEntry( CourseEntry &out ); }; class CourseID diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 906ecac2a0..fc457f829e 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -57,7 +57,7 @@ SortOrder GetDefaultSort() return StringToSortOrder( DEFAULT_SORT ); } ThemeMetric DEFAULT_SONG ("GameState","DefaultSong"); -Song* GetDefaultSong() +Song* GameState::GetDefaultSong() const { SongID sid; sid.LoadFromDir( DEFAULT_SONG ); diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 7715b3b0ff..2db9a8dad9 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -42,6 +42,7 @@ public: void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized void EndGame(); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits void SaveCurrentSettingsToProfile( PlayerNumber pn ); // called at the beginning of each stage + Song* GetDefaultSong() const; void Update( float fDelta ); diff --git a/stepmania/src/ScreenOptionsEditCourse.cpp b/stepmania/src/ScreenOptionsEditCourse.cpp index 8e82d3c7b3..ab930f5118 100644 --- a/stepmania/src/ScreenOptionsEditCourse.cpp +++ b/stepmania/src/ScreenOptionsEditCourse.cpp @@ -9,6 +9,7 @@ #include "song.h" #include "ScreenMiniMenu.h" #include "ScreenPrompt.h" +#include "CourseUtil.h" enum EditCourseRow { @@ -140,7 +141,9 @@ void ScreenOptionsEditCourse::HandleScreenMessage( const ScreenMessage SM ) ScreenPrompt::Prompt( SM_None, sError ); return; } - pCourse->m_vEntries.insert( pCourse->m_vEntries.begin() + GetCourseEntryIndexWithFocus(), CourseEntry() ); + CourseEntry ce; + CourseUtil::MakeDefaultEditCourseEntry( ce ); + pCourse->m_vEntries.insert( pCourse->m_vEntries.begin() + GetCourseEntryIndexWithFocus(), ce ); SCREENMAN->SetNewScreen( this->m_sName ); // reload } break; @@ -252,7 +255,9 @@ void ScreenOptionsEditCourse::ProcessMenuStart( PlayerNumber pn, const InputEven ScreenPrompt::Prompt( SM_None, sError ); return; } - pCourse->m_vEntries.push_back( CourseEntry() ); + CourseEntry ce; + CourseUtil::MakeDefaultEditCourseEntry( ce ); + pCourse->m_vEntries.push_back( ce ); GAMESTATE->m_iEditCourseEntryIndex.Set( pCourse->m_vEntries.size()-1 ); SCREENMAN->SetNewScreen( this->m_sName ); // reload } diff --git a/stepmania/src/ScreenOptionsManageCourses.cpp b/stepmania/src/ScreenOptionsManageCourses.cpp index 71397faf92..073c37df19 100644 --- a/stepmania/src/ScreenOptionsManageCourses.cpp +++ b/stepmania/src/ScreenOptionsManageCourses.cpp @@ -10,6 +10,7 @@ #include "ScreenMiniMenu.h" #include "GameManager.h" #include "Difficulty.h" +#include "CourseUtil.h" static void RefreshTrail() { @@ -82,7 +83,8 @@ void ScreenOptionsEditCourseSubMenu::MenuSelect( PlayerNumber pn, const InputEve -AutoScreenMessage( SM_BackFromEnterName ) +AutoScreenMessage( SM_BackFromEnterNameForNew ) +AutoScreenMessage( SM_BackFromRename ) AutoScreenMessage( SM_BackFromDeleteConfirm ) AutoScreenMessage( SM_BackFromContextMenu ) @@ -105,6 +107,28 @@ static MenuDef g_TempMenu( "ScreenMiniMenuContext" ); + +static bool ValidateEditCourseName( const CString &sAnswer, CString &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 comepare name against ourself + + if( (*c)->GetDisplayFullTitle() == sAnswer ) + return false; + } + + return true; +} + + REGISTER_SCREEN_CLASS( ScreenOptionsManageCourses ); ScreenOptionsManageCourses::ScreenOptionsManageCourses( CString sName ) : ScreenOptionsEditCourseSubMenu( sName ) { @@ -212,7 +236,7 @@ void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM ) return; // don't call base } } - else if( SM == SM_BackFromEnterName ) + else if( SM == SM_BackFromEnterNameForNew ) { if( !ScreenTextEntry::s_bCancelledLast ) { @@ -225,8 +249,9 @@ void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM ) Course *pCourse = new Course; pCourse->m_sMainTitle = ScreenTextEntry::s_sLastAnswer; pCourse->SetLoadedFromProfile( PROFILE_SLOT_MACHINE ); - pCourse->m_vEntries.push_back( CourseEntry() ); // one blank entry - pCourse->m_vEntries[0].baseDifficulty = DIFFICULTY_MEDIUM; + CourseEntry ce; + CourseUtil::MakeDefaultEditCourseEntry( ce ); + pCourse->m_vEntries.push_back( ce ); SONGMAN->AddCourse( pCourse ); GAMESTATE->m_pCurCourse.Set( pCourse ); @@ -235,6 +260,17 @@ void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM ) this->HandleScreenMessage( SM_GoToNextScreen ); } } + else if( SM == SM_BackFromRename ) + { + if( !ScreenTextEntry::s_bCancelledLast ) + { + ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this + + GAMESTATE->m_pCurCourse->m_sMainTitle = ScreenTextEntry::s_sLastAnswer; + + SCREENMAN->SetNewScreen( this->m_sName ); // reload + } + } else if( SM == SM_BackFromDeleteConfirm ) { if( ScreenPrompt::s_LastAnswer == ANSWER_YES ) @@ -261,13 +297,12 @@ void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM ) break; case CourseAction_Rename: { - CString sCurrentProfileName = "New Course"; ScreenTextEntry::TextEntry( - SM_BackFromEnterName, - "Enter a name for a new course.", - sCurrentProfileName, + SM_BackFromRename, + "Enter a name for the course.", + GAMESTATE->m_pCurCourse->GetDisplayFullTitle(), MAX_EDIT_COURSE_TITLE_LENGTH, - SongManager::ValidateEditCourseName ); + ValidateEditCourseName ); } break; case CourseAction_Delete: @@ -301,13 +336,20 @@ void ScreenOptionsManageCourses::ProcessMenuStart( PlayerNumber pn, const InputE if( iCurRow == 0 ) // "create new" { - CString sCurrentProfileName = "New Course"; + CString sDefaultName; + CString sThrowAway; + for( int i=1; i<=9999; i++ ) + { + sDefaultName = ssprintf( "NewCourse%04d", i ); + if( ValidateEditCourseName(sDefaultName,sThrowAway) ) + break; + } ScreenTextEntry::TextEntry( - SM_BackFromEnterName, + SM_BackFromEnterNameForNew, "Enter a name for a new course.", - sCurrentProfileName, + sDefaultName, MAX_EDIT_COURSE_TITLE_LENGTH, - SongManager::ValidateEditCourseName ); + ValidateEditCourseName ); } else if( iCurRow == (int)m_pRows.size()-1 ) // "done" {