控件模块/场景代码更好地响应系统长按

This commit is contained in:
MrZ626
2021-06-17 22:17:35 +08:00
parent 37a3e36bd5
commit e5a3b6c6ac
35 changed files with 143 additions and 165 deletions

View File

@@ -257,7 +257,7 @@ local function noDevkeyPressed(key)
return true
end
end
function love.keypressed(key)
function love.keypressed(key,_,isRep)
mouseShow=false
if devMode and not noDevkeyPressed(key)then
return
@@ -272,11 +272,13 @@ function love.keypressed(key)
end
elseif not SCN.swapping then
if SCN.keyDown then
if #EDITING==0 then SCN.keyDown(key)end
elseif key=="escape"then
if EDITING==""then
SCN.keyDown(key,isRep)
end
elseif key=="escape"and not isRep then
SCN.back()
else
WIDGET.keyPressed(key)
WIDGET.keyPressed(key,isRep)
end
end
end

View File

@@ -1150,9 +1150,9 @@ function WIDGET.release(x,y)
W:release(x,y+WIDGET.scrollPos)
end
end
function WIDGET.keyPressed(k)
function WIDGET.keyPressed(k,isRep)
local W=WIDGET.sel
if k=="space"or k=="return"then
if not isRep and(k=="space"or k=="return")then
WIDGET.press()
elseif kb.isDown("lshift","lalt","lctrl")and(k=="left"or k=="right")then
--When hold [↑], control slider with left/right

View File

@@ -134,7 +134,8 @@ local function tapBoard(x,y,key)
end
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="up"then
tapBoard(cx,cy-(revKB and 1 or -1),true)
elseif key=="down"then

View File

@@ -16,6 +16,7 @@ local startTime,time
local state,progress
local move
local autoPressing
local nextTile,nextCD
local nextPos,prevPos
local prevSpawnTime=0
@@ -232,10 +233,6 @@ function scene.sceneInit()
tapControl=false
startTime=0
reset()
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.mouseDown(x,y,k)
@@ -277,7 +274,9 @@ local function playRep(n)
repeater.focus=false
local move0=move
for i=1,#repeater.seq[n],3 do
autoPressing=true
scene.keyDown(arrows[repeater.seq[n]:sub(i,i+2)],true)
autoPressing=false
end
if move~=move0 then
if repeater.seq[n]~=repeater.last[n]then
@@ -289,7 +288,8 @@ local function playRep(n)
end
end
end
function scene.keyDown(key,auto)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="up"or key=="down"or key=="left"or key=="right"then
if repeater.focus then
local f=repeater.focus
@@ -311,7 +311,7 @@ function scene.keyDown(key,auto)
newTile()
TEXT.show(arrows[key],640,360,80,'beat',3)
move=move+1
if not auto then
if not autoPressing then
SFX.play('move')
end
end

View File

@@ -41,13 +41,10 @@ function scene.sceneInit()
startTime=0
time=0
state=0
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if #key==1 then
if state<2 and frameKeyCount<3 then
if key:upper():byte()==targetString:byte(progress)then

View File

