房间内文本框操作更自然

This commit is contained in:
MrZ626
2021-05-16 02:55:25 +08:00
parent d246064ded
commit ffc09b0801
2 changed files with 7 additions and 8 deletions

View File

@@ -1076,6 +1076,7 @@ function WIDGET.isFocus(W)
return W==nil and WIDGET.sel or WIDGET.sel==W return W==nil and WIDGET.sel or WIDGET.sel==W
end end
function WIDGET.focus(W) function WIDGET.focus(W)
if WIDGET.sel==W then return end
if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end
WIDGET.sel=W WIDGET.sel=W
if W and W.type=='inputBox'then if W and W.type=='inputBox'then
@@ -1122,25 +1123,24 @@ function WIDGET.release(x,y)
end end
end end
function WIDGET.keyPressed(k) function WIDGET.keyPressed(k)
local W=WIDGET.sel
if k=="space"or k=="return"then if k=="space"or k=="return"then
WIDGET.press() WIDGET.press()
elseif kb.isDown("lshift","lalt","lctrl")and(k=="left"or k=="right")then elseif kb.isDown("lshift","lalt","lctrl")and(k=="left"or k=="right")then
--When hold [↑], control slider with left/right --When hold [↑], control slider with left/right
local W=WIDGET.sel
if W and W.type=='slider'or W.type=='selector'then if W and W.type=='slider'or W.type=='selector'then
W:arrowKey(k=="left") W:arrowKey(k=="left")
end end
elseif k=="up"or k=="down"or k=="left"or k=="right"then elseif k=="up"or k=="down"or k=="left"or k=="right"then
if not WIDGET.sel then if not W then
for _,W in next,WIDGET.active do for _,w in next,WIDGET.active do
if not W.hide and W.isAbove then if not w.hide and w.isAbove then
WIDGET.sel=W WIDGET.sel=w
return return
end end
end end
return return
end end
local W=WIDGET.sel
if not W.getCenter then return end if not W.getCenter then return end
local WX,WY=W:getCenter() local WX,WY=W:getCenter()
local dir=(k=="right"or k=="down")and 1 or -1 local dir=(k=="right"or k=="down")and 1 or -1
@@ -1169,7 +1169,6 @@ function WIDGET.keyPressed(k)
WIDGET.sel=tar WIDGET.sel=tar
end end
else else
local W=WIDGET.sel
if W and W.type=='inputBox'then if W and W.type=='inputBox'then
W:keypress(k) W:keypress(k)
end end

View File

@@ -102,7 +102,7 @@ function scene.keyDown(key)
end end
elseif not inputBox.hide then elseif not inputBox.hide then
WIDGET.focus(inputBox) WIDGET.focus(inputBox)
WIDGET.keyPressed(key) inputBox:keypress(key)
elseif playing then elseif playing then
if not playing or noKey then return end if not playing or noKey then return end
local k=keyMap.keyboard[key] local k=keyMap.keyboard[key]