working on ScreenOptionsProfiles

This commit is contained in:
Chris Danford
2005-07-05 23:13:49 +00:00
parent c69c3af4b9
commit 7c6dbc102b
10 changed files with 158 additions and 51 deletions
+9 -2
View File
@@ -4496,14 +4496,18 @@ NextScreen=@GetGameplayNextScreen()
Class=ScreenCourseManager Class=ScreenCourseManager
Fallback=ScreenOptions Fallback=ScreenOptions
TimerSeconds=0 TimerSeconds=0
ShowExitRow=0
ThemeItems=0 ThemeItems=0
[ScreenEditCourse] [ScreenEditCourse]
Class=ScreenEditCourse Class=ScreenEditCourse
Fallback=ScreenOptions Fallback=ScreenOptions
TimerSeconds=0 TimerSeconds=0
ShowExitRow=0 ThemeItems=0
[ScreenEditCourseEntry]
Class=ScreenEditCourseEntry
Fallback=ScreenOptions
TimerSeconds=0
ThemeItems=0 ThemeItems=0
[ScreenMiniMenuProfiles] [ScreenMiniMenuProfiles]
@@ -4515,3 +4519,6 @@ Class=ScreenOptionsProfiles
Fallback=ScreenOptionsSubmenu Fallback=ScreenOptionsSubmenu
StyleIcon=0 StyleIcon=0
TimerSeconds=0 TimerSeconds=0
[ProfileManager]
NewProfileDefaultName=New
+31 -9
View File
@@ -31,6 +31,9 @@ ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our
#define MACHINE_PROFILE_DIR "Data/MachineProfile/" #define MACHINE_PROFILE_DIR "Data/MachineProfile/"
const CString LAST_GOOD_DIR = "LastGood/"; const CString LAST_GOOD_DIR = "LastGood/";
static ThemeMetric<CString> NEW_PROFILE_DEFAULT_NAME( "ProfileManager", "NewProfileDefaultName" );
// Directories to search for a profile if m_sMemoryCardProfileSubdir doesn't // Directories to search for a profile if m_sMemoryCardProfileSubdir doesn't
// exist, separated by ";": // exist, separated by ";":
static Preference<CString> g_sMemoryCardProfileImportSubdirs( "MemoryCardProfileImportSubdirs", "" ); static Preference<CString> g_sMemoryCardProfileImportSubdirs( "MemoryCardProfileImportSubdirs", "" );
@@ -69,19 +72,22 @@ void ProfileManager::GetLocalProfileIDs( vector<CString> &asProfileIDsOut ) cons
void ProfileManager::GetLocalProfileNames( vector<CString> &asNamesOut ) const void ProfileManager::GetLocalProfileNames( vector<CString> &asNamesOut ) const
{ {
asNamesOut.clear();
CStringArray vsProfileIDs; CStringArray vsProfileIDs;
GetLocalProfileIDs( vsProfileIDs ); GetLocalProfileIDs( vsProfileIDs );
LOG->Trace("GetLocalProfileNames: %u", unsigned(vsProfileIDs.size())); LOG->Trace("GetLocalProfileNames: %u", unsigned(vsProfileIDs.size()));
for( unsigned i=0; i<vsProfileIDs.size(); i++ ) FOREACH_CONST( CString, vsProfileIDs, s )
{ asNamesOut.push_back( ProfileIDToName(*s) );
CString sProfileID = vsProfileIDs[i];
CString sProfileDir = USER_PROFILES_DIR + sProfileID + "/";
CString sDisplayName = Profile::GetProfileDisplayNameFromDir( sProfileDir );
LOG->Trace(" '%s'", sDisplayName.c_str());
asNamesOut.push_back( sDisplayName );
}
} }
CString ProfileManager::ProfileIDToName( const CString &sProfileID ) const
{
CString sProfileDir = USER_PROFILES_DIR + sProfileID + "/";
CString sDisplayName = Profile::GetProfileDisplayNameFromDir( sProfileDir );
LOG->Trace(" '%s'", sDisplayName.c_str());
return sDisplayName;
}
int ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) int ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard )
{ {
@@ -327,7 +333,7 @@ bool ProfileManager::RenameLocalProfile( CString sProfileID, CString sNewName )
{ {
ASSERT( !sProfileID.empty() ); ASSERT( !sProfileID.empty() );
CString sProfileDir = USER_PROFILES_DIR + sProfileID; CString sProfileDir = USER_PROFILES_DIR + sProfileID + "/";
Profile pro; Profile pro;
Profile::LoadResult lr; Profile::LoadResult lr;
@@ -632,6 +638,22 @@ bool ProfileManager::IsPersistentProfile( ProfileSlot slot ) const
} }
} }
CString ProfileManager::GetNewProfileDefaultName() const
{
vector<CString> vsNames;
GetLocalProfileNames( vsNames );
CString sPotentialName;
for( int i=1; i<1000; i++ )
{
sPotentialName = ssprintf( "%s%04d", NEW_PROFILE_DEFAULT_NAME.GetValue().c_str(), i );
bool bNameIsUsed = find( vsNames.begin(), vsNames.end(), sPotentialName ) != vsNames.end();
if( !bNameIsUsed )
return sPotentialName;
}
return sPotentialName;
}
// lua start // lua start
#include "LuaBinding.h" #include "LuaBinding.h"
+3
View File
@@ -30,6 +30,9 @@ public:
void GetLocalProfileIDs( vector<CString> &asProfileIDsOut ) const; void GetLocalProfileIDs( vector<CString> &asProfileIDsOut ) const;
void GetLocalProfileNames( vector<CString> &asNamesOut ) const; void GetLocalProfileNames( vector<CString> &asNamesOut ) const;
CString ProfileIDToName( const CString &sProfileID ) const;
CString GetNewProfileDefaultName() const;
bool LoadFirstAvailableProfile( PlayerNumber pn ); // memory card or local profile bool LoadFirstAvailableProfile( PlayerNumber pn ); // memory card or local profile
bool LoadLocalProfileFromMachine( PlayerNumber pn ); bool LoadLocalProfileFromMachine( PlayerNumber pn );
+8 -8
View File
@@ -1865,49 +1865,49 @@ void ScreenEdit::OnSnapModeChange()
// Begin helper functions for InputEdit // Begin helper functions for InputEdit
void ChangeDescription( CString sNew ) void ChangeDescription( const CString &sNew )
{ {
Steps* pSteps = GAMESTATE->m_pCurSteps[PLAYER_1]; Steps* pSteps = GAMESTATE->m_pCurSteps[PLAYER_1];
pSteps->SetDescription(sNew); pSteps->SetDescription(sNew);
} }
void ChangeMainTitle( CString sNew ) void ChangeMainTitle( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sMainTitle = sNew; pSong->m_sMainTitle = sNew;
} }
void ChangeSubTitle( CString sNew ) void ChangeSubTitle( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sSubTitle = sNew; pSong->m_sSubTitle = sNew;
} }
void ChangeArtist( CString sNew ) void ChangeArtist( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sArtist = sNew; pSong->m_sArtist = sNew;
} }
void ChangeCredit( CString sNew ) void ChangeCredit( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sCredit = sNew; pSong->m_sCredit = sNew;
} }
void ChangeMainTitleTranslit( CString sNew ) void ChangeMainTitleTranslit( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sMainTitleTranslit = sNew; pSong->m_sMainTitleTranslit = sNew;
} }
void ChangeSubTitleTranslit( CString sNew ) void ChangeSubTitleTranslit( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sSubTitleTranslit = sNew; pSong->m_sSubTitleTranslit = sNew;
} }
void ChangeArtistTranslit( CString sNew ) void ChangeArtistTranslit( const CString &sNew )
{ {
Song* pSong = GAMESTATE->m_pCurSong; Song* pSong = GAMESTATE->m_pCurSong;
pSong->m_sArtistTranslit = sNew; pSong->m_sArtistTranslit = sNew;
+2 -2
View File
@@ -157,7 +157,7 @@ static CString GetCopyDescription( const Steps *pSourceSteps )
return s; return s;
} }
static bool ValidateCurrentStepsDescription( CString s, CString &sErrorOut ) static bool ValidateCurrentStepsDescription( const CString &s, CString &sErrorOut )
{ {
ASSERT( GAMESTATE->m_pCurSteps[0]->GetDifficulty() == DIFFICULTY_EDIT ); ASSERT( GAMESTATE->m_pCurSteps[0]->GetDifficulty() == DIFFICULTY_EDIT );
@@ -176,7 +176,7 @@ static bool ValidateCurrentStepsDescription( CString s, CString &sErrorOut )
return true; return true;
} }
static void SetCurrentStepsDescription( CString s ) static void SetCurrentStepsDescription( const CString &s )
{ {
GAMESTATE->m_pCurSteps[0]->SetDescription( s ); GAMESTATE->m_pCurSteps[0]->SetDescription( s );
} }
+85 -15
View File
@@ -4,10 +4,40 @@
#include "ScreenMiniMenu.h" #include "ScreenMiniMenu.h"
#include "ProfileManager.h" #include "ProfileManager.h"
#include "ScreenTextEntry.h" #include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
#include "RageUtil.h" #include "RageUtil.h"
AutoScreenMessage( SM_BackFromCreateNewName ) AutoScreenMessage( SM_BackFromEnterName )
AutoScreenMessage( SM_BackFromProfileContextMenu ) AutoScreenMessage( SM_BackFromProfileContextMenu )
AutoScreenMessage( SM_BackFromDelete )
CString ScreenOptionsProfiles::s_sCurrentProfileID = "";
const int PROFILE_MAX_NAME_LENGTH = 64;
static bool ValidateProfileName( const CString &sAnswer, CString &sErrorOut )
{
CString sCurrentProfileOldName = PROFILEMAN->ProfileIDToName( ScreenOptionsProfiles::s_sCurrentProfileID );
vector<CString> vsProfileNames;
PROFILEMAN->GetLocalProfileNames( vsProfileNames );
bool bAlreadyAProfileWithThisName = find( vsProfileNames.begin(), vsProfileNames.end(), sAnswer ) != vsProfileNames.end();
if( sAnswer == "" )
{
sErrorOut = "Profile name cannot be blank.";
return false;
}
else if( sAnswer == sCurrentProfileOldName )
{
return true;
}
else if( bAlreadyAProfileWithThisName )
{
sErrorOut = "There is already another profile with this name. Please choose a different name.";
return false;
}
return true;
}
enum ContextMenuAnswer enum ContextMenuAnswer
{ {
@@ -19,10 +49,10 @@ enum ContextMenuAnswer
static MenuDef g_ProfileContextMenu( static MenuDef g_ProfileContextMenu(
"ScreenMiniMenuProfiles", "ScreenMiniMenuProfiles",
MenuRowDef( -1, "Edit", true, EDIT_MODE_PRACTICE, 0, "" ), MenuRowDef( A_EDIT, "Edit", true, EDIT_MODE_PRACTICE, 0, "" ),
MenuRowDef( -1, "Rename", true, EDIT_MODE_PRACTICE, 0, "" ), MenuRowDef( A_RENAME, "Rename", true, EDIT_MODE_PRACTICE, 0, "" ),
MenuRowDef( -1, "Delete", true, EDIT_MODE_PRACTICE, 0, "" ), MenuRowDef( A_DELETE, "Delete", true, EDIT_MODE_PRACTICE, 0, "" ),
MenuRowDef( -1, "Cancel", true, EDIT_MODE_PRACTICE, 0, "" ) MenuRowDef( A_CANCEL, "Cancel", true, EDIT_MODE_PRACTICE, 0, "" )
); );
REGISTER_SCREEN_CLASS( ScreenOptionsProfiles ); REGISTER_SCREEN_CLASS( ScreenOptionsProfiles );
@@ -93,16 +123,31 @@ void ScreenOptionsProfiles::GoToPrevScreen()
void ScreenOptionsProfiles::HandleScreenMessage( const ScreenMessage SM ) void ScreenOptionsProfiles::HandleScreenMessage( const ScreenMessage SM )
{ {
if( SM == SM_BackFromCreateNewName ) if( SM == SM_BackFromEnterName )
{ {
if( !ScreenTextEntry::s_bCancelledLast && ScreenTextEntry::s_sLastAnswer != "" ) if( !ScreenTextEntry::s_bCancelledLast )
{ {
ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this
CString sNewName = ScreenTextEntry::s_sLastAnswer; CString sNewName = ScreenTextEntry::s_sLastAnswer;
bool bResult = PROFILEMAN->CreateLocalProfile( sNewName ); if( s_sCurrentProfileID.empty() )
if( bResult ) {
SCREENMAN->SetNewScreen( m_sName ); // reload // create
bool bResult = PROFILEMAN->CreateLocalProfile( sNewName );
if( bResult )
SCREENMAN->SetNewScreen( m_sName ); // reload
else
ScreenPrompt::Prompt( SM_None, ssprintf("Error creating profile '%s'.", sNewName.c_str()) );
}
else else
SCREENMAN->Prompt( SM_None, ssprintf("Error creating profile '%s'.", sNewName.c_str()) ); {
// rename
bool bResult = PROFILEMAN->RenameLocalProfile( s_sCurrentProfileID, sNewName );
if( bResult )
SCREENMAN->SetNewScreen( m_sName ); // reload
else
ScreenPrompt::Prompt( SM_None, ssprintf("Error renaming profile '%s'.", sNewName.c_str()) );
}
} }
} }
else if( SM == SM_BackFromProfileContextMenu ) else if( SM == SM_BackFromProfileContextMenu )
@@ -112,13 +157,34 @@ void ScreenOptionsProfiles::HandleScreenMessage( const ScreenMessage SM )
default: default:
ASSERT(0); ASSERT(0);
case A_EDIT: case A_EDIT:
SCREENMAN->SetNewScreen( "ScreenOptionsEditProfile" );
break;
case A_RENAME: case A_RENAME:
{
CString sCurrentProfileName = PROFILEMAN->ProfileIDToName( s_sCurrentProfileID );
ScreenTextEntry::TextEntry( SM_BackFromEnterName, "Enter a name for a new profile.", sCurrentProfileName, PROFILE_MAX_NAME_LENGTH, ValidateProfileName );
}
break;
case A_DELETE: case A_DELETE:
{
CString sCurrentProfileName = PROFILEMAN->ProfileIDToName( s_sCurrentProfileID );
CString sMessage = ssprintf( "Are you sure you want to delete the profile '%s'?", sCurrentProfileName.c_str() );
ScreenPrompt::Prompt( SM_BackFromDelete, sMessage, PROMPT_YES_NO );
}
break;
case A_CANCEL: case A_CANCEL:
SCREENMAN->PlayInvalidSound(); SCREENMAN->PlayInvalidSound();
break; break;
} }
} }
else if( SM == SM_BackFromDelete )
{
if( ScreenPrompt::s_LastAnswer == ANSWER_YES )
{
PROFILEMAN->DeleteLocalProfile( s_sCurrentProfileID );
SCREENMAN->SetNewScreen( m_sName ); // reload
}
}
} }
void ScreenOptionsProfiles::ProcessMenuStart( PlayerNumber pn, const InputEventType type ) void ScreenOptionsProfiles::ProcessMenuStart( PlayerNumber pn, const InputEventType type )
@@ -128,17 +194,21 @@ void ScreenOptionsProfiles::ProcessMenuStart( PlayerNumber pn, const InputEventT
if( iRow == 0 ) // "create new" if( iRow == 0 ) // "create new"
{ {
//ScreenOptions::BeginFadingOut(); s_sCurrentProfileID = "";
SCREENMAN->TextEntry( SM_BackFromCreateNewName, "Enter a name for a new profile.", "", 64 ); ScreenTextEntry::TextEntry( SM_BackFromEnterName, "Enter a name for a new profile.", PROFILEMAN->GetNewProfileDefaultName(), PROFILE_MAX_NAME_LENGTH, ValidateProfileName );
} }
else if( row.GetRowType() == OptionRow::ROW_EXIT ) else if( row.GetRowType() == OptionRow::ROW_EXIT )
{ {
s_sCurrentProfileID = "";
ScreenOptions::ProcessMenuStart( pn, type ); ScreenOptions::ProcessMenuStart( pn, type );
} }
else else
{ {
SCREENMAN->MiniMenu( &g_ProfileContextMenu, SM_BackFromProfileContextMenu ); int iProfileIndex = iRow - 1;
vector<CString> vsProfileIDs;
PROFILEMAN->GetLocalProfileIDs( vsProfileIDs );
s_sCurrentProfileID = vsProfileIDs[ iProfileIndex ];
ScreenMiniMenu::MiniMenu( &g_ProfileContextMenu, SM_BackFromProfileContextMenu );
} }
} }
+2
View File
@@ -10,6 +10,8 @@ public:
virtual void Init(); virtual void Init();
virtual ~ScreenOptionsProfiles(); virtual ~ScreenOptionsProfiles();
static CString s_sCurrentProfileID;
protected: protected:
private: private:
virtual void ImportOptions( int row, const vector<PlayerNumber> &vpns ); virtual void ImportOptions( int row, const vector<PlayerNumber> &vpns );
+1 -1
View File
@@ -13,7 +13,7 @@ static const float LineHeight = 50;
CString CustomText; CString CustomText;
void ChangeText(CString txt) void ChangeText(const CString &txt)
{ {
CustomText = txt; CustomText = txt;
} }
+4 -4
View File
@@ -43,8 +43,8 @@ void ScreenTextEntry::TextEntry(
CString sQuestion, CString sQuestion,
CString sInitialAnswer, CString sInitialAnswer,
int iMaxInputLength, int iMaxInputLength,
bool(*Validate)(CString sAnswer,CString &sErrorOut), bool(*Validate)(const CString &sAnswer,CString &sErrorOut),
void(*OnOK)(CString sAnswer), void(*OnOK)(const CString &sAnswer),
void(*OnCancel)(), void(*OnCancel)(),
bool bPassword bool bPassword
) )
@@ -82,8 +82,8 @@ ScreenTextEntry::ScreenTextEntry(
CString sQuestion, CString sQuestion,
CString sInitialAnswer, CString sInitialAnswer,
int iMaxInputLength, int iMaxInputLength,
bool(*Validate)(CString sAnswer,CString &sErrorOut), bool(*Validate)(const CString &sAnswer,CString &sErrorOut),
void(*OnOK)(CString sAnswer), void(*OnOK)(const CString &sAnswer),
void(*OnCancel)(), void(*OnCancel)(),
bool bPassword ) : bool bPassword ) :
Screen( sClassName ) Screen( sClassName )
+12 -9
View File
@@ -32,12 +32,15 @@ public:
CString sQuestion, CString sQuestion,
CString sInitialAnswer, CString sInitialAnswer,
int iMaxInputLength, int iMaxInputLength,
bool(*Validate)(CString sAnswer,CString &sErrorOut) = NULL, bool(*Validate)(const CString &sAnswer,CString &sErrorOut) = NULL,
void(*OnOK)(CString sAnswer) = NULL, void(*OnOK)(const CString &sAnswer) = NULL,
void(*OnCanel)() = NULL, void(*OnCanel)() = NULL,
bool bPassword = false bool bPassword = false );
); static void Password(
static void Password( ScreenMessage smSendOnPop, const CString &sQuestion, void(*OnOK)(CString sPassword) = NULL, void(*OnCanel)() = NULL ) ScreenMessage smSendOnPop,
const CString &sQuestion,
void(*OnOK)(const CString &sPassword) = NULL,
void(*OnCanel)() = NULL )
{ {
TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true ); TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true );
} }
@@ -48,8 +51,8 @@ public:
CString sQuestion, CString sQuestion,
CString sInitialAnswer, CString sInitialAnswer,
int iMaxInputLength, int iMaxInputLength,
bool(*Validate)(CString sAnswer,CString &sErrorOut) = NULL, bool(*Validate)(const CString &sAnswer,CString &sErrorOut) = NULL,
void(*OnOK)(CString sAnswer) = NULL, void(*OnOK)(const CString &sAnswer) = NULL,
void(*OnCanel)() = NULL, void(*OnCanel)() = NULL,
bool bPassword = false ); bool bPassword = false );
~ScreenTextEntry(); ~ScreenTextEntry();
@@ -91,8 +94,8 @@ protected:
AutoActor m_sprAnswerBox; AutoActor m_sprAnswerBox;
wstring m_sAnswer; wstring m_sAnswer;
BitmapText m_textAnswer; BitmapText m_textAnswer;
bool(*m_pValidate)( CString sAnswer, CString &sErrorOut ); bool(*m_pValidate)( const CString &sAnswer, CString &sErrorOut );
void(*m_pOnOK)( CString sAnswer ); void(*m_pOnOK)( const CString &sAnswer );
void(*m_pOnCancel)(); void(*m_pOnCancel)();
AutoActor m_sprCursor; AutoActor m_sprCursor;