Files
itgmania212121/src/ScreenGameplayLesson.cpp
T

220 lines
6.1 KiB
C++
Raw Normal View History

2005-09-08 22:47:16 +00:00
#include "global.h"
#include "ScreenGameplayLesson.h"
#include "RageLog.h"
#include "GameState.h"
2006-11-21 05:02:55 +00:00
#include "GamePreferences.h"
#include "StatsManager.h"
#include "Song.h"
2005-09-08 22:47:16 +00:00
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenGameplayLesson );
2006-01-15 19:49:02 +00:00
ScreenGameplayLesson::ScreenGameplayLesson()
2005-09-08 22:47:16 +00:00
{
m_iCurrentPageIndex = 0;
m_Try = Try_1;
2005-09-08 22:47:16 +00:00
}
void ScreenGameplayLesson::Init()
{
2006-09-30 22:13:20 +00:00
ASSERT( GAMESTATE->GetCurrentStyle() );
2005-09-08 22:47:16 +00:00
ASSERT( GAMESTATE->m_pCurSong );
/* Now that we've set up, init the base class. */
ScreenGameplayNormal::Init();
2005-09-08 22:47:16 +00:00
ClearMessageQueue(); // remove all of the messages set in ScreenGameplay that animate "ready", "here we go", etc.
GAMESTATE->m_bGameplayLeadIn.Set( false );
2005-09-08 22:47:16 +00:00
m_DancingState = STATE_DANCING;
// Load pages
2005-09-08 22:47:16 +00:00
Song *pSong = GAMESTATE->m_pCurSong;
2006-01-22 01:00:06 +00:00
RString sDir = pSong->GetSongDir();
vector<RString> vs;
2005-09-08 22:47:16 +00:00
GetDirListing( sDir+"Page*", vs, true, true );
m_vPages.resize( vs.size() );
2006-01-22 01:00:06 +00:00
FOREACH( RString, vs, s )
2005-09-08 22:47:16 +00:00
{
int i = s - vs.begin();
AutoActor &aa = m_vPages[i];
2005-09-08 22:47:16 +00:00
2006-11-02 06:12:48 +00:00
LuaThreadVariable iIndex( "PageIndex", LuaReference::Create(i) );
LuaThreadVariable iPages( "NumPages", LuaReference::Create( (int)vs.size() ) );
2005-09-08 22:47:16 +00:00
aa.Load( *s );
aa->SetDrawOrder( DRAW_ORDER_OVERLAY+1 );
2005-09-08 22:47:16 +00:00
this->AddChild( aa );
}
FOREACH( AutoActor, m_vPages, aa )
{
bool bIsFirst = aa == m_vPages.begin();
(*aa)->PlayCommand( bIsFirst ? "Show" : "Hide" );
2005-09-08 22:47:16 +00:00
(*aa)->PlayCommand( "On" );
}
2005-09-12 08:04:47 +00:00
// Reset stage number (not relevant in lessons)
GAMESTATE->m_iCurrentStageIndex = 0;
FOREACH_ENUM( PlayerNumber, p )
2007-04-25 03:50:17 +00:00
GAMESTATE->m_iPlayerStageTokens[p] = 1;
2005-09-12 08:04:47 +00:00
// Autoplay during demonstration
FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi )
pi->GetPlayerState()->m_PlayerController = PC_AUTOPLAY;
2005-09-08 22:47:16 +00:00
}
void ScreenGameplayLesson::Input( const InputEventPlus &input )
{
//LOG->Trace( "ScreenGameplayLesson::Input()" );
if( m_iCurrentPageIndex != -1 )
2005-09-08 22:47:16 +00:00
{
// show a lesson page
Screen::Input( input );
}
else
{
// in the "your turn" section"
ScreenGameplay::Input( input );
}
}
void ScreenGameplayLesson::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_NotesEnded )
{
bool bShowingAPage = m_iCurrentPageIndex != -1;
2005-09-08 22:47:16 +00:00
// While showing a page, loop the music.
2005-09-08 22:47:16 +00:00
if( bShowingAPage )
{
ResetAndRestartCurrentSong();
2005-09-08 22:47:16 +00:00
}
else
{
PlayerStageStats &pss = STATSMAN->m_CurStageStats.m_player[PLAYER_1];
2005-09-12 08:04:47 +00:00
int iActual = pss.GetLessonScoreActual();
int iNeeded = pss.GetLessonScoreNeeded();
bool bCleared = iActual >= iNeeded;
bool bAnyTriesLeft = m_Try + 1 < NUM_Try;
if( bCleared )
{
MESSAGEMAN->Broadcast( Message_LessonCleared );
this->HandleScreenMessage( SM_LeaveGameplay );
2005-09-12 08:04:47 +00:00
// Commit scores here since we don't go through an eval screen.
// Only commit if we've cleared. Don't commit if we've failed all 3 tries.
2009-08-09 20:11:23 +00:00
STATSMAN->m_CurStageStats.FinalizeScores( false );
}
else if( bAnyTriesLeft )
{
ResetAndRestartCurrentSong();
m_Try = (Try)(m_Try+1);
2006-11-13 22:36:39 +00:00
MESSAGEMAN->Broadcast( (MessageID)(Message_LessonTry1+m_Try) );
}
else
{
this->HandleScreenMessage( SM_BeginFailed );
MESSAGEMAN->Broadcast( Message_LessonFailed );
}
2005-09-08 22:47:16 +00:00
}
return; // handled
2005-09-08 22:47:16 +00:00
}
ScreenGameplay::HandleScreenMessage( SM );
}
2006-09-15 01:47:24 +00:00
void ScreenGameplayLesson::MenuStart( const InputEventPlus &input )
2005-09-08 22:47:16 +00:00
{
2006-09-15 01:47:24 +00:00
// XXX: Allow repeats?
if( m_iCurrentPageIndex == -1 )
2005-09-08 22:47:16 +00:00
return;
ChangeLessonPage( +1 );
}
2006-09-15 01:47:24 +00:00
void ScreenGameplayLesson::MenuBack( const InputEventPlus &input )
2005-09-08 22:47:16 +00:00
{
2006-09-15 01:47:24 +00:00
// XXX: Allow repeats?
2005-09-12 08:04:47 +00:00
if( m_iCurrentPageIndex == 0 )
{
BeginBackingOutFromGameplay();
return;
}
if( m_iCurrentPageIndex == -1 )
2005-09-08 22:47:16 +00:00
return;
ChangeLessonPage( -1 );
}
void ScreenGameplayLesson::ChangeLessonPage( int iDir )
{
if( m_iCurrentPageIndex + iDir < 0 )
2005-09-08 22:47:16 +00:00
{
// don't change
return;
}
2005-09-11 01:28:25 +00:00
else if( m_iCurrentPageIndex + iDir >= (int)m_vPages.size() )
2005-09-08 22:47:16 +00:00
{
m_vPages[m_iCurrentPageIndex]->PlayCommand( "Hide" );
m_iCurrentPageIndex = -1;
ResetAndRestartCurrentSong();
2005-09-08 22:47:16 +00:00
2006-11-13 22:36:39 +00:00
MESSAGEMAN->Broadcast( (MessageID)(Message_LessonTry1+m_Try) );
2005-09-12 08:04:47 +00:00
// Change back to the current autoplay setting (in most cases, human controlled).
FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi )
{
/* Mike: I'm not sure if you can actually have the player options enabled in this mode,
* but I'm putting the check here anyways to play it safe. If it's unnecessary, then it
* should be removed. */
if( pi->GetPlayerState()->m_PlayerOptions.GetCurrent().m_fPlayerAutoPlay != 0 )
pi->GetPlayerState()->m_PlayerController = PC_AUTOPLAY;
else
pi->GetPlayerState()->m_PlayerController = GamePreferences::m_AutoPlay;
}
2005-09-08 22:47:16 +00:00
}
else
{
m_vPages[m_iCurrentPageIndex]->PlayCommand( "Hide" );
m_iCurrentPageIndex += iDir;
m_vPages[m_iCurrentPageIndex]->PlayCommand( "Show" );
2005-09-08 22:47:16 +00:00
}
}
void ScreenGameplayLesson::ResetAndRestartCurrentSong()
{
STATSMAN->m_CurStageStats.m_player[PLAYER_1].ResetScoreForLesson();
m_pSoundMusic->Stop();
ReloadCurrentSong();
StartPlayingSong( 2, 0 );
}
2005-09-08 22:47:16 +00:00
/*
* (c) 2003-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.
*/