升级控件模块,封装focus相关的几个静态方法
This commit is contained in:
@@ -190,7 +190,7 @@ function love.touchreleased(id,x,y)
|
|||||||
WIDGET.release(x,y)
|
WIDGET.release(x,y)
|
||||||
touching=false
|
touching=false
|
||||||
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
||||||
WIDGET.sel=false
|
WIDGET.unFocus()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if SCN.touchUp then SCN.touchUp(x,y)end
|
if SCN.touchUp then SCN.touchUp(x,y)end
|
||||||
@@ -214,7 +214,7 @@ local function noDevkeyPressed(key)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
|
elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
|
||||||
elseif key=="f5"then if WIDGET.sel then print(WIDGET.sel)end
|
elseif key=="f5"then print(WIDGET.isFocus()or"no widget selected")
|
||||||
elseif key=="f6"then for k,v in next,_G do print(k,v)end
|
elseif key=="f6"then for k,v in next,_G do print(k,v)end
|
||||||
elseif key=="f7"then if love._openConsole then love._openConsole()end
|
elseif key=="f7"then if love._openConsole then love._openConsole()end
|
||||||
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF")
|
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF")
|
||||||
@@ -224,8 +224,8 @@ local function noDevkeyPressed(key)
|
|||||||
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4")
|
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4")
|
||||||
elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
|
elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
|
||||||
elseif devMode==2 then
|
elseif devMode==2 then
|
||||||
if WIDGET.sel then
|
local W=WIDGET.sel
|
||||||
local W=WIDGET.sel
|
if W then
|
||||||
if key=="left"then W.x=W.x-10
|
if key=="left"then W.x=W.x-10
|
||||||
elseif key=="right"then W.x=W.x+10
|
elseif key=="right"then W.x=W.x+10
|
||||||
elseif key=="up"then W.y=W.y-10
|
elseif key=="up"then W.y=W.y-10
|
||||||
|
|||||||
@@ -1035,7 +1035,7 @@ WIDGET.indexMeta={
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
function WIDGET.set(list)
|
function WIDGET.set(list)
|
||||||
WIDGET.sel=false
|
WIDGET.unFocus()
|
||||||
WIDGET.active=list or NONE
|
WIDGET.active=list or NONE
|
||||||
|
|
||||||
--Reset all widgets
|
--Reset all widgets
|
||||||
@@ -1072,6 +1072,21 @@ function WIDGET.setLang(widgetText)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function WIDGET.isFocus(W)
|
||||||
|
return W==nil and WIDGET.sel or WIDGET.sel==W
|
||||||
|
end
|
||||||
|
function WIDGET.focus(W)
|
||||||
|
if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end
|
||||||
|
WIDGET.sel=W
|
||||||
|
if W and W.type=='inputBox'then
|
||||||
|
local _,y1=SCR.xOy:transformPoint(0,W.y+W.h)
|
||||||
|
kb.setTextInput(true,0,y1,1,1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function WIDGET.unFocus()
|
||||||
|
if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end
|
||||||
|
WIDGET.sel=false
|
||||||
|
end
|
||||||
|
|
||||||
function WIDGET.cursorMove(x,y)
|
function WIDGET.cursorMove(x,y)
|
||||||
for _,W in next,WIDGET.active do
|
for _,W in next,WIDGET.active do
|
||||||
@@ -1081,22 +1096,22 @@ function WIDGET.cursorMove(x,y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
||||||
WIDGET.sel=false
|
WIDGET.unFocus()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function WIDGET.press(x,y,k)
|
function WIDGET.press(x,y,k)
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if not W then return end
|
if not W then return end
|
||||||
W:press(x,y,k)
|
W:press(x,y,k)
|
||||||
if W.hide then WIDGET.sel=false end
|
if W.hide then WIDGET.unFocus()end
|
||||||
end
|
end
|
||||||
function WIDGET.drag(x,y,dx,dy)
|
function WIDGET.drag(x,y,dx,dy)
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if not W then return end
|
if not W then return end
|
||||||
if W.type=='slider'or W.type=='textBox'then
|
if W.type=='slider'or W.type=='textBox'then
|
||||||
W:drag(x,y,dx,dy)
|
W:drag(x,y,dx,dy)
|
||||||
elseif not W:isAbove(x,y)then
|
elseif not W:isAbove(x,y)and not WIDGET.sel.keepFocus then
|
||||||
WIDGET.sel=false
|
WIDGET.unFocus()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function WIDGET.release(x,y)
|
function WIDGET.release(x,y)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
local kb=love.keyboard
|
|
||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local gc_push,gc_pop=gc.push,gc.pop
|
local gc_push,gc_pop=gc.push,gc.pop
|
||||||
local gc_origin,gc_translate=gc.origin,gc.translate
|
local gc_origin,gc_translate=gc.origin,gc.translate
|
||||||
@@ -12,7 +11,6 @@ local SETTING,GAME,SCR=SETTING,GAME,SCR
|
|||||||
|
|
||||||
|
|
||||||
--System
|
--System
|
||||||
function enableTextInput()if not MOBILE then kb.setTextInput(true)end end
|
|
||||||
function switchFullscreen()
|
function switchFullscreen()
|
||||||
SETTING.fullscreen=not SETTING.fullscreen
|
SETTING.fullscreen=not SETTING.fullscreen
|
||||||
love.window.setFullscreen(SETTING.fullscreen)
|
love.window.setFullscreen(SETTING.fullscreen)
|
||||||
|
|||||||
@@ -505,8 +505,8 @@ function NET.updateWS_stream()
|
|||||||
netPLY.freshStreamConn(res.data.connected)
|
netPLY.freshStreamConn(res.data.connected)
|
||||||
elseif res.action==0 then--Game start
|
elseif res.action==0 then--Game start
|
||||||
NET.waitingStream=false
|
NET.waitingStream=false
|
||||||
if SCN.socketRead then SCN.socketRead('go',d)end
|
|
||||||
NET.roomInfo.start=true
|
NET.roomInfo.start=true
|
||||||
|
if SCN.socketRead then SCN.socketRead('go',d)end
|
||||||
elseif res.action==1 then--Game finished
|
elseif res.action==1 then--Game finished
|
||||||
--?
|
--?
|
||||||
elseif res.action==2 then--Player join
|
elseif res.action==2 then--Player join
|
||||||
|
|||||||
@@ -677,8 +677,7 @@ userG.the_box=first_box
|
|||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
TASK.new(function()WIDGET.focus(inputBox)end)
|
||||||
enableTextInput()
|
|
||||||
BG.set('none')
|
BG.set('none')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -780,13 +779,13 @@ function scene.keyDown(k)
|
|||||||
elseif combKey[k]and kb.isDown("lctrl","rctrl")then
|
elseif combKey[k]and kb.isDown("lctrl","rctrl")then
|
||||||
combKey[k]()
|
combKey[k]()
|
||||||
elseif k=="escape"then
|
elseif k=="escape"then
|
||||||
if WIDGET.sel~=inputBox then
|
if not WIDGET.isFocus(inputBox)then
|
||||||
WIDGET.sel=inputBox
|
WIDGET.focus(inputBox)
|
||||||
else
|
else
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if WIDGET.sel~=inputBox then WIDGET.sel=inputBox end
|
if not WIDGET.isFocus(inputBox)then WIDGET.focus(inputBox)end
|
||||||
WIDGET.keyPressed(k)
|
WIDGET.keyPressed(k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ function scene.sceneInit()
|
|||||||
scrollPos=0
|
scrollPos=0
|
||||||
|
|
||||||
lastSearch=false
|
lastSearch=false
|
||||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
TASK.new(function()YIELD()WIDGET.focus(inputBox)end)
|
||||||
enableTextInput()
|
|
||||||
BG.set('rainbow')
|
BG.set('rainbow')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ function scene.sceneInit()
|
|||||||
emailBox:setText(data[1])
|
emailBox:setText(data[1])
|
||||||
passwordBox:setText(data[2])
|
passwordBox:setText(data[2])
|
||||||
end
|
end
|
||||||
enableTextInput()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ function scene.mouseDown(x,y)
|
|||||||
end
|
end
|
||||||
scene.touchDown=scene.mouseDown
|
scene.touchDown=scene.mouseDown
|
||||||
local function testButton(n)
|
local function testButton(n)
|
||||||
if WIDGET.sel==scene.widgetList[n]then
|
if WIDGET.isFocus(scene.widgetList[n])then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
WIDGET.sel=scene.widgetList[n]
|
WIDGET.focus(scene.widgetList[n])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.keyDown(key)
|
function scene.keyDown(key)
|
||||||
@@ -121,7 +121,7 @@ function scene.update(dt)
|
|||||||
end
|
end
|
||||||
local L=scene.widgetList
|
local L=scene.widgetList
|
||||||
for i=1,8 do
|
for i=1,8 do
|
||||||
L[i].x=L[i].x*.9+(widgetX0[i]-400+(WIDGET.sel==L[i]and(i<5 and 100 or -100)or 0))*.1
|
L[i].x=L[i].x*.9+(widgetX0[i]-400+(WIDGET.isFocus(L[i])and(i<5 and 100 or -100)or 0))*.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ function scene.keyDown(key)
|
|||||||
if inputBox.hide then
|
if inputBox.hide then
|
||||||
textBox.hide=false
|
textBox.hide=false
|
||||||
inputBox.hide=false
|
inputBox.hide=false
|
||||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
TASK.new(function()YIELD()WIDGET.focus(inputBox)end)
|
||||||
enableTextInput()
|
|
||||||
else
|
else
|
||||||
local mes=STRING.trim(inputBox:getText())
|
local mes=STRING.trim(inputBox:getText())
|
||||||
if mes and #mes>0 then
|
if mes and #mes>0 then
|
||||||
@@ -98,12 +97,11 @@ function scene.keyDown(key)
|
|||||||
elseif #EDITING==0 then
|
elseif #EDITING==0 then
|
||||||
textBox.hide=true
|
textBox.hide=true
|
||||||
inputBox.hide=true
|
inputBox.hide=true
|
||||||
WIDGET.sel=nil
|
WIDGET.unFocus()
|
||||||
kb.setTextInput(false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif not inputBox.hide then
|
elseif not inputBox.hide then
|
||||||
WIDGET.sel=inputBox
|
WIDGET.focus(inputBox)
|
||||||
WIDGET.keyPressed(key)
|
WIDGET.keyPressed(key)
|
||||||
elseif playing then
|
elseif playing then
|
||||||
if not playing or noKey then return end
|
if not playing or noKey then return end
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ local function register()
|
|||||||
NET.register(username,email,password)
|
NET.register(username,email,password)
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.sceneInit()
|
|
||||||
enableTextInput()
|
|
||||||
end
|
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newText{name="title", x=80, y=50,font=70,align='L'},
|
WIDGET.newText{name="title", x=80, y=50,font=70,align='L'},
|
||||||
WIDGET.newButton{name="login", x=1140, y=100,w=170,h=80,color='lY',code=function()SCN.swapTo('login','swipeL')end},
|
WIDGET.newButton{name="login", x=1140, y=100,w=170,h=80,color='lY',code=function()SCN.swapTo('login','swipeL')end},
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ function scene.touchUp()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.touchMove(_,_,dx,dy)
|
function scene.touchMove(_,_,dx,dy)
|
||||||
if selected and not WIDGET.sel then
|
if selected and WIDGET.isFocus(false)then
|
||||||
local B=VK_org[selected]
|
local B=VK_org[selected]
|
||||||
B.x,B.y=B.x+dx,B.y+dy
|
B.x,B.y=B.x+dx,B.y+dy
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user