Files
itgmania212121/stepmania/src/ScreenPrompt.cpp
T

242 lines
5.9 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-05-20 08:59:37 +00:00
#include "ScreenPrompt.h"
#include "PrefsManager.h"
#include "ScreenManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2002-05-20 08:59:37 +00:00
#include "GameConstantsAndTypes.h"
#include "GameState.h"
#include "Style.h"
#include "ThemeManager.h"
#include "ScreenDimensions.h"
2005-03-23 06:13:28 +00:00
#include "ActorUtil.h"
2002-05-20 08:59:37 +00:00
PromptAnswer ScreenPrompt::s_LastAnswer = ANSWER_YES;
2005-03-23 06:13:28 +00:00
bool ScreenPrompt::s_bCancelledLast = false;
#define ANSWER_TEXT( elem ) THEME->GetMetric(m_sName,elem+"Text")
2002-05-20 08:59:37 +00:00
2004-11-26 17:28:47 +00:00
//REGISTER_SCREEN_CLASS( ScreenPrompt );
ScreenPrompt::ScreenPrompt(
CString sText,
PromptType type,
PromptAnswer defaultAnswer,
void(*OnYes)(void*),
void(*OnNo)(void*),
void* pCallbackData
) :
2005-03-23 06:13:28 +00:00
Screen("ScreenPrompt")
2002-07-27 19:29:51 +00:00
{
m_bIsTransparent = true; // draw screens below us
m_PromptType = type;
m_Answer = defaultAnswer;
2005-03-23 06:13:28 +00:00
CLAMP( (int&)m_Answer, 0, m_PromptType );
2002-07-27 19:29:51 +00:00
m_pOnYes = OnYes;
m_pOnNo = OnNo;
m_pCallbackData = pCallbackData;
m_sText = sText;
}
void ScreenPrompt::Init()
{
Screen::Init();
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
m_Background.LoadFromAniDir( THEME->GetPathB(m_sName,"background") );
m_Background.PlayCommand("On");
this->AddChild( &m_Background );
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
m_textQuestion.LoadFromFont( THEME->GetPathF(m_sName,"question") );
m_textQuestion.SetName( "Question" );
m_textQuestion.SetText( m_sText );
2005-03-23 06:13:28 +00:00
SET_XY_AND_ON_COMMAND( m_textQuestion );
this->AddChild( &m_textQuestion );
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
m_sprCursor.Load( THEME->GetPathG(m_sName,"cursor") );
m_sprCursor->SetName( "Cursor" );
ON_COMMAND( m_sprCursor );
this->AddChild( m_sprCursor );
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
for( int i=0; i<=m_PromptType; i++ )
{
2005-03-23 06:13:28 +00:00
m_textAnswer[i].LoadFromFont( THEME->GetPathF(m_sName,"answer") );
CString sElem = ssprintf("Answer%dOf%d", i+1, m_PromptType+1);
m_textAnswer[i].SetName( sElem );
m_textAnswer[i].SetText( ANSWER_TEXT(sElem) );
this->AddChild( &m_textAnswer[i] );
2005-03-23 06:13:28 +00:00
SET_XY_AND_ON_COMMAND( m_textAnswer[i] );
2002-05-20 08:59:37 +00:00
}
2005-03-23 06:13:28 +00:00
PositionCursor();
2005-03-23 06:13:28 +00:00
m_In.Load( THEME->GetPathB(m_sName,"in") );
m_In.StartTransitioning();
this->AddChild( &m_In );
2005-03-23 06:13:28 +00:00
m_Out.Load( THEME->GetPathB(m_sName,"out") );
this->AddChild( &m_Out );
2005-03-23 06:13:28 +00:00
m_Cancel.Load( THEME->GetPathB(m_sName,"cancel") );
this->AddChild( &m_Cancel );
2005-03-18 21:51:30 +00:00
2005-03-23 06:13:28 +00:00
m_sndChange.Load( THEME->GetPathS(m_sName,"change"), true );
2002-05-20 08:59:37 +00:00
}
void ScreenPrompt::Update( float fDeltaTime )
{
Screen::Update( fDeltaTime );
}
void ScreenPrompt::DrawPrimitives()
{
Screen::DrawPrimitives();
}
void ScreenPrompt::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
2002-05-20 08:59:37 +00:00
return;
if( DeviceI.device==DEVICE_KEYBOARD && type==IET_FIRST_PRESS )
{
PlayerNumber pn;
if ( GAMESTATE->GetCurrentStyle() == NULL )
pn = (PlayerNumber)GameI.controller;
else
pn = GAMESTATE->GetCurrentStyle()->ControllerToPlayerNumber( GameI.controller );
switch( DeviceI.button )
{
2004-09-09 17:48:25 +00:00
case KEY_LEFT:
this->MenuLeft( pn );
return;
2004-09-09 17:48:25 +00:00
case KEY_RIGHT:
this->MenuRight( pn );
return;
}
}
2002-05-20 08:59:37 +00:00
Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
}
void ScreenPrompt::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
case SM_DoneClosingWipingLeft:
break;
case SM_DoneClosingWipingRight:
break;
case SM_DoneOpeningWipingLeft:
break;
case SM_DoneOpeningWipingRight:
2004-01-30 05:07:26 +00:00
SCREENMAN->PopTopScreen();
2002-05-20 08:59:37 +00:00
break;
}
}
void ScreenPrompt::Change( int dir )
2002-05-20 08:59:37 +00:00
{
m_textAnswer[m_Answer].SetEffectNone();
m_Answer = (PromptAnswer)(m_Answer+dir);
ASSERT( m_Answer >= 0 && m_Answer < NUM_PROMPT_ANSWERS );
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
PositionCursor();
2002-05-20 08:59:37 +00:00
2005-03-18 21:51:30 +00:00
m_sndChange.Play();
2002-05-20 08:59:37 +00:00
}
void ScreenPrompt::MenuLeft( PlayerNumber pn )
{
if( CanGoLeft() )
Change( -1 );
}
void ScreenPrompt::MenuRight( PlayerNumber pn )
{
if( CanGoRight() )
Change( +1 );
}
void ScreenPrompt::MenuStart( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
2005-03-23 06:13:28 +00:00
End( false );
}
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
void ScreenPrompt::MenuBack( PlayerNumber pn )
{
switch( m_PromptType )
{
case PROMPT_OK:
case PROMPT_YES_NO:
// don't allow cancel
break;
case PROMPT_YES_NO_CANCEL:
End( true );
break;
}
}
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
void ScreenPrompt::End( bool bCancelled )
{
if( bCancelled )
{
2005-03-23 06:13:28 +00:00
m_Cancel.StartTransitioning( SM_DoneOpeningWipingRight );
}
else
{
SCREENMAN->PlayStartSound();
m_Out.StartTransitioning( SM_DoneOpeningWipingRight );
}
2002-05-20 08:59:37 +00:00
2005-03-23 06:13:28 +00:00
OFF_COMMAND( m_textQuestion );
OFF_COMMAND( m_sprCursor );
for( int i=0; i<=m_PromptType; i++ )
OFF_COMMAND( m_textAnswer[i] );
2002-08-02 09:31:06 +00:00
switch( m_Answer )
{
case ANSWER_YES:
if( m_pOnYes )
m_pOnYes(m_pCallbackData);
break;
case ANSWER_NO:
if( m_pOnNo )
m_pOnNo(m_pCallbackData);
break;
}
2003-11-01 19:36:52 +00:00
2005-03-23 06:13:28 +00:00
s_LastAnswer = bCancelled ? ANSWER_CANCEL : m_Answer;
s_bCancelledLast = bCancelled;
2002-05-20 08:59:37 +00:00
}
2005-03-23 06:13:28 +00:00
void ScreenPrompt::PositionCursor()
2002-05-20 08:59:37 +00:00
{
2005-03-23 06:13:28 +00:00
BitmapText &bt = m_textAnswer[m_Answer];
m_sprCursor->SetXY( bt.GetX(), bt.GetY() );
2002-05-20 08:59:37 +00:00
}
2004-06-08 05:22:33 +00:00
2005-03-23 06:13:28 +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.
*/