增加注释,整理代码

This commit is contained in:
MrZ626
2020-11-02 14:25:26 +08:00
parent 54c5e469c4
commit 01913b7b8e
2 changed files with 22 additions and 23 deletions

View File

@@ -37,7 +37,7 @@ function text:draw()
gc.draw(self.text,self.x-self.text:getWidth(),self.y) gc.draw(self.text,self.x-self.text:getWidth(),self.y)
end end
end end
function WIDGET.newText(D) function WIDGET.newText(D)--name,x,y[,color][,font=30][,align="M"][,hide]
local _={ local _={
name= D.name, name= D.name,
x= D.x, x= D.x,
@@ -64,7 +64,7 @@ function image:draw()
gc.setColor(1,1,1,self.alpha) gc.setColor(1,1,1,self.alpha)
gc.draw(self.img,self.x,self.y,self.ang,self.k) gc.draw(self.img,self.x,self.y,self.ang,self.k)
end end
function WIDGET.newImage(D) function WIDGET.newImage(D)--name[,img(name)],x,y[,ang][,k][,hide]
local _={ local _={
name= D.name, name= D.name,
img= D.img or D.name, img= D.img or D.name,
@@ -143,7 +143,7 @@ end
function button:getInfo() function button:getInfo()
return format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font) return format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font)
end end
function WIDGET.newButton(D) function WIDGET.newButton(D)--name,x,y,w[,h][,color][,font],code[,hide]
if not D.h then D.h=D.w end if not D.h then D.h=D.w end
local _={ local _={
name= D.name, name= D.name,
@@ -218,7 +218,7 @@ end
function key:getInfo() function key:getInfo()
return format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font) return format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font)
end end
function WIDGET.newKey(D) function WIDGET.newKey(D)--name,x,y,w[,h][,color][,font],code[,hide]
if not D.h then D.h=D.w end if not D.h then D.h=D.w end
local _={ local _={
name= D.name, name= D.name,
@@ -302,7 +302,7 @@ end
function switch:getInfo() function switch:getInfo()
return format("x=%d,y=%d,font=%d",self.x,self.y,self.font) return format("x=%d,y=%d,font=%d",self.x,self.y,self.font)
end end
function WIDGET.newSwitch(D) function WIDGET.newSwitch(D)--name,x,y[,font][,disp],code,hide
local _={ local _={
name= D.name, name= D.name,
@@ -328,6 +328,7 @@ local slider={
ATV=0,--Activating time(0~8) ATV=0,--Activating time(0~8)
TAT=0,--Text activating time(0~180) TAT=0,--Text activating time(0~180)
pos=0,--Position shown pos=0,--Position shown
lastTime=0,
} }
local sliderShowFunc={ local sliderShowFunc={
int=function(S) int=function(S)
@@ -339,10 +340,6 @@ local sliderShowFunc={
percent=function(S) percent=function(S)
return int(S.disp()*100).."%" return int(S.disp()*100).."%"
end, end,
frame_time=function(S)
S=S.disp()
return S.."F "..int(S*16.67).."ms"
end,
} }
function slider:reset() function slider:reset()
self.ATV=0 self.ATV=0
@@ -425,7 +422,7 @@ end
function slider:getInfo() function slider:getInfo()
return format("x=%d,y=%d,w=%d",self.x,self.y,self.w) return format("x=%d,y=%d,w=%d",self.x,self.y,self.w)
end end
function WIDGET.newSlider(D) function WIDGET.newSlider(D)--name,x,y,w[,unit][,smooth][,font][,change],disp,code,hide
local _={ local _={
name= D.name, name= D.name,
@@ -442,15 +439,13 @@ function WIDGET.newSlider(D)
}, },
unit= D.unit or 1, unit= D.unit or 1,
--smooth=nil, smooth=nil,
font= D.font or 30, font= D.font or 30,
change= D.change, change= D.change,
disp= D.disp, disp= D.disp,
code= D.code, code= D.code,
hide= D.hide, hide= D.hide,
--show= nil, show= nil,
lastTime=0,
} }
if D.smooth~=nil then if D.smooth~=nil then
_.smooth=D.smooth _.smooth=D.smooth
@@ -556,7 +551,7 @@ end
function selector:getInfo() function selector:getInfo()
return format("x=%d,y=%d,w=%d",self.x+self.w*.5,self.y+30,self.w) return format("x=%d,y=%d,w=%d",self.x+self.w*.5,self.y+30,self.w)
end end
function WIDGET.newSelector(D) function WIDGET.newSelector(D)--name,x,y,w[,color],list,disp,code,hide
local _={ local _={
name= D.name, name= D.name,
@@ -645,8 +640,7 @@ end
function textBox:getInfo() function textBox:getInfo()
return format("x=%d,y=%d,w=%d,h=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h) return format("x=%d,y=%d,w=%d,h=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h)
end end
function WIDGET.newTextBox(D) function WIDGET.newTextBox(D)--name,x,y,w[,h][,font][,secret][,regex],hide
if not D.h then D.h=D.w end
local _={ local _={
name= D.name, name= D.name,
@@ -654,8 +648,6 @@ function WIDGET.newTextBox(D)
y= D.y, y= D.y,
w= D.w, w= D.w,
h= D.h, h= D.h,
secret= D.secret,
regex= D.regex,
resCtr={ resCtr={
D.x+D.w*.2,D.y, D.x+D.w*.2,D.y,
@@ -664,6 +656,8 @@ function WIDGET.newTextBox(D)
}, },
font= int(D.h/7-1)*5, font= int(D.h/7-1)*5,
secret= D.secret,
regex= D.regex,
hide= D.hide, hide= D.hide,
} }
for k,v in next,textBox do _[k]=v end for k,v in next,textBox do _[k]=v end

View File

@@ -1,4 +1,5 @@
local gc=love.graphics local gc=love.graphics
local int=math.floor
function sceneInit.setting_control() function sceneInit.setting_control()
sceneTemp={ sceneTemp={
@@ -74,14 +75,18 @@ function Pnt.setting_control()
gc.draw(_,x+40,580,nil,40/30) gc.draw(_,x+40,580,nil,40/30)
end end
local function sliderShow(S)
S=S.disp()
return S.."F "..int(S*16.67).."ms"
end
WIDGET.init("setting_control",{ WIDGET.init("setting_control",{
WIDGET.newText({name="title", x=80, y=50,font=70,align="L"}), WIDGET.newText({name="title", x=80, y=50,font=70,align="L"}),
WIDGET.newText({name="preview", x=520, y=540,font=40,align="R"}), WIDGET.newText({name="preview", x=520, y=540,font=40,align="R"}),
WIDGET.newSlider({name="das", x=250, y=200,w=910,unit=26,disp=WIDGET.lnk.SETval("das"), show="frame_time",code=WIDGET.lnk.SETsto("das")}), WIDGET.newSlider({name="das", x=250, y=200,w=910,unit=26,disp=WIDGET.lnk.SETval("das"), show=sliderShow,code=WIDGET.lnk.SETsto("das")}),
WIDGET.newSlider({name="arr", x=250, y=290,w=525,unit=15,disp=WIDGET.lnk.SETval("arr"), show="frame_time",code=WIDGET.lnk.SETsto("arr")}), WIDGET.newSlider({name="arr", x=250, y=290,w=525,unit=15,disp=WIDGET.lnk.SETval("arr"), show=sliderShow,code=WIDGET.lnk.SETsto("arr")}),
WIDGET.newSlider({name="sddas", x=250, y=380,w=350,unit=10,disp=WIDGET.lnk.SETval("sddas"), show="frame_time",code=WIDGET.lnk.SETsto("sddas")}), WIDGET.newSlider({name="sddas", x=250, y=380,w=350,unit=10,disp=WIDGET.lnk.SETval("sddas"), show=sliderShow,code=WIDGET.lnk.SETsto("sddas")}),
WIDGET.newSlider({name="sdarr", x=250, y=470,w=140,unit=4, disp=WIDGET.lnk.SETval("sdarr"), show="frame_time",code=WIDGET.lnk.SETsto("sdarr")}), WIDGET.newSlider({name="sdarr", x=250, y=470,w=140,unit=4, disp=WIDGET.lnk.SETval("sdarr"), show=sliderShow,code=WIDGET.lnk.SETsto("sdarr")}),
WIDGET.newSwitch({name="ihs", x=1100, y=290, disp=WIDGET.lnk.SETval("ihs"), code=WIDGET.lnk.SETrev("ihs")}), WIDGET.newSwitch({name="ihs", x=1100, y=290, disp=WIDGET.lnk.SETval("ihs"), code=WIDGET.lnk.SETrev("ihs")}),
WIDGET.newSwitch({name="irs", x=1100, y=380, disp=WIDGET.lnk.SETval("irs"), code=WIDGET.lnk.SETrev("irs")}), WIDGET.newSwitch({name="irs", x=1100, y=380, disp=WIDGET.lnk.SETval("irs"), code=WIDGET.lnk.SETrev("irs")}),
WIDGET.newSwitch({name="ims", x=1100, y=470, disp=WIDGET.lnk.SETval("ims"), code=WIDGET.lnk.SETrev("ims")}), WIDGET.newSwitch({name="ims", x=1100, y=470, disp=WIDGET.lnk.SETval("ims"), code=WIDGET.lnk.SETrev("ims")}),