From 485dda2a0f039ac10ebd45244e2f074aeef81cbf Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 10 Apr 2012 16:35:46 +0800 Subject: [PATCH] fix: bugs in inputbox.lua * one typo * clear ret_code on exit * add init() method --- inputbox.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/inputbox.lua b/inputbox.lua index a38950022..c26b9e20f 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -31,6 +31,7 @@ InputBox = { fheight = 25, fwidth = 15, commands = nil, + initialized = false, } function InputBox:new(o) @@ -40,6 +41,13 @@ function InputBox:new(o) return o end +function InputBox:init() + if not self.initialized then + self:addAllCommands() + self.initialized = true + end +end + function InputBox:refreshText() -- clear previous painted text fb.bb:paintRect(140, self.input_start_y-19, @@ -125,8 +133,8 @@ end -- @d_text: default to nil (used to set default text in input slot) ---------------------------------------------------------------------- function InputBox:input(ypos, height, title, d_text) + self:init() -- do some initilization - self:addAllCommands() self.ypos = ypos self.h = height self.input_start_y = ypos + 35 @@ -170,6 +178,7 @@ function InputBox:input(ypos, height, title, d_text) end if ret_code == "break" then + ret_code = nil break end end -- if @@ -265,13 +274,12 @@ end -- Designed by eLiNK ---------------------------------------------------- -NumInputBox = InputBox:new{} +NumInputBox = InputBox:new{ + initialized = false, + commands = Commands:new{}, +} function NumInputBox:addAllCommands() - if self.commands then - -- we only initialize once - return - end self.commands = Commands:new{} INPUT_NUM_KEYS = { @@ -320,7 +328,7 @@ function NumInputBox:addAllCommands() ) end -function InputBox:drawHelpMsg(ypos, w, h) +function NumInputBox:drawHelpMsg(ypos, w, h) local w = 415 local y = ypos - 60 local x = (G_width - w) / 2