@@ -15,23 +15,23 @@ function scene.sceneInit()
end
scene.mouseDown=NULL
function scene.keyDown(k)
if k:byte()>=48 and k:byte()<=57 then
function scene.keyDown(key)
if key:byte()>=48 and key:byte()<=57 then
if sym=="="then
val=k
val=key
sym=false
elseif sym and not reg then
reg=val
val=k
val=key
else
if #val<14 then
if val=="0"then val=""end
val=val..k
val=val..key
end
end
elseif k:sub(1,2)=="kp"then
scene.keyDown(k:sub(3))
elseif k=="."then
elseif key:sub(1,2)=="kp"then
scene.keyDown(key:sub(3))
elseif key=="."then
if not(val:find(".",nil,true)or val:find("e"))then
if sym and not reg then
reg=val
@@ -39,11 +39,11 @@ function scene.keyDown(k)
end
val=val.."."
end
elseif k=="e"then
elseif key=="e"then
if not val:find("e")then
val=val.."e"
end
elseif k=="backspace"then
elseif key=="backspace"then
if sym=="="then
val=""
elseif sym then
@@ -52,11 +52,11 @@ function scene.keyDown(k)
val=val:sub(1,-2)
end
if val==""then val="0"end
elseif k=="+"or k=="="and kb.isDown("lshift","rshift")then sym="+" reg=false
elseif k=="*"or k=="8"and kb.isDown("lshift","rshift")then sym="*" reg=false
elseif k=="-"then sym="-" reg=false
elseif k=="/"then sym="/" reg=false
elseif k=="return"then
elseif key=="+"or key=="="and kb.isDown("lshift","rshift")then sym="+" reg=false
elseif key=="*"or key=="8"and kb.isDown("lshift","rshift")then sym="*" reg=false
elseif key=="-"then sym="-" reg=false
elseif key=="/"then sym="/" reg=false
elseif key=="return"then
if val:byte(-1)==101 then val=val:sub(1,-2)end
if sym and reg then
if reg:byte(-1)==101 then reg=reg:sub(1,-2)end
@@ -69,13 +69,13 @@ function scene.keyDown(k)
end
sym="="
reg=false
elseif k=="escape"then
elseif key=="escape"then
if val~="0"then
val,reg,sym="0"
else
SCN.back()
end
elseif k=="delete"then
elseif key=="delete"then
val="0"
end
end

View File

@@ -15,13 +15,10 @@ function scene.sceneInit()
ex,ey=626,260
BG.set('matrix')
BGM.play('hang out')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="space"or key=="return"then
if state==0 then
state=1

View File

@@ -835,8 +835,8 @@ function scene.wheelMoved(_,y)
WHEELMOV(y,"scrollup","scrolldown")
end
function scene.keyDown(k)
if k=="return"then
function scene.keyDown(key)
if key=="return"then
local input=STRING.trim(inputBox:getText())
if input==""then return end
@@ -881,7 +881,7 @@ function scene.keyDown(k)
end
end
inputBox:clear()
elseif k=="up"then
elseif key=="up"then
if not hisPtr then
hisPtr=#history
if hisPtr>0 then
@@ -891,7 +891,7 @@ function scene.keyDown(k)
hisPtr=hisPtr-1
inputBox:setText(history[hisPtr])
end
elseif k=="down"then
elseif key=="down"then
if hisPtr then
hisPtr=hisPtr+1
if history[hisPtr]then
@@ -901,7 +901,7 @@ function scene.keyDown(k)
inputBox:clear()
end
end
elseif k=="tab"then
elseif key=="tab"then
local str=inputBox:getText()
if str~=""and not str:find("%s")then
local res={}
@@ -919,15 +919,15 @@ function scene.keyDown(k)
inputBox:setText(res[1])
end
end
elseif k=="scrollup"then outputBox:scroll(-5)
elseif k=="scrolldown"then outputBox:scroll(5)
elseif k=="pageup"then outputBox:scroll(-20)
elseif k=="pagedown"then outputBox:scroll(20)
elseif k=="home"then outputBox:scroll(-1e99)
elseif k=="end"then outputBox:scroll(1e99)
elseif combKey[k]and kb.isDown("lctrl","rctrl")then
combKey[k]()
elseif k=="escape"then
elseif key=="scrollup"then outputBox:scroll(-5)
elseif key=="scrolldown"then outputBox:scroll(5)
elseif key=="pageup"then outputBox:scroll(-20)
elseif key=="pagedown"then outputBox:scroll(20)
elseif key=="home"then outputBox:scroll(-1e99)
elseif key=="end"then outputBox:scroll(1e99)
elseif combKey[key]and kb.isDown("lctrl","rctrl")then
combKey[key]()
elseif key=="escape"then
if not WIDGET.isFocus(inputBox)then
WIDGET.focus(inputBox)
else
@@ -935,7 +935,7 @@ function scene.keyDown(k)
end
else
if not WIDGET.isFocus(inputBox)then WIDGET.focus(inputBox)end
WIDGET.keyPressed(k)
WIDGET.keyPressed(key)
end
end

