Just one here.

This commit is contained in:
Jason Felds
2013-04-30 22:17:40 -04:00
parent 1c9e72440f
commit 3c026ced74
+247 -247
View File
@@ -1,247 +1,247 @@
#include "global.h" #include "global.h"
#include "ScreenOptionsMemoryCard.h" #include "ScreenOptionsMemoryCard.h"
#include "RageLog.h" #include "RageLog.h"
#include "arch/MemoryCard/MemoryCardDriver.h" #include "arch/MemoryCard/MemoryCardDriver.h"
#include "MemoryCardManager.h" #include "MemoryCardManager.h"
#include "GameState.h" #include "GameState.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ScreenPrompt.h" #include "ScreenPrompt.h"
#include "LocalizedString.h" #include "LocalizedString.h"
#include "OptionRowHandler.h" #include "OptionRowHandler.h"
REGISTER_SCREEN_CLASS( ScreenOptionsMemoryCard ); REGISTER_SCREEN_CLASS( ScreenOptionsMemoryCard );
void ScreenOptionsMemoryCard::Init() void ScreenOptionsMemoryCard::Init()
{ {
ScreenOptions::Init(); ScreenOptions::Init();
m_textOsMountDir.SetName( "Mount" ); m_textOsMountDir.SetName( "Mount" );
m_textOsMountDir.LoadFromFont( THEME->GetPathF(m_sName,"mount") ); m_textOsMountDir.LoadFromFont( THEME->GetPathF(m_sName,"mount") );
ActorUtil::LoadAllCommands( m_textOsMountDir, m_sName ); ActorUtil::LoadAllCommands( m_textOsMountDir, m_sName );
this->AddChild( &m_textOsMountDir ); this->AddChild( &m_textOsMountDir );
this->SubscribeToMessage( Message_StorageDevicesChanged ); this->SubscribeToMessage( Message_StorageDevicesChanged );
} }
bool ScreenOptionsMemoryCard::UpdateCurrentUsbStorageDevices() bool ScreenOptionsMemoryCard::UpdateCurrentUsbStorageDevices()
{ {
vector<UsbStorageDevice> aOldDevices = m_CurrentUsbStorageDevices; vector<UsbStorageDevice> aOldDevices = m_CurrentUsbStorageDevices;
const vector<UsbStorageDevice> &aNewDevices = MEMCARDMAN->GetStorageDevices(); const vector<UsbStorageDevice> &aNewDevices = MEMCARDMAN->GetStorageDevices();
m_CurrentUsbStorageDevices.clear(); m_CurrentUsbStorageDevices.clear();
for( size_t i = 0; i < aNewDevices.size(); ++i ) for( size_t i = 0; i < aNewDevices.size(); ++i )
{ {
const UsbStorageDevice &dev = aNewDevices[i]; const UsbStorageDevice &dev = aNewDevices[i];
if( dev.m_State == UsbStorageDevice::STATE_CHECKING ) if( dev.m_State == UsbStorageDevice::STATE_CHECKING )
continue; continue;
m_CurrentUsbStorageDevices.push_back( dev ); m_CurrentUsbStorageDevices.push_back( dev );
} }
return aOldDevices != m_CurrentUsbStorageDevices; return aOldDevices != m_CurrentUsbStorageDevices;
} }
static LocalizedString NO_LABEL ("ScreenOptionsMemoryCard", "(no label)" ); static LocalizedString NO_LABEL ("ScreenOptionsMemoryCard", "(no label)" );
static LocalizedString SIZE_UNKNOWN ("ScreenOptionsMemoryCard", "size ???" ); static LocalizedString SIZE_UNKNOWN ("ScreenOptionsMemoryCard", "size ???" );
static LocalizedString VOLUME_SIZE ("ScreenOptionsMemoryCard", "%dMB" ); static LocalizedString VOLUME_SIZE ("ScreenOptionsMemoryCard", "%dMB" );
void ScreenOptionsMemoryCard::CreateMenu() void ScreenOptionsMemoryCard::CreateMenu()
{ {
vector<OptionRowHandler*> vHands; vector<OptionRowHandler*> vHands;
FOREACH_CONST( UsbStorageDevice, m_CurrentUsbStorageDevices, iter ) for (UsbStorageDevice const &iter : m_CurrentUsbStorageDevices)
{ {
vector<RString> vs; vector<RString> vs;
if( iter->sVolumeLabel.empty() ) if( iter.sVolumeLabel.empty() )
vs.push_back( NO_LABEL ); vs.push_back( NO_LABEL );
else else
vs.push_back( iter->sVolumeLabel ); vs.push_back( iter.sVolumeLabel );
if( iter->iVolumeSizeMB == 0 ) if( iter.iVolumeSizeMB == 0 )
vs.push_back( SIZE_UNKNOWN ); vs.push_back( SIZE_UNKNOWN );
else else
vs.push_back( ssprintf(RString(VOLUME_SIZE).c_str(),iter->iVolumeSizeMB) ); vs.push_back( ssprintf(RString(VOLUME_SIZE).c_str(),iter.iVolumeSizeMB) );
vHands.push_back( OptionRowHandlerUtil::MakeNull() ); vHands.push_back( OptionRowHandlerUtil::MakeNull() );
OptionRowDefinition &def = vHands.back()->m_Def; OptionRowDefinition &def = vHands.back()->m_Def;
RString sDescription = join(", ", vs); RString sDescription = join(", ", vs);
def.m_sName = sDescription; def.m_sName = sDescription;
def.m_vsChoices.push_back( "" ); def.m_vsChoices.push_back( "" );
def.m_sExplanationName = "Memory Card"; def.m_sExplanationName = "Memory Card";
def.m_bAllowThemeTitle = false; def.m_bAllowThemeTitle = false;
def.m_bOneChoiceForAllPlayers = true; def.m_bOneChoiceForAllPlayers = true;
} }
if( m_CurrentUsbStorageDevices.empty() ) if( m_CurrentUsbStorageDevices.empty() )
{ {
vHands.push_back( OptionRowHandlerUtil::MakeNull() ); vHands.push_back( OptionRowHandlerUtil::MakeNull() );
OptionRowDefinition &def = vHands.back()->m_Def; OptionRowDefinition &def = vHands.back()->m_Def;
def.m_sName = "No USB memory cards found"; def.m_sName = "No USB memory cards found";
def.m_sExplanationName = "No Memory Card"; def.m_sExplanationName = "No Memory Card";
def.m_vsChoices.push_back( "" ); def.m_vsChoices.push_back( "" );
def.m_bAllowThemeTitle = true; def.m_bAllowThemeTitle = true;
def.m_bOneChoiceForAllPlayers = true; def.m_bOneChoiceForAllPlayers = true;
} }
InitMenu( vHands ); InitMenu( vHands );
} }
void ScreenOptionsMemoryCard::BeginScreen() void ScreenOptionsMemoryCard::BeginScreen()
{ {
UpdateCurrentUsbStorageDevices(); UpdateCurrentUsbStorageDevices();
CreateMenu(); CreateMenu();
ScreenOptions::BeginScreen(); ScreenOptions::BeginScreen();
// select the last chosen memory card (if present) // select the last chosen memory card (if present)
SelectRowWithMemoryCard( MEMCARDMAN->m_sEditorMemoryCardOsMountPoint.Get() ); SelectRowWithMemoryCard( MEMCARDMAN->m_sEditorMemoryCardOsMountPoint.Get() );
} }
void ScreenOptionsMemoryCard::HandleScreenMessage( const ScreenMessage SM ) void ScreenOptionsMemoryCard::HandleScreenMessage( const ScreenMessage SM )
{ {
ScreenOptions::HandleScreenMessage( SM ); ScreenOptions::HandleScreenMessage( SM );
} }
void ScreenOptionsMemoryCard::AfterChangeRow( PlayerNumber pn ) void ScreenOptionsMemoryCard::AfterChangeRow( PlayerNumber pn )
{ {
ScreenOptions::AfterChangeRow( pn ); ScreenOptions::AfterChangeRow( pn );
if( m_CurrentUsbStorageDevices.empty() ) if( m_CurrentUsbStorageDevices.empty() )
{ {
m_textOsMountDir.SetText( "" ); m_textOsMountDir.SetText( "" );
} }
else else
{ {
int iRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()]; int iRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()];
m_textOsMountDir.SetText( m_CurrentUsbStorageDevices[iRow].sOsMountDir ); m_textOsMountDir.SetText( m_CurrentUsbStorageDevices[iRow].sOsMountDir );
} }
} }
void ScreenOptionsMemoryCard::HandleMessage( const Message &msg ) void ScreenOptionsMemoryCard::HandleMessage( const Message &msg )
{ {
if( msg == Message_StorageDevicesChanged ) if( msg == Message_StorageDevicesChanged )
{ {
if( !m_Out.IsTransitioning() ) if( !m_Out.IsTransitioning() )
{ {
/* Remember the old mountpoint. */ /* Remember the old mountpoint. */
const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices; const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices;
int iRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()]; int iRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()];
RString sOldMountPoint; RString sOldMountPoint;
if( iRow < int(v.size()) ) if( iRow < int(v.size()) )
{ {
const UsbStorageDevice &dev = v[iRow]; const UsbStorageDevice &dev = v[iRow];
sOldMountPoint = dev.sOsMountDir; sOldMountPoint = dev.sOsMountDir;
} }
/* If the devices that we'd actually show haven't changed, don't recreate the menu. */ /* If the devices that we'd actually show haven't changed, don't recreate the menu. */
if( !UpdateCurrentUsbStorageDevices() ) if( !UpdateCurrentUsbStorageDevices() )
return; return;
CreateMenu(); CreateMenu();
RestartOptions(); RestartOptions();
/* If the memory card that was selected previously is still there, select it. */ /* If the memory card that was selected previously is still there, select it. */
SelectRowWithMemoryCard( sOldMountPoint ); SelectRowWithMemoryCard( sOldMountPoint );
} }
} }
ScreenOptions::HandleMessage( msg ); ScreenOptions::HandleMessage( msg );
} }
void ScreenOptionsMemoryCard::ImportOptions( int iRow, const vector<PlayerNumber> &vpns ) void ScreenOptionsMemoryCard::ImportOptions( int iRow, const vector<PlayerNumber> &vpns )
{ {
} }
void ScreenOptionsMemoryCard::ExportOptions( int iRow, const vector<PlayerNumber> &vpns ) void ScreenOptionsMemoryCard::ExportOptions( int iRow, const vector<PlayerNumber> &vpns )
{ {
OptionRow &row = *m_pRows[iRow]; OptionRow &row = *m_pRows[iRow];
if( row.GetRowType() == OptionRow::RowType_Exit ) if( row.GetRowType() == OptionRow::RowType_Exit )
return; return;
PlayerNumber pn = GAMESTATE->GetMasterPlayerNumber(); PlayerNumber pn = GAMESTATE->GetMasterPlayerNumber();
if( m_iCurrentRow[pn] == iRow ) if( m_iCurrentRow[pn] == iRow )
{ {
const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices; const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices;
if( iRow < int(v.size()) ) if( iRow < int(v.size()) )
{ {
const UsbStorageDevice &dev = v[iRow]; const UsbStorageDevice &dev = v[iRow];
MEMCARDMAN->m_sEditorMemoryCardOsMountPoint.Set( dev.sOsMountDir ); MEMCARDMAN->m_sEditorMemoryCardOsMountPoint.Set( dev.sOsMountDir );
} }
} }
} }
void ScreenOptionsMemoryCard::SelectRowWithMemoryCard( const RString &sOsMountPoint ) void ScreenOptionsMemoryCard::SelectRowWithMemoryCard( const RString &sOsMountPoint )
{ {
if( sOsMountPoint.empty() ) if( sOsMountPoint.empty() )
return; return;
const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices; const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices;
for( unsigned i=0; i<v.size(); i++ ) for( unsigned i=0; i<v.size(); i++ )
{ {
if( v[i].sOsMountDir == sOsMountPoint ) if( v[i].sOsMountDir == sOsMountPoint )
{ {
this->MoveRowAbsolute( PLAYER_1, i ); this->MoveRowAbsolute( PLAYER_1, i );
return; return;
} }
} }
} }
static LocalizedString ERROR_MOUNTING_CARD ("ScreenOptionsMemoryCard", "Error mounting card: %s" ); static LocalizedString ERROR_MOUNTING_CARD ("ScreenOptionsMemoryCard", "Error mounting card: %s" );
void ScreenOptionsMemoryCard::ProcessMenuStart( const InputEventPlus & ) void ScreenOptionsMemoryCard::ProcessMenuStart( const InputEventPlus & )
{ {
if( IsTransitioning() ) if( IsTransitioning() )
return; return;
int iCurRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()]; int iCurRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()];
const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices; const vector<UsbStorageDevice> &v = m_CurrentUsbStorageDevices;
if( iCurRow < int(v.size()) ) // a card if( iCurRow < int(v.size()) ) // a card
{ {
// Why is this statement in twice? Doubt it would change right after the if. -Wolfman2000 // Why is this statement in twice? Doubt it would change right after the if. -Wolfman2000
const vector<UsbStorageDevice> &vUSB = m_CurrentUsbStorageDevices; const vector<UsbStorageDevice> &vUSB = m_CurrentUsbStorageDevices;
const UsbStorageDevice &dev = vUSB[iCurRow]; const UsbStorageDevice &dev = vUSB[iCurRow];
MEMCARDMAN->m_sEditorMemoryCardOsMountPoint.Set( dev.sOsMountDir ); MEMCARDMAN->m_sEditorMemoryCardOsMountPoint.Set( dev.sOsMountDir );
/* The destination screen must UnmountCard. XXX: brittle */ /* The destination screen must UnmountCard. XXX: brittle */
bool bSuccess = MEMCARDMAN->MountCard( PLAYER_1, dev ); bool bSuccess = MEMCARDMAN->MountCard( PLAYER_1, dev );
if( bSuccess ) if( bSuccess )
{ {
SCREENMAN->PlayStartSound(); SCREENMAN->PlayStartSound();
this->BeginFadingOut(); this->BeginFadingOut();
} }
else else
{ {
RString s = ssprintf(ERROR_MOUNTING_CARD.GetValue(), MEMCARDMAN->GetCardError(PLAYER_1).c_str() ); RString s = ssprintf(ERROR_MOUNTING_CARD.GetValue(), MEMCARDMAN->GetCardError(PLAYER_1).c_str() );
ScreenPrompt::Prompt( SM_None, s ); ScreenPrompt::Prompt( SM_None, s );
} }
} }
else else
{ {
SCREENMAN->PlayInvalidSound(); SCREENMAN->PlayInvalidSound();
} }
} }
/* /*
* (c) 2005 Chris Danford * (c) 2005 Chris Danford
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the * copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to * 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 * whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of * copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this * the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation. * permission notice appear in supporting documentation.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS * 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 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * 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 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */