封装inputBox控件的文本修改方法
This commit is contained in:
@@ -742,6 +742,24 @@ function inputBox:reset()
|
||||
kb.setTextInput(true)
|
||||
end
|
||||
end
|
||||
function inputBox:hasText()
|
||||
return #self.value>0
|
||||
end
|
||||
function inputBox:getText()
|
||||
return self.value
|
||||
end
|
||||
function inputBox:setText(str)
|
||||
if type(str)=='string'then
|
||||
self.value=str
|
||||
end
|
||||
end
|
||||
function inputBox:addText(str)
|
||||
if type(str)=='string'then
|
||||
self.value=self.value..str
|
||||
else
|
||||
LOG.print("inputBox "..self.name.." dead, addText("..type(str)..")",'warn')
|
||||
end
|
||||
end
|
||||
function inputBox:clear()
|
||||
self.value=""
|
||||
end
|
||||
|
||||
@@ -604,16 +604,16 @@ end
|
||||
|
||||
local combKey={}
|
||||
function combKey.x()
|
||||
love.system.setClipboardText(inputBox.value)
|
||||
inputBox.value=""
|
||||
love.system.setClipboardText(inputBox:getText())
|
||||
inputBox:clear()
|
||||
SFX.play('reach')
|
||||
end
|
||||
function combKey.c()
|
||||
love.system.setClipboardText(inputBox.value)
|
||||
love.system.setClipboardText(inputBox:getText())
|
||||
SFX.play('reach')
|
||||
end
|
||||
function combKey.v()
|
||||
inputBox.value=inputBox.value..love.system.getClipboardText()
|
||||
inputBox:addText(love.system.getClipboardText())
|
||||
SFX.play('reach')
|
||||
end
|
||||
|
||||
@@ -687,7 +687,7 @@ end
|
||||
|
||||
function scene.keyDown(k)
|
||||
if k=="return"then
|
||||
local input=inputBox.value
|
||||
local input=inputBox:getText()
|
||||
if input==""then return end
|
||||
|
||||
--Write History
|
||||
@@ -736,24 +736,24 @@ function scene.keyDown(k)
|
||||
if not hisPtr then
|
||||
hisPtr=#history
|
||||
if hisPtr>0 then
|
||||
inputBox.value=history[hisPtr]
|
||||
inputBox:setText(history[hisPtr])
|
||||
end
|
||||
elseif hisPtr>1 then
|
||||
hisPtr=hisPtr-1
|
||||
inputBox.value=history[hisPtr]
|
||||
inputBox:setText(history[hisPtr])
|
||||
end
|
||||
elseif k=="down"then
|
||||
if hisPtr then
|
||||
hisPtr=hisPtr+1
|
||||
if history[hisPtr]then
|
||||
inputBox.value=history[hisPtr]
|
||||
inputBox:setText(history[hisPtr])
|
||||
else
|
||||
hisPtr=nil
|
||||
inputBox.value=""
|
||||
inputBox:clear()
|
||||
end
|
||||
end
|
||||
elseif k=="tab"then
|
||||
local str=inputBox.value
|
||||
local str=inputBox:getText()
|
||||
if str~=""and not str:find("%s")then
|
||||
local res={}
|
||||
for c in next,commands do
|
||||
@@ -767,7 +767,7 @@ function scene.keyDown(k)
|
||||
table.sort(res)
|
||||
for i=1,#res do log{COLOR.lH,res[i]}end
|
||||
elseif #res==1 then
|
||||
inputBox.value=res[1]
|
||||
inputBox:setText(res[1])
|
||||
end
|
||||
end
|
||||
elseif k=="scrollup"then outputBox:scroll(-5)
|
||||
|
||||
@@ -37,7 +37,7 @@ local function clearResult()
|
||||
waiting,lastSearch=0,false
|
||||
end
|
||||
local function search()
|
||||
local input=inputBox.value:lower()
|
||||
local input=inputBox:getText():lower()
|
||||
clearResult()
|
||||
local first
|
||||
for i=1,#dict do
|
||||
@@ -97,7 +97,7 @@ function scene.keyDown(key)
|
||||
elseif key=="link"then
|
||||
love.system.openURL(url)
|
||||
elseif key=="delete"then
|
||||
if #inputBox.value>0 then
|
||||
if inputBox:hasText()then
|
||||
clearResult()
|
||||
inputBox:clear()
|
||||
SFX.play('hold')
|
||||
@@ -105,7 +105,7 @@ function scene.keyDown(key)
|
||||
elseif key=="backspace"then
|
||||
WIDGET.keyPressed("backspace")
|
||||
elseif key=="escape"then
|
||||
if #inputBox.value>0 then
|
||||
if inputBox:hasText()then
|
||||
scene.keyDown("delete")
|
||||
else
|
||||
SCN.back()
|
||||
@@ -115,7 +115,7 @@ function scene.keyDown(key)
|
||||
end
|
||||
|
||||
function scene.update(dt)
|
||||
local input=inputBox.value
|
||||
local input=inputBox:getText()
|
||||
if input~=lastTickInput then
|
||||
if #input==0 then
|
||||
clearResult()
|
||||
|
||||
@@ -4,7 +4,7 @@ local passwordBox=WIDGET.newInputBox{name="password",x=380,y=300,w=620,h=60,secr
|
||||
local savePW=false
|
||||
|
||||
local function login()
|
||||
local email,password=emailBox.value,passwordBox.value
|
||||
local email,password=emailBox:getText(),passwordBox:getText()
|
||||
if not STRING.simpEmailCheck(email)then
|
||||
LOG.print(text.wrongEmail)return
|
||||
elseif #password==0 then
|
||||
@@ -26,8 +26,8 @@ function scene.sceneInit()
|
||||
local data=FILE.load("conf/account")
|
||||
if data then
|
||||
savePW=true
|
||||
emailBox.value=data[1]
|
||||
passwordBox.value=data[2]
|
||||
emailBox:setText(data[1])
|
||||
passwordBox:setText(data[2])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
local scene={}
|
||||
|
||||
local function register()
|
||||
local username= WIDGET.active.username.value
|
||||
local email= WIDGET.active.email.value
|
||||
local password= WIDGET.active.password.value
|
||||
local password2=WIDGET.active.password2.value
|
||||
local username= WIDGET.active.username:getText()
|
||||
local email= WIDGET.active.email:getText()
|
||||
local password= WIDGET.active.password:getText()
|
||||
local password2=WIDGET.active.password2:getText()
|
||||
if #username==0 then
|
||||
LOG.print(text.noUsername)return
|
||||
elseif not STRING.simpEmailCheck(email)then
|
||||
|
||||
Reference in New Issue
Block a user