222 lines
5.4 KiB
Lua
222 lines
5.4 KiB
Lua
local gc=love.graphics
|
|
local ms=love.mouse
|
|
|
|
local int,sin=math.floor,math.sin
|
|
|
|
local scene={}
|
|
|
|
local defaultSetSelect
|
|
local snapUnit=1
|
|
local selected--Button selected
|
|
|
|
function scene.sceneInit()
|
|
BG.set("rainbow")
|
|
defaultSetSelect=1
|
|
selected=false
|
|
end
|
|
function scene.sceneBack()
|
|
FILE.save(VK_org,"conf/virtualkey")
|
|
end
|
|
|
|
local function onVK_org(x,y)
|
|
local dist,nearest=1e10
|
|
for K=1,#VK_org do
|
|
local B=VK_org[K]
|
|
if B.ava then
|
|
local d1=(x-B.x)^2+(y-B.y)^2
|
|
if d1<B.r^2 then
|
|
if d1<dist then
|
|
nearest,dist=K,d1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return nearest
|
|
end
|
|
function scene.mouseDown(x,y,k)
|
|
if k==2 then SCN.back()end
|
|
selected=onVK_org(x,y)or selected
|
|
end
|
|
function scene.mouseMove(_,_,dx,dy)
|
|
if selected and ms.isDown(1)and not WIDGET.sel then
|
|
local B=VK_org[selected]
|
|
B.x,B.y=B.x+dx,B.y+dy
|
|
end
|
|
end
|
|
function scene.mouseUp()
|
|
if selected then
|
|
local B=VK_org[selected]
|
|
local k=snapUnit
|
|
B.x,B.y=int(B.x/k+.5)*k,int(B.y/k+.5)*k
|
|
end
|
|
end
|
|
function scene.touchDown(x,y)
|
|
selected=onVK_org(x,y)or selected
|
|
end
|
|
function scene.touchUp()
|
|
if selected then
|
|
local B=VK_org[selected]
|
|
local k=snapUnit
|
|
B.x,B.y=int(B.x/k+.5)*k,int(B.y/k+.5)*k
|
|
end
|
|
end
|
|
function scene.touchMove(_,_,dx,dy)
|
|
if selected and not WIDGET.sel then
|
|
local B=VK_org[selected]
|
|
B.x,B.y=B.x+dx,B.y+dy
|
|
end
|
|
end
|
|
|
|
local function virtualkeyPreview()
|
|
if SETTING.VKSwitch then
|
|
for i=1,#VK_org do
|
|
local B=VK_org[i]
|
|
if B.ava then
|
|
gc.setColor(1,1,1,SETTING.VKAlpha)
|
|
gc.setLineWidth(B.r*.07)
|
|
gc.circle("line",B.x,B.y,B.r,10)
|
|
if selected==i and TIME()%.26<.13 then
|
|
gc.setColor(1,1,1,SETTING.VKAlpha*.62)
|
|
gc.circle("fill",B.x,B.y,B.r,10)
|
|
end
|
|
if SETTING.VKIcon then
|
|
local c=B.color
|
|
gc.setColor(c[1],c[2],c[3],SETTING.VKAlpha)
|
|
gc.draw(TEXTURE.VKIcon[i],B.x,B.y,nil,B.r*.025,nil,18,18)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
function scene.draw()
|
|
gc.setColor(1,1,1)
|
|
gc.setLineWidth(7)gc.rectangle("line",340,15,600,690)
|
|
gc.setLineWidth(3)gc.rectangle("line",490,85,300,600)
|
|
virtualkeyPreview()
|
|
local d=snapUnit
|
|
if d>=10 then
|
|
gc.setLineWidth(3)
|
|
gc.setColor(1,1,1,sin(TIME()*4)*.1+.1)
|
|
for i=1,1280/d-1 do
|
|
gc.line(d*i,0,d*i,720)
|
|
end
|
|
for i=1,720/d-1 do
|
|
gc.line(0,d*i,1280,d*i)
|
|
end
|
|
end
|
|
end
|
|
|
|
local virtualkeySet={
|
|
{
|
|
{1, 80, 720-200, 80},--moveLeft
|
|
{2, 320, 720-200, 80},--moveRight
|
|
{3, 1280-80, 720-200, 80},--rotRight
|
|
{4, 1280-200, 720-80, 80},--rotLeft
|
|
{5, 1280-200, 720-320, 80},--rot180
|
|
{6, 200, 720-320, 80},--hardDrop
|
|
{7, 200, 720-80, 80},--softDrop
|
|
{8, 1280-320, 720-200, 80},--hold
|
|
{9, 80, 280, 80},--func1
|
|
{10,1280-80, 280, 80},--func2
|
|
},--Farter's tetr.js set
|
|
{
|
|
{1, 1280-320, 720-200, 80},--moveLeft
|
|
{2, 1280-80, 720-200, 80},--moveRight
|
|
{3, 200, 720-80, 80},--rotRight
|
|
{4, 80, 720-200, 80},--rotLeft
|
|
{5, 200, 720-320, 80},--rot180
|
|
{6, 1280-200, 720-320, 80},--hardDrop
|
|
{7, 1280-200, 720-80, 80},--softDrop
|
|
{8, 320, 720-200, 80},--hold
|
|
{9, 1280-80, 280, 80},--func1
|
|
{10,80, 280, 80},--func2
|
|
},--Mirrored tetr.js set
|
|
{
|
|
{1, 80, 720-80, 80},--moveLeft
|
|
{2, 240, 720-80, 80},--moveRight
|
|
{3, 1280-240, 720-80, 80},--rotRight
|
|
{4, 1280-400, 720-80, 80},--rotLeft
|
|
{5, 1280-240, 720-240, 80},--rot180
|
|
{6, 1280-80, 720-80, 80},--hardDrop
|
|
{7, 1280-80, 720-240, 80},--softDrop
|
|
{8, 1280-80, 720-400, 80},--hold
|
|
{9, 80, 720-240, 80},--func1
|
|
{10,240, 720-240, 80},--func2
|
|
},--Author's set, not recommend
|
|
{
|
|
{1, 1280-400, 720-80, 80},--moveLeft
|
|
{2, 1280-80, 720-80, 80},--moveRight
|
|
{3, 240, 720-80, 80},--rotRight
|
|
{4, 80, 720-80, 80},--rotLeft
|
|
{5, 240, 720-240, 80},--rot180
|
|
{6, 1280-240, 720-240, 80},--hardDrop
|
|
{7, 1280-240, 720-80, 80},--softDrop
|
|
{8, 400, 720-80, 80},--hold
|
|
{9, 80, 720-240, 80},--func1
|
|
{10,80, 720-400, 80},--func2
|
|
},--Keyboard set
|
|
{
|
|
{9, 70, 50,30},--func1
|
|
{10,130, 50,30},--func2
|
|
{4, 190, 50,30},--rotLeft
|
|
{3, 250, 50,30},--rotRight
|
|
{5, 310, 50,30},--rot180
|
|
{1, 370, 50,30},--moveLeft
|
|
{2, 430, 50,30},--moveRight
|
|
{8, 490, 50,30},--hold
|
|
{7, 550, 50,30},--softDrop1
|
|
{6, 610, 50,30},--hardDrop
|
|
{11,670, 50,30},--insLeft
|
|
{12,730, 50,30},--insRight
|
|
{13,790, 50,30},--insDown
|
|
{14,850, 50,30},--down1
|
|
{15,910, 50,30},--down4
|
|
{16,970, 50,30},--down10
|
|
{17,1030, 50,30},--dropLeft
|
|
{18,1090, 50,30},--dropRight
|
|
{19,1150, 50,30},--zangiLeft
|
|
{20,1210, 50,30},--zangiRight
|
|
},--PC key feedback(top&in a row)
|
|
}
|
|
scene.widgetList={
|
|
WIDGET.newButton{name="default",x=520,y=90,w=200,h=80,font=35,
|
|
code=function()
|
|
local D=virtualkeySet[defaultSetSelect]
|
|
for i=1,#VK_org do
|
|
VK_org[i].ava=false
|
|
end
|
|
|
|
--Replace keys
|
|
for n=1,#D do
|
|
local T=D[n]
|
|
if T[1]then
|
|
local B=VK_org[n]
|
|
B.ava=true
|
|
B.x,B.y,B.r=T[2],T[3],T[4]
|
|
end
|
|
end
|
|
LOG.print("[ "..defaultSetSelect.." ]")
|
|
defaultSetSelect=defaultSetSelect%5+1
|
|
selected=false
|
|
end},
|
|
WIDGET.newSelector{name="snap", x=760,y=90,w=200,h=80,color="yellow",list={1,10,20,40,60,80},disp=function()return snapUnit end,code=function(i)snapUnit=i end},
|
|
WIDGET.newButton{name="option", x=520,y=190,w=200,h=80,font=40,
|
|
code=function()
|
|
SCN.go("setting_touchSwitch")
|
|
end},
|
|
WIDGET.newButton{name="back", x=760,y=190,w=200,h=80,font=35,code=backScene},
|
|
WIDGET.newSlider{name="size", x=450,y=270,w=460,unit=19,font=40,show="vkSize",
|
|
disp=function()
|
|
return VK_org[selected].r/10-1
|
|
end,
|
|
code=function(v)
|
|
if selected then
|
|
VK_org[selected].r=(v+1)*10
|
|
end
|
|
end,
|
|
hide=function()
|
|
return not selected
|
|
end},
|
|
}
|
|
|
|
return scene |