整理代码习惯,常量字符串改用单引号,可能有遗漏
This commit is contained in:
@@ -16,7 +16,7 @@ local widgetMetatable={
|
||||
}
|
||||
|
||||
local text={
|
||||
type="text",
|
||||
type='text',
|
||||
mustHaveText=true,
|
||||
alpha=0,
|
||||
}
|
||||
@@ -34,16 +34,16 @@ function text:draw()
|
||||
if self.alpha>0 then
|
||||
local c=self.color
|
||||
gc.setColor(c[1],c[2],c[3],self.alpha)
|
||||
if self.align=="M"then
|
||||
if self.align=='M'then
|
||||
mDraw_X(self.obj,self.x,self.y)
|
||||
elseif self.align=="L"then
|
||||
elseif self.align=='L'then
|
||||
gc.draw(self.obj,self.x,self.y)
|
||||
elseif self.align=="R"then
|
||||
elseif self.align=='R'then
|
||||
gc.draw(self.obj,self.x-self.obj:getWidth(),self.y)
|
||||
end
|
||||
end
|
||||
end
|
||||
function WIDGET.newText(D)--name,x,y[,fText][,color][,font=30][,align="M"][,hide]
|
||||
function WIDGET.newText(D)--name,x,y[,fText][,color][,font=30][,align='M'][,hide]
|
||||
local _={
|
||||
name= D.name,
|
||||
x= D.x,
|
||||
@@ -52,7 +52,7 @@ function WIDGET.newText(D)--name,x,y[,fText][,color][,font=30][,align="M"][,hide
|
||||
fText= D.fText,
|
||||
color= D.color and(COLOR[D.color]or D.color)or COLOR.Z,
|
||||
font= D.font or 30,
|
||||
align= D.align or"M",
|
||||
align= D.align or'M',
|
||||
hideCon=D.hide,
|
||||
}
|
||||
for k,v in next,text do _[k]=v end
|
||||
@@ -62,10 +62,10 @@ function WIDGET.newText(D)--name,x,y[,fText][,color][,font=30][,align="M"][,hide
|
||||
end
|
||||
|
||||
local image={
|
||||
type="image",
|
||||
type='image',
|
||||
}
|
||||
function image:reset()
|
||||
if type(self.img)=="string"then
|
||||
if type(self.img)=='string'then
|
||||
self.img=IMG[self.img]
|
||||
end
|
||||
end
|
||||
@@ -90,7 +90,7 @@ function WIDGET.newImage(D)--name[,img(name)],x,y[,ang][,k][,hide]
|
||||
end
|
||||
|
||||
local button={
|
||||
type="button",
|
||||
type='button',
|
||||
mustHaveText=true,
|
||||
ATV=0,--Activating time(0~8)
|
||||
}
|
||||
@@ -98,7 +98,7 @@ function button:reset()
|
||||
self.ATV=0
|
||||
end
|
||||
function button:setObject(obj)
|
||||
if type(obj)=="string"or type(obj)=="number"then
|
||||
if type(obj)=='string'or type(obj)=='number'then
|
||||
self.obj=gc.newText(getFont(self.font),obj)
|
||||
elseif obj then
|
||||
self.obj=obj
|
||||
@@ -139,16 +139,16 @@ function button:draw()
|
||||
local c=self.color
|
||||
local r,g,b=c[1],c[2],c[3]
|
||||
gc.setColor(.2+r*.8,.2+g*.8,.2+b*.8,.7)
|
||||
gc.rectangle("fill",x-ATV,y-ATV,w+2*ATV,h+2*ATV)
|
||||
gc.rectangle('fill',x-ATV,y-ATV,w+2*ATV,h+2*ATV)
|
||||
if ATV>0 then
|
||||
gc.setLineWidth(4)
|
||||
gc.setColor(1,1,1,ATV*.125)
|
||||
gc.rectangle("line",x-ATV+2,y-ATV+2,w+2*ATV-4,h+2*ATV-4)
|
||||
gc.rectangle('line',x-ATV+2,y-ATV+2,w+2*ATV-4,h+2*ATV-4)
|
||||
end
|
||||
local obj=self.obj
|
||||
local y0=y+h*.5-ATV*.5
|
||||
gc.setColor(1,1,1,.2+ATV*.05)
|
||||
if self.align=="M"then
|
||||
if self.align=='M'then
|
||||
local x0=x+w*.5
|
||||
mDraw(obj,x0-2,y0-2)
|
||||
mDraw(obj,x0-2,y0+2)
|
||||
@@ -156,7 +156,7 @@ function button:draw()
|
||||
mDraw(obj,x0+2,y0+2)
|
||||
gc.setColor(r*.5,g*.5,b*.5)
|
||||
mDraw(obj,x0,y0)
|
||||
elseif self.align=="L"then
|
||||
elseif self.align=='L'then
|
||||
local edge=self.edge
|
||||
mDraw_Y(obj,x+edge-2,y0-2)
|
||||
mDraw_Y(obj,x+edge-2,y0+2)
|
||||
@@ -164,7 +164,7 @@ function button:draw()
|
||||
mDraw_Y(obj,x+edge+2,y0+2)
|
||||
gc.setColor(r*.5,g*.5,b*.5)
|
||||
mDraw_Y(obj,x+edge,y0)
|
||||
elseif self.align=="R"then
|
||||
elseif self.align=='R'then
|
||||
local x0=x+w-self.edge-obj:getWidth()
|
||||
mDraw_Y(obj,x0-2,y0-2)
|
||||
mDraw_Y(obj,x0-2,y0+2)
|
||||
@@ -180,9 +180,9 @@ end
|
||||
function button:press(_,_,k)
|
||||
self.code(k)
|
||||
self:FX()
|
||||
if self.sound then SFX.play("button")end
|
||||
if self.sound then SFX.play('button')end
|
||||
end
|
||||
function WIDGET.newButton(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true][,align="M"][,edge=0],code[,hide]
|
||||
function WIDGET.newButton(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true][,align='M'][,edge=0],code[,hide]
|
||||
if not D.h then D.h=D.w end
|
||||
local _={
|
||||
name= D.name,
|
||||
@@ -203,7 +203,7 @@ function WIDGET.newButton(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=tr
|
||||
fText= D.fText,
|
||||
color= D.color and(COLOR[D.color]or D.color)or COLOR.Z,
|
||||
font= D.font or 30,
|
||||
align= D.align or"M",
|
||||
align= D.align or'M',
|
||||
edge= D.edge or 0,
|
||||
sound= D.sound~=false,
|
||||
code= D.code,
|
||||
@@ -215,7 +215,7 @@ function WIDGET.newButton(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=tr
|
||||
end
|
||||
|
||||
local key={
|
||||
type="key",
|
||||
type='key',
|
||||
mustHaveText=true,
|
||||
ATV=0,--Activating time(0~4)
|
||||
}
|
||||
@@ -223,7 +223,7 @@ function key:reset()
|
||||
self.ATV=0
|
||||
end
|
||||
function key:setObject(obj)
|
||||
if type(obj)=="string"or type(obj)=="number"then
|
||||
if type(obj)=='string'or type(obj)=='number'then
|
||||
self.obj=gc.newText(getFont(self.font),obj)
|
||||
elseif obj then
|
||||
self.obj=obj
|
||||
@@ -254,18 +254,18 @@ function key:draw()
|
||||
local r,g,b=c[1],c[2],c[3]
|
||||
|
||||
gc.setColor(1,1,1,ATV*.125)
|
||||
gc.rectangle("fill",x,y,w,h)
|
||||
gc.rectangle('fill',x,y,w,h)
|
||||
|
||||
gc.setColor(.2+r*.8,.2+g*.8,.2+b*.8,.7)
|
||||
gc.setLineWidth(4)
|
||||
gc.rectangle("line",x,y,w,h)
|
||||
gc.rectangle('line',x,y,w,h)
|
||||
|
||||
gc.setColor(r,g,b,1.2)
|
||||
if self.align=="M"then
|
||||
if self.align=='M'then
|
||||
mDraw(self.obj,x+w*.5,y+h*.5)
|
||||
elseif self.align=="L"then
|
||||
elseif self.align=='L'then
|
||||
mDraw_Y(self.obj,x+self.edge,y+h*.5)
|
||||
elseif self.align=="R"then
|
||||
elseif self.align=='R'then
|
||||
mDraw_Y(self.obj,x+w-self.edge-self.obj:getWidth(),y+h*.5)
|
||||
end
|
||||
end
|
||||
@@ -274,9 +274,9 @@ function key:getInfo()
|
||||
end
|
||||
function key:press(_,_,k)
|
||||
self.code(k)
|
||||
if self.sound then SFX.play("key")end
|
||||
if self.sound then SFX.play('key')end
|
||||
end
|
||||
function WIDGET.newKey(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true][,align="M"][,edge=0],code[,hide]
|
||||
function WIDGET.newKey(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true][,align='M'][,edge=0],code[,hide]
|
||||
if not D.h then D.h=D.w end
|
||||
local _={
|
||||
name= D.name,
|
||||
@@ -298,7 +298,7 @@ function WIDGET.newKey(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true]
|
||||
color= D.color and(COLOR[D.color]or D.color)or COLOR.Z,
|
||||
font= D.font or 30,
|
||||
sound= D.sound~=false,
|
||||
align= D.align or"M",
|
||||
align= D.align or'M',
|
||||
edge= D.edge or 0,
|
||||
code= D.code,
|
||||
hide= D.hide,
|
||||
@@ -309,7 +309,7 @@ function WIDGET.newKey(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true]
|
||||
end
|
||||
|
||||
local switch={
|
||||
type="switch",
|
||||
type='switch',
|
||||
mustHaveText=true,
|
||||
ATV=0,--Activating time(0~8)
|
||||
CHK=0,--Check alpha(0~6)
|
||||
@@ -341,7 +341,7 @@ function switch:draw()
|
||||
--Checked
|
||||
if ATV>0 then
|
||||
gc.setColor(1,1,1,ATV*.08)
|
||||
gc.rectangle("fill",x,y,50,50)
|
||||
gc.rectangle('fill',x,y,50,50)
|
||||
end
|
||||
if self.CHK>0 then
|
||||
gc.setColor(.9,1,.9,self.CHK/6)
|
||||
@@ -352,7 +352,7 @@ function switch:draw()
|
||||
--Frame
|
||||
gc.setLineWidth(4)
|
||||
gc.setColor(1,1,1,.6+ATV*.05)
|
||||
gc.rectangle("line",x,y,50,50)
|
||||
gc.rectangle('line',x,y,50,50)
|
||||
|
||||
--Drawable
|
||||
gc.setColor(self.color)
|
||||
@@ -363,7 +363,7 @@ function switch:getInfo()
|
||||
end
|
||||
function switch:press()
|
||||
self.code()
|
||||
if self.sound then SFX.play("move")end
|
||||
if self.sound then SFX.play('move')end
|
||||
end
|
||||
function WIDGET.newSwitch(D)--name,x,y[,fText][,color][,font=30][,sound=true][,disp],code,hide
|
||||
local _={
|
||||
@@ -390,7 +390,7 @@ function WIDGET.newSwitch(D)--name,x,y[,fText][,color][,font=30][,sound=true][,d
|
||||
end
|
||||
|
||||
local slider={
|
||||
type="slider",
|
||||
type='slider',
|
||||
ATV=0,--Activating time(0~8)
|
||||
TAT=0,--Text activating time(0~180)
|
||||
pos=0,--Position shown
|
||||
@@ -463,12 +463,12 @@ function slider:draw()
|
||||
local cx=x+(x2-x)*self.pos/self.unit
|
||||
local bx,by,bw,bh=cx-10-ATV*.5,y-16-ATV,20+ATV,32+2*ATV
|
||||
gc.setColor(.8,.8,.8)
|
||||
gc.rectangle("fill",bx,by,bw,bh)
|
||||
gc.rectangle('fill',bx,by,bw,bh)
|
||||
|
||||
if ATV>0 then
|
||||
gc.setLineWidth(2)
|
||||
gc.setColor(1,1,1,ATV*.16)
|
||||
gc.rectangle("line",bx+1,by+1,bw-2,bh-2)
|
||||
gc.rectangle('line',bx+1,by+1,bw-2,bh-2)
|
||||
end
|
||||
if self.TAT>0 and self.show then
|
||||
setFont(25)
|
||||
@@ -552,7 +552,7 @@ function WIDGET.newSlider(D)--name,x,y,w[,fText][,color][,unit][,smooth][,font=3
|
||||
_.smooth=_.unit<=1
|
||||
end
|
||||
if D.show then
|
||||
if type(D.show)=="function"then
|
||||
if type(D.show)=='function'then
|
||||
_.show=D.show
|
||||
else
|
||||
_.show=sliderShowFunc[D.show]
|
||||
@@ -570,7 +570,7 @@ function WIDGET.newSlider(D)--name,x,y,w[,fText][,color][,unit][,smooth][,font=3
|
||||
end
|
||||
|
||||
local selector={
|
||||
type="selector",
|
||||
type='selector',
|
||||
mustHaveText=true,
|
||||
ATV=8,--Activating time(0~4)
|
||||
select=0,--Selected item ID
|
||||
@@ -588,7 +588,7 @@ function selector:reset()
|
||||
end
|
||||
end
|
||||
self.hide=true
|
||||
LOG.print("Selector "..self.name.." dead, disp= "..tostring(V),"warn")
|
||||
LOG.print("Selector "..self.name.." dead, disp= "..tostring(V),'warn')
|
||||
end
|
||||
function selector:isAbove(x,y)
|
||||
return
|
||||
@@ -619,7 +619,7 @@ function selector:draw()
|
||||
|
||||
gc.setColor(1,1,1,.6+ATV*.1)
|
||||
gc.setLineWidth(3)
|
||||
gc.rectangle("line",x,y,w,60)
|
||||
gc.rectangle('line',x,y,w,60)
|
||||
|
||||
gc.setColor(1,1,1,.2+ATV*.1)
|
||||
local t=(TIME()%.5)^.5
|
||||
@@ -667,7 +667,7 @@ function selector:press(x)
|
||||
self.code(self.list[s])
|
||||
self.select=s
|
||||
self.selText=self.list[s]
|
||||
if self.sound then SFX.play("prerotate")end
|
||||
if self.sound then SFX.play('prerotate')end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -684,7 +684,7 @@ function selector:arrowKey(isLeft)
|
||||
self.code(self.list[s])
|
||||
self.select=s
|
||||
self.selText=self.list[s]
|
||||
if self.sound then SFX.play("prerotate")end
|
||||
if self.sound then SFX.play('prerotate')end
|
||||
end
|
||||
function WIDGET.newSelector(D)--name,x,y,w[,fText][,color][,sound=true],list,disp,code,hide
|
||||
local _={
|
||||
@@ -717,7 +717,7 @@ function WIDGET.newSelector(D)--name,x,y,w[,fText][,color][,sound=true],list,dis
|
||||
end
|
||||
|
||||
local inputBox={
|
||||
type="inputBox",
|
||||
type='inputBox',
|
||||
keepFocus=true,
|
||||
ATV=0,--Activating time(0~4)
|
||||
value="",--Text contained
|
||||
@@ -754,11 +754,11 @@ function inputBox:draw()
|
||||
local ATV=self.ATV
|
||||
|
||||
gc.setColor(1,1,1,ATV*.1)
|
||||
gc.rectangle("fill",x,y,w,h)
|
||||
gc.rectangle('fill',x,y,w,h)
|
||||
|
||||
gc.setColor(1,1,1)
|
||||
gc.setLineWidth(4)
|
||||
gc.rectangle("line",x,y,w,h)
|
||||
gc.rectangle('line',x,y,w,h)
|
||||
|
||||
--Drawable
|
||||
setFont(self.font)
|
||||
@@ -770,7 +770,7 @@ function inputBox:draw()
|
||||
gc.print("*",x-5+self.font*.5*i,y+h*.5-self.font*.7)
|
||||
end
|
||||
else
|
||||
gc.printf(self.value,x+10,y,self.w,"left")
|
||||
gc.printf(self.value,x+10,y,self.w)
|
||||
setFont(self.font-10)
|
||||
if WIDGET.sel==self then
|
||||
gc.print(EDITING,x+10,y+12-self.font*1.4)
|
||||
@@ -795,10 +795,10 @@ function inputBox:keypress(k)
|
||||
p=p-1
|
||||
end
|
||||
t=sub(t,1,p-1)
|
||||
SFX.play("lock")
|
||||
SFX.play('lock')
|
||||
elseif k=="delete"then
|
||||
t=""
|
||||
SFX.play("hold")
|
||||
SFX.play('hold')
|
||||
end
|
||||
self.value=t
|
||||
end
|
||||
@@ -829,7 +829,7 @@ function WIDGET.newInputBox(D)--name,x,y,w[,h][,font=30][,secret][,regex],hide
|
||||
end
|
||||
|
||||
local textBox={
|
||||
type="textBox",
|
||||
type='textBox',
|
||||
scrollPos=0,--Which line display at bottom
|
||||
scrollPix=0,--Hidden wheel move value
|
||||
sure=0,--Sure-timer for clear history
|
||||
@@ -899,7 +899,7 @@ end
|
||||
function textBox:clear()
|
||||
self.texts={}
|
||||
self.scrollPos=0
|
||||
SFX.play("fall")
|
||||
SFX.play('fall')
|
||||
end
|
||||
function textBox:draw()
|
||||
local x,y,w,h=self.x,self.y,self.w,self.h
|
||||
@@ -910,19 +910,19 @@ function textBox:draw()
|
||||
|
||||
--Background
|
||||
gc.setColor(0,0,0,.3)
|
||||
gc.rectangle("fill",x,y,w,h)
|
||||
gc.rectangle('fill',x,y,w,h)
|
||||
|
||||
--Frame
|
||||
gc.setLineWidth(4)
|
||||
gc.setColor(1,1,WIDGET.sel==self and 0 or 1)
|
||||
gc.rectangle("line",x,y,w,h)
|
||||
gc.rectangle('line',x,y,w,h)
|
||||
|
||||
--Slider
|
||||
if #texts>cap then
|
||||
gc.setLineWidth(2)
|
||||
gc.rectangle("line",x-25,y,20,h)
|
||||
gc.rectangle('line',x-25,y,20,h)
|
||||
local len=max(h*cap/#texts,26)
|
||||
gc.rectangle("fill",x-22,y+(h-len-6)*(scroll-cap)/(#texts-cap)+3,14,len)
|
||||
gc.rectangle('fill',x-22,y+(h-len-6)*(scroll-cap)/(#texts-cap)+3,14,len)
|
||||
end
|
||||
|
||||
gc.setColor(1,1,1)
|
||||
@@ -930,7 +930,7 @@ function textBox:draw()
|
||||
--Clear button
|
||||
if not self.fix then
|
||||
mStr(self.sure>0 and"?"or"X",x+w-20,y-1)
|
||||
gc.rectangle("line",x+w-40,y,40,40)
|
||||
gc.rectangle('line',x+w-40,y,40,40)
|
||||
end
|
||||
|
||||
--Texts
|
||||
@@ -1004,7 +1004,7 @@ function WIDGET.set(list)
|
||||
for i=1,#list do
|
||||
list[i]:reset()
|
||||
end
|
||||
if SCN.cur~="custom_field"then
|
||||
if SCN.cur~='custom_field'then
|
||||
local colorList=THEME.getThemeColor()
|
||||
if not colorList then return end
|
||||
local rnd=math.random
|
||||
@@ -1025,7 +1025,7 @@ function WIDGET.setLang(widgetText)
|
||||
t=W.name or"##"
|
||||
W.color=COLOR.dV
|
||||
end
|
||||
if type(t)=="string"and W.font then
|
||||
if type(t)=='string'and W.font then
|
||||
t=gc.newText(getFont(W.font),t)
|
||||
end
|
||||
W.obj=t
|
||||
@@ -1054,7 +1054,7 @@ end
|
||||
function WIDGET.drag(x,y,dx,dy)
|
||||
local W=WIDGET.sel
|
||||
if not W then return end
|
||||
if W.type=="slider"or W.type=="textBox"then
|
||||
if W.type=='slider'or W.type=='textBox'then
|
||||
W:drag(x,y,dx,dy)
|
||||
elseif not W:isAbove(x,y)then
|
||||
WIDGET.sel=false
|
||||
@@ -1063,7 +1063,7 @@ end
|
||||
function WIDGET.release(x,y)
|
||||
local W=WIDGET.sel
|
||||
if not W then return end
|
||||
if W.type=="slider"then
|
||||
if W.type=='slider'then
|
||||
W:release(x,y)
|
||||
end
|
||||
end
|
||||
@@ -1073,7 +1073,7 @@ function WIDGET.keyPressed(k)
|
||||
elseif kb.isDown("lshift","lalt","lctrl")and(k=="left"or k=="right")then
|
||||
--When hold [↑], control slider with left/right
|
||||
local W=WIDGET.sel
|
||||
if W and W.type=="slider"or W.type=="selector"then
|
||||
if W and W.type=='slider'or W.type=='selector'then
|
||||
W:arrowKey(k=="left")
|
||||
end
|
||||
elseif k=="up"or k=="down"or k=="left"or k=="right"then
|
||||
@@ -1116,19 +1116,19 @@ function WIDGET.keyPressed(k)
|
||||
end
|
||||
else
|
||||
local W=WIDGET.sel
|
||||
if W and W.type=="inputBox"then
|
||||
if W and W.type=='inputBox'then
|
||||
W:keypress(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
function WIDGET.textinput(texts)
|
||||
local W=WIDGET.sel
|
||||
if W and W.type=="inputBox"then
|
||||
if W and W.type=='inputBox'then
|
||||
if not W.regex or texts:match(W.regex)then
|
||||
WIDGET.sel.value=WIDGET.sel.value..texts
|
||||
SFX.play("move")
|
||||
SFX.play('move')
|
||||
else
|
||||
SFX.play("finesseError",.3)
|
||||
SFX.play('finesseError',.3)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1146,9 +1146,9 @@ function WIDGET.gamepadPressed(i)
|
||||
elseif i=="a"or i=="b"then
|
||||
local W=WIDGET.sel
|
||||
if W then
|
||||
if W.type=="button"or W.type=="key"then
|
||||
if W.type=='button'or W.type=='key'then
|
||||
WIDGET.press()
|
||||
elseif W.type=="slider"then
|
||||
elseif W.type=='slider'then
|
||||
local p=W.disp()
|
||||
local P=i=="left"and(p>0 and p-1)or p<W.unit and p+1
|
||||
if p==P or not P then return end
|
||||
|
||||
Reference in New Issue
Block a user