升级控件模块,封装focus相关的几个静态方法
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
local kb=love.keyboard
|
||||
local gc=love.graphics
|
||||
local gc_push,gc_pop=gc.push,gc.pop
|
||||
local gc_origin,gc_translate=gc.origin,gc.translate
|
||||
@@ -12,7 +11,6 @@ local SETTING,GAME,SCR=SETTING,GAME,SCR
|
||||
|
||||
|
||||
--System
|
||||
function enableTextInput()if not MOBILE then kb.setTextInput(true)end end
|
||||
function switchFullscreen()
|
||||
SETTING.fullscreen=not SETTING.fullscreen
|
||||
love.window.setFullscreen(SETTING.fullscreen)
|
||||
|
||||
@@ -505,8 +505,8 @@ function NET.updateWS_stream()
|
||||
netPLY.freshStreamConn(res.data.connected)
|
||||
elseif res.action==0 then--Game start
|
||||
NET.waitingStream=false
|
||||
if SCN.socketRead then SCN.socketRead('go',d)end
|
||||
NET.roomInfo.start=true
|
||||
if SCN.socketRead then SCN.socketRead('go',d)end
|
||||
elseif res.action==1 then--Game finished
|
||||
--?
|
||||
elseif res.action==2 then--Player join
|
||||
|
||||
@@ -677,8 +677,7 @@ userG.the_box=first_box
|
||||
local scene={}
|
||||
|
||||
function scene.sceneInit()
|
||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
||||
enableTextInput()
|
||||
TASK.new(function()WIDGET.focus(inputBox)end)
|
||||
BG.set('none')
|
||||
end
|
||||
|
||||
@@ -780,13 +779,13 @@ function scene.keyDown(k)
|
||||
elseif combKey[k]and kb.isDown("lctrl","rctrl")then
|
||||
combKey[k]()
|
||||
elseif k=="escape"then
|
||||
if WIDGET.sel~=inputBox then
|
||||
WIDGET.sel=inputBox
|
||||
if not WIDGET.isFocus(inputBox)then
|
||||
WIDGET.focus(inputBox)
|
||||
else
|
||||
SCN.back()
|
||||
end
|
||||
else
|
||||
if WIDGET.sel~=inputBox then WIDGET.sel=inputBox end
|
||||
if not WIDGET.isFocus(inputBox)then WIDGET.focus(inputBox)end
|
||||
WIDGET.keyPressed(k)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,8 +68,7 @@ function scene.sceneInit()
|
||||
scrollPos=0
|
||||
|
||||
lastSearch=false
|
||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
||||
enableTextInput()
|
||||
TASK.new(function()YIELD()WIDGET.focus(inputBox)end)
|
||||
BG.set('rainbow')
|
||||
end
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ function scene.sceneInit()
|
||||
emailBox:setText(data[1])
|
||||
passwordBox:setText(data[2])
|
||||
end
|
||||
enableTextInput()
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
|
||||
@@ -46,10 +46,10 @@ function scene.mouseDown(x,y)
|
||||
end
|
||||
scene.touchDown=scene.mouseDown
|
||||
local function testButton(n)
|
||||
if WIDGET.sel==scene.widgetList[n]then
|
||||
if WIDGET.isFocus(scene.widgetList[n])then
|
||||
return true
|
||||
else
|
||||
WIDGET.sel=scene.widgetList[n]
|
||||
WIDGET.focus(scene.widgetList[n])
|
||||
end
|
||||
end
|
||||
function scene.keyDown(key)
|
||||
@@ -121,7 +121,7 @@ function scene.update(dt)
|
||||
end
|
||||
local L=scene.widgetList
|
||||
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
|
||||
|
||||
|
||||
@@ -88,8 +88,7 @@ function scene.keyDown(key)
|
||||
if inputBox.hide then
|
||||
textBox.hide=false
|
||||
inputBox.hide=false
|
||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
||||
enableTextInput()
|
||||
TASK.new(function()YIELD()WIDGET.focus(inputBox)end)
|
||||
else
|
||||
local mes=STRING.trim(inputBox:getText())
|
||||
if mes and #mes>0 then
|
||||
@@ -98,12 +97,11 @@ function scene.keyDown(key)
|
||||
elseif #EDITING==0 then
|
||||
textBox.hide=true
|
||||
inputBox.hide=true
|
||||
WIDGET.sel=nil
|
||||
kb.setTextInput(false)
|
||||
WIDGET.unFocus()
|
||||
end
|
||||
end
|
||||
elseif not inputBox.hide then
|
||||
WIDGET.sel=inputBox
|
||||
WIDGET.focus(inputBox)
|
||||
WIDGET.keyPressed(key)
|
||||
elseif playing then
|
||||
if not playing or noKey then return end
|
||||
|
||||
@@ -17,10 +17,6 @@ local function register()
|
||||
NET.register(username,email,password)
|
||||
end
|
||||
|
||||
function scene.sceneInit()
|
||||
enableTextInput()
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
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},
|
||||
|
||||
@@ -76,7 +76,7 @@ function scene.touchUp()
|
||||
end
|
||||
end
|
||||
function scene.touchMove(_,_,dx,dy)
|
||||
if selected and not WIDGET.sel then
|
||||
if selected and WIDGET.isFocus(false)then
|
||||
local B=VK_org[selected]
|
||||
B.x,B.y=B.x+dx,B.y+dy
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user