修复键盘控制滑条或者选择器时报错

This commit is contained in:
MrZ626
2021-07-08 02:00:56 +08:00
parent f3994316e3
commit 7b227181f2

View File

@@ -558,7 +558,7 @@ function slider:scroll(n)
end
end
function slider:arrowKey(k)
self:scroll(k=="left"or k=="up"and -1 or 1)
self:scroll((k=="left"or k=="up")and -1 or 1)
end
function WIDGET.newSlider(D)--name,x,y,w[,fText][,color][,unit][,smooth][,font=30][,change],disp,code,hide
local _={
@@ -713,11 +713,12 @@ function selector:press(x)
end
function selector:scroll(n)
local s=self.select
if n==-1 and s==1 or not n and s==#self.list then return end
if n==-1 then
if s==1 then return end
s=s-1
SYSFX.newShade(3,self.x,self.y-WIDGET.scrollPos,self.w*.5,60)
else
if s==#self.list then return end
s=s+1
SYSFX.newShade(3,self.x+self.w*.5,self.y-WIDGET.scrollPos,self.w*.5,60)
end
@@ -727,7 +728,7 @@ function selector:scroll(n)
if self.sound then SFX.play('prerotate')end
end
function selector:arrowKey(k)
self:scroll(k=="left"or k=="up"and -1 or 1)
self:scroll((k=="left"or k=="up")and -1 or 1)
end
function WIDGET.newSelector(D)--name,x,y,w[,fText][,color][,sound=true],list,disp,code,hide
@@ -1333,10 +1334,11 @@ function WIDGET.keyPressed(k,isRep)
if not isRep then
WIDGET.press()
end
elseif kb.isDown("lshift","lalt","lctrl")then
elseif k=="up"or k=="down"or k=="left"or k=="right"then
if kb.isDown("lshift","lalt","lctrl")then
--Control some widgets with arrowkeys when hold shift/ctrl/alt
if W and W.arrowKey then W:arrowKey(k)end
elseif k=="up"or k=="down"or k=="left"or k=="right"then
else
if not W then
for _,w in next,WIDGET.active do
if not w.hide and w.isAbove then
@@ -1372,6 +1374,7 @@ function WIDGET.keyPressed(k,isRep)
WIDGET.focus(tar)
end
end
end
else
if W and W.keypress then
W:keypress(k)