From dd71daeee4a07231d54d5f0f269c5aa1a4cfbce5 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sat, 2 Sep 2006 23:27:27 +0000 Subject: [PATCH] Validation function for floating point values. 1 2.3 -4.5 -8.2e-10 are all valid. --- stepmania/src/ScreenTextEntry.cpp | 13 ++++++++++++- stepmania/src/ScreenTextEntry.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/stepmania/src/ScreenTextEntry.cpp b/stepmania/src/ScreenTextEntry.cpp index f977d10707..3e011ae918 100644 --- a/stepmania/src/ScreenTextEntry.cpp +++ b/stepmania/src/ScreenTextEntry.cpp @@ -11,6 +11,7 @@ #include "ActorUtil.h" #include "InputEventPlus.h" #include "RageInput.h" +#include "LocalizedString.h" static const char* g_szKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW] = { @@ -88,6 +89,16 @@ void ScreenTextEntry::TextEntry( SCREENMAN->AddNewScreenToTop( "ScreenTextEntry", smSendOnPop ); } +static LocalizedString INVALID_FLOAT( "ScreenTextEntry", "\"%s\" is an invalid floating point value." ); +bool ScreenTextEntry::FloatValidate( const RString &sAnswer, RString &sErrorOut ) +{ + float f; + if( StringToFloat(sAnswer, f) ) + return true; + sErrorOut = ssprintf( INVALID_FLOAT.GetValue(), sAnswer.c_str() ); + return false; +} + bool ScreenTextEntry::s_bCancelledLast = false; /* @@ -313,7 +324,7 @@ void ScreenTextEntryVisual::Init() for( int x=0; x( text.Copy() ); // XXX: Copy() should be covariant + pbt = dynamic_cast( text.Copy() ); // XXX: Copy() should be covariant this->AddChild( pbt ); RString s = g_szKeys[r][x]; diff --git a/stepmania/src/ScreenTextEntry.h b/stepmania/src/ScreenTextEntry.h index 2a523774ab..270b8d5b88 100644 --- a/stepmania/src/ScreenTextEntry.h +++ b/stepmania/src/ScreenTextEntry.h @@ -55,6 +55,8 @@ public: { TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true ); } + + static bool FloatValidate( const RString &sAnswer, RString &sErrorOut ); virtual void Init(); virtual void BeginScreen();