set default profile ID when creating profiles
This commit is contained in:
@@ -113,10 +113,10 @@ private:
|
||||
template <class T>
|
||||
class Preference1D
|
||||
{
|
||||
public:
|
||||
typedef Preference<T> PreferenceT;
|
||||
vector<PreferenceT*> m_v;
|
||||
|
||||
public:
|
||||
Preference1D( void pfn(size_t i, RString &sNameOut, T &defaultValueOut ), size_t N )
|
||||
{
|
||||
for( size_t i=0; i<N; ++i )
|
||||
|
||||
@@ -486,6 +486,14 @@ bool ProfileManager::DeleteLocalProfile( RString sProfileID )
|
||||
if( DeleteRecursive(sProfileDir) )
|
||||
{
|
||||
g_vLocalProfile.erase( i );
|
||||
|
||||
// Delete all references to this profileID
|
||||
FOREACH_CONST( Preference<RString>*, PROFILEMAN->m_sDefaultLocalProfileID.m_v, i )
|
||||
{
|
||||
if( (*i)->Get() == sProfileID )
|
||||
(*i)->Set( "" );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -495,6 +503,8 @@ bool ProfileManager::DeleteLocalProfile( RString sProfileID )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOG->Warn( "DeleteLocalProfile: ProfileID '%s' doesn't exist", sProfileID.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ void ScreenOptionsManageProfiles::BeginScreen()
|
||||
|
||||
static LocalizedString CONFIRM_DELETE_PROFILE ( "ScreenOptionsManageProfiles", "Are you sure you want to delete the profile '%s'?" );
|
||||
static LocalizedString CONFIRM_CLEAR_PROFILE ( "ScreenOptionsManageProfiles", "Are you sure you want to clear all data in the profile '%s'?" );
|
||||
static LocalizedString ENTER_PROFILE_NAME ( "ScreenOptionsManageProfiles", "Enter a name for the profile." );
|
||||
static LocalizedString ENTER_PROFILE_NAME ( "ScreenOptionsManageProfiles", "Enter a name for the profile." );
|
||||
void ScreenOptionsManageProfiles::HandleScreenMessage( const ScreenMessage SM )
|
||||
{
|
||||
if( SM == SM_GoToNextScreen )
|
||||
@@ -183,11 +183,31 @@ void ScreenOptionsManageProfiles::HandleScreenMessage( const ScreenMessage SM )
|
||||
RString sNewName = ScreenTextEntry::s_sLastAnswer;
|
||||
ASSERT( GAMESTATE->m_sEditLocalProfileID.Get().empty() );
|
||||
|
||||
int iNumProfiles = PROFILEMAN->GetNumLocalProfiles();
|
||||
|
||||
// create
|
||||
RString sProfileID;
|
||||
PROFILEMAN->CreateLocalProfile( ScreenTextEntry::s_sLastAnswer, sProfileID );
|
||||
PROFILEMAN->CreateLocalProfile( ScreenTextEntry::s_sLastAnswer, sProfileID ); // TODO: Check return value
|
||||
GAMESTATE->m_sEditLocalProfileID.Set( sProfileID );
|
||||
|
||||
if( iNumProfiles < NUM_PLAYERS )
|
||||
{
|
||||
int iFirstUnused = -1;
|
||||
FOREACH_CONST( Preference<RString>*, PROFILEMAN->m_sDefaultLocalProfileID.m_v, i )
|
||||
{
|
||||
RString sLocalProfileID = (*i)->Get();
|
||||
if( sLocalProfileID.empty() )
|
||||
{
|
||||
iFirstUnused = i - PROFILEMAN->m_sDefaultLocalProfileID.m_v.begin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( iFirstUnused != -1 )
|
||||
{
|
||||
PROFILEMAN->m_sDefaultLocalProfileID.m_v[iFirstUnused]->Set( sProfileID );
|
||||
}
|
||||
}
|
||||
|
||||
SCREENMAN->SetNewScreen( this->m_sName ); // reload
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user