框架keyDown事件机制微调,重构框架主循环和控件相关代码

可以用键盘和手柄控制光标(手柄不完善)
整理代码和部分语言文件细节
This commit is contained in:
MrZ626
2021-11-27 23:16:21 +08:00
parent f6b4c1b109
commit b6c37a5c9f
21 changed files with 246 additions and 339 deletions

View File

@@ -16,10 +16,10 @@ end
scene.touchDown=scene.mouseDown
function scene.keyDown(key)
if key=='escape'then
SCN.back()
elseif key=='space'then
if key=='space'then
loadGame('stack_e',true)
else
return true
end
end

View File

@@ -229,7 +229,7 @@ scene.widgetList={
WIDGET.newKey{name='7',x=540,y=320,w=90,font=60,fText="7",code=pressKey'7'},
WIDGET.newKey{name='8',x=640,y=320,w=90,font=60,fText="8",code=pressKey'8'},
WIDGET.newKey{name='9',x=740,y=320,w=90,font=60,fText="9",code=pressKey'9'},
WIDGET.newButton{name='back',x=1200,y=660,w=110,h=60,font=60,fText=CHAR.icon.back,code=pressKey'escape'},
WIDGET.newButton{name='back',x=1200,y=660,w=110,h=60,font=60,fText=CHAR.icon.back,code=backScene},
}
return scene

View File

@@ -4,7 +4,7 @@ local ins,rem=table.insert,table.remove
local C=COLOR
local inputBox=WIDGET.newInputBox{name='input',x=40,y=650,w=1200,h=50,fType='mono'}
local outputBox=WIDGET.newTextBox{name='output',x=40,y=30,w=1200,h=610,font=25,fType='mono',lineH=25,fix=true}
local outputBox=WIDGET.newTextBox{name='output',x=40,y=30,w=1200,h=610,font=25,fType='mono',lineH=23,fix=true}
local function log(str)outputBox:push(str)end
log{C.lP,"Techmino Console"}
@@ -1088,8 +1088,8 @@ function scene.keyDown(key)
end
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=='pageup'then outputBox:scroll(-25)
elseif key=='pagedown'then outputBox:scroll(25)
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]()
@@ -1103,7 +1103,7 @@ function scene.keyDown(key)
if not WIDGET.isFocus(inputBox)then
WIDGET.focus(inputBox)
end
WIDGET.keyPressed(key)
return true
end
end

View File

@@ -234,7 +234,7 @@ function scene.draw()
end
scene.widgetList={
WIDGET.newButton{name='back',x=1140,y=60,w=170,h=80,font=60,fText=CHAR.icon.back,code=pressKey'escape'},
WIDGET.newButton{name='back',x=1140,y=60,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene},
}
return scene

View File

@@ -163,7 +163,7 @@ function scene.draw()
end
scene.widgetList={
WIDGET.newKey{name='back',x=1140,y=60,w=170,h=80,color='D',font=60,fText=CHAR.icon.back,code=pressKey'escape'},
WIDGET.newKey{name='back',x=1140,y=60,w=170,h=80,color='D',font=60,fText=CHAR.icon.back,code=backScene},
}
return scene

View File

@@ -32,44 +32,46 @@ function scene.sceneInit()
BGM.play(CUSTOMENV.bgm)
end
function scene.sceneBack()
saveFile(CUSTOMENV,'conf/customEnv')
BGM.play()
end
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'then
if CUSTOMENV.sequence=='fixed'then
MES.new('error',text.cc_fixed)
return
end
if CUSTOMENV.holdMode=='swap'then
MES.new('error',text.cc_swap)
return
end
local function _play(mode)
if CUSTOMENV.opponent~="X"then
if CUSTOMENV.opponent:sub(1,2)=='CC'then
if CUSTOMENV.sequence=='fixed'then
MES.new('error',text.cc_fixed)
return
end
if #BAG>0 then
for _=1,#BAG do
if BAG[_]>7 then
MES.new('error',text.ai_prebag)
return
end
end
end
if #MISSION>0 then
MES.new('error',text.ai_mission)
if CUSTOMENV.holdMode=='swap'then
MES.new('error',text.cc_swap)
return
end
end
if key=='return2'or kb.isDown('lalt','lctrl','lshift')then
if #FIELD[1]>0 then
saveFile(CUSTOMENV,'conf/customEnv')
loadGame('custom_puzzle',true)
if #BAG>0 then
for _=1,#BAG do
if BAG[_]>7 then
MES.new('error',text.ai_prebag)
return
end
end
else
saveFile(CUSTOMENV,'conf/customEnv')
loadGame('custom_clear',true)
end
if #MISSION>0 then
MES.new('error',text.ai_mission)
return
end
end
saveFile(CUSTOMENV,'conf/customEnv')
loadGame('custom_'..mode,true)
end
function scene.keyDown(key,isRep)
if isRep then return true end
if key=='return'and kb.isDown('lctrl','lalt')then
if kb.isDown('lalt')and #FIELD[1]>0 then
_play('puzzle')
elseif kb.isDown('lctrl')then
_play('clear')
end
elseif key=='f'then
SCN.go('custom_field','swipeD')
@@ -122,11 +124,8 @@ function scene.keyDown(key,isRep)
MES.new('check',text.importSuccess)
do return end
::THROW_fail::MES.new('error',text.dataCorrupted)
elseif key=='escape'then
saveFile(CUSTOMENV,'conf/customEnv')
SCN.back()
else
WIDGET.keyPressed(key)
return true
end
end

