选择器控件完成

This commit is contained in:
MrZ626
2020-09-17 21:05:08 +08:00
parent 2f4cd650fd
commit 31f5393dfc
4 changed files with 189 additions and 45 deletions

View File

@@ -208,7 +208,7 @@ function slider:reset()
self.pos=0
end
function slider:isAbove(x,y)
return x>self.x-10 and x<self.x+self.w+10 and y>self.y-20 and y<self.y+20
return x>self.x-10 and x<self.x+self.w+10 and y>self.y-25 and y<self.y+25
end
function slider:getCenter()
return self.x+self.w*(self.pos/self.unit),self.y
@@ -284,8 +284,90 @@ function slider:printInfo()
DBP(format("x=%d,y=%d,w=%d",self.x,self.y,self.w))
end
local selector={
type="selector",
ATV=8,--Activating time(0~4)
select=0,--Selected item ID
selText=nil,--Selected item name
}
function selector:reset()
self.ATV=0
local V=self.disp()
local L=self.list
for i=1,#L do
if L[i]==V then
self.select=i
self.selText=self.list[i]
break
end
end
end
function selector:isAbove(x,y)
return
x>self.x and
x<self.x+self.w+2 and
y>self.y and
y<self.y+60
end
function selector:getCenter()
return self.x+self.w*(self.pos/self.unit),self.y
end
function selector:update()
local atv=self.ATV
if WIDGET.sel==self then
if atv<8 then
self.ATV=atv+1
end
else
if atv>0 then
self.ATV=atv-.5
end
end
end
function selector:draw()
local x,y=self.x,self.y
local r,g,b=unpack(self.color)
local w=self.w
local ATV=self.ATV
gc.setColor(1,1,1,.6+ATV*.1)
gc.setLineWidth(3)
gc.rectangle("line",x,y,w,60)
gc.setColor(1,1,1,.2+ATV*.1)
local t=(Timer()%.5)^.5
if self.select>1 then
gc.draw(drawableText.small,x+6,y+20)
if ATV>0 then
gc.setColor(1,1,1,ATV*.4*(.5-t))
gc.draw(drawableText.small,x+6-t*40,y+20)
gc.setColor(1,1,1,.2+ATV*.1)
end
end
if self.select<#self.list then
gc.draw(drawableText.large,x+w-24,y+20)
if ATV>0 then
gc.setColor(1,1,1,ATV*.4*(.5-t))
gc.draw(drawableText.large,x+w-24+t*40,y+20)
end
end
setFont(28)
t=self.text
if t then
if type(t)=="function"then t=t()end
gc.setColor(r,g,b)
mStr(self.text,x+w*.5,y+17-21)
end
gc.setColor(1,1,1)
mStr(self.selText,x+w*.5,y+43-21)
end
function selector:printInfo()
DBP(format("x=%d,y=%d,w=%d",self.x,self.y,self.w))
end
local WIDGET={}
WIDGET.active={}--Table, contains all active widgets
WIDGET.active={}--Table contains all active widgets
WIDGET.sel=nil--Selected widget
function WIDGET.set(L)
WIDGET.sel=nil
@@ -306,7 +388,7 @@ function WIDGET.newText(D)
x= D.x,
y= D.y,
align= D.align,
color= color[D.color]or D.color,
color= D.color and(color[D.color]or D.color)or color.white,
font= D.font,
hide= D.hide,
}for k,v in next,button do _[k]=v end return _
@@ -318,7 +400,7 @@ function WIDGET.newImage(D)
y= D.y-h*.5,
w= D.w,
h= D.h,
color= color[D.color]or D.color,
color= D.color and(color[D.color]or D.color)or color.white,
font= D.font,
code= D.code,
hide= D.hide,
@@ -342,7 +424,7 @@ function WIDGET.newButton(D)
D.x+D.w*.35,D.y+D.h*.35,
},
color= color[D.color]or D.color,
color= D.color and(color[D.color]or D.color)or color.white,
font= D.font,
code= D.code,
hide= D.hide,
@@ -366,7 +448,7 @@ function WIDGET.newKey(D)
D.x+D.w*.35,D.y+D.h*.35,
},
color= color[D.color]or D.color,
color= D.color and(color[D.color]or D.color)or color.white,
font= D.font,
code= D.code,
hide= D.hide,
@@ -379,8 +461,6 @@ function WIDGET.newSwitch(D)
x= D.x,
y= D.y,
cx= D.x+25,
cy= D.y,
resCtr={
D.x+25,D.y,
},
@@ -399,8 +479,6 @@ function WIDGET.newSlider(D)
y= D.y,
w= D.w,
cx= D.x+D.w*.5,
cy= D.y,
resCtr={
D.x,D.y,
D.x+D.w*.25,D.y,
@@ -440,6 +518,30 @@ function WIDGET.newSlider(D)
end
for k,v in next,slider do _[k]=v end return _
end
function WIDGET.newSelector(D)
local _={
name= D.name,
x= D.x-D.w*.5,
y= D.y-30,
w= D.w,
resCtr={
D.x,D.y,
D.x+D.w*.25,D.y,
D.x+D.w*.5,D.y,
D.x+D.w*.75,D.y,
D.x+D.w,D.y,
},
color= D.color and(color[D.color]or D.color)or color.white,
list= D.list,
disp= D.disp,
code= D.code,
hide= D.hide,
}
for k,v in next,selector do _[k]=v end return _
end
function WIDGET.moveCursor(x,y)
WIDGET.sel=nil
@@ -462,9 +564,28 @@ function WIDGET.press(x,y)
SFX.play("lock")
elseif W.type=="switch"then
W.code()
SFX.play("move",.6)
SFX.play("move")
elseif W.type=="slider"then
WIDGET.drag(x,y)
elseif W.type=="selector"then
local s=W.select
if x<W.x+W.w*.5 then
if s>1 then
s=s-1
sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60)
end
else
if s<#W.list then
s=s+1
sysFX.newShade(.3,1,1,1,W.x+W.w*.5,W.y,W.w*.5,60)
end
end
if W.select~=s then
W.code(W.list[s])
W.select=s
W.selText=W.list[s]
SFX.play("prerotate")
end
end
if W.hide and W.hide()then WIDGET.sel=nil end
end
@@ -473,8 +594,9 @@ function WIDGET.drag(x,y,dx,dy)
if not W then return end
if W.type=="slider"then
if not x then return end
x=x-W.x
local p=W.disp()
local P=x<W.x and 0 or x>W.x+W.w and W.unit or(x-W.x)/W.w*W.unit
local P=x<0 and 0 or x>W.w and W.unit or x/W.w*W.unit
if not W.smooth then
P=int(P+.5)
end
@@ -518,6 +640,26 @@ function WIDGET.keyPressed(i)
W.lastTime=Timer()
W.change()
end
elseif W.type=="selector"then
print(1)
local s=W.select
if i=="left"then
if s>1 then
s=s-1
sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60)
end
else
if s<#W.list then
s=s+1
sysFX.newShade(.3,1,1,1,W.x+W.w*.5,W.y,W.w*.5,60)
end
end
if W.select~=s then
W.code(W.list[s])
W.select=s
W.selText=W.list[s]
SFX.play("prerotate")
end
end
end
end

