diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 07892eb7da..c44bcd6fc6 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -12,8 +12,8 @@ #include "EnumHelper.h" #include "RageTypes.h" -struct PlayerOptions; -struct SongOptions; +class PlayerOptions; +class SongOptions; class Song; class Steps; class Profile; diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index 9572f87329..8732e7790a 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -4,29 +4,22 @@ #include "RageLog.h" #include "GameManager.h" #include "GameState.h" -#include "RageDisplay.h" #include "AnnouncerManager.h" +#include "PlayerOptions.h" #include "ProfileManager.h" #include "Profile.h" #include "StepMania.h" #include "ScreenManager.h" -#include "SongManager.h" #include "PrefsManager.h" -#include "arch/ArchHooks/ArchHooks.h" -#include "MemoryCardManager.h" -#include "song.h" #include "Game.h" #include "Style.h" #include "Foreach.h" -#include "Command.h" #include "arch/Dialog/Dialog.h" -#include "Bookkeeper.h" -#include "UnlockManager.h" #include "GameSoundManager.h" -#include "ThemeManager.h" #include "PlayerState.h" -#include "Course.h" -#include "RageFileManager.h" +#include "SongManager.h" +#include "song.h" +#include "UnlockManager.h" void GameCommand::Init() { @@ -58,20 +51,11 @@ void GameCommand::Init() m_GoalType = GOAL_INVALID; m_sProfileID = ""; - m_bClearBookkeepingData = false; - m_bClearMachineStats = false; - m_bClearMachineEdits = false; - m_bFillMachineStats = false; - m_bTransferStatsFromMachine = false; - m_bTransferStatsToMachine = false; - m_bCopyEditsFromMachine = false; - m_bCopyEditsToMachine = false; m_bInsertCredit = false; - m_bResetToFactoryDefaults = false; m_bStopMusic = false; - m_bApplyDefaultOptions = false; } +class SongOptions; bool CompareSongOptions( const SongOptions &so1, const SongOptions &so2 ); bool GameCommand::DescribesCurrentModeForAllPlayers() const @@ -363,54 +347,15 @@ void GameCommand::LoadOne( const Command& cmd ) m_vsScreensToPrepare.push_back( sValue ); } - else if( sName == "clearbookkeepingdata" ) - { - m_bClearBookkeepingData = true; - } - else if( sName == "clearmachinestats" ) - { - m_bClearMachineStats = true; - } - else if( sName == "clearmachineedits" ) - { - m_bClearMachineEdits = true; - } - else if( sName == "fillmachinestats" ) - { - m_bFillMachineStats = true; - } - else if( sName == "transferstatsfrommachine" ) - { - m_bTransferStatsFromMachine = true; - } - else if( sName == "copyeditstomachine" ) - { - m_bCopyEditsToMachine = true; - } - else if( sName == "copyeditsfrommachine" ) - { - m_bCopyEditsFromMachine = true; - } - else if( sName == "transferstatstomachine" ) - { - m_bTransferStatsToMachine = true; - } else if( sName == "insertcredit" ) { m_bInsertCredit = true; } - else if( sName == "resettofactorydefaults" ) - { - m_bResetToFactoryDefaults = true; - } + else if( sName == "stopmusic" ) { m_bStopMusic = true; } - else if( sName == "applydefaultoptions" ) - { - m_bApplyDefaultOptions = true; - } else { @@ -609,77 +554,6 @@ void GameCommand::Apply( PlayerNumber pn ) const Apply( vpns ); } -static HighScore MakeRandomHighScore( float fPercentDP ) -{ - HighScore hs; - hs.SetName( "FAKE" ); - hs.SetGrade( (Grade)SCALE( rand()%5, 0, 4, Grade_Tier01, Grade_Tier05 ) ); - hs.SetScore( rand()%100*1000 ); - hs.SetPercentDP( fPercentDP ); - hs.SetSurviveSeconds( randomf(30.0f, 100.0f) ); - PlayerOptions po; - po.ChooseRandomModifiers(); - hs.SetModifiers( po.GetString() ); - hs.SetDateTime( DateTime::GetNowDateTime() ); - hs.SetPlayerGuid( Profile::MakeGuid() ); - hs.SetMachineGuid( Profile::MakeGuid() ); - hs.SetProductID( rand()%10 ); - FOREACH_TapNoteScore( tns ) - hs.SetTapNoteScore( tns, rand() % 100 ); - FOREACH_HoldNoteScore( hns ) - hs.SetHoldNoteScore( hns, rand() % 100 ); - RadarValues rv; - FOREACH_RadarCategory( rc ) - rv.m_Values.f[rc] = randomf( 0, 1 ); - hs.SetRadarValues( rv ); - - return hs; -} - -static void FillProfile( Profile *pProfile ) -{ - // Choose a percent for all scores. This is useful for testing unlocks - // where some elements are unlocked at a certain percent complete - float fPercentDP = randomf( 0.6f, 1.2f ); - CLAMP( fPercentDP, 0.0f, 1.0f ); - - int iCount = pProfile->IsMachine()? - PREFSMAN->m_iMaxHighScoresPerListForMachine.Get(): - PREFSMAN->m_iMaxHighScoresPerListForPlayer.Get(); - - vector vpAllSongs = SONGMAN->GetAllSongs(); - FOREACH( Song*, vpAllSongs, pSong ) - { - vector vpAllSteps = (*pSong)->GetAllSteps(); - FOREACH( Steps*, vpAllSteps, pSteps ) - { - pProfile->IncrementStepsPlayCount( *pSong, *pSteps ); - for( int i=0; iAddStepsHighScore( *pSong, *pSteps, MakeRandomHighScore(fPercentDP), iIndex ); - } - } - } - - vector vpAllCourses; - SONGMAN->GetAllCourses( vpAllCourses, true ); - FOREACH( Course*, vpAllCourses, pCourse ) - { - vector vpAllTrails; - (*pCourse)->GetAllTrails( vpAllTrails ); - FOREACH( Trail*, vpAllTrails, pTrail ) - { - pProfile->IncrementCoursePlayCount( *pCourse, *pTrail ); - for( int i=0; iAddCourseHighScore( *pCourse, *pTrail, MakeRandomHighScore(fPercentDP), iIndex ); - } - } - } -} - /* Hack: if this GameCommand would set the screen, clear the setting and return * the screen that would have been set. */ @@ -844,268 +718,10 @@ void GameCommand::ApplySelf( const vector &vpns ) const FOREACH_CONST( CString, m_vsScreensToPrepare, s ) SCREENMAN->PrepareScreen( *s ); - if( m_bClearBookkeepingData ) - { - BOOKKEEPER->ClearAll(); - BOOKKEEPER->WriteToDisk(); - SCREENMAN->SystemMessage( "Bookkeeping data cleared." ); - } - if( m_bClearMachineStats ) - { - Profile* pProfile = PROFILEMAN->GetMachineProfile(); - // don't reset the Guid - CString sGuid = pProfile->m_sGuid; - pProfile->InitAll(); - pProfile->m_sGuid = sGuid; - PROFILEMAN->SaveMachineProfile(); - SCREENMAN->SystemMessage( "Machine stats cleared." ); - } - if( m_bClearMachineEdits ) - { - int iNumAttempted = 0; - int iNumSuccessful = 0; - - vector vsEditFiles; - GetDirListing( PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE)+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true ); - GetDirListing( PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE)+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true ); - FOREACH_CONST( CString, vsEditFiles, i ) - { - iNumAttempted++; - bool bSuccess = FILEMAN->Remove( *i ); - if( bSuccess ) - iNumSuccessful++; - } - - // reload the machine profile - PROFILEMAN->SaveMachineProfile(); - PROFILEMAN->LoadMachineProfile(); - - SCREENMAN->SystemMessage( ssprintf("%d edits cleared, %d errors.",iNumSuccessful,iNumAttempted-iNumSuccessful) ); - } - if( m_bFillMachineStats ) - { - Profile* pProfile = PROFILEMAN->GetMachineProfile(); - FillProfile( pProfile ); - - PROFILEMAN->SaveMachineProfile(); - SCREENMAN->SystemMessage( "Machine stats filled." ); - } - if( m_bTransferStatsFromMachine ) - { - bool bTriedToSave = false; - FOREACH_PlayerNumber( pn ) - { - if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) - continue; // skip - - MEMCARDMAN->MountCard(pn); - - bTriedToSave = true; - - CString sDir = MEM_CARD_MOUNT_POINT[pn]; - sDir += "MachineProfile/"; - - bool bSaved = PROFILEMAN->GetMachineProfile()->SaveAllToDir( sDir, PREFSMAN->m_bSignProfileData ); - - MEMCARDMAN->UnmountCard(pn); - - if( bSaved ) - SCREENMAN->SystemMessage( ssprintf("Machine stats saved to P%d card.",pn+1) ); - else - SCREENMAN->SystemMessage( ssprintf("Error saving machine stats to P%d card.",pn+1) ); - break; - } - - if( !bTriedToSave ) - SCREENMAN->SystemMessage( "Stats not saved - No memory cards ready." ); - - MEMCARDMAN->FlushAndReset(); - } - if( m_bTransferStatsToMachine ) - { - bool bTriedToLoad = false; - FOREACH_PlayerNumber( pn ) - { - if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) - continue; // skip - - MEMCARDMAN->MountCard(pn); - - bTriedToLoad = true; - - CString sDir = MEM_CARD_MOUNT_POINT[pn]; - sDir += "MachineProfile/"; - - Profile backup = *PROFILEMAN->GetMachineProfile(); - - ProfileLoadResult lr = PROFILEMAN->GetMachineProfile()->LoadAllFromDir( sDir, PREFSMAN->m_bSignProfileData ); - switch( lr ) - { - case ProfileLoadResult_Success: - SCREENMAN->SystemMessage( ssprintf("Machine stats loaded from P%d card.",pn+1) ); - break; - case ProfileLoadResult_FailedNoProfile: - SCREENMAN->SystemMessage( ssprintf("There is no machine profile on P%d card.",pn+1) ); - *PROFILEMAN->GetMachineProfile() = backup; - break; - case ProfileLoadResult_FailedTampered: - SCREENMAN->SystemMessage( ssprintf("The profile on P%d card contains corrupt or tampered data.",pn+1) ); - *PROFILEMAN->GetMachineProfile() = backup; - break; - default: - ASSERT(0); - } - - MEMCARDMAN->UnmountCard(pn); - break; - } - - if( !bTriedToLoad ) - SCREENMAN->SystemMessage( "Stats not loaded - No memory cards ready." ); - - MEMCARDMAN->FlushAndReset(); - } - if( m_bCopyEditsFromMachine ) - { - bool bTriedToCopy = false; - FOREACH_PlayerNumber( pn ) - { - if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) - continue; // skip - - MEMCARDMAN->MountCard(pn); - - bTriedToCopy = true; - - int iNumAttempted = 0; - int iNumSuccessful = 0; - int iNumOverwritten = 0; - - { - CString sFromDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_STEPS_SUBDIR; - CString sToDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_STEPS_SUBDIR; - - vector vsFiles; - GetDirListing( sFromDir+"*.edit", vsFiles, false, false ); - FOREACH_CONST( CString, vsFiles, i ) - { - iNumAttempted++; - if( DoesFileExist(sToDir+*i) ) - iNumOverwritten++; - bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); - if( bSuccess ) - iNumSuccessful++; - } - } - - { - CString sFromDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_COURSES_SUBDIR; - CString sToDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_COURSES_SUBDIR; - - vector vsFiles; - GetDirListing( sFromDir+"*.crs", vsFiles, false, false ); - FOREACH_CONST( CString, vsFiles, i ) - { - iNumAttempted++; - if( DoesFileExist(sToDir+*i) ) - iNumOverwritten++; - bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); - if( bSuccess ) - iNumSuccessful++; - } - } - - MEMCARDMAN->UnmountCard(pn); - - SCREENMAN->SystemMessage( ssprintf("Copied to P%d card: %d/%d copies OK (%d overwritten).",pn+1,iNumSuccessful,iNumAttempted,iNumOverwritten) ); - break; - } - - if( !bTriedToCopy ) - SCREENMAN->SystemMessage( "Edits not copied - No memory cards ready." ); - - MEMCARDMAN->FlushAndReset(); - } - if( m_bCopyEditsToMachine ) - { - bool bTriedToCopy = false; - FOREACH_PlayerNumber( pn ) - { - if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) - continue; // skip - - MEMCARDMAN->MountCard(pn); - - bTriedToCopy = true; - - int iNumAttempted = 0; - int iNumSuccessful = 0; - int iNumOverwritten = 0; - - { - CString sFromDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_STEPS_SUBDIR; - CString sToDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_STEPS_SUBDIR; - - vector vsFiles; - GetDirListing( sFromDir+"*.edit", vsFiles, false, false ); - FOREACH_CONST( CString, vsFiles, i ) - { - iNumAttempted++; - if( DoesFileExist(sToDir+*i) ) - iNumOverwritten++; - bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); - if( bSuccess ) - iNumSuccessful++; - } - } - - { - CString sFromDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_COURSES_SUBDIR; - CString sToDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_COURSES_SUBDIR; - - vector vsFiles; - GetDirListing( sFromDir+"*.crs", vsFiles, false, false ); - FOREACH_CONST( CString, vsFiles, i ) - { - iNumAttempted++; - if( DoesFileExist(sToDir+*i) ) - iNumOverwritten++; - bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); - if( bSuccess ) - iNumSuccessful++; - } - } - - MEMCARDMAN->UnmountCard(pn); - - // reload the machine profile - PROFILEMAN->SaveMachineProfile(); - PROFILEMAN->LoadMachineProfile(); - - SCREENMAN->SystemMessage( ssprintf("Copied from P%d card: %d/%d copies OK (%d overwritten).",pn+1,iNumSuccessful,iNumAttempted,iNumOverwritten) ); - break; - } - - if( !bTriedToCopy ) - SCREENMAN->SystemMessage( "Edits not copied - No memory cards ready." ); - - MEMCARDMAN->FlushAndReset(); - } if( m_bInsertCredit ) { InsertCredit(); } - if( m_bResetToFactoryDefaults ) - { - PREFSMAN->ResetToFactoryDefaults(); - SCREENMAN->SystemMessage( "All options reset to factory defaults." ); - } - if( m_bApplyDefaultOptions ) - { - FOREACH_PlayerNumber( p ) - GAMESTATE->GetDefaultPlayerOptions( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions ); - GAMESTATE->GetDefaultSongOptions( GAMESTATE->m_SongOptions ); - } // HACK: Set life type to BATTERY just once here so it happens once and // we don't override the user's changes if they back out. if( GAMESTATE->m_PlayMode == PLAY_MODE_ONI && diff --git a/stepmania/src/GameCommand.h b/stepmania/src/GameCommand.h index b135b39351..7b85c1e0da 100644 --- a/stepmania/src/GameCommand.h +++ b/stepmania/src/GameCommand.h @@ -76,18 +76,8 @@ public: GoalType m_GoalType; CString m_sProfileID; - bool m_bClearBookkeepingData; - bool m_bClearMachineStats; - bool m_bClearMachineEdits; - bool m_bFillMachineStats; // for testing - bool m_bTransferStatsFromMachine; - bool m_bTransferStatsToMachine; - bool m_bCopyEditsFromMachine; - bool m_bCopyEditsToMachine; bool m_bInsertCredit; - bool m_bResetToFactoryDefaults; bool m_bStopMusic; - bool m_bApplyDefaultOptions; // Lua void PushSelf( lua_State *L ); diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 22ba1ef969..7428c9dd66 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -29,7 +29,7 @@ class PlayerState; struct lua_State; class LuaTable; class Profile; -struct PlayerOptions; +class PlayerOptions; class GameState { diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index 1b308dadc5..171d3abe18 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -60,6 +60,7 @@ ScreenPrompt.cpp ScreenPrompt.h ScreenRanking.cpp ScreenRanking.h \ ScreenReloadSongs.cpp ScreenReloadSongs.h \ ScreenSandbox.cpp ScreenSandbox.h \ ScreenSaveSync.cpp ScreenSaveSync.h \ +ScreenServiceAction.cpp ScreenServiceAction.h \ ScreenStatsOverlay.cpp ScreenStatsOverlay.h \ ScreenSelect.cpp ScreenSelect.h ScreenSelectCharacter.cpp ScreenSelectCharacter.h \ ScreenSelectDifficulty.cpp ScreenSelectDifficulty.h ScreenSelectGroup.cpp ScreenSelectGroup.h \ diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp index ed7fe7db0c..7c525f8795 100644 --- a/stepmania/src/MessageManager.cpp +++ b/stepmania/src/MessageManager.cpp @@ -64,6 +64,7 @@ static const CString MessageNames[] = { "LessonTry3", "LessonCleared", "LessonFailed", + "StorageDevicesChanged", }; XToString( Message, NUM_Message ); diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h index bac15059b9..a09398e75a 100644 --- a/stepmania/src/MessageManager.h +++ b/stepmania/src/MessageManager.h @@ -79,6 +79,7 @@ enum Message Message_LessonTry3, Message_LessonCleared, Message_LessonFailed, + Message_StorageDevicesChanged, NUM_Message, // leave this at the end Message_Invalud }; diff --git a/stepmania/src/NoteDataUtil.h b/stepmania/src/NoteDataUtil.h index 4debe500a5..62593d428f 100644 --- a/stepmania/src/NoteDataUtil.h +++ b/stepmania/src/NoteDataUtil.h @@ -7,7 +7,7 @@ #include "NoteTypes.h" #include "NoteData.h" -struct PlayerOptions; +class PlayerOptions; struct RadarValues; /* Utils for NoteData. Things should go in here if they can be (cleanly and diff --git a/stepmania/src/OptionIconRow.h b/stepmania/src/OptionIconRow.h index b940f4485c..fb6dc7700f 100644 --- a/stepmania/src/OptionIconRow.h +++ b/stepmania/src/OptionIconRow.h @@ -6,7 +6,7 @@ #include "ActorFrame.h" #include "OptionIcon.h" -struct PlayerOptions; +class PlayerOptions; struct lua_State; const unsigned NUM_OPTION_COLS = 8; diff --git a/stepmania/src/PlayerOptions.h b/stepmania/src/PlayerOptions.h index 457688e727..80ee20067a 100644 --- a/stepmania/src/PlayerOptions.h +++ b/stepmania/src/PlayerOptions.h @@ -10,8 +10,9 @@ class Trail; #include "GameConstantsAndTypes.h" -struct PlayerOptions +class PlayerOptions { +public: PlayerOptions() { Init(); }; void Init(); void Approach( const PlayerOptions& other, float fDeltaSeconds ); diff --git a/stepmania/src/ScreenCredits.cpp b/stepmania/src/ScreenCredits.cpp index f8c89f244d..9b804b9269 100644 --- a/stepmania/src/ScreenCredits.cpp +++ b/stepmania/src/ScreenCredits.cpp @@ -1,7 +1,6 @@ #include "global.h" #include "ScreenCredits.h" #include "GameSoundManager.h" -#include "RageLog.h" #include "AnnouncerManager.h" diff --git a/stepmania/src/ScreenOptionsMemoryCard.cpp b/stepmania/src/ScreenOptionsMemoryCard.cpp index 88a7b36ed4..fcb119bdb7 100644 --- a/stepmania/src/ScreenOptionsMemoryCard.cpp +++ b/stepmania/src/ScreenOptionsMemoryCard.cpp @@ -4,6 +4,7 @@ #include "arch/MemoryCard/MemoryCardDriver.h" #include "MemoryCardManager.h" #include "GameState.h" +#include "ScreenManager.h" REGISTER_SCREEN_CLASS( ScreenOptionsMemoryCard ); @@ -25,7 +26,7 @@ void ScreenOptionsMemoryCard::Init() if( sVolumeLabel.empty() ) sVolumeLabel = "(no label)"; CString sDescription = ssprintf( "%s %s", sOsMountDir.c_str(), sVolumeLabel.c_str() ); - OptionRowDefinition def( sDescription, true, "Enable", "Disable" ); + OptionRowDefinition def( sDescription, true, "" ); def.m_bAllowThemeTitles = false; def.m_bAllowExplanation = false; m_vDefs.push_back( def ); @@ -57,13 +58,16 @@ void ScreenOptionsMemoryCard::BeginScreen() void ScreenOptionsMemoryCard::HandleScreenMessage( const ScreenMessage SM ) { - if( SM == SM_GoToNextScreen ) - { - MEMCARDMAN->Update(0, true); - } ScreenOptions::HandleScreenMessage( SM ); } +void ScreenOptionsMemoryCard::HandleMessage( const CString& sMessage ) +{ + if( sMessage == MessageToString(Message_StorageDevicesChanged) ) + { + SCREENMAN->SetNewScreen( this->m_sName ); // reload + } +} void ScreenOptionsMemoryCard::MenuStart( const InputEventPlus &input ) { diff --git a/stepmania/src/ScreenOptionsMemoryCard.h b/stepmania/src/ScreenOptionsMemoryCard.h index 12a640395e..de749d6a75 100644 --- a/stepmania/src/ScreenOptionsMemoryCard.h +++ b/stepmania/src/ScreenOptionsMemoryCard.h @@ -18,6 +18,8 @@ private: void ImportOptions( int iRow, const vector &vpns ); void ExportOptions( int iRow, const vector &vpns ); + void HandleMessage( const CString& sMessage ); + vector m_vDefs; }; diff --git a/stepmania/src/ScreenSaveSync.cpp b/stepmania/src/ScreenSaveSync.cpp index e11aeb3d78..8a823576f8 100644 --- a/stepmania/src/ScreenSaveSync.cpp +++ b/stepmania/src/ScreenSaveSync.cpp @@ -3,7 +3,6 @@ #include "GameState.h" #include "song.h" #include "PrefsManager.h" -#include "ScreenPrompt.h" static CString GetPromptText() diff --git a/stepmania/src/ScreenServiceAction.cpp b/stepmania/src/ScreenServiceAction.cpp new file mode 100644 index 0000000000..c439e8b6e0 --- /dev/null +++ b/stepmania/src/ScreenServiceAction.cpp @@ -0,0 +1,447 @@ +#include "global.h" +#include "ScreenServiceAction.h" +#include "ThemeManager.h" +#include "Bookkeeper.h" +#include "Profile.h" +#include "ProfileManager.h" +#include "ScreenManager.h" +#include "RageFileManager.h" +#include "PrefsManager.h" +#include "SongManager.h" +#include "song.h" +#include "MemoryCardManager.h" +#include "GameState.h" +#include "PlayerState.h" + + +static CString ClearBookkeepingData() +{ + BOOKKEEPER->ClearAll(); + BOOKKEEPER->WriteToDisk(); + return "Bookkeeping data cleared."; +} + +static CString ClearMachineStats() +{ + Profile* pProfile = PROFILEMAN->GetMachineProfile(); + // don't reset the Guid + CString sGuid = pProfile->m_sGuid; + pProfile->InitAll(); + pProfile->m_sGuid = sGuid; + PROFILEMAN->SaveMachineProfile(); + return "Machine stats cleared."; +} + +static CString ClearMachineEdits() +{ + int iNumAttempted = 0; + int iNumSuccessful = 0; + + vector vsEditFiles; + GetDirListing( PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE)+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true ); + GetDirListing( PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE)+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true ); + FOREACH_CONST( CString, vsEditFiles, i ) + { + iNumAttempted++; + bool bSuccess = FILEMAN->Remove( *i ); + if( bSuccess ) + iNumSuccessful++; + } + + // reload the machine profile + PROFILEMAN->SaveMachineProfile(); + PROFILEMAN->LoadMachineProfile(); + + return ssprintf("%d edits cleared, %d errors.",iNumSuccessful,iNumAttempted-iNumSuccessful); +} + +static CString ClearMemoryCardEdits() +{ + int iNumAttempted = 0; + int iNumSuccessful = 0; + + bool bTriedToLoad = false; + FOREACH_PlayerNumber( pn ) + { + if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) + continue; // skip + + MEMCARDMAN->MountCard(pn); + + bTriedToLoad = true; + + CString sDir = MEM_CARD_MOUNT_POINT[pn]; + + vector vsEditFiles; + GetDirListing( sDir+EDIT_STEPS_SUBDIR+"*.edit", vsEditFiles, false, true ); + GetDirListing( sDir+EDIT_COURSES_SUBDIR+"*.crs", vsEditFiles, false, true ); + FOREACH_CONST( CString, vsEditFiles, i ) + { + iNumAttempted++; + bool bSuccess = FILEMAN->Remove( *i ); + if( bSuccess ) + iNumSuccessful++; + } + + MEMCARDMAN->UnmountCard(pn); + break; + } + + if( !bTriedToLoad ) + return "Stats not loaded - No memory cards ready."; + + MEMCARDMAN->FlushAndReset(); + + return ssprintf("%d edits cleared, %d errors.",iNumSuccessful,iNumAttempted-iNumSuccessful); +} + +static HighScore MakeRandomHighScore( float fPercentDP ) +{ + HighScore hs; + hs.SetName( "FAKE" ); + hs.SetGrade( (Grade)SCALE( rand()%5, 0, 4, Grade_Tier01, Grade_Tier05 ) ); + hs.SetScore( rand()%100*1000 ); + hs.SetPercentDP( fPercentDP ); + hs.SetSurviveSeconds( randomf(30.0f, 100.0f) ); + PlayerOptions po; + po.ChooseRandomModifiers(); + hs.SetModifiers( po.GetString() ); + hs.SetDateTime( DateTime::GetNowDateTime() ); + hs.SetPlayerGuid( Profile::MakeGuid() ); + hs.SetMachineGuid( Profile::MakeGuid() ); + hs.SetProductID( rand()%10 ); + FOREACH_TapNoteScore( tns ) + hs.SetTapNoteScore( tns, rand() % 100 ); + FOREACH_HoldNoteScore( hns ) + hs.SetHoldNoteScore( hns, rand() % 100 ); + RadarValues rv; + FOREACH_RadarCategory( rc ) + rv.m_Values.f[rc] = randomf( 0, 1 ); + hs.SetRadarValues( rv ); + + return hs; +} + +static void FillProfile( Profile *pProfile ) +{ + // Choose a percent for all scores. This is useful for testing unlocks + // where some elements are unlocked at a certain percent complete + float fPercentDP = randomf( 0.6f, 1.2f ); + CLAMP( fPercentDP, 0.0f, 1.0f ); + + int iCount = pProfile->IsMachine()? + PREFSMAN->m_iMaxHighScoresPerListForMachine.Get(): + PREFSMAN->m_iMaxHighScoresPerListForPlayer.Get(); + + vector vpAllSongs = SONGMAN->GetAllSongs(); + FOREACH( Song*, vpAllSongs, pSong ) + { + vector vpAllSteps = (*pSong)->GetAllSteps(); + FOREACH( Steps*, vpAllSteps, pSteps ) + { + pProfile->IncrementStepsPlayCount( *pSong, *pSteps ); + for( int i=0; iAddStepsHighScore( *pSong, *pSteps, MakeRandomHighScore(fPercentDP), iIndex ); + } + } + } + + vector vpAllCourses; + SONGMAN->GetAllCourses( vpAllCourses, true ); + FOREACH( Course*, vpAllCourses, pCourse ) + { + vector vpAllTrails; + (*pCourse)->GetAllTrails( vpAllTrails ); + FOREACH( Trail*, vpAllTrails, pTrail ) + { + pProfile->IncrementCoursePlayCount( *pCourse, *pTrail ); + for( int i=0; iAddCourseHighScore( *pCourse, *pTrail, MakeRandomHighScore(fPercentDP), iIndex ); + } + } + } +} + +static CString FillMachineStats() +{ + Profile* pProfile = PROFILEMAN->GetMachineProfile(); + FillProfile( pProfile ); + + PROFILEMAN->SaveMachineProfile(); + return "Machine stats filled."; +} + +static CString TransferStatsMachineToMemoryCard() +{ + bool bTriedToSave = false; + FOREACH_PlayerNumber( pn ) + { + if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) + continue; // skip + + MEMCARDMAN->MountCard(pn); + + bTriedToSave = true; + + CString sDir = MEM_CARD_MOUNT_POINT[pn]; + sDir += "MachineProfile/"; + + bool bSaved = PROFILEMAN->GetMachineProfile()->SaveAllToDir( sDir, PREFSMAN->m_bSignProfileData ); + + MEMCARDMAN->UnmountCard(pn); + + if( bSaved ) + return ssprintf("Machine stats saved to P%d card.",pn+1); + else + return ssprintf("Error saving machine stats to P%d card.",pn+1); + break; + } + + if( !bTriedToSave ) + return "Stats not saved - No memory cards ready."; + + MEMCARDMAN->FlushAndReset(); + + return "Stats transferred to Memory Card"; +} + +static CString TransferStatsMemoryCardToMachine() +{ + bool bTriedToLoad = false; + FOREACH_PlayerNumber( pn ) + { + if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) + continue; // skip + + MEMCARDMAN->MountCard(pn); + + bTriedToLoad = true; + + CString sDir = MEM_CARD_MOUNT_POINT[pn]; + sDir += "MachineProfile/"; + + Profile backup = *PROFILEMAN->GetMachineProfile(); + + ProfileLoadResult lr = PROFILEMAN->GetMachineProfile()->LoadAllFromDir( sDir, PREFSMAN->m_bSignProfileData ); + switch( lr ) + { + case ProfileLoadResult_Success: + return ssprintf("Machine stats loaded from P%d card.",pn+1); + break; + case ProfileLoadResult_FailedNoProfile: + return ssprintf("There is no machine profile on P%d card.",pn+1); + *PROFILEMAN->GetMachineProfile() = backup; + break; + case ProfileLoadResult_FailedTampered: + return ssprintf("The profile on P%d card contains corrupt or tampered data.",pn+1); + *PROFILEMAN->GetMachineProfile() = backup; + break; + default: + ASSERT(0); + } + + MEMCARDMAN->UnmountCard(pn); + break; + } + + if( !bTriedToLoad ) + return "Stats not loaded - No memory cards ready."; + + MEMCARDMAN->FlushAndReset(); + + return "Stats transferred to machine."; +} + +static CString CopyEditsMachineToMemoryCard() +{ + bool bTriedToCopy = false; + FOREACH_PlayerNumber( pn ) + { + if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) + continue; // skip + + MEMCARDMAN->MountCard(pn); + + bTriedToCopy = true; + + int iNumAttempted = 0; + int iNumSuccessful = 0; + int iNumOverwritten = 0; + + { + CString sFromDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_STEPS_SUBDIR; + CString sToDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_STEPS_SUBDIR; + + vector vsFiles; + GetDirListing( sFromDir+"*.edit", vsFiles, false, false ); + FOREACH_CONST( CString, vsFiles, i ) + { + iNumAttempted++; + if( DoesFileExist(sToDir+*i) ) + iNumOverwritten++; + bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); + if( bSuccess ) + iNumSuccessful++; + } + } + + { + CString sFromDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_COURSES_SUBDIR; + CString sToDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_COURSES_SUBDIR; + + vector vsFiles; + GetDirListing( sFromDir+"*.crs", vsFiles, false, false ); + FOREACH_CONST( CString, vsFiles, i ) + { + iNumAttempted++; + if( DoesFileExist(sToDir+*i) ) + iNumOverwritten++; + bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); + if( bSuccess ) + iNumSuccessful++; + } + } + + MEMCARDMAN->UnmountCard(pn); + + return ssprintf("Copied to P%d card: %d/%d copies OK (%d overwritten).",pn+1,iNumSuccessful,iNumAttempted,iNumOverwritten); + break; + } + + if( !bTriedToCopy ) + return "Edits not copied - No memory cards ready."; + + MEMCARDMAN->FlushAndReset(); + + return "Edits copied to machine."; +} + +static CString CopyEditsMemoryCardToMachine() +{ + bool bTriedToCopy = false; + FOREACH_PlayerNumber( pn ) + { + if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) + continue; // skip + + MEMCARDMAN->MountCard(pn); + + bTriedToCopy = true; + + int iNumAttempted = 0; + int iNumSuccessful = 0; + int iNumOverwritten = 0; + + { + CString sFromDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_STEPS_SUBDIR; + CString sToDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_STEPS_SUBDIR; + + vector vsFiles; + GetDirListing( sFromDir+"*.edit", vsFiles, false, false ); + FOREACH_CONST( CString, vsFiles, i ) + { + iNumAttempted++; + if( DoesFileExist(sToDir+*i) ) + iNumOverwritten++; + bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); + if( bSuccess ) + iNumSuccessful++; + } + } + + { + CString sFromDir = MEM_CARD_MOUNT_POINT[pn] + (CString)PREFSMAN->m_sMemoryCardProfileSubdir + "/" + EDIT_COURSES_SUBDIR; + CString sToDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_COURSES_SUBDIR; + + vector vsFiles; + GetDirListing( sFromDir+"*.crs", vsFiles, false, false ); + FOREACH_CONST( CString, vsFiles, i ) + { + iNumAttempted++; + if( DoesFileExist(sToDir+*i) ) + iNumOverwritten++; + bool bSuccess = FileCopy( sFromDir+*i, sToDir+*i ); + if( bSuccess ) + iNumSuccessful++; + } + } + + MEMCARDMAN->UnmountCard(pn); + + // reload the machine profile + PROFILEMAN->SaveMachineProfile(); + PROFILEMAN->LoadMachineProfile(); + + return ssprintf("Copied from P%d card: %d/%d copies OK (%d overwritten).",pn+1,iNumSuccessful,iNumAttempted,iNumOverwritten); + break; + } + + if( !bTriedToCopy ) + return "Edits not copied - No memory cards ready."; + + MEMCARDMAN->FlushAndReset(); + + return "Edits copied to memory card."; +} + +static CString ResetPreferences() +{ + PREFSMAN->ResetToFactoryDefaults(); + return "Preferences reset."; +} + + + +REGISTER_SCREEN_CLASS( ScreenServiceAction ); +ScreenServiceAction::ScreenServiceAction( CString sClassName ) : ScreenPrompt( sClassName ) +{ + CString sAction = THEME->GetMetric(m_sName,"Action"); + + CString (*pfn)() = NULL; + + if( sAction == "ClearBookkeepingData" ) pfn = ClearBookkeepingData; + else if( sAction == "ClearMachineStats" ) pfn = ClearMachineStats; + else if( sAction == "ClearMachineEdits" ) pfn = ClearMachineEdits; + else if( sAction == "ClearMemoryCardEdits" ) pfn = ClearMemoryCardEdits; + else if( sAction == "FillMachineStats" ) pfn = FillMachineStats; + else if( sAction == "TransferStatsMachineToMemoryCard" ) pfn = TransferStatsMachineToMemoryCard; + else if( sAction == "TransferStatsMemoryCardToMachine" ) pfn = TransferStatsMemoryCardToMachine; + else if( sAction == "CopyEditsMachineToMemoryCard" ) pfn = CopyEditsMachineToMemoryCard; + else if( sAction == "CopyEditsMemoryCardToMachine" ) pfn = CopyEditsMemoryCardToMachine; + else if( sAction == "ResetPreferences" ) pfn = ResetPreferences; + + ASSERT_M( pfn, sAction ); + + CString s = pfn(); + + ScreenPrompt::SetPromptSettings( s, PROMPT_OK ); +} + +/* + * (c) 2001-2005 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. + */ diff --git a/stepmania/src/ScreenServiceAction.h b/stepmania/src/ScreenServiceAction.h new file mode 100644 index 0000000000..bbfee28674 --- /dev/null +++ b/stepmania/src/ScreenServiceAction.h @@ -0,0 +1,40 @@ +/* ScreenServiceAction - */ + +#ifndef ScreenServiceAction_H +#define ScreenServiceAction_H + +#include "ScreenPrompt.h" + +class ScreenServiceAction : public ScreenPrompt +{ +public: + ScreenServiceAction( CString sName ); +}; + + +#endif + +/* + * (c) 2001-2005 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. + */ diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 6642858795..3a327c923d 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -7,7 +7,7 @@ class LoadingWindow; class Song; class Style; class Steps; -struct PlayerOptions; +class PlayerOptions; struct lua_State; #include "RageTypes.h" diff --git a/stepmania/src/SongOptions.h b/stepmania/src/SongOptions.h index d791882845..72ab4494c9 100644 --- a/stepmania/src/SongOptions.h +++ b/stepmania/src/SongOptions.h @@ -3,8 +3,9 @@ #ifndef SONG_OPTIONS_H #define SONG_OPTIONS_H -struct SongOptions +class SongOptions { +public: enum LifeType { LIFE_BAR=0, diff --git a/stepmania/src/StepMania-net2003.vcproj b/stepmania/src/StepMania-net2003.vcproj index c50fb619f5..1d07aecf1a 100644 --- a/stepmania/src/StepMania-net2003.vcproj +++ b/stepmania/src/StepMania-net2003.vcproj @@ -610,6 +610,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index d6c4b178f0..372689653a 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -1,5 +1,5 @@ # Microsoft Developer Studio Project File - Name="StepMania" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 60000 +# Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Application" 0x0101 @@ -62,7 +62,7 @@ IntDir=.\../Debug6 TargetDir=\cvs\stepmania\Program TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -99,7 +99,7 @@ IntDir=.\../Release6 TargetDir=\cvs\stepmania\Program TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -3008,6 +3008,14 @@ SOURCE=.\ScreenSelectStyle.h # End Source File # Begin Source File +SOURCE=.\ScreenServiceAction.cpp +# End Source File +# Begin Source File + +SOURCE=.\ScreenServiceAction.h +# End Source File +# Begin Source File + SOURCE=.\ScreenSetTime.cpp # End Source File # Begin Source File