View File

@@ -124,8 +124,6 @@ function scene.keyDown(key)
inputBox:clear()
SFX.play('hold')
end
elseif key=='backspace'then
WIDGET.keyPressed("backspace")
elseif key=='escape'then
if inputBox:hasText()then
scene.keyDown('delete')
@@ -143,7 +141,7 @@ function scene.keyDown(key)
if not WIDGET.isFocus(inputBox)then
WIDGET.focus(inputBox)
end
WIDGET.keyPressed(key)
return true
end
end

View File

@@ -46,76 +46,9 @@ function scene.mouseDown(x,y)
end
end
scene.touchDown=scene.mouseDown
local function _testButton(n)
if NET.getlock('access_and_login')then
MES.new('warn',text.wsConnecting)
else
if WIDGET.isFocus(scene.widgetList[n])then
return true
else
WIDGET.focus(scene.widgetList[n])
end
end
end
function scene.keyDown(key,isRep)
if isRep then return end
if key=='1'then
if _testButton(1)then
SCN.go('mode')
end
elseif key=='q'then
if _testButton(2)then
loadGame(STAT.lastPlay,true)
end
elseif key=='a'then
if _testButton(3)then
if WS.status('app')=='running'then
NET.tryLogin(false)
elseif WS.status('app')=='dead'then
NET.wsconn_app()
SFX.play('connect')
MES.new('info',text.wsConnecting)
end
end
elseif key=='z'then
if _testButton(4)then
SCN.go('customGame')
end
elseif key=='-'then
if _testButton(5)then
SCN.go('setting_game')
end
elseif key=='p'then
if _testButton(6)then
SCN.go('stat')
end
elseif key=='l'then
if _testButton(7)then
SCN.go('dict')
end
elseif key==','then
if _testButton(8)then
SCN.go('replays')
end
elseif key=='2'then
if _testButton(9)then
SCN.go('music')
end
elseif key=='3'then
if _testButton(10)then
SCN.go('lang')
end
elseif key=='x'then
if _testButton(11)then
SCN.go('about')
end
elseif key=='m'then
if _testButton(12)then
SCN.go('manual')
end
elseif key=='c'then
enterConsole()
elseif key=='escape'then
if isRep then return true end
if key=='escape'then
if TIME()-lastQuitTime<1 then
VOC.play('bye')
SCN.swapTo('quit','slowFade')
@@ -123,6 +56,10 @@ function scene.keyDown(key,isRep)
lastQuitTime=TIME()
MES.new('warn',text.sureQuit)
end
elseif key=='c'then
enterConsole()
else
return true
end
end
@@ -183,21 +120,36 @@ function scene.draw()
end
end
local function notConn()
if NET.getlock('access_and_login')then
MES.new('warn',text.wsConnecting)
else
return true
end
end
scene.widgetList={
WIDGET.newButton{name='offline',x=-1200,y=210,w=800,h=100,color='lR',font=45,align='R',edge=30,code=pressKey'1'},
WIDGET.newButton{name='qplay', x=-1200,y=330,w=800,h=100,color='lM',font=40,align='R',edge=30,code=pressKey'q'},
WIDGET.newButton{name='online', x=-1200,y=450,w=800,h=100,color='lV',font=45,align='R',edge=30,code=pressKey'a'},
WIDGET.newButton{name='custom', x=-1200,y=570,w=800,h=100,color='lS',font=45,align='R',edge=30,code=pressKey'z'},
WIDGET.newButton{name='offline',x=-1200,y=210,w=800,h=100,color='lR',font=45,align='R',edge=30,code=function()if notConn()then SCN.go('mode')end end},
WIDGET.newButton{name='qplay', x=-1200,y=330,w=800,h=100,color='lM',font=40,align='R',edge=30,code=function()loadGame(STAT.lastPlay,true)end},
WIDGET.newButton{name='online', x=-1200,y=450,w=800,h=100,color='lV',font=45,align='R',edge=30,code=function()
if WS.status('app')=='running'then
NET.tryLogin(false)
elseif WS.status('app')=='dead'then
NET.wsconn_app()
SFX.play('connect')
MES.new('info',text.wsConnecting)
end
end},
WIDGET.newButton{name='custom', x=-1200,y=570,w=800,h=100,color='lS',font=45,align='R',edge=30,code=function()if notConn()then SCN.go('customGame')end end},
WIDGET.newButton{name='setting',x=2480,y=210,w=800,h=100, color='lO',font=40,align='L',edge=30,code=pressKey'-'},
WIDGET.newButton{name='stat', x=2480,y=330,w=800,h=100, color='lL',font=40,align='L',edge=30,code=pressKey'p'},
WIDGET.newButton{name='dict', x=2480,y=450,w=800,h=100, color='lG',font=40,align='L',edge=30,code=pressKey'l'},
WIDGET.newButton{name='replays',x=2480,y=570,w=800,h=100, color='lC',font=40,align='L',edge=30,code=pressKey','},
WIDGET.newButton{name='setting',x=2480,y=210,w=800,h=100, color='lO',font=40,align='L',edge=30,code=function()if notConn()then SCN.go('setting_game')end end},
WIDGET.newButton{name='stat', x=2480,y=330,w=800,h=100, color='lL',font=40,align='L',edge=30,code=function()if notConn()then SCN.go('stat')end end},
WIDGET.newButton{name='dict', x=2480,y=450,w=800,h=100, color='lG',font=40,align='L',edge=30,code=function()if notConn()then SCN.go('dict')end end},
WIDGET.newButton{name='replays',x=2480,y=570,w=800,h=100, color='lC',font=40,align='L',edge=30,code=function()if notConn()then SCN.go('replays')end end},
WIDGET.newButton{name='music', x=120,y=80,w=100, color='lO',code=pressKey'2',font=70,fText=CHAR.icon.music},
WIDGET.newButton{name='lang', x=280,y=80,w=100, color='lN',code=pressKey'3',font=70,fText=CHAR.icon.language},
WIDGET.newButton{name='about', x=-110,y=670,w=600,h=70, color='lB',align='R',edge=20,code=pressKey'x',font=50,fText=CHAR.icon.info},
WIDGET.newButton{name='manual', x=1390,y=670,w=600,h=70, color='lR',align='L',edge=20,code=pressKey'm',font=50,fText=CHAR.icon.help},
WIDGET.newButton{name='music', x=120,y=80,w=100, color='lO',code=function()if notConn()then SCN.go('music')end end,font=70,fText=CHAR.icon.music},
WIDGET.newButton{name='lang', x=280,y=80,w=100, color='lN',code=function()if notConn()then SCN.go('lang')end end,font=70,fText=CHAR.icon.language},
WIDGET.newButton{name='about', x=-110,y=670,w=600,h=70, color='lB',align='R',edge=20,code=function()if notConn()then SCN.go('about')end end,font=50,fText=CHAR.icon.info},
WIDGET.newButton{name='manual', x=1390,y=670,w=600,h=70, color='lR',align='L',edge=20,code=function()if notConn()then SCN.go('manual')end end,font=50,fText=CHAR.icon.help},
}
return scene

