Split out visual keyboard text entry, to allow direct input only.

This commit is contained in:
Glenn Maynard
2006-01-29 00:49:23 +00:00
parent ceb55bbbb4
commit bdbd8eac51
2 changed files with 211 additions and 167 deletions
+171 -143
View File
@@ -70,14 +70,10 @@ bool ScreenTextEntry::s_bCancelledLast = false;
* subject to change and shouldn't be written to disk. * subject to change and shouldn't be written to disk.
*/ */
REGISTER_SCREEN_CLASS( ScreenTextEntry ); REGISTER_SCREEN_CLASS( ScreenTextEntry );
REGISTER_SCREEN_CLASS( ScreenTextEntryVisual );
void ScreenTextEntry::Init() void ScreenTextEntry::Init()
{ {
ROW_START_X.Load( m_sName, "RowStartX" );
ROW_START_Y.Load( m_sName, "RowStartY" );
ROW_END_X.Load( m_sName, "RowEndX" );
ROW_END_Y.Load( m_sName, "RowEndY" );
ScreenWithMenuElements::Init(); ScreenWithMenuElements::Init();
m_textQuestion.LoadFromFont( THEME->GetPathF(m_sName,"question") ); m_textQuestion.LoadFromFont( THEME->GetPathF(m_sName,"question") );
@@ -94,44 +90,8 @@ void ScreenTextEntry::Init()
m_bShowAnswerCaret = false; m_bShowAnswerCaret = false;
m_sprCursor.Load( THEME->GetPathG(m_sName,"cursor") );
m_sprCursor->SetName( "Cursor" );
this->AddChild( m_sprCursor );
// Init keyboard
{
BitmapText text;
text.LoadFromFont( THEME->GetPathF(m_sName,"keyboard") );
text.SetName( "Keys" );
ActorUtil::LoadAllCommands( text, m_sName );
text.PlayCommand( "Init" );
FOREACH_KeyboardRow( r )
{
for( int x=0; x<KEYS_PER_ROW; ++x )
{
BitmapText *&pbt = m_ptextKeys[r][x];
pbt = static_cast<BitmapText *>( text.Copy() ); // XXX: Copy() should be covariant
this->AddChild( pbt );
RString s = g_szKeys[r][x];
if( !s.empty() && r == KEYBOARD_ROW_SPECIAL )
s = THEME->GetString( m_sName, s );
pbt->SetText( s );
}
}
}
m_sndType.Load( THEME->GetPathS(m_sName,"type"), true ); m_sndType.Load( THEME->GetPathS(m_sName,"type"), true );
m_sndBackspace.Load( THEME->GetPathS(m_sName,"backspace"), true ); m_sndBackspace.Load( THEME->GetPathS(m_sName,"backspace"), true );
m_sndChange.Load( THEME->GetPathS(m_sName,"change"), true );
}
ScreenTextEntry::~ScreenTextEntry()
{
FOREACH_KeyboardRow( r )
for( int x=0; x<KEYS_PER_ROW; ++x )
SAFE_DELETE( m_ptextKeys[r][x] );
} }
void ScreenTextEntry::BeginScreen() void ScreenTextEntry::BeginScreen()
@@ -146,23 +106,6 @@ void ScreenTextEntry::BeginScreen()
SET_XY_AND_ON_COMMAND( m_textAnswer ); SET_XY_AND_ON_COMMAND( m_textAnswer );
UpdateAnswerText(); UpdateAnswerText();
ON_COMMAND( m_sprCursor );
m_iFocusX = 0;
m_iFocusY = (KeyboardRow)0;
FOREACH_KeyboardRow( r )
{
for( int x=0; x<KEYS_PER_ROW; ++x )
{
BitmapText &bt = *m_ptextKeys[r][x];
float fX = roundf( SCALE( x, 0, KEYS_PER_ROW-1, ROW_START_X, ROW_END_X ) );
float fY = roundf( SCALE( r, 0, NUM_KEYBOARD_ROWS-1, ROW_START_Y, ROW_END_Y ) );
bt.SetXY( fX, fY );
}
}
PositionCursor();
} }
void ScreenTextEntry::UpdateAnswerText() void ScreenTextEntry::UpdateAnswerText()
@@ -183,13 +126,6 @@ void ScreenTextEntry::UpdateAnswerText()
m_textAnswer.SetText( s ); m_textAnswer.SetText( s );
} }
void ScreenTextEntry::PositionCursor()
{
BitmapText &bt = *m_ptextKeys[m_iFocusY][m_iFocusX];
m_sprCursor->SetXY( bt.GetX(), bt.GetY() );
m_sprCursor->PlayCommand( m_iFocusY == KEYBOARD_ROW_SPECIAL ? "SpecialKey" : "RegularKey" );
}
void ScreenTextEntry::Update( float fDelta ) void ScreenTextEntry::Update( float fDelta )
{ {
ScreenWithMenuElements::Update( fDelta ); ScreenWithMenuElements::Update( fDelta );
@@ -249,65 +185,13 @@ void ScreenTextEntry::Input( const InputEventPlus &input )
AppendToAnswer( ssprintf( "%c", c ) ); AppendToAnswer( ssprintf( "%c", c ) );
// If the user wishes to select text in traditional way, start should finish text entry TextEnteredDirectly();
m_iFocusY = KEYBOARD_ROW_SPECIAL;
m_iFocusX = DONE;
PositionCursor();
} }
} }
ScreenWithMenuElements::Input( input ); ScreenWithMenuElements::Input( input );
} }
void ScreenTextEntry::MoveX( int iDir )
{
RString sKey;
do
{
m_iFocusX += iDir;
wrap( m_iFocusX, KEYS_PER_ROW );
sKey = g_szKeys[m_iFocusY][m_iFocusX];
}
while( sKey == "" );
m_sndChange.Play();
PositionCursor();
}
void ScreenTextEntry::MoveY( int iDir )
{
RString sKey;
do
{
m_iFocusY = (KeyboardRow)(m_iFocusY + iDir);
wrap( (int&)m_iFocusY, NUM_KEYBOARD_ROWS );
// HACK: Round to nearest option so that we always stop
// on KEYBOARD_ROW_SPECIAL.
if( m_iFocusY == KEYBOARD_ROW_SPECIAL )
{
for( int i=0; true; i++ )
{
sKey = g_szKeys[m_iFocusY][m_iFocusX];
if( sKey != "" )
break;
// UGLY: Probe one space to the left before looking to the right
m_iFocusX += (i==0) ? -1 : +1;
wrap( m_iFocusX, KEYS_PER_ROW );
}
}
sKey = g_szKeys[m_iFocusY][m_iFocusX];
}
while( sKey == "" );
m_sndChange.Play();
PositionCursor();
}
void ScreenTextEntry::AppendToAnswer( RString s ) void ScreenTextEntry::AppendToAnswer( RString s )
{ {
wstring sNewAnswer = m_sAnswer+RStringToWstring(s); wstring sNewAnswer = m_sAnswer+RStringToWstring(s);
@@ -336,30 +220,7 @@ void ScreenTextEntry::BackspaceInAnswer()
void ScreenTextEntry::MenuStart( PlayerNumber pn ) void ScreenTextEntry::MenuStart( PlayerNumber pn )
{ {
if( m_iFocusY == KEYBOARD_ROW_SPECIAL ) End( false );
{
switch( m_iFocusX )
{
case SPACEBAR:
AppendToAnswer( " " );
break;
case BACKSPACE:
BackspaceInAnswer();
break;
case CANCEL:
End( true );
break;
case DONE:
End( false );
break;
default:
break;
}
}
else
{
AppendToAnswer( g_szKeys[m_iFocusY][m_iFocusX] );
}
} }
void ScreenTextEntry::TweenOffScreen() void ScreenTextEntry::TweenOffScreen()
@@ -369,7 +230,6 @@ void ScreenTextEntry::TweenOffScreen()
OFF_COMMAND( m_textQuestion ); OFF_COMMAND( m_textQuestion );
OFF_COMMAND( m_sprAnswerBox ); OFF_COMMAND( m_sprAnswerBox );
OFF_COMMAND( m_textAnswer ); OFF_COMMAND( m_textAnswer );
OFF_COMMAND( m_sprCursor );
} }
void ScreenTextEntry::End( bool bCancelled ) void ScreenTextEntry::End( bool bCancelled )
@@ -416,6 +276,174 @@ void ScreenTextEntry::MenuBack( PlayerNumber pn )
End( true ); End( true );
} }
void ScreenTextEntryVisual::Init()
{
ROW_START_X.Load( m_sName, "RowStartX" );
ROW_START_Y.Load( m_sName, "RowStartY" );
ROW_END_X.Load( m_sName, "RowEndX" );
ROW_END_Y.Load( m_sName, "RowEndY" );
ScreenTextEntry::Init();
m_sprCursor.Load( THEME->GetPathG(m_sName,"cursor") );
m_sprCursor->SetName( "Cursor" );
this->AddChild( m_sprCursor );
// Init keyboard
{
BitmapText text;
text.LoadFromFont( THEME->GetPathF(m_sName,"keyboard") );
text.SetName( "Keys" );
ActorUtil::LoadAllCommands( text, m_sName );
text.PlayCommand( "Init" );
FOREACH_KeyboardRow( r )
{
for( int x=0; x<KEYS_PER_ROW; ++x )
{
BitmapText *&pbt = m_ptextKeys[r][x];
pbt = static_cast<BitmapText *>( text.Copy() ); // XXX: Copy() should be covariant
this->AddChild( pbt );
RString s = g_szKeys[r][x];
if( !s.empty() && r == KEYBOARD_ROW_SPECIAL )
s = THEME->GetString( m_sName, s );
pbt->SetText( s );
}
}
}
m_sndChange.Load( THEME->GetPathS(m_sName,"change"), true );
}
ScreenTextEntryVisual::~ScreenTextEntryVisual()
{
FOREACH_KeyboardRow( r )
for( int x=0; x<KEYS_PER_ROW; ++x )
SAFE_DELETE( m_ptextKeys[r][x] );
}
void ScreenTextEntryVisual::BeginScreen()
{
ScreenTextEntry::BeginScreen();
ON_COMMAND( m_sprCursor );
m_iFocusX = 0;
m_iFocusY = (KeyboardRow)0;
FOREACH_KeyboardRow( r )
{
for( int x=0; x<KEYS_PER_ROW; ++x )
{
BitmapText &bt = *m_ptextKeys[r][x];
float fX = roundf( SCALE( x, 0, KEYS_PER_ROW-1, ROW_START_X, ROW_END_X ) );
float fY = roundf( SCALE( r, 0, NUM_KEYBOARD_ROWS-1, ROW_START_Y, ROW_END_Y ) );
bt.SetXY( fX, fY );
}
}
PositionCursor();
}
void ScreenTextEntryVisual::PositionCursor()
{
BitmapText &bt = *m_ptextKeys[m_iFocusY][m_iFocusX];
m_sprCursor->SetXY( bt.GetX(), bt.GetY() );
m_sprCursor->PlayCommand( m_iFocusY == KEYBOARD_ROW_SPECIAL ? "SpecialKey" : "RegularKey" );
}
void ScreenTextEntryVisual::TextEnteredDirectly()
{
// If the user enters text with a keyboard, jump to DONE, so enter ends the screen.
m_iFocusY = KEYBOARD_ROW_SPECIAL;
m_iFocusX = DONE;
PositionCursor();
}
void ScreenTextEntryVisual::MoveX( int iDir )
{
RString sKey;
do
{
m_iFocusX += iDir;
wrap( m_iFocusX, KEYS_PER_ROW );
sKey = g_szKeys[m_iFocusY][m_iFocusX];
}
while( sKey == "" );
m_sndChange.Play();
PositionCursor();
}
void ScreenTextEntryVisual::MoveY( int iDir )
{
RString sKey;
do
{
m_iFocusY = enum_add2( m_iFocusY, +iDir );
wrap( (int&)m_iFocusY, NUM_KEYBOARD_ROWS );
// HACK: Round to nearest option so that we always stop
// on KEYBOARD_ROW_SPECIAL.
if( m_iFocusY == KEYBOARD_ROW_SPECIAL )
{
for( int i=0; true; i++ )
{
sKey = g_szKeys[m_iFocusY][m_iFocusX];
if( sKey != "" )
break;
// UGLY: Probe one space to the left before looking to the right
m_iFocusX += (i==0) ? -1 : +1;
wrap( m_iFocusX, KEYS_PER_ROW );
}
}
sKey = g_szKeys[m_iFocusY][m_iFocusX];
}
while( sKey == "" );
m_sndChange.Play();
PositionCursor();
}
void ScreenTextEntryVisual::MenuStart( PlayerNumber pn )
{
if( m_iFocusY == KEYBOARD_ROW_SPECIAL )
{
switch( m_iFocusX )
{
case SPACEBAR:
AppendToAnswer( " " );
break;
case BACKSPACE:
BackspaceInAnswer();
break;
case CANCEL:
End( true );
break;
case DONE:
End( false );
break;
default:
break;
}
}
else
{
AppendToAnswer( g_szKeys[m_iFocusY][m_iFocusX] );
}
}
void ScreenTextEntryVisual::TweenOffScreen()
{
ScreenTextEntry::TweenOffScreen();
OFF_COMMAND( m_sprCursor );
}
/* /*
* (c) 2001-2004 Chris Danford * (c) 2001-2004 Chris Danford
* All rights reserved. * All rights reserved.
+40 -24
View File
@@ -42,7 +42,6 @@ public:
TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true ); TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true );
} }
~ScreenTextEntry();
virtual void Init(); virtual void Init();
virtual void BeginScreen(); virtual void BeginScreen();
@@ -54,49 +53,66 @@ public:
static bool s_bCancelledLast; static bool s_bCancelledLast;
protected: protected:
void MoveX( int iDir );
void MoveY( int iDir );
void AppendToAnswer( RString s ); void AppendToAnswer( RString s );
void BackspaceInAnswer(); void BackspaceInAnswer();
virtual void TextEnteredDirectly() { }
void End( bool bCancelled ); void End( bool bCancelled );
virtual void MenuLeft( PlayerNumber pn ) { MoveX(-1); } private:
virtual void MenuRight( PlayerNumber pn ) { MoveX(+1); }
virtual void MenuUp( PlayerNumber pn ) { MoveY(-1); }
virtual void MenuDown( PlayerNumber pn ) { MoveY(+1); }
virtual void MenuStart( PlayerNumber pn ); virtual void MenuStart( PlayerNumber pn );
virtual void MenuBack( PlayerNumber pn ); virtual void MenuBack( PlayerNumber pn );
void UpdateAnswerText(); void UpdateAnswerText();
BitmapText m_textQuestion;
AutoActor m_sprAnswerBox;
wstring m_sAnswer; wstring m_sAnswer;
BitmapText m_textAnswer;
bool m_bShowAnswerCaret; bool m_bShowAnswerCaret;
AutoActor m_sprCursor; BitmapText m_textQuestion;
AutoActor m_sprAnswerBox;
int m_iFocusX; BitmapText m_textAnswer;
KeyboardRow m_iFocusY;
void PositionCursor();
BitmapText *m_ptextKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW];
ThemeMetric<float> ROW_START_X;
ThemeMetric<float> ROW_START_Y;
ThemeMetric<float> ROW_END_X;
ThemeMetric<float> ROW_END_Y;
RageSound m_sndType; RageSound m_sndType;
RageSound m_sndBackspace; RageSound m_sndBackspace;
RageSound m_sndChange;
RageTimer m_timerToggleCursor; RageTimer m_timerToggleCursor;
}; };
class ScreenTextEntryVisual: public ScreenTextEntry
{
public:
~ScreenTextEntryVisual();
void Init();
void BeginScreen();
virtual void TweenOffScreen();
protected:
void MoveX( int iDir );
void MoveY( int iDir );
void PositionCursor();
virtual void TextEnteredDirectly();
virtual void MenuLeft( PlayerNumber pn ) { MoveX(-1); }
virtual void MenuRight( PlayerNumber pn ) { MoveX(+1); }
virtual void MenuUp( PlayerNumber pn ) { MoveY(-1); }
virtual void MenuDown( PlayerNumber pn ) { MoveY(+1); }
virtual void MenuStart( PlayerNumber pn );
int m_iFocusX;
KeyboardRow m_iFocusY;
AutoActor m_sprCursor;
BitmapText *m_ptextKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW];
RageSound m_sndChange;
ThemeMetric<float> ROW_START_X;
ThemeMetric<float> ROW_START_Y;
ThemeMetric<float> ROW_END_X;
ThemeMetric<float> ROW_END_Y;
};
#endif #endif