View File

@@ -64,10 +64,6 @@ function scene.sceneInit()
gc.setLineJoin('bevel')
BGM.play('push')
BG.set('none')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.touchDown(x)
@@ -102,7 +98,8 @@ function scene.touchUp(x)
scene.keyDown("space")
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
SCN.back()
elseif play then

View File

@@ -34,13 +34,10 @@ function scene.sceneInit()
state='menu'
BGM.play('hang out')
BG.set('space')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="space"or key=="return"then
if state=='move'then
if floor>0 then

View File

@@ -108,10 +108,6 @@ function scene.sceneInit()
reset()
BG.set('gray')
BGM.play('way')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
local function touch(n)
@@ -153,7 +149,8 @@ local function touch(n)
SFX.play('clear_2')
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="r"then reset()
elseif key=="escape"then SCN.back()
elseif state~=2 then

View File

@@ -38,16 +38,13 @@ function scene.sceneInit()
end
BG.set('none')
BGM.play('dream')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.keyDown(k)
if k=="escape"then
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
SCN.back()
elseif k=="space"then
elseif key=="space"then
if state==0 then--main
if timer==0 then
state=1

View File

@@ -42,7 +42,8 @@ local function start()
vx=rnd()>.5 and 6 or -6
vy=rnd()*6-3
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="space"then
if state==0 then
start()

View File

@@ -17,13 +17,10 @@ end
function scene.sceneInit()
reset()
BG.set('none')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if state==0 then
if key=="space"then
reset()

View File

@@ -80,7 +80,8 @@ end
function scene.touchDown(x,y)
tapBoard(x,y)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="z"or key=="x"then
love.mousepressed(ms.getPosition())
elseif key=="space"then

View File

@@ -14,13 +14,10 @@ function scene.sceneInit()
keyTime={}for i=1,40 do keyTime[i]=-1e99 end
BG.set('gray')
BGM.play('push')
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
SCN.back()
else

View File

@@ -122,7 +122,8 @@ local function merge()
failPos=cy*10+cx
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="up"or key=="down"or key=="left"or key=="right"then
if state==2 then return end
if not cx then

View File

@@ -47,7 +47,8 @@ function scene.sceneBack()
BGM.play()
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="return"or key=="return2"then
if CUSTOMENV.opponent~="X"then
if CUSTOMENV.opponent:sub(1,2)=='CC'and CUSTOMENV.sequence=="fixed"then

View File

@@ -110,6 +110,8 @@ function scene.keyDown(key)
else
SCN.back()
end
else
return
end
url=getList()[selected][5]
end

View File

@@ -8,7 +8,6 @@ local touchMoveLastFrame=false
local scene={}
function scene.sceneInit()
love.keyboard.setKeyRepeat(false)
if GAME.init then
resetGameData()
GAME.init=false
@@ -17,7 +16,6 @@ function scene.sceneInit()
noTouch=not SETTING.VKSwitch or noKey
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
destroyPlayers()
end
@@ -68,7 +66,8 @@ function scene.touchMove()
::CONTINUE_nextKey::
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
local k=keyMap.keyboard[key]
if k then
if k>0 then

View File

@@ -8,16 +8,16 @@ end
function scene.wheelMoved(_,y)
WHEELMOV(y)
end
function scene.keyDown(k)
if k=="up"then
function scene.keyDown(key)
if key=="up"then
WIDGET.active.texts:scroll(-5)
elseif k=="down"then
elseif key=="down"then
WIDGET.active.texts:scroll(5)
elseif k=="pageup"then
elseif key=="pageup"then
WIDGET.active.texts:scroll(-20)
elseif k=="pagedown"then
elseif key=="pagedown"then
WIDGET.active.texts:scroll(20)
elseif k=="escape"then
elseif key=="escape"then
SCN.back()
end
end