View File

@@ -53,16 +53,6 @@ function scene.sceneBack()
BGM.play()
end
function scene.keyDown(key)
if key=='return'then
_createRoom()
elseif key=='escape'then
SCN.back()
else
WIDGET.keyPressed(key)
end
end
scene.widgetScrollHeight=400
scene.widgetList={
WIDGET.newText{name='title',x=40,y=15,font=70,align='L'},
@@ -95,7 +85,7 @@ scene.widgetList={
--Capacity & Create & Back
WIDGET.newSelector{name='capacity', x=1070,y=330,w=310,color='lY',list={2,3,4,5,7,10,17,31,49,99},disp=ROOMval('capacity'),code=ROOMsto('capacity')},
WIDGET.newButton{name='create', x=1070,y=480,w=310,h=140,color='lN',font=40,code=pressKey'return'},
WIDGET.newButton{name='create', x=1070,y=480,w=310,h=140,color='lN',font=40,code=_createRoom},
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene},
--Special rules

View File

@@ -61,31 +61,21 @@ function scene.sceneInit()
end
function scene.keyDown(key)
if NET.getlock('enterRoom')then return end
if WIDGET.sel~=passwordBox then
if key=='r'then
if fetchTimer<=7 then
_fetchRoom()
end
elseif key=='s'then
SCN.go('setting_game')
elseif key=='n'then
SCN.go('net_newRoom')
elseif key=='escape'then
SCN.back()
elseif roomList:getLen()>0 and key=='return'then
local R=roomList:getSel()
if NET.getlock('fetchRoom')or not R then return end
if R.roomInfo.version==VERSION.room then
NET.enterRoom(R,passwordBox.value)
else
MES.new('error',text.versionNotMatch)
end
if NET.getlock('enterRoom')then return true end
if key=='r'then
if fetchTimer<=7 then
_fetchRoom()
end
elseif roomList:getLen()>0 and(key=='join'or key=='return'and love.keyboard.isDown('lctrl','rctrl'))then
local R=roomList:getSel()
if NET.getlock('fetchRoom')or not R then return end
if R.roomInfo.version==VERSION.room then
NET.enterRoom(R,passwordBox.value)
else
WIDGET.keyPressed(key)
MES.new('error',text.versionNotMatch)
end
else
WIDGET.keyPressed(key)
return true
end
end
@@ -144,12 +134,12 @@ end
scene.widgetList={
roomList,
passwordBox,
WIDGET.newKey{name='setting', x=1200,y=160,w=90,h=90,font=60,fText=CHAR.icon.settings,code=pressKey's'},
WIDGET.newKey{name='setting', x=1200,y=160,w=90,h=90,font=60,fText=CHAR.icon.settings,code=goScene'setting_game'},
WIDGET.newText{name='refreshing',x=450,y=240,font=45,hideF=function()return not NET.getlock('fetchRoom')end},
WIDGET.newText{name='noRoom', x=450,y=245,font=40,hideF=function()return roomList:getLen()>0 or NET.getlock('fetchRoom')end},
WIDGET.newKey{name='refresh', x=250,y=630,w=140,h=120,code=_fetchRoom,hideF=function()return fetchTimer>7 end},
WIDGET.newKey{name='new', x=510,y=630,w=260,h=120,code=pressKey'n'},
WIDGET.newKey{name='join', x=780,y=630,w=140,h=120,code=pressKey'return',hideF=function()return roomList:getLen()==0 or NET.getlock('enterRoom')end},
WIDGET.newKey{name='new', x=510,y=630,w=260,h=120,code=goScene'net_newRoom'},
WIDGET.newKey{name='join', x=780,y=630,w=140,h=120,code=pressKey'join',hideF=function()return roomList:getLen()==0 or NET.getlock('enterRoom')end},
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=pressKey'escape'},
}

View File

@@ -121,7 +121,7 @@ function scene.sceneBack()
end
function scene.keyDown(key,isRep)
if isRep then return end
if isRep then return true end
if key=='q'then
SCN.back()
GAME.playing=false
@@ -165,7 +165,7 @@ function scene.keyDown(key,isRep)
SYSFX.newShade(1.2,555,200,620,380,.6,.6,.6)
end
else
WIDGET.keyPressed(key)
return true
end
end

View File

@@ -137,10 +137,8 @@ function scene.keyDown(key)
MES.new('info',text.sureReset)
end
end
elseif key=='escape'then
SCN.back()
else
WIDGET.keyPressed(key)
return true
end
end

View File

@@ -31,7 +31,7 @@ local forbbidenKeys={
["return"]=true,
}
function scene.keyDown(key,isRep)
if isRep then return end
if isRep then return true end
if key=='escape'then
if selected then
selected=false
@@ -57,7 +57,7 @@ function scene.keyDown(key,isRep)
SFX.play('reach',.5)
end
else
WIDGET.keyPressed(key)
return true
end
end
function scene.gamepadDown(key)
@@ -80,14 +80,14 @@ function scene.gamepadDown(key)
selected=false
SFX.play('reach',.5)
else
WIDGET.gamepadPressed(key)
return true
end
end
function scene.draw()
setFont(20)
gc.setColor(COLOR.Z)
gc.printf(text.keySettingInstruction,540,620,500,'right')
gc.printf(text.keySettingInstruction,526,620,500,'right')
for i=0,20 do
for j=1,#keyList[i]do

View File

@@ -38,10 +38,10 @@ end
scene.touchDown=scene.mouseDown
function scene.keyDown(key)
if key=='escape'then
SCN.back()
elseif key=='space'then
if key=='space'then
scene.mouseDown(942,626)
else
return true
end
end

View File

@@ -31,12 +31,12 @@ end
scene.touchDown=scene.mouseDown
function scene.keyDown(key)
if key=='escape'then
SCN.back()
elseif key=='l'then
if key=='l'then
loadGame('sprintLock',true)
elseif key=='f'then
loadGame('sprintFix',true)
else
return true
end
end

View File

@@ -54,11 +54,11 @@ function scene.mouseDown(x,y)
end
end
scene.touchDown=scene.mouseDown
function scene.keyDown(key)
if key=='escape'then
SCN.back()
elseif love.keyboard.isDown('m')and love.keyboard.isDown('d')then
function scene.keyDown()
if love.keyboard.isDown('m')and love.keyboard.isDown('d')then
loadGame('sprintMD',true)
else
return true
end
end