From 760ca931bcbbf6caecebf0e0ffcd20acbf560fe3 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 14 Aug 2005 20:31:20 +0000 Subject: [PATCH] fix local profile switching stuck if current local profileID doesn't exist fix local profile loading broken because dir missing trailing slash --- stepmania/src/Profile.cpp | 2 ++ stepmania/src/ProfileManager.cpp | 29 ++++++++++++++++------------- stepmania/src/ProfileManager.h | 3 ++- stepmania/src/ScreenTitleMenu.cpp | 28 +++++++++++++--------------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index ce07d4ddbc..1b563ebe77 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -794,6 +794,8 @@ ProfileLoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignature LOG->Trace( "Profile::LoadAllFromDir( %s )", sDir.c_str() ); + ASSERT( sDir.Right(1) == "/" ); + InitAll(); // Not critical if this fails diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index 5e1b7570bb..24d7b990f6 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -91,18 +91,14 @@ void ProfileManager::Init() { CString sCharacterID = FIXED_PROFILE_CHARACTER_ID( i ); Character *pCharacter = CHARMAN->GetCharacterFromID( sCharacterID ); - CString sThrowAway; - CreateLocalProfile( pCharacter->GetDisplayName(), sThrowAway ); + CString sProfileID; + CreateLocalProfile( pCharacter->GetDisplayName(), sProfileID ); + Profile* pProfile = GetLocalProfile( sProfileID ); + pProfile->m_sCharacterID = sCharacterID; + SaveLocalProfile( sProfileID ); } ASSERT( (int)g_vLocalProfile.size() == NUM_FIXED_PROFILES ); - - // apply fixed characters - for( int i=0; im_bSignProfileData ); + dap.profile.LoadAllFromDir( dap.sDir, PREFSMAN->m_bSignProfileData ); } } @@ -756,7 +752,7 @@ void ProfileManager::GetLocalProfileDisplayNames( vector &vsProfileDisp vsProfileDisplayNamesOut.push_back( i->profile.m_sDisplayName ); } -int ProfileManager::GetLocalProfileIndex( CString sProfileID ) const +int ProfileManager::GetLocalProfileIndexFromID( CString sProfileID ) const { CString sDir = LocalProfileIdToDir( sProfileID ); FOREACH_CONST( DirAndProfile, g_vLocalProfile, i ) @@ -767,6 +763,11 @@ int ProfileManager::GetLocalProfileIndex( CString sProfileID ) const return -1; } +Profile *ProfileManager::GetLocalProfileFromIndex( int iIndex ) +{ + return &g_vLocalProfile[iIndex].profile; +} + int ProfileManager::GetNumLocalProfiles() const { return g_vLocalProfile.size(); @@ -794,7 +795,8 @@ public: lua_pushnil(L ); return 1; } - static int GetLocalProfileIndex( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLocalProfileIndex(SArg(1)) ); return 1; } + static int GetLocalProfileFromIndex( T* p, lua_State *L ) { Profile *pProfile = p->GetLocalProfileFromIndex(IArg(1)); ASSERT(pProfile); pProfile->PushSelf(L); return 1; } + static int GetLocalProfileIndexFromID( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLocalProfileIndexFromID(SArg(1)) ); return 1; } static int GetNumLocalProfiles( T* p, lua_State *L ) { lua_pushnumber(L, p->GetNumLocalProfiles() ); return 1; } static void Register(lua_State *L) @@ -804,7 +806,8 @@ public: ADD_METHOD( GetMachineProfile ) ADD_METHOD( SaveMachineProfile ) ADD_METHOD( GetLocalProfile ) - ADD_METHOD( GetLocalProfileIndex ) + ADD_METHOD( GetLocalProfileFromIndex ) + ADD_METHOD( GetLocalProfileIndexFromID ) ADD_METHOD( GetNumLocalProfiles ) Luna::Register( L ); diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index 0cc6d4d990..8dfb726682 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -31,6 +31,7 @@ public: void RefreshLocalProfilesFromDisk(); const Profile *GetLocalProfile( const CString &sProfileID ) const; Profile *GetLocalProfile( const CString &sProfileID ) { return (Profile*) ((const ProfileManager *) this)->GetLocalProfile(sProfileID); } + Profile *GetLocalProfileFromIndex( int iIndex ); bool CreateLocalProfile( CString sName, CString &sProfileIDOut ); void AddLocalProfileByID( Profile *pProfile, CString sProfileID ); // transfers ownership of pProfile @@ -38,7 +39,7 @@ public: bool DeleteLocalProfile( CString sProfileID ); void GetLocalProfileIDs( vector &vsProfileIDsOut ) const; void GetLocalProfileDisplayNames( vector &vsProfileDisplayNamesOut ) const; - int GetLocalProfileIndex( CString sProfileID ) const; + int GetLocalProfileIndexFromID( CString sProfileID ) const; int GetNumLocalProfiles() const; diff --git a/stepmania/src/ScreenTitleMenu.cpp b/stepmania/src/ScreenTitleMenu.cpp index b4da9df67f..2fdbe05c8f 100644 --- a/stepmania/src/ScreenTitleMenu.cpp +++ b/stepmania/src/ScreenTitleMenu.cpp @@ -195,27 +195,25 @@ void ScreenTitleMenu::ChangeDefaultLocalProfile( PlayerNumber pn, int iDir ) int iIndex = 0; vector::const_iterator iter = find( vsProfileID.begin(), vsProfileID.end(), sCurrent ); if( iter != vsProfileID.end() ) - { iIndex = iter - vsProfileID.begin(); - for( int i=0; iGetNumLocalProfiles(); i++ ) - { - iIndex += iDir; - wrap( iIndex, vsProfileID.size() ); - sCurrent = vsProfileID[iIndex]; + for( int i=0; iGetNumLocalProfiles(); i++ ) + { + iIndex += iDir; + wrap( iIndex, vsProfileID.size() ); + sCurrent = vsProfileID[iIndex]; - bool bAnyOtherIsUsingThisProfile = false; - FOREACH_PlayerNumber( p ) + bool bAnyOtherIsUsingThisProfile = false; + FOREACH_PlayerNumber( p ) + { + if( p!=pn && PREFSMAN->GetDefaultLocalProfileID(p).Get() == sCurrent ) { - if( p!=pn && PREFSMAN->GetDefaultLocalProfileID(p).Get() == sCurrent ) - { - bAnyOtherIsUsingThisProfile = true; - break; - } - } - if( !bAnyOtherIsUsingThisProfile ) + bAnyOtherIsUsingThisProfile = true; break; + } } + if( !bAnyOtherIsUsingThisProfile ) + break; } m_soundProfileChange.Play();