View File

@@ -19,7 +19,8 @@ end
function scene.touchDown()
scene.mouseDown()
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
VOC.play('bye')
SCN.swapTo('quit','slowFade')

View File

@@ -1,4 +1,4 @@
local gc,kb=love.graphics,love.keyboard
local gc=love.graphics
local scene={}
@@ -212,13 +212,13 @@ function scene.sceneInit()
shadePhase2=6.26*math.random()
skip=0--Skip time
light[6*3],light[26*3]=true,true
kb.setKeyRepeat(false)
end
function scene.sceneBack()
love.event.quit()
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
SCN.back()
elseif key=="s"then
@@ -252,7 +252,6 @@ function scene.update(dt)
end
if openTime>=3.26 and not SCN.swapping then
SCN.swapTo('intro')
love.keyboard.setKeyRepeat(true)
end
end
end

View File

@@ -52,7 +52,8 @@ local function testButton(n)
WIDGET.focus(scene.widgetList[n])
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="1"then
if testButton(1)then
SCN.go('mode')

View File

@@ -8,16 +8,16 @@ end
function scene.wheelMoved(_,y)
WHEELMOV(y)
end
function scene.keyDown(k)
if k=="up"then
function scene.keyDown(key)
if key=="up"then
WIDGET.active.texts:scroll(-5)
elseif k=="down"then
elseif key=="down"then
WIDGET.active.texts:scroll(5)
elseif k=="pageup"then
elseif key=="pageup"then
WIDGET.active.texts:scroll(-20)
elseif k=="pagedown"then
elseif key=="pagedown"then
WIDGET.active.texts:scroll(20)
elseif k=="escape"then
elseif key=="escape"then
SCN.back()
end
end

View File

@@ -120,7 +120,8 @@ end
function scene.touchClick(x,y)
scene.mouseClick(x,y)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="return"then
if mapCam.sel then
mapCam.keyCtrl=false

View File

@@ -30,7 +30,7 @@ end
function scene.wheelMoved(_,y)
WHEELMOV(y)
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
local S=selected
if key=="down"then
if S<#bgmList then
@@ -42,17 +42,19 @@ function scene.keyDown(key)
selected=S-1
SFX.play('move',.7)
end
elseif key=="return"or key=="space"then
if BGM.nowPlay~=bgmList[S]then
BGM.play(bgmList[S])
if SETTING.bgm>0 then SFX.play('click')end
else
BGM.stop()
elseif not isRep then
if key=="return"or key=="space"then
if BGM.nowPlay~=bgmList[S]then
BGM.play(bgmList[S])
if SETTING.bgm>0 then SFX.play('click')end
else
BGM.stop()
end
elseif key=="tab"then
SCN.swapTo('sound','none')
elseif key=="escape"then
SCN.back()
end
elseif key=="tab"then
SCN.swapTo('sound','none')
elseif key=="escape"then
SCN.back()
end
end

View File

@@ -73,9 +73,6 @@ function scene.sceneInit(org)
NET.specSRID=false
end
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
end
scene.mouseDown=NULL
function scene.mouseMove(x,y)netPLY.mouseMove(x,y)end
@@ -120,22 +117,18 @@ function scene.touchMove()
::CONTINUE_nextKey::
end
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if key=="escape"then
if not inputBox.hide then
scene.keyDown("switchChat")
_switchChat()
else
_quit()
end
elseif key=="return"then
local mes=STRING.trim(inputBox:getText())
if not inputBox.hide then
if #mes>0 then
NET.sendMessage(mes)
inputBox:clear()
else
_switchChat()
end
if not inputBox.hide and #mes>0 then
NET.sendMessage(mes)
inputBox:clear()
else
_switchChat()
end
@@ -143,7 +136,7 @@ function scene.keyDown(key)
WIDGET.focus(inputBox)
inputBox:keypress(key)
elseif playing then
if noKey then return end
if noKey or isRep then return end
local k=keyMap.keyboard[key]
if k and k>0 then
PLAYERS[1]:pressKey(k)
@@ -214,7 +207,6 @@ function scene.socketRead(cmd,d)
elseif cmd=='go'then
if not playing then
playing=true
love.keyboard.setKeyRepeat(false)
lastUpstreamTime=0
upstreamProgress=1
resetGameData('n',NET.seed)

