Files
itgmania212121/stepmania/src/ScreenSelect.cpp
T

255 lines
8.0 KiB
C++
Raw Normal View History

2003-03-03 10:03:02 +00:00
#include "global.h"
#include "ScreenSelect.h"
#include "ScreenManager.h"
#include "PrefsManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2003-03-03 10:03:02 +00:00
#include "GameConstantsAndTypes.h"
#include "PrefsManager.h"
2004-01-25 16:49:05 +00:00
#include "SongManager.h"
2003-03-03 10:03:02 +00:00
#include "GameManager.h"
#include "RageLog.h"
#include "AnnouncerManager.h"
#include "GameState.h"
#include "GameConstantsAndTypes.h"
#include "ThemeManager.h"
#include "ModeChoice.h"
#include "RageDisplay.h"
2004-01-25 16:31:38 +00:00
#include "UnlockSystem.h"
#include "arch/ArchHooks/ArchHooks.h"
2004-03-30 07:44:29 +00:00
#include "LightsManager.h"
2003-03-03 10:03:02 +00:00
#define CHOICE_NAMES THEME->GetMetric (m_sName,"ChoiceNames")
2004-02-13 07:45:21 +00:00
#define CHOICE( sChoiceName ) THEME->GetMetric (m_sName,ssprintf("Choice%s",sChoiceName.c_str()))
2004-01-25 16:31:38 +00:00
#define NUM_CODES THEME->GetMetricI(m_sName,"NumCodes")
#define CODE( c ) THEME->GetMetric (m_sName,ssprintf("Code%d",c+1))
#define CODE_ACTION( c ) THEME->GetMetric (m_sName,ssprintf("Code%dAction",c+1))
2003-04-12 06:16:12 +00:00
#define HELP_TEXT THEME->GetMetric (m_sName,"HelpText")
#define NEXT_SCREEN( c ) THEME->GetMetric (m_sName,ssprintf("NextScreen%d",c+1))
2003-03-03 10:03:02 +00:00
ScreenSelect::ScreenSelect( CString sClassName ) : ScreenWithMenuElements(sClassName)
2003-03-03 10:03:02 +00:00
{
LOG->Trace( "ScreenSelect::ScreenSelect()" );
2003-04-12 06:16:12 +00:00
m_sName = sClassName;
2003-03-03 10:03:02 +00:00
2004-02-13 08:15:05 +00:00
//
// Load choices
//
2003-03-09 00:55:49 +00:00
{
2004-02-13 08:15:05 +00:00
// Instead of using NUM_CHOICES, use a comma-separated list of choices. Each
// element in the list is a choice name. This level of indirection
// makes it easier to add or remove items without having to change a bunch
// of indices.
CStringArray asChoiceNames;
split( CHOICE_NAMES, ",", asChoiceNames, true );
for( unsigned c=0; c<asChoiceNames.size(); c++ )
{
CString sChoiceName = asChoiceNames[c];
CString sChoice = CHOICE(sChoiceName);
ModeChoice mc;
mc.m_sName = sChoiceName;
mc.Load( c, sChoice );
m_aModeChoices.push_back( mc );
CString sBGAnimationDir = THEME->GetPath(BGAnimations, m_sName, mc.m_sName, true); // true="optional"
2004-02-13 08:15:05 +00:00
if( sBGAnimationDir == "" )
sBGAnimationDir = THEME->GetPathToB(m_sName+" background");
BGAnimation *pBGA = new BGAnimation;
m_vpBGAnimations.push_back( pBGA );
}
2003-03-03 10:03:02 +00:00
}
2004-02-13 08:15:05 +00:00
//
// Load codes
//
for( int c=0; c<NUM_CODES; c++ )
2004-01-25 16:31:38 +00:00
{
CodeItem code;
if( !code.Load( CODE(c) ) )
continue;
2004-02-13 08:15:05 +00:00
m_aCodes.push_back( code );
m_aCodeActions.push_back( CODE_ACTION(c) );
ModeChoice mc;
mc.Load( c, CODE_ACTION(c) );
m_aCodeChoices.push_back( mc );
2004-01-25 16:31:38 +00:00
}
2004-03-30 07:44:29 +00:00
if( !m_aModeChoices.size() )
RageException::Throw( "Screen \"%s\" does not set any choices", m_sName.c_str() );
2004-03-30 07:44:29 +00:00
// derived classes can override if they want
2004-03-30 07:44:29 +00:00
LIGHTSMAN->SetLightsMode( LIGHTSMODE_MENU );
2003-03-03 10:03:02 +00:00
}
ScreenSelect::~ScreenSelect()
{
LOG->Trace( "ScreenSelect::~ScreenSelect()" );
2004-02-13 08:15:05 +00:00
for( unsigned i=0; i<m_vpBGAnimations.size(); i++ )
SAFE_DELETE( m_vpBGAnimations[i] );
m_vpBGAnimations.clear();
2003-03-03 10:03:02 +00:00
}
void ScreenSelect::Update( float fDelta )
{
if(m_bFirstUpdate)
{
/* Don't play sounds during the ctor, since derived classes havn't loaded yet. */
2003-07-26 23:05:16 +00:00
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo(m_sName+" intro") );
SOUND->PlayMusic( THEME->GetPathToS(m_sName+" music") );
}
2003-03-03 10:03:02 +00:00
Screen::Update( fDelta );
// GAMESTATE->m_MasterPlayerNumber is set to PLAYER_INVALID when going Back to
// the title screen and this screen is updated after. TODO: find out why
if( GAMESTATE->m_MasterPlayerNumber != PLAYER_INVALID )
{
int iSelection = this->GetSelectionIndex(GAMESTATE->m_MasterPlayerNumber);
m_vpBGAnimations[iSelection]->Update( fDelta );
}
2003-03-03 10:03:02 +00:00
}
void ScreenSelect::DrawPrimitives()
{
// GAMESTATE->m_MasterPlayerNumber is set to PLAYER_INVALID when going Back to
// the title screen and this screen is updated after. TODO: find out why
if( GAMESTATE->m_MasterPlayerNumber != PLAYER_INVALID )
{
int iSelection = this->GetSelectionIndex(GAMESTATE->m_MasterPlayerNumber);
m_vpBGAnimations[iSelection]->Draw();
}
2003-03-03 10:03:02 +00:00
Screen::DrawPrimitives();
}
void ScreenSelect::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
// LOG->Trace( "ScreenSelect::Input()" );
2003-03-03 10:03:02 +00:00
2004-05-07 08:08:11 +00:00
if( MenuI.button == MENU_BUTTON_COIN ||
Screen::JoinInput(DeviceI, type, GameI, MenuI, StyleI) )
2003-03-03 10:03:02 +00:00
{
2004-06-04 21:56:36 +00:00
if( type == IET_FIRST_PRESS )
this->UpdateSelectableChoices();
2003-11-09 01:09:35 +00:00
return; // don't let the screen handle the MENU_START press
2003-03-03 10:03:02 +00:00
}
if( IsTransitioning() )
2003-03-03 10:03:02 +00:00
return;
2004-01-25 16:31:38 +00:00
for( unsigned i = 0; i < m_aCodes.size(); ++i )
{
if( !m_aCodes[i].EnteredCode( GameI.controller ) )
continue;
const CString &action = m_aCodeActions[i];
LOG->Trace("entered code for '%s'", action.c_str());
vector<CString> parts;
split( action, ";", parts, true );
for( unsigned j = 0; j < parts.size(); ++j )
{
vector<CString> asBits;
split( parts[j], ",", asBits, true );
if( !asBits[0].CompareNoCase("unlock") )
2004-02-21 01:06:35 +00:00
UNLOCKMAN->UnlockCode( atoi(asBits[1]) );
2004-01-25 16:31:38 +00:00
if( !asBits[0].CompareNoCase("sound") )
SOUND->PlayOnce( THEME->GetPathToS( asBits[1] ) );
}
2004-01-25 16:49:05 +00:00
m_aCodeChoices[i].Apply( MenuI.player );
2004-01-25 16:31:38 +00:00
}
2003-03-03 10:03:02 +00:00
Screen::Input( DeviceI, type, GameI, MenuI, StyleI ); // default input handler
}
void ScreenSelect::FinalizeChoices()
{
/* At this point, we're tweening out; we can't change the selection.
* We don't want to allow players to join if the style will be set,
* since that can change the available selection and is likely to
* invalidate the choice we've already made. Hack: apply the style.
* (Applying the style may have other side-effects, so it'll be re-applied
* in SM_GoToNextScreen.) */
FOREACH_PlayerNumber( p )
if( GAMESTATE->IsHumanPlayer(p) )
{
2004-07-28 16:05:39 +00:00
const int sel = GetSelectionIndex( p );
2004-06-28 07:26:00 +00:00
if( m_aModeChoices[sel].m_pStyle )
GAMESTATE->m_pCurStyle = m_aModeChoices[sel].m_pStyle;
}
SCREENMAN->RefreshCreditsMessages();
}
2003-03-03 10:03:02 +00:00
void ScreenSelect::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
/* Screen is starting to tween out. */
case SM_BeginFadingOut:
FinalizeChoices();
break;
2003-03-03 10:03:02 +00:00
/* It's our turn to tween out. */
case SM_AllDoneChoosing:
FinalizeChoices();
if( !IsTransitioning() )
StartTransitioning( SM_GoToNextScreen );
2003-03-03 10:03:02 +00:00
break;
case SM_GoToNextScreen:
{
2003-09-16 05:57:23 +00:00
/* Apply here, not in SM_AllDoneChoosing, because applying can take a very
* long time (200+ms), and at SM_AllDoneChoosing, we're still tweening stuff
* off-screen. */
FOREACH_PlayerNumber( p )
2003-09-16 05:57:23 +00:00
if( GAMESTATE->IsHumanPlayer(p) )
m_aModeChoices[this->GetSelectionIndex((PlayerNumber)p)].Apply( (PlayerNumber)p );
2003-11-05 19:55:28 +00:00
const int iSelectionIndex = GetSelectionIndex(GAMESTATE->m_MasterPlayerNumber);
if( m_aModeChoices[iSelectionIndex].m_sScreen != "" )
SCREENMAN->SetNewScreen( m_aModeChoices[iSelectionIndex ].m_sScreen );
else
SCREENMAN->SetNewScreen( NEXT_SCREEN(iSelectionIndex) );
2003-03-03 10:03:02 +00:00
}
2004-05-08 06:26:24 +00:00
return;
2003-03-03 10:03:02 +00:00
}
2004-05-08 06:26:24 +00:00
Screen::HandleScreenMessage( SM );
2003-03-03 10:03:02 +00:00
}
void ScreenSelect::MenuBack( PlayerNumber pn )
{
2003-07-26 23:05:16 +00:00
SOUND->StopMusic();
2003-03-03 10:03:02 +00:00
Back( SM_GoToPrevScreen );
2003-03-03 10:03:02 +00:00
}
2004-06-08 05:22:33 +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.
*/