Files
itgmania212121/src/CourseContentsList.cpp
T

190 lines
5.3 KiB
C++
Raw Normal View History

#include "global.h"
#include "CourseContentsList.h"
#include "GameConstantsAndTypes.h"
#include "RageLog.h"
#include "Course.h"
2007-04-07 23:49:40 +00:00
#include "Trail.h"
#include "GameState.h"
2007-04-07 23:49:40 +00:00
#include "XmlFile.h"
2005-07-29 22:59:11 +00:00
#include "ActorUtil.h"
2007-04-07 23:49:40 +00:00
#include "RageUtil.h"
#include "Steps.h"
2005-07-29 22:59:11 +00:00
REGISTER_ACTOR_CLASS( CourseContentsList )
2005-04-10 23:42:47 +00:00
CourseContentsList::~CourseContentsList()
{
2007-04-07 23:49:40 +00:00
FOREACH( Actor *, m_vpDisplay, d )
2005-04-10 23:42:47 +00:00
delete *d;
m_vpDisplay.clear();
2005-03-30 17:42:41 +00:00
}
void CourseContentsList::LoadFromNode( const XNode* pNode )
2005-07-29 22:59:11 +00:00
{
2007-04-08 17:23:02 +00:00
int iMaxSongs = 5;
pNode->GetAttrValue( "MaxSongs", iMaxSongs );
2005-07-29 22:59:11 +00:00
2007-04-07 23:49:40 +00:00
const XNode *pDisplayNode = pNode->GetChild( "Display" );
if( pDisplayNode == NULL )
RageException::Throw( "%s: CourseContentsList: missing the Display child", ActorUtil::GetWhere(pNode).c_str() );
2007-04-08 17:23:02 +00:00
for( int i=0; i<iMaxSongs; i++ )
2007-04-07 23:49:40 +00:00
{
Actor *pDisplay = ActorUtil::LoadFromNode( pDisplayNode, this );
pDisplay->SetUseZBuffer( true );
m_vpDisplay.push_back( pDisplay );
}
2007-04-08 17:23:02 +00:00
ActorScroller::LoadFromNode( pNode );
2005-07-29 22:59:11 +00:00
}
2004-06-03 08:22:02 +00:00
void CourseContentsList::SetFromGameState()
{
2005-04-10 23:42:47 +00:00
RemoveAllChildren();
// FIXME: Is there a better way to handle when players don't have
// the same number of TrailEntries?
2004-05-25 20:47:49 +00:00
// They have to have the same number, and of the same songs, or gameplay
// isn't going to line up.
2008-05-16 02:53:49 +00:00
if( GAMESTATE->m_MasterPlayerNumber == PlayerNumber_Invalid )
return;
2007-04-07 23:49:40 +00:00
const Trail *pMasterTrail = GAMESTATE->m_pCurTrail[GAMESTATE->m_MasterPlayerNumber];
2004-06-06 19:43:31 +00:00
if( pMasterTrail == NULL )
return;
2009-03-22 08:42:27 +00:00
unsigned uNumEntriesToShow = pMasterTrail->m_vEntries.size();
CLAMP( uNumEntriesToShow, 0, m_vpDisplay.size() );
2004-06-03 08:22:02 +00:00
2005-04-10 23:42:47 +00:00
for( int i=0; i<(int)uNumEntriesToShow; i++ )
{
2007-04-07 23:49:40 +00:00
Actor *pDisplay = m_vpDisplay[i];
SetItemFromGameState( pDisplay, i );
this->AddChild( pDisplay );
}
2005-04-10 23:42:47 +00:00
bool bLoop = pMasterTrail->m_vEntries.size() > uNumEntriesToShow;
2006-08-16 18:19:38 +00:00
this->SetLoop( bLoop );
2006-08-16 18:31:00 +00:00
this->Load2();
this->SetTransformFromHeight( m_vpDisplay[0]->GetUnzoomedHeight() );
2005-12-06 03:05:57 +00:00
this->EnableMask( m_vpDisplay[0]->GetUnzoomedWidth(), m_vpDisplay[0]->GetUnzoomedHeight() );
2005-04-10 23:42:47 +00:00
if( bLoop )
{
2005-04-10 23:42:47 +00:00
SetPauseCountdownSeconds( 1.5f );
2007-04-07 23:49:40 +00:00
this->SetDestinationItem( m_vpDisplay.size()+1 ); // loop forever
}
}
void CourseContentsList::SetItemFromGameState( Actor *pActor, int iCourseEntryIndex )
{
const Course *pCourse = GAMESTATE->m_pCurCourse;
FOREACH_HumanPlayer(pn)
{
2007-04-08 17:23:02 +00:00
const Trail *pTrail = GAMESTATE->m_pCurTrail[pn];
if( pTrail == NULL || iCourseEntryIndex >= (int) pTrail->m_vEntries.size() )
2007-04-08 17:23:02 +00:00
continue;
const TrailEntry *te = &pTrail->m_vEntries[iCourseEntryIndex];
const CourseEntry *ce = &pCourse->m_vEntries[iCourseEntryIndex];
2007-04-07 23:49:40 +00:00
if( te == NULL )
continue;
RString s;
Difficulty dc;
if( te->bSecret )
{
if( ce == NULL )
continue;
int iLow = ce->stepsCriteria.m_iLowMeter;
int iHigh = ce->stepsCriteria.m_iHighMeter;
bool bLowIsSet = iLow != -1;
bool bHighIsSet = iHigh != -1;
if( !bLowIsSet && !bHighIsSet )
{
s = "?";
}
if( !bLowIsSet && bHighIsSet )
{
s = ssprintf( ">=%d", iHigh );
}
else if( bLowIsSet && !bHighIsSet )
{
s = ssprintf( "<=%d", iLow );
}
else if( bLowIsSet && bHighIsSet )
{
if( iLow == iHigh )
s = ssprintf( "%d", iLow );
else
s = ssprintf( "%d-%d", iLow, iHigh );
}
dc = te->dc;
if( dc == Difficulty_Invalid )
dc = Difficulty_Edit;
}
else
{
s = ssprintf("%d", te->pSteps->GetMeter());
dc = te->pSteps->GetDifficulty();
}
Message msg("SetSong");
msg.SetParam( "PlayerNumber", pn );
msg.SetParam( "Song", te->pSong );
msg.SetParam( "Steps", te->pSteps );
2007-04-07 23:49:40 +00:00
msg.SetParam( "Difficulty", dc );
msg.SetParam( "Meter", s );
msg.SetParam( "Number", iCourseEntryIndex+1 );
msg.SetParam( "Modifiers", te->Modifiers );
msg.SetParam( "Secret", te->bSecret );
2007-04-07 23:49:40 +00:00
pActor->HandleMessage( msg );
}
}
2005-07-29 22:59:11 +00:00
// lua start
#include "LuaBinding.h"
class LunaCourseContentsList: public Luna<CourseContentsList>
{
public:
static int SetFromGameState( T* p, lua_State *L ) { p->SetFromGameState(); return 0; }
2006-09-27 20:03:31 +00:00
LunaCourseContentsList()
2005-07-29 22:59:11 +00:00
{
2006-09-27 20:03:31 +00:00
ADD_METHOD( SetFromGameState );
2005-07-29 22:59:11 +00:00
}
};
LUA_REGISTER_DERIVED_CLASS( CourseContentsList, ActorScroller )
// lua end
2004-06-07 21:14:03 +00:00
/*
* (c) 2001-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.
*/