[ScreenTextEntry] Added Load(TextEntrySettings) Lua binding. [freem]

TextEntrySettings is implemented similar to the Attributes in BitmapText.

example settings and explanation:
local teSettings = {
	SendOnPop = "",					-- ScreenMessage to send on pop (optional, "SM_None" if omitted)
	Question = "",					-- The question to display
	InitialAnswer = "",				-- Initial answer text
	MaxInputLength = 0,				-- Maximum amount of characters
	Password = false,				-- Mask character input (optional)
	Validate = nil,					-- Validation function; function(answer, errorOut), must return boolean, string.
	OnOK = nil,						-- On OK; function(answer)
	OnCancel = nil,					-- On Cancel; function()
	ValidateAppend = nil,			-- Validate appending a character; function(answer,append), must return boolean
	FormatAnswerForDisplay = nil,	-- Format answer for display; function(answer), must return string
};
This commit is contained in:
AJ Kelly
2011-01-12 13:11:41 -06:00
parent 7827af4b2a
commit 17e557c396
3 changed files with 323 additions and 23 deletions
+38 -15
View File
@@ -58,6 +58,26 @@ public:
TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCancel, true );
}
struct TextEntrySettings {
TextEntrySettings() { }
ScreenMessage smSendOnPop;
RString sQuestion;
RString sInitialAnswer;
int iMaxInputLength;
bool bPassword; // (optional)
LuaReference Validate; // (RString sAnswer, RString sErrorOut; optional)
LuaReference OnOK; // (RString sAnswer; optional)
LuaReference OnCancel; // (optional)
LuaReference ValidateAppend; // (RString sAnswerBeforeChar, RString sAppend; optional)
LuaReference FormatAnswerForDisplay; // (RString sAnswer; optional)
// see BitmapText.cpp Attribute::FromStack() and
// OptionRowHandler.cpp LoadInternal() for ideas on how to implement the
// main part, and ImportOption() from OptionRowHandler.cpp for functions.
void FromStack( lua_State *L );
};
void LoadFromTextEntrySettings( const TextEntrySettings &settings );
static bool FloatValidate( const RString &sAnswer, RString &sErrorOut );
virtual void Init();
@@ -69,6 +89,9 @@ public:
static RString s_sLastAnswer;
static bool s_bCancelledLast;
// Lua
virtual void PushSelf( lua_State *L );
protected:
void TryAppendToAnswer( RString s );
void BackspaceInAnswer();
@@ -81,16 +104,16 @@ private:
void UpdateAnswerText();
wstring m_sAnswer;
bool m_bShowAnswerCaret;
wstring m_sAnswer;
bool m_bShowAnswerCaret;
BitmapText m_textQuestion;
BitmapText m_textAnswer;
BitmapText m_textQuestion;
BitmapText m_textAnswer;
RageSound m_sndType;
RageSound m_sndBackspace;
RageSound m_sndType;
RageSound m_sndBackspace;
RageTimer m_timerToggleCursor;
RageTimer m_timerToggleCursor;
};
class ScreenTextEntryVisual: public ScreenTextEntry
@@ -107,20 +130,20 @@ protected:
virtual void TextEnteredDirectly();
virtual void MenuLeft( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveX(-1); }
virtual void MenuRight( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveX(+1); }
virtual void MenuUp( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveY(-1); }
virtual void MenuDown( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveY(+1); }
virtual void MenuLeft( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveX(-1); }
virtual void MenuRight( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveX(+1); }
virtual void MenuUp( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveY(-1); }
virtual void MenuDown( const InputEventPlus &input ) { if(input.type==IET_FIRST_PRESS) MoveY(+1); }
virtual void MenuStart( const InputEventPlus &input );
int m_iFocusX;
KeyboardRow m_iFocusY;
KeyboardRow m_iFocusY;
AutoActor m_sprCursor;
BitmapText *m_ptextKeys[NUM_KeyboardRow][KEYS_PER_ROW];
AutoActor m_sprCursor;
BitmapText *m_ptextKeys[NUM_KeyboardRow][KEYS_PER_ROW];
RageSound m_sndChange;
RageSound m_sndChange;
ThemeMetric<float> ROW_START_X;
ThemeMetric<float> ROW_START_Y;