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