Files
itgmania212121/stepmania/src/ScreenProfileOptions.cpp
T

265 lines
8.4 KiB
C++
Raw Normal View History

#include "global.h"
#include "ScreenProfileOptions.h"
#include "RageLog.h"
#include "ProfileManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
#include "ThemeManager.h"
#include "PrefsManager.h"
#include "ScreenManager.h"
2003-11-01 19:36:52 +00:00
#include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
#include "GameState.h"
2004-10-25 12:40:05 +00:00
enum {
PO_PLAYER1,
PO_PLAYER2,
PO_CREATE_NEW,
PO_DELETE_,
2003-09-08 07:21:41 +00:00
PO_RENAME_,
PO_OS_MOUNT_1,
PO_OS_MOUNT_2,
2003-09-30 05:25:47 +00:00
NUM_PROFILE_OPTIONS_LINES
};
2005-02-11 07:50:26 +00:00
OptionRowDefinition g_ProfileOptionsLines[NUM_PROFILE_OPTIONS_LINES] = {
OptionRowDefinition( "Player1Profile", true ),
OptionRowDefinition( "Player2Profile", true ),
OptionRowDefinition( "CreateNew", true, "PRESS START" ),
2005-02-11 07:50:26 +00:00
OptionRowDefinition( "Delete", true ),
OptionRowDefinition( "Rename", true ),
OptionRowDefinition( "OsMountPlayer1", true, "" ),
OptionRowDefinition( "OsMountPlayer2", true, "" ),
};
AutoScreenMessage( SM_DoneCreating )
AutoScreenMessage( SM_DoneRenaming )
AutoScreenMessage( SM_DoneDeleting )
2003-11-01 19:36:52 +00:00
2004-11-26 17:28:47 +00:00
REGISTER_SCREEN_CLASS( ScreenProfileOptions );
2003-09-27 22:30:51 +00:00
ScreenProfileOptions::ScreenProfileOptions( CString sClassName ) : ScreenOptions( sClassName )
{
LOG->Trace( "ScreenProfileOptions::ScreenProfileOptions()" );
}
void ScreenProfileOptions::Init()
{
ScreenOptions::Init();
g_ProfileOptionsLines[PO_PLAYER1].choices.clear();
2003-09-08 07:21:41 +00:00
g_ProfileOptionsLines[PO_PLAYER1].choices.push_back( "-NONE-" );
2003-12-07 08:19:10 +00:00
PROFILEMAN->GetLocalProfileNames( g_ProfileOptionsLines[PO_PLAYER1].choices );
g_ProfileOptionsLines[PO_PLAYER2].choices.clear();
2003-09-08 07:21:41 +00:00
g_ProfileOptionsLines[PO_PLAYER2].choices.push_back( "-NONE-" );
2003-12-07 08:19:10 +00:00
PROFILEMAN->GetLocalProfileNames( g_ProfileOptionsLines[PO_PLAYER2].choices );
g_ProfileOptionsLines[PO_DELETE_].choices.clear();
2003-09-08 07:21:41 +00:00
g_ProfileOptionsLines[PO_DELETE_].choices.push_back( "-NONE-" );
2003-12-07 08:19:10 +00:00
PROFILEMAN->GetLocalProfileNames( g_ProfileOptionsLines[PO_DELETE_].choices );
2003-09-08 07:21:41 +00:00
g_ProfileOptionsLines[PO_RENAME_].choices.clear();
g_ProfileOptionsLines[PO_RENAME_].choices.push_back( "-NONE-" );
2003-12-07 08:19:10 +00:00
PROFILEMAN->GetLocalProfileNames( g_ProfileOptionsLines[PO_RENAME_].choices );
if( PREFSMAN->m_sMemoryCardOsMountPoint[PLAYER_1].empty() )
g_ProfileOptionsLines[PO_OS_MOUNT_1].choices[0] = "-NOT SET IN INI-";
2003-11-01 22:04:43 +00:00
else
g_ProfileOptionsLines[PO_OS_MOUNT_1].choices[0] = PREFSMAN->m_sMemoryCardOsMountPoint[PLAYER_1];
2003-11-01 22:04:43 +00:00
if( PREFSMAN->m_sMemoryCardOsMountPoint[PLAYER_2].empty() )
g_ProfileOptionsLines[PO_OS_MOUNT_2].choices[0] = "-NOT SET IN INI-";
2003-11-01 22:04:43 +00:00
else
g_ProfileOptionsLines[PO_OS_MOUNT_2].choices[0] = PREFSMAN->m_sMemoryCardOsMountPoint[PLAYER_2];
2003-11-01 22:04:43 +00:00
//Enable all lines for all players
for ( unsigned int i = 0; i < NUM_PROFILE_OPTIONS_LINES; i++ )
FOREACH_PlayerNumber( pn )
g_ProfileOptionsLines[i].m_vEnabledForPlayers.insert( pn );
vector<OptionRowDefinition> vDefs( &g_ProfileOptionsLines[0], &g_ProfileOptionsLines[ARRAYSIZE(g_ProfileOptionsLines)] );
vector<OptionRowHandler*> vHands( vDefs.size(), NULL );
InitMenu( INPUTMODE_SHARE_CURSOR, vDefs, vHands );
2005-02-06 03:32:53 +00:00
SOUND->PlayMusic( THEME->GetPathS("ScreenMachineOptions","music") );
}
2005-04-03 06:21:02 +00:00
void ScreenProfileOptions::ImportOptions( int row, const vector<PlayerNumber> &vpns )
{
switch( row )
{
case PO_PLAYER1:
case PO_PLAYER2:
{
PlayerNumber pn = (PlayerNumber)(row - PO_PLAYER1);
vector<CString> vsProfiles;
PROFILEMAN->GetLocalProfileIDs( vsProfiles );
CStringArray::iterator iter = find(
vsProfiles.begin(),
vsProfiles.end(),
PREFSMAN->m_sDefaultLocalProfileID[pn] );
if( iter != vsProfiles.end() )
m_Rows[row]->SetOneSharedSelection( iter - vsProfiles.begin() + 1 );
}
break;
}
}
2005-04-03 06:21:02 +00:00
void ScreenProfileOptions::ExportOptions( int row, const vector<PlayerNumber> &vpns )
{
switch( row )
{
case PO_PLAYER1:
case PO_PLAYER2:
{
PlayerNumber pn = (PlayerNumber)(row - PO_PLAYER1);
vector<CString> vsProfiles;
PROFILEMAN->GetLocalProfileIDs( vsProfiles );
if( m_Rows[row]->GetOneSharedSelection() > 0 )
PREFSMAN->m_sDefaultLocalProfileID[pn] = vsProfiles[m_Rows[row]->GetOneSharedSelection()-1];
else
PREFSMAN->m_sDefaultLocalProfileID[pn] = "";
}
break;
}
}
2004-12-05 11:59:39 +00:00
void ScreenProfileOptions::GoToPrevScreen()
{
SCREENMAN->SetNewScreen( "ScreenOptionsMenu" );
}
2004-12-05 11:59:39 +00:00
void ScreenProfileOptions::GoToNextScreen()
{
PREFSMAN->SaveGlobalPrefsToDisk();
2004-12-05 11:59:39 +00:00
GoToPrevScreen();
}
2003-09-08 07:21:41 +00:00
2003-11-01 19:36:52 +00:00
void ScreenProfileOptions::HandleScreenMessage( const ScreenMessage SM )
2003-09-08 07:21:41 +00:00
{
if( SM == SM_DoneCreating)
2003-09-08 07:21:41 +00:00
{
2004-01-01 01:33:34 +00:00
if( !ScreenTextEntry::s_bCancelledLast && ScreenTextEntry::s_sLastAnswer != "" )
2003-09-08 07:21:41 +00:00
{
2003-11-01 22:04:43 +00:00
CString sNewName = ScreenTextEntry::s_sLastAnswer;
2003-12-07 08:19:10 +00:00
bool bResult = PROFILEMAN->CreateLocalProfile( sNewName );
2003-11-01 19:36:52 +00:00
if( bResult )
SCREENMAN->SetNewScreen( "ScreenProfileOptions" ); // reload
2003-09-08 07:21:41 +00:00
else
2003-11-01 22:04:43 +00:00
SCREENMAN->Prompt( SM_None, ssprintf("Error creating profile '%s'.", sNewName.c_str()) );
2003-09-08 07:21:41 +00:00
}
}
else if( SM == SM_DoneRenaming )
{
2003-11-01 19:36:52 +00:00
if( !ScreenTextEntry::s_bCancelledLast )
2003-09-08 07:21:41 +00:00
{
2003-12-16 07:20:45 +00:00
CString sProfileID = GetSelectedProfileID();
CString sName = GetSelectedProfileName();
2003-11-01 19:36:52 +00:00
CString sNewName = ScreenTextEntry::s_sLastAnswer;
2003-12-07 08:19:10 +00:00
bool bResult = PROFILEMAN->RenameLocalProfile( sProfileID, sNewName );
2003-11-01 19:36:52 +00:00
if( bResult )
SCREENMAN->SetNewScreen( "ScreenProfileOptions" ); // reload
2003-09-08 07:21:41 +00:00
else
2003-11-01 19:36:52 +00:00
SCREENMAN->Prompt( SM_None, ssprintf("Error renaming profile %s '%s'\nto '%s'.", sProfileID.c_str(), sName.c_str(), sNewName.c_str()) );
2003-09-08 07:21:41 +00:00
}
}
else if ( SM == SM_DoneDeleting )
{
if( ScreenPrompt::s_LastAnswer == ANSWER_YES )
2003-11-01 19:36:52 +00:00
{
2003-12-16 07:20:45 +00:00
CString sProfileID = GetSelectedProfileID();
CString sName = GetSelectedProfileName();
2003-12-07 08:19:10 +00:00
bool bResult = PROFILEMAN->DeleteLocalProfile( sProfileID );
2003-11-01 19:36:52 +00:00
if( bResult )
SCREENMAN->SetNewScreen( "ScreenProfileOptions" ); // reload
else
SCREENMAN->Prompt( SM_None, ssprintf("Error deleting profile %s '%s'.", sName.c_str(), sProfileID.c_str()) );
}
}
ScreenOptions::HandleScreenMessage( SM );
}
void ScreenProfileOptions::MenuStart( PlayerNumber pn, const InputEventType type )
2003-11-01 19:36:52 +00:00
{
switch( GetCurrentRow() )
{
case PO_CREATE_NEW:
2005-03-26 19:55:22 +00:00
SCREENMAN->TextEntry( SM_DoneCreating, "Enter a profile name", "", 12 );
2003-11-01 19:36:52 +00:00
break;
case PO_DELETE_:
2004-01-13 07:07:47 +00:00
{
const CString sProfileID = GetSelectedProfileID();
const CString sName = GetSelectedProfileName();
2003-11-01 19:36:52 +00:00
if( sProfileID=="" )
SCREENMAN->PlayInvalidSound();
2003-11-01 19:36:52 +00:00
else
SCREENMAN->Prompt( SM_DoneDeleting, ssprintf("Delete profile %s '%s'?",sProfileID.c_str(),sName.c_str()), PROMPT_YES_NO, ANSWER_NO );
2003-11-01 19:36:52 +00:00
break;
2004-01-13 07:07:47 +00:00
}
2003-11-01 19:36:52 +00:00
case PO_RENAME_:
2004-01-13 07:07:47 +00:00
{
const CString sProfileID = GetSelectedProfileID();
const CString sName = GetSelectedProfileName();
2003-11-01 19:36:52 +00:00
if( sProfileID=="" )
SCREENMAN->PlayInvalidSound();
2003-11-01 19:36:52 +00:00
else
2005-03-29 19:30:16 +00:00
SCREENMAN->TextEntry( SM_DoneRenaming, ssprintf("Rename profile %s '%s'",sProfileID.c_str(),sName.c_str()), sName, 12 );
2003-11-01 19:36:52 +00:00
break;
2004-01-13 07:07:47 +00:00
}
2003-09-08 07:21:41 +00:00
default:
ScreenOptions::MenuStart( pn, type );
2003-09-08 07:21:41 +00:00
}
}
2003-11-01 19:36:52 +00:00
CString ScreenProfileOptions::GetSelectedProfileID()
{
vector<CString> vsProfiles;
2003-12-07 08:19:10 +00:00
PROFILEMAN->GetLocalProfileIDs( vsProfiles );
2003-11-01 19:36:52 +00:00
2005-02-11 07:50:26 +00:00
const OptionRow &row = *m_Rows[GetCurrentRow()];
2004-01-13 07:07:47 +00:00
const int Selection = row.GetOneSharedSelection();
if( !Selection )
2003-11-01 19:36:52 +00:00
return "";
2004-01-13 07:07:47 +00:00
return vsProfiles[ Selection-1 ];
2003-11-01 19:36:52 +00:00
}
CString ScreenProfileOptions::GetSelectedProfileName()
{
2005-02-11 07:50:26 +00:00
const OptionRow &row = *m_Rows[GetCurrentRow()];
2004-01-13 07:07:47 +00:00
const int Selection = row.GetOneSharedSelection();
if( !Selection )
2003-11-01 19:36:52 +00:00
return "";
2004-01-13 07:07:47 +00:00
return g_ProfileOptionsLines[PO_PLAYER1].choices[ Selection ];
2003-11-01 19:36:52 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/