Files
itgmania212121/stepmania/src/CourseContentsList.cpp
T

174 lines
5.3 KiB
C++
Raw Normal View History

#include "global.h"
#include "CourseContentsList.h"
#include "RageUtil.h"
#include "GameConstantsAndTypes.h"
#include "PrefsManager.h"
#include "RageLog.h"
#include "PrefsManager.h"
#include "Course.h"
#include "SongManager.h"
#include "ThemeManager.h"
2003-08-03 00:13:55 +00:00
#include "Steps.h"
#include "GameState.h"
2004-06-28 07:26:00 +00:00
#include "Style.h"
2003-11-07 20:46:04 +00:00
#include "RageTexture.h"
CourseContentsList::CourseContentsList()
{
m_iNumContents = 0;
2003-05-29 01:30:41 +00:00
m_quad.SetDiffuse( RageColor(0,0,0,1) );
m_quad.SetBlendMode( BLEND_NO_EFFECT ); // invisible, since we want to write only to the Zbuffer
m_fTimeUntilScroll = 0;
m_fItemAtTopOfList = 0;
2005-03-30 17:42:41 +00:00
ContentsBarHeight = 1;
ContentsBarWidth = 1;
}
void CourseContentsList::Load()
{
2003-05-29 01:30:41 +00:00
m_quad.SetUseZBuffer( true );
for( int i = 0; i < MAX_TOTAL_CONTENTS; ++i )
2003-11-16 21:44:42 +00:00
{
m_CourseContentDisplays[i].SetName( "CourseEntryDisplay" );
m_CourseContentDisplays[i].Load();
2003-05-29 01:30:41 +00:00
m_CourseContentDisplays[i].SetUseZBuffer( true );
2003-11-16 21:44:42 +00:00
}
2003-05-29 01:30:41 +00:00
/* These are all the same; grab the dimensions. */
2003-11-16 21:44:42 +00:00
ContentsBarHeight = m_CourseContentDisplays[0].GetUnzoomedHeight();
ContentsBarWidth = m_CourseContentDisplays[0].GetUnzoomedWidth();
}
2004-06-03 08:22:02 +00:00
void CourseContentsList::SetFromGameState()
{
2004-06-03 08:22:02 +00:00
Course* pCourse = GAMESTATE->m_pCurCourse;
2003-07-20 02:27:37 +00:00
if( pCourse == NULL )
{
m_iNumContents = 0;
return;
}
// 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.
2004-06-06 19:43:31 +00:00
Trail* pMasterTrail = GAMESTATE->m_pCurTrail[GAMESTATE->m_MasterPlayerNumber];
if( pMasterTrail == NULL )
return;
2004-06-03 08:22:02 +00:00
int iNumEntriesToShow = min((int)pMasterTrail->m_vEntries.size(), MAX_TOTAL_CONTENTS);
m_iNumContents = 0;
2004-06-03 08:22:02 +00:00
for( int i=0; i<iNumEntriesToShow; i++ )
{
CourseEntryDisplay& display = m_CourseContentDisplays[m_iNumContents];
2004-06-06 19:43:31 +00:00
2004-06-03 20:49:10 +00:00
const TrailEntry* pte[NUM_PLAYERS];
2004-06-06 20:18:50 +00:00
ZERO( pte );
FOREACH_EnabledPlayer(pn)
2004-06-06 19:43:31 +00:00
{
2004-06-06 20:08:11 +00:00
Trail* pTrail = GAMESTATE->m_pCurTrail[pn];
if( pTrail == NULL )
2004-06-06 20:18:50 +00:00
continue; // skip
2004-06-06 20:27:52 +00:00
if( unsigned(i) < pTrail->m_vEntries.size() )
2004-06-06 20:18:50 +00:00
pte[pn] = &pTrail->m_vEntries[i];
2004-06-06 19:43:31 +00:00
}
2004-06-03 20:49:10 +00:00
display.LoadFromTrailEntry( m_iNumContents+1, pte );
2004-01-21 06:58:01 +00:00
m_iNumContents++;
}
}
void CourseContentsList::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
if( m_fTimeUntilScroll > 0 && m_iNumContents > MAX_VISIBLE_CONTENTS)
m_fTimeUntilScroll -= fDeltaTime;
if( m_fTimeUntilScroll <= 0 ) {
m_fItemAtTopOfList += fDeltaTime;
m_fItemAtTopOfList = fmodf(m_fItemAtTopOfList, float(m_iNumContents));
}
for( int i=0; i<m_iNumContents; i++ )
m_CourseContentDisplays[i].Update( fDeltaTime );
}
void CourseContentsList::DrawPrimitives()
{
// write to z buffer so that top and bottom are clipped
m_quad.SetZ( 1 );
2003-11-16 21:44:42 +00:00
RectF rectBarSize(-ContentsBarWidth/2, -ContentsBarHeight/2,
ContentsBarWidth/2, ContentsBarHeight/2);
m_quad.StretchTo( rectBarSize );
m_quad.SetY( (-(MAX_VISIBLE_CONTENTS-1)/2 - 1) * float(ContentsBarHeight) );
m_quad.Draw();
m_quad.SetY( ((MAX_VISIBLE_CONTENTS-1)/2 + 1) * float(ContentsBarHeight) );
m_quad.Draw();
int iItemToDraw = (int)m_fItemAtTopOfList;
// HACK: Insert a little pause as a new item appears on the screen
float fRemainder = m_fItemAtTopOfList - (int)m_fItemAtTopOfList;
fRemainder = min( fRemainder*1.5f, 1 );
const float fY = (-fRemainder-(MAX_VISIBLE_CONTENTS-1)/2) * ContentsBarHeight;
for( int i=0; i<min(MAX_VISIBLE_CONTENTS+1, m_iNumContents); i++ )
{
if( m_fTimeUntilScroll <= 0 )
m_CourseContentDisplays[iItemToDraw].SetY( fY + i*ContentsBarHeight);
m_CourseContentDisplays[iItemToDraw].Draw();
iItemToDraw = (iItemToDraw+1) % m_iNumContents;
}
}
void CourseContentsList::TweenInAfterChangedCourse()
{
m_fItemAtTopOfList = 0;
m_fTimeUntilScroll = 3;
for( int i=0; i<m_iNumContents; i++ )
{
CourseEntryDisplay& display = m_CourseContentDisplays[i];
display.StopTweening();
2003-03-28 02:15:29 +00:00
display.SetXY( 0, -((MAX_VISIBLE_CONTENTS-1)/2) * float(ContentsBarHeight) );
display.BeginTweening( i*0.1f );
2003-04-12 06:16:12 +00:00
display.SetY( (-(MAX_VISIBLE_CONTENTS-1)/2 + i) * float(ContentsBarHeight) );
}
}
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.
*/