Files
itgmania212121/stepmania/src/ScreenSelectStyle.cpp
T

280 lines
7.3 KiB
C++
Raw Normal View History

2003-03-03 10:03:02 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
2003-03-09 00:55:49 +00:00
Class: ScreenSelectStyle
2003-03-03 10:03:02 +00:00
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
2003-03-09 00:55:49 +00:00
#include "ScreenSelectStyle.h"
2003-03-03 10:03:02 +00:00
#include "GameManager.h"
2003-07-26 23:05:16 +00:00
#include "RageSounds.h"
2003-03-03 10:03:02 +00:00
#include "ThemeManager.h"
#include "PrefsManager.h"
#include "ScreenManager.h"
#include "GameState.h"
2003-04-01 19:46:13 +00:00
#include "AnnouncerManager.h"
2003-04-13 21:17:14 +00:00
#include "ActorUtil.h"
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
#define ICON_GAIN_FOCUS_COMMAND THEME->GetMetric ("ScreenSelectStyle","IconGainFocusCommand")
#define ICON_LOSE_FOCUS_COMMAND THEME->GetMetric ("ScreenSelectStyle","IconLoseFocusCommand")
#define DISABLED_COLOR THEME->GetMetricC("ScreenSelectStyle","DisabledColor")
ScreenSelectStyle::ScreenSelectStyle() : ScreenSelect( "ScreenSelectStyle" )
2003-03-03 10:03:02 +00:00
{
m_iSelection = 0;
unsigned i;
for( i=0; i<m_aModeChoices.size(); i++ )
{
const ModeChoice& mc = m_aModeChoices[i];
//
// Load icon
//
2003-03-09 00:55:49 +00:00
CString sIconElementName = ssprintf("ScreenSelectStyle icon %s", mc.name );
CString sIconPath = THEME->GetPathToG(sIconElementName);
2003-04-12 06:16:12 +00:00
m_textIcon[i].SetName( ssprintf("Icon%d",i+1) );
m_sprIcon[i].SetName( ssprintf("Icon%d",i+1) );
2003-03-03 10:03:02 +00:00
if( sIconPath.empty() ) // element doesn't exist
{
m_textIcon[i].LoadFromFont( THEME->GetPathToF("Common normal") );
2003-03-03 10:03:02 +00:00
m_textIcon[i].SetText( mc.name );
m_textIcon[i].SetZoom(0.5f);
this->AddChild( &m_textIcon[i] );
}
else
{
m_sprIcon[i].Load( sIconPath );
this->AddChild( &m_sprIcon[i] );
}
//
2003-03-09 00:55:49 +00:00
// Load Picture
2003-03-03 10:03:02 +00:00
//
2003-03-09 00:55:49 +00:00
CString sPictureElementName = ssprintf("ScreenSelectStyle picture %s", mc.name );
CString sPicturePath = THEME->GetPathToG(sPictureElementName);
2003-03-09 00:55:49 +00:00
if( sPicturePath != "" )
2003-03-03 10:03:02 +00:00
{
2003-04-12 06:16:12 +00:00
m_sprPicture[i].SetName( ssprintf("Picture") );
2003-03-09 00:55:49 +00:00
m_sprPicture[i].Load( sPicturePath );
m_sprPicture[i].SetDiffuse( RageColor(1,1,1,0) );
this->AddChild( &m_sprPicture[i] );
2003-03-03 10:03:02 +00:00
}
//
// Load info
//
2003-03-09 00:55:49 +00:00
CString sInfoElementName = ssprintf("ScreenSelectStyle info %s", mc.name );
CString sInfoPath = THEME->GetPathToG(sInfoElementName);
2003-03-03 10:03:02 +00:00
if( sInfoPath != "" )
{
2003-04-12 06:16:12 +00:00
m_sprInfo[i].SetName( ssprintf("Info") );
2003-03-03 10:03:02 +00:00
m_sprInfo[i].Load( sInfoPath );
m_sprInfo[i].SetDiffuse( RageColor(1,1,1,0) );
this->AddChild( &m_sprInfo[i] );
}
}
2003-03-09 00:55:49 +00:00
2003-04-12 06:16:12 +00:00
m_sprWarning.SetName( "Warning" );
m_sprWarning.Load( THEME->GetPathToG("ScreenSelectStyle warning") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_sprWarning );
2003-04-12 06:16:12 +00:00
m_sprExplanation.SetName( "Explanation" );
m_sprExplanation.Load( THEME->GetPathToG("ScreenSelectStyle explanation") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_sprExplanation );
// fix Z ordering of Picture and Info so that they draw on top
2003-03-03 10:03:02 +00:00
for( i=0; i<this->m_aModeChoices.size(); i++ )
2003-03-09 00:55:49 +00:00
this->MoveToTail( &m_sprPicture[i] );
2003-03-03 10:03:02 +00:00
for( i=0; i<this->m_aModeChoices.size(); i++ )
this->MoveToTail( &m_sprInfo[i] );
this->UpdateSelectableChoices();
2003-04-14 03:26:53 +00:00
m_sprJointPremium.SetName( "JointPremium" );
2003-03-03 10:03:02 +00:00
if( PREFSMAN->m_bJointPremium )
{
m_sprJointPremium.Load( THEME->GetPathToG("ScreenSelectStyle joint premium") );
2003-03-03 10:03:02 +00:00
this->AddChild( &m_sprJointPremium );
}
m_soundChange.Load( THEME->GetPathToS("ScreenSelectStyle change") );
m_soundSelect.Load( THEME->GetPathToS("Common start") );
2003-03-03 10:03:02 +00:00
//
// TweenOnScreen
//
for( i=0; i<m_aModeChoices.size(); i++ )
{
2003-04-12 06:16:12 +00:00
SET_XY_AND_ON_COMMAND( m_textIcon[i] );
SET_XY_AND_ON_COMMAND( m_sprIcon[i] );
2003-03-03 10:03:02 +00:00
}
2003-04-12 06:16:12 +00:00
SET_XY_AND_ON_COMMAND( m_sprExplanation );
SET_XY_AND_ON_COMMAND( m_sprWarning );
SET_XY_AND_ON_COMMAND( m_sprJointPremium );
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
// let AfterChange tween Picture and Info
2003-03-03 10:03:02 +00:00
}
2003-03-09 00:55:49 +00:00
void ScreenSelectStyle::MenuLeft( PlayerNumber pn )
2003-03-03 10:03:02 +00:00
{
int iSwitchToIndex = -1; // -1 means none found
for( int i=m_iSelection-1; i>=0; i-- )
{
if( GAMESTATE->IsPlayable(m_aModeChoices[i]) )
{
iSwitchToIndex = i;
break;
}
}
if( iSwitchToIndex == -1 )
return;
BeforeChange();
m_iSelection = iSwitchToIndex;
m_soundChange.Play();
AfterChange();
}
2003-03-09 00:55:49 +00:00
void ScreenSelectStyle::MenuRight( PlayerNumber pn )
2003-03-03 10:03:02 +00:00
{
int iSwitchToIndex = -1; // -1 means none found
for( unsigned i=m_iSelection+1; i<m_aModeChoices.size(); i++ )
{
if( GAMESTATE->IsPlayable(m_aModeChoices[i]) )
{
iSwitchToIndex = i;
break;
}
}
if( iSwitchToIndex == -1 )
return;
BeforeChange();
m_iSelection = iSwitchToIndex;
m_soundChange.Play();
AfterChange();
}
2003-03-09 00:55:49 +00:00
void ScreenSelectStyle::MenuStart( PlayerNumber pn )
2003-03-03 10:03:02 +00:00
{
m_soundSelect.Play();
2003-03-25 21:17:29 +00:00
SCREENMAN->PostMessageToTopScreen( SM_AllDoneChoosing, 0 );
2003-03-03 10:03:02 +00:00
2003-04-01 19:46:13 +00:00
const ModeChoice& mc = m_aModeChoices[GetSelectionIndex(pn)];
2003-07-26 23:05:16 +00:00
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo(ssprintf("ScreenSelectStyle comment %s",mc.name)) );
2003-04-01 19:46:13 +00:00
2003-03-03 10:03:02 +00:00
//
// TweenOffScreen
//
unsigned i;
/* Stop all tweens where they are, since we might have selected before
* we finished tweening in. */
for( i=0; i<m_SubActors.size(); i++ )
m_SubActors[i]->StopTweening();
for( i=0; i<m_aModeChoices.size(); i++ )
2003-03-03 10:03:02 +00:00
{
2003-04-12 06:16:12 +00:00
OFF_COMMAND( m_sprIcon[i] );
OFF_COMMAND( m_textIcon[i] );
2003-03-03 10:03:02 +00:00
}
2003-04-12 06:16:12 +00:00
OFF_COMMAND( m_sprExplanation );
OFF_COMMAND( m_sprWarning );
OFF_COMMAND( m_sprPicture[m_iSelection] );
OFF_COMMAND( m_sprInfo[m_iSelection] );
OFF_COMMAND( m_sprJointPremium );
2003-03-03 10:03:02 +00:00
}
2003-03-09 00:55:49 +00:00
int ScreenSelectStyle::GetSelectionIndex( PlayerNumber pn )
2003-03-03 10:03:02 +00:00
{
return m_iSelection;
}
2003-03-09 00:55:49 +00:00
void ScreenSelectStyle::UpdateSelectableChoices()
2003-03-03 10:03:02 +00:00
{
unsigned i;
2003-03-04 23:03:36 +00:00
/* If a player joins during the tween-in, this diffuse change
* will be undone by the tween. Hmm.
*
* This is fixed now, since SetDiffuse() will affect the latest
* tween, if we're currently tweening. */
2003-03-03 10:03:02 +00:00
for( i=0; i<m_aModeChoices.size(); i++ )
{
/* If the icon is text, use a dimmer diffuse, or we won't be
* able to see the glow. */
if( GAMESTATE->IsPlayable(m_aModeChoices[i]) )
{
m_sprIcon[i].SetDiffuse( RageColor(1,1,1,1) );
m_textIcon[i].SetDiffuse( RageColor(0.5f,0.5f,0.5f,1) ); // gray so glow is visible
}
else
{
m_sprIcon[i].SetDiffuse( DISABLED_COLOR );
m_textIcon[i].SetDiffuse( DISABLED_COLOR );
}
}
// Select first enabled choie
BeforeChange();
int iSwitchToStyleIndex = -1; // -1 means none found
for( i=0; i<m_aModeChoices.size(); i++ )
{
if( GAMESTATE->IsPlayable(m_aModeChoices[i]) )
{
iSwitchToStyleIndex = i;
break;
}
}
ASSERT( iSwitchToStyleIndex != -1 ); // no styles are enabled. We're stuck! This should never happen
m_iSelection = iSwitchToStyleIndex;
AfterChange();
}
2003-03-09 00:55:49 +00:00
void ScreenSelectStyle::BeforeChange()
2003-03-03 10:03:02 +00:00
{
// dim/hide old selection
2003-03-09 00:55:49 +00:00
m_sprIcon[m_iSelection].Command( ICON_LOSE_FOCUS_COMMAND );
m_textIcon[m_iSelection].Command( ICON_LOSE_FOCUS_COMMAND );
m_sprPicture[m_iSelection].StopTweening();
2003-03-03 10:03:02 +00:00
m_sprInfo[m_iSelection].StopTweening();
2003-03-09 00:55:49 +00:00
m_sprPicture[m_iSelection].SetDiffuse( RageColor(1,1,1,0) );
2003-03-03 10:03:02 +00:00
m_sprInfo[m_iSelection].SetDiffuse( RageColor(1,1,1,0) );
2003-03-09 00:55:49 +00:00
m_sprPicture[m_iSelection].SetGlow( RageColor(1,1,1,0) );
2003-03-03 10:03:02 +00:00
m_sprInfo[m_iSelection].SetGlow( RageColor(1,1,1,0) );
}
2003-03-09 00:55:49 +00:00
void ScreenSelectStyle::AfterChange()
2003-03-03 10:03:02 +00:00
{
2003-03-09 00:55:49 +00:00
m_sprIcon[m_iSelection].Command( ICON_GAIN_FOCUS_COMMAND );
m_textIcon[m_iSelection].Command( ICON_GAIN_FOCUS_COMMAND );
m_sprPicture[m_iSelection].SetDiffuse( RageColor(1,1,1,1) );
2003-03-03 10:03:02 +00:00
m_sprInfo[m_iSelection].SetDiffuse( RageColor(1,1,1,1) );
2003-03-09 00:55:49 +00:00
m_sprPicture[m_iSelection].SetZoom( 1 );
2003-03-03 10:03:02 +00:00
m_sprInfo[m_iSelection].SetZoom( 1 );
2003-04-12 06:16:12 +00:00
SET_XY_AND_ON_COMMAND( m_sprPicture[m_iSelection] );
SET_XY_AND_ON_COMMAND( m_sprInfo[m_iSelection] );
2003-03-03 10:03:02 +00:00
}