新增文本框控件,空间框架略微修改适配文本输入
This commit is contained in:
@@ -171,8 +171,10 @@ function love.touchreleased(id,x,y)
|
|||||||
WIDGET.press(x,y)
|
WIDGET.press(x,y)
|
||||||
WIDGET.release(x,y)
|
WIDGET.release(x,y)
|
||||||
touching=nil
|
touching=nil
|
||||||
|
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
||||||
WIDGET.sel=nil
|
WIDGET.sel=nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if touchUp[SCN.cur]then
|
if touchUp[SCN.cur]then
|
||||||
touchUp[SCN.cur](id,x,y)
|
touchUp[SCN.cur](id,x,y)
|
||||||
end
|
end
|
||||||
@@ -253,6 +255,11 @@ function love.keyreleased(i)
|
|||||||
if SCN.swapping then return end
|
if SCN.swapping then return end
|
||||||
if keyUp[SCN.cur]then keyUp[SCN.cur](i)end
|
if keyUp[SCN.cur]then keyUp[SCN.cur](i)end
|
||||||
end
|
end
|
||||||
|
function love.textinput(text)
|
||||||
|
if WIDGET.sel and WIDGET.sel.type=="textBox"then
|
||||||
|
WIDGET.sel.value=WIDGET.sel.value..text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function love.joystickadded(JS)
|
function love.joystickadded(JS)
|
||||||
joysticks[#joysticks+1]=JS
|
joysticks[#joysticks+1]=JS
|
||||||
|
|||||||
@@ -457,6 +457,9 @@ local langList={
|
|||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
title="登录/注册",
|
title="登录/注册",
|
||||||
|
username="用户名",
|
||||||
|
password="密码",
|
||||||
|
password2="确认密码",
|
||||||
},
|
},
|
||||||
account={
|
account={
|
||||||
title="账户",
|
title="账户",
|
||||||
@@ -1044,6 +1047,9 @@ local langList={
|
|||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
title="登录/注册",
|
title="登录/注册",
|
||||||
|
username="用户名",
|
||||||
|
password="密码",
|
||||||
|
password2="确认密码",
|
||||||
},
|
},
|
||||||
account={
|
account={
|
||||||
title="账户",
|
title="账户",
|
||||||
@@ -1621,6 +1627,9 @@ local langList={
|
|||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
title="Log in / Sign up",
|
title="Log in / Sign up",
|
||||||
|
username="Username",
|
||||||
|
password="Password",
|
||||||
|
password2="Again Password",
|
||||||
},
|
},
|
||||||
account={
|
account={
|
||||||
title="Account",
|
title="Account",
|
||||||
@@ -2212,6 +2221,9 @@ local langList={
|
|||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
title="Log in / Sign up",
|
title="Log in / Sign up",
|
||||||
|
username="@",
|
||||||
|
password="*",
|
||||||
|
password2="*",
|
||||||
},
|
},
|
||||||
account={
|
account={
|
||||||
title="@_@",
|
title="@_@",
|
||||||
@@ -2796,6 +2808,9 @@ local langList={
|
|||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
title="登录/注册",
|
title="登录/注册",
|
||||||
|
username="用户名",
|
||||||
|
password="密码",
|
||||||
|
password2="你觉得应该填啥",
|
||||||
},
|
},
|
||||||
account={
|
account={
|
||||||
title="账户",
|
title="账户",
|
||||||
|
|||||||
@@ -100,6 +100,20 @@ do--setFont
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
do--upperChar
|
||||||
|
local upper=string.upper
|
||||||
|
upperList={
|
||||||
|
["1"]="!",["2"]="@",["3"]="#",["4"]="$",["5"]="%",
|
||||||
|
["6"]="^",["7"]="&",["8"]="*",["9"]="(",["0"]=")",
|
||||||
|
["`"]="~",["-"]="_",["="]="+",
|
||||||
|
["["]="{",["]"]="}",["\\"]="|",
|
||||||
|
[";"]=":",["'"]="\"",
|
||||||
|
[","]="<",["."]=">",["/"]="?",
|
||||||
|
}
|
||||||
|
function upperChar(c)
|
||||||
|
return upperList[c]or upper(c)
|
||||||
|
end
|
||||||
|
end
|
||||||
do--dumpTable
|
do--dumpTable
|
||||||
local tabs={
|
local tabs={
|
||||||
[0]="",
|
[0]="",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local gc=love.graphics
|
|||||||
local kb=love.keyboard
|
local kb=love.keyboard
|
||||||
local int,abs=math.floor,math.abs
|
local int,abs=math.floor,math.abs
|
||||||
local max,min=math.max,math.min
|
local max,min=math.max,math.min
|
||||||
|
local sub=string.sub
|
||||||
local format=string.format
|
local format=string.format
|
||||||
local color=color
|
local color=color
|
||||||
local setFont=setFont
|
local setFont=setFont
|
||||||
@@ -586,6 +587,86 @@ function WIDGET.newSelector(D)
|
|||||||
return _
|
return _
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local textBox={
|
||||||
|
type="textBox",
|
||||||
|
keepFocus=true,
|
||||||
|
ATV=0,--Activating time(0~4)
|
||||||
|
value="",--Text contained
|
||||||
|
}
|
||||||
|
function textBox:reset()
|
||||||
|
self.ATV=0
|
||||||
|
end
|
||||||
|
function textBox:isAbove(x,y)
|
||||||
|
return
|
||||||
|
x>self.x and
|
||||||
|
y>self.y and
|
||||||
|
x<self.x+self.w and
|
||||||
|
y<self.y+self.h
|
||||||
|
end
|
||||||
|
function textBox:getCenter()
|
||||||
|
return self.x+self.w*.5,self.y
|
||||||
|
end
|
||||||
|
function textBox:update()
|
||||||
|
local ATV=self.ATV
|
||||||
|
if WIDGET.sel==self then
|
||||||
|
if ATV<3 then self.ATV=ATV+1 end
|
||||||
|
else
|
||||||
|
if ATV>0 then self.ATV=ATV-.25 end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function textBox:draw()
|
||||||
|
local x,y,w,h=self.x,self.y,self.w,self.h
|
||||||
|
local ATV=self.ATV
|
||||||
|
|
||||||
|
gc.setColor(1,1,1,ATV*.1)
|
||||||
|
gc.rectangle("fill",x,y,w,h)
|
||||||
|
|
||||||
|
gc.setColor(1,1,1)
|
||||||
|
gc.setLineWidth(4)
|
||||||
|
gc.rectangle("line",x,y,w,h)
|
||||||
|
|
||||||
|
--Text
|
||||||
|
setFont(self.font)
|
||||||
|
if self.secret then
|
||||||
|
for i=1,#self.value do
|
||||||
|
gc.print("*",x-5+self.font*.5*i,y+h*.5-self.font*.7)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
gc.print(self.value,x+10,y+h*.5-self.font*.7)
|
||||||
|
end
|
||||||
|
t=self.text
|
||||||
|
if t then
|
||||||
|
gc.printf(t,x-412,y+h*.5-self.font*.7,400,"right")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function textBox:getInfo()
|
||||||
|
return format("x=%d,y=%d,w=%d,h=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h)
|
||||||
|
end
|
||||||
|
function WIDGET.newTextBox(D)
|
||||||
|
if not D.h then D.h=D.w end
|
||||||
|
local _={
|
||||||
|
name= D.name,
|
||||||
|
|
||||||
|
x= D.x,
|
||||||
|
y= D.y,
|
||||||
|
w= D.w,
|
||||||
|
h= D.h,
|
||||||
|
secret= D.secret,
|
||||||
|
|
||||||
|
resCtr={
|
||||||
|
D.x+.5,D.y,
|
||||||
|
D.x+D.w*.2,D.y,
|
||||||
|
D.x+D.w*.8,D.y,
|
||||||
|
},
|
||||||
|
|
||||||
|
font= int(D.h/7-1)*5,
|
||||||
|
hide= D.hide,
|
||||||
|
}
|
||||||
|
for k,v in next,textBox do _[k]=v end
|
||||||
|
setmetatable(_,widgetMetatable)
|
||||||
|
return _
|
||||||
|
end
|
||||||
|
|
||||||
WIDGET.active={}--Table contains all active widgets
|
WIDGET.active={}--Table contains all active widgets
|
||||||
WIDGET.sel=nil--Selected widget
|
WIDGET.sel=nil--Selected widget
|
||||||
function WIDGET.set(L)
|
function WIDGET.set(L)
|
||||||
@@ -601,13 +682,15 @@ function WIDGET.set(L)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function WIDGET.moveCursor(x,y)
|
function WIDGET.moveCursor(x,y)
|
||||||
WIDGET.sel=nil
|
|
||||||
for _,W in next,WIDGET.active do
|
for _,W in next,WIDGET.active do
|
||||||
if not(W.hide and W.hide())and W.resCtr and W:isAbove(x,y)then
|
if not(W.hide and W.hide())and W.resCtr and W:isAbove(x,y)then
|
||||||
WIDGET.sel=W
|
WIDGET.sel=W
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
||||||
|
WIDGET.sel=nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
function WIDGET.press(x,y)
|
function WIDGET.press(x,y)
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
@@ -645,14 +728,10 @@ function WIDGET.press(x,y)
|
|||||||
SFX.play("prerotate")
|
SFX.play("prerotate")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif W.type=="keyboard"then
|
elseif W.type=="textBox"then
|
||||||
if x then
|
if system=="Android"then
|
||||||
x,y=int((x-W.x)/W.w*15)+1,int((y-W.y)/W.h*5)
|
local _,y=xOy:transformPoint(0,W.y+W.h)
|
||||||
local k=keyboardKeys[15*y+x]
|
kb.setTextInput(true,0,y,1,1)
|
||||||
if k then
|
|
||||||
sysFX.newShade(.4,1,1,1,W.x+(x-1)/15*W.w,W.y+y/5*W.h,W.w/15,W.h/5)
|
|
||||||
love.keypressed(k)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if W.hide and W.hide()then WIDGET.sel=nil end
|
if W.hide and W.hide()then WIDGET.sel=nil end
|
||||||
@@ -686,22 +765,18 @@ function WIDGET.release(x,y)
|
|||||||
W.lastTime=0
|
W.lastTime=0
|
||||||
WIDGET.drag(x,y)
|
WIDGET.drag(x,y)
|
||||||
end
|
end
|
||||||
WIDGET.sel=nil
|
|
||||||
end
|
end
|
||||||
function WIDGET.keyPressed(i)
|
function WIDGET.keyPressed(key)
|
||||||
if i=="space"or i=="return"then
|
if key=="space"or key=="return"then
|
||||||
if WIDGET.sel then
|
|
||||||
WIDGET.press()
|
WIDGET.press()
|
||||||
end
|
elseif kb.isDown("lshift","lalt","lctrl")and key=="left"or key=="right"then
|
||||||
elseif kb.isDown("lshift","lalt","lctrl")then
|
|
||||||
--When hold [↑], control slider with left/right
|
--When hold [↑], control slider with left/right
|
||||||
if i=="left"or i=="right"then
|
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if W then
|
if W then
|
||||||
if W.type=="slider"then
|
if W.type=="slider"then
|
||||||
local p=W.disp()
|
local p=W.disp()
|
||||||
local u=(W.smooth and .01 or 1)
|
local u=(W.smooth and .01 or 1)
|
||||||
local P=i=="left"and max(p-u,0)or min(p+u,W.unit)
|
local P=key=="left"and max(p-u,0)or min(p+u,W.unit)
|
||||||
if p==P or not P then return end
|
if p==P or not P then return end
|
||||||
W.code(P)
|
W.code(P)
|
||||||
if W.change and Timer()-W.lastTime>.18 then
|
if W.change and Timer()-W.lastTime>.18 then
|
||||||
@@ -710,7 +785,7 @@ function WIDGET.keyPressed(i)
|
|||||||
end
|
end
|
||||||
elseif W.type=="selector"then
|
elseif W.type=="selector"then
|
||||||
local s=W.select
|
local s=W.select
|
||||||
if i=="left"then
|
if key=="left"then
|
||||||
if s>1 then
|
if s>1 then
|
||||||
s=s-1
|
s=s-1
|
||||||
sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60)
|
sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60)
|
||||||
@@ -729,16 +804,15 @@ function WIDGET.keyPressed(i)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
elseif key=="up"or key=="down"or key=="left"or key=="right"then
|
||||||
elseif i=="up"or i=="down"or i=="left"or i=="right"then
|
|
||||||
if WIDGET.sel then
|
if WIDGET.sel then
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if W.getCenter then
|
if W.getCenter then
|
||||||
local WX,WY=W:getCenter()
|
local WX,WY=W:getCenter()
|
||||||
local dir=(i=="right"or i=="down")and 1 or -1
|
local dir=(key=="right"or key=="down")and 1 or -1
|
||||||
local tar
|
local tar
|
||||||
local minDist=1e99
|
local minDist=1e99
|
||||||
if i=="left"or i=="right"then
|
if key=="left"or key=="right"then
|
||||||
for i=1,#WIDGET.active do
|
for i=1,#WIDGET.active do
|
||||||
local W1=WIDGET.active[i]
|
local W1=WIDGET.active[i]
|
||||||
if W~=W1 and W1.resCtr then
|
if W~=W1 and W1.resCtr then
|
||||||
@@ -787,6 +861,25 @@ function WIDGET.keyPressed(i)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if WIDGET.sel and WIDGET.sel.type=="textBox"then
|
||||||
|
local t=WIDGET.sel.value
|
||||||
|
if key=="backspace"then
|
||||||
|
if #t>0 then
|
||||||
|
while t:byte(#t)>=128 and t:byte(#t)<192 do
|
||||||
|
t=sub(t,1,-2)
|
||||||
|
end
|
||||||
|
t=sub(t,1,-2)
|
||||||
|
SFX.play("lock")
|
||||||
|
end
|
||||||
|
elseif key=="delete"then
|
||||||
|
if #t>0 then
|
||||||
|
t=""
|
||||||
|
SFX.play("hold")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
WIDGET.sel.value=t
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local keyMirror={
|
local keyMirror={
|
||||||
@@ -799,9 +892,7 @@ local keyMirror={
|
|||||||
}
|
}
|
||||||
function WIDGET.gamepadPressed(i)
|
function WIDGET.gamepadPressed(i)
|
||||||
if i=="start"then
|
if i=="start"then
|
||||||
if WIDGET.sel then
|
|
||||||
WIDGET.press()
|
WIDGET.press()
|
||||||
end
|
|
||||||
elseif i=="a"or i=="b"then
|
elseif i=="a"or i=="b"then
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if W then
|
if W then
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ local newKey= WIDGET.newKey
|
|||||||
local newSwitch= WIDGET.newSwitch
|
local newSwitch= WIDGET.newSwitch
|
||||||
local newSlider= WIDGET.newSlider
|
local newSlider= WIDGET.newSlider
|
||||||
local newSelector= WIDGET.newSelector
|
local newSelector= WIDGET.newSelector
|
||||||
|
local newTextBox= WIDGET.newTextBox
|
||||||
|
|
||||||
--All widgets
|
--All widgets
|
||||||
local Widgets={
|
local Widgets={
|
||||||
@@ -658,6 +659,9 @@ local Widgets={
|
|||||||
},
|
},
|
||||||
login={
|
login={
|
||||||
newText({name="title", x=80,y=50,font=70,align="L"}),
|
newText({name="title", x=80,y=50,font=70,align="L"}),
|
||||||
|
newTextBox({name="username",x=400,y=200,w=500,h=60}),
|
||||||
|
newTextBox({name="password",x=400,y=300,w=626,h=60,secret=true}),
|
||||||
|
newTextBox({name="password2",x=400,y=400,w=626,h=60,secret=true}),
|
||||||
},
|
},
|
||||||
account={
|
account={
|
||||||
newText({name="title", x=80,y=50,font=70,align="L"}),
|
newText({name="title", x=80,y=50,font=70,align="L"}),
|
||||||
|
|||||||
1
main.lua
1
main.lua
@@ -19,7 +19,6 @@ LOGIN=false
|
|||||||
--Global Setting & Vars
|
--Global Setting & Vars
|
||||||
math.randomseed(os.time()*626)
|
math.randomseed(os.time()*626)
|
||||||
love.keyboard.setKeyRepeat(true)
|
love.keyboard.setKeyRepeat(true)
|
||||||
love.keyboard.setTextInput(false)
|
|
||||||
love.mouse.setVisible(false)
|
love.mouse.setVisible(false)
|
||||||
|
|
||||||
system=love.system.getOS()
|
system=love.system.getOS()
|
||||||
|
|||||||
Reference in New Issue
Block a user