From 97ace858afdae9fef1349e5417398f3858b721a0 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 19 Oct 2020 00:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E6=9C=AC=E6=A1=86?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=EF=BC=8C=E7=A9=BA=E9=97=B4=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E7=95=A5=E5=BE=AE=E4=BF=AE=E6=94=B9=E9=80=82=E9=85=8D=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 9 +- Zframework/languages.lua | 15 +++ Zframework/toolfunc.lua | 14 +++ Zframework/widget.lua | 195 ++++++++++++++++++++++++++++---------- Zframework/widgetList.lua | 4 + main.lua | 1 - 6 files changed, 184 insertions(+), 54 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index a7343f56..70db546b 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -171,7 +171,9 @@ function love.touchreleased(id,x,y) WIDGET.press(x,y) WIDGET.release(x,y) touching=nil - WIDGET.sel=nil + if WIDGET.sel and not WIDGET.sel.keepFocus then + WIDGET.sel=nil + end end if touchUp[SCN.cur]then touchUp[SCN.cur](id,x,y) @@ -253,6 +255,11 @@ function love.keyreleased(i) if SCN.swapping then return end if keyUp[SCN.cur]then keyUp[SCN.cur](i)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) joysticks[#joysticks+1]=JS diff --git a/Zframework/languages.lua b/Zframework/languages.lua index b1ac27b3..59cb953e 100644 --- a/Zframework/languages.lua +++ b/Zframework/languages.lua @@ -457,6 +457,9 @@ local langList={ }, login={ title="登录/注册", + username="用户名", + password="密码", + password2="确认密码", }, account={ title="账户", @@ -1044,6 +1047,9 @@ local langList={ }, login={ title="登录/注册", + username="用户名", + password="密码", + password2="确认密码", }, account={ title="账户", @@ -1621,6 +1627,9 @@ local langList={ }, login={ title="Log in / Sign up", + username="Username", + password="Password", + password2="Again Password", }, account={ title="Account", @@ -2212,6 +2221,9 @@ local langList={ }, login={ title="Log in / Sign up", + username="@", + password="*", + password2="*", }, account={ title="@_@", @@ -2796,6 +2808,9 @@ local langList={ }, login={ title="登录/注册", + username="用户名", + password="密码", + password2="你觉得应该填啥", }, account={ title="账户", diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index 5f42d38e..7e28df81 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -100,6 +100,20 @@ do--setFont 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 local tabs={ [0]="", diff --git a/Zframework/widget.lua b/Zframework/widget.lua index d835b504..f3be7b0a 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -2,6 +2,7 @@ local gc=love.graphics local kb=love.keyboard local int,abs=math.floor,math.abs local max,min=math.max,math.min +local sub=string.sub local format=string.format local color=color local setFont=setFont @@ -586,6 +587,86 @@ function WIDGET.newSelector(D) return _ 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 + x0 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.sel=nil--Selected widget function WIDGET.set(L) @@ -601,13 +682,15 @@ function WIDGET.set(L) end function WIDGET.moveCursor(x,y) - WIDGET.sel=nil for _,W in next,WIDGET.active do if not(W.hide and W.hide())and W.resCtr and W:isAbove(x,y)then WIDGET.sel=W return end end + if WIDGET.sel and not WIDGET.sel.keepFocus then + WIDGET.sel=nil + end end function WIDGET.press(x,y) local W=WIDGET.sel @@ -645,14 +728,10 @@ function WIDGET.press(x,y) SFX.play("prerotate") end end - elseif W.type=="keyboard"then - if x then - x,y=int((x-W.x)/W.w*15)+1,int((y-W.y)/W.h*5) - local k=keyboardKeys[15*y+x] - 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 + elseif W.type=="textBox"then + if system=="Android"then + local _,y=xOy:transformPoint(0,W.y+W.h) + kb.setTextInput(true,0,y,1,1) end end if W.hide and W.hide()then WIDGET.sel=nil end @@ -686,59 +765,54 @@ function WIDGET.release(x,y) W.lastTime=0 WIDGET.drag(x,y) end - WIDGET.sel=nil end -function WIDGET.keyPressed(i) - if i=="space"or i=="return"then - if WIDGET.sel then - WIDGET.press() - end - elseif kb.isDown("lshift","lalt","lctrl")then +function WIDGET.keyPressed(key) + if key=="space"or key=="return"then + WIDGET.press() + elseif kb.isDown("lshift","lalt","lctrl")and key=="left"or key=="right"then --When hold [↑], control slider with left/right - if i=="left"or i=="right"then - local W=WIDGET.sel - if W then - if W.type=="slider"then - local p=W.disp() - local u=(W.smooth and .01 or 1) - local P=i=="left"and max(p-u,0)or min(p+u,W.unit) - if p==P or not P then return end - W.code(P) - if W.change and Timer()-W.lastTime>.18 then - W.lastTime=Timer() - W.change() + local W=WIDGET.sel + if W then + if W.type=="slider"then + local p=W.disp() + local u=(W.smooth and .01 or 1) + local P=key=="left"and max(p-u,0)or min(p+u,W.unit) + if p==P or not P then return end + W.code(P) + if W.change and Timer()-W.lastTime>.18 then + W.lastTime=Timer() + W.change() + end + elseif W.type=="selector"then + local s=W.select + if key=="left"then + if s>1 then + s=s-1 + sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60) end - elseif W.type=="selector"then - local s=W.select - if i=="left"then - if s>1 then - s=s-1 - sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60) - end - else - if s<#W.list then - s=s+1 - sysFX.newShade(.3,1,1,1,W.x+W.w*.5,W.y,W.w*.5,60) - end - end - if W.select~=s then - W.code(W.list[s]) - W.select=s - W.selText=W.list[s] - SFX.play("prerotate") + else + if s<#W.list then + s=s+1 + sysFX.newShade(.3,1,1,1,W.x+W.w*.5,W.y,W.w*.5,60) end end + if W.select~=s then + W.code(W.list[s]) + W.select=s + W.selText=W.list[s] + SFX.play("prerotate") + end end end - elseif i=="up"or i=="down"or i=="left"or i=="right"then + elseif key=="up"or key=="down"or key=="left"or key=="right"then if WIDGET.sel then local W=WIDGET.sel if W.getCenter then 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 minDist=1e99 - if i=="left"or i=="right"then + if key=="left"or key=="right"then for i=1,#WIDGET.active do local W1=WIDGET.active[i] if W~=W1 and W1.resCtr then @@ -787,6 +861,25 @@ function WIDGET.keyPressed(i) 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 local keyMirror={ @@ -799,9 +892,7 @@ local keyMirror={ } function WIDGET.gamepadPressed(i) if i=="start"then - if WIDGET.sel then - WIDGET.press() - end + WIDGET.press() elseif i=="a"or i=="b"then local W=WIDGET.sel if W then diff --git a/Zframework/widgetList.lua b/Zframework/widgetList.lua index 869118fd..97c0ef52 100644 --- a/Zframework/widgetList.lua +++ b/Zframework/widgetList.lua @@ -125,6 +125,7 @@ local newKey= WIDGET.newKey local newSwitch= WIDGET.newSwitch local newSlider= WIDGET.newSlider local newSelector= WIDGET.newSelector +local newTextBox= WIDGET.newTextBox --All widgets local Widgets={ @@ -658,6 +659,9 @@ local Widgets={ }, login={ 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={ newText({name="title", x=80,y=50,font=70,align="L"}), diff --git a/main.lua b/main.lua index 4c2f64cb..60844da5 100644 --- a/main.lua +++ b/main.lua @@ -19,7 +19,6 @@ LOGIN=false --Global Setting & Vars math.randomseed(os.time()*626) love.keyboard.setKeyRepeat(true) -love.keyboard.setTextInput(false) love.mouse.setVisible(false) system=love.system.getOS()