Zframework的控件/场景/文本/任务模块支持基于时间更新
修改几处其他地方基于时间update
This commit is contained in:
@@ -616,14 +616,14 @@ function love.run()
|
||||
STEP()
|
||||
VOC.update()
|
||||
BG.update(dt)
|
||||
TEXT_update()
|
||||
TEXT_update(dt)
|
||||
MES_update(dt)
|
||||
WS_update(dt)
|
||||
TASK_update()
|
||||
TASK_update(dt)
|
||||
SYSFX_update(dt)
|
||||
if SCN.update then SCN.update(dt)end
|
||||
if SCN.swapping then SCN.swapUpdate()end
|
||||
WIDGET_update()
|
||||
if SCN.swapping then SCN.swapUpdate(dt)end
|
||||
WIDGET_update(dt)
|
||||
|
||||
--DRAW
|
||||
if not MINI()then
|
||||
|
||||
@@ -46,14 +46,14 @@ function SCN.add(name,scene)
|
||||
end
|
||||
end
|
||||
|
||||
function SCN.swapUpdate()
|
||||
function SCN.swapUpdate(dt)
|
||||
local S=SCN.stat
|
||||
S.time=S.time-1
|
||||
if S.time==S.changeTime then
|
||||
--Scene swapped this moment
|
||||
S.time=S.time-dt
|
||||
if S.time<S.changeTime and S.time+dt>=S.changeTime then
|
||||
--Scene swapped this frame
|
||||
SCN.init(S.tar,SCN.cur)
|
||||
end
|
||||
if S.time==0 then
|
||||
if S.time<0 then
|
||||
SCN.swapping=false
|
||||
end
|
||||
end
|
||||
@@ -103,41 +103,65 @@ function SCN.pop()
|
||||
end
|
||||
|
||||
local swap={
|
||||
none={duration=1,changeTime=0,draw=function()end},
|
||||
flash={duration=8,changeTime=1,draw=function()gc.clear(1,1,1)end},
|
||||
fade={duration=30,changeTime=15,draw=function(t)
|
||||
t=t>15 and 2-t/15 or t/15
|
||||
gc.setColor(0,0,0,t)
|
||||
gc.rectangle('fill',0,0,SCR.w,SCR.h)
|
||||
end},
|
||||
fade_togame={duration=120,changeTime=20,draw=function(t)
|
||||
t=t>20 and(120-t)/100 or t/20
|
||||
gc.setColor(0,0,0,t)
|
||||
gc.rectangle('fill',0,0,SCR.w,SCR.h)
|
||||
end},
|
||||
slowFade={duration=180,changeTime=90,draw=function(t)
|
||||
t=t>90 and 2-t/90 or t/90
|
||||
gc.setColor(0,0,0,t)
|
||||
gc.rectangle('fill',0,0,SCR.w,SCR.h)
|
||||
end},
|
||||
swipeL={duration=30,changeTime=15,draw=function(t)
|
||||
t=t/30
|
||||
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||
t=t*t*(3-2*t)*2-1
|
||||
gc.rectangle('fill',t*SCR.w,0,SCR.w,SCR.h)
|
||||
end},
|
||||
swipeR={duration=30,changeTime=15,draw=function(t)
|
||||
t=t/30
|
||||
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||
t=t*t*(2*t-3)*2+1
|
||||
gc.rectangle('fill',t*SCR.w,0,SCR.w,SCR.h)
|
||||
end},
|
||||
swipeD={duration=30,changeTime=15,draw=function(t)
|
||||
t=t/30
|
||||
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||
t=t*t*(2*t-3)*2+1
|
||||
gc.rectangle('fill',0,t*SCR.h,SCR.w,SCR.h)
|
||||
end},
|
||||
none={
|
||||
duration=0,changeTime=0,
|
||||
draw=function()end
|
||||
},
|
||||
flash={
|
||||
duration=.16,changeTime=.08,
|
||||
draw=function()gc.clear(1,1,1)end
|
||||
},
|
||||
fade={
|
||||
duration=.5,changeTime=.25,
|
||||
draw=function(t)
|
||||
t=t>.25 and 2-t*4 or t*4
|
||||
gc.setColor(0,0,0,t)
|
||||
gc.rectangle('fill',0,0,SCR.w,SCR.h)
|
||||
end
|
||||
},
|
||||
fade_togame={
|
||||
duration=2,changeTime=.5,
|
||||
draw=function(t)
|
||||
t=t>.5 and(2-t)/1.5 or t*.5
|
||||
gc.setColor(0,0,0,t)
|
||||
gc.rectangle('fill',0,0,SCR.w,SCR.h)
|
||||
end
|
||||
},
|
||||
slowFade={
|
||||
duration=3,changeTime=1.5,
|
||||
draw=function(t)
|
||||
t=t>1.5 and (3-t)/1.5 or t/1.5
|
||||
gc.setColor(0,0,0,t)
|
||||
gc.rectangle('fill',0,0,SCR.w,SCR.h)
|
||||
end
|
||||
},
|
||||
swipeL={
|
||||
duration=.5,changeTime=.25,
|
||||
draw=function(t)
|
||||
t=t*2
|
||||
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||
t=t*t*(3-2*t)*2-1
|
||||
gc.rectangle('fill',t*SCR.w,0,SCR.w,SCR.h)
|
||||
end
|
||||
},
|
||||
swipeR={
|
||||
duration=.5,changeTime=.25,
|
||||
draw=function(t)
|
||||
t=t*2
|
||||
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||
t=t*t*(2*t-3)*2+1
|
||||
gc.rectangle('fill',t*SCR.w,0,SCR.w,SCR.h)
|
||||
end
|
||||
},
|
||||
swipeD={
|
||||
duration=.5,changeTime=.25,
|
||||
draw=function(t)
|
||||
t=t*2
|
||||
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||
t=t*t*(2*t-3)*2+1
|
||||
gc.rectangle('fill',0,t*SCR.h,SCR.w,SCR.h)
|
||||
end
|
||||
},
|
||||
}--Scene swapping animations
|
||||
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
|
||||
if scenes[tar]then
|
||||
|
||||
@@ -6,14 +6,19 @@ local TASK={}
|
||||
function TASK.getCount()
|
||||
return #tasks
|
||||
end
|
||||
function TASK.update()
|
||||
for i=#tasks,1,-1 do
|
||||
local T=tasks[i]
|
||||
if status(T.thread)=='dead'then
|
||||
rem(tasks,i)
|
||||
else
|
||||
assert(resume(T.thread))
|
||||
local trigTime=0
|
||||
function TASK.update(dt)
|
||||
trigTime=trigTime+dt
|
||||
while trigTime>1/60 do
|
||||
for i=#tasks,1,-1 do
|
||||
local T=tasks[i]
|
||||
if status(T.thread)=='dead'then
|
||||
rem(tasks,i)
|
||||
else
|
||||
assert(resume(T.thread))
|
||||
end
|
||||
end
|
||||
trigTime=trigTime-1/60
|
||||
end
|
||||
end
|
||||
function TASK.new(code,...)
|
||||
|
||||
@@ -106,7 +106,7 @@ function TEXT.show(text,x,y,font,style,spd,stop)
|
||||
text=gc.newText(FONT.get(int(font/5)*5 or 40),text), --String
|
||||
x=x or 0, --X
|
||||
y=y or 0, --Y
|
||||
spd=(spd or 1)/60, --Timing speed(1=last 1 sec)
|
||||
spd=(spd or 1), --Timing speed(1=last 1 sec)
|
||||
stop=stop, --Stop time(sustained text)
|
||||
draw=assert(textFX[style or'appear'],"no text type:"..style),--Draw method
|
||||
})
|
||||
@@ -117,18 +117,18 @@ function TEXT.getText(text,x,y,font,style,spd,stop)--Another version of TEXT.sho
|
||||
text=gc.newText(FONT.get(int(font/5)*5 or 40),text),
|
||||
x=x or 0,
|
||||
y=y or 0,
|
||||
spd=(spd or 1)/60,
|
||||
spd=(spd or 1),
|
||||
stop=stop,
|
||||
draw=textFX[style or'appear']or error("unavailable type:"..style),
|
||||
}
|
||||
end
|
||||
function TEXT.update(list)
|
||||
function TEXT.update(dt,list)
|
||||
if not list then
|
||||
list=texts
|
||||
end
|
||||
for i=#list,1,-1 do
|
||||
local t=list[i]
|
||||
t.c=t.c+t.spd
|
||||
t.c=t.c+t.spd*dt
|
||||
if t.stop then
|
||||
if t.c>t.stop then
|
||||
t.c=t.stop
|
||||
|
||||
@@ -59,13 +59,13 @@ local text={
|
||||
}
|
||||
|
||||
function text:reset()end
|
||||
function text:update()
|
||||
function text:update(dt)
|
||||
if self.hideF and self.hideF()then
|
||||
if self.alpha>0 then
|
||||
self.alpha=self.alpha-.125
|
||||
self.alpha=max(self.alpha-dt*7.5,0)
|
||||
end
|
||||
elseif self.alpha<1 then
|
||||
self.alpha=self.alpha+.125
|
||||
self.alpha=min(self.alpha+dt*7.5,1)
|
||||
end
|
||||
end
|
||||
function text:draw()
|
||||
@@ -154,12 +154,12 @@ end
|
||||
function button:getCenter()
|
||||
return self.x+self.w*.5,self.y+self.h*.5
|
||||
end
|
||||
function button:update()
|
||||
function button:update(dt)
|
||||
local ATV=self.ATV
|
||||
if WIDGET.sel==self then
|
||||
if ATV<8 then self.ATV=ATV+1 end
|
||||
if ATV<8 then self.ATV=min(ATV+dt*60,8)end
|
||||
else
|
||||
if ATV>0 then self.ATV=ATV-.5 end
|
||||
if ATV>0 then self.ATV=max(ATV-dt*30,0)end
|
||||
end
|
||||
end
|
||||
function button:draw()
|
||||
@@ -282,12 +282,12 @@ end
|
||||
function key:getCenter()
|
||||
return self.x+self.w*.5,self.y+self.h*.5
|
||||
end
|
||||
function key:update()
|
||||
function key:update(dt)
|
||||
local ATV=self.ATV
|
||||
if WIDGET.sel==self then
|
||||
if ATV<4 then self.ATV=ATV+1 end
|
||||
if ATV<4 then self.ATV=min(ATV+dt*60,4)end
|
||||
else
|
||||
if ATV>0 then self.ATV=ATV-.5 end
|
||||
if ATV>0 then self.ATV=max(ATV-dt*30,0)end
|
||||
end
|
||||
end
|
||||
function key:draw()
|
||||
@@ -389,18 +389,18 @@ end
|
||||
function switch:getCenter()
|
||||
return self.x,self.y
|
||||
end
|
||||
function switch:update()
|
||||
local atv=self.ATV
|
||||
function switch:update(dt)
|
||||
local ATV=self.ATV
|
||||
if WIDGET.sel==self then
|
||||
if atv<8 then self.ATV=atv+1 end
|
||||
if ATV<8 then self.ATV=min(ATV+dt*60,8)end
|
||||
else
|
||||
if atv>0 then self.ATV=atv-.5 end
|
||||
if ATV>0 then self.ATV=max(ATV-dt*30,0)end
|
||||
end
|
||||
local chk=self.CHK
|
||||
if self:disp()then
|
||||
if chk<6 then self.CHK=chk+1 end
|
||||
if chk<6 then self.CHK=min(chk+dt*60,6)end
|
||||
else
|
||||
if chk>0 then self.CHK=chk-1 end
|
||||
if chk>0 then self.CHK=max(chk-dt*60,0)end
|
||||
end
|
||||
end
|
||||
function switch:draw()
|
||||
@@ -492,22 +492,16 @@ end
|
||||
function slider:getCenter()
|
||||
return self.x+self.w*(self.pos/self.unit),self.y
|
||||
end
|
||||
function slider:update()
|
||||
local atv=self.ATV
|
||||
function slider:update(dt)
|
||||
local ATV=self.ATV
|
||||
if self.TAT>0 then
|
||||
self.TAT=self.TAT-1
|
||||
self.TAT=max(self.TAT-dt*60,0)
|
||||
end
|
||||
if WIDGET.sel==self then
|
||||
if atv<6 then
|
||||
atv=atv+1
|
||||
self.ATV=atv
|
||||
end
|
||||
if ATV<6 then self.ATV=min(ATV+dt*60,6)end
|
||||
self.TAT=180
|
||||
else
|
||||
if atv>0 then
|
||||
atv=atv-.5
|
||||
self.ATV=atv
|
||||
end
|
||||
if ATV>0 then self.ATV=max(ATV-dt*30,0)end
|
||||
end
|
||||
if not self.hide then
|
||||
self.pos=self.pos*.7+self.disp()*.3
|
||||
@@ -682,16 +676,12 @@ end
|
||||
function selector:getCenter()
|
||||
return self.x+self.w*.5,self.y+30
|
||||
end
|
||||
function selector:update()
|
||||
local atv=self.ATV
|
||||
function selector:update(dt)
|
||||
local ATV=self.ATV
|
||||
if WIDGET.sel==self then
|
||||
if atv<8 then
|
||||
self.ATV=atv+1
|
||||
end
|
||||
if ATV<8 then self.ATV=min(ATV+dt*60,8)end
|
||||
else
|
||||
if atv>0 then
|
||||
self.ATV=atv-.5
|
||||
end
|
||||
if ATV>0 then self.ATV=max(ATV-dt*30,0)end
|
||||
end
|
||||
end
|
||||
function selector:draw()
|
||||
@@ -850,12 +840,12 @@ end
|
||||
function inputBox:getCenter()
|
||||
return self.x+self.w*.5,self.y
|
||||
end
|
||||
function inputBox:update()
|
||||
function inputBox:update(dt)
|
||||
local ATV=self.ATV
|
||||
if WIDGET.sel==self then
|
||||
if ATV<3 then self.ATV=ATV+1 end
|
||||
if ATV<3 then self.ATV=min(ATV+dt*60,3)end
|
||||
else
|
||||
if ATV>0 then self.ATV=ATV-.25 end
|
||||
if ATV>0 then self.ATV=max(ATV-dt*15,0)end
|
||||
end
|
||||
end
|
||||
function inputBox:draw()
|
||||
@@ -967,9 +957,9 @@ end
|
||||
function textBox:getCenter()
|
||||
return self.x+self.w*.5,self.y+self.w
|
||||
end
|
||||
function textBox:update()
|
||||
function textBox:update(dt)
|
||||
if self.sure>0 then
|
||||
self.sure=self.sure-1
|
||||
self.sure=max(self.sure-dt,0)
|
||||
end
|
||||
end
|
||||
function textBox:push(t)
|
||||
@@ -986,7 +976,7 @@ function textBox:press(x,y)
|
||||
self:clear()
|
||||
self.sure=0
|
||||
else
|
||||
self.sure=60
|
||||
self.sure=1
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1476,7 +1466,7 @@ function WIDGET.gamepadPressed(i)
|
||||
end
|
||||
end
|
||||
|
||||
function WIDGET.update()
|
||||
function WIDGET.update(dt)
|
||||
for _,W in next,WIDGET.active do
|
||||
if W.hideF then
|
||||
W.hide=W.hideF()
|
||||
@@ -1484,7 +1474,7 @@ function WIDGET.update()
|
||||
WIDGET.unFocus(true)
|
||||
end
|
||||
end
|
||||
if W.update then W:update()end
|
||||
if W.update then W:update(dt)end
|
||||
end
|
||||
end
|
||||
local widgetCanvas
|
||||
|
||||
@@ -429,6 +429,7 @@ local DemoEnv={
|
||||
life=1e99,
|
||||
allowMod=false,
|
||||
fine=false,
|
||||
FTLock=true,
|
||||
}
|
||||
function PLY.newDemoPlayer(id)
|
||||
local P=_newEmptyPlayer(id)
|
||||
|
||||
@@ -1826,7 +1826,7 @@ local function _updateMisc(P)
|
||||
|
||||
--Update texts
|
||||
if P.bonus then
|
||||
TEXT.update(P.bonus)
|
||||
TEXT.update(1/60,P.bonus)
|
||||
end
|
||||
|
||||
--Update tasks
|
||||
|
||||
@@ -163,12 +163,12 @@ function scene.keyDown(key)
|
||||
end
|
||||
end
|
||||
|
||||
function scene.update()
|
||||
function scene.update(dt)
|
||||
if not LOADED then
|
||||
loading=loadingThread()
|
||||
progress=progress+1
|
||||
else
|
||||
t1,t2=t1+1,t2+1
|
||||
t1,t2=t1+dt*60,t2+dt*60
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ end
|
||||
|
||||
function scene.update(dt)
|
||||
PLAYERS[1]:update(dt)
|
||||
scrollX=scrollX-2.6
|
||||
scrollX=scrollX-162*dt
|
||||
if scrollX<-tip:getWidth()then
|
||||
scrollX=tipLength
|
||||
tip:set(text.getTip())
|
||||
|
||||
Reference in New Issue
Block a user