2002-12-05 03:49:46 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
Class: MusicBannerWheel
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Andrew Livy
-----------------------------------------------------------------------------
*/
#include "MusicBannerWheel.h"
#include "RageUtil.h"
#include "GameState.h"
#include "PrefsManager.h"
#include "SongManager.h"
#include "ThemeManager.h"
#include "RageMusic.h"
2002-12-20 19:05:54 +00:00
#include "StyleDef.h"
2002-12-05 03:49:46 +00:00
#define BANNERSPACING 200
2002-12-10 23:16:44 +00:00
#define MAXSONGSINBUFFER 5
#define BANNERTYPE 1
2002-12-05 03:49:46 +00:00
2003-01-01 17:20:36 +00:00
#define DEFAULT_SCROLL_DIRECTION THEME->GetMetricI("Notes","DefaultScrollDirection")
2002-12-05 03:49:46 +00:00
MusicBannerWheel :: MusicBannerWheel ()
{
currentPos = 0 ;
2002-12-10 23:16:44 +00:00
scrlistPos = 0 ;
2002-12-29 23:24:53 +00:00
SongsExist = 0 ;
2002-12-31 03:09:58 +00:00
SingleLoad = 0 ;
2002-12-05 03:49:46 +00:00
2003-01-01 17:20:36 +00:00
if ( DEFAULT_SCROLL_DIRECTION && GAMESTATE -> m_pCurSong == NULL ) /* check the song is null... incase they have just come back from a song and changed their PlayerOptions */
{
for ( int i = 0 ; i < NUM_PLAYERS ; i ++ )
GAMESTATE -> m_PlayerOptions [ i ]. m_bReverseScroll = true ;
}
2002-12-10 23:16:44 +00:00
m_ScrollingList . UseSpriteType ( BANNERTYPE );
2002-12-05 03:49:46 +00:00
m_ScrollingList . SetXY ( 0 , 0 );
m_ScrollingList . SetSpacing ( BANNERSPACING );
this -> AddChild ( & m_ScrollingList );
2002-12-29 23:24:53 +00:00
if ( 0 == stricmp ( GAMESTATE -> m_sPreferredGroup , "All Music" ) )
{
arraySongs = SONGMAN -> m_pSongs ;
}
else // Get the Group They Want
{
for ( unsigned i = 0 ; i < SONGMAN -> m_pSongs . size (); i ++ )
{
Song * pSong = SONGMAN -> m_pSongs [ i ];
if ( GAMESTATE -> m_sPreferredGroup != "ALL MUSIC" && pSong -> m_sGroupName != GAMESTATE -> m_sPreferredGroup )
{
continue ;
}
else
{
arraySongs . push_back ( pSong );
}
}
}
if ( arraySongs . size () > 0 )
{
SongsExist = 1 ;
}
else
{
SongsExist = 0 ;
return ;
}
2002-12-05 03:49:46 +00:00
2002-12-20 19:05:54 +00:00
// If there is no currently selected song, select one.
if ( GAMESTATE -> m_pCurSong == NULL )
{
currentPos = 0 ;
}
else // theres a song already selected (i.e. they came back from gameplay)...
{
// find our song and change the currentPos to wherever it may be.
for ( int i = 0 ; i < arraySongs . size (); i ++ )
{
if ( GAMESTATE -> m_pCurSong == arraySongs [ i ])
{
currentPos = i ;
i = ( arraySongs . size () - 1 ); // get us out of the loop by moving i ahead to the end
}
}
}
2002-12-10 23:16:44 +00:00
LoadSongData ();
m_debugtext . LoadFromFont ( THEME -> GetPathTo ( "Fonts" , "small titles" ) );
m_debugtext . SetXY ( 0 , - 120 );
this -> AddChild ( & m_debugtext );
2002-12-05 03:49:46 +00:00
}
2002-12-10 23:16:44 +00:00
/************ TODO: OPTIMIZE THIS: MUST!!!! ********************/
void MusicBannerWheel :: LoadSongData ()
2002-12-05 03:49:46 +00:00
{
Song * pSong ;
CStringArray asGraphicPaths ;
2002-12-31 03:09:58 +00:00
if ( MAXSONGSINBUFFER >= arraySongs . size () && SingleLoad != 1 ) // less than the MAXSONGSINBUFFER means we can get away with loading the lot in one go
{
SingleLoad = 2 ;
int difference = 0 ;
// find out just how short of a full buffer we are =)
difference = MAXSONGSINBUFFER - arraySongs . size ();
for ( int i = 0 ; i <= difference ; i ++ )
{
for ( int c = 0 ; c < arraySongs . size (); c ++ )
{
pSong = arraySongs [ c ];
if ( pSong == NULL ) asGraphicPaths . push_back ( THEME -> GetPathTo ( "Graphics" , "fallback banner" ));
else if ( pSong -> HasBanner ()) asGraphicPaths . push_back ( pSong -> GetBannerPath ());
else if ( PREFSMAN -> m_bUseBGIfNoBanner && pSong -> HasBackground () ) asGraphicPaths . push_back ( pSong -> GetBannerPath ());
else asGraphicPaths . push_back ( THEME -> GetPathTo ( "Graphics" , "fallback banner" ));
}
}
2002-12-10 23:16:44 +00:00
}
2002-12-31 03:09:58 +00:00
if ( SingleLoad == 0 )
{
for ( int count = 0 ; count < MAXSONGSINBUFFER ; count ++ )
{
/* In essence, this element is the central one so we want the scrolling list
to load in the song as specified by currentPos */
if ( count == scrlistPos )
{
pSong = arraySongs [ currentPos ];
}
/* if it's the next element
*/
else if ( count == scrlistPos + 2 || ( scrlistPos == MAXSONGSINBUFFER - 2 && count == 0 ))
{
if ( currentPos + 2 <= arraySongs . size () - 1 )
pSong = arraySongs [ currentPos + 2 ];
else
pSong = arraySongs [ 0 + 2 ];
}
else if ( count == scrlistPos - 2 || ( scrlistPos == 0 && count == MAXSONGSINBUFFER - 2 ))
{
if ( currentPos - 2 >= 0 )
pSong = arraySongs [ currentPos - 2 ];
else
pSong = arraySongs [ arraySongs . size () - 2 ];
}
else if ( count == scrlistPos + 1 || ( scrlistPos == MAXSONGSINBUFFER - 1 && count == 0 ))
{
if ( currentPos + 1 <= arraySongs . size () - 1 )
pSong = arraySongs [ currentPos + 1 ];
else
pSong = arraySongs [ 0 ];
}
/* if it's the previous element OR if we're at element 0..the 5th element (which will wrap to before element 0)
will actually appear as 5 songs along and not the one immediately before it,, so pull a sneaky and make the
final element actually be the song before... */
else if ( count == scrlistPos - 1 || ( scrlistPos == 0 && count == MAXSONGSINBUFFER - 1 ))
{
if ( currentPos - 1 >= 0 )
pSong = arraySongs [ currentPos - 1 ];
else
pSong = arraySongs [ arraySongs . size () - 1 ];
}
if ( pSong == NULL ) asGraphicPaths . push_back ( THEME -> GetPathTo ( "Graphics" , "fallback banner" ));
else if ( pSong -> HasBanner ()) asGraphicPaths . push_back ( pSong -> GetBannerPath ());
else if ( PREFSMAN -> m_bUseBGIfNoBanner && pSong -> HasBackground () ) asGraphicPaths . push_back ( pSong -> GetBannerPath ());
else asGraphicPaths . push_back ( THEME -> GetPathTo ( "Graphics" , "fallback banner" ));
}
}
if ( SingleLoad != 1 )
m_ScrollingList . Load ( asGraphicPaths );
if ( SingleLoad == 2 )
SingleLoad = 1 ;
2002-12-10 23:16:44 +00:00
PlayMusicSample ();
2002-12-05 03:49:46 +00:00
}
2002-12-10 23:16:44 +00:00
2002-12-05 03:49:46 +00:00
Song * MusicBannerWheel :: GetSelectedSong ()
{
Song * pSong ;
2002-12-10 23:16:44 +00:00
pSong = arraySongs [ currentPos ];
2002-12-05 03:49:46 +00:00
return ( pSong );
}
void MusicBannerWheel :: PlayMusicSample ()
{
Song * pSong = GetSelectedSong ();
if ( pSong && pSong -> HasMusic () )
{
MUSIC -> Stop ();
MUSIC -> Load ( pSong -> GetMusicPath () );
MUSIC -> Play ( true , pSong -> m_fMusicSampleStartSeconds , pSong -> m_fMusicSampleLengthSeconds );
}
}
void MusicBannerWheel :: BannersLeft ()
{
2002-12-10 23:16:44 +00:00
if ( currentPos == 0 )
currentPos = arraySongs . size () - 1 ;
else
currentPos -- ;
if ( scrlistPos == 0 )
2002-12-31 03:09:58 +00:00
if ( SingleLoad == 0 )
scrlistPos = MAXSONGSINBUFFER - 1 ;
else
scrlistPos = arraySongs . size () - 1 ;
2002-12-10 23:16:44 +00:00
else
scrlistPos -- ;
2002-12-31 03:09:58 +00:00
if ( SingleLoad == 0 )
m_ScrollingList . Unload ();
2002-12-10 23:16:44 +00:00
LoadSongData ();
m_debugtext . SetText ( ssprintf ( "currentPos: %d scrlistPos: %d" , currentPos , scrlistPos ));
2002-12-05 03:49:46 +00:00
m_ScrollingList . Left ();
2002-12-20 19:05:54 +00:00
ChangeNotes ();
2002-12-05 03:49:46 +00:00
}
void MusicBannerWheel :: BannersRight ()
{
2002-12-10 23:16:44 +00:00
if ( currentPos >= arraySongs . size () - 1 )
currentPos = 0 ;
else
currentPos ++ ;
if ( scrlistPos == MAXSONGSINBUFFER - 1 )
scrlistPos = 0 ;
else
scrlistPos ++ ;
2002-12-31 03:09:58 +00:00
if ( SingleLoad == 0 )
m_ScrollingList . Unload ();
2002-12-10 23:16:44 +00:00
LoadSongData ();
m_debugtext . SetText ( ssprintf ( "currentPos: %d scrlistPos: %d" , currentPos , scrlistPos ));
2002-12-05 03:49:46 +00:00
m_ScrollingList . Right ();
2002-12-20 19:05:54 +00:00
ChangeNotes ();
2002-12-05 03:49:46 +00:00
}
2002-12-20 19:05:54 +00:00
void MusicBannerWheel :: ChangeNotes ()
{
}
2002-12-05 03:49:46 +00:00
MusicBannerWheel ::~ MusicBannerWheel ()
{
}