text entry: replace placeholders on save, so they don't end up in
SMs.
This commit is contained in:
@@ -190,16 +190,18 @@ void BitmapText::DrawChars()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* sText is UTF-8. */
|
/* sText is UTF-8. */
|
||||||
void BitmapText::SetText( CString sText )
|
void BitmapText::SetText( CString sText, bool DoSubst )
|
||||||
{
|
{
|
||||||
ASSERT( m_pFont );
|
ASSERT( m_pFont );
|
||||||
|
|
||||||
|
if(DoSubst)
|
||||||
|
FontManager::ReplaceMarkers(sText);
|
||||||
|
|
||||||
if(m_szText == sText)
|
if(m_szText == sText)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_szText = sText;
|
m_szText = sText;
|
||||||
|
|
||||||
FontManager::ReplaceMarkers(sText);
|
|
||||||
|
|
||||||
/* Break the string into lines. */
|
/* Break the string into lines. */
|
||||||
m_szTextLines.clear();
|
m_szTextLines.clear();
|
||||||
m_iLineWidths.clear();
|
m_iLineWidths.clear();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
bool LoadFromFont( CString sFontName );
|
bool LoadFromFont( CString sFontName );
|
||||||
bool LoadFromNumbers( CString sTexturePath ) { return LoadFromTextureAndChars(sTexturePath,"0123456789%. :x"); };
|
bool LoadFromNumbers( CString sTexturePath ) { return LoadFromTextureAndChars(sTexturePath,"0123456789%. :x"); };
|
||||||
bool LoadFromTextureAndChars( CString sTexturePath, CString sChars );
|
bool LoadFromTextureAndChars( CString sTexturePath, CString sChars );
|
||||||
void SetText( CString sText );
|
void SetText( CString sText, bool DoSubst = true );
|
||||||
|
|
||||||
int GetWidestLineWidthInSourcePixels() { return m_iWidestLineWidth; };
|
int GetWidestLineWidthInSourcePixels() { return m_iWidestLineWidth; };
|
||||||
void CropToWidth( int iWidthInSourcePixels );
|
void CropToWidth( int iWidthInSourcePixels );
|
||||||
|
|||||||
@@ -924,6 +924,16 @@ lstring CStringToLstring(const CString &str)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CString LStringToCString(const lstring &str)
|
||||||
|
{
|
||||||
|
CString ret;
|
||||||
|
|
||||||
|
for(unsigned i = 0; i < str.size(); ++i)
|
||||||
|
ret.append(LcharToUTF8(str[i]));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int unichar_to_utf8 (longchar c, char *outbuf)
|
int unichar_to_utf8 (longchar c, char *outbuf)
|
||||||
{
|
{
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ typedef basic_string<longchar> lstring;
|
|||||||
extern const longchar INVALID_CHAR;
|
extern const longchar INVALID_CHAR;
|
||||||
|
|
||||||
lstring CStringToLstring(const CString &str);
|
lstring CStringToLstring(const CString &str);
|
||||||
|
CString LStringToCString(const lstring &str);
|
||||||
CString LcharToUTF8( longchar c );
|
CString LcharToUTF8( longchar c );
|
||||||
|
|
||||||
// Splits a CString into an CStringArray according the Deliminator.
|
// Splits a CString into an CStringArray according the Deliminator.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "GameConstantsAndTypes.h"
|
#include "GameConstantsAndTypes.h"
|
||||||
#include "PrefsManager.h"
|
#include "PrefsManager.h"
|
||||||
#include "ThemeManager.h"
|
#include "ThemeManager.h"
|
||||||
|
#include "FontManager.h"
|
||||||
|
|
||||||
const float QUESTION_X = CENTER_X;
|
const float QUESTION_X = CENTER_X;
|
||||||
const float QUESTION_Y = CENTER_Y - 60;
|
const float QUESTION_Y = CENTER_Y - 60;
|
||||||
@@ -27,12 +28,20 @@ const float ANSWER_Y = CENTER_Y + 120;
|
|||||||
const float ANSWER_WIDTH = 440;
|
const float ANSWER_WIDTH = 440;
|
||||||
const float ANSWER_HEIGHT = 30;
|
const float ANSWER_HEIGHT = 30;
|
||||||
|
|
||||||
|
/* XXX: Don't let the user use internal-use codepoints (those
|
||||||
|
* that resolve to Unicode codepoints above 0xFFFF); those are
|
||||||
|
* subject to change and shouldn't be written to .SMs.
|
||||||
|
*
|
||||||
|
* Handle UTF-8. Right now, we need to at least be able to backspace
|
||||||
|
* a whole UTF-8 character. Better would be to operate in longchars.
|
||||||
|
*/
|
||||||
ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer), void(*OnCancel)() )
|
ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuestion, CString sInitialAnswer, void(*OnOK)(CString sAnswer), void(*OnCancel)() )
|
||||||
{
|
{
|
||||||
m_SMSendWhenDone = SM_SendWhenDone;
|
m_SMSendWhenDone = SM_SendWhenDone;
|
||||||
m_pOnOK = OnOK;
|
m_pOnOK = OnOK;
|
||||||
m_pOnCancel = OnCancel;
|
m_pOnCancel = OnCancel;
|
||||||
m_sAnswer = sInitialAnswer;
|
|
||||||
|
m_sAnswer = CStringToLstring(sInitialAnswer);
|
||||||
m_bCancelled = false;
|
m_bCancelled = false;
|
||||||
|
|
||||||
m_Fade.SetTransitionTime( 0.5f );
|
m_Fade.SetTransitionTime( 0.5f );
|
||||||
@@ -57,7 +66,7 @@ ScreenTextEntry::ScreenTextEntry( ScreenMessage SM_SendWhenDone, CString sQuesti
|
|||||||
m_textAnswer.LoadFromFont( THEME->GetPathTo("Fonts","header1") );
|
m_textAnswer.LoadFromFont( THEME->GetPathTo("Fonts","header1") );
|
||||||
m_textAnswer.LoadFromFont( THEME->GetPathTo("Fonts","header1") );
|
m_textAnswer.LoadFromFont( THEME->GetPathTo("Fonts","header1") );
|
||||||
m_textAnswer.SetXY( ANSWER_X, ANSWER_Y );
|
m_textAnswer.SetXY( ANSWER_X, ANSWER_Y );
|
||||||
m_textAnswer.SetText( m_sAnswer );
|
m_textAnswer.SetText( LStringToCString(m_sAnswer) );
|
||||||
this->AddChild( &m_textAnswer );
|
this->AddChild( &m_textAnswer );
|
||||||
|
|
||||||
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","menu prompt") );
|
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","menu prompt") );
|
||||||
@@ -91,8 +100,9 @@ void ScreenTextEntry::Input( const DeviceInput& DeviceI, const InputEventType ty
|
|||||||
MenuStart(PLAYER_1);
|
MenuStart(PLAYER_1);
|
||||||
break;
|
break;
|
||||||
case SDLK_BACKSPACE:
|
case SDLK_BACKSPACE:
|
||||||
m_sAnswer = m_sAnswer.Left( max(0,m_sAnswer.GetLength()-1) );
|
if(!m_sAnswer.empty())
|
||||||
m_textAnswer.SetText( m_sAnswer );
|
m_sAnswer = m_sAnswer.erase( m_sAnswer.size()-1 );
|
||||||
|
m_textAnswer.SetText( LStringToCString(m_sAnswer) );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
char c;
|
char c;
|
||||||
@@ -137,7 +147,7 @@ void ScreenTextEntry::Input( const DeviceInput& DeviceI, const InputEventType ty
|
|||||||
if( c != '\0' )
|
if( c != '\0' )
|
||||||
{
|
{
|
||||||
m_sAnswer += c;
|
m_sAnswer += c;
|
||||||
m_textAnswer.SetText( m_sAnswer );
|
m_textAnswer.SetText( LStringToCString(m_sAnswer) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -187,7 +197,12 @@ void ScreenTextEntry::MenuStart( PlayerNumber pn )
|
|||||||
if( m_bCancelled ) {
|
if( m_bCancelled ) {
|
||||||
if( m_pOnCancel ) m_pOnCancel();
|
if( m_pOnCancel ) m_pOnCancel();
|
||||||
} else {
|
} else {
|
||||||
if( m_pOnOK ) m_pOnOK( m_sAnswer );
|
if( m_pOnOK )
|
||||||
|
{
|
||||||
|
CString ret = LStringToCString(m_sAnswer);
|
||||||
|
FontManager::ReplaceMarkers(ret);
|
||||||
|
m_pOnOK( ret );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ protected:
|
|||||||
TransitionFade m_Fade;
|
TransitionFade m_Fade;
|
||||||
BitmapText m_textQuestion;
|
BitmapText m_textQuestion;
|
||||||
Quad m_rectAnswerBox;
|
Quad m_rectAnswerBox;
|
||||||
CString m_sAnswer;
|
lstring m_sAnswer;
|
||||||
BitmapText m_textAnswer;
|
BitmapText m_textAnswer;
|
||||||
ScreenMessage m_SMSendWhenDone;
|
ScreenMessage m_SMSendWhenDone;
|
||||||
void(*m_pOnOK)( CString sAnswer );
|
void(*m_pOnOK)( CString sAnswer );
|
||||||
|
|||||||
Reference in New Issue
Block a user