View File

@@ -42,13 +42,13 @@ function scene.sceneBack()
BGM.play()
end
function scene.keyDown(k)
if k=="return"then
function scene.keyDown(key)
if key=="return"then
createRoom()
elseif k=="escape"then
elseif key=="escape"then
SCN.back()
else
WIDGET.keyPressed(k)
WIDGET.keyPressed(key)
end
end

View File

@@ -36,29 +36,29 @@ end
function scene.wheelMoved(_,y)
scrollPos=max(0,min(scrollPos-y,#NET.roomList-10))
end
function scene.keyDown(k)
if k=="r"then
function scene.keyDown(key)
if key=="r"then
if fetchTimer<=7 then
fetchRoom()
end
elseif k=="s"then
elseif key=="s"then
SCN.go('setting_game')
elseif k=="n"then
elseif key=="n"then
SCN.go('net_newRoom')
elseif k=="escape"then
elseif key=="escape"then
SCN.back()
elseif #NET.roomList>0 then
if k=="down"then
if key=="down"then
if selected<#NET.roomList then
selected=selected+1
scrollPos=max(selected-10,min(scrollPos,selected-1))
end
elseif k=="up"then
elseif key=="up"then
if selected>1 then
selected=selected-1
scrollPos=max(selected-10,min(scrollPos,selected-1))
end
elseif k=="return"then
elseif key=="return"then
if NET.getlock('fetchRoom')or not NET.roomList[selected]then return end
local R=NET.roomList[selected]
if R.roomInfo.version~=VERSION.short then MES.new('error',"Version doesn't match")return end

View File

@@ -119,12 +119,12 @@ function scene.sceneInit(org)
end
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
STAT.todayTime=STAT.todayTime+PLAYERS[1].stat.time
trySave()
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="q"then
SCN.back()
elseif key=="escape"then

View File

@@ -30,7 +30,8 @@ local forbbidenKeys={
["\\"]=true,
["return"]=true,
}
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
if selected then
for k,v in next,keyMap.keyboard do

View File

@@ -8,7 +8,8 @@ end
local blockName={'z','s','j','l','t','o','i'}
local lineCount={'single','double','triple','techrash'}
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
if key=="1"then
mini=not mini
elseif key=="2"then

View File

@@ -33,13 +33,14 @@ function scene.touchDown(x,y)
scene.mouseDown(x,y)
end
function scene.keyDown(k)
if k=="escape"then
function scene.keyDown(key,isRep)
if isRep then return end
if key=="escape"then
SCN.back()
else
if k=="l"then
if key=="l"then
loadGame('sprintLock',true)
elseif k=="f"then
elseif key=="f"then
loadGame('sprintFix',true)
end
end

View File

@@ -14,12 +14,6 @@ function scene.sceneInit()
backCounter=5
list={}
timer=0
love.keyboard.setKeyRepeat(false)
end
function scene.sceneBack()
list={}
love.keyboard.setKeyRepeat(true)
end
function scene.gamepadDown(key)
@@ -28,7 +22,8 @@ end
function scene.gamepadUp(key)
push{COLOR.H,"[gamepadUp] <"..key..">"}
end
function scene.keyDown(key)
function scene.keyDown(key,isRep)
if isRep then return end
push("[keyDown] <"..key..">")
if key=="escape"then
backCounter=backCounter-1