diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index af4255d5..1ac4d257 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -15,6 +15,18 @@ local playSFX=SFX.play --System +do--function tryBackScene() + local sureQuitTime=-1e99 + function tryBack() + if TIME()-sureQuitTime<1 then + sureQuitTime=-1e99 + SCN.back() + else + sureQuitTime=TIME() + MES.new('warn',text.sureQuit) + end + end +end do--function loadFile(name,args), function saveFile(data,name,args) local t=setmetatable({},{__index=function()return"'$1' loading failed: $2"end}) function loadFile(name,args) diff --git a/parts/scenes/app_2048.lua b/parts/scenes/app_2048.lua index 9b87a52f..530beb8d 100644 --- a/parts/scenes/app_2048.lua +++ b/parts/scenes/app_2048.lua @@ -331,7 +331,7 @@ function scene.keyDown(key,isRep) elseif key=='escape'then if repeater.focus then repeater.focus=false - else + elseif tryBack()then SCN.back() end end diff --git a/parts/scenes/app_arithmetic.lua b/parts/scenes/app_arithmetic.lua index 8670bbb9..cb6f6d8b 100644 --- a/parts/scenes/app_arithmetic.lua +++ b/parts/scenes/app_arithmetic.lua @@ -185,7 +185,9 @@ function scene.keyDown(key,isRep) elseif key=='r'then reset() elseif key=='escape'then - SCN.back() + if tryBack()then + SCN.back() + end end end diff --git a/parts/scenes/app_cannon.lua b/parts/scenes/app_cannon.lua index 5d88fa68..a4f7b668 100644 --- a/parts/scenes/app_cannon.lua +++ b/parts/scenes/app_cannon.lua @@ -28,7 +28,9 @@ function scene.keyDown(key,isRep) vy=pow*sin(ang)/2.6 end elseif key=='escape'then - SCN.back() + if tryBack()then + SCN.back() + end end end function scene.mouseDown(_,_,k) diff --git a/parts/scenes/app_dropper.lua b/parts/scenes/app_dropper.lua index cae2d2f6..72ee0a07 100644 --- a/parts/scenes/app_dropper.lua +++ b/parts/scenes/app_dropper.lua @@ -62,7 +62,9 @@ function scene.keyDown(key,isRep) state='move' end elseif key=='escape'then - SCN.back() + if tryBack()then + SCN.back() + end end end function scene.mouseDown(_,_,k) diff --git a/parts/scenes/app_link.lua b/parts/scenes/app_link.lua index 426b5dda..3b380bba 100644 --- a/parts/scenes/app_link.lua +++ b/parts/scenes/app_link.lua @@ -262,11 +262,12 @@ function scene.keyDown(key,isRep) elseif key=='z'or key=='x'then love.mousepressed(ms.getPosition()) elseif key=='escape'then - if state~=1 or sure>.2 then - SCN.back() + if state~=1 then + if tryBack()then + SCN.back() + end else sure=1 - MES.new('info',"Press again") end elseif state==0 then if key=='q'then diff --git a/parts/scenes/app_memorize.lua b/parts/scenes/app_memorize.lua index f86f33ef..f54b0a96 100644 --- a/parts/scenes/app_memorize.lua +++ b/parts/scenes/app_memorize.lua @@ -41,7 +41,9 @@ end function scene.keyDown(key,isRep) if isRep then return end if key=='escape'then - SCN.back() + if tryBack()then + SCN.back() + end elseif key=='r'then _reset() elseif state==0 then diff --git a/parts/scenes/app_polyforge.lua b/parts/scenes/app_polyforge.lua index a4d1f358..43f5f343 100644 --- a/parts/scenes/app_polyforge.lua +++ b/parts/scenes/app_polyforge.lua @@ -45,7 +45,9 @@ end function scene.keyDown(key,isRep) if isRep then return end if key=='escape'then - SCN.back() + if tryBack()then + SCN.back() + end elseif key=='space'then if state==0 then--main if timer==0 then diff --git a/parts/scenes/app_ten.lua b/parts/scenes/app_ten.lua index e5098653..2afb35a4 100644 --- a/parts/scenes/app_ten.lua +++ b/parts/scenes/app_ten.lua @@ -109,11 +109,11 @@ local function merge() end if chosen>=5 then SFX.play( - chosen>=9 and"ren_mega"or - chosen>=8 and"spin_3"or - chosen>=7 and"spin_2"or - chosen>=6 and"spin_1"or - "spin_0" + chosen>=9 and'ren_mega'or + chosen>=8 and'spin_3'or + chosen>=7 and'spin_2'or + chosen>=6 and'spin_1'or + 'spin_0' ) end fallingTimer=fast and 8 or 12 @@ -157,7 +157,9 @@ function scene.keyDown(key,isRep) fast=not fast end elseif key=='escape'then - SCN.back() + if tryBack()then + SCN.back() + end end end function scene.mouseMove(x,y) diff --git a/parts/scenes/main.lua b/parts/scenes/main.lua index 4bbc352d..539d346f 100644 --- a/parts/scenes/main.lua +++ b/parts/scenes/main.lua @@ -116,12 +116,9 @@ function scene.keyDown(key,isRep) elseif key=='c'then enterConsole() elseif key=='escape'then - if TIME()-lastQuitTime<1 then + if tryBack()then VOC.play('bye') SCN.swapTo('quit','slowFade') - else - lastQuitTime=TIME() - MES.new('warn',text.sureQuit) end elseif key=='c'then enterConsole() diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index 35a36acb..d190d33e 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -16,7 +16,6 @@ local inputBox=WIDGET.newInputBox{name='input',x=340,y=660,w=600,h=50,limit=256} local playing local lastUpstreamTime local upstreamProgress -local lastBackTime=0 local noTouch,noKey=false,false local touchMoveLastFrame=false local newMessageTimer @@ -36,15 +35,12 @@ local function _gotoSetting() SCN.go('setting_game') end local function _quit() - if TIME()-lastBackTime<1 then + if tryBack()then NET.signal_quit() if SCN.stack[#SCN.stack-1]=='net_newRoom'then SCN.pop() end SCN.back() - else - lastBackTime=TIME() - MES.new('info',text.sureQuit) end end local function _switchChat() diff --git a/parts/scenes/net_menu.lua b/parts/scenes/net_menu.lua index 670c3f23..6a29c614 100644 --- a/parts/scenes/net_menu.lua +++ b/parts/scenes/net_menu.lua @@ -1,9 +1,6 @@ -local lastLogoutTime - local scene={} function scene.sceneInit() - lastLogoutTime=-1e99 BG.set() end function scene.sceneBack() @@ -22,7 +19,7 @@ scene.widgetList={ WIDGET.newButton{name='rooms', x=640, y=540,w=350,h=120,font=40,code=goScene'net_rooms'}, WIDGET.newButton{name='logout',x=880, y=40,w=180, h=60,color='dR', code=function() - if TIME()-lastLogoutTime<1 then + if tryBack()then if USER.uid then NET.wsclose_play() NET.wsclose_user() @@ -31,9 +28,6 @@ scene.widgetList={ saveFile(USER,'conf/user') SCN.back() end - else - MES.new('info',text.sureQuit) - lastLogoutTime=TIME() end end}, WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene},