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

@@ -66,23 +66,25 @@ function love.load()
SCENE = SETTINGS.firstTime and InputConfigScene(true) or TitleScene()
VCTRL.toggle(love.system.getOS()=='Android' or true)
VCTRL.new{
-- {type='button',x= 100,y=320,key= 'up',icon= 'up',r=35,iconSize=60,alpha=0.75},
-- {type='button',x= 160,y=380,key='right',icon= 'right',r=35,iconSize=60,alpha=0.75},
-- {type='button',x= 100,y=440,key= 'down',icon= 'down',r=35,iconSize=60,alpha=0.75},
-- {type='button',x= 40,y=380,key= 'left',icon= 'left',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640-100,y=320,key= 'f16',icon='rotate_right2',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640-160,y=380,key= 'f14',icon= 'rotate_left2',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640-100,y=440,key= 'f15',icon= 'rotate_right',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640- 40,y=380,key= 'f13',icon= 'rotate_left',r=35,iconSize=60,alpha=0.75},
{type='button',x= 70,y=280,key= 'up',icon= 'up',r=45,iconSize=60,alpha=0.75},
{type='button',x= 145,y=355,key='right',icon= 'right',r=45,iconSize=60,alpha=0.75},
{type='button',x= 70,y=430,key= 'down',icon= 'down',r=45,iconSize=60,alpha=0.75},
{type='button',x= -5,y=355,key= 'left',icon= 'left',r=45,iconSize=60,alpha=0.75},
{type='button',x=640- 70,y=280,key= 'f16',icon='rotate_right2',r=45,iconSize=60,alpha=0.75},
{type='button',x=640-145,y=355,key= 'f14',icon= 'rotate_left2',r=45,iconSize=60,alpha=0.75},
{type='button',x=640- 70,y=430,key= 'f15',icon= 'rotate_right',r=45,iconSize=60,alpha=0.75},
{type='button',x=640- -5,y=355,key= 'f13',icon= 'rotate_left',r=45,iconSize=60,alpha=0.75},
VCTRL.new{ -- up down left right --- right left down up
-- {type='button',x= 100,y=320,key= 'up',r=35,iconSize=60,alpha=0.75},
-- {type='button',x= 100,y=440,key= 'down',r=35,iconSize=60,alpha=0.75},
-- {type='button',x= 40,y=380,key= 'left',r=35,iconSize=60,alpha=0.75},
-- {type='button',x= 160,y=380,key= 'right',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640- 40,y=380,key= 'rotate_left',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640-160,y=380,key= 'rotate_left2',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640-100,y=440,key= 'rotate_right',r=35,iconSize=60,alpha=0.75},
-- {type='button',x=640-100,y=320,key='rotate_right2',r=35,iconSize=60,alpha=0.75},
{type='button',x= 70,y=280,key= 'up',r=45,iconSize=60,alpha=0.75},
{type='button',x= 70,y=430,key= 'down',r=45,iconSize=60,alpha=0.75},
{type='button',x= -5,y=355,key= 'left',r=45,iconSize=60,alpha=0.75},
{type='button',x= 145,y=355,key= 'right',r=45,iconSize=60,alpha=0.75},
{type='button',x=640- -5,y=355,key= 'rotate_left',r=45,iconSize=60,alpha=0.75},
{type='button',x=640-145,y=355,key= 'rotate_left2',r=45,iconSize=60,alpha=0.75},
{type='button',x=640- 70,y=430,key= 'rotate_right',r=45,iconSize=60,alpha=0.75},
{type='button',x=640- 70,y=280,key='rotate_right2',r=45,iconSize=60,alpha=0.75},
{type='button',x=320- 40,y=420,key= 'menu_decide',r=35,iconSize=60,alpha=0.75},
{type='button',x=320+ 40,y=420,key= 'menu_back',r=35,iconSize=60,alpha=0.75},
}
end
@@ -105,47 +107,39 @@ function love.draw()
VCTRL.draw()
-- -- Grid system
-- local grid_width, grid_height = 40, 20
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
-- love.graphics.setColor(1,1,1,0.5)
-- love.graphics.setLineWidth(1)
-- -- From 0 to X
-- for ix=1,math.floor(64) do
-- love.graphics.line(10*ix,0,10*ix,480)
-- for ix=0,math.floor(640 / grid_width) do
-- love.graphics.line(grid_width * ix, 0 , grid_width * ix, 480)
-- end
-- -- From 0 to Y
-- for iy=1,math.floor(48) do
-- love.graphics.line(0,10*iy,640,10*iy)
-- for iy=0,math.floor(480 / grid_height) do
-- love.graphics.line(0, grid_height * iy, 640, grid_height * iy)
-- end
if DEBUG_showKey then
drawText(
"Pressed: "..(LastPressedKey or '[NONE]').." | Released: "..(LastReleasedKey or '[NONE]'),
0,0,1000,"left"
)
end
-- drawText(
-- "Pressed: "..(LastPressedKey or '[NONE]').." | Released: "..(LastReleasedKey or '[NONE]'),
-- 0,0,1000,"left"
-- )
love.graphics.pop()
end
local return_scancode, escape_scancode = love.keyboard.getScancodeFromKey('return'), love.keyboard.getScancodeFromKey('escape')
function love.touchpressed(id,x,y)
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
if not VCTRL.press(x,y,id) then
if x >= 320 and x <= 640 then
love.keypressed('escape', escape_scancode)
elseif x >= 0 and x <= 320 then
love.keypressed('return', return_scancode)
end
SCENE:onInputPress{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
end
end
function love.touchreleased(id,x,y)
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
if not VCTRL.release(id) then
if x >= 320 and x <= 640 then
love.keyreleased('escape', escape_scancode)
elseif x >= 0 and x <= 320 then
love.keyreleased('return', return_scancode)
end
SCENE:onInputPress{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
end
end
@@ -162,14 +156,14 @@ function love.keypressed(key, scancode)
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
return
-- escape is reserved for menu_back
elseif scancode == "escape" or scancode == "acback" then
SCENE:onInputPress({input="menu_back", type="key", key=key, scancode=scancode})
elseif scancode == "escape" then
SCENE:onInputPress{input="menu_back", type="key", key=key, scancode=scancode}
-- pass any other key to the scene, with its configured mapping
else
if SETTINGS.input and SETTINGS.input.keys then
input_pressed = SETTINGS.input.keys[scancode]
end
SCENE:onInputPress({input=input_pressed, type="key", key=key, scancode=scancode})
SCENE:onInputPress{input=input_pressed, type="key", key=key, scancode=scancode}
end
LastPressedKey = input_pressed or scancode
@@ -180,7 +174,7 @@ function love.keyreleased(key, scancode)
-- escape is reserved for menu_back
if scancode == "escape" or scancode == 'acback' then
SCENE:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode})
SCENE:onInputRelease{input="menu_back", type="key", key=key, scancode=scancode}
-- function keys are reserved
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
return
@@ -189,7 +183,7 @@ function love.keyreleased(key, scancode)
if SETTINGS.input and SETTINGS.input.keys then
input_released = SETTINGS.input.keys[scancode]
end
SCENE:onInputRelease({input=input_released, type="key", key=key, scancode=scancode})
SCENE:onInputRelease{input=input_released, type="key", key=key, scancode=scancode}
end
LastReleasedKey = input_released or scancode