diff --git a/stepmania/src/CodeDetector.cpp b/stepmania/src/CodeDetector.cpp index 7478724e6e..60366347ec 100644 --- a/stepmania/src/CodeDetector.cpp +++ b/stepmania/src/CodeDetector.cpp @@ -61,7 +61,8 @@ const CString g_sCodeNames[CodeDetector::NUM_CODES] = { "NextGame", "NextGame2", "NextBannerGroup", - "NextBannerGroup2" + "NextBannerGroup2", + "SaveScreenshot" }; CodeItem g_CodeItems[CodeDetector::NUM_CODES]; diff --git a/stepmania/src/CodeDetector.h b/stepmania/src/CodeDetector.h index 40c36b2f07..868c9b68bc 100644 --- a/stepmania/src/CodeDetector.h +++ b/stepmania/src/CodeDetector.h @@ -74,6 +74,7 @@ public: CODE_NEXT_GAME2, CODE_BW_NEXT_GROUP, CODE_BW_NEXT_GROUP2, + CODE_SAVE_SCREENSHOT, NUM_CODES // leave this at the end }; diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 28a4c4602b..518bf07c22 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -20,6 +20,7 @@ #include "SDL_utils.h" #include "SDL_image.h" #include "RageFile.h" +#include "SDL_SaveJPEG.h" // needs to be added to avoid an error #include "SDL_SaveJPEG.h" diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 203ef33fe9..4a7caf0b51 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -33,6 +33,9 @@ #include "song.h" #include "StageStats.h" #include "Grade.h" +#include "CodeDetector.h" +#include "RageDisplay.h" +#include "StepMania.h" const int NUM_SCORE_DIGITS = 9; @@ -139,6 +142,9 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : Screen(sClassName) m_bFailed = false; // the evaluation is not showing failed results by default + ZERO( m_bSavedScreenshot ); + + m_sName = sClassName; if( !TYPE.CompareNoCase("stage") ) m_Type = stage; @@ -1304,6 +1310,26 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t if( m_Menu.IsTransitioning() ) return; + if( GameI.IsValid() ) + { + PlayerNumber pn = GAMESTATE->GetCurrentStyleDef()->ControllerToPlayerNumber( GameI.controller ); + + if( CodeDetector::EnteredCode(GameI.controller, CodeDetector::CODE_SAVE_SCREENSHOT) ) + { + if( !m_bSavedScreenshot[pn] && // only allow one screenshot + PROFILEMAN->IsUsingProfile(pn) ) + { + /* XXX: What's the difference between this and StyleI.player? */ + /* StyleI won't be valid if it's a menu button that's pressed. + * There's got to be a better way of doing this. -Chris */ + CString sDir = PROFILEMAN->GetProfileDir((ProfileSlot)pn); + SaveScreenshot( sDir ); + m_bSavedScreenshot[pn] = true; + return; // handled + } + } + } + Screen::Input( DeviceI, type, GameI, MenuI, StyleI ); } diff --git a/stepmania/src/ScreenEvaluation.h b/stepmania/src/ScreenEvaluation.h index 4696f61719..32ca56136f 100644 --- a/stepmania/src/ScreenEvaluation.h +++ b/stepmania/src/ScreenEvaluation.h @@ -148,6 +148,7 @@ protected: bool m_bPassFailTriggered; // has the pass / fail sound been played yet? RageTimer m_timerSoundSequences; // timer used for triggering sounds. vector m_SoundSequences; // a sequence of sounds to be played (although they're stored in no particular order!) + bool m_bSavedScreenshot[NUM_PLAYERS]; }; #endif diff --git a/stepmania/src/ScreenEz2SelectMusic.cpp b/stepmania/src/ScreenEz2SelectMusic.cpp index cbeb845e73..a88fdb89e3 100644 --- a/stepmania/src/ScreenEz2SelectMusic.cpp +++ b/stepmania/src/ScreenEz2SelectMusic.cpp @@ -85,7 +85,6 @@ ScreenEz2SelectMusic::ScreenEz2SelectMusic( CString sName ) : Screen( sName ) m_bScanning = false; m_fRemainingWaitTime = 0.0f; i_ErrorDetected=0; - CodeDetector::RefreshCacheItems(); if(PREVIEWMUSICMODE == 4) { diff --git a/stepmania/src/ScreenSelectCourse.cpp b/stepmania/src/ScreenSelectCourse.cpp index 3b10590d31..5fcee86d79 100644 --- a/stepmania/src/ScreenSelectCourse.cpp +++ b/stepmania/src/ScreenSelectCourse.cpp @@ -63,8 +63,6 @@ ScreenSelectCourse::ScreenSelectCourse( CString sClassName ) : Screen( sClassNam /* Finish any previous stage. It's OK to call this when we havn't played a stage yet. */ GAMESTATE->FinishStage(); - CodeDetector::RefreshCacheItems(); - SOUND->PlayMusic( THEME->GetPathToS("ScreenSelectCourse music") ); m_MusicWheel.Load(); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 999e6d6e78..6d02c1f5c7 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -99,8 +99,6 @@ ScreenSelectMusic::ScreenSelectMusic( CString sClassName ) : Screen( sClassName if( GAMESTATE->m_PlayMode == PLAY_MODE_INVALID ) RageException::Throw( "The PlayMode has not been set. A theme must set the PlayMode before loading ScreenSelectMusic." ); - CodeDetector::RefreshCacheItems(); - m_MusicWheel.Load(); int p; @@ -690,6 +688,8 @@ void ScreenSelectMusic::Input( const DeviceInput& DeviceI, InputEventType type, /* XXX: What's the difference between this and StyleI.player? */ + /* StyleI won't be valid if it's a menu button that's pressed. + * There's got to be a better way of doing this. -Chris */ PlayerNumber pn = GAMESTATE->GetCurrentStyleDef()->ControllerToPlayerNumber( GameI.controller ); if( !GAMESTATE->IsHumanPlayer(pn) ) return; diff --git a/stepmania/src/ScreenTitleMenu.cpp b/stepmania/src/ScreenTitleMenu.cpp index c19306a0e7..582804c4d9 100644 --- a/stepmania/src/ScreenTitleMenu.cpp +++ b/stepmania/src/ScreenTitleMenu.cpp @@ -80,8 +80,6 @@ ScreenTitleMenu::ScreenTitleMenu( CString sClassName ) : ScreenSelect( sClassNam LIGHTSMAN->SetLightMode( LIGHTMODE_JOINING ); // do this after Reset! - CodeDetector::RefreshCacheItems(); - m_sprLogo.Load( THEME->GetPathToG(ssprintf("ScreenLogo %s",GAMESTATE->GetCurrentGameDef()->m_szName)) ); m_sprLogo.Command( PREFSMAN->m_iCoinMode==COIN_HOME ? LOGO_HOME_ON_COMMAND : LOGO_ON_COMMAND ); this->AddChild( &m_sprLogo ); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index a6b4c5473d..1fcd497e50 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -31,6 +31,8 @@ #include "SDL_utils.h" +#include "CodeDetector.h" + // // StepMania global classes // @@ -995,6 +997,8 @@ int main(int argc, char* argv[]) ResetGame(); + CodeDetector::RefreshCacheItems(); + /* Initialize which courses are ranking courses here. */ SONGMAN->UpdateRankingCourses(); @@ -1079,6 +1083,28 @@ int main(int argc, char* argv[]) return 0; } +bool SaveScreenshot( CString sDir, bool bSaveUncompressed ) +{ + // Save Screenshot. + CString sPath; + + FlushDirCache(); + + /* XXX slow? */ + for( int i=0; i<10000; i++ ) + { + sPath = ssprintf( sDir+"screen%04d.%s",i,bSaveUncompressed ? "bmp" : "jpg" ); + if( !DoesFileExist(sPath) ) + break; + } + bool bResult = DISPLAY->SaveScreenshot( sPath, bSaveUncompressed ? RageDisplay::bmp : RageDisplay::jpg ); + if( bResult ) + SOUND->PlayOnce( THEME->GetPathToS("Common screenshot") ); + else + SOUND->PlayOnce( THEME->GetPathToS("Common invalid") ); + return bResult; +} + /* Returns true if the key has been handled and should be discarded, false if * the key should be sent on to screens. */ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput GameI, MenuInput MenuI, StyleInput StyleI ) @@ -1124,6 +1150,7 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam TEXTUREMAN->ReloadAll(); SCREENMAN->ReloadCreditsText(); NOTESKIN->RefreshNoteSkinData( GAMESTATE->m_CurGame ); + CodeDetector::RefreshCacheItems(); // HACK: Also save bookkeeping and profile info for debugging // so we don't have to play through a whole song to get new output. @@ -1178,24 +1205,7 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam { // If holding LShift save a BMP, else save a JPG bool bSaveBmp = INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LSHIFT) ); - - // Save Screenshot. - CString sPath; - - FlushDirCache(); - - /* XXX slow? */ - for( int i=0; i<10000; i++ ) - { - sPath = ssprintf("Screenshots/screen%04d.%s",i,bSaveBmp?"bmp":"jpg"); - if( !DoesFileExist(sPath) ) - break; - } - bool bResult = DISPLAY->SaveScreenshot( sPath, bSaveBmp ? RageDisplay::bmp : RageDisplay::jpg ); - if( bResult ) - SOUND->PlayOnce( THEME->GetPathToS("Common screenshot") ); - else - SOUND->PlayOnce( THEME->GetPathToS("Common invalid") ); + SaveScreenshot( "Screenshots/", bSaveBmp ? RageDisplay::bmp : RageDisplay::jpg ); return true; // handled } diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 97760d6f7f..9b858b1736 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -20,6 +20,7 @@ void ResetGame( bool ReturnToFirstScreen=true ); void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame=true ); void SaveGamePrefsToDisk(); void ChangeCurrentGame( Game g ); +bool SaveScreenshot( CString sDir, bool bSaveUncompressed = false ); #if defined(_WINDOWS) #include "windows.h"