Small changes on how virtual key call action

This commit is contained in:
SweetSea-ButImNotSweet
2024-04-28 19:51:01 +07:00
parent 5f2687f855
commit 5eced5bf8d
4 changed files with 61 additions and 85 deletions

View File

@@ -24,12 +24,13 @@ local virtual_quad=setmetatable((function()
for i,name in next,{
'left','right','up','down','',
'rotate_right','rotate_left','','','',
'menu_deicde','','menu_back','','',
'','','','','',
'','','back','','',
'','','','','',
'','','','','select',
'','','menu_back','','',
'','','','','',
'','','','','menu_decide',
} do if #name>0 then t[name]=gc_newQuad((i-1)%5*w,math.floor((i-1)/5)*w,w,w,5*w,7*w) end end
t.rotate_right2, t.rotate_left2 = t.rotate_right, t.rotate_left
return t
end)(),{
__index=function() return empty_quad end
@@ -52,7 +53,7 @@ function control_type.button:new(data)
key=data.key or 'X',
iconSize=data.iconSize or 80,
alpha=data.alpha or 0.75,
quad=virtual_quad[data.icon]
quad=virtual_quad[data.key]
},self)
end
function control_type.button:reset()
@@ -62,11 +63,13 @@ end
function control_type.button:press()
self.pressed=true
self.lastPressTime=love.timer.getTime()
love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
-- love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
SCENE:onInputPress{input=self.key,type="virtual"}
end
function control_type.button:release()
self.pressed=false
love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
-- love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
SCENE:onInputRelease{input=self.key,type="virtual"}
end
function control_type.button:drag(dx,dy)
self.x,self.y=self.x+dx,self.y+dy
@@ -74,12 +77,18 @@ end
function control_type.button:draw(forceLight)
love.graphics.setLineWidth(4)
if self.shape=='circle' then
love.graphics.setColor(0,0,0,self.alpha*0.5)
love.graphics.circle('fill',self.x,self.y,self.r-4)
love.graphics.setColor(1,1,1,self.pressed and .5 or .05)
love.graphics.circle('fill',self.x,self.y,self.r-4)
love.graphics.setColor(1,1,1)
love.graphics.circle('line',self.x,self.y,self.r-2)
elseif self.shape=='square' then
love.graphics.setColor(0,0,0,self.alpha*0.5)
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
love.graphics.setColor(1,1,1,self.pressed and .5 or .05)
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
@@ -125,6 +134,7 @@ end
---@field key string
---@field iconSize number
---@field alpha number
---@field show boolean
---Adding (multiple) virtual button(s)
function VCTRL.new(...)
for _,d in pairs(...) do