2003-07-09 03:10:01 +00:00
/*
-----------------------------------------------------------------------------
Class: ScreenUnlock
Desc: See header.
Copyright (c) 2003 by the person(s) listed below. All rights reserved.
2003-07-10 07:22:31 +00:00
Andrew Wong
2003-07-09 03:10:01 +00:00
-----------------------------------------------------------------------------
*/
# include "global.h"
# include "PrefsManager.h"
# include "ScreenUnlock.h"
# include "ThemeManager.h"
# include "GameState.h"
# include "RageLog.h"
# include "UnlockSystem.h"
2003-07-09 04:46:24 +00:00
# include "SongManager.h"
2003-07-12 20:35:48 +00:00
# include "ActorUtil.h"
2003-07-16 20:11:03 +00:00
# include "song.h"
2003-07-17 23:33:19 +00:00
# include "Course.h"
# define NUM_UNLOCKS THEME->GetMetricI("ScreenUnlock", "NumUnlocks")
# define UNLOCK_TEXT_SCROLL_X THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollX");
# define UNLOCK_TEXT_SCROLL_START_Y THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollStartY")
# define UNLOCK_TEXT_SCROLL_END_Y THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollEndY")
# define UNLOCK_TEXT_SCROLL_ZOOM THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollZoom")
# define UNLOCK_TEXT_SCROLL_ROWS THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollRows")
# define UNLOCK_TEXT_SCROLL_MAX_WIDTH THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollMaxWidth")
# define UNLOCK_TEXT_SCROLL_ICON_X THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollIconX")
# define UNLOCK_TEXT_SCROLL_ICON_SIZE THEME->GetMetricF("ScreenUnlock", "UnlockTextScrollIconSize")
# define DISPLAYED_SONG(i) THEME->GetMetric ("ScreenUnlock", ssprintf("Unlock%dSong", i))
# define UNLOCK_TEXT_SCROLL THEME->GetMetricI("ScreenUnlock", "UnlockTextScroll")
# define TYPE_TO_DISPLAY THEME->GetMetric("ScreenUnlock", "TypeOfPointsToDisplay")
# define ICON_COMMAND THEME->GetMetric ("ScreenUnlock", "UnlockIconCommand")
# define TIME_TO_DISPLAY THEME->GetMetricF("ScreenUnlock", "TimeToDisplay")
# define POINTS_ZOOM THEME->GetMetricF("ScreenUnlock","PointsZoom")
2003-07-09 03:10:01 +00:00
ScreenUnlock : : ScreenUnlock ( ) : ScreenAttract ( " ScreenUnlock " )
{
LOG - > Trace ( " ScreenUnlock::ScreenUnlock() " ) ;
PointsUntilNextUnlock . LoadFromFont ( THEME - > GetPathToF ( " Common normal " ) ) ;
PointsUntilNextUnlock . SetHorizAlign ( Actor : : align_left ) ;
2003-07-13 14:18:26 +00:00
// get unlock data first
2003-07-09 06:05:43 +00:00
CString sDP = ssprintf ( " %d " , ( int ) GAMESTATE - > m_pUnlockingSys - > DancePointsUntilNextUnlock ( ) ) ;
CString sAP = ssprintf ( " %d " , ( int ) GAMESTATE - > m_pUnlockingSys - > ArcadePointsUntilNextUnlock ( ) ) ;
CString sSP = ssprintf ( " %d " , ( int ) GAMESTATE - > m_pUnlockingSys - > SongPointsUntilNextUnlock ( ) ) ;
2003-07-10 07:22:31 +00:00
2003-07-17 23:33:19 +00:00
CString IconCommand = ICON_COMMAND ;
2003-07-09 03:10:01 +00:00
2003-07-20 18:18:11 +00:00
int i ;
2003-07-18 15:00:33 +00:00
for ( i = 1 ; i < = NUM_UNLOCKS ; i + + )
2003-07-09 03:10:01 +00:00
{
2003-07-16 14:03:40 +00:00
Sprite * entry = new Sprite ;
2003-07-09 03:10:01 +00:00
// new unlock graphic
2003-07-16 14:03:40 +00:00
entry - > Load ( THEME - > GetPathToG ( ssprintf ( " ScreenUnlock %d icon " , i ) ) ) ;
2003-07-09 03:10:01 +00:00
2003-07-10 14:44:13 +00:00
// set graphic location
2003-07-16 14:03:40 +00:00
entry - > SetName ( ssprintf ( " Unlock%d " , i ) ) ;
SET_XY ( * entry ) ;
2003-07-09 03:10:01 +00:00
2003-07-10 14:44:13 +00:00
// get pertaining songentry
2003-07-17 23:33:19 +00:00
LOG - > Trace ( " UnlockScreen: Searching for %s " , DISPLAYED_SONG ( i ) . c_str ( ) ) ;
2003-07-18 06:38:05 +00:00
SongEntry * pSong = GAMESTATE - > m_pUnlockingSys - > FindLockEntry ( DISPLAYED_SONG ( i ) ) ;
2003-07-10 14:44:13 +00:00
if ( pSong = = NULL )
2003-07-17 12:14:19 +00:00
{
LOG - > Trace ( " Can't find song " ) ;
2003-07-09 04:46:24 +00:00
continue ;
2003-07-17 12:14:19 +00:00
}
2003-07-09 04:46:24 +00:00
2003-07-16 14:03:40 +00:00
entry - > Command ( IconCommand ) ;
Unlocks . push_back ( entry ) ;
2003-07-10 07:22:31 +00:00
2003-07-10 14:44:13 +00:00
if ( ! pSong - > isLocked )
2003-07-17 12:14:19 +00:00
this - > AddChild ( Unlocks [ Unlocks . size ( ) - 1 ] ) ;
2003-07-09 03:10:01 +00:00
}
2003-07-16 13:13:26 +00:00
// scrolling text
2003-07-17 23:33:19 +00:00
if ( UNLOCK_TEXT_SCROLL ! = 0 )
2003-07-16 13:13:26 +00:00
{
2003-07-17 23:33:19 +00:00
int NumberUnlocks = NUM_UNLOCKS ;
float ScrollingTextX = UNLOCK_TEXT_SCROLL_X ;
float ScrollingTextStartY = UNLOCK_TEXT_SCROLL_START_Y ;
float ScrollingTextEndY = UNLOCK_TEXT_SCROLL_END_Y ;
float ScrollingTextZoom = UNLOCK_TEXT_SCROLL_ZOOM ;
float ScrollingTextRows = UNLOCK_TEXT_SCROLL_ROWS ;
float MaxWidth = UNLOCK_TEXT_SCROLL_MAX_WIDTH ;
float SecondsToScroll = TIME_TO_DISPLAY ;
2003-07-16 13:13:26 +00:00
if ( SecondsToScroll > 2 ) SecondsToScroll - - ;
2003-07-18 15:00:33 +00:00
float SECS_PER_CYCLE = 0 ;
if ( UNLOCK_TEXT_SCROLL ! = 3 )
SECS_PER_CYCLE = ( float ) SecondsToScroll / ( ScrollingTextRows + NumberUnlocks ) ;
else
SECS_PER_CYCLE = ( float ) SecondsToScroll / ( ScrollingTextRows * 3 + NumberUnlocks + 4 ) ;
2003-07-16 13:13:26 +00:00
2003-07-18 15:00:33 +00:00
for ( i = 1 ; i < = NumberUnlocks ; i + + )
2003-07-16 13:13:26 +00:00
{
2003-07-16 14:03:40 +00:00
BitmapText * text = new BitmapText ;
2003-07-16 13:13:26 +00:00
2003-07-18 15:00:33 +00:00
text - > LoadFromFont ( THEME - > GetPathToF ( " ScreenUnlock text " ) ) ;
2003-07-16 14:03:40 +00:00
text - > SetHorizAlign ( Actor : : align_left ) ;
2003-07-16 13:13:26 +00:00
2003-07-17 23:33:19 +00:00
CString DisplayedSong = DISPLAYED_SONG ( i ) ;
DisplayedSong . MakeUpper ( ) ;
2003-07-18 06:38:05 +00:00
SongEntry * pSong = GAMESTATE - > m_pUnlockingSys - > FindLockEntry ( DisplayedSong ) ;
2003-07-17 23:33:19 +00:00
/* Reset zoom before using SetTextMaxWidth. */
text - > SetZoom ( ScrollingTextZoom ) ;
2003-07-16 13:13:26 +00:00
2003-07-18 06:38:05 +00:00
if ( pSong & & pSong - > m_pSong ! = NULL )
2003-07-17 23:33:19 +00:00
{
2003-07-18 06:38:05 +00:00
CString title = pSong - > m_pSong - > GetDisplayMainTitle ( ) ;
2003-07-18 07:34:43 +00:00
CString subtitle = pSong - > m_pSong - > GetDisplaySubTitle ( ) ;
2003-07-17 23:33:19 +00:00
if ( subtitle ! = " " )
title = title + " \n " + subtitle ;
text - > SetTextMaxWidth ( MaxWidth , title ) ;
}
2003-07-16 14:03:40 +00:00
else // song is missing
2003-07-17 12:14:19 +00:00
{
2003-07-17 23:33:19 +00:00
Course * crs = SONGMAN - > FindCourse ( DisplayedSong ) ;
if ( crs ! = NULL )
{
text - > SetTextMaxWidth ( MaxWidth , crs - > m_sName ) ;
text - > Command ( " Diffuse,0,1,0,1 " ) ;
}
2003-07-18 07:34:43 +00:00
else // entry isn't a song or course
2003-07-17 23:33:19 +00:00
{
text - > SetText ( " " ) ;
2003-07-17 12:14:19 +00:00
text - > Command ( " Diffuse,0.5,0,0,1 " ) ;
2003-07-17 23:33:19 +00:00
}
2003-07-17 12:14:19 +00:00
}
2003-07-16 13:13:26 +00:00
2003-07-17 23:33:19 +00:00
if ( pSong ! = NULL )
{
if ( pSong - > isLocked )
{
text - > SetText ( " ??? " ) ;
} else {
2003-07-18 06:38:05 +00:00
RageColor color = SONGMAN - > GetGroupColor ( pSong - > m_pSong - > m_sGroupName ) ;
2003-07-17 23:33:19 +00:00
text - > SetGlobalDiffuseColor ( color ) ;
}
2003-07-17 12:14:19 +00:00
}
2003-07-16 13:13:26 +00:00
2003-07-16 14:03:40 +00:00
text - > SetXY ( ScrollingTextX , ScrollingTextStartY ) ;
2003-07-20 15:09:37 +00:00
if ( UNLOCK_TEXT_SCROLL = = 3 & & UNLOCK_TEXT_SCROLL_ROWS + i > NUM_UNLOCKS )
{
2003-07-20 18:18:11 +00:00
float TargetRow = - 0.5f + i + UNLOCK_TEXT_SCROLL_ROWS - NUM_UNLOCKS ;
2003-07-20 15:09:37 +00:00
float StopOffPoint = ScrollingTextEndY - TargetRow / UNLOCK_TEXT_SCROLL_ROWS * ( ScrollingTextEndY - ScrollingTextStartY ) ;
float FirstCycleTime = ( UNLOCK_TEXT_SCROLL_ROWS - TargetRow ) * SECS_PER_CYCLE ;
float SecondCycleTime = ( 6 + TargetRow ) * SECS_PER_CYCLE - FirstCycleTime ;
LOG - > Trace ( " Target Row: %f " , TargetRow ) ;
LOG - > Trace ( " command for icon %d: %s " , i , ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0 " , SECS_PER_CYCLE * ( i - 1 ) , FirstCycleTime , StopOffPoint , SecondCycleTime * 2 , ScrollingTextEndY ) . c_str ( ) ) ;
text - > Command ( ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0 " , SECS_PER_CYCLE * ( i - 1 ) , FirstCycleTime , StopOffPoint , SecondCycleTime , ScrollingTextEndY ) ) ;
}
else
text - > Command ( ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,0.1;diffusealpha,0 " , SECS_PER_CYCLE * ( i - 1 ) , SECS_PER_CYCLE * ( ScrollingTextRows ) , ScrollingTextEndY ) ) ;
2003-07-16 13:13:26 +00:00
2003-07-16 14:03:40 +00:00
item . push_back ( text ) ;
2003-07-18 15:00:33 +00:00
if ( UNLOCK_TEXT_SCROLL > = 2 )
2003-07-16 13:13:26 +00:00
{
2003-07-16 14:03:40 +00:00
Sprite * IconCount = new Sprite ;
// new unlock graphic
IconCount - > Load ( THEME - > GetPathToG ( ssprintf ( " ScreenUnlock %d icon " , i ) ) ) ;
2003-07-16 13:13:26 +00:00
2003-07-16 14:03:40 +00:00
// set graphic location
2003-07-17 23:33:19 +00:00
IconCount - > SetXY ( UNLOCK_TEXT_SCROLL_ICON_X , ScrollingTextStartY ) ;
2003-07-16 13:13:26 +00:00
2003-07-17 23:33:19 +00:00
IconCount - > SetHeight ( UNLOCK_TEXT_SCROLL_ICON_SIZE ) ;
IconCount - > SetWidth ( UNLOCK_TEXT_SCROLL_ICON_SIZE ) ;
2003-07-16 13:13:26 +00:00
2003-07-20 15:09:37 +00:00
if ( UNLOCK_TEXT_SCROLL = = 3 & & UNLOCK_TEXT_SCROLL_ROWS + i > NUM_UNLOCKS )
{
2003-07-20 18:18:11 +00:00
float TargetRow = - 0.5f + i + UNLOCK_TEXT_SCROLL_ROWS - NUM_UNLOCKS ;
2003-07-20 15:09:37 +00:00
float StopOffPoint = ScrollingTextEndY - TargetRow / UNLOCK_TEXT_SCROLL_ROWS * ( ScrollingTextEndY - ScrollingTextStartY ) ;
float FirstCycleTime = ( UNLOCK_TEXT_SCROLL_ROWS - TargetRow ) * SECS_PER_CYCLE ;
float SecondCycleTime = ( 6 + TargetRow ) * SECS_PER_CYCLE - FirstCycleTime ;
LOG - > Trace ( " Target Row: %f " , TargetRow ) ;
LOG - > Trace ( " command for icon %d: %s " , i , ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0 " , SECS_PER_CYCLE * ( i - 1 ) , FirstCycleTime , StopOffPoint , SecondCycleTime * 2 , ScrollingTextEndY ) . c_str ( ) ) ;
IconCount - > Command ( ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0 " , SECS_PER_CYCLE * ( i - 1 ) , FirstCycleTime , StopOffPoint , SecondCycleTime , ScrollingTextEndY ) ) ;
}
else
IconCount - > Command ( ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,0.1;diffusealpha,0 " , SECS_PER_CYCLE * ( i - 1 ) , SECS_PER_CYCLE * ( ScrollingTextRows ) , ScrollingTextEndY ) ) ;
2003-07-16 13:13:26 +00:00
2003-07-16 14:03:40 +00:00
ItemIcons . push_back ( IconCount ) ;
2003-07-17 12:14:19 +00:00
LOG - > Trace ( " Added unlock text %d " , i ) ;
2003-07-16 14:03:40 +00:00
2003-07-18 15:00:33 +00:00
if ( UNLOCK_TEXT_SCROLL = = 3 )
{
if ( ! pSong - > isLocked )
LastUnlocks . push_back ( i ) ;
}
2003-07-16 14:03:40 +00:00
}
2003-07-16 13:13:26 +00:00
}
}
2003-07-18 15:00:33 +00:00
if ( UNLOCK_TEXT_SCROLL = = 3 )
{
int NumberUnlocks = NUM_UNLOCKS ;
float ScrollingTextX = UNLOCK_TEXT_SCROLL_X ;
float ScrollingTextStartY = UNLOCK_TEXT_SCROLL_START_Y ;
float ScrollingTextEndY = UNLOCK_TEXT_SCROLL_END_Y ;
2003-07-20 18:18:11 +00:00
// float ScrollingTextZoom = UNLOCK_TEXT_SCROLL_ZOOM;
2003-07-18 15:00:33 +00:00
float ScrollingTextRows = UNLOCK_TEXT_SCROLL_ROWS ;
float MaxWidth = UNLOCK_TEXT_SCROLL_MAX_WIDTH ;
float SecondsToScroll = TIME_TO_DISPLAY - 1 ;
float SECS_PER_CYCLE = ( float ) SecondsToScroll / ( ScrollingTextRows * 3 + NumberUnlocks + 4 ) ;
2003-07-18 17:02:10 +00:00
for ( i = 1 ; i < = UNLOCK_TEXT_SCROLL_ROWS ; i + + )
2003-07-18 15:00:33 +00:00
{
2003-07-20 18:18:11 +00:00
if ( i > ( int ) LastUnlocks . size ( ) )
2003-07-18 15:00:33 +00:00
continue ;
int NextIcon = LastUnlocks [ LastUnlocks . size ( ) - i ] ;
Sprite * NewIcon = new Sprite ;
BitmapText * NewText = new BitmapText ;
NewText - > LoadFromFont ( THEME - > GetPathToF ( " ScreenUnlock text " ) ) ;
NewText - > SetHorizAlign ( Actor : : align_left ) ;
CString DisplayedSong = DISPLAYED_SONG ( NextIcon ) ;
DisplayedSong . MakeUpper ( ) ;
SongEntry * pSong = GAMESTATE - > m_pUnlockingSys - > FindLockEntry ( DisplayedSong ) ;
/* Reset zoom before using SetTextMaxWidth. */
NewText - > SetZoom ( UNLOCK_TEXT_SCROLL_ZOOM ) ;
CString title = pSong - > m_pSong - > GetDisplayMainTitle ( ) ;
CString subtitle = pSong - > m_pSong - > GetDisplaySubTitle ( ) ;
if ( subtitle ! = " " )
title = title + " \n " + subtitle ;
NewText - > SetTextMaxWidth ( MaxWidth , title ) ;
RageColor color = SONGMAN - > GetGroupColor ( pSong - > m_pSong - > m_sGroupName ) ;
NewText - > SetGlobalDiffuseColor ( color ) ;
NewText - > SetXY ( ScrollingTextX , ScrollingTextStartY ) ;
2003-07-20 15:54:47 +00:00
NewText - > Command ( ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f; " , SECS_PER_CYCLE * ( NumberUnlocks + 2 * i - 2 ) , SECS_PER_CYCLE * ( ( ScrollingTextRows - i ) * 2 + 1 ) , ( ScrollingTextStartY + ( ScrollingTextEndY - ScrollingTextStartY ) * ( ScrollingTextRows - i + 0.5 ) / ScrollingTextRows ) ) ) ;
2003-07-18 15:00:33 +00:00
// new unlock graphic
NewIcon - > Load ( THEME - > GetPathToG ( ssprintf ( " ScreenUnlock %d icon " , NextIcon ) ) ) ;
// set graphic location
NewIcon - > SetXY ( UNLOCK_TEXT_SCROLL_ICON_X , ScrollingTextStartY ) ;
NewIcon - > SetHeight ( UNLOCK_TEXT_SCROLL_ICON_SIZE ) ;
NewIcon - > SetWidth ( UNLOCK_TEXT_SCROLL_ICON_SIZE ) ;
2003-07-20 15:54:47 +00:00
NewIcon - > Command ( ssprintf ( " diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f; " , SECS_PER_CYCLE * ( NumberUnlocks + 2 * i - 2 ) , SECS_PER_CYCLE * ( ( ScrollingTextRows - i ) * 2 + 1 ) , ( ScrollingTextStartY + ( ScrollingTextEndY - ScrollingTextStartY ) * ( ScrollingTextRows - i + 0.5 ) / ScrollingTextRows ) ) ) ;
2003-07-18 15:00:33 +00:00
ItemIcons . push_back ( NewIcon ) ;
item . push_back ( NewText ) ;
}
}
2003-07-16 13:13:26 +00:00
2003-07-20 18:18:11 +00:00
for ( i = item . size ( ) - 1 ; i > = 0 ; i - - )
2003-07-20 03:54:26 +00:00
this - > AddChild ( item [ i ] ) ;
2003-07-20 18:18:11 +00:00
for ( i = ItemIcons . size ( ) - 1 ; i > = 0 ; i - - )
2003-07-20 03:54:26 +00:00
this - > AddChild ( ItemIcons [ i ] ) ;
2003-07-09 06:05:43 +00:00
PointsUntilNextUnlock . SetName ( " PointsDisplay " ) ;
2003-07-17 23:33:19 +00:00
CString PointDisplay = TYPE_TO_DISPLAY ;
2003-07-09 06:05:43 +00:00
if ( PointDisplay = = " DP " | | PointDisplay = = " Dance " )
PointsUntilNextUnlock . SetText ( sDP ) ;
if ( PointDisplay = = " AP " | | PointDisplay = = " Arcade " )
PointsUntilNextUnlock . SetText ( sAP ) ;
if ( PointDisplay = = " SP " | | PointDisplay = = " Song " )
PointsUntilNextUnlock . SetText ( sSP ) ;
2003-07-17 23:33:19 +00:00
PointsUntilNextUnlock . SetZoom ( POINTS_ZOOM ) ;
2003-07-09 03:10:01 +00:00
SET_XY ( PointsUntilNextUnlock ) ;
this - > AddChild ( & PointsUntilNextUnlock ) ;
2003-07-10 07:22:31 +00:00
this - > ClearMessageQueue ( SM_BeginFadingOut ) ; // ignore ScreenAttract's SecsToShow
2003-07-17 23:33:19 +00:00
this - > PostScreenMessage ( SM_BeginFadingOut , TIME_TO_DISPLAY ) ;
2003-07-09 03:10:01 +00:00
}
2003-07-16 13:13:26 +00:00