控件系统升级,部分控件的text属性改为任意love可绘制对象
This commit is contained in:
@@ -6,12 +6,12 @@ local max,min=math.max,math.min
|
|||||||
local sub,format=string.sub,string.format
|
local sub,format=string.sub,string.format
|
||||||
local ins=table.insert
|
local ins=table.insert
|
||||||
local setFont,mStr=setFont,mStr
|
local setFont,mStr=setFont,mStr
|
||||||
|
local mDraw_Y=MDRAW.simpY
|
||||||
|
|
||||||
local alignModes={
|
local allowNoText={
|
||||||
M="center",
|
image=true,
|
||||||
L="left",
|
inputBox=true,
|
||||||
R="right",
|
textBox=true,
|
||||||
F="justify",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local WIDGET={}
|
local WIDGET={}
|
||||||
@@ -25,15 +25,7 @@ local text={
|
|||||||
type="text",
|
type="text",
|
||||||
alpha=0,
|
alpha=0,
|
||||||
}
|
}
|
||||||
function text:reset()
|
function text:reset()end
|
||||||
if type(self.text)=="string"then
|
|
||||||
self.text=gc.newText(getFont(self.font),self.text)
|
|
||||||
elseif type(self.text)~="userdata"or self.text.type(self.text)~="Text"then
|
|
||||||
self.text=gc.newText(getFont(self.font),self.name)
|
|
||||||
self.color=COLOR.dPurple
|
|
||||||
self.font=self.font-10
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function text:update()
|
function text:update()
|
||||||
if self.hideCon and self.hideCon()then
|
if self.hideCon and self.hideCon()then
|
||||||
if self.alpha>0 then
|
if self.alpha>0 then
|
||||||
@@ -47,12 +39,13 @@ function text:draw()
|
|||||||
if self.alpha>0 then
|
if self.alpha>0 then
|
||||||
local c=self.color
|
local c=self.color
|
||||||
gc.setColor(c[1],c[2],c[3],self.alpha)
|
gc.setColor(c[1],c[2],c[3],self.alpha)
|
||||||
|
local obj=self.obj
|
||||||
if self.align=="M"then
|
if self.align=="M"then
|
||||||
gc.draw(self.text,self.x-self.text:getWidth()*.5,self.y)
|
gc.draw(obj,self.x-obj:getWidth()*.5,self.y)
|
||||||
elseif self.align=="L"then
|
elseif self.align=="L"then
|
||||||
gc.draw(self.text,self.x,self.y)
|
gc.draw(obj,self.x,self.y)
|
||||||
elseif self.align=="R"then
|
elseif self.align=="R"then
|
||||||
gc.draw(self.text,self.x-self.text:getWidth(),self.y)
|
gc.draw(obj,self.x-obj:getWidth(),self.y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -150,21 +143,33 @@ function button:draw()
|
|||||||
gc.setColor(1,1,1,ATV*.125)
|
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
|
end
|
||||||
local t=self.text
|
local obj=self.obj
|
||||||
if t then
|
local y0=y+h*.5-ATV*.5
|
||||||
setFont(self.font)
|
gc.setColor(1,1,1,.2+ATV*.05)
|
||||||
local y0=y+h*.5-self.font*.7-ATV*.5
|
if self.align=="M"then
|
||||||
gc.setColor(1,1,1,.2+ATV*.05)
|
local x0=x+w*.5
|
||||||
local edge=self.edge
|
mDraw(obj,x0-2,y0-2)
|
||||||
gc.printf(t,x+edge-2,y0-2,w-2*edge,self.align)
|
mDraw(obj,x0-2,y0+2)
|
||||||
gc.printf(t,x+edge-2,y0+2,w-2*edge,self.align)
|
mDraw(obj,x0+2,y0-2)
|
||||||
gc.printf(t,x+edge+2,y0-2,w-2*edge,self.align)
|
mDraw(obj,x0+2,y0+2)
|
||||||
gc.printf(t,x+edge+2,y0+2,w-2*edge,self.align)
|
|
||||||
gc.setColor(r*.5,g*.5,b*.5)
|
gc.setColor(r*.5,g*.5,b*.5)
|
||||||
gc.printf(t,x+edge,y0,w-2*edge,self.align)
|
mDraw(obj,x0,y0)
|
||||||
else
|
elseif self.align=="L"then
|
||||||
self.text=self.name or"###"
|
local edge=self.edge
|
||||||
self.color=COLOR.dPurple
|
mDraw_Y(obj,x+edge-2,y0-2)
|
||||||
|
mDraw_Y(obj,x+edge-2,y0+2)
|
||||||
|
mDraw_Y(obj,x+edge+2,y0-2)
|
||||||
|
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
|
||||||
|
local x0=x+w-self.edge-obj:getWidth()
|
||||||
|
mDraw_Y(obj,x0-2,y0-2)
|
||||||
|
mDraw_Y(obj,x0-2,y0+2)
|
||||||
|
mDraw_Y(obj,x0+2,y0-2)
|
||||||
|
mDraw_Y(obj,x0+2,y0+2)
|
||||||
|
gc.setColor(r*.5,g*.5,b*.5)
|
||||||
|
mDraw_Y(obj,x0,y0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function button:getInfo()
|
function button:getInfo()
|
||||||
@@ -196,7 +201,7 @@ function WIDGET.newButton(D)--name,x,y,w[,h][,fText][,color][,font][,align="M"[,
|
|||||||
fText= D.fText,
|
fText= D.fText,
|
||||||
color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
|
color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
|
||||||
font= D.font or 30,
|
font= D.font or 30,
|
||||||
align= alignModes[D.align or"M"]or"center",
|
align= D.align or"M",
|
||||||
edge= D.edge or 0,
|
edge= D.edge or 0,
|
||||||
code= D.code,
|
code= D.code,
|
||||||
hide= D.hide,
|
hide= D.hide,
|
||||||
@@ -244,14 +249,13 @@ function key:draw()
|
|||||||
gc.setLineWidth(4)
|
gc.setLineWidth(4)
|
||||||
gc.rectangle("line",x,y,w,h)
|
gc.rectangle("line",x,y,w,h)
|
||||||
|
|
||||||
local t=self.text
|
gc.setColor(r,g,b,1.2)
|
||||||
if t then
|
if self.align=="M"then
|
||||||
setFont(self.font)
|
mDraw(self.obj,x+w*.5,y+h*.5)
|
||||||
gc.setColor(r,g,b,1.2)
|
elseif self.align=="L"then
|
||||||
gc.printf(t,x+self.edge,y+h*.5-self.font*.7,w-2*self.edge,self.align)
|
mDraw_Y(self.obj,x+self.edge,y+h*.5)
|
||||||
else
|
elseif self.align=="R"then
|
||||||
self.text=self.name or"###"
|
mDraw_Y(self.obj,x+w*.5,y+h*.5)
|
||||||
self.color=COLOR.dPurple
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function key:getInfo()
|
function key:getInfo()
|
||||||
@@ -281,7 +285,7 @@ function WIDGET.newKey(D)--name,x,y,w[,h][,fText][,color][,font][,align="M"[,edg
|
|||||||
fText= D.fText,
|
fText= D.fText,
|
||||||
color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
|
color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
|
||||||
font= D.font or 30,
|
font= D.font or 30,
|
||||||
align= alignModes[D.align or"M"]or"center",
|
align= D.align or"M",
|
||||||
edge= D.edge or 0,
|
edge= D.edge or 0,
|
||||||
code= D.code,
|
code= D.code,
|
||||||
hide= D.hide,
|
hide= D.hide,
|
||||||
@@ -336,13 +340,10 @@ function switch:draw()
|
|||||||
gc.setColor(1,1,1,.6+ATV*.05)
|
gc.setColor(1,1,1,.6+ATV*.05)
|
||||||
gc.rectangle("line",x,y,50,50)
|
gc.rectangle("line",x,y,50,50)
|
||||||
|
|
||||||
--Text
|
--Drawable
|
||||||
local t=self.text
|
local obj=self.obj
|
||||||
if t then
|
gc.setColor(self.color)
|
||||||
gc.setColor(self.color)
|
mDraw_Y(obj,x-12-ATV-obj:getWidth(),y+25)
|
||||||
setFont(self.font)
|
|
||||||
gc.printf(t,x-412-ATV,y+20-self.font*.7,400,"right")
|
|
||||||
end
|
|
||||||
end
|
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)
|
||||||
@@ -461,13 +462,10 @@ function slider:draw()
|
|||||||
mStr(self:show(),cx,by-30)
|
mStr(self:show(),cx,by-30)
|
||||||
end
|
end
|
||||||
|
|
||||||
--Text
|
--Drawable
|
||||||
local t=self.text
|
local obj=self.obj
|
||||||
if t then
|
gc.setColor(self.color)
|
||||||
gc.setColor(self.color)
|
mDraw_Y(obj,x-12-ATV-obj:getWidth(),y)
|
||||||
setFont(self.font)
|
|
||||||
gc.printf(t,x-312-ATV,y-self.font*.7,300,"right")
|
|
||||||
end
|
|
||||||
end
|
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)
|
||||||
@@ -622,14 +620,11 @@ function selector:draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--Text
|
--Drawable
|
||||||
setFont(30)
|
gc.setColor(self.color)
|
||||||
t=self.text
|
MDRAW.simpX(self.obj,x+w*.5,y+17-21)
|
||||||
if t then
|
|
||||||
gc.setColor(self.color)
|
|
||||||
mStr(self.text,x+w*.5,y+17-21)
|
|
||||||
end
|
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
|
setFont(30)
|
||||||
mStr(self.selText,x+w*.5,y+43-21)
|
mStr(self.selText,x+w*.5,y+43-21)
|
||||||
end
|
end
|
||||||
function selector:getInfo()
|
function selector:getInfo()
|
||||||
@@ -690,6 +685,7 @@ function WIDGET.newSelector(D)--name,x,y,w[,fText][,color],list,disp,code,hide
|
|||||||
|
|
||||||
fText= D.fText,
|
fText= D.fText,
|
||||||
color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
|
color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
|
||||||
|
font= 30,
|
||||||
list= D.list,
|
list= D.list,
|
||||||
disp= D.disp,
|
disp= D.disp,
|
||||||
code= D.code,
|
code= D.code,
|
||||||
@@ -744,11 +740,11 @@ function inputBox:draw()
|
|||||||
gc.setLineWidth(4)
|
gc.setLineWidth(4)
|
||||||
gc.rectangle("line",x,y,w,h)
|
gc.rectangle("line",x,y,w,h)
|
||||||
|
|
||||||
--Text
|
--Drawable
|
||||||
setFont(self.font)
|
setFont(self.font)
|
||||||
local t=self.text
|
local obj=self.obj
|
||||||
if t then
|
if obj then
|
||||||
gc.printf(t,x-412,y+h*.5-self.font*.7,400,"right")
|
mDraw_Y(obj,x-12-obj:getWidth(),y+h*.5)
|
||||||
end
|
end
|
||||||
if self.secret then
|
if self.secret then
|
||||||
for i=1,#self.value do
|
for i=1,#self.value do
|
||||||
@@ -1004,7 +1000,15 @@ function WIDGET.setLang(widgetText)
|
|||||||
for S,L in next,SCN.scenes do
|
for S,L in next,SCN.scenes do
|
||||||
if L.widgetList then
|
if L.widgetList then
|
||||||
for _,W in next,L.widgetList do
|
for _,W in next,L.widgetList do
|
||||||
W.text=W.fText or widgetText[S][W.name]
|
local t=W.fText or widgetText[S][W.name]
|
||||||
|
if not t and not allowNoText[W.type]then
|
||||||
|
t=W.name or"##"
|
||||||
|
W.color=COLOR.dPurple
|
||||||
|
end
|
||||||
|
if type(t)=="string"and W.font then
|
||||||
|
t=gc.newText(getFont(W.font),t)
|
||||||
|
end
|
||||||
|
W.obj=t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ function scene.sceneInit()
|
|||||||
cmdEntryThread()
|
cmdEntryThread()
|
||||||
|
|
||||||
--Set quick-play-button text
|
--Set quick-play-button text
|
||||||
scene.widgetList[2].text=text.WidgetText.main.qplay..": "..text.modes[STAT.lastPlay][1]
|
scene.widgetList[2].text=gc.newText(getFont(scene.widgetList[2].font),text.WidgetText.main.qplay..": "..text.modes[STAT.lastPlay][1])
|
||||||
quickSure=false
|
quickSure=false
|
||||||
|
|
||||||
--Create demo player
|
--Create demo player
|
||||||
|
|||||||
Reference in New Issue
Block a user