From 9580a5f8a4583312de77e36afe22a4f563cff49b Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 9 Sep 2005 21:49:29 +0000 Subject: [PATCH] add "success/try again" looping logic to lesson mode --- stepmania/src/MessageManager.cpp | 3 +- stepmania/src/MessageManager.h | 1 + stepmania/src/PlayerStageStats.cpp | 66 ++++++++++++++++++ stepmania/src/PlayerStageStats.h | 4 ++ stepmania/src/ScreenGameplay.cpp | 11 ++- stepmania/src/ScreenGameplay.h | 3 + stepmania/src/ScreenGameplayLesson.cpp | 97 +++++++++++++++++++------- stepmania/src/ScreenGameplayLesson.h | 17 ++++- 8 files changed, 171 insertions(+), 31 deletions(-) diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp index 0a9ab7b593..9cd21f5f76 100644 --- a/stepmania/src/MessageManager.cpp +++ b/stepmania/src/MessageManager.cpp @@ -56,7 +56,8 @@ static const CString MessageNames[] = { "AutosyncChanged", "PreferredSongGroupChanged", "PreferredCourseGroupChanged", - "SortOrderChanged" + "SortOrderChanged", + "LessonYourTurn", }; XToString( Message, NUM_Message ); diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h index b07e4af4f4..92c3d66ca5 100644 --- a/stepmania/src/MessageManager.h +++ b/stepmania/src/MessageManager.h @@ -72,6 +72,7 @@ enum Message Message_PreferredSongGroupChanged, Message_PreferredCourseGroupChanged, Message_SortOrderChanged, + Message_LessonYourTurn, NUM_Message, // leave this at the end Message_Invalud }; diff --git a/stepmania/src/PlayerStageStats.cpp b/stepmania/src/PlayerStageStats.cpp index 7bd5466e67..9d582c82f7 100644 --- a/stepmania/src/PlayerStageStats.cpp +++ b/stepmania/src/PlayerStageStats.cpp @@ -220,6 +220,68 @@ float PlayerStageStats::GetCurMaxPercentDancePoints() const return fCurMaxPercentDancePoints; } +int PlayerStageStats::GetLessonScoreActual() const +{ + int iScore = 0; + + FOREACH_TapNoteScore( tns ) + { + switch( tns ) + { + case TNS_AVOIDED_MINE: + case TNS_MISS: + case TNS_BOO: + case TNS_GOOD: + case TNS_GREAT: + case TNS_PERFECT: + case TNS_MARVELOUS: + iScore += iTapNoteScores[tns]; + break; + } + } + + FOREACH_HoldNoteScore( hns ) + { + switch( hns ) + { + case HNS_OK: + iScore += iHoldNoteScores[hns]; + break; + } + } + + return iScore; +} + +int PlayerStageStats::GetLessonScorePossible() const +{ + int iScore = 0; + + FOREACH_TapNoteScore( tns ) + iScore += iTapNoteScores[tns]; + + FOREACH_HoldNoteScore( hns ) + iScore += iHoldNoteScores[hns]; + + return iScore; +} + +void PlayerStageStats::ResetScoreForLesson() +{ + iCurPossibleDancePoints = 0; + iActualDancePoints = 0; + FOREACH_TapNoteScore( tns ) + iTapNoteScores[tns] = 0; + FOREACH_HoldNoteScore( hns ) + iHoldNoteScores[hns] = 0; + iCurCombo = 0; + iMaxCombo = 0; + iCurMissCombo = 0; + iScore = 0; + iCurMaxScore = 0; + iMaxScore = 0; +} + void PlayerStageStats::SetLifeRecordAt( float fLife, float fStepsSecond ) { // Don't save life stats in endless courses, or could run OOM in a few hours. @@ -462,6 +524,8 @@ public: static int FullCombo( T* p, lua_State *L ) { lua_pushnumber(L, p->FullCombo()); return 1; } static int MaxCombo( T* p, lua_State *L ) { lua_pushnumber(L, p->GetMaxCombo().cnt); return 1; } static int GetGrade( T* p, lua_State *L ) { lua_pushnumber(L, p->GetGrade()); return 1; } + static int GetLessonScoreActual( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLessonScoreActual()); return 1; } + static int GetLessonScorePossible( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLessonScorePossible()); return 1; } static void Register(lua_State *L) { @@ -471,6 +535,8 @@ public: ADD_METHOD( FullCombo ) ADD_METHOD( MaxCombo ) ADD_METHOD( GetGrade ) + ADD_METHOD( GetLessonScoreActual ) + ADD_METHOD( GetLessonScorePossible ) Luna::Register( L ); } }; diff --git a/stepmania/src/PlayerStageStats.h b/stepmania/src/PlayerStageStats.h index 056af3a3e5..14db89373b 100644 --- a/stepmania/src/PlayerStageStats.h +++ b/stepmania/src/PlayerStageStats.h @@ -23,6 +23,10 @@ public: float GetPercentDancePoints() const; float GetCurMaxPercentDancePoints() const; + int GetLessonScoreActual() const; + int GetLessonScorePossible() const; + void ResetScoreForLesson(); + vector vpPlayedSteps; vector vpPossibleSteps; float fAliveSeconds; // how far into the music did they last before failing? Updated by Gameplay, scaled by music rate. diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 000620dc00..f52079f998 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -82,9 +82,6 @@ AutoScreenMessage( SM_StartLoadingNextSong ) // received while STATE_OUTRO AutoScreenMessage( SM_GoToScreenAfterBack ) -AutoScreenMessage( SM_BeginFailed ) -AutoScreenMessage( SM_LeaveGameplay ) - // received while STATE_INTRO AutoScreenMessage( SM_StartHereWeGo ) AutoScreenMessage( SM_StopHereWeGo ) @@ -1051,6 +1048,14 @@ void ScreenGameplay::LoadCourseSongNumber( int iSongNumber ) SCREENMAN->ZeroNextUpdate(); } +void ScreenGameplay::ReloadCurrentSong() +{ + FOREACH_EnabledPlayerInfoNotDummy( m_vPlayerInfo, pi ) + pi->GetPlayerStageStats()->iSongsPlayed--; + + LoadNextSong(); +} + void ScreenGameplay::LoadNextSong() { GAMESTATE->ResetMusicStatistics(); diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index c2319d2692..8f771e12d6 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -34,6 +34,8 @@ class ScoreKeeper; class PlayerScoreList; AutoScreenMessage( SM_NotesEnded ) +AutoScreenMessage( SM_BeginFailed ) +AutoScreenMessage( SM_LeaveGameplay ) class PlayerInfo { @@ -132,6 +134,7 @@ protected: bool IsLastSong(); void SetupSong( int iSongIndex ); + void ReloadCurrentSong(); void LoadNextSong(); void LoadCourseSongNumber( int SongNumber ); float StartPlayingSong(float MinTimeToNotes, float MinTimeToMusic); diff --git a/stepmania/src/ScreenGameplayLesson.cpp b/stepmania/src/ScreenGameplayLesson.cpp index 73c0cb1135..c48c2f251d 100644 --- a/stepmania/src/ScreenGameplayLesson.cpp +++ b/stepmania/src/ScreenGameplayLesson.cpp @@ -3,13 +3,15 @@ #include "RageLog.h" #include "GameState.h" #include "PrefsManager.h" +#include "StatsManager.h" REGISTER_SCREEN_CLASS( ScreenGameplayLesson ); ScreenGameplayLesson::ScreenGameplayLesson( CString sName ) : ScreenGameplayNormal( sName ) { LOG->Trace( "ScreenGameplayLesson::ScreenGameplayLesson()" ); - m_iCurrentLessonPageIndex = 0; + m_iCurrentPageIndex = 0; + m_Try = Try_1; } void ScreenGameplayLesson::Init() @@ -27,16 +29,16 @@ void ScreenGameplayLesson::Init() m_DancingState = STATE_DANCING; - // Load lessons + // Load pages Song *pSong = GAMESTATE->m_pCurSong; CString sDir = pSong->GetSongDir(); vector vs; GetDirListing( sDir+"Page*", vs, true, true ); - m_vLessonPages.resize( vs.size() ); + m_vPages.resize( vs.size() ); FOREACH( CString, vs, s ) { int i = s - vs.begin(); - AutoActor &aa = m_vLessonPages[i]; + AutoActor &aa = m_vPages[i]; LUA->SetGlobal( "PageIndex", i ); @@ -46,28 +48,44 @@ void ScreenGameplayLesson::Init() LUA->UnsetGlobal( "NumPages" ); - aa->SetDrawOrder( DRAW_ORDER_OVERLAY ); + aa->SetDrawOrder( DRAW_ORDER_OVERLAY+1 ); this->AddChild( aa ); } this->SortByDrawOrder(); // Show the first lesson page - if( !m_vLessonPages.empty() ) + if( !m_vPages.empty() ) { - AutoActor &aa = m_vLessonPages[0]; - aa->PlayCommand( "Show" ); + AutoActor &aa = m_vPages[0]; } - FOREACH( AutoActor, m_vLessonPages, aa ) + FOREACH( AutoActor, m_vPages, aa ) + { + bool bIsFirst = aa == m_vPages.begin(); + (*aa)->PlayCommand( bIsFirst ? "Show" : "Hide" ); (*aa)->PlayCommand( "On" ); + } + + + // load Try graphics + for( int i=0; iGetPathB(m_sName,s) ); + m_sprTry[i]->PlayCommand( "Hide" ); + m_sprTry[i]->SetDrawOrder( DRAW_ORDER_OVERLAY+1 ); + this->AddChild( m_sprTry[i] ); + } + + this->SortByDrawOrder(); } void ScreenGameplayLesson::Input( const InputEventPlus &input ) { //LOG->Trace( "ScreenGameplayLesson::Input()" ); - if( m_iCurrentLessonPageIndex != -1 ) + if( m_iCurrentPageIndex != -1 ) { // show a lesson page Screen::Input( input ); @@ -83,16 +101,37 @@ void ScreenGameplayLesson::HandleScreenMessage( const ScreenMessage SM ) { if( SM == SM_NotesEnded ) { - bool bShowingAPage = m_iCurrentLessonPageIndex != -1; + bool bShowingAPage = m_iCurrentPageIndex != -1; + // While showing a page, loop the music. if( bShowingAPage ) { - // reload and loop + ResetAndRestartCurrentSong(); } else { - // show finish message if passed, loop if failed + bool bCleared = false; // TODO + bool bAnyTriesLeft = m_Try + 1 < NUM_Try; + + if( bCleared ) + { + this->HandleScreenMessage( SM_LeaveGameplay ); + } + else if( bAnyTriesLeft ) + { + ResetAndRestartCurrentSong(); + + m_sprTry[m_Try]->PlayCommand( "Hide" ); + m_Try = (Try)(m_Try+1); + m_sprTry[m_Try]->PlayCommand( "Show" ); + } + else + { + m_sprTry[m_Try]->PlayCommand( "Hide" ); + this->HandleScreenMessage( SM_BeginFailed ); + } } + return; // handled } ScreenGameplay::HandleScreenMessage( SM ); @@ -100,41 +139,51 @@ void ScreenGameplayLesson::HandleScreenMessage( const ScreenMessage SM ) void ScreenGameplayLesson::MenuStart( PlayerNumber pn ) { - if( m_iCurrentLessonPageIndex == -1 ) + if( m_iCurrentPageIndex == -1 ) return; ChangeLessonPage( +1 ); } void ScreenGameplayLesson::MenuBack( PlayerNumber pn ) { - if( m_iCurrentLessonPageIndex == -1 ) + if( m_iCurrentPageIndex == -1 ) return; ChangeLessonPage( -1 ); } void ScreenGameplayLesson::ChangeLessonPage( int iDir ) { - if( m_iCurrentLessonPageIndex + iDir < 0 ) + if( m_iCurrentPageIndex + iDir < 0 ) { // don't change return; } - else if( m_iCurrentLessonPageIndex + iDir >= m_vLessonPages.size() ) + else if( m_iCurrentPageIndex + iDir >= m_vPages.size() ) { - // dismissed the last page. Proceed to the "your turn" portion. - FOREACH( AutoActor, m_vLessonPages, aa ) - (*aa)->PlayCommand( "Off" ); + m_vPages[m_iCurrentPageIndex]->PlayCommand( "Hide" ); + m_iCurrentPageIndex = -1; + m_sprTry[m_Try]->PlayCommand( "Show" ); - m_iCurrentLessonPageIndex = -1; + ResetAndRestartCurrentSong(); + + MESSAGEMAN->Broadcast( Message_LessonYourTurn ); } else { - m_vLessonPages[m_iCurrentLessonPageIndex]->PlayCommand( "Hide" ); - m_iCurrentLessonPageIndex += iDir; - m_vLessonPages[m_iCurrentLessonPageIndex]->PlayCommand( "Show" ); + m_vPages[m_iCurrentPageIndex]->PlayCommand( "Hide" ); + m_iCurrentPageIndex += iDir; + m_vPages[m_iCurrentPageIndex]->PlayCommand( "Show" ); } } +void ScreenGameplayLesson::ResetAndRestartCurrentSong() +{ + STATSMAN->m_CurStageStats.m_player[PLAYER_1].ResetScoreForLesson(); + m_pSoundMusic->Stop(); + ReloadCurrentSong(); + StartPlayingSong( 2, 0 ); +} + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/ScreenGameplayLesson.h b/stepmania/src/ScreenGameplayLesson.h index 0421fcf398..4f346906f8 100644 --- a/stepmania/src/ScreenGameplayLesson.h +++ b/stepmania/src/ScreenGameplayLesson.h @@ -1,4 +1,4 @@ -/* ScreenGameplayLesson - Plays whole songs continuously. */ +/* ScreenGameplayLesson - Shows some explanation pages, then allows 3 tries to pass a song. */ #ifndef ScreenGameplayLesson_H #define ScreenGameplayLesson_H @@ -20,9 +20,20 @@ public: protected: void ChangeLessonPage( int iDir ); + void ResetAndRestartCurrentSong(); - vector m_vLessonPages; - int m_iCurrentLessonPageIndex; + vector m_vPages; + int m_iCurrentPageIndex; + + enum Try + { + Try_1, + Try_2, + Try_3, + NUM_Try + }; + AutoActor m_sprTry[NUM_Try]; + Try m_Try; }; #endif