View File

@@ -86,7 +86,7 @@ local CUSlist={
opponent={0,1,2,3,4,5,6,7,8,9,10},
life={0,1,2,3,4,5,10,42,87,500},
pushSpeed={1,2,3,5,15},
bg={"none","bg1","bg2","rainbow","aura","rgb","glow","matrix"},
bg={"none","glow","rgb","flink","aura","bg1","bg2","rainbow","rainbow2","lightning","lightning2","matrix","space"},
bgm={"blank","race","push","way","reason","newera","oxygen","infinite","down","secret7th","secret8th","rockblock","cruelty","final"},
}
--Lambda Funcs for widgets,delete at file end
@@ -167,43 +167,43 @@ local Widgets={
},
custom={
--Basic
newSelector({name="drop", x=180, y=150+20,w=260, list=CUSlist.drop, disp=CUSval("drop"), code=CUSsto("drop")}),
newSelector({name="lock", x=180, y=230+20,w=260, list=CUSlist.lock, disp=CUSval("lock"), code=CUSsto("lock")}),
newSelector({name="wait", x=180, y=310+20,w=260, list=CUSlist.wait, disp=CUSval("wait"), code=CUSsto("wait")}),
newSelector({name="fall", x=180, y=390+20,w=260, list=CUSlist.fall, disp=CUSval("fall"), code=CUSsto("fall")}),
newSelector({name="drop", x=180, y=150+20,w=260,color="red", list=CUSlist.drop, disp=CUSval("drop"), code=CUSsto("drop")}),
newSelector({name="lock", x=180, y=230+20,w=260,color="red", list=CUSlist.lock, disp=CUSval("lock"), code=CUSsto("lock")}),
newSelector({name="wait", x=180, y=310+20,w=260,color="orange", list=CUSlist.wait, disp=CUSval("wait"), code=CUSsto("wait")}),
newSelector({name="fall", x=180, y=390+20,w=260,color="orange", list=CUSlist.fall, disp=CUSval("fall"), code=CUSsto("fall")}),
newSlider({name="next", x=120, y=500,w=200,unit=6, font=30, disp=CUSval("next"), code=CUSsto("next")}),
newSwitch({name="hold", x=230, y=570, font=30, disp=CUSval("hold"), code=CUSrev("hold")}),
newSwitch({name="oncehold", x=230, y=650, font=30, disp=CUSval("oncehold"),code=CUSrev("oncehold"),hide=function()return not customEnv.hold end}),
newSlider({name="next", x=120, y=500,w=200,unit=6, font=30, disp=CUSval("next"), code=CUSsto("next")}),
newSwitch({name="hold", x=230, y=570, font=30, disp=CUSval("hold"), code=CUSrev("hold")}),
newSwitch({name="oncehold", x=230, y=650, font=30, disp=CUSval("oncehold"),code=CUSrev("oncehold"),hide=function()return not customEnv.hold end}),
--Visual
newSlider({name="block", x=470, y=150,w=120,unit=1, font=25, disp=CUSval("block"), code=CUSsto("block")}),
newSlider({name="ghost", x=470, y=210,w=120,unit=.6, font=25, disp=CUSval("ghost"), code=CUSsto("ghost")}),
newSlider({name="center", x=470, y=270,w=120,unit=1, font=25, disp=CUSval("center"), code=CUSsto("center")}),
newSwitch({name="bagLine", x=570, y=340, font=30, disp=CUSval("bagLine"), code=CUSrev("bagLine")}),
newSwitch({name="highCam", x=570, y=400, font=30, disp=CUSval("highCam"), code=CUSrev("highCam")}),
newSwitch({name="nextPos", x=570, y=460, font=30, disp=CUSval("nextPos"), code=CUSrev("nextPos")}),
newSwitch({name="bone", x=570, y=520, font=30, disp=CUSval("bone"), code=CUSrev("bone")}),
newSlider({name="block", x=470, y=150,w=120,unit=1, font=25, disp=CUSval("block"), code=CUSsto("block")}),
newSlider({name="ghost", x=470, y=210,w=120,unit=.6, font=25, disp=CUSval("ghost"), code=CUSsto("ghost")}),
newSlider({name="center", x=470, y=270,w=120,unit=1, font=25, disp=CUSval("center"), code=CUSsto("center")}),
newSwitch({name="bagLine", x=570, y=340, font=30, disp=CUSval("bagLine"), code=CUSrev("bagLine")}),
newSwitch({name="highCam", x=570, y=400, font=30, disp=CUSval("highCam"), code=CUSrev("highCam")}),
newSwitch({name="nextPos", x=570, y=460, font=30, disp=CUSval("nextPos"), code=CUSrev("nextPos")}),
newSwitch({name="bone", x=570, y=520, font=30, disp=CUSval("bone"), code=CUSrev("bone")}),
--Rule
newSlider({name="mindas", x=750, y=150,w=200,unit=15,font=25, disp=CUSval("mindas"), code=CUSsto("mindas")}),
newSlider({name="minarr", x=750, y=210,w=200,unit=10,font=25, disp=CUSval("minarr"), code=CUSsto("minarr")}),
newSlider({name="minsdarr", x=750, y=270,w=200,unit=4, font=22, disp=CUSval("minsdarr"),code=CUSsto("minsdarr")}),
newSelector({name="sequence", x=520, y=600,w=200, list=CUSlist.sequence, disp=CUSval("sequence"),code=CUSsto("sequence")}),
newSwitch({name="ospin", x=860, y=340, font=30, disp=CUSval("ospin"), code=CUSrev("ospin")}),
newSwitch({name="noTele", x=860, y=400, font=25, disp=CUSval("noTele"), code=CUSrev("noTele")}),
newSwitch({name="fineKill", x=860, y=460, font=22, disp=CUSval("fineKill"),code=CUSrev("fineKill")}),
newSwitch({name="easyFresh", x=860, y=520, font=18, disp=CUSval("easyFresh"),code=CUSrev("easyFresh")}),
newSelector({name="visible", x=1120, y=60,w=260, list=CUSlist.visible, disp=CUSval("visible"), code=CUSsto("visible")}),
newSelector({name="target", x=1120, y=140,w=260, list=CUSlist.target, disp=CUSval("target"), code=CUSsto("target")}),
newSelector({name="freshLimit", x=1120, y=220,w=260, list=CUSlist.freshLimit,disp=CUSval("freshLimit"),code=CUSsto("freshLimit")}),
newSelector({name="opponent", x=1120, y=300,w=260, list=CUSlist.opponent, disp=CUSval("opponent"),code=CUSsto("opponent")}),
newSelector({name="life", x=1120, y=380,w=260, list=CUSlist.life, disp=CUSval("life"), code=CUSsto("life")}),
newSelector({name="pushSpeed", x=1120, y=460,w=260, list=CUSlist.pushSpeed, disp=CUSval("pushSpeed"),code=CUSsto("pushSpeed")}),
newSlider({name="mindas", x=750, y=150,w=200,unit=15,font=25, disp=CUSval("mindas"), code=CUSsto("mindas")}),
newSlider({name="minarr", x=750, y=210,w=200,unit=10,font=25, disp=CUSval("minarr"), code=CUSsto("minarr")}),
newSlider({name="minsdarr", x=750, y=270,w=200,unit=4, font=22, disp=CUSval("minsdarr"),code=CUSsto("minsdarr")}),
newSelector({name="sequence", x=520, y=600,w=200,color="green", list=CUSlist.sequence, disp=CUSval("sequence"),code=CUSsto("sequence")}),
newSwitch({name="ospin", x=860, y=340, font=30, disp=CUSval("ospin"), code=CUSrev("ospin")}),
newSwitch({name="noTele", x=860, y=400, font=25, disp=CUSval("noTele"), code=CUSrev("noTele")}),
newSwitch({name="fineKill", x=860, y=460, font=22, disp=CUSval("fineKill"),code=CUSrev("fineKill")}),
newSwitch({name="easyFresh", x=860, y=520, font=18, disp=CUSval("easyFresh"),code=CUSrev("easyFresh")}),
newSelector({name="visible", x=1120, y=60,w=260,color="lBlue", list=CUSlist.visible, disp=CUSval("visible"), code=CUSsto("visible")}),
newSelector({name="target", x=1120, y=140,w=260,color="green", list=CUSlist.target, disp=CUSval("target"), code=CUSsto("target")}),
newSelector({name="freshLimit", x=1120, y=220,w=260,color="purple", list=CUSlist.freshLimit,disp=CUSval("freshLimit"),code=CUSsto("freshLimit")}),
newSelector({name="opponent", x=1120, y=300,w=260,color="red", list=CUSlist.opponent, disp=CUSval("opponent"),code=CUSsto("opponent")}),
newSelector({name="life", x=1120, y=380,w=260,color="red", list=CUSlist.life, disp=CUSval("life"), code=CUSsto("life")}),
newSelector({name="pushSpeed", x=1120, y=460,w=260,color="red", list=CUSlist.pushSpeed, disp=CUSval("pushSpeed"),code=CUSsto("pushSpeed")}),
--Else
newSelector({name="bg", x=800, y=600, w=220, list=CUSlist.bg, disp=CUSval("bg"), code=CUSsto("bg")}),
newSelector({name="bgm", x=800, y=670, w=220, list=CUSlist.bgm, disp=CUSval("bgm"), code=CUSsto("bgm")}),
newSelector({name="bg", x=800, y=600, w=220,color="yellow", list=CUSlist.bg, disp=CUSval("bg"), code=function(i)customEnv.bg=i BG.set(i)end}),
newSelector({name="bgm", x=800, y=670, w=220,color="yellow", list=CUSlist.bgm, disp=CUSval("bgm"), code=function(i)customEnv.bgm=i BGM.play(i)end}),
newButton({name="seq", x=520, y=670, w=200,h=60, color="lGreen", font=30,code=pressKey("q")}),
newButton({name="draw", x=150, y=80, w=220,h=80, color="white", font=35,code=pressKey("e")}),

View File

@@ -165,8 +165,8 @@ end
local function T(s,t)return love.graphics.newText(setFont(s),t)end
drawableText={
question=T(100,"?"),
right=T(45,""),
question=T(100,"?"),right=T(45,""),
small=T(30,"<"),large=T(30,">"),
bpm=T(15,"BPM"),kpm=T(15,"KPM"),
speedLV=T(20,"speed level"),

View File

@@ -1304,6 +1304,8 @@ do--custom
SCN.swapTo("draw","swipeL")
elseif key=="escape"then
SCN.back()
else
WIDGET.keyPressed(key)
end
end