2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
#include "ScreenPrompt.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"
|
2004-12-04 11:09:32 +00:00
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "Style.h"
|
2002-11-11 04:53:31 +00:00
|
|
|
#include "ThemeManager.h"
|
2004-09-21 06:07:12 +00:00
|
|
|
#include "ScreenDimensions.h"
|
2005-03-23 06:13:28 +00:00
|
|
|
#include "ActorUtil.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2005-03-08 04:02:25 +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
|
|
|
|
2005-07-03 04:33:22 +00:00
|
|
|
void ScreenPrompt::Prompt( ScreenMessage smSendOnPop, const CString &sText, PromptType type, PromptAnswer defaultAnswer, void(*OnYes)(void*), void(*OnNo)(void*), void* pCallbackData )
|
|
|
|
|
{
|
|
|
|
|
// add the new state onto the back of the array
|
|
|
|
|
ScreenPrompt *pNewScreen = new ScreenPrompt( "ScreenPrompt" );
|
|
|
|
|
pNewScreen->Init();
|
2005-07-18 02:45:40 +00:00
|
|
|
pNewScreen->Load( sText, type, defaultAnswer, OnYes, OnNo, pCallbackData );
|
2005-07-03 04:33:22 +00:00
|
|
|
SCREENMAN->ZeroNextUpdate();
|
2005-07-18 02:45:40 +00:00
|
|
|
SCREENMAN->PushScreen( pNewScreen, true, smSendOnPop );
|
2005-07-03 04:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-26 17:28:47 +00:00
|
|
|
//REGISTER_SCREEN_CLASS( ScreenPrompt );
|
2005-07-03 03:49:19 +00:00
|
|
|
ScreenPrompt::ScreenPrompt( const CString &sScreenName ):
|
2005-07-13 20:26:41 +00:00
|
|
|
ScreenWithMenuElements( sScreenName )
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
2005-02-23 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenPrompt::Init()
|
|
|
|
|
{
|
2005-07-13 20:26:41 +00:00
|
|
|
ScreenWithMenuElements::Init();
|
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" );
|
2002-09-02 21:59:58 +00:00
|
|
|
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" );
|
|
|
|
|
this->AddChild( m_sprCursor );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2005-07-03 03:49:19 +00:00
|
|
|
for( int i=0; i<NUM_PROMPT_ANSWERS; i++ )
|
2002-08-27 03:59:22 +00:00
|
|
|
{
|
2005-03-23 06:13:28 +00:00
|
|
|
m_textAnswer[i].LoadFromFont( THEME->GetPathF(m_sName,"answer") );
|
2005-03-08 04:02:25 +00:00
|
|
|
this->AddChild( &m_textAnswer[i] );
|
2002-05-20 08:59:37 +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
|
|
|
}
|
|
|
|
|
|
2005-07-03 03:49:19 +00:00
|
|
|
void ScreenPrompt::Load(
|
|
|
|
|
CString sText,
|
|
|
|
|
PromptType type,
|
|
|
|
|
PromptAnswer defaultAnswer,
|
|
|
|
|
void (*OnYes)(void*),
|
|
|
|
|
void (*OnNo)(void*),
|
|
|
|
|
void* pCallbackData )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2005-07-03 03:49:19 +00:00
|
|
|
m_sText = sText;
|
|
|
|
|
m_PromptType = type;
|
|
|
|
|
m_Answer = defaultAnswer;
|
|
|
|
|
CLAMP( (int&)m_Answer, 0, m_PromptType );
|
|
|
|
|
m_pOnYes = OnYes;
|
|
|
|
|
m_pOnNo = OnNo;
|
|
|
|
|
m_pCallbackData = pCallbackData;
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2005-07-03 03:49:19 +00:00
|
|
|
|
|
|
|
|
m_textQuestion.SetText( m_sText );
|
|
|
|
|
SET_XY_AND_ON_COMMAND( m_textQuestion );
|
|
|
|
|
|
|
|
|
|
ON_COMMAND( m_sprCursor );
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<=m_PromptType; i++ )
|
|
|
|
|
{
|
|
|
|
|
CString sElem = ssprintf("Answer%dOf%d", i+1, m_PromptType+1);
|
|
|
|
|
m_textAnswer[i].SetName( sElem );
|
|
|
|
|
m_textAnswer[i].SetText( ANSWER_TEXT(sElem) );
|
|
|
|
|
SET_XY_AND_ON_COMMAND( m_textAnswer[i] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PositionCursor();
|
|
|
|
|
|
|
|
|
|
m_In.StartTransitioning();
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenPrompt::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
|
|
|
|
{
|
2003-04-12 18:34:05 +00:00
|
|
|
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
2002-05-20 08:59:37 +00:00
|
|
|
return;
|
|
|
|
|
|
2003-01-11 08:55:21 +00:00
|
|
|
if( DeviceI.device==DEVICE_KEYBOARD && type==IET_FIRST_PRESS )
|
2003-01-10 02:22:07 +00:00
|
|
|
{
|
2005-01-25 06:20:48 +00:00
|
|
|
PlayerNumber pn;
|
|
|
|
|
if ( GAMESTATE->GetCurrentStyle() == NULL )
|
|
|
|
|
pn = (PlayerNumber)GameI.controller;
|
|
|
|
|
else
|
|
|
|
|
pn = GAMESTATE->GetCurrentStyle()->ControllerToPlayerNumber( GameI.controller );
|
2003-01-10 02:22:07 +00:00
|
|
|
switch( DeviceI.button )
|
|
|
|
|
{
|
2004-09-09 17:48:25 +00:00
|
|
|
case KEY_LEFT:
|
2004-12-04 11:09:32 +00:00
|
|
|
this->MenuLeft( pn );
|
2003-01-10 02:22:07 +00:00
|
|
|
return;
|
2004-09-09 17:48:25 +00:00
|
|
|
case KEY_RIGHT:
|
2004-12-04 11:09:32 +00:00
|
|
|
this->MenuRight( pn );
|
2003-01-10 02:22:07 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-13 20:26:41 +00:00
|
|
|
ScreenWithMenuElements::Input( DeviceI, type, GameI, MenuI, StyleI );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-08 04:02:25 +00:00
|
|
|
void ScreenPrompt::Change( int dir )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2005-03-08 04:02:25 +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
|
|
|
}
|
|
|
|
|
|
2005-03-08 04:02:25 +00:00
|
|
|
void ScreenPrompt::MenuLeft( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
if( CanGoLeft() )
|
|
|
|
|
Change( -1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenPrompt::MenuRight( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
if( CanGoRight() )
|
|
|
|
|
Change( +1 );
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-04 03:49:08 +00:00
|
|
|
void ScreenPrompt::MenuStart( PlayerNumber pn )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2005-05-19 23:29:39 +00:00
|
|
|
if( m_Out.IsTransitioning() || m_Cancel.IsTransitioning() )
|
|
|
|
|
return;
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
2005-05-19 23:29:39 +00:00
|
|
|
if( m_Out.IsTransitioning() || m_Cancel.IsTransitioning() )
|
|
|
|
|
return;
|
|
|
|
|
|
2005-03-23 06:13:28 +00:00
|
|
|
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-08 04:02:25 +00:00
|
|
|
{
|
2005-07-14 03:50:19 +00:00
|
|
|
m_Cancel.StartTransitioning( SM_GoToNextScreen );
|
2005-03-23 06:13:28 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SCREENMAN->PlayStartSound();
|
2005-07-14 03:50:19 +00:00
|
|
|
m_Out.StartTransitioning( SM_GoToNextScreen );
|
2005-03-08 04:02:25 +00:00
|
|
|
}
|
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
|
|
|
|
2005-03-08 04:02:25 +00:00
|
|
|
switch( m_Answer )
|
2003-06-24 20:03:28 +00:00
|
|
|
{
|
2005-03-08 04:02:25 +00:00
|
|
|
case ANSWER_YES:
|
2002-09-16 00:56:30 +00:00
|
|
|
if( m_pOnYes )
|
2003-08-23 18:33:49 +00:00
|
|
|
m_pOnYes(m_pCallbackData);
|
2005-03-08 04:02:25 +00:00
|
|
|
break;
|
|
|
|
|
case ANSWER_NO:
|
2002-09-16 00:56:30 +00:00
|
|
|
if( m_pOnNo )
|
2003-08-23 18:33:49 +00:00
|
|
|
m_pOnNo(m_pCallbackData);
|
2005-03-08 04:02:25 +00:00
|
|
|
break;
|
2003-06-24 20:03:28 +00:00
|
|
|
}
|
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.
|
|
|
|
|
*/
|