diff --git a/stepmania/src/ScreenTextEntry.cpp b/stepmania/src/ScreenTextEntry.cpp index 3cb3ad1b3d..9ed7bc7d60 100644 --- a/stepmania/src/ScreenTextEntry.cpp +++ b/stepmania/src/ScreenTextEntry.cpp @@ -70,14 +70,10 @@ bool ScreenTextEntry::s_bCancelledLast = false; * subject to change and shouldn't be written to disk. */ REGISTER_SCREEN_CLASS( ScreenTextEntry ); +REGISTER_SCREEN_CLASS( ScreenTextEntryVisual ); 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(); m_textQuestion.LoadFromFont( THEME->GetPathF(m_sName,"question") ); @@ -94,44 +90,8 @@ void ScreenTextEntry::Init() 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( 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_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; xSetXY( bt.GetX(), bt.GetY() ); - m_sprCursor->PlayCommand( m_iFocusY == KEYBOARD_ROW_SPECIAL ? "SpecialKey" : "RegularKey" ); -} - void ScreenTextEntry::Update( float fDelta ) { ScreenWithMenuElements::Update( fDelta ); @@ -249,65 +185,13 @@ void ScreenTextEntry::Input( const InputEventPlus &input ) AppendToAnswer( ssprintf( "%c", c ) ); - // If the user wishes to select text in traditional way, start should finish text entry - m_iFocusY = KEYBOARD_ROW_SPECIAL; - m_iFocusX = DONE; - - PositionCursor(); + TextEnteredDirectly(); } } 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 ) { wstring sNewAnswer = m_sAnswer+RStringToWstring(s); @@ -336,30 +220,7 @@ void ScreenTextEntry::BackspaceInAnswer() void ScreenTextEntry::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] ); - } + End( false ); } void ScreenTextEntry::TweenOffScreen() @@ -369,7 +230,6 @@ void ScreenTextEntry::TweenOffScreen() OFF_COMMAND( m_textQuestion ); OFF_COMMAND( m_sprAnswerBox ); OFF_COMMAND( m_textAnswer ); - OFF_COMMAND( m_sprCursor ); } void ScreenTextEntry::End( bool bCancelled ) @@ -416,6 +276,174 @@ void ScreenTextEntry::MenuBack( PlayerNumber pn ) 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( 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; xSetXY( 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 * All rights reserved. diff --git a/stepmania/src/ScreenTextEntry.h b/stepmania/src/ScreenTextEntry.h index b66d3639be..e2fd3763f7 100644 --- a/stepmania/src/ScreenTextEntry.h +++ b/stepmania/src/ScreenTextEntry.h @@ -42,7 +42,6 @@ public: TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true ); } - ~ScreenTextEntry(); virtual void Init(); virtual void BeginScreen(); @@ -54,49 +53,66 @@ public: static bool s_bCancelledLast; protected: - void MoveX( int iDir ); - void MoveY( int iDir ); - void AppendToAnswer( RString s ); void BackspaceInAnswer(); + virtual void TextEnteredDirectly() { } void End( bool bCancelled ); - 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); } +private: virtual void MenuStart( PlayerNumber pn ); virtual void MenuBack( PlayerNumber pn ); void UpdateAnswerText(); + wstring m_sAnswer; + bool m_bShowAnswerCaret; + BitmapText m_textQuestion; AutoActor m_sprAnswerBox; - wstring m_sAnswer; BitmapText m_textAnswer; - bool m_bShowAnswerCaret; - AutoActor m_sprCursor; - - int m_iFocusX; - KeyboardRow m_iFocusY; - - void PositionCursor(); - - BitmapText *m_ptextKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW]; - ThemeMetric ROW_START_X; - ThemeMetric ROW_START_Y; - ThemeMetric ROW_END_X; - ThemeMetric ROW_END_Y; - RageSound m_sndType; RageSound m_sndBackspace; - RageSound m_sndChange; 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 ROW_START_X; + ThemeMetric ROW_START_Y; + ThemeMetric ROW_END_X; + ThemeMetric ROW_END_Y; +}; #endif