整理代码,返回需要二次确认的小程序统一用一